From 6791263bef9e25fce3521ac7632622294b6fb56e Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期六, 12 十月 2024 17:07:46 +0800
Subject: [PATCH] statistic workload test

---
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportSv.java           |   65 ++++++++++++++++-----
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportCtrl.java         |    5 +
 pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/WebListenerConfiguration.java |   50 ++++++++++++++++
 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticWorkloadMapper.java |    2 
 pms-parent/pms-global/src/main/resources/mapper/OthStatisticWorkloadMapper.xml              |    8 +-
 5 files changed, 110 insertions(+), 20 deletions(-)

diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticWorkloadMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticWorkloadMapper.java
index 6ef592b..0cc8409 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticWorkloadMapper.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticWorkloadMapper.java
@@ -1,6 +1,7 @@
 package com.dy.pmsGlobal.daoOth;
 
 import com.dy.pmsGlobal.pojoOth.OthStatisticWorkload;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.time.LocalDate;
@@ -12,6 +13,7 @@
 * @createDate 2024-10-12 11:06:03
 * @Entity com.dy.pmsGlobal.pojoOth.OthStatisticWorkload
 */
+@Mapper
 public interface OthStatisticWorkloadMapper {
 
     int deleteByPrimaryKey(Long id);
diff --git a/pms-parent/pms-global/src/main/resources/mapper/OthStatisticWorkloadMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/OthStatisticWorkloadMapper.xml
index c67ca1f..6e49e54 100644
--- a/pms-parent/pms-global/src/main/resources/mapper/OthStatisticWorkloadMapper.xml
+++ b/pms-parent/pms-global/src/main/resources/mapper/OthStatisticWorkloadMapper.xml
@@ -66,7 +66,7 @@
     </insert>
     <insert id="insertBatch">
         INSERT INTO oth_statistic_workload
-        (statistic_date,user_id
+        (id,statistic_date,user_id
         ,user_name,type,node_content
         ,number)
          WITH  total as (select
@@ -81,12 +81,12 @@
                left join (select pap.id,pap.`name` as plan_name,pp.`name` as pro_name
                from  pr_assembly_plan pap, plt_product pp where pap.pro_id = pp.id) p on t.plan_id = p.id
                left JOIN ba_user u on u.id=t.updated_by)
-        select  DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id, user_name,'璁″垝浠诲姟' AS type, node_content ,sum(number) as number  from total where curr_node IS NOT NULL GROUP BY user_id,user_name,node_content
+        select null AS id, DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id, user_name,'璁″垝浠诲姟' AS type, node_content ,sum(number) as number  from total where curr_node IS NOT NULL GROUP BY user_id,user_name,node_content
         UNION
-        select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date, user_id,  user_name,'涓存椂浠诲姟' AS type, node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no !='' AND device_no IS NOT NULL)
+        select null AS id, DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date, user_id,  user_name,'涓存椂浠诲姟' AS type, node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no !='' AND device_no IS NOT NULL)
         GROUP BY user_id,user_name,node_content
         UNION
