Fancy
2024-10-12 6791263bef9e25fce3521ac7632622294b6fb56e
statistic workload test
4个文件已修改
1个文件已添加
130 ■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoOth/OthStatisticWorkloadMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/OthStatisticWorkloadMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/WebListenerConfiguration.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportCtrl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/screen/ScreenReportSv.java 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
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">
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/config/WebListenerConfiguration.java
New file
@@ -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 ;
    /*
    * 解析各种***config.xml配置的ConfigListener,当前springboot工程暂时不采用此种配置方式
    *
    @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;
    }
}
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();
    }
}
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<>(); // 使用并发安全的Map
        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);
            }
        }
    }
}