diff --git a/psdc-business/src/main/java/com/psdc/mapper/PsdcTimerMapper.java b/psdc-business/src/main/java/com/psdc/mapper/PsdcTimerMapper.java index a22ac1d..20a228d 100644 --- a/psdc-business/src/main/java/com/psdc/mapper/PsdcTimerMapper.java +++ b/psdc-business/src/main/java/com/psdc/mapper/PsdcTimerMapper.java @@ -21,7 +21,7 @@ public interface PsdcTimerMapper{ * @param timerId 主键 * @return 实例对象 */ - PsdcTimer queryById(Integer timerId); + PsdcTimer queryById(@Param("timerId") Integer timerId); /** * 通过ID查询单条数据 @@ -29,7 +29,7 @@ public interface PsdcTimerMapper{ * @param timerId 主键 * @return 实例对象 */ - PsdcTimerVo queryById2(Integer timerId); + PsdcTimerVo queryById2(@Param("timerId") Integer timerId); /** * 分页查询指定行数据 * @@ -71,5 +71,5 @@ public interface PsdcTimerMapper{ * @param timerId 主键 * @return 影响行数 */ - int deleteById(Integer timerId); + int deleteById(@Param("timerId") Integer timerId); } \ No newline at end of file diff --git a/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java b/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java index 1998696..8c99a26 100644 --- a/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java +++ b/psdc-business/src/main/java/com/psdc/service/impl/PsdcControlLogServiceImpl.java @@ -23,6 +23,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService { * @param controlLogId 主键 * @return 实例对象 */ + @Override public PsdcControlLog queryById(Integer controlLogId){ return psdcControlLogMapper.queryById(controlLogId); } @@ -35,6 +36,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService { * @param psdcControlLog 实例对象 * @return 实例对象 */ + @Override public PsdcControlLog insert(PsdcControlLog psdcControlLog){ psdcControlLogMapper.insert(psdcControlLog); return psdcControlLog; @@ -46,6 +48,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService { * @param psdcControlLog 实例对象 * @return 实例对象 */ + @Override public PsdcControlLog update(PsdcControlLog psdcControlLog){ psdcControlLogMapper.update(psdcControlLog); return queryById(psdcControlLog.getControlLogId()); @@ -57,6 +60,7 @@ public class PsdcControlLogServiceImpl implements IPsdcControlLogService { * @param controlLogId 主键 * @return 是否成功 */ + @Override public boolean deleteById(Integer controlLogId){ int total = psdcControlLogMapper.deleteById(controlLogId); return total > 0; diff --git a/psdc-business/src/main/java/com/psdc/service/impl/PsdcTimerServiceImpl.java b/psdc-business/src/main/java/com/psdc/service/impl/PsdcTimerServiceImpl.java index 2f52d20..0233226 100644 --- a/psdc-business/src/main/java/com/psdc/service/impl/PsdcTimerServiceImpl.java +++ b/psdc-business/src/main/java/com/psdc/service/impl/PsdcTimerServiceImpl.java @@ -25,11 +25,14 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; +import java.util.Objects; +import java.util.function.Function; /** * 定时控制任务表;(psdc_timer)表服务实现类 - * @date : 2023-5-10 + * + * @date : 2023-5-10 */ @Service @Slf4j @@ -43,48 +46,51 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService { @Resource private IPsdcDeviceService psdcDeviceService; - - /** - * 通过ID查询单条数据 + + /** + * 通过ID查询单条数据 * * @param timerId 主键 * @return 实例对象 */ - public PsdcTimerVo queryById(Integer timerId){ + @Override + public PsdcTimerVo queryById(Integer timerId) { return psdcTimerMapper.queryById2(timerId); } - - - /** + + /** * 新增数据 * * @param psdcTimer 实例对象 * @return 实例对象 */ - public PsdcTimer insert(PsdcTimer psdcTimer){ + @Override + public PsdcTimer insert(PsdcTimer psdcTimer) { psdcTimerMapper.insert(psdcTimer); return psdcTimer; } - - /** + + /** * 更新数据 * * @param psdcTimer 实例对象 * @return 实例对象 */ - public PsdcTimerVo update(PsdcTimer psdcTimer){ + @Override + public PsdcTimerVo update(PsdcTimer psdcTimer) { psdcTimerMapper.update(psdcTimer); return queryById(psdcTimer.getTimerId()); } - - /** + + /** * 通过主键删除数据 * * @param timerId 主键 * @return 是否成功 */ - public boolean deleteById(Integer timerId){ + @Override + public boolean deleteById(Integer timerId) { int total = psdcTimerMapper.deleteById(timerId); return total > 0; } @@ -92,124 +98,135 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService { @Override public List query(PsdcTimerRequest psdcTimerRequest) { psdcTimerRequest.setUserId(SecurityUtils.getUserId()); - return psdcTimerMapper.queryAllByLimit(psdcTimerRequest); + List psdcTimerVos = psdcTimerMapper.queryAllByLimit(psdcTimerRequest); + for (PsdcTimerVo psdcTimerVo : psdcTimerVos) { + if ("startandstop".equals(psdcTimerVo.getControlKey())) { + if ("1".equals(psdcTimerVo.getControlValue())) { + psdcTimerVo.setControlValue("开启"); + } else { + psdcTimerVo.setControlValue("关闭"); + } + } + } + return psdcTimerVos; } /** * 创建定时任务 + * * @param psdcTimerRunTimeRequest 请求类 * @return int */ @Override @Transactional public Integer addTimer(PsdcTimerRunTimeRequest psdcTimerRunTimeRequest) { - //获取psdcTimerRunTimeRequest中的timeList数组,根据内容拼出cron表达式 + // 获取psdcTimerRunTimeRequest中的timeList数组,根据内容拼出cron表达式 String runDay = psdcTimerRunTimeRequest.getRunday(); String runtime = psdcTimerRunTimeRequest.getRuntime(); - //设置cron表达式 + // 设置cron表达式 String[] cronArr = new String[7]; - //秒,默认为每分钟的0秒 - if (runtime == null || !runtime.contains(":") ){ - throw new ServiceException("设定执行时间错误,创建定时任务失败,设定时间为:"+runtime); + // 秒,默认为每分钟的0秒 + if (runtime == null || !runtime.contains(":")) { + throw new ServiceException("设定执行时间错误,创建定时任务失败,设定时间为:" + runtime); } if (runDay == null || "".equals(runDay)) { - throw new ServiceException("设定日期错误,创建定时任务失败,设定日期为:" + runDay); + throw new ServiceException("设定日期错误,创建定时任务失败,设定日期为:" + runDay); } Integer deviceId = psdcTimerRunTimeRequest.getDeviceId(); PsdcDevice psdcDevice = psdcDeviceService.queryById(deviceId); - if(psdcDevice == null){ + if (psdcDevice == null) { throw new ServiceException("创建定时任务失败,未找到该设备"); } - if (psdcDevice.getIsControl() != 2 ){ + if (psdcDevice.getIsControl() != 2) { throw new ControlException("该设备无法控制,请联系管理员"); } String[] split1 = runtime.split(":"); cronArr[0] = "0"; - //分 + // 分 cronArr[1] = split1[1]; - //时 + // 时 cronArr[2] = split1[0]; /* 接下来拼装日月,或周,只有三种情况 */ - if(runDay.equals("0")){ - //每天的情况 - //日 + if (runDay.equals("0")) { + // 每天的情况 + // 日 cronArr[3] = "*"; - //月 + // 月 cronArr[4] = "*"; - //周 + // 周 cronArr[5] = "?"; } else if (runDay.length() == 10 && (runDay.contains("-"))) { - //设定日期情况,就是一次的情况 + // 设定日期情况,就是一次的情况 String[] split = runDay.split("-"); - //日 + // 日 cronArr[3] = split[2]; - //月 + // 月 cronArr[4] = split[1]; - //周 + // 周 cronArr[5] = "?"; } else if (runDay.contains(",")) { - //设定星期情况 + // 设定星期情况 String[] split = runDay.split("-"); - //日 + // 日 cronArr[3] = "?"; - //月 + // 月 cronArr[4] = "*"; - //周 - cronArr[5] = StringUtils.join(split,","); + // 周 + cronArr[5] = StringUtils.join(split, ","); } else { - throw new ServiceException("设定日期错误,创建定时任务失败,设定日期为:" + runDay); + throw new ServiceException("设定日期错误,创建定时任务失败,设定日期为:" + runDay); } - //年,。暂时不用 + // 年,。暂时不用 // cronArr[6] = String cron = StringUtils.join(cronArr, " "); - log.info("cron表达式:{}",cron); + log.info("cron表达式:{}", cron); try { /* 创建job对象,往quartz中插入执行的任务,拿到jobId */ SysJob job = new SysJob(); - //设备id + 控制键 + 控制值 + 控制日期 + 控制时间 + + // 设备id + 控制键 + 控制值 + 控制日期 + 控制时间 + String jobName = psdcTimerRunTimeRequest.getDeviceId() + "+" + ControlKeyEnum.getControlContext(psdcTimerRunTimeRequest.getControlKey()) + "-" + psdcTimerRunTimeRequest.getControlValue() + "+" + psdcTimerRunTimeRequest.getRunday() + "+" + psdcTimerRunTimeRequest.getRuntime() + "+" + System.currentTimeMillis(); job.setJobName(jobName); - //默认 + // 默认 job.setJobGroup("psdc"); String controlKey = psdcTimerRunTimeRequest.getControlKey(); String jobClassName = ""; - //判断控制指令 - if (controlKey.equals( "startandstop")){ - //控制启停 + // 判断控制指令 + if (controlKey.equals("startandstop")) { + // 控制启停 log.info("控制设备启停"); - jobClassName = String.format("psdcDeviceServiceImpl.controlDeviceStartAndStop(%d,%d,'%s',%d))",psdcTimerRunTimeRequest.getDeviceId(),Integer.valueOf(psdcTimerRunTimeRequest.getControlValue()),SecurityUtils.getUsername(),2); - } else if (controlKey.equals( "intemp") || controlKey.equals( "outtemp") || controlKey.equals( "temp") ) { - //控制温度 - jobClassName = String.format("psdcDeviceServiceImpl.setTemperature(%d,'%s','%s','%s',%d))",psdcTimerRunTimeRequest.getDeviceId(),controlKey,psdcTimerRunTimeRequest.getControlValue(),SecurityUtils.getUsername(),2); + jobClassName = String.format("psdcDeviceServiceImpl.controlDeviceStartAndStop(%d,%d,'%s',%d))", psdcTimerRunTimeRequest.getDeviceId(), Integer.valueOf(psdcTimerRunTimeRequest.getControlValue()), SecurityUtils.getUsername(), 2); + } else if (controlKey.equals("intemp") || controlKey.equals("outtemp") || controlKey.equals("temp")) { + // 控制温度 + jobClassName = String.format("psdcDeviceServiceImpl.setTemperature(%d,'%s','%s','%s',%d))", psdcTimerRunTimeRequest.getDeviceId(), controlKey, psdcTimerRunTimeRequest.getControlValue(), SecurityUtils.getUsername(), 2); } job.setInvokeTarget(jobClassName); - //cron表达式 + // cron表达式 job.setCronExpression(cron); - //执行错误放弃执行 + // 执行错误放弃执行 job.setMisfirePolicy("3"); - //是否并发,不并发 + // 是否并发,不并发 job.setConcurrent("1"); job.setCreateBy(SecurityUtils.getUsername()); int i = jobService.insertJob(job); SysJob job1 = null; - if( i > 0){ + if (i > 0) { job1 = jobService.selectJobByName(jobName); - } else { + } else { throw new ServiceException("创建定时任务失败,请联系管理员"); } - //将创建的任务插入psdcTimer表 + // 将创建的任务插入psdcTimer表 PsdcTimer psdcTimer = new PsdcTimer(); - BeanUtils.copyProperties(psdcTimerRunTimeRequest,psdcTimer); + BeanUtils.copyProperties(psdcTimerRunTimeRequest, psdcTimer); psdcTimer.setUserId(SecurityUtils.getUserId().intValue()); - psdcTimer.setControlContext( ControlKeyEnum.getControlContext(psdcTimerRunTimeRequest.getControlKey())); + psdcTimer.setControlContext(ControlKeyEnum.getControlContext(psdcTimerRunTimeRequest.getControlKey())); psdcTimer.setCronText(cron); psdcTimer.setJobId(job1.getJobId().intValue()); psdcTimer.setTimerStatus(Integer.valueOf(job1.getStatus())); @@ -222,21 +239,20 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService { } - } @Override @Transactional public int updateStatus(Integer timerId, Integer status) throws SchedulerException { - //获取jobId + // 获取jobId PsdcTimer psdcTimer = psdcTimerMapper.queryById(timerId); - //修改quartz状态 + // 修改quartz状态 SysJob job = new SysJob(); job.setStatus(status.toString()); job.setJobId(psdcTimer.getJobId().longValue()); job.setJobGroup("psdc"); int i = jobService.changeStatus(job); - if (i > 0){ + if (i > 0) { return psdcTimerMapper.updateStatus(timerId, status); } else { throw new ServiceException("修改定时任务状态失败"); @@ -246,14 +262,14 @@ public class PsdcTimerServiceImpl implements IPsdcTimerService { @Override @Transactional public Integer delete(Integer timerId) throws SchedulerException { - //获取jobId + // 获取jobId PsdcTimer psdcTimer = psdcTimerMapper.queryById(timerId); - //删除quartz任务 + // 删除quartz任务 SysJob job = new SysJob(); job.setJobId(psdcTimer.getJobId().longValue()); job.setJobGroup("psdc"); int i = jobService.deleteJob(job); - if (i > 0){ + if (i > 0) { return psdcTimerMapper.deleteById(timerId); } else { throw new ServiceException("删除定时任务失败"); diff --git a/psdc-business/src/main/resources/mapper/business/PsdcTimerMapper.xml b/psdc-business/src/main/resources/mapper/business/PsdcTimerMapper.xml index 0473492..8715af1 100644 --- a/psdc-business/src/main/resources/mapper/business/PsdcTimerMapper.xml +++ b/psdc-business/src/main/resources/mapper/business/PsdcTimerMapper.xml @@ -54,7 +54,7 @@ - select pt.timer_id,pt.device_id,pd.device_name,pt.user_id,pt.runday,pt.runtime,pt.control_key,pt.control_context,pt.control_value,pt.cron_text,pt.job_id,pt.timer_status,pt.create_by,pt.create_time,pt.update_by,pt.update_time from psdc_timer pt left join psdc_device pd on pt.device_id = pd.device_id diff --git a/psdc-ui/src/views/analyse/nhfx/index.vue b/psdc-ui/src/views/analyse/nhfx/index.vue index 28e335b..d6a1a0b 100644 --- a/psdc-ui/src/views/analyse/nhfx/index.vue +++ b/psdc-ui/src/views/analyse/nhfx/index.vue @@ -15,8 +15,8 @@ 查询
-
- +
+
@@ -49,7 +49,7 @@ @@ -79,6 +79,8 @@ @@ -561,7 +673,9 @@ onBeforeUnmount(() => { .floatRight{ margin-left: 90%; } - +::v-deep .el-dialog{ + background-color: rgba(47,61,138) !important; +} ::v-deep .el-tabs__item{ color: #fff; diff --git a/psdc-ui/src/views/control/timer/index.vue b/psdc-ui/src/views/control/timer/index.vue index 0bfed0b..bf4f0dd 100644 --- a/psdc-ui/src/views/control/timer/index.vue +++ b/psdc-ui/src/views/control/timer/index.vue @@ -55,6 +55,7 @@ +