-        select DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id , user_name,'涓存椂浠诲姟(鏃犺澶囩爜)' AS type,node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no IS NULL OR device_no ='')
+        select null AS id, DATE_FORMAT(#{startDt}, '%Y-%m-%d') as statistic_date,user_id , user_name,'涓存椂浠诲姟(鏃犺澶囩爜)' AS type,node_content, sum(number) as number  from total where curr_node IS NULL AND (device_no IS NULL OR device_no ='')
         GROUP BY user_id,user_name,node_content;
     </insert>
     <update id="updateByPrimaryKeySelective" parameterType="com.dy.pmsGlobal.pojoOth.OthStatisticWorkload">
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/WebListenerConfiguration.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/WebListenerConfiguration.java
new file mode 100644
index 0000000..ba796dc
--- /dev/null
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/WebListenerConfiguration.java
@@ -0,0 +1,50 @@
+package com.dy.pmsOther.config;
+
+import com.dy.common.webListener.GenerateIdSetSuffixListener;
+import jakarta.servlet.ServletContextListener;
+import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class WebListenerConfiguration {
+
+    /**
+     * 鍚姩椤哄簭
+     */
+    //private static final int order_config = 0 ;
+    private static final int order_idSetSuffix = 1 ;
+
+    /*
+    * 瑙f瀽鍚勭***config.xml閰嶇疆鐨凜onfigListener锛屽綋鍓峴pringboot宸ョ▼鏆傛椂涓嶉噰鐢ㄦ绉嶉厤缃柟寮�
+    *
+    @Bean
+    public ConfigListener getGlConfigListener(){
+        return new ConfigListener() ;
+    }
+    /**
+     * 澶栭儴鎻愪緵Listener
+     * @param listener 澶栭儴鎻愪緵Listener
+     * @return 娉ㄥ唽Bean
+    @Bean
+    public ServletListenerRegistrationBean<? extends ServletContextListener> regConfigListener(ConfigListener listener) {
+        ServletListenerRegistrationBean<ConfigListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>();
+        listenerRegistrationBean.setListener(listener);
+        listenerRegistrationBean.setOrder(order_config);
+        return listenerRegistrationBean;
+    }
+    */
+
+    /**
+     * 鍐呴儴鎻愪緵listener锛岃listener鍦ㄧ郴缁熷惎鍔ㄦ椂锛屾牴鎹厤缃� 璁剧疆ID浜х敓鍣ㄧ殑鍚庣紑
+     * @return 娉ㄥ唽Bean
+     */
+    @Bean
+    public ServletListenerRegistrationBean<? extends ServletContextListener> regIdSuffixListener() {
+        ServletListenerRegistrationBean<GenerateIdSetSuffixListener> listenerRegistrationBean = new ServletListenerRegistrationBean<>();
+        listenerRegistrationBean.setListener(new GenerateIdSetSuffixListener());
+        listenerRegistrationBean.setOrder(order_idSetSuffix);
+        return listenerRegistrationBean;
+    }
+
+}
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportCtrl.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportCtrl.java
index 8ddcc73..5621eda 100644
--- a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportCtrl.java
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportCtrl.java
@@ -54,4 +54,9 @@
         List<JSONObject> list = sv.queryPlanList();
         return BaseResponseUtils.buildSuccess(list);
     }
+    @GetMapping(path="test")
+    public BaseResponse test(){
+         sv.test();
+        return BaseResponseUtils.buildSuccess();
+    }
 }
\ No newline at end of file
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportSv.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportSv.java
index 1150855..7fd3d85 100644
--- a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportSv.java
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportSv.java
@@ -4,6 +4,8 @@
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.dy.common.springUtil.SpringContextUtil;
+import com.dy.pmsGlobal.daoOth.OthStatisticWorkloadMapper;
 import com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper;
 import com.dy.pmsGlobal.daoSta.*;
 import com.dy.pmsGlobal.pojoSta.*;
@@ -16,6 +18,7 @@
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.time.temporal.TemporalAccessor;
 import java.util.Date;
 import java.util.HashMap;
@@ -33,6 +36,8 @@
     private StaDeviceProductionLogMapper deviceProductionLogDao;
     private StaRepairInfoMapper repairInfoDao;
     private PrAssemblyPlanMapper assemblyPlanDao;
+    private OthStatisticWorkloadMapper workloadDao;
+
     @Autowired
     public void setDeviceLastDao(StaDeviceLastMapper deviceLastDao) {
         this.deviceLastDao = deviceLastDao;
@@ -63,6 +68,11 @@
         this.repairInfoDao = repairInfoDao;
     }
 
