Explorar o código

新增定时任务_更新试车参数设置预估结束日期

wangxuan hai 9 meses
pai
achega
a98a5b5b75

+ 6 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxCommissionCheckParameterSetDetalDao.java

@@ -28,4 +28,10 @@ public interface ZhcxCommissionCheckParameterSetDetalDao extends BaseMapper<Zhcx
     String selectNotholidaydetail();
 
     List<ZhcxCommissionCheckParameterSetDetalDo> getAllByCheckidOrId(@Param("masterId") String masterId);
+
+    /**
+     * 获取全部的试车检查主表id
+     * @return
+     */
+    List<String> getAllChecks();
 }

+ 5 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxCommissionCheckParameterSetDetalService.java

@@ -20,4 +20,9 @@ public interface ZhcxCommissionCheckParameterSetDetalService extends IService<Zh
      * @return
      */
     R computeCheckParameterSetDetalEstimatedenddate(String masterId);
+
+    /**
+     * 定时任务更新试车检查参数设置子表预估试车结束日期
+     */
+    void scheduledComputeEstimatedenddate();
 }

+ 33 - 21
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxCommissionCheckParameterSetDetalServiceImpl.java

@@ -32,26 +32,26 @@ public class ZhcxCommissionCheckParameterSetDetalServiceImpl extends ServiceImpl
 
     @Override
     public R computeCheckParameterSetDetalEstimatedenddate(String masterId) {
-        if(StringUtils.isEmpty(masterId)){
+        if (StringUtils.isEmpty(masterId)) {
             return R.error("试车主表ID不能为空");
         }
         List<ZhcxCommissionCheckParameterSetDetalDo> list = baseMapper.getAllByCheckidOrId(masterId);
-        if (list.size() != 1){
+        if (list.size() != 1) {
             return R.ok("试车参数数据异常");
         }
         ZhcxCommissionCheckParameterSetDetalDo parameterSetDetalDo = list.get(0);
         // 前端已经计算了 填入开始时间
-        if(Objects.isNull(parameterSetDetalDo.getBegindate())){
+        if (Objects.isNull(parameterSetDetalDo.getBegindate())) {
             parameterSetDetalDo.setBegindate(parameterSetDetalDo.getRecentlyTime());
         }
         // 剩余天数 = 难度系数*预估剩余天数
-        if(StringUtils.isEmpty(parameterSetDetalDo.getDifficultyfactor())){
+        if (StringUtils.isEmpty(parameterSetDetalDo.getDifficultyfactor())) {
             parameterSetDetalDo.setDifficultyfactor("1");
         }
-        if(StringUtils.isEmpty(parameterSetDetalDo.getDailytime())){
+        if (StringUtils.isEmpty(parameterSetDetalDo.getDailytime())) {
             return R.ok("每天试车时间为空");
         }
-        if(StringUtils.isEmpty(parameterSetDetalDo.getEESIDUALTIME())){
+        if (StringUtils.isEmpty(parameterSetDetalDo.getEESIDUALTIME())) {
             return R.ok("剩余试车时间(min)为空,该试车检查内容已全部完成");
         }
         double eesidualtime = Double.parseDouble(parameterSetDetalDo.getEESIDUALTIME());
@@ -59,7 +59,7 @@ public class ZhcxCommissionCheckParameterSetDetalServiceImpl extends ServiceImpl
         int days = (int) Math.ceil(eesidualtime / (dailytime * 60));
         parameterSetDetalDo.setEstimateddaynum(String.valueOf(days));
         // 计算预估剩余天数
-        if(StringUtils.isEmpty(parameterSetDetalDo.getEstimateddaynum())){
+        if (StringUtils.isEmpty(parameterSetDetalDo.getEstimateddaynum())) {
             return R.ok("预估剩余天数为空");
         }
         int dayNum = 0;
@@ -75,7 +75,7 @@ public class ZhcxCommissionCheckParameterSetDetalServiceImpl extends ServiceImpl
         // 选择的加班日期 (周日,周六,节假日)
         String selectdate = parameterSetDetalDo.getSelectdate();
         // 防止空指针异常
-        if(StringUtils.isEmpty(selectdate)){
+        if (StringUtils.isEmpty(selectdate)) {
             selectdate = "";
         }
         // 计算预估试车结束日期
@@ -89,7 +89,7 @@ public class ZhcxCommissionCheckParameterSetDetalServiceImpl extends ServiceImpl
     }
 
     // 计算实际偏转日期
-    private String computeEstimatedenddate(int dayNum,String selectdate){
+    private String computeEstimatedenddate(int dayNum, String selectdate) {
         // 是否周六上班  (周日,周六,节假日)
         boolean workInSaturDays = selectdate.contains("周六");
         // 是否周日上班
@@ -103,58 +103,58 @@ public class ZhcxCommissionCheckParameterSetDetalServiceImpl extends ServiceImpl
         // 拿到放假的日期
         String selectholidaydetail = baseMapper.selectholidaydetail();
         // 防止空指针异常
-        if(StringUtils.isEmpty(selectholidaydetail)){
+        if (StringUtils.isEmpty(selectholidaydetail)) {
             selectholidaydetail = "";
         }
         // 拿到上班的日期
         String selectNotholidaydetail = baseMapper.selectNotholidaydetail();
         // 防止空指针异常
-        if(StringUtils.isEmpty(selectNotholidaydetail)){
+        if (StringUtils.isEmpty(selectNotholidaydetail)) {
             selectNotholidaydetail = "";
         }
         Date baseDate = new Date();
-        while (actualDayList.size() != dayNum){
+        while (actualDayList.size() != dayNum) {
             // 拿到第一次偏转的日期
             DateTime dateTime = DateUtil.offsetDay(baseDate, actualDayNum);
             String dateString = new SimpleDateFormat("yyyy-MM-dd").format(dateTime);
             // 判断是否为节假日 并且节假日不上班
-            if(selectholidaydetail.contains(dateString) && workInHoliday){
+            if (selectholidaydetail.contains(dateString) && workInHoliday) {
                 actualDayList.add(dateString);
                 actualDayNum++;
                 continue;
-            }else if(selectholidaydetail.contains(dateString) && !workInHoliday){
+            } else if (selectholidaydetail.contains(dateString) && !workInHoliday) {
                 actualDayNum++;
                 continue;
-            } else if(isSATURDAY(dateTime) && workInSaturDays){
+            } else if (isSATURDAY(dateTime) && workInSaturDays) {
                 actualDayList.add(dateString);
                 actualDayNum++;
                 continue;
             }
             // 判断是否为周日 并且周日不上班
-            else if(isSUNDAY(dateTime) && workInSunDays){
+            else if (isSUNDAY(dateTime) && workInSunDays) {
                 actualDayList.add(dateString);
                 actualDayNum++;
                 continue;
             }
             // 判断该天是否因为调休去上班
-            else if(selectNotholidaydetail.contains(dateString)){
+            else if (selectNotholidaydetail.contains(dateString)) {
                 actualDayList.add(dateString);
                 actualDayNum++;
                 continue;
-            } else if(!isSATURDAY(dateTime) && !isSUNDAY(dateTime)){
+            } else if (!isSATURDAY(dateTime) && !isSUNDAY(dateTime)) {
                 actualDayList.add(dateString);
                 actualDayNum++;
                 continue;
             }
             actualDayNum++;
         }
-        if(actualDayList.isEmpty()){
+        if (actualDayList.isEmpty()) {
             // 抛出异常
             throw new CustomException("计算实际偏转日期异常");
         }
-        log.info("实际上要上班的日期为:{}",actualDayList.stream().collect(Collectors.joining(", ")));
+        log.info("实际上要上班的日期为:{}", actualDayList.stream().collect(Collectors.joining(", ")));
         // 返回最后一个日期
-        return  actualDayList.get(actualDayList.size()-1);
+        return actualDayList.get(actualDayList.size() - 1);
     }
 
     // 是否为周六
@@ -162,10 +162,22 @@ public class ZhcxCommissionCheckParameterSetDetalServiceImpl extends ServiceImpl
         final Week week = DateUtil.dayOfWeekEnum(date);
         return Week.SATURDAY == week;
     }
+
     // 是否为周日
     private static boolean isSUNDAY(Date date) {
         final Week week = DateUtil.dayOfWeekEnum(date);
         return Week.SUNDAY == week;
     }
 
+    @Override
+    public void scheduledComputeEstimatedenddate() {
+        // 获取全部的试车检查主表
+        List<String> checks = baseMapper.getAllChecks();
+        log.info("定时任务更新试车检查参数设置子表预估试车结束日期开始");
+        // 执行更新试车参数预估结束日期
+        for (String checkId : checks) {
+            computeCheckParameterSetDetalEstimatedenddate(checkId);
+        }
+        log.info("定时任务更新试车检查参数设置子表预估试车结束日期结束");
+    }
 }

+ 2 - 1
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPMQMServiceImpl.java

@@ -220,7 +220,8 @@ public class ZhcxPMQMServiceImpl implements ZhcxPMQMService {
         Security.setProperty("jdk.tls.client.protocols", "TLSv1.2,TLSv1.1,TLSv1");
         try(Connection connection = DriverManager.getConnection(url,nxdbuser,nxdbpw);
             Statement statement = connection.createStatement()) {
-            String sqlStr = "SELECT TOP (300) * FROM JUV1841 WHERE 下发日期 > '"+maxTime+"'";
+            //String sqlStr = "SELECT TOP (300) * FROM JUV1841 WHERE 下发日期 > '"+maxTime+"'";
+            String sqlStr = "SELECT * FROM JUV1841 WHERE 下发日期 > '"+maxTime+"'";
             log.info("三单连接SQL" + sqlStr);
             try(ResultSet resultSet = statement.executeQuery(sqlStr)) {
                 while (resultSet.next()) {

+ 4 - 0
business-common/src/main/resources/mybatis/business/ZhcxCommissionCheckParameterSetDetalDao.xml

@@ -52,4 +52,8 @@
             )c ON c.PID = x.CHECKID
         WHERE (x.CHECKID = #{masterId} OR x.ID = #{masterId} ) AND x.DELETED = '0'
     </select>
+
+    <select id="getAllChecks" resultType="java.lang.String">
+        SELECT x.ID FROM INCONTROL.ZHCX_COMMISSION_CHECK x WHERE X.DELETED = '0'
+    </select>
 </mapper>

+ 12 - 0
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxCommissionCheckBaseInfoDetailController.java

@@ -64,5 +64,17 @@ public class ZhcxCommissionCheckBaseInfoDetailController {
             return R.error("计算试车检查参数设置子表预估试车结束日期异常");
         }
     }
+
+
+    @PostMapping("scheduledComputeEstimatedenddate")
+    @ApiOperation("定时任务更新试车检查参数设置子表预估试车结束日期")
+    public void scheduledComputeEstimatedenddate(){
+        try {
+            log.info("定时任务更新试车检查参数设置子表预估试车结束日期");
+            checkParameterSetDetalService.scheduledComputeEstimatedenddate();
+        } catch (Exception e) {
+            log.info(String.valueOf(e));
+        }
+    }
 }
 

+ 2 - 2
business-server/src/main/java/com/rongwei/bsserver/controller/ZhcxPMQMController.java

@@ -30,7 +30,7 @@ public class ZhcxPMQMController {
 
     @PostMapping("/gdfnx")
     @ApiOperation("获取NX系统的三单数据")
-    public R getDataFromNX(@RequestBody Map<String,Object> map) {
+    public R getDataFromNX() {
         Map<String,String> map2 = new HashMap<>();
         map2.put("dateStr", "2021-01-01 10:10:10");
         List<Map<String, Object>> list = pmqmService.getPMQMData(map2);
@@ -46,7 +46,7 @@ public class ZhcxPMQMController {
 
 
     @PostMapping("/gnsd")
-    public R getNxSystemData(@RequestBody Map<String,Object> map) {
+    public R getNxSystemData() {
         List<ZhcxPmqManagementSourceDo> lsit = pmqmService.getNxSystemData();
         return R.ok();
     }