2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-04-27 cda9d3a12240ad659efc11603862487d946715b2
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LedScheduleService.java
@@ -12,10 +12,13 @@
import com.sandu.ximon.admin.config.RealtimeServerBean;
import com.sandu.ximon.admin.param.LEDScheduleParam_xixun;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.JsonUtil;
import com.sandu.ximon.admin.utils.LightemitUtils;
import com.sandu.ximon.admin.utils.request.Schedules;
import com.sandu.ximon.admin.utils.request.Task;
import com.sandu.ximon.admin.utils.request.requestbody.GetSchedules;
import com.sandu.ximon.admin.utils.request.requestbody.Task;
import com.sandu.ximon.admin.utils.request.TaskSchedules;
import com.sandu.ximon.admin.vo.LedScheduleVO;
import com.sandu.ximon.dao.domain.LedScheduleEntity;
import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.sandu.ximon.dao.mapper.LedScheduleEntityMapper;
@@ -83,6 +86,12 @@
        String json = JSON.toJSONString(taskSchedules, SerializerFeature.WriteMapNullValue);
//         String json = new Gson().toJson(taskSchedules);
        ledScheduleEntity.setSchedule(json);
        if (SecurityUtils.getClientId() != null) {
            ledScheduleEntity.setUserId(SecurityUtils.getUserId());
            if (clientService.findClientId()) {
                ledScheduleEntity.setClientId(clientService.getClientId());
            }
        }
        return this.save(ledScheduleEntity);
    }
@@ -95,7 +104,12 @@
     */
    public void ledschedulepush(Integer scheduleId, Long[] lightemitIds) {
        LedScheduleEntity ledScheduleEntity = baseMapper.selectById(scheduleId);
//        LedScheduleEntity ledScheduleEntity = baseMapper.selectById(scheduleId);
        LedScheduleEntity ledScheduleEntity = getById(scheduleId);
        if (ledScheduleEntity == null) {
            throw new BusinessException("该定时任务不存在");
        }
//        SendCommand sendCommand = new SendCommand();
//        SendCommand sendCommand = new SendCommand();
//        sendCommand.setTask(ledScheduleEntity.getSchedule());
//        String json = new Gson().toJson(sendCommand);
@@ -136,21 +150,81 @@
    }
    /**
     * 播放计划列表(熙讯)
     *
     * @param baseConditionVO
     * @param keyword
     * @return
     */
    public List listSchedule(BaseConditionVO baseConditionVO, String keyword) {
        LambdaQueryWrapper<LedScheduleEntity> eq = new LambdaQueryWrapper<>();
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        if (SecurityUtils.getClientId() != null && clientService.findClientId()) {
            eq = Wrappers.lambdaQuery(LedScheduleEntity.class).eq(LedScheduleEntity::getUserId, SecurityUtils.getUserId());
        } else if (SecurityUtils.getClientId() != null && !clientService.findClientId()) {
            eq = Wrappers.lambdaQuery(LedScheduleEntity.class).eq(LedScheduleEntity::getClientId, SecurityUtils.getUserId());
        } else {
            eq = Wrappers.lambdaQuery(LedScheduleEntity.class);
        LambdaQueryWrapper<LedScheduleEntity> eq = Wrappers.lambdaQuery(LedScheduleEntity.class);
        //用户类型判断
        if (SecurityUtils.getClientId() != null) {
            eq = eq.eq(LedScheduleEntity::getUserId, SecurityUtils.getUserId()).or(w -> {
                w.eq(LedScheduleEntity::getClientId, SecurityUtils.getUserId());
            });
        }
        if (!keyword.isEmpty()) {
        //模糊查询关键字判断
        if (keyword != null && !keyword.isEmpty()) {
            eq = eq.like(LedScheduleEntity::getName, keyword);
        }
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        return list(eq);
    }
    /**
     * 定时查询
     */
    public LedScheduleVO getledschedules(Long id) {
        PoleLightemitEntity poleLightemitEntity = poleLightemitService.getById(id);
        String result1 = lightemitUtils.getTimeSchedule(poleLightemitEntity.getLightemitControlCode());
        if(result1.indexOf("not open")!=-1){
            LedScheduleVO notOpen = new LedScheduleVO();
            notOpen.setLedName(poleLightemitEntity.getLightemitName());
            notOpen.setScheduleName("设备未开启");
            return notOpen;
        }
        boolean flag = result1.contains("exist");
        if(flag!=true) {
            String result = lightemitUtils.getTimeSchedule(poleLightemitEntity.getLightemitControlCode());
//            if(result !=null){
            GetSchedules getSchedules = new GetSchedules();
            try {
                getSchedules = JsonUtil.convertJsonStringToObject(result, GetSchedules.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            LedScheduleVO ledScheduleVO = new LedScheduleVO();
            ledScheduleVO.setLedName(poleLightemitEntity.getLightemitName());
            if (getSchedules.getTask().getName() != null) {
                ledScheduleVO.setScheduleName(getSchedules.getTask().getName());
                List<Schedules> list = new ArrayList();
                list = getSchedules.getTask().getSchedules();
                for (Schedules schedules : list) {
                    ledScheduleVO.setStartTime(schedules.getStartTime());
                    ledScheduleVO.setEndTime(schedules.getEndTime());
                    ledScheduleVO.setStartDate(schedules.getStartDate());
                    ledScheduleVO.setEndDate(schedules.getEndDate());
                    ledScheduleVO.setWeek(schedules.getWeekFilter());
                }
                ;
            } else {
                ledScheduleVO.setScheduleName("无定时");
            }
            return ledScheduleVO;
        }else {
            LedScheduleVO ledScheduleVO = new LedScheduleVO();
            ledScheduleVO.setLedName(poleLightemitEntity.getLightemitName());
            ledScheduleVO.setScheduleName("设备未开启");
            return ledScheduleVO;
        }
    }
}