+    @Autowired
+    public void setWorkloadDao(OthStatisticWorkloadMapper workloadDao) {
+        this.workloadDao = workloadDao;
+    }
+
     public Map<String, Object> getDeviceInfo(String deviceNo) {
         if (StringUtils.isBlank(deviceNo)) {
             return null;
@@ -72,7 +82,7 @@
         if (deviceLast == null) {
             return null;
         }
-        Map<String, Object> deviceInfo =new HashMap<>();
+        Map<String, Object> deviceInfo = new HashMap<>();
         deviceInfo.put("deviceInfo", deviceLast);
         //鏌ヨ璁惧鏃ュ織
         List<StaDeviceProductionLog> log = deviceProductionLogDao.selectByDeviceNo(deviceNo);
@@ -90,21 +100,21 @@
     }
 
     public List<StaDeviceProductionLog> queryDeviceLog(String startTime, String endTime) {
-        Date startDt = parseToDate(startTime,0);
-        Date endDt = parseToDate(endTime,1);
+        Date startDt = parseToDate(startTime, 0);
+        Date endDt = parseToDate(endTime, 1);
         //鏌ヨ璁惧鏃ュ織
-        List<StaDeviceProductionLog> log = deviceProductionLogDao.selectProductLog("",startDt,endDt);
+        List<StaDeviceProductionLog> log = deviceProductionLogDao.selectProductLog("", startDt, endDt);
         return log;
     }
 
-    private Date parseToDate(String strDt,long offDays) {
-        LocalDateTime dt = LocalDateTime.of(LocalDate.now().plusDays(offDays), LocalTime.of(0,0,0)); // 浠婂ぉ24鐐�
+    private Date parseToDate(String strDt, long offDays) {
+        LocalDateTime dt = LocalDateTime.of(LocalDate.now().plusDays(offDays), LocalTime.of(0, 0, 0)); // 浠婂ぉ24鐐�
         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         if (strDt.matches("\\d{4}(-\\d{2}){2} \\d{2}(:\\d{2}){2}")) {//2024-08-15 00:00:00
-            dt = LocalDateTime.parse(strDt,dtf);
-        }else if (strDt.matches("\\d{4}(-\\d{2}){2}")){
-            dt = LocalDateTime.of(LocalDate.parse(strDt,dtf1), LocalTime.of(0,0,0));
+            dt = LocalDateTime.parse(strDt, dtf);
+        } else if (strDt.matches("\\d{4}(-\\d{2}){2}")) {
+            dt = LocalDateTime.of(LocalDate.parse(strDt, dtf1), LocalTime.of(0, 0, 0));
         }
         Date date = Date.from(dt.atZone(ZoneId.systemDefault()).toInstant());
         return date;
@@ -113,29 +123,52 @@
     public List<JSONObject> queryPlanList() {
         List<JSONObject> list = assemblyPlanDao.queryPlanList();
         Map<String, JSONObject> map = new ConcurrentHashMap<>(); // 浣跨敤骞跺彂瀹夊叏鐨凪ap
-        for(JSONObject item:list){
+        for (JSONObject item : list) {
             String planId = String.valueOf(item.getObj("planId"));
             JSONObject innerObject = new JSONObject()
                     .set("nodeId", String.valueOf(item.getObj("nodeId")))
                     .set("content", item.getObj("content"));
-            if(map.containsKey(planId)){
-                JSONArray array = (JSONArray)map.get(planId).get("nodes");
+            if (map.containsKey(planId)) {
+                JSONArray array = (JSONArray) map.get(planId).get("nodes");
                 array.add(innerObject);
-            }else{
+            } else {
                 JSONArray array = new JSONArray();
                 array.add(innerObject);
-                JSONObject outObject= new JSONObject()
+                JSONObject outObject = new JSONObject()
                         .set("planId", planId)
                         .set("planName", item.getObj("planName"))
                         .set("nodes", array);
-                map.put(planId,outObject);
+                map.put(planId, outObject);
             }
         }
         return map.values().stream().collect(Collectors.toList());
     }
 
+    public void test() {
 
-
+        //OthStatisticWorkloadMapper workloadMapper = SpringContextUtil.getBean(OthStatisticWorkloadMapper.class);
+        //鎵惧埌鏈�澶т竴鏉℃棩鏈熻褰�
+        Date maxDate = workloadDao.selectMaxDate();
+        //寰�鍚庡惊鐜ぉ鏁版眹鎬�
+        if (maxDate != null) {
+            //寰幆缁熻
+            LocalDate firstDay = maxDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+            LocalDate today = LocalDate.now();
+            LocalDate nextDate = firstDay.plusDays(1);
+            //today 瑕佺粺璁�  firstday涓嶇粺璁�
+            long daysBetween = ChronoUnit.DAYS.between(firstDay, today);
+            if (daysBetween > 30) {
+                daysBetween = 30;
+                nextDate = firstDay.plusDays(daysBetween);
+            }
+            for (int i = 1; i <= daysBetween; i++) {
+                Date startDt = Date.from(LocalDateTime.of(nextDate, LocalTime.of(0, 0, 0)).atZone(ZoneId.systemDefault()).toInstant());
+                Date endDt = Date.from(LocalDateTime.of(nextDate, LocalTime.of(23, 59, 59)).atZone(ZoneId.systemDefault()).toInstant());
+                workloadDao.insertBatch(startDt, endDt);
+                nextDate = firstDay.plusDays(i);
+            }
+        }
+    }
 
 
 }

--
Gitblit v1.8.0