刘小明
2024-07-17 bea49667b0a34a17490c4b47f6a14857a737f647
新增生产日志历史表,每天00:05把生产日志表中的数据移动到历史表中
5个文件已添加
7个文件已修改
251 ■■■■■ 已修改文件
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLast.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceLife.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLog.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLogPast.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/StaDeviceLifeLastMapper.xml 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java
New file
@@ -0,0 +1,21 @@
package com.dy.pmsGlobal.daoSta;
import com.dy.pmsGlobal.pojoSta.StaDeviceProductionLogPast;
import org.apache.ibatis.annotations.Mapper;
/**
* @author User
* @description 针对表【sta_device_production_log_past(过往设备生产日志表,存储历史日志数据)】的数据库操作Mapper
* @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);
}
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoPr/PrDevice.java
@@ -47,7 +47,7 @@
    public String qrCode;
    /**
     * 状态:正在生产(0),生产结束(1)
     * 状态:待生产(0),1(组装中),2(完成),3(维修),4(报废),5(测试不通过),6(品检不通过)
     */
    public Integer status;
}
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;
    /**
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;
    /**
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;
    /**
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/pojoSta/StaDeviceProductionLogPast.java
New file
@@ -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;
    /**
    * 操作员id
    */
    @JSONField(serializeUsing= ObjectWriterImplToString.class)
    public Long updatedBy;
    /**
    * 备注
    */
    public String memo;
}
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
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>
pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml
New file
@@ -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>
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("节点开始和结束节点有且只能有一个");
        }
    }
    // 将节点和工作指示的保存逻辑封装到一个方法中
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java
New file
@@ -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);
    }
}
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java
New file
@@ -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("生产日志移动任务结束");
    }
}