From bea49667b0a34a17490c4b47f6a14857a737f647 Mon Sep 17 00:00:00 2001 From: 刘小明 <liuxm_a@163.com> Date: 星期三, 17 七月 2024 08:47:31 +0800 Subject: [PATCH] 新增生产日志历史表,每天00:05把生产日志表中的数据移动到历史表中 --- pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java | 2 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLog.java | 2 pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogMapper.xml | 6 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java | 21 ++++ pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml | 53 ++++++++++ pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLast.java | 2 pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java | 16 +++ pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java | 25 +++++ pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java | 12 ++ pms-parent/pms-global/src/main/resources/mapper/StaDeviceLifeLastMapper.xml | 14 +- pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLife.java | 2 pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLogPast.java | 106 +++++++++++++++++++++ 12 files changed, 249 insertions(+), 12 deletions(-) diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java new file mode 100644 index 0000000..a59132e --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java @@ -0,0 +1,21 @@ +package com.dy.pmsGlobal.daoSta; + +import com.dy.pmsGlobal.pojoSta.StaDeviceProductionLogPast; +import org.apache.ibatis.annotations.Mapper; + +/** +* @author User +* @description 閽堝琛ㄣ�恠ta_device_production_log_past(杩囧線璁惧鐢熶骇鏃ュ織琛紝瀛樺偍鍘嗗彶鏃ュ織鏁版嵁)銆戠殑鏁版嵁搴撴搷浣淢apper +* @createDate 2024-07-13 10:34:59 +* @Entity com.dy.pmsGlobal.pojoSta.StaDeviceProductionLogPast +*/ +@Mapper +public interface StaDeviceProductionLogPastMapper { + + int insertIntoPastLogs(); + int deleteFromLogTable(); + + StaDeviceProductionLogPast selectByPrimaryKey(Long id); + +// void createNewTable(String newTableName); +} diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java index 8495254..beb8002 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java @@ -47,7 +47,7 @@ public String qrCode; /** - * 鐘舵��:姝e湪鐢熶骇锛�0锛夛紝鐢熶骇缁撴潫锛�1锛� + * 鐘舵��:寰呯敓浜э紙0锛夛紝1(缁勮涓�),2(瀹屾垚),3(缁翠慨),4(鎶ュ簾),5(娴嬭瘯涓嶉�氳繃),6(鍝佹涓嶉�氳繃) */ public Integer status; } \ No newline at end of file diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLast.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLast.java index 41f9d23..38d20ca 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLast.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLast.java @@ -66,7 +66,7 @@ */ public String deviceCycleContent; /** - * 鐘舵��: 1:缁勮涓�,2:瀹屾垚,3:缁翠慨,4:鎶ュ簾,5:娴嬭瘯涓嶉�氳繃,6:鍝佹涓嶉�氳繃 + * 鐘舵��: 0:寰呯敓浜�,1:缁勮涓�,2:瀹屾垚,3:缁翠慨,4:鎶ュ簾,5:娴嬭瘯涓嶉�氳繃,6:鍝佹涓嶉�氳繃 */ public Integer status; /** diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLife.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLife.java index 2df3032..81ac20e 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLife.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLife.java @@ -67,7 +67,7 @@ public String deviceCycleContent; /** - * 鐘舵��: 1:缁勮涓�,2:瀹屾垚,3:缁翠慨,4:鎶ュ簾 + * 鐘舵��: 0:寰呯敓浜�,1:缁勮涓�,2:瀹屾垚,3:缁翠慨,4:鎶ュ簾,5:娴嬭瘯涓嶉�氳繃,6:鍝佹涓嶉�氳繃 */ public Integer status; /** diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLog.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLog.java index c29613d..193f784 100644 --- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLog.java +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLog.java @@ -66,7 +66,7 @@ */ public String deviceCycleContent; /** - * 鐘舵��: 1:缁勮涓�,2:瀹屾垚,3:缁翠慨,4:鎶ュ簾 + * 鐘舵��: 0:寰呯敓浜�,1:缁勮涓�,2:瀹屾垚,3:缁翠慨,4:鎶ュ簾,5:娴嬭瘯涓嶉�氳繃,6:鍝佹涓嶉�氳繃 */ public Integer status; /** diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLogPast.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLogPast.java new file mode 100644 index 0000000..b430230 --- /dev/null +++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLogPast.java @@ -0,0 +1,106 @@ +package com.dy.pmsGlobal.pojoSta; + +import com.alibaba.fastjson2.annotation.JSONField; +import com.alibaba.fastjson2.writer.ObjectWriterImplToString; +import com.baomidou.mybatisplus.annotation.TableName; +import com.dy.common.po.BaseEntity; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.*; + + + +import java.util.Date; + +/** +* 杩囧線璁惧鐢熶骇鏃ュ織琛紝瀛樺偍鍘嗗彶鏃ュ織鏁版嵁 +* @TableName sta_device_production_log_past +*/ +@TableName(value="sta_device_production_log_past", autoResultMap = true) +@Data +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class StaDeviceProductionLogPast implements BaseEntity { + + /** + * + */ + @NotNull(message="涓嶈兘涓虹┖") + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long id; + /** + * 璁惧鐮� + */ + @NotBlank(message="璁惧鐮佷笉鑳戒负绌�") + public String deviceNo; + /** + * 鐢熶骇鐧诲綍id + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long workId; + /** + * 缁翠慨id + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long repairId; + /** + * 璁″垝id + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long planId; + /** + * 宸ョ珯id + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long stationId; + /** + * 褰撳墠鑺傜偣 + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long currNode; + /** + * 鑺傜偣浣滀笟鍐呭 + */ + public String nodeContent; + /** + * 璁板綍璁惧鍛ㄦ湡鍐呭 + */ + public String deviceCycleContent; + /** + * 鐘舵��: 0(寰呯敓浜э級锛�1(缁勮涓�),2(瀹屾垚),3(缁翠慨),4(鎶ュ簾),5(娴嬭瘯涓嶉�氳繃),6(鍝佹涓嶉�氳繃) + */ + public Integer status; + /** + * 1:鎴愬姛,2:澶辫触 + */ + public Integer result; + /** + * 缁翠慨鑺傜偣杩斿洖鐨勯敊璇俊鎭� + */ + public String errorMsg; + /** + * 杈呭姪浜哄憳:杈呭姪鍛樺伐id,浠ラ�楀彿闅斿紑 + */ + public String assistants; + /** + * 鍏ョ珯鏃堕棿 + */ + public Date inTime; + /** + * 鍑虹珯鏃堕棿 + */ + public Date outTime; + /** + * 鎿嶄綔鍛榠d + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + public Long updatedBy; + /** + * 澶囨敞 + */ + public String memo; + + +} diff --git a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceLifeLastMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceLifeLastMapper.xml index aadffd9..e5b4514 100644 --- a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceLifeLastMapper.xml +++ b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceLifeLastMapper.xml @@ -22,6 +22,7 @@ <result property="updatedBy" column="updated_by" jdbcType="BIGINT"/> <result property="memo" column="memo" jdbcType="VARCHAR"/> </resultMap> + <resultMap id="joinResultMap" type="com.dy.pmsGlobal.pojoSta.StaDeviceLifeLast" extends="BaseResultMap"> <result property="planName" column="plan_name" jdbcType="VARCHAR"/> <result property="stationName" column="station_name" jdbcType="VARCHAR"/> @@ -38,11 +39,12 @@ in_time,out_time,updated_by, memo </sql> + <select id="selectByDeviceNo" parameterType="java.lang.String" resultMap="joinResultMap"> select t.* ,p.`name` plan_name,s.`name` station_name,u.`name` update_user_name FROM - sta_device_life t + sta_device_life_last t left join pr_assembly_plan p on t.plan_id=p.id left join plt_station s on s.id = t.station_id left JOIN ba_user u on u.id=t.updated_by @@ -54,12 +56,12 @@ select <include refid="Base_Column_List" /> from sta_device_life_last - where id = #{id,jdbcType=BIGINT} + where id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> delete from sta_device_life_last - where id = #{id,jdbcType=BIGINT} + where id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.dy.pmsGlobal.pojoSta.StaDeviceLifeLast" useGeneratedKeys="true"> insert into sta_device_life_last @@ -164,11 +166,11 @@ memo = #{memo,jdbcType=VARCHAR}, </if> </set> - where id = #{id,jdbcType=BIGINT} + where id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKey" parameterType="com.dy.pmsGlobal.pojoSta.StaDeviceLifeLast"> update sta_device_life_last - set + set device_no = #{deviceNo,jdbcType=VARCHAR}, work_id = #{workId,jdbcType=BIGINT}, repair_id = #{repairId,jdbcType=BIGINT}, @@ -184,7 +186,7 @@ out_time = #{outTime,jdbcType=TIMESTAMP}, updated_by = #{updatedBy,jdbcType=BIGINT}, memo = #{memo,jdbcType=VARCHAR} - where id = #{id,jdbcType=BIGINT} + where id = #{id,jdbcType=BIGINT} </update> <update id="updateByDeviceNo"> update sta_device_life_last diff --git a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogMapper.xml index f815c1e..6bf8a26 100644 --- a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogMapper.xml +++ b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogMapper.xml @@ -51,11 +51,13 @@ select t.* ,p.`name` plan_name,s.`name` station_name,u.`name` update_user_name FROM - sta_device_production_log t + ( + select * from sta_device_production_log_past where device_no = #{deviceNo,jdbcType=VARCHAR} union + select * from sta_device_production_log where device_no = #{deviceNo,jdbcType=VARCHAR} + ) t left join pr_assembly_plan p on t.plan_id=p.id left join plt_station s on s.id = t.station_id left JOIN ba_user u on u.id=t.updated_by - where t.device_no = #{deviceNo,jdbcType=VARCHAR} ORDER BY t.id DESC </select> diff --git a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml new file mode 100644 index 0000000..f4e0fe2 --- /dev/null +++ b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.dy.pmsGlobal.daoSta.StaDeviceProductionLogPastMapper"> + + <resultMap id="BaseResultMap" type="com.dy.pmsGlobal.pojoSta.StaDeviceProductionLogPast"> + <id property="id" column="id" jdbcType="BIGINT"/> + <result property="deviceNo" column="device_no" jdbcType="VARCHAR"/> + <result property="workId" column="work_id" jdbcType="BIGINT"/> + <result property="repairId" column="repair_id" jdbcType="BIGINT"/> + <result property="planId" column="plan_id" jdbcType="BIGINT"/> + <result property="stationId" column="station_id" jdbcType="BIGINT"/> + <result property="currNode" column="curr_node" jdbcType="BIGINT"/> + <result property="nodeContent" column="node_content" jdbcType="VARCHAR"/> + <result property="deviceCycleContent" column="device_cycle_content" jdbcType="VARCHAR"/> + <result property="status" column="status" jdbcType="TINYINT"/> + <result property="result" column="result" jdbcType="TINYINT"/> + <result property="errorMsg" column="error_msg" jdbcType="VARCHAR"/> + <result property="assistants" column="assistants" jdbcType="VARCHAR"/> + <result property="inTime" column="in_time" jdbcType="TIMESTAMP"/> + <result property="outTime" column="out_time" jdbcType="TIMESTAMP"/> + <result property="updatedBy" column="updated_by" jdbcType="BIGINT"/> + <result property="memo" column="memo" jdbcType="VARCHAR"/> + </resultMap> + + <sql id="Base_Column_List"> + id,device_no,work_id, + repair_id,plan_id,station_id, + curr_node,node_content,device_cycle_content, + status,result,error_msg, + assistants,in_time,out_time, + updated_by,memo + </sql> +<!-- <update id="createNewTable">--> +<!-- CREATE TABLE ${newTableName} LIKE sta_device_production_log--> +<!-- </update>--> + + <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> + select + <include refid="Base_Column_List" /> + from sta_device_production_log_past + where id = #{id,jdbcType=BIGINT} + </select> + + <!-- 灏嗚繃寰�鏃ュ織绉诲姩鍒� sta_device_production_log_past --> + <insert id="insertIntoPastLogs"> + INSERT INTO sta_device_production_log_past SELECT * FROM sta_device_production_log WHERE DATE(out_time) != CURDATE(); + </insert> + <delete id="deleteFromLogTable"> + DELETE FROM sta_device_production_log WHERE DATE(out_time) != CURDATE(); + </delete> +</mapper> diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java index d51b920..50c55f4 100644 --- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java +++ b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Slf4j @@ -150,10 +151,21 @@ if (loginUser != null) { process.creator = loginUser.id; } + AtomicInteger startCount = new AtomicInteger(); + AtomicInteger endCount = new AtomicInteger(); process.nodes.forEach(node -> { node.processId = process.id; node.deleted = false; + if(node.isStart){ + startCount.getAndIncrement(); + } + if(node.isEnd){ + endCount.getAndIncrement(); + } }); + if (startCount.get() != 1 || endCount.get() != 1) { + throw new RuntimeException("鑺傜偣寮�濮嬪拰缁撴潫鑺傜偣鏈変笖鍙兘鏈変竴涓�"); + } } // 灏嗚妭鐐瑰拰宸ヤ綔鎸囩ず鐨勪繚瀛橀�昏緫灏佽鍒颁竴涓柟娉曚腑 diff --git a/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java new file mode 100644 index 0000000..cd9b256 --- /dev/null +++ b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java @@ -0,0 +1,16 @@ +package com.dy.pmsStation.config; + +import com.dy.common.schedulerTask.SchedulerTaskSupport; +import com.dy.pmsStation.task.LogMoveTask; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +public class AppStartupRunner implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + SchedulerTaskSupport.addDailyJob("logMoveTask", "station", LogMoveTask.class, + null, 0, 5); + } +} diff --git a/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java new file mode 100644 index 0000000..2e20fd5 --- /dev/null +++ b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java @@ -0,0 +1,25 @@ +package com.dy.pmsStation.task; + +import com.dy.common.schedulerTask.TaskJob; +import com.dy.common.springUtil.SpringContextUtil; +import com.dy.pmsGlobal.daoSta.StaDeviceProductionLogPastMapper; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Slf4j +@Component +public class LogMoveTask extends TaskJob { + + @Override + @Transactional + public void execute(JobExecutionContext ctx) throws JobExecutionException { + log.info("鐢熶骇鏃ュ織绉诲姩浠诲姟寮�濮�"); + StaDeviceProductionLogPastMapper pastMapper = SpringContextUtil.getBean(StaDeviceProductionLogPastMapper.class); + pastMapper.insertIntoPastLogs(); + pastMapper.deleteFromLogTable(); + log.info("鐢熶骇鏃ュ織绉诲姩浠诲姟缁撴潫"); + } +} -- Gitblit v1.8.0