From e55c8b0a92eb9715edd90c31dfd4de51a47b588b Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 04 十一月 2022 17:40:08 +0800
Subject: [PATCH] changes
---
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java | 147 +++++++++++++++++++++++++++++++++---------------
1 files changed, 101 insertions(+), 46 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
index 6dc208a..346f302 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
@@ -1,95 +1,150 @@
package com.sandu.ximon.admin.service;
+import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
+import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.param.LEDProgramParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.LEDProgram;
+import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.LEDProgramMapper;
import lombok.AllArgsConstructor;
-import nova.traffic.utils.NovaTraffic;
import org.springframework.stereotype.Service;
+
+import java.util.List;
@Service
@AllArgsConstructor
public class LEDProgramService extends BaseServiceImpl<LEDProgramMapper, LEDProgram> {
- private final LEDProgramMapper ledProgramMapper;
+ private final ClientService clientService;
public boolean addProgram(LEDProgramParam receiveParam) {
- // public boolean addProgram(String name,Integer kind,String url ) {
LEDProgram led = new LEDProgram();
- led.setUserId(SecurityUtils.getClientId());
- led.setPixel(receiveParam.getPixel());
- led.setSize(receiveParam.getSize());
+ led.setUserId(SecurityUtils.getUserId());
+ led.setUserName(SecurityUtils.getUsername());
+ if (clientService.findClientId()) {
+ led.setClientId(clientService.getClientId());
+ }
led.setName(receiveParam.getName());
- led.setKind(receiveParam.getKind());
- led.setProgramBase64(receiveParam.getProgramBase64());
- /* LEDProgram led = new LEDProgram();
- led.setUserId(SecurityUtils.getClientId());
- led.setName(name);
- led.setKind(kind);
- led.setProgramBase64(url);*/
-
+ led.setPreview(receiveParam.getPreviewUrl());
+ led.setWidth(receiveParam.getWidth());
+ led.setHeight(receiveParam.getHeight());
+ if (receiveParam.getPages() == null) {
+ throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+ }
+ led.setPages(JSON.toJSONString(receiveParam.getPages()));
return save(led);
}
- public boolean updateProgram(LEDProgramParam receiveParam) {
+ public boolean updateProgram(Long pid, LEDProgramParam receiveParam) {
- LEDProgram byId = getById(receiveParam.getId());
- if (byId == null) {
+ LEDProgram led = getById(pid);
+ if (led == null) {
throw new BusinessException("鏈壘鍒拌鑺傜洰");
}
- LEDProgram led = new LEDProgram();
- led.setId(receiveParam.getId());
- //led.setUserId(SecurityUtils.getClientId());
- led.setPixel(receiveParam.getPixel());
- led.setSize(receiveParam.getSize());
led.setName(receiveParam.getName());
- led.setKind(receiveParam.getKind());
- led.setProgramBase64(receiveParam.getProgramBase64());
+ led.setPreview(receiveParam.getPreviewUrl());
+ led.setWidth(receiveParam.getWidth());
+ led.setHeight(receiveParam.getHeight());
+ if (receiveParam.getPages() == null) {
+ throw new BusinessException("鑺傜洰鍐呭涓㈠け");
+ }
+ led.setPages(JSON.toJSONString(receiveParam.getPages()));
return updateById(led);
}
- public boolean deleteProgram(Long id) {
+ public boolean deleteProgram(List<Long> pids) {
+ List<LEDProgram> ledPrograms = listByIds(pids);
+ if (ledPrograms.isEmpty()) {
+ throw new BusinessException("鏈壘鍒拌鑺傜洰");
+ }
+
+ return removeByIds(pids);
+
+ }
+
+ public LEDProgramParam getByPid(Long id) {
LEDProgram byId = getById(id);
if (byId == null) {
throw new BusinessException("鏈壘鍒拌鑺傜洰");
}
-
- return removeById(id);
-
+ LEDProgramParam param = new LEDProgramParam();
+ param.setId(byId.getId());
+ param.setHeight(byId.getHeight());
+ param.setWidth(byId.getWidth());
+ param.setName(byId.getName());
+ param.setPreviewUrl(byId.getPreview());
+ param.setPages(JSON.parseObject(byId.getPages(), List.class));
+ return param;
}
+ public List<LEDProgram> listProgram(BaseConditionVO baseConditionVO, Integer order, Integer seq, String keyword) {
+ LambdaQueryWrapper<LEDProgram> wrapper = listPrograms();
- public LambdaQueryWrapper<LEDProgram> listProgram() {
- // LambdaQueryWrapper<LEDProgram> wrapper= new LambdaQueryWrapper<>();
- /* if(SecurityUtils.getClientId()!=null){
- return list(Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId, SecurityUtils.getClientId()));
- }else {
- return list(Wrappers.lambdaQuery(LEDProgram.class));
- }*/
- if(SecurityUtils.getClientId()!=null){
- return Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId,SecurityUtils.getClientId());
- }else {
- return Wrappers.lambdaQuery(LEDProgram.class);
+ if (keyword != null && !keyword.isEmpty()) {
+ wrapper.like(LEDProgram::getName, keyword);
+ }
+ //鎺掑簭瀛楁
+ String orderByResult = "id";
+ //姝e簭銆佸�掑彊
+ String orderBySeq = OrderByEnums.ASC.getCode();
+ if (order != null) {
+ switch (order) {
+ case 1:
+ orderByResult = OrderByEnums.LED_N_PROGRAM_CREATE_TIME.getCode();
+ break;
+ default:
+ }
+ }
+ if (seq != null) {
+ switch (seq) {
+ case 1:
+ orderBySeq = OrderByEnums.ASC.getCode();
+ break;
+ case 2:
+ orderBySeq = OrderByEnums.DESC.getCode();
+ break;
+ default:
+ break;
+ }
+ }
+ //鎺掑簭鏂瑰紡
+ String orderBy = orderByResult + " " + orderBySeq;
+
+ if (baseConditionVO != null) {
+ PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize(), orderBy);
+ }
+ return list(wrapper);
+ }
+
+ public List<LEDProgram> listProgramOnBinding(String keyword) {
+ LambdaQueryWrapper<LEDProgram> wrapper = listPrograms();
+
+ if (keyword != null && !keyword.isEmpty()) {
+ wrapper.like(LEDProgram::getName, keyword);
}
-
+ return list(wrapper);
}
- public void NovaTraffic(String ip, int port){
- NovaTraffic novaTraffic = new NovaTraffic("192.168.0.220", 5000);
-
-
-
+ public LambdaQueryWrapper<LEDProgram> listPrograms() {
+ if (SecurityUtils.getClientId() == null) {
+ return Wrappers.lambdaQuery(LEDProgram.class);
+ } else {
+ return Wrappers.lambdaQuery(LEDProgram.class).eq(LEDProgram::getUserId, SecurityUtils.getUserId())
+ .or(w -> {
+ w.eq(LEDProgram::getClientId, SecurityUtils.getClientId());
+ });
+ }
}
-
}
--
Gitblit v1.9.3