瀏覽代碼

添加首件处理

guozx 3 年之前
父節點
當前提交
eddc9835fd

+ 106 - 0
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/entry/FirstCalendar.java

@@ -0,0 +1,106 @@
+package com.jihengbel.intelligent.applicationtask.entry;
+
+import java.io.Serializable;
+
+public class FirstCalendar implements Serializable {
+
+    private long id;
+    private long benteler_plan_id;
+    private String start_day;
+    private String end_day;
+    private String two_hundred_submit_time;
+    private int day_validate;
+    private int day_outtime;
+    private int user_id;
+    private int type_flag;
+    private String task_time;
+    private long first_task_id;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getBenteler_plan_id() {
+        return benteler_plan_id;
+    }
+
+    public void setBenteler_plan_id(long benteler_plan_id) {
+        this.benteler_plan_id = benteler_plan_id;
+    }
+
+    public String getStart_day() {
+        return start_day;
+    }
+
+    public void setStart_day(String start_day) {
+        this.start_day = start_day;
+    }
+
+    public String getEnd_day() {
+        return end_day;
+    }
+
+    public void setEnd_day(String end_day) {
+        this.end_day = end_day;
+    }
+
+    public String getTwo_hundred_submit_time() {
+        return two_hundred_submit_time;
+    }
+
+    public void setTwo_hundred_submit_time(String two_hundred_submit_time) {
+        this.two_hundred_submit_time = two_hundred_submit_time;
+    }
+
+    public int getDay_validate() {
+        return day_validate;
+    }
+
+    public void setDay_validate(int day_validate) {
+        this.day_validate = day_validate;
+    }
+
+    public int getDay_outtime() {
+        return day_outtime;
+    }
+
+    public void setDay_outtime(int day_outtime) {
+        this.day_outtime = day_outtime;
+    }
+
+    public int getUser_id() {
+        return user_id;
+    }
+
+    public void setUser_id(int user_id) {
+        this.user_id = user_id;
+    }
+
+    public int getType_flag() {
+        return type_flag;
+    }
+
+    public void setType_flag(int type_flag) {
+        this.type_flag = type_flag;
+    }
+
+    public String getTask_time() {
+        return task_time;
+    }
+
+    public void setTask_time(String task_time) {
+        this.task_time = task_time;
+    }
+
+    public long getFirst_task_id() {
+        return first_task_id;
+    }
+
+    public void setFirst_task_id(long first_task_id) {
+        this.first_task_id = first_task_id;
+    }
+}

+ 47 - 0
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/entry/FirstTask.java

@@ -0,0 +1,47 @@
+package com.jihengbel.intelligent.applicationtask.entry;
+
+import java.io.Serializable;
+
+
+public class FirstTask implements Serializable {
+
+     private long id;
+
+     private long first_article_calendar_id ;
+
+     private int status;
+
+     private String task_time;
+
+     public long getId() {
+          return id;
+     }
+
+     public void setId(long id) {
+          this.id = id;
+     }
+
+     public long getFirst_article_calendar_id() {
+          return first_article_calendar_id;
+     }
+
+     public void setFirst_article_calendar_id(long first_article_calendar_id) {
+          this.first_article_calendar_id = first_article_calendar_id;
+     }
+
+     public int getStatus() {
+          return status;
+     }
+
+     public void setStatus(int status) {
+          this.status = status;
+     }
+
+     public String getTask_time() {
+          return task_time;
+     }
+
+     public void setTask_time(String task_time) {
+          this.task_time = task_time;
+     }
+}

+ 122 - 0
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/init/FirstTaskJob.java

