Fancy
2024-10-12 6791263bef9e25fce3521ac7632622294b6fb56e
statistic workload test
4个文件已修改
1个文件已添加
100 ■■■■■ 已修改文件
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 35 ●●●●● 补丁 | 查看 | 原始文档 | 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;
@@ -61,6 +66,11 @@
    @Autowired
    public void setRepairInfoDao(StaRepairInfoMapper repairInfoDao) {
        this.repairInfoDao = repairInfoDao;
    }
    @Autowired
    public void setWorkloadDao(OthStatisticWorkloadMapper workloadDao) {
        this.workloadDao = workloadDao;
    }
    public Map<String, Object> getDeviceInfo(String deviceNo) {
@@ -134,8 +144,31 @@
        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);
            }
        }
    }
}