| | |
| | | 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; |
| | |
| | | * @createDate 2024-10-12 11:06:03 |
| | | * @Entity com.dy.pmsGlobal.pojoOth.OthStatisticWorkload |
| | | */ |
| | | @Mapper |
| | | public interface OthStatisticWorkloadMapper { |
| | | |
| | | int deleteByPrimaryKey(Long id); |
| | |
| | | </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 |
| | |
| | | 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"> |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |
| | |
| | | List<JSONObject> list = sv.queryPlanList(); |
| | | return BaseResponseUtils.buildSuccess(list); |
| | | } |
| | | @GetMapping(path="test") |
| | | public BaseResponse test(){ |
| | | sv.test(); |
| | | return BaseResponseUtils.buildSuccess(); |
| | | } |
| | | } |
| | |
| | | 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.*; |
| | |
| | | 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; |
| | |
| | | private StaDeviceProductionLogMapper deviceProductionLogDao; |
| | | private StaRepairInfoMapper repairInfoDao; |
| | | private PrAssemblyPlanMapper assemblyPlanDao; |
| | | private OthStatisticWorkloadMapper workloadDao; |
| | | |
| | | @Autowired |
| | | public void setDeviceLastDao(StaDeviceLastMapper deviceLastDao) { |
| | | this.deviceLastDao = deviceLastDao; |
| | |
| | | @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) { |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |