| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | 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.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.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.request.Schedules; |
| | | import com.sandu.ximon.admin.utils.request.Task; |
| | | import com.sandu.ximon.admin.utils.request.TaskSchedules; |
| | | import com.sandu.ximon.admin.utils.request.requestbody.GetSchedules; |
| | | import com.sandu.ximon.admin.utils.request.requestbody.Task; |
| | | 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; |
| | |
| | | |
| | | public boolean insert(LEDScheduleParam_xixun ledEntity) { |
| | | LedScheduleEntity ledScheduleEntity = new LedScheduleEntity(); |
| | | BeanUtil.copyProperties(ledEntity,ledScheduleEntity); |
| | | BeanUtil.copyProperties(ledEntity, ledScheduleEntity); |
| | | ledScheduleEntity.setUserId(SecurityUtils.getClientId()); |
| | | Schedules schedules = new Schedules(); |
| | | Task task = new Task(); |
| | | TaskSchedules taskSchedules = new TaskSchedules(); |
| | | if(ledEntity.getStartTime() =="" || ledEntity.getEndTime() == "" || ledEntity.getStartTime() == null || ledEntity.getEndTime() ==null ){ |
| | | if (ledEntity.getStartTime() == "" || ledEntity.getEndTime() == "" || ledEntity.getStartTime() == null || ledEntity.getEndTime() == null) { |
| | | schedules.setTimeType("All"); |
| | | }else { |
| | | } else { |
| | | schedules.setTimeType("Range"); |
| | | schedules.setStartTime(ledEntity.getStartTime()); |
| | | schedules.setEndTime(ledEntity.getEndTime()); |
| | | } |
| | | if(ledEntity.getStartDate() =="" || ledEntity.getEndDate() == "" || ledEntity.getStartDate() == null || ledEntity.getEndDate() ==null ){ |
| | | if (ledEntity.getStartDate() == "" || ledEntity.getEndDate() == "" || ledEntity.getStartDate() == null || ledEntity.getEndDate() == null) { |
| | | schedules.setDateType("All"); |
| | | }else { |
| | | } else { |
| | | schedules.setDateType("Range"); |
| | | schedules.setStartDate(ledEntity.getStartDate()); |
| | | schedules.setEndDate(ledEntity.getEndDate()); |
| | | } |
| | | if(ledEntity.getWeek().length != 0){ |
| | | if (ledEntity.getWeek().length != 0) { |
| | | schedules.setFilterType("Week"); |
| | | schedules.setWeekFilter(ledEntity.getWeek()); |
| | | }else { |
| | | } else { |
| | | schedules.setFilterType("None"); |
| | | } |
| | | List list =new ArrayList(); |
| | | List list = new ArrayList(); |
| | | list.add(schedules); |
| | | task.setSchedules(list); |
| | | task.setCreateDate(ledEntity.getCreateDate()); |
| | |
| | | String json = JSON.toJSONString(taskSchedules, SerializerFeature.WriteMapNullValue); |
| | | // String json = new Gson().toJson(taskSchedules); |
| | | ledScheduleEntity.setSchedule(json); |
| | | return this.save(ledScheduleEntity); |
| | | if (SecurityUtils.getClientId() != null) { |
| | | ledScheduleEntity.setUserId(SecurityUtils.getUserId()); |
| | | if (clientService.findClientId()) { |
| | | ledScheduleEntity.setClientId(clientService.getClientId()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 熙汛定时更改 日志记录开始 |
| | | */ |
| | | String content = "{熙汛定时id:" + ledScheduleEntity.getId() + ",熙汛定时名称:" + ledScheduleEntity.getName() + "熙汛定时内容:" + JSON.toJSONString(ledScheduleEntity.getSchedule()) + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "熙汛定时任务更改", content); |
| | | /** |
| | | * 熙汛定时更改 日志记录结束 |
| | | */ |
| | | return this.save(ledScheduleEntity); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 定时推送 |
| | | * |
| | | * @param scheduleId |
| | | * @param lightemitIds |
| | | */ |
| | | 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); |
| | | Collection<PoleLightemitEntity> poleLightemitEntities = poleLightemitService.listByIds(Arrays.asList(lightemitIds)); |
| | | |
| | | if(poleLightemitEntities != null){ |
| | | for (PoleLightemitEntity entity: poleLightemitEntities) { |
| | | if (poleLightemitEntities != null) { |
| | | for (PoleLightemitEntity entity : poleLightemitEntities) { |
| | | lightemitUtils.post(realtimeServerBean.getCommand() + entity.getLightemitControlCode(), ledScheduleEntity.getSchedule()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 熙汛定时推送 日志记录开始 |
| | | */ |
| | | String message = ""; |
| | | List<String> listCode = new ArrayList<>(); |
| | | |
| | | for (PoleLightemitEntity entity : poleLightemitEntities) { |
| | | |
| | | listCode.add(entity.getLightemitControlCode()); |
| | | message += "[屏幕Code:" + entity.getLightemitControlCode() + "屏幕名称:" + entity.getLightemitName() + "],"; |
| | | } |
| | | String content = "{熙汛定时id:" + ledScheduleEntity.getId() + ",熙汛定时名称:" + ledScheduleEntity.getName() + "熙汛屏幕信息:" + message + " }"; |
| | | StoreOperationRecordsUtils.storeOperationData(listCode, null, "推送熙汛定时任务", content); |
| | | /** |
| | | * 熙汛定时任务推送 日志记录结束 |
| | | */ |
| | | } |
| | | |
| | | public boolean updateSchedule(LEDScheduleParam_xixun paramXixun){ |
| | | if(paramXixun.getId()==null){ |
| | | public boolean updateSchedule(LEDScheduleParam_xixun paramXixun) { |
| | | if (paramXixun.getId() == null) { |
| | | throw new BusinessException("参数错误"); |
| | | } |
| | | LedScheduleEntity byId = getById(paramXixun.getId()); |
| | | if(byId==null){ |
| | | if (byId == null) { |
| | | throw new BusinessException("未找到该定时数据"); |
| | | } |
| | | boolean result=false; |
| | | if( removeById(paramXixun.getId())){ |
| | | result = insert(paramXixun); |
| | | } |
| | | return result; |
| | | boolean result = false; |
| | | if (removeById(paramXixun.getId())) { |
| | | result = insert(paramXixun); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public LedScheduleEntity getSchedule(Integer id){ |
| | | if(id==null){ |
| | | public LedScheduleEntity getSchedule(Integer id) { |
| | | if (id == null) { |
| | | throw new BusinessException("参数错误"); |
| | | } |
| | | LedScheduleEntity byId = getById(id); |
| | | if(byId==null){ |
| | | if (byId == null) { |
| | | throw new BusinessException("未找到该定时数据"); |
| | | } |
| | | //List<Map> schedule = JSON.parseArray(byId.getSchedule(), List.class); |
| | | //List<Map> schedule = JSON.parseArray(byId.getSchedule(), List.class); |
| | | return byId; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 播放计划列表(熙讯) |
| | | * |
| | | * @param baseConditionVO |
| | | * @param keyword |
| | | * @return |
| | | */ |
| | | public List listSchedule(BaseConditionVO baseConditionVO, String keyword) { |
| | | 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 != 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; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |