新增生产日志历史表,每天00:05把生产日志表中的数据移动到历史表中
New file |
| | |
| | | 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); |
| | | } |
| | |
| | | public String qrCode; |
| | | |
| | | /** |
| | | * 状态:正在生产(0),生产结束(1) |
| | | * 状态:待生产(0),1(组装中),2(完成),3(维修),4(报废),5(测试不通过),6(品检不通过) |
| | | */ |
| | | public Integer status; |
| | | } |
| | |
| | | */ |
| | | public String deviceCycleContent; |
| | | /** |
| | | * 状态: 1:组装中,2:完成,3:维修,4:报废,5:测试不通过,6:品检不通过 |
| | | * 状态: 0:待生产,1:组装中,2:完成,3:维修,4:报废,5:测试不通过,6:品检不通过 |
| | | */ |
| | | public Integer status; |
| | | /** |
| | |
| | | public String deviceCycleContent; |
| | | |
| | | /** |
| | | * 状态: 1:组装中,2:完成,3:维修,4:报废 |
| | | * 状态: 0:待生产,1:组装中,2:完成,3:维修,4:报废,5:测试不通过,6:品检不通过 |
| | | */ |
| | | public Integer status; |
| | | /** |
| | |
| | | */ |
| | | public String deviceCycleContent; |
| | | /** |
| | | * 状态: 1:组装中,2:完成,3:维修,4:报废 |
| | | * 状态: 0:待生产,1:组装中,2:完成,3:维修,4:报废,5:测试不通过,6:品检不通过 |
| | | */ |
| | | public Integer status; |
| | | /** |
New file |
| | |
| | | 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; |
| | | |
| | | |
| | | } |
| | |
| | | <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"/> |
| | |
| | | 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 |
| | |
| | | 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> |
| | | |
New file |
| | |
| | | <?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> |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | 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("节点开始和结束节点有且只能有一个"); |
| | | } |
| | | } |
| | | |
| | | // 将节点和工作指示的保存逻辑封装到一个方法中 |
New file |
| | |
| | | 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); |
| | | } |
| | | } |
New file |
| | |
| | | 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("生产日志移动任务结束"); |
| | | } |
| | | } |