已修改19个文件
已添加12个文件
已删除1个文件
| | |
| | | /** |
| | | * 宿¶å¨å½ä»¤å¸§ |
| | | */ |
| | | private String order; |
| | | private String framePayload; |
| | | |
| | | /** |
| | | * å建æ¶é´ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.dao.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import java.io.Serializable; |
| | | import java.time.LocalDateTime; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * è·¯ç¯ä»»å¡å®æ¶å¨æ§è¡æ¥å¿è¡¨ |
| | | * @TableName light_task_quartz_log |
| | | */ |
| | | @TableName(value ="light_task_quartz_log") |
| | | @Data |
| | | public class LightTaskQuartzLog implements Serializable { |
| | | /** |
| | | * |
| | | */ |
| | | @TableId(type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** |
| | | * ä»»å¡id |
| | | */ |
| | | private Long taskId; |
| | | |
| | | /** |
| | | * 宿¶å¨id |
| | | */ |
| | | private Long quartzId; |
| | | |
| | | /** |
| | | * ä»»å¡åç§° |
| | | */ |
| | | private String taskName; |
| | | |
| | | /** |
| | | * 宿¶å¨cron |
| | | */ |
| | | private String cronExpression; |
| | | |
| | | /** |
| | | * 帧è´è· |
| | | */ |
| | | private String framePayload; |
| | | |
| | | /** |
| | | * è¯·æ±æ¶é´ |
| | | */ |
| | | private Long time; |
| | | |
| | | /** |
| | | * é误æ¥å¿ |
| | | */ |
| | | private String exceptionDetail; |
| | | |
| | | /** |
| | | * å建æ¶é´ |
| | | */ |
| | | private LocalDateTime createTime; |
| | | |
| | | @TableField(exist = false) |
| | | private static final long serialVersionUID = 1L; |
| | | } |
| | |
| | | |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @Entity com.sandu.ximon.dao.domain.LightTask |
| | | */ |
| | | @Mapper |
| | | public interface LightTaskMapper extends BaseMapper<LightTask> { |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.dao.mapper; |
| | | |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartzLog; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @Entity com.sandu.ximon.dao.domain.LightTaskQuartzLog |
| | | */ |
| | | @Mapper |
| | | public interface LightTaskQuartzLogMapper extends BaseMapper<LightTaskQuartzLog> { |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.sandu.ximon.dao.mapper.LightTaskQuartzLogMapper"> |
| | | |
| | | <resultMap id="BaseResultMap" type="com.sandu.ximon.dao.domain.LightTaskQuartzLog"> |
| | | <id property="id" column="id" jdbcType="BIGINT"/> |
| | | <result property="taskId" column="task_id" jdbcType="BIGINT"/> |
| | | <result property="quartzId" column="quartz_id" jdbcType="BIGINT"/> |
| | | <result property="taskName" column="task_name" jdbcType="VARCHAR"/> |
| | | <result property="cronExpression" column="cron_expression" jdbcType="VARCHAR"/> |
| | | <result property="framePayload" column="frame_payload" jdbcType="VARCHAR"/> |
| | | <result property="time" column="time" jdbcType="BIGINT"/> |
| | | <result property="exceptionDetail" column="exception_detail" jdbcType="VARCHAR"/> |
| | | <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> |
| | | </resultMap> |
| | | |
| | | <sql id="Base_Column_List"> |
| | | id,task_id,quartz_id, |
| | | task_name,cron_expression,frame_payload, |
| | | time,exception_detail,create_time |
| | | </sql> |
| | | </mapper> |
| | |
| | | <result property="quartzName" column="quartz_name" jdbcType="VARCHAR"/> |
| | | <result property="cronExpression" column="cron_expression" jdbcType="VARCHAR"/> |
| | | <result property="pause" column="pause" jdbcType="TINYINT"/> |
| | | <result property="order" column="order" jdbcType="VARCHAR"/> |
| | | <result property="framePayload" column="frame_payload" jdbcType="VARCHAR"/> |
| | | <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> |
| | | <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> |
| | | </resultMap> |
| | | |
| | | <sql id="Base_Column_List"> |
| | | id,task_id,quartz_name, |
| | | cron_expression,pause,order, |
| | | cron_expression,pause,frame_payload, |
| | | create_time,update_time |
| | | </sql> |
| | | </mapper> |
| | |
| | | |
| | | /** |
| | | * @author yadong.zhang (yadong.zhang0415(a)gmail.com) |
| | | * @website https://www.zhyd.me |
| | | * @version 1.0 |
| | | * @website https://www.zhyd.me |
| | | * @date 2018/4/16 16:26 |
| | | * @since 1.0 |
| | | */ |
| | | public enum ResponseStatusEnums { |
| | | /** æä½æå*/ |
| | | /** |
| | | * æä½æå |
| | | */ |
| | | SUCCESS(20000, "success"), |
| | | FAIL(40000, "fail"), |
| | | |
| | | BAD_CREDENTIALS(40001, "ç¨æ·åæå¯ç 䏿£ç¡®"), |
| | | DISABLE_ACCOUNT(40002, "该账å·å·²è¢«ç¦æ¢ä½¿ç¨"), |
| | | /** token ç¸å
³ */ |
| | | TOKEN_INVALID(40011, "token失æ"), |
| | | /** |
| | | * token ç¸å
³ |
| | | */ |
| | | TOKEN_INVALID(40011, "tokenæ æ"), |
| | | TOKEN_EXPIRED(40012, "tokenè¿æ"), |
| | | TOKEN_NONE(40013, "token为空"), |
| | | SINGLE_LOGIN(40014, "该账å·å¨å
¶ä»è®¾å¤ç»å½,è¯·éæ°ç»å½"), |
| | | TENANT_NONE(40015, "ç§æ·id为空"), |
| | | TENANT_ERROR(40016, "ç§æ·å¼åºé"), |
| | | TENANT_EXPIRED(40017, "ç§æ·ä¼åå·²è¿æ"), |
| | | |
| | | FORBIDDEN(40030, "没æç¸å
³æé"), |
| | | |
| | | WECHAT_LOGIN_UNREGISTERED(40041, "è¯¥ä¸æ¹è´¦å·æªæ³¨åï¼è¯·å°æ³¨åçé¢"), |
| | | WECHAT_LOGIN_SET_PASSWORD(40042, "ææºä¸ºé¦æ¬¡ç»å½ï¼è¯·è®¾ç½®ç»å½å¯ç "), |
| | | |
| | | /** æå¡å¨å¼å¸¸ */ |
| | | /** |
| | | * æå¡å¨å¼å¸¸ |
| | | */ |
| | | SERVER_ERROR(50000, "apiæ¥å£åºé"), |
| | | ; |
| | | |
| | |
| | | |
| | | @Override |
| | | protected void executeInternal(JobExecutionContext context) { |
| | | System.out.println("æ§è¡ä»»å¡"); |
| | | System.out.println(Thread.currentThread().toString()); |
| | | } |
| | | } |
| | |
| | | package com.sandu.common.quartz.service; |
| | | |
| | | import com.sandu.common.quartz.dto.QuartzJobDto; |
| | | import org.springframework.scheduling.quartz.QuartzJobBean; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | |
| | | /** |
| | | * å¢å ä¸ä¸ªä»»å¡job |
| | | * @param quartzJobDto 宿¶ä»»å¡å®ä½ç±» |
| | | * |
| | | * @param jobClass å®ç°çä»»å¡ç±» |
| | | * @param jobId ä»»å¡å¯ä¸id |
| | | * @param cron cronè¡¨è¾¾å¼ |
| | | * @param jobData åæ° |
| | | */ |
| | | void addJob(Class<? extends QuartzJobBean> jobClass, QuartzJobDto quartzJobDto); |
| | | void addJob(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData); |
| | | |
| | | /** |
| | | * ä¿®æ¹ä¸ä¸ªä»»å¡job |
| | | * @param quartzJobDto 宿¶ä»»å¡å®ä½ç±» |
| | | * |
| | | * @param jobClass å®ç°çä»»å¡ç±» |
| | | * @param jobId ä»»å¡å¯ä¸id |
| | | * @param cron cronè¡¨è¾¾å¼ |
| | | * @param jobData åæ° |
| | | */ |
| | | void updateJobCron(Class<? extends QuartzJobBean> jobClass,QuartzJobDto quartzJobDto); |
| | | void updateJobCron(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData); |
| | | |
| | | /** |
| | | * å é¤ä¸ä¸ªä»»å¡job |
| | | * @param jobId 宿¶ä»»å¡id |
| | | * |
| | | * @param jobClass å®ç°çä»»å¡ç±» |
| | | * @param jobId 宿¶ä»»å¡id |
| | | */ |
| | | void deleteJob(Class<? extends QuartzJobBean> jobClass,Long jobId); |
| | | void deleteJob(Class<? extends QuartzJobBean> jobClass, Long jobId); |
| | | |
| | | /** |
| | | * æåä¸ä¸ªä»»å¡job |
| | | * @param jobId 宿¶ä»»å¡id |
| | | * |
| | | * @param jobClass å®ç°çä»»å¡ç±» |
| | | * @param jobId 宿¶ä»»å¡id |
| | | */ |
| | | void pauseJob(Class<? extends QuartzJobBean> jobClass,Long jobId); |
| | | void pauseJob(Class<? extends QuartzJobBean> jobClass, Long jobId); |
| | | |
| | | /** |
| | | * æ¢å¤ä¸ä¸ªä»»å¡job |
| | | * @param quartzJobDto 宿¶ä»»å¡å®ä½ç±» |
| | | * |
| | | * @param jobClass å®ç°çä»»å¡ç±» |
| | | * @param jobId ä»»å¡å¯ä¸id |
| | | * @param cron cronè¡¨è¾¾å¼ |
| | | * @param jobData åæ° |
| | | */ |
| | | void resumeJob(Class<? extends QuartzJobBean> jobClass,QuartzJobDto quartzJobDto); |
| | | void resumeJob(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData); |
| | | |
| | | /** |
| | | * ç«å³æ§è¡ä¸ä¸ªä»»å¡job |
| | | * @param quartzJobDto 宿¶ä»»å¡å®ä½ç±» |
| | | * |
| | | * @param jobClass å®ç°çä»»å¡ç±» |
| | | * @param jobId ä»»å¡å¯ä¸id |
| | | * @param cron cronè¡¨è¾¾å¼ |
| | | * @param jobData åæ° |
| | | */ |
| | | void runJobNow(Class<? extends QuartzJobBean> jobClass,QuartzJobDto quartzJobDto); |
| | | void runJobNow(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData); |
| | | } |
| | |
| | | package com.sandu.common.quartz.service; |
| | | |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.quartz.ExecutionJob; |
| | | import com.sandu.common.quartz.dto.QuartzJobDto; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.quartz.*; |
| | | import org.quartz.impl.triggers.CronTriggerImpl; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.quartz.QuartzJobBean; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | private Scheduler scheduler; |
| | | |
| | | @Override |
| | | public void addJob(Class<? extends QuartzJobBean> jobClass, QuartzJobDto quartzJobDto) { |
| | | public void addJob(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData) { |
| | | try { |
| | | String simpleName = jobClass.getSimpleName(); |
| | | JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class) |
| | | .withIdentity(simpleName + quartzJobDto.getId()) |
| | | JobDetail jobDetail = JobBuilder.newJob(jobClass) |
| | | .withIdentity(simpleName + jobId) |
| | | .build(); |
| | | CronTrigger cronTrigger = TriggerBuilder.newTrigger() |
| | | .withIdentity(simpleName + quartzJobDto.getId()) |
| | | .withSchedule(CronScheduleBuilder.cronSchedule(quartzJobDto.getCronExpression())) |
| | | .withIdentity(simpleName + jobId) |
| | | .startNow() |
| | | .withSchedule(CronScheduleBuilder.cronSchedule(cron)) |
| | | .build(); |
| | | cronTrigger.getJobDataMap().put(QuartzJobDto.JOB_KEY, quartzJobDto); |
| | | |
| | | cronTrigger.getJobDataMap().putAll(jobData); |
| | | ((CronTriggerImpl) cronTrigger).setStartTime(new Date()); |
| | | scheduler.scheduleJob(jobDetail, cronTrigger); |
| | | |
| | | log.info("æ·»å 宿¶å¨{}", simpleName + jobId); |
| | | } catch (SchedulerException e) { |
| | | log.error("åå»ºå®æ¶ä»»å¡å¤±è´¥", e); |
| | | throw new BusinessException("åå»ºå®æ¶ä»»å¡å¤±è´¥"); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updateJobCron(Class<? extends QuartzJobBean> jobClass, QuartzJobDto quartzJobDto) { |
| | | public void updateJobCron(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData) { |
| | | try { |
| | | TriggerKey triggerKey = TriggerKey.triggerKey(jobClass.getSimpleName() + quartzJobDto.getId()); |
| | | TriggerKey triggerKey = TriggerKey.triggerKey(jobClass.getSimpleName() + jobId); |
| | | CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); |
| | | if (trigger == null) { |
| | | addJob(jobClass, quartzJobDto); |
| | | addJob(jobClass, jobId, cron, jobData); |
| | | trigger = (CronTrigger) scheduler.getTrigger(triggerKey); |
| | | } |
| | | CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJobDto.getCronExpression()); |
| | | CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron); |
| | | trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); |
| | | trigger.getJobDataMap().put(QuartzJobDto.JOB_KEY, quartzJobDto); |
| | | trigger.getJobDataMap().putAll(jobData); |
| | | |
| | | scheduler.rescheduleJob(triggerKey, trigger); |
| | | } catch (SchedulerException e) { |
| | |
| | | JobKey jobKey = JobKey.jobKey(jobClass.getSimpleName() + jobId); |
| | | scheduler.pauseJob(jobKey); |
| | | scheduler.deleteJob(jobKey); |
| | | log.info("å é¤å®æ¶å¨{}", jobClass.getSimpleName() + jobId); |
| | | } catch (SchedulerException e) { |
| | | log.error("å é¤å®æ¶ä»»å¡å¤±è´¥", e); |
| | | throw new BusinessException("å é¤å®æ¶ä»»å¡å¤±è´¥"); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void resumeJob(Class<? extends QuartzJobBean> jobClass, QuartzJobDto quartzJobDto) { |
| | | public void resumeJob(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData) { |
| | | try { |
| | | TriggerKey triggerKey = TriggerKey.triggerKey(jobClass.getSimpleName() + quartzJobDto.getId()); |
| | | TriggerKey triggerKey = TriggerKey.triggerKey(jobClass.getSimpleName() + jobId); |
| | | CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); |
| | | // 妿ä¸åå¨åå建ä¸ä¸ªå®æ¶ä»»å¡ |
| | | if (trigger == null) { |
| | | addJob(jobClass, quartzJobDto); |
| | | addJob(jobClass, jobId, cron, jobData); |
| | | } |
| | | JobKey jobKey = JobKey.jobKey(jobClass.getSimpleName() + quartzJobDto.getId()); |
| | | JobKey jobKey = JobKey.jobKey(jobClass.getSimpleName() + jobId); |
| | | scheduler.resumeJob(jobKey); |
| | | } catch (Exception e) { |
| | | log.error("æ¢å¤å®æ¶ä»»å¡å¤±è´¥", e); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void runJobNow(Class<? extends QuartzJobBean> jobClass, QuartzJobDto quartzJobDto) { |
| | | public void runJobNow(Class<? extends QuartzJobBean> jobClass, Long jobId, String cron, Map<String, Object> jobData) { |
| | | try { |
| | | TriggerKey triggerKey = TriggerKey.triggerKey(jobClass.getSimpleName() + quartzJobDto.getId()); |
| | | TriggerKey triggerKey = TriggerKey.triggerKey(jobClass.getSimpleName() + jobId); |
| | | CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); |
| | | // 妿ä¸åå¨åå建ä¸ä¸ªå®æ¶ä»»å¡ |
| | | if (trigger == null) { |
| | | addJob(jobClass, quartzJobDto); |
| | | addJob(jobClass, jobId, cron, jobData); |
| | | } |
| | | JobDataMap dataMap = new JobDataMap(); |
| | | dataMap.put(QuartzJobDto.JOB_KEY, quartzJobDto); |
| | | JobKey jobKey = JobKey.jobKey(jobClass.getSimpleName() + quartzJobDto.getId()); |
| | | dataMap.putAll(jobData); |
| | | JobKey jobKey = JobKey.jobKey(jobClass.getSimpleName() + jobId); |
| | | scheduler.triggerJob(jobKey, dataMap); |
| | | } catch (Exception e) { |
| | | log.error("宿¶ä»»å¡æ§è¡å¤±è´¥", e); |
| | |
| | | SecurityProperties properties = SpringContextHolder.getBean(SecurityProperties.class); |
| | | |
| | | if (!StringUtils.hasText(token)) { |
| | | writeResponse(response, ResponseUtil.error(ResponseStatusEnums.TOKEN_NONE.getCode(), ResponseStatusEnums.TOKEN_NONE.getMessage())); |
| | | writeResponse(response, ResponseUtil.error(ResponseStatusEnums.TOKEN_INVALID.getCode(), ResponseStatusEnums.TOKEN_INVALID.getMessage())); |
| | | return; |
| | | } |
| | | |
| | |
| | | active: dev |
| | | # active: "@profileActive@" |
| | | |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.config; |
| | | |
| | | import com.sandu.ximon.admin.service.LightTaskQuartzService; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartz; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.boot.ApplicationArguments; |
| | | import org.springframework.boot.ApplicationRunner; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/16 11:55 |
| | | */ |
| | | @AllArgsConstructor |
| | | @Component |
| | | public class JobRunner implements ApplicationRunner { |
| | | |
| | | private final LightTaskQuartzService lightTaskQuartzService; |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | | System.out.println("--------------------注å
¥è·¯ç¯å®æ¶ä»»å¡---------------------"); |
| | | List<LightTaskQuartz> list = lightTaskQuartzService.list(); |
| | | lightTaskQuartzService.runLightTaskQuartz(list); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.constant; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/16 11:42 |
| | | */ |
| | | public class Constants { |
| | | |
| | | // ç¯å®æ¶å½ä»¤é¿åº¦ |
| | | public final static int LIGHT_TIMER_ORDER_LENGTH = 8; |
| | | } |
| | |
| | | @Slf4j |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("v1/admin") |
| | | @RequestMapping("/v1/admin") |
| | | public class AdminController { |
| | | |
| | | private final SecurityProperties properties; |
| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.param.LightTaskDelParam; |
| | | import com.sandu.ximon.admin.param.LightTaskParam; |
| | | import com.sandu.ximon.admin.service.LightTaskService; |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è·¯ç¯ä»»å¡ç¸å
³æ§å¶ç±» |
| | |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | public ResponseVO<Object> listLightTask(BaseConditionVO conditionVO, @RequestParam(required = false) String keyword) { |
| | | List<LightTask> taskList = lightTaskService.listLightTask(conditionVO.getPageNo(), conditionVO.getPageSize(), keyword); |
| | | return ResponseUtil.successPage(taskList); |
| | | } |
| | | |
| | | @PostMapping("/del") |
| | | public ResponseVO<Object> delLightTask(@RequestBody @Validated LightTaskDelParam param) { |
| | | boolean result = lightTaskService.delLightTask(param.getTaskIdList()); |
| | | if (result) { |
| | | return ResponseUtil.success("å 餿å"); |
| | | } else { |
| | | return ResponseUtil.fail("å é¤å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/update/{taskId}") |
| | | public ResponseVO<Object> updateLightTask(@PathVariable Long taskId, @RequestBody @Validated LightTaskParam param) { |
| | | boolean result = lightTaskService.updateLightTask(taskId,param); |
| | | if (result) { |
| | | return ResponseUtil.success("ç¼è¾æå"); |
| | | } else { |
| | | return ResponseUtil.fail("ç¼è¾å¤±è´¥"); |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.manager.iot.frame.inner.request; |
| | | |
| | | import cn.hutool.core.util.HexUtil; |
| | | import com.sandu.ximon.admin.dto.SingleLightOrderDto; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.IRequestInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5LightDataEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.MQTTConnectTypeEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC32Utils; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.SupplementUtils; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/6 14:46 |
| | | * A5->01->23 |
| | | * 宿¶æ§ç¯ |
| | | * 0x00ï¼å
³ç¯ |
| | | * å
¶å®ï¼å¼ç¯&亮度å¼" |
| | | */ |
| | | public class A5LightTimerReqInnerFrame implements IRequestInnerFrame { |
| | | |
| | | private final String payload; |
| | | private final String functionCode = A5LightDataEnum.LightTimer.getCode(); |
| | | private final String payloadLength; |
| | | |
| | | /** |
| | | * @param framePayload å¤ä¸ªè·¯ç¯å®æ¶æä»¤ï¼ |
| | | */ |
| | | public A5LightTimerReqInnerFrame(String framePayload) { |
| | | String destinationAddress = "FFFF"; |
| | | payload = destinationAddress + framePayload; |
| | | this.payloadLength = SupplementUtils.suppleZero(Integer.toHexString((payload.length() / 2)).toUpperCase(), 4); |
| | | } |
| | | |
| | | @Override |
| | | public String getEncodeFrame() { |
| | | String frame = functionCode + payloadLength + payload; |
| | | return MQTTConnectTypeEnum.SYNCHRONIZATION.getCode() + frame.toUpperCase() + CRC32Utils.getCRC32(frame.toUpperCase()); |
| | | } |
| | | |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.manager.iot.frame.inner.response; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.BaseResponseInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.CRC32Utils; |
| | | import lombok.Data; |
| | | import lombok.ToString; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/6 14:46 |
| | | * A5-81-23ç¯å®æ¶ä»»å¡ åºç |
| | | */ |
| | | @Data |
| | | @ToString(callSuper = true) |
| | | public class A5LightTimerRespInnerFrame extends BaseResponseInnerFrame<A5LightTimerRespInnerFrame> { |
| | | |
| | | /** |
| | | * ç®æ å°å 2 |
| | | */ |
| | | private String destinationAddress; |
| | | /** |
| | | * ååºç¶æ 1 |
| | | */ |
| | | private String responseStatus; |
| | | |
| | | @Override |
| | | public A5LightTimerRespInnerFrame transformFrame(String hex) { |
| | | if (StrUtil.isBlank(hex)) { |
| | | return null; |
| | | } |
| | | // MQTTéä¿¡æ¹å¼(1) |
| | | setConnectType(hex.substring(0, 2)); |
| | | // åè½ç (1) |
| | | setFunctionCode(hex.substring(2, 4)); |
| | | // è´è·é¿åº¦(2) |
| | | setPayloadLength(hex.substring(4, 8)); |
| | | |
| | | setDestinationAddress(hex.substring(8, 12)); |
| | | |
| | | setResponseStatus(hex.substring(12, 14)); |
| | | setCrc32(hex.substring(14, 22)); |
| | | // æ ¡éªCRC32 |
| | | String frame = getFunctionCode() + getPayloadLength() + getDestinationAddress() + getResponseStatus(); |
| | | this.setValidate(CRC32Utils.validateFrame(frame, getCrc32())); |
| | | return this; |
| | | } |
| | | } |
| | |
| | | // å
ææ§å¶ |
| | | LightSensorControl("04"), |
| | | |
| | | //è®¾ç½®å®æ¶æ§ç¯åæ° |
| | | LightTimer("23"), |
| | | // æ¸
é¤åç¯ç´¯è®¡æ°æ® |
| | | LightReset("25"); |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.param; |
| | | |
| | | import lombok.Data; |
| | | import org.hibernate.validator.constraints.Length; |
| | | |
| | | import javax.validation.constraints.NotEmpty; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * è·¯ç¯ä»»å¡ |
| | | */ |
| | | @Data |
| | | public class LightTaskDelParam { |
| | | |
| | | @NotEmpty(message = "ä»»å¡idä¸è½ä¸ºç©º") |
| | | private List<Long> taskIdList; |
| | | |
| | | } |
| | |
| | | */ |
| | | @Data |
| | | public class LightTaskParam { |
| | | |
| | | public static final int REQUEST_ORDER_LENGTH = 7; |
| | | /** |
| | | * ä»»å¡åç§° |
| | | */ |
| | |
| | | /** |
| | | * å¼ç¯å½ä»¤ |
| | | */ |
| | | @Length(min = 6, max = 6, message = "å¼ç¯å½ä»¤é¿åº¦é误") |
| | | @Length(min = REQUEST_ORDER_LENGTH, max = REQUEST_ORDER_LENGTH, message = "å¼ç¯å½ä»¤é¿åº¦é误") |
| | | private String openOrder; |
| | | |
| | | /** |
| | | * å
³éç¯å½ä»¤ |
| | | */ |
| | | @Length(min = 6, max = 6, message = "å
³ç¯å½ä»¤é¿åº¦é误") |
| | | @Length(min = REQUEST_ORDER_LENGTH, max = REQUEST_ORDER_LENGTH, message = "å
³ç¯å½ä»¤é¿åº¦é误") |
| | | private String closeOrder; |
| | | /** |
| | | * ç¯æ§å½ä»¤ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.quartz; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.common.util.ThrowableUtil; |
| | | import com.sandu.ximon.admin.service.*; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartz; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartzLog; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | import org.springframework.scheduling.quartz.QuartzJobBean; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/15 10:28 |
| | | * è®¾ç½®å®æ¶æ§ç¯ç宿¶ä»»å¡ |
| | | */ |
| | | public class LightTimerJob extends QuartzJobBean { |
| | | |
| | | @Override |
| | | protected void executeInternal(JobExecutionContext context) throws JobExecutionException { |
| | | System.out.println("æ§è¡ä»»å¡" + Thread.currentThread().toString()); |
| | | long quartzId = context.getMergedJobDataMap().getLong("quartzId"); |
| | | String taskName = context.getMergedJobDataMap().getString("taskName"); |
| | | long taskId = context.getMergedJobDataMap().getLong("taskId"); |
| | | String cron = context.getMergedJobDataMap().getString("cron"); |
| | | |
| | | LightTaskQuartzLog log = new LightTaskQuartzLog(); |
| | | log.setCronExpression(cron); |
| | | log.setTaskId(taskId); |
| | | log.setTaskName(taskName); |
| | | log.setQuartzId(quartzId); |
| | | |
| | | PoleService poleService = SpringContextHolder.getBean(PoleService.class); |
| | | LightTaskPoleRelationService lightTaskPoleRelationService = SpringContextHolder.getBean(LightTaskPoleRelationService.class); |
| | | LightTaskQuartzService lightTaskQuartzService = SpringContextHolder.getBean(LightTaskQuartzService.class); |
| | | LightTaskService lightTaskService = SpringContextHolder.getBean(LightTaskService.class); |
| | | LightTaskQuartzLogService lightTaskQuartzLogService = SpringContextHolder.getBean(LightTaskQuartzLogService.class); |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | try { |
| | | // ä»»å¡ç»å®çç¯æ |
| | | List<Long> poleIdList = lightTaskPoleRelationService.listPoleIdByTaskId(taskId); |
| | | // ç¯æç设å¤ç |
| | | List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList); |
| | | |
| | | if (CollectionUtil.isNotEmpty(deviceCodeList)) { |
| | | LightTaskQuartz lightTaskQuartz = lightTaskQuartzService.getById(quartzId); |
| | | if (lightTaskQuartz != null) { |
| | | for (String deviceCode : deviceCodeList) { |
| | | // 宿¶ç»æ¯ä¸ªè®¾å¤ååéç¯æ§è¯·æ± |
| | | lightTaskService.sendTimeRRpc(lightTaskQuartz.getFramePayload(), deviceCode); |
| | | } |
| | | log.setFramePayload(lightTaskQuartz.getFramePayload()); |
| | | } |
| | | } |
| | | long times = System.currentTimeMillis() - startTime; |
| | | log.setTime(times); |
| | | } catch (Exception e) { |
| | | log.setExceptionDetail(ThrowableUtil.getStackTrace(e)); |
| | | long times = System.currentTimeMillis() - startTime; |
| | | log.setTime(times); |
| | | } finally { |
| | | lightTaskQuartzLogService.save(log); |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.dao.domain.LightTaskPoleRelation; |
| | | import com.sandu.ximon.dao.mapper.LightTaskPoleRelationMapper; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/16 14:15 |
| | | */ |
| | | @Service |
| | | public class LightTaskPoleRelationService extends BaseServiceImpl<LightTaskPoleRelationMapper, LightTaskPoleRelation> { |
| | | |
| | | /** |
| | | * æ¹éä¿åä»»å¡åç¯æçå
³ç³» |
| | | * |
| | | * @param taskId ä»»å¡id |
| | | * @param poleIdList ç¯æid |
| | | * @return è¿åæ¯å¦æå |
| | | */ |
| | | public boolean updateLightTaskPoleRelation(Long taskId, List<Long> poleIdList) { |
| | | remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, taskId)); |
| | | if (CollectionUtil.isEmpty(poleIdList)) { |
| | | return true; |
| | | } |
| | | List<LightTaskPoleRelation> batchSave = new ArrayList<>(); |
| | | for (Long poleId : poleIdList) { |
| | | LightTaskPoleRelation lightTaskPoleRelation = new LightTaskPoleRelation(); |
| | | lightTaskPoleRelation.setPoleId(poleId); |
| | | lightTaskPoleRelation.setTaskId(taskId); |
| | | batchSave.add(lightTaskPoleRelation); |
| | | } |
| | | |
| | | return saveBatch(batchSave); |
| | | } |
| | | |
| | | public List<Long> listPoleIdByTaskId(Long taskId) { |
| | | if (taskId == null) { |
| | | return null; |
| | | } |
| | | return list(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, taskId).select(LightTaskPoleRelation::getPoleId)) |
| | | .stream().map(LightTaskPoleRelation::getPoleId).collect(Collectors.toList()); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartzLog; |
| | | import com.sandu.ximon.dao.mapper.LightTaskQuartzLogMapper; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/16 15:12 |
| | | */ |
| | | @Service |
| | | public class LightTaskQuartzLogService extends BaseServiceImpl<LightTaskQuartzLogMapper,LightTaskQuartzLog> { |
| | | } |
| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.HexUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.quartz.ExecutionJob; |
| | | import com.sandu.common.quartz.service.QuartzService; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.constant.Constants; |
| | | import com.sandu.ximon.admin.dto.SingleLightOrderDto; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.SupplementUtils; |
| | | import com.sandu.ximon.admin.param.LightTaskParam; |
| | | import com.sandu.ximon.admin.quartz.LightTimerJob; |
| | | import com.sandu.ximon.admin.utils.TaskOrderUtil; |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartz; |
| | | import com.sandu.ximon.dao.mapper.LightTaskQuartzMapper; |
| | | import org.quartz.CronScheduleBuilder; |
| | | import org.quartz.DateBuilder; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | | * @date 2021/12/15 17:46 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class LightTaskQuartzService extends BaseServiceImpl<LightTaskQuartzMapper, LightTaskQuartz> { |
| | | |
| | | @Resource |
| | | private QuartzService quartzService; |
| | | |
| | | /** |
| | | * æ·»å 宿¶å¨ä»»å¡ |
| | | * |
| | | * @param lightTask è·¯ç¯ä»»å¡å®ä½ç±»ï¼ä¸ä¸ªè·¯ç¯ä»»å¡æå¤ä¸ªå®æ¶å¨ä»»å¡ |
| | | */ |
| | | public boolean addLightTaskQuartz(LightTask lightTask) { |
| | | public List<LightTaskQuartz> addLightTaskQuartz(LightTask lightTask) { |
| | | List<LightTaskQuartz> list = buildLightTaskQuartzList(lightTask); |
| | | |
| | | boolean saveBatch = saveBatch(list); |
| | | if (!saveBatch) { |
| | | throw new BusinessException("ä¿å宿¶ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | runLightTaskQuartz(list); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è·¯ç¯ä»»å¡ä¿¡æ¯çæè·¯ç¯å®æ¶å¨å表 |
| | | * @param lightTask è·¯ç¯ä»»å¡ä¿¡æ¯ |
| | | * @return è·¯ç¯å®æ¶å¨å表 |
| | | */ |
| | | private List<LightTaskQuartz> buildLightTaskQuartzList(LightTask lightTask) { |
| | | List<LightTaskQuartz> list = new ArrayList<>(); |
| | | |
| | | // æ·»å å¼ç¯å®æ¶å¨ |
| | | String openOrder = lightTask.getOpenOrder(); |
| | | SingleLightOrderDto singleLightOrder = TaskOrderUtil.parseLightOrder(openOrder); |
| | | SingleLightOrderDto openLightOrder = TaskOrderUtil.parseLightOrder(lightTask.getOpenOrder()); |
| | | SingleLightOrderDto closeLightOrder = TaskOrderUtil.parseLightOrder(lightTask.getCloseOrder()); |
| | | String[] controlOrderArray = StrUtil.split(lightTask.getControlOrder(), LightTaskParam.REQUEST_ORDER_LENGTH); |
| | | Integer[] weekArrays = TaskOrderUtil.parseLightWeek(lightTask.getWeek()); |
| | | if (singleLightOrder == null) { |
| | | if (openLightOrder == null || closeLightOrder == null) { |
| | | throw new BusinessException("è§£æåç¯å½ä»¤å¤±è´¥"); |
| | | } |
| | | if(ArrayUtil.isEmpty(weekArrays)) { |
| | | if (ArrayUtil.isEmpty(weekArrays)) { |
| | | throw new BusinessException("请设置ææ"); |
| | | } |
| | | String cron = TaskOrderUtil.getHourAndMinuteOnGivenDaysOfWeek(singleLightOrder.getHour(), singleLightOrder.getMinute(), weekArrays); |
| | | |
| | | LightTaskQuartz lightTaskQuartz = new LightTaskQuartz(); |
| | | lightTaskQuartz.setTaskId(lightTask.getTaskId()); |
| | | lightTaskQuartz.setCronExpression(cron); |
| | | StringBuilder sb = new StringBuilder(); |
| | | String weekHex = SupplementUtils.suppleZero(HexUtil.toHex(lightTask.getWeek()), 2); |
| | | |
| | | // æ¼æ¥å¼ç¯å½ä»¤ |
| | | sb.append(weekHex); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getHour()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getMinute()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(openLightOrder.getBrightness()), 2)); |
| | | |
| | | return false; |
| | | // æ¼æ¥å
³ç¯å½ä»¤ |
| | | sb.append(weekHex); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getHour()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getMinute()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(closeLightOrder.getBrightness()), 2)); |
| | | |
| | | // æ°å¢å¼ç¯å®æ¶å¨ |
| | | LightTaskQuartz openLightTaskQuartz = new LightTaskQuartz(); |
| | | openLightTaskQuartz.setTaskId(lightTask.getTaskId()); |
| | | openLightTaskQuartz.setCronExpression(TaskOrderUtil.getHourAndMinuteOnGivenDaysOfWeek(openLightOrder.getHour(), openLightOrder.getMinute(), weekArrays)); |
| | | openLightTaskQuartz.setQuartzName(lightTask.getTaskName()); |
| | | list.add(openLightTaskQuartz); |
| | | |
| | | // æ°å¢å
³ç¯ç¯å®æ¶å¨ |
| | | LightTaskQuartz closeLightTaskQuartz = new LightTaskQuartz(); |
| | | closeLightTaskQuartz.setTaskId(lightTask.getTaskId()); |
| | | closeLightTaskQuartz.setCronExpression(TaskOrderUtil.getHourAndMinuteOnGivenDaysOfWeek(closeLightOrder.getHour(), closeLightOrder.getMinute(), weekArrays)); |
| | | closeLightTaskQuartz.setQuartzName(lightTask.getTaskName()); |
| | | list.add(closeLightTaskQuartz); |
| | | |
| | | // æ¼æ¥äº®åº¦æ§ç¯å½ä»¤ |
| | | for (String controlOrderStr : controlOrderArray) { |
| | | SingleLightOrderDto controlLightOrder = TaskOrderUtil.parseLightOrder(controlOrderStr); |
| | | if (controlLightOrder != null) { |
| | | sb.append(weekHex); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getHour()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getMinute()), 2)); |
| | | sb.append(SupplementUtils.suppleZero(HexUtil.toHex(controlLightOrder.getBrightness()), 2)); |
| | | |
| | | LightTaskQuartz controlLightTaskQuartz = new LightTaskQuartz(); |
| | | controlLightTaskQuartz.setTaskId(lightTask.getTaskId()); |
| | | controlLightTaskQuartz.setCronExpression(TaskOrderUtil.getHourAndMinuteOnGivenDaysOfWeek(controlLightOrder.getHour(), controlLightOrder.getMinute(), weekArrays)); |
| | | controlLightTaskQuartz.setQuartzName(lightTask.getTaskName()); |
| | | list.add(controlLightTaskQuartz); |
| | | } |
| | | } |
| | | |
| | | String lightOrder = sb.toString(); |
| | | |
| | | for (LightTaskQuartz lightTaskQuartz : list) { |
| | | lightTaskQuartz.setFramePayload(lightOrder); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(CronScheduleBuilder.atHourAndMinuteOnGivenDaysOfWeek(0, 1, DateBuilder.SUNDAY).build().getCalendarName()); |
| | | /** |
| | | * æ§è¡å®æ¶å¨ä»»å¡ |
| | | * @param list 宿¶å¨å表 |
| | | */ |
| | | public void runLightTaskQuartz(List<LightTaskQuartz> list){ |
| | | for (LightTaskQuartz taskQuartz : list) { |
| | | Map<String, Object> build = MapUtil.<String, Object>builder() |
| | | .put("taskId", taskQuartz.getTaskId()) |
| | | .put("taskName", taskQuartz.getQuartzName()) |
| | | .put("quartzId", taskQuartz.getId()) |
| | | .put("cron", taskQuartz.getCronExpression()).build(); |
| | | quartzService.addJob(LightTimerJob.class, taskQuartz.getId(), taskQuartz.getCronExpression(), build); |
| | | } |
| | | } |
| | | |
| | | public List<LightTaskQuartz> updateLightTaskQuartz(LightTask lightTask) { |
| | | |
| | | Long taskId = lightTask.getTaskId(); |
| | | // å 餿§ä»»å¡ |
| | | removeLightTaskQuartz(CollectionUtil.toList(taskId)); |
| | | |
| | | List<LightTaskQuartz> list = addLightTaskQuartz(lightTask); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public boolean removeLightTaskQuartz(List<Long> taskIdList) { |
| | | List<Long> delTaskQuartzIdList = list(Wrappers.lambdaQuery(LightTaskQuartz.class).in(LightTaskQuartz::getTaskId, taskIdList).select(LightTaskQuartz::getId)) |
| | | .stream().map(LightTaskQuartz::getId).collect(Collectors.toList()); |
| | | for (Long delTaskQuartzId : delTaskQuartzIdList) { |
| | | quartzService.deleteJob(LightTimerJob.class,delTaskQuartzId); |
| | | } |
| | | |
| | | return removeByIds(delTaskQuartzIdList); |
| | | } |
| | | } |
| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | 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.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.IRequestFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightTimerReqInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.response.A5LightTimerRespInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.dto.WrapResponseCommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.param.LightTaskParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.dao.domain.LightTask; |
| | | import com.sandu.ximon.dao.domain.LightTaskPoleRelation; |
| | | import com.sandu.ximon.dao.domain.LightTaskQuartz; |
| | | import com.sandu.ximon.dao.mapper.LightTaskMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | @AllArgsConstructor |
| | | public class LightTaskService extends BaseServiceImpl<LightTaskMapper, LightTask> { |
| | | |
| | | private final static int ORDER_LENGTH = 6; |
| | | |
| | | private final LightTaskQuartzService lightTaskQuartzService; |
| | | private final PoleService poleService; |
| | | private final LightTaskPoleRelationService lightTaskPoleRelationService; |
| | | |
| | | /** |
| | | * æ°å¢è·¯ç¯ä»»å¡ |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addLightTask(LightTaskParam param) { |
| | | if(StrUtil.length(param.getControlOrder()) % ORDER_LENGTH != 0){ |
| | | if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) { |
| | | throw new BusinessException("ç¯æ§å½ä»¤æ ¼å¼ä¸æ£ç¡®"); |
| | | } |
| | | LightTask lightTask = new LightTask(); |
| | |
| | | lightTask.setOpenOrder(param.getOpenOrder()); |
| | | lightTask.setControlOrder(param.getControlOrder()); |
| | | lightTask.setCreateUser(SecurityUtils.getUsername()); |
| | | if(!save(lightTask)) { |
| | | if (!save(lightTask)) { |
| | | throw new BusinessException("ä¿åè·¯ç¯ä»»å¡å¤±è´¥"); |
| | | } |
| | | boolean result = lightTaskQuartzService.addLightTaskQuartz(lightTask); |
| | | return false; |
| | | List<LightTaskQuartz> list = lightTaskQuartzService.addLightTaskQuartz(lightTask); |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | throw new BusinessException("æ·»å 宿¶ä»»å¡å¤±è´¥"); |
| | | } |
| | | // æ·»å ç»å®ç¯æ |
| | | if (!lightTaskPoleRelationService.updateLightTaskPoleRelation(lightTask.getTaskId(), param.getPoleIdList())) { |
| | | throw new BusinessException("ç»å®ç¯æå¤±è´¥"); |
| | | } |
| | | |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList); |
| | | if (CollectionUtil.isEmpty(deviceCodeList)) { |
| | | throw new BusinessException("æ¾ä¸å°ç¯æmacï¼æ æ³åé宿¶ä»»å¡"); |
| | | } |
| | | // è·å宿¶ç¯æ§å½ä»¤ |
| | | String framePayload = list.get(0).getFramePayload(); |
| | | |
| | | // rrpc åç宿¶å½ä»¤ |
| | | for (String deviceCode : deviceCodeList) { |
| | | sendTimeRRpc(framePayload, deviceCode); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * åéç¯æ§è¯·æ± |
| | | * |
| | | * @param framePayload ç¯æ§åæ° |
| | | * @param deviceCode 设å¤å |
| | | * @return è¿å帧 |
| | | */ |
| | | public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode) { |
| | | IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload)) |
| | | .orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).build(); |
| | | WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance() |
| | | .sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class); |
| | | System.out.println("åéç»æ"); |
| | | A5LightTimerRespInnerFrame responseInnerFrame = responseCommonFrame.getResponseInnerFrame(); |
| | | System.out.println(responseInnerFrame.getResponseStatus()); |
| | | return responseInnerFrame; |
| | | } |
| | | |
| | | public List<LightTask> listLightTask(int pageNo, int pageSize, String keyword) { |
| | | LambdaQueryWrapper<LightTask> wrapper = Wrappers.lambdaQuery(LightTask.class); |
| | | if (StrUtil.isNotBlank(keyword)) { |
| | | wrapper.like(LightTask::getTaskName, keyword); |
| | | } |
| | | Long clientId = SecurityUtils.getClientId(); |
| | | if (clientId != null) { |
| | | wrapper.eq(LightTask::getClientId, clientId); |
| | | } |
| | | |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | return list(wrapper); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateLightTask(Long taskId, LightTaskParam param) { |
| | | if (StrUtil.length(param.getControlOrder()) % LightTaskParam.REQUEST_ORDER_LENGTH != 0) { |
| | | throw new BusinessException("ç¯æ§å½ä»¤æ ¼å¼ä¸æ£ç¡®"); |
| | | } |
| | | LightTask lightTask = getById(taskId); |
| | | if (lightTask == null) { |
| | | throw new BusinessException("æ¾ä¸å°è·¯ç¯ä»»å¡"); |
| | | } |
| | | |
| | | lightTask.setTaskName(param.getTaskName()); |
| | | lightTask.setWeek(param.getWeek()); |
| | | lightTask.setControlOrder(param.getControlOrder()); |
| | | lightTask.setOpenOrder(param.getOpenOrder()); |
| | | lightTask.setCloseOrder(param.getCloseOrder()); |
| | | lightTask.setUpdateTime(LocalDateTime.now()); |
| | | |
| | | if (!updateById(lightTask)) { |
| | | throw new BusinessException("ç¼è¾ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | List<LightTaskQuartz> list = lightTaskQuartzService.updateLightTaskQuartz(lightTask); |
| | | if (CollectionUtil.isEmpty(list)) { |
| | | throw new BusinessException("ç¼è¾å®æ¶ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | // æ·»å ç»å®ç¯æ |
| | | if (!lightTaskPoleRelationService.updateLightTaskPoleRelation(lightTask.getTaskId(), param.getPoleIdList())) { |
| | | throw new BusinessException("ç»å®ç¯æå¤±è´¥"); |
| | | } |
| | | List<Long> poleIdList = param.getPoleIdList(); |
| | | if (CollectionUtil.isNotEmpty(poleIdList)) { |
| | | List<String> deviceCodeList = poleService.listDeviceCodeByIds(poleIdList); |
| | | if (CollectionUtil.isEmpty(deviceCodeList)) { |
| | | throw new BusinessException("æ¾ä¸å°ç¯æmacï¼æ æ³åé宿¶ä»»å¡"); |
| | | } |
| | | // è·å宿¶ç¯æ§å½ä»¤ |
| | | String framePayload = list.get(0).getFramePayload(); |
| | | |
| | | // rrpc åç宿¶å½ä»¤ |
| | | for (String deviceCode : deviceCodeList) { |
| | | sendTimeRRpc(framePayload, deviceCode); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean delLightTask(List<Long> taskIdList) { |
| | | List<LightTask> lightTaskList = listByIds(taskIdList); |
| | | if (CollectionUtil.isEmpty(lightTaskList)) { |
| | | throw new BusinessException("æ¾ä¸å°ä»»å¡ä¿¡æ¯"); |
| | | } |
| | | |
| | | // å é¤ä»»å¡ |
| | | if (!removeByIds(taskIdList)) { |
| | | throw new BusinessException("å é¤ä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | // å é¤ç»å®ç¯æ |
| | | if (!lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList))) { |
| | | throw new BusinessException("å é¤ç»å®ç¯æå¤±è´¥"); |
| | | } |
| | | |
| | | // å é¤å®æ¶å¨ |
| | | if (!lightTaskQuartzService.removeLightTaskQuartz(taskIdList)) { |
| | | throw new BusinessException("å é¤å®æ¶å¨å¤±è´¥"); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | } |
| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.aliyuncs.iot.model.v20180120.BatchGetDeviceStateResponse; |
| | | import com.aliyuncs.iot.model.v20180120.QueryDeviceDetailResponse; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * ç¯æç¸å
³ |
| | |
| | | } |
| | | return setMac; |
| | | } |
| | | |
| | | public List<String> listDeviceCodeByIds(List<Long> poleIdList) { |
| | | if(CollectionUtil.isEmpty(poleIdList)){ |
| | | return null; |
| | | } |
| | | return list(Wrappers.lambdaQuery(Pole.class).in(Pole::getId, poleIdList).select(Pole::getDeviceCode)) |
| | | .stream().map(Pole::getDeviceCode).filter(StrUtil::isNotEmpty).collect(Collectors.toList()); |
| | | } |
| | | } |
| | |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.NumberUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.sandu.ximon.admin.constant.Constants; |
| | | import com.sandu.ximon.admin.dto.SingleLightOrderDto; |
| | | import com.sandu.ximon.dao.enums.WeekEnums; |
| | | import org.quartz.DateBuilder; |
| | |
| | | public class TaskOrderUtil { |
| | | |
| | | public static SingleLightOrderDto parseLightOrder(String lightOrder) { |
| | | if (StrUtil.length(lightOrder) != 6) { |
| | | if (StrUtil.length(lightOrder) != 7) { |
| | | return null; |
| | | } |
| | | SingleLightOrderDto singleLightOrderDto = new SingleLightOrderDto(); |
| | | singleLightOrderDto.setHour(NumberUtil.parseInt(lightOrder.substring(0, 2))); |
| | | singleLightOrderDto.setMinute(NumberUtil.parseInt(lightOrder.substring(2, 4))); |
| | | singleLightOrderDto.setBrightness(NumberUtil.parseInt(lightOrder.substring(4, 6))); |
| | | singleLightOrderDto.setBrightness(NumberUtil.parseInt(lightOrder.substring(4, 7))); |
| | | return singleLightOrderDto; |
| | | } |
| | | |
| | |
| | | storage: local |
| | | common: |
| | | urlPrefix: http://localhost:8080/file/ |
| | | quartz: |
| | | enable: true |
| | | |
| | | |
| | |
| | | package com.sandu.ximon.admin; |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.sandu.ximon.admin.service.PoleService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.quartz.*; |
| | |
| | | |
| | | @Test |
| | | void contextLoads() { |
| | | System.out.println(passwordEncoder.encode("666666")); |
| | | //ae8b5aa26a3ae31612eec1d1f6ffbce9 |
| | | String encode = SecureUtil.md5("66666"); |
| | | String encode2 = passwordEncoder.encode(encode); |
| | | System.out.println(encode); |
| | | System.out.println(encode2); |
| | | } |
| | | |
| | | @Test |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.sandu.ximon.admin; |
| | | |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import com.sandu.common.quartz.service.QuartzServiceImpl; |
| | | import com.sandu.ximon.admin.param.LightTaskParam; |
| | | import com.sandu.ximon.admin.service.LightTaskService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @SpringBootTest |
| | | @Slf4j |
| | | class QuartzTests { |
| | | |
| | | @Resource |
| | | private QuartzServiceImpl quartzService; |
| | | @Resource |
| | | private LightTaskService lightTaskService; |
| | | |
| | | @Test |
| | | void addLightTask() { |
| | | LightTaskParam lightTaskParam = new LightTaskParam(); |
| | | lightTaskParam.setTaskName("æ¥å¸¸ä»»å¡"); |
| | | lightTaskParam.setPoleIdList(ListUtil.toList(1L)); |
| | | lightTaskParam.setWeek(126); |
| | | lightTaskParam.setOpenOrder("1630100"); |
| | | lightTaskParam.setCloseOrder("0600000"); |
| | | lightTaskParam.setControlOrder("00000500300020"); |
| | | System.out.println(lightTaskService.addLightTask(lightTaskParam)); |
| | | } |
| | | |
| | | |
| | | } |