@@ -0,0 +1,122 @@
+package com.jihengbel.intelligent.applicationtask.init;
+
+import com.jihengbel.intelligent.applicationtask.common.CommonUtil;
+import com.jihengbel.intelligent.applicationtask.entry.FirstCalendar;
+import com.jihengbel.intelligent.applicationtask.entry.FirstTask;
+import com.jihengbel.intelligent.applicationtask.entry.OnsiteCalendar;
+import com.jihengbel.intelligent.applicationtask.service.FirstTaskService;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.FutureTask;
+
+/**
+ * 首件任务定时器
+ */
+@DisallowConcurrentExecution
+public class FirstTaskJob implements Job {
+    private static Logger log = LoggerFactory.getLogger(FirstTaskJob.class);
+
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException {
+        ConcurrentMap<String, Object> paramMap = (ConcurrentMap<String, Object>) context.getJobDetail().getJobDataMap().get(QuartzManager.JOB_PARAM_NAME);
+        createTask(paramMap);// 执行任务
+    }
+
+    /**
+     * 创建Task主方法
+     *
+     * @param paramMap
+     */
+    public void createTask(ConcurrentMap<String, Object> paramMap) {
+        Integer result = 0;//没什么意义只是为了不出现整体并行
+        List<FutureTask<Integer>> tasks = new ArrayList<>();
+        tasks.add(getFirstFutureTask(paramMap));
+        tasks.add(get200FutureTask(paramMap));
+        try {
+            for (FutureTask<Integer> t : tasks) {
+                t.get();
+            }//等等所有线程结束
+        } catch (Throwable e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /**
+     * day
+     *
+     * @param paramMap
+     * @return
+     */
+    private FutureTask<Integer> getFirstFutureTask(ConcurrentMap<String, Object> paramMap) {
+        HashMap param = new HashMap();
+        param.put("type_flag", 0);
+        FutureTask<Integer> task = new FutureTask<Integer>(new addTask(paramMap, param));
+        Thread thread = new Thread(task);
+        thread.start();  //开启线程
+        return task;
+    }
+
+    /**
+     * 200
+     *
+     * @param paramMap
+     * @return
+     */
+    private FutureTask<Integer> get200FutureTask(ConcurrentMap<String, Object> paramMap) {
+        HashMap param = new HashMap();
+        param.put("type_flag", 1);
+        FutureTask<Integer> task = new FutureTask<Integer>(new addTask(paramMap, param));
+        Thread thread = new Thread(task);
+        thread.start();  //开启线程
+        return task;
+    }
+
+
+    /**
+     * 生产任务
+     */
+    public class addTask implements Callable<Integer> {
+
+        private ConcurrentMap<String, Object> paramMap;
+        private HashMap paramQuery;
+
+
+        public addTask(ConcurrentMap<String, Object> paramMap, HashMap paramQuery) {
+            this.paramMap = paramMap;
+            this.paramQuery = paramQuery;
+        }
+
+        @Override
+        public Integer call() throws Exception {
+            FirstTaskService firstTaskService = (FirstTaskService) paramMap.get("firstTaskService");
+            String td = CommonUtil.getDateStr(new Date(), "yyyy-MM-dd");
+            List<FirstCalendar> cals = firstTaskService.getCalenderFirstForType(paramQuery);
+            for (FirstCalendar cal : cals) {
+                try {
+                    FirstTask task = new FirstTask();
+                    task.setTask_time(td);
+                    task.setFirst_article_calendar_id(cal.getId());
+                    firstTaskService.insertFirstTask(task);
+                } catch (Throwable e) {
+                    e.getStackTrace();
+                    log.error(e.getStackTrace().toString());
+                }
+
+            }
+            return 0;
+        }
+    }
+
+}

+ 4 - 9
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/init/OnsiteRemindJob.java

@@ -40,9 +40,9 @@ public class OnsiteRemindJob implements Job {
         tasks.add( getDayFutureTask(paramMap,true));
         tasks.add( getWeekFutureTask(paramMap,true));
         tasks.add( getMonthFutureTask(paramMap,true));
-//        tasks.add( getDayFutureTask(paramMap,false));
-//        tasks.add( getWeekFutureTask(paramMap,false));
-//        tasks.add( getMonthFutureTask(paramMap,false));
+        tasks.add( getDayFutureTask(paramMap,false));
+        tasks.add( getWeekFutureTask(paramMap,false));
+        tasks.add( getMonthFutureTask(paramMap,false));
         try{
             for(FutureTask<Integer> t:tasks){
                 t.get();
@@ -52,12 +52,7 @@ public class OnsiteRemindJob implements Job {
         }
 
     }
-//            <if test="remind_task_flag != null">
-//    and  a.remind_task_flag = ${remind_task_flag}
-//        </if>
-//        <if test="remind_nowork_flag">
-//    and  a.remind_nowork_flag = ${remind_nowork_flag}
-//        </if>
+
 
     /**
      * day

+ 37 - 0
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/model/FirstTaskMapper.java

@@ -0,0 +1,37 @@
+package com.jihengbel.intelligent.applicationtask.model;
+
+
+import com.jihengbel.intelligent.applicationtask.entry.FirstCalendar;
+import com.jihengbel.intelligent.applicationtask.entry.FirstTask;
+import com.jihengbel.intelligent.applicationtask.entry.OnsiteCalendar;
+import com.jihengbel.intelligent.applicationtask.entry.OnsiteTask;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+import java.util.Map;
+
+@Mapper
+public interface FirstTaskMapper {
+
+
+
+    /**
+     * 获取对应的规则
+     * @param paarm
+     * @return
+     */
+    public List<FirstCalendar> getCalenderFirstForType(Map<String,Object> param);
+
+
+    /**
+     * 添加当天任务
+     *
+     * @param task
+     * @return
+     */
+    public int insertFirstTask(FirstTask task);
+
+
+
+
+}

+ 27 - 0
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/service/FirstTaskService.java

@@ -0,0 +1,27 @@
+package com.jihengbel.intelligent.applicationtask.service;
+
+import com.jihengbel.intelligent.applicationtask.entry.FirstCalendar;
+import com.jihengbel.intelligent.applicationtask.entry.FirstTask;
+
+import java.util.List;
+import java.util.Map;
+
+public interface FirstTaskService {
+
+    /**
+     * 获取对应的规则
+     * @param paarm
+     * @return
+     */
+    public List<FirstCalendar> getCalenderFirstForType(Map<String,Object> param);
+
+    /**
+     * 添加当天任务
+     *
+     * @param task
+     * @return
+     */
+    public int insertFirstTask(FirstTask task);
+
+
+}

+ 41 - 0
application-task/src/main/java/com/jihengbel/intelligent/applicationtask/service/impl/FirstTaskServiceImp.java

@@ -0,0 +1,41 @@
+package com.jihengbel.intelligent.applicationtask.service.impl;
+
+import com.jihengbel.intelligent.applicationtask.entry.FirstCalendar;
+import com.jihengbel.intelligent.applicationtask.entry.FirstTask;
+import com.jihengbel.intelligent.applicationtask.model.FirstTaskMapper;
+import com.jihengbel.intelligent.applicationtask.service.FirstTaskService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class FirstTaskServiceImp implements FirstTaskService {
+
+    @Autowired
+    FirstTaskMapper mapper;
+
+    /**
+     * 获取对应的规则
+     * @param paarm
+     * @return
+     */
+    public List<FirstCalendar> getCalenderFirstForType(Map<String,Object> param){
+      return  mapper.getCalenderFirstForType(param);
+    }
+
+    /**
+     * 添加当天任务
+     *
+     * @param task
+     * @return
+     */
+    public int insertFirstTask(FirstTask task){
+        return  mapper.insertFirstTask(task);
+    }
+
+
+
+
+}

+ 4 - 0
application-task/src/main/resources/application.properties

@@ -28,3 +28,7 @@ mybatis.config-locations=conf/mybatis-config.xml
 onsite.task.cron=0 0 2 * * ?
 #onsite 工作提醒
 onsite.remind.work.cron=0 */5 * * * ? 
+#每日执行job时间 每日2点用于执行onsite任务的生成
+first.task.cron=0 0 2 * * ?
+#onsite 工作提醒
+first.remind.work.cron=0 */5 * * * ? 

+ 47 - 0
application-task/src/main/resources/mappers/FirstTaskMapper.xml

@@ -0,0 +1,47 @@
+<?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.jihengbel.intelligent.applicationtask.model.FirstTaskMapper" >
+
+
+    <resultMap id="calendarFirst" type="com.jihengbel.intelligent.applicationtask.entry.FirstCalendar">
+        <id column="id" property="id"/>
+        <result column="benteler_plan_id" property="benteler_plan_id"/>
+        <result column="start_day" property="start_day"/>
+        <result column="end_day" property="end_day"/>
+        <result column="day_validate" property="day_validate"/>
+        <result column="day_outtime" property="day_outtime"/>
+        <result column="two_hundred_submit_time" property="two_hundred_submit_time"/>
+        <result column="user_id" property="user_id"/>
+        <result column="type_flag" property="type_flag"/>
+        <result column="task_time" property="task_time"/>
+        <result column="first_task_id" property="first_task_id"/>
+    </resultMap>
+
+
+
+
+
+
+    <select id="getCalenderFirstForType" resultMap="calendarFirst">  <!-- todo  这个还需要状态 -->
+        SELECT b.* FROM  benteler_plan a,first_article_calendar b
+        WHERE a.id=b.benteler_plan_id and a.pause_flag=0 and a.deleted=0 and a.updated_time &lt;= now()
+        and b.type_flag=${type_flag}
+    </select>
+
+    <insert id="insertFirstTask" parameterType="com.jihengbel.intelligent.applicationtask.entry.FirstTask">
+        insert into first_article_task_key(first_article_calendar_id,task_time)
+        values(
+                  ${first_article_calendar_id},#{task_time}
+              );
+        insert into first_article_task(first_article_calendar_id,task_time)
+        values(
+                  ${first_article_calendar_id},#{task_time}
+              );
+    </insert>
+
+
+
+
+
+
+</mapper>