Ver Fonte

安全指数计算得分/固化异常数据 定时任务代码提交

jingyuanchao há 1 ano atrás
pai
commit
b876771959

+ 9 - 1
project_data/sql/0.0.4/quartz/quartz.sql

@@ -1,3 +1,11 @@
 
 -- 新增定时任务登记簿临时文件删除:凌晨删除下载的固化pdf
-INSERT INTO `sys_job`(`job_id`, `job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (213, '登记簿临时文件删除', 'DEFAULT', 'RegisterBookPdfTask.deletedZipFile()', '59 59 23 * * ?', '1', '1', '0', null,now(), null, NULL);
+delete from sys_job where invoke_target='RegisterBookPdfTask.deletedZipFile()';
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`)VALUES ('登记簿临时文件删除', 'DEFAULT', 'RegisterBookPdfTask.deletedZipFile()', '59 59 23 * * ?', '1', '1', '0', null,now(), null, NULL);
+
+
+delete from sys_job where invoke_target in ('CoreSafetyIndexTask.collectExceptionData()','CoreSafetyIndexTask.calculateSafetyIndex()','CoreSafetyIndexTask.collectExceptionData(\'date\')', 'CoreSafetyIndexTask.calculateSafetyIndex(\'date\')');
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('安全指数异常数据固化', 'DEFAULT', 'CoreSafetyIndexTask.collectExceptionData()', '0 1 1 * * ?', '1', '1', '0', null,now(), null, NULL);
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('安全指数异常数据固化(补偿接口)', 'DEFAULT', 'CoreSafetyIndexTask.collectExceptionData(\'date\')', '0 1 1 * * ?', '1', '1', '1', null,now(), null, NULL);
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('安全指数分数计算', 'DEFAULT', 'CoreSafetyIndexTask.calculateSafetyIndex()', '0 2 1 * * ?', '1', '1', '0', null,now(), null, NULL);
+INSERT INTO `sys_job`(`job_name`, `job_group`, `invoke_target`, `cron_expression`, `misfire_policy`, `concurrent`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES ('安全指数分数计算(补偿接口)', 'DEFAULT', 'CoreSafetyIndexTask.calculateSafetyIndex(\'date\')', '0 2 1 * * ?', '1', '1', '1', null,now(), null, NULL);

+ 16 - 1
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/RemoteSafetyIndexService.java

@@ -1,12 +1,27 @@
 package com.xunmei.system.api;
 
+import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.constant.ServiceNameConstants;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.domain.SysRole;
 import com.xunmei.system.api.factory.RemoteSafetyIndexFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestParam;
 
-@FeignClient(contextId = "remoteSafetyIndexService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteSafetyIndexFallbackFactory.class)
+import java.util.List;
+
+@FeignClient(contextId = "remoteSafetyIndexService", value = ServiceNameConstants.CORE_SERVICE, fallbackFactory = RemoteSafetyIndexFallbackFactory.class)
 public interface RemoteSafetyIndexService {
 
 
 
+    @GetMapping("/safetyExceptionData/data/{date}")
+    AjaxResult collectExceptionData(@PathVariable("date") String date, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+
+    @GetMapping("/safetyExceptionData/calculate/{date}")
+    AjaxResult calculateSafetyIndex(@PathVariable("date") String date, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+
 }

+ 10 - 2
soc-api/soc-api-system/src/main/java/com/xunmei/system/api/factory/RemoteSafetyIndexFallbackFactory.java

@@ -4,6 +4,7 @@ import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.domain.worktime.domain.SysWorkTime;
 import com.xunmei.common.core.domain.worktime.dto.WorkTimeDto;
 import com.xunmei.common.core.utils.Ymd;
+import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.system.api.RemoteSafetyIndexService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -20,10 +21,17 @@ public class RemoteSafetyIndexFallbackFactory implements FallbackFactory<RemoteS
 
     @Override
     public RemoteSafetyIndexService create(Throwable throwable) {
-        log.error("作息服务调用失败:{}", throwable.getMessage());
+        log.error("安全指数服务调用失败:{}", throwable.getMessage());
         return new RemoteSafetyIndexService() {
+            @Override
+            public AjaxResult collectExceptionData(String date, String source) {
+                return null;
+            }
 
-
+            @Override
+            public AjaxResult calculateSafetyIndex(String date, String source) {
+                return null;
+            }
         };
     }
 }

+ 4 - 3
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/ResumptionServiceImpl.java

@@ -349,13 +349,14 @@ public class ResumptionServiceImpl extends ServiceImpl<ResumptionMapper, Resumpt
                 .in(Resumption::getId, dataIdList)
                 .eq(Resumption::getYmdYear, DateUtil.year(request.getDate()))
                 .eq(Resumption::getYmdQuarter, DateUtil.quarter(request.getDate())));
-        List<Long> roleIdList = taskList.stream().map(Resumption::getRoleId).distinct().collect(Collectors.toList());
+        //List<Long> roleIdList = taskList.stream().map(Resumption::getRoleId).distinct().collect(Collectors.toList());
         List<SafeScoreResumptionDataVo> list = new ArrayList<>();
-        Map<Long, String> map = getRoleNames(roleIdList);
+        //Map<Long, String> map = getRoleNames(roleIdList);
         for (Resumption resumption : taskList) {
             SafeScoreResumptionDataVo resumptionDataVo = new SafeScoreResumptionDataVo();
             resumptionDataVo.setId(resumption.getId().toString());
-            resumptionDataVo.setExecPostName(map.get(resumption.getRoleId()));
+            resumptionDataVo.setExecPostName("网点安全员");
+            //resumptionDataVo.setExecPostName(map.get(resumption.getRoleId()));
             resumptionDataVo.setPlanTimeStart(resumption.getPlanStartTime());
             resumptionDataVo.setPlanTimeEnd(resumption.getPlanEndTime());
             resumptionDataVo.setOrgName(resumption.getOrgName());

+ 3 - 4
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/safetyindex/controller/CoreSafetyExceptionDataController.java

@@ -28,7 +28,7 @@ public class CoreSafetyExceptionDataController extends BaseController {
     @ApiOperation(value = "固化异常数据")
     @GetMapping("/data/{date}")
     public AjaxResult collectExceptionData(@PathVariable String date) {
-
+        //date应传递当月时间,业务代码会自行计算的时候上个月的时间
         exceptionDataService.countExceptionData(date);
         return AjaxResult.success();
 
@@ -38,7 +38,7 @@ public class CoreSafetyExceptionDataController extends BaseController {
     @ApiOperation(value = "计算得分")
     @GetMapping("/calculate/{date}")
     public AjaxResult calculateSafetyIndex(@PathVariable String date) {
-
+        //date应传递当月时间,业务代码会自行计算的时候上个月的时间
         exceptionDataService.calculateSafetyIndex(date);
         return AjaxResult.success();
 
@@ -48,10 +48,9 @@ public class CoreSafetyExceptionDataController extends BaseController {
     @RequiresPermissions("core:safetyExceptionData:reCalculate")
     @PostMapping("/reCalculate")
     public AjaxResult reCalculate(@RequestBody CoreSafetyIndexReCalculateDto request) {
-
+        //date应传递当月时间,业务代码会自行计算的时候上个月的时间
         exceptionDataService.reCalculate(request);
         return AjaxResult.success();
 
     }
-
 }

+ 4 - 4
soc-modules/soc-modules-core/src/main/resources/mapper/drill/CoreDrillTaskMapper.xml

@@ -287,17 +287,17 @@
 
     <select id="selectWaitRecTaskList" resultType="com.xunmei.common.core.domain.panel.vo.PanelListVo">
         select distinct t.id as id, title as taskName,t.start_date startTime,t.end_date as endTime,t.status,t.rec_status
-        from core_drill_task t inner join sys_org o on t.org_id=o.id
+        from core_drill_task t
         where t.org_path like concat(#{request.orgPath},'%')
         <include refid="timeRangeSql"/>
         <if test="request.orgType==3">
-            and t.rec_status =0 and o.type=4
+            and t.rec_status =0
         </if>
         <if test="request.orgType==2">
-            and t.rec_status =2 and o.type=3
+            and t.rec_status =2
         </if>
         <if test="request.orgType==1">
-            and t.rec_status =4 and o.type=2
+            and t.rec_status =4
         </if>
         order by  t.drill_end_time desc
     </select>

+ 50 - 0
soc-modules/soc-modules-job/src/main/java/com/xunmei/job/task/CoreSafetyIndexTask.java

@@ -0,0 +1,50 @@
+package com.xunmei.job.task;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.lang.UUID;
+import com.alibaba.fastjson2.JSON;
+import com.xunmei.common.core.constant.CacheConstants;
+import com.xunmei.common.core.constant.Constants;
+import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.system.api.RemoteDrillService;
+import com.xunmei.system.api.RemoteSafetyIndexService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@Slf4j
+@Component("CoreSafetyIndexTask")
+public class CoreSafetyIndexTask {
+
+    @Autowired
+    RemoteSafetyIndexService service;
+
+    public void collectExceptionData() {
+        log.info("安全指数固化异常数据定时任务开始执行(无参)");
+        final Date date = new Date();
+        AjaxResult result = service.collectExceptionData(DateUtil.format(DateUtil.beginOfMonth(date), Constants.DAILY_FORMAT), SecurityConstants.INNER);
+        log.info("安全指数固化异常数据定时任务执行完成(无参),返回参数:{}", JSON.toJSONString(result));
+    }
+
+    public void collectExceptionData(String date) {
+        log.info("安全指数固化异常数据定时任务开始执行(有参)");
+        AjaxResult result = service.collectExceptionData(date, SecurityConstants.INNER);
+        log.info("安全指数固化异常数据定时任务执行完成(有参),返回参数:{}", JSON.toJSONString(result));
+    }
+
+    public void calculateSafetyIndex() {
+        log.info("安全指数计算指标分数定时任务开始执行(无参)");
+        final Date date = new Date();
+        AjaxResult result = service.calculateSafetyIndex(DateUtil.format(DateUtil.beginOfMonth(date), Constants.DAILY_FORMAT), SecurityConstants.INNER);
+        log.info("安全指数计算指标分数定时任务执行完成(无参),返回参数:{}", JSON.toJSONString(result));
+    }
+
+    public void calculateSafetyIndex(String date) {
+        log.info("安全指数计算指标分数定时任务开始执行(有参)");
+        AjaxResult result = service.calculateSafetyIndex(date, SecurityConstants.INNER);
+        log.info("安全指数计算指标分数定时任务执行完成(有参),返回参数:{}", JSON.toJSONString(result));
+    }
+}