2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-05-26 4e91adbb41c89688fe5b0ef03807cfe748a7d59d
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LEDProgramService.java
@@ -1,5 +1,6 @@
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.sandu.common.execption.BusinessException;
@@ -9,50 +10,46 @@
import com.sandu.ximon.dao.domain.LEDProgram;
import com.sandu.ximon.dao.mapper.LEDProgramMapper;
import lombok.AllArgsConstructor;
import nova.traffic.utils.NovaTraffic;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
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());
        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());
        led.setPages(JSON.toJSONString(receiveParam.getPages()));
        return updateById(led);
    }
@@ -67,29 +64,30 @@
    }
    public LEDProgramParam getByPid(Long id) {
        LEDProgram byId = getById(id);
        if (byId == null) {
            throw new BusinessException("未找到该节目");
        }
        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 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 (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());
                    });
        }
    }
    public void NovaTraffic(String ip, int port){
        NovaTraffic novaTraffic = new NovaTraffic("192.168.0.220", 5000);
    }
}