Explorar o código

添加定时任务

zhoutg %!s(int64=5) %!d(string=hai) anos
pai
achega
78f192fc33

+ 20 - 1
src/main/java/com/diagbot/facade/BehospitalInfoFacade.java

@@ -49,6 +49,7 @@ import com.diagbot.vo.QcResultAlgQueryVO;
 import com.diagbot.vo.QcResultAlgVO;
 import com.diagbot.vo.QueryVo;
 import com.diagbot.vo.RecordContentVO;
+import com.diagbot.vo.TaskVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -655,7 +656,8 @@ public class BehospitalInfoFacade extends BehospitalInfoServiceImpl {
      * 执行未评分的病历
      */
     public void execute() {
-        List<BehospitalInfo> behospitalInfoList = getNoGrade();
+        TaskVO taskVO = new TaskVO();
+        List<BehospitalInfo> behospitalInfoList = getNoGrade(taskVO);
         for (BehospitalInfo bean : behospitalInfoList) {
             AnalyzeVO analyzeVO = new AnalyzeVO();
             analyzeVO.setIsTask(true);
@@ -682,6 +684,23 @@ public class BehospitalInfoFacade extends BehospitalInfoServiceImpl {
     }
 
 
+    /**
+     * 对出院日期之前3天的未评分的病历进行评分
+     */
+    public void execute2() {
+        TaskVO taskVO = new TaskVO();
+        Date date = DateUtil.addDay(DateUtil.now(), -3);
+        taskVO.setLeaveDate(date);
+        List<BehospitalInfo> behospitalInfoList = getNoGrade(taskVO);
+        for (BehospitalInfo bean : behospitalInfoList) {
+            AnalyzeVO analyzeVO = new AnalyzeVO();
+            analyzeVO.setIsTask(true);
+            analyzeVO.setHospitalId(bean.getHospitalId());
+            analyzeVO.setBehospitalCode(bean.getBehospitalCode());
+            authServiceClient.analyze_rpc(analyzeVO);
+        }
+    }
+
     /**
      * 评分api
      *

+ 2 - 2
src/main/java/com/diagbot/mapper/BehospitalInfoMapper.java

@@ -13,6 +13,7 @@ import com.diagbot.vo.FilterByDeptVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.HPFilterByDeptVO;
 import com.diagbot.vo.HomePageFilterVO;
+import com.diagbot.vo.TaskVO;
 
 import java.util.List;
 
@@ -72,8 +73,7 @@ public interface BehospitalInfoMapper extends BaseMapper<BehospitalInfo> {
      */
     public int getTotleResultNum(FilterVO filterVO);
 
-
-    public List<BehospitalInfo> getNoGrade();
+    public List<BehospitalInfo> getNoGrade(TaskVO taskVO);
 
     IPage<BehospitalInfoDTO> getPageByDept(BehospitalPageVO behospitalPageVO);
 

+ 2 - 1
src/main/java/com/diagbot/service/BehospitalInfoService.java

@@ -13,6 +13,7 @@ import com.diagbot.vo.FilterByDeptVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.HPFilterByDeptVO;
 import com.diagbot.vo.HomePageFilterVO;
+import com.diagbot.vo.TaskVO;
 
 import java.util.List;
 
@@ -73,7 +74,7 @@ public interface BehospitalInfoService extends IService<BehospitalInfo> {
     public int getTotleResultNum(FilterVO filterVO);
 
 
-    public List<BehospitalInfo> getNoGrade();
+    public List<BehospitalInfo> getNoGrade(TaskVO taskVO);
 
     IPage<BehospitalInfoDTO> getPageByDept(BehospitalPageVO behospitalPageVO);
 

+ 3 - 2
src/main/java/com/diagbot/service/impl/BehospitalInfoServiceImpl.java

@@ -15,6 +15,7 @@ import com.diagbot.vo.FilterByDeptVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.HPFilterByDeptVO;
 import com.diagbot.vo.HomePageFilterVO;
+import com.diagbot.vo.TaskVO;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -101,8 +102,8 @@ public class BehospitalInfoServiceImpl extends ServiceImpl<BehospitalInfoMapper,
     }
 
     @Override
-    public List<BehospitalInfo> getNoGrade() {
-        return baseMapper.getNoGrade();
+    public List<BehospitalInfo> getNoGrade(TaskVO taskVO) {
+        return baseMapper.getNoGrade(taskVO);
     }
 
     @Override

+ 72 - 0
src/main/java/com/diagbot/task/TASK_CX.java

@@ -0,0 +1,72 @@
+package com.diagbot.task;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.diagbot.entity.SysTaskCron;
+import com.diagbot.enums.IsDeleteEnum;
+import com.diagbot.facade.BehospitalInfoFacade;
+import com.diagbot.facade.SysTaskCronFacade;
+import com.diagbot.util.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.Trigger;
+import org.springframework.scheduling.TriggerContext;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+import org.springframework.scheduling.support.CronTrigger;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/4/15 17:45
+ */
+@Configuration      //1.主要用于标记配置类,兼备Component的效果。
+@EnableScheduling   // 2.开启定时任务
+@Slf4j
+public class TASK_CX implements SchedulingConfigurer {
+    @Autowired
+    private SysTaskCronFacade sysTaskCronFacade;
+
+    private SysTaskCron task = new SysTaskCron();
+
+    @Autowired
+    private BehospitalInfoFacade behospitalInfoFacade;
+
+    /**
+     * 执行定时任务.
+     */
+    @Override
+    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+        taskRegistrar.addTriggerTask(new Runnable() {
+            @Override
+            public void run() {
+                //1.添加任务内容(Runnable)
+                if (null != task
+                        && task.getIsDeleted().equals(IsDeleteEnum.N.getKey())
+                        && task.getIsUsed().equals(1)) {
+                    log.info("执行动态定时任务: " + LocalDateTime.now().toLocalTime());
+                    behospitalInfoFacade.execute2();
+                }
+            }
+        }, new Trigger() {
+            @Override
+            public Date nextExecutionTime(TriggerContext triggerContext) {
+                //2.1 从数据库获取执行周期
+                task = sysTaskCronFacade.getOne(new QueryWrapper<SysTaskCron>()
+                        .eq("cron_code", "TASK_CX")
+                );
+                String cron = "0/5 * * * * ?";
+                //2.2 合法性校验.
+                if (null != task && StringUtil.isNotBlank(task.getCron())) {
+                    cron = task.getCron();
+                }
+                CronTrigger trigger = new CronTrigger(cron);
+                return trigger.nextExecutionTime(triggerContext);
+            }
+        });
+    }
+}

+ 17 - 0
src/main/java/com/diagbot/vo/TaskVO.java

@@ -0,0 +1,17 @@
+package com.diagbot.vo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/4/14 9:53
+ */
+@Data
+public class TaskVO {
+
+    // 出院时间过滤
+    private Date leaveDate;
+}

+ 3 - 0
src/main/resources/mapper/BehospitalInfoMapper.xml

@@ -376,6 +376,9 @@
             AND a.behospital_code = b.behospital_code
             )
          and a.qc_type_id != 0
+         <if test="leaveDate != null">
+             <![CDATA[ and a.leave_hospital_date < #{leaveDate}]]>
+         </if>
     </select>
 
     <!--质控评分(科室)分页-->