Selaa lähdekoodia

添加修正23:00-24:00的次数统计的定时任务

wutt 5 vuotta sitten
vanhempi
commit
469457c0f0

+ 11 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/controller/MouldController.java

@@ -245,5 +245,16 @@ public class MouldController {
         return msg;
     }
 
+    /**
+     * 运行次数更新(23:00-24:00)
+     */
+    @ApiOperation("运行次数更新(23:00-24:00)")
+    @RequestMapping("/updateLastTimeRuntimesTask")
+    @ResponseBody
+    @Scheduled(cron = "0 0 1 * * ?")//定时任务,每天1点触发
+    public HttpRespMsg updateLastTimeRuntimesTask() throws Exception {
+        HttpRespMsg msg = mouldService.updateLastTimeRuntimesTask();
+        return msg;
+    }
 }
 

+ 2 - 0
cloud-model/src/main/java/com/hssx/cloudmodel/service/MouldService.java

@@ -37,4 +37,6 @@ public interface MouldService extends IService<Mould> {
     HttpRespMsg packageLoss();
 
     HttpRespMsg updateRuntimesTask();
+
+    HttpRespMsg updateLastTimeRuntimesTask();
 }

+ 32 - 1
cloud-model/src/main/java/com/hssx/cloudmodel/service/impl/MouldServiceImpl.java

@@ -618,7 +618,8 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
 
     @Override
     public HttpRespMsg updateRuntimesTask() {
-        List<MouldHistoryTime> list = mouldHistoryTimeMapper.selectListByTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
+        Date date = new Date();
+        List<MouldHistoryTime> list = mouldHistoryTimeMapper.selectListByTime(new SimpleDateFormat("yyyy-MM-dd").format(date));
         Map<String, List<MouldHistoryTime>> map = list.stream().collect(Collectors.groupingBy(MouldHistoryTime::getEquipmentNo));
         for (Map.Entry<String, List<MouldHistoryTime>> stringListEntry : map.entrySet()) {
             for (int i = 0; i < 24; i++) {
@@ -648,5 +649,35 @@ public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements
         }
         return new HttpRespMsg();
     }
+
+    @Override
+    public HttpRespMsg updateLastTimeRuntimesTask() {
+        List<MouldHistoryTime> mouldHistoryTimes = mouldHistoryTimeMapper.selectList(new QueryWrapper<MouldHistoryTime>().select("equipment_no","open_time").apply("date_format(open_time,'%H') between '23' and '24'"));
+        if(CollectionUtils.isEmpty(mouldHistoryTimes)){
+            return null;
+        }
+        //获取到按照equipmentNo分组的map
+        Map<String, List<MouldHistoryTime>> equipmentNoList = mouldHistoryTimes.stream().collect(Collectors.groupingBy(MouldHistoryTime::getEquipmentNo));
+        for (Map.Entry<String, List<MouldHistoryTime>> equipmentNoTimeList : equipmentNoList.entrySet()){
+            //再把给个编号的所有数据按照日期进行分组
+            Map<String, List<MouldHistoryTime>> openTimeStringDateList = equipmentNoTimeList.getValue().stream().collect(Collectors.groupingBy(x -> DateTimeFormatter.ofPattern("yyyy-MM-dd").format(x.getOpenTime())));
+            for (Map.Entry<String, List<MouldHistoryTime>> openTimeData : openTimeStringDateList.entrySet()){
+                openTimeData.getKey();
+                MouldCycleRuntime mr = new MouldCycleRuntime();
+                mr.setDateStr(openTimeData.getKey());
+                mr.setEquipmentNo(equipmentNoTimeList.getKey());
+                mr.setTimeSlot("23:00-24:00");
+                MouldCycleRuntime mouldCycleRuntime = mouldCycleRuntimeMapper.selectOne(new QueryWrapper<MouldCycleRuntime>(mr));
+                if(mouldCycleRuntime == null){
+                    mr.setRuntime(openTimeData.getValue().size());
+                    mouldCycleRuntimeMapper.insert(mr);
+                }else{
+                    mouldCycleRuntime.setRuntime(openTimeData.getValue().size());
+                    mouldCycleRuntimeMapper.updateById(mouldCycleRuntime);
+                }
+            }
+        }
+        return null;
+    }
 }
 

+ 1 - 1
cloud-model/src/main/resources/application.properties

@@ -14,7 +14,7 @@ spring.thymeleaf.jackson.date-format=yyyy-MM-dd HH:mm:ss
 # Êý¾ÝÔ´ÅäÖÃ
 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 #spring.datasource.url=jdbc:mysql://118.190.47.230:3306/cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-spring.datasource.url=jdbc:mysql://47.100.37.243:7644/cloud_model?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+spring.datasource.url=jdbc:mysql://47.100.37.243:7644/cloud_mould?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=Hssx2018.!
 #spring.datasource.druid.test-on-borrow=true

+ 22 - 8
cloud-model/src/test/java/com/hssx/cloudmodel/CloudModelApplicationTests.java

@@ -1,8 +1,11 @@
 package com.hssx.cloudmodel;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.hssx.cloudmodel.entity.CustomCompany;
+import com.hssx.cloudmodel.entity.MouldHistoryTime;
 import com.hssx.cloudmodel.entity.vo.ProjectVO;
 import com.hssx.cloudmodel.entity.vo.UserVO;
+import com.hssx.cloudmodel.mapper.MouldHistoryTimeMapper;
 import com.hssx.cloudmodel.mapper.ProjectMapper;
 import com.hssx.cloudmodel.mapper.ProjectUserMapper;
 import com.hssx.cloudmodel.mapper.UserMapper;
@@ -10,8 +13,10 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 @RunWith(SpringRunner.class)
@@ -23,18 +28,27 @@ public class CloudModelApplicationTests {
     @Resource
     UserMapper userMapper;
     @Resource
+    MouldHistoryTimeMapper mouldHistoryTimeMapper;
+    @Resource
     ProjectMapper  projectMapper;
     @Test
     public void contextLoads() {
+//        List<MouldHistoryTime> mouldHistoryTimes;
+        System.out.println(mouldHistoryTimeMapper.selectList(new QueryWrapper<MouldHistoryTime>().apply("date_format(open_time,'%H') between '23' and '24'")));
+//        mouldHistoryTimes = null;
+//        System.out.println(CollectionUtils.isEmpty(mouldHistoryTimes));
+//        mouldHistoryTimes = new ArrayList<>();
+//        System.out.println(CollectionUtils.isEmpty(mouldHistoryTimes));
+//        System.out.println(mouldHistoryTimeMapper.selectList(new QueryWrapper<MouldHistoryTime>().apply("date_format(open_time,'%H') between '23' and '24'")));
 
-        CustomCompany customCompany = new CustomCompany();
-        UserVO vo = new UserVO();
-        vo.setProjectId(5);
-        vo.setId(165);
-//        vo.setCompanyId(9);
-        vo.setKeyName("111");
-        List<ProjectVO> projectVOS = projectMapper.selectUserPowerList1(vo, 0);
-        System.out.println(projectVOS);
+//        CustomCompany customCompany = new CustomCompany();
+//        UserVO vo = new UserVO();
+//        vo.setProjectId(5);
+//        vo.setId(165);
+////        vo.setCompanyId(9);
+//        vo.setKeyName("111");
+//        List<ProjectVO> projectVOS = projectMapper.selectUserPowerList1(vo, 0);
+//        System.out.println(projectVOS);
 //        customCompany.setCompanyId(10);
 //        customCompany.setProjectId(4);
 //        customCompanyMapper.update(customCompany,new QueryWrapper<CustomCompany>().eq("company_id",10));