diff --git a/src/main/java/com/gaotao/modules/schedule/entity/ShiftChangeDetailRecordEntity.java b/src/main/java/com/gaotao/modules/schedule/entity/ShiftChangeDetailRecordEntity.java new file mode 100644 index 0000000..a7d2ffd --- /dev/null +++ b/src/main/java/com/gaotao/modules/schedule/entity/ShiftChangeDetailRecordEntity.java @@ -0,0 +1,44 @@ +package com.gaotao.modules.schedule.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 换班结转及随后产量报告的逐排历史快照。 + * 结转时卷号为 *、recordType 为换班结转;产量报告另记最终报告,并把结转行回填为实际卷号。 + */ +@Data +@TableName("shift_change_detail_record") +public class ShiftChangeDetailRecordEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @TableId(type = IdType.AUTO) + private Long id; + private String site; + private String buNo; + private String orderNo; + private Integer seqNo; + private String rollNo; + /** 换班结转 / 最终报告 */ + private String recordType; + private String fixtureNo; + private String shiftFrom; + private Integer rowCount; + private Integer rollCount; + // 沿用参考表的 row_bumber 字段,保存页面原始排号,分卷时不重新编号。 + private Integer rowBumber; + private BigDecimal goodQty; + private BigDecimal defectQty; + private BigDecimal surfaceLossQty; + private BigDecimal poorPerformanceQty; + private String remark; + private String packingList; + private String createdBy; + private Date createdTime; +} diff --git a/src/main/java/com/gaotao/modules/schedule/mapper/ShiftChangeDetailRecordMapper.java b/src/main/java/com/gaotao/modules/schedule/mapper/ShiftChangeDetailRecordMapper.java new file mode 100644 index 0000000..bdd005e --- /dev/null +++ b/src/main/java/com/gaotao/modules/schedule/mapper/ShiftChangeDetailRecordMapper.java @@ -0,0 +1,22 @@ +package com.gaotao.modules.schedule.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.gaotao.modules.schedule.entity.ShiftChangeDetailRecordEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface ShiftChangeDetailRecordMapper extends BaseMapper { + int batchInsert(@Param("list") List list); + + /** 仅回填同一生产任务、相同原始排号、类型为换班结转且卷号仍为 * 的记录。 */ + int fillRollNo(@Param("site") String site, + @Param("buNo") String buNo, + @Param("orderNo") String orderNo, + @Param("seqNo") Integer seqNo, + @Param("rollNo") String rollNo, + @Param("recordType") String recordType, + @Param("rowNumbers") List rowNumbers); +} diff --git a/src/main/java/com/gaotao/modules/schedule/service/ShiftChangeDetailRecordService.java b/src/main/java/com/gaotao/modules/schedule/service/ShiftChangeDetailRecordService.java new file mode 100644 index 0000000..14b2c34 --- /dev/null +++ b/src/main/java/com/gaotao/modules/schedule/service/ShiftChangeDetailRecordService.java @@ -0,0 +1,12 @@ +package com.gaotao.modules.schedule.service; + +import com.gaotao.modules.schedule.data.SearchScheduleData; +import com.gaotao.modules.schedule.entity.ShiftChangeProductionReportEntity; + +import java.util.List; + +public interface ShiftChangeDetailRecordService { + void saveTransferSnapshot(List rows); + + void saveCreatedRollSnapshot(SearchScheduleData inData, String rollNo); +} diff --git a/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java b/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java index d11679b..315853d 100644 --- a/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java +++ b/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java @@ -30,6 +30,7 @@ import com.gaotao.modules.schedule.mapper.ShiftChangeProductionReportMapper; import com.gaotao.modules.schedule.mapper.SchedulingMapper; import com.gaotao.modules.schedule.service.ScheduleService; import com.gaotao.modules.schedule.service.SchedulingService; +import com.gaotao.modules.schedule.service.ShiftChangeDetailRecordService; import com.gaotao.modules.shopOrder.entity.OperatorData; import com.gaotao.modules.sys.entity.SysUserEntity; import com.gaotao.modules.sys.entity.SysSceneExceptionRuleConditionEntity; @@ -107,6 +108,8 @@ public class ScheduleServiceImpl implements ScheduleService { @Autowired private ShiftChangeProductionReportMapper shiftChangeProductionReportMapper; @Autowired + private ShiftChangeDetailRecordService shiftChangeDetailRecordService; + @Autowired private ScheduleTodoMessageMapper scheduleTodoMessageMapper; @Autowired private ScheduleTodoDetailRecordMapper scheduleTodoDetailRecordMapper; @@ -4996,6 +4999,9 @@ public class ScheduleServiceImpl implements ScheduleService { //获取卷号的信息 String rollNos = String.valueOf(resultMap.get("rollNos")); String[] rollNoArr = rollNos.split(";"); + // 工作缓存要等本次产量报告的各卷都创建完才标记已处理,所以每一卷都还能判断出做过换班结转。 + boolean recordShiftHistory = inData.getRollRows() != null && !inData.getRollRows().isEmpty() + && hasUnprocessedShiftChange(site, orderNo, seqNo); //打印信息的数据 List> printList = new ArrayList<>(); //循环获取打印的数据 @@ -5048,12 +5054,24 @@ public class ScheduleServiceImpl implements ScheduleService { // 调用保存方法 schedulingService.saveProductionReportAndDefect(site, orderNo, Float.valueOf(itemNo), Integer.valueOf(seqNo), rollNoArr[i], operatorId, reportList, rollNo, inData.getRollDefectDetails()); + if (recordShiftHistory) { + shiftChangeDetailRecordService.saveCreatedRollSnapshot(inData, rollNoArr[i]); + } } } //返回打印的数据 2022-05-09 return printList; } + private boolean hasUnprocessedShiftChange(String site, String orderNo, String seqNo) { + if (!StringUtils.hasText(seqNo)) { + return false; + } + List pending = shiftChangeProductionReportMapper.selectUnprocessedData( + site, orderNo, Integer.valueOf(seqNo)); + return pending != null && !pending.isEmpty(); + } + /** * @return void * @Author LR @@ -7437,4 +7455,4 @@ public class ScheduleServiceImpl implements ScheduleService { logger.info("打开材料卷结果,code: {}, message: {}", code, message); return result; } -} \ No newline at end of file +} diff --git a/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeDetailRecordServiceImpl.java b/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeDetailRecordServiceImpl.java new file mode 100644 index 0000000..2e35b00 --- /dev/null +++ b/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeDetailRecordServiceImpl.java @@ -0,0 +1,113 @@ +package com.gaotao.modules.schedule.service.impl; + +import com.gaotao.modules.schedule.data.SearchScheduleData; +import com.gaotao.modules.schedule.entity.ShiftChangeDetailRecordEntity; +import com.gaotao.modules.schedule.entity.ShiftChangeProductionReportEntity; +import com.gaotao.modules.schedule.mapper.ShiftChangeDetailRecordMapper; +import com.gaotao.modules.schedule.service.ShiftChangeDetailRecordService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +public class ShiftChangeDetailRecordServiceImpl implements ShiftChangeDetailRecordService { + // 换班结转尚未回填实际卷号时的占位值。 + private static final String PENDING_ROLL_NO = "*"; + private static final String RECORD_TYPE_SHIFT = "换班结转"; + private static final String RECORD_TYPE_REPORT = "最终报告"; + // SQL Server 每条语句最多 2100 个参数;每行绑定 18 个参数。 + private static final int INSERT_BATCH_SIZE = 100; + + @Autowired + private ShiftChangeDetailRecordMapper detailRecordMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveTransferSnapshot(List rows) { + if (CollectionUtils.isEmpty(rows)) { + return; + } + List snapshots = new ArrayList<>(); + for (ShiftChangeProductionReportEntity row : rows) { + ShiftChangeDetailRecordEntity snapshot = new ShiftChangeDetailRecordEntity(); + BeanUtils.copyProperties(row, snapshot, "id", "createdTime"); + snapshot.setRollNo(PENDING_ROLL_NO); + snapshot.setRecordType(RECORD_TYPE_SHIFT); + snapshots.add(snapshot); + } + // 历次交接只追加,不能随工作缓存覆盖或删除。 + insertSnapshots(snapshots); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveCreatedRollSnapshot(SearchScheduleData inData, String rollNo) { + if (CollectionUtils.isEmpty(inData.getRollRows())) { + return; + } + Integer seqNo = Integer.valueOf(inData.getSeqNo()); + if (!StringUtils.hasText(rollNo) || "null".equalsIgnoreCase(rollNo.trim()) + || PENDING_ROLL_NO.equals(rollNo.trim())) { + throw new IllegalArgumentException("创建分卷未返回有效卷号,无法保存追溯明细"); + } + List snapshots = new ArrayList<>(); + for (Map row : inData.getRollRows()) { + ShiftChangeDetailRecordEntity snapshot = new ShiftChangeDetailRecordEntity(); + snapshot.setSite(inData.getSite()); + snapshot.setBuNo(inData.getBuNo()); + snapshot.setOrderNo(inData.getOrderNo()); + snapshot.setSeqNo(seqNo); + snapshot.setRollNo(rollNo); + snapshot.setRecordType(RECORD_TYPE_REPORT); + snapshot.setFixtureNo(inData.getFixture()); + snapshot.setShiftFrom(inData.getShiftNo()); + snapshot.setRowCount(inData.getRowCount() == null ? inData.getRollRows().size() : inData.getRowCount()); + snapshot.setRollCount(inData.getRollCount()); + snapshot.setRowBumber(Integer.valueOf(String.valueOf(row.get("rowNumber")))); + snapshot.setGoodQty(decimal(row.get("goodQty"))); + snapshot.setDefectQty(decimal(row.get("defectQty"))); + snapshot.setSurfaceLossQty(decimal(row.get("surfaceLossQty"))); + snapshot.setPoorPerformanceQty(decimal(row.get("poorPerformanceQty"))); + snapshot.setRemark(text(row.get("remark"))); + snapshot.setPackingList(text(row.get("packingList"))); + snapshot.setCreatedBy(StringUtils.hasText(inData.getOperatorId()) + ? inData.getOperatorId() : inData.getCreatedBy()); + snapshots.add(snapshot); + } + // 按本次实际生成卷所含的原始排号回填,避免多卷时把全部结转排刷到第一卷。 + for (int start = 0; start < snapshots.size(); start += INSERT_BATCH_SIZE) { + List rowNumbers = new ArrayList<>(); + for (ShiftChangeDetailRecordEntity snapshot : snapshots.subList(start, + Math.min(start + INSERT_BATCH_SIZE, snapshots.size()))) { + rowNumbers.add(snapshot.getRowBumber()); + } + detailRecordMapper.fillRollNo(inData.getSite(), inData.getBuNo(), inData.getOrderNo(), + seqNo, rollNo, RECORD_TYPE_SHIFT, rowNumbers); + } + // 最终数据另外追加,不能覆盖结转时的数量、班次、操作人和时间。 + insertSnapshots(snapshots); + } + + private void insertSnapshots(List snapshots) { + for (int start = 0; start < snapshots.size(); start += INSERT_BATCH_SIZE) { + detailRecordMapper.batchInsert(snapshots.subList(start, + Math.min(start + INSERT_BATCH_SIZE, snapshots.size()))); + } + } + + private BigDecimal decimal(Object value) { + return value == null ? BigDecimal.ZERO : new BigDecimal(String.valueOf(value)); + } + + private String text(Object value) { + return value == null ? "" : String.valueOf(value); + } +} diff --git a/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeProductionReportServiceImpl.java b/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeProductionReportServiceImpl.java index 6873f6e..28f8919 100644 --- a/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeProductionReportServiceImpl.java +++ b/src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeProductionReportServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gaotao.modules.schedule.entity.ShiftChangeProductionReportEntity; import com.gaotao.modules.schedule.mapper.ShiftChangeProductionReportMapper; import com.gaotao.modules.schedule.service.ShiftChangeProductionReportService; +import com.gaotao.modules.schedule.service.ShiftChangeDetailRecordService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,6 +22,9 @@ public class ShiftChangeProductionReportServiceImpl @Autowired private ShiftChangeProductionReportMapper shiftChangeProductionReportMapper; + @Autowired + private ShiftChangeDetailRecordService shiftChangeDetailRecordService; + @Override public List getUnprocessedData(String site, String orderNo, Integer seqNo) { return shiftChangeProductionReportMapper.selectUnprocessedData(site, orderNo, seqNo); @@ -35,6 +39,7 @@ public class ShiftChangeProductionReportServiceImpl // 再批量插入新数据 if (dataList != null && !dataList.isEmpty()) { shiftChangeProductionReportMapper.batchInsert(dataList); + shiftChangeDetailRecordService.saveTransferSnapshot(dataList); } } diff --git a/src/main/resources/mapper/schedule/ShiftChangeDetailRecordMapper.xml b/src/main/resources/mapper/schedule/ShiftChangeDetailRecordMapper.xml new file mode 100644 index 0000000..67534df --- /dev/null +++ b/src/main/resources/mapper/schedule/ShiftChangeDetailRecordMapper.xml @@ -0,0 +1,33 @@ + + + + + INSERT INTO shift_change_detail_record ( + site, bu_no, order_no, seq_no, roll_no, record_type, fixture_no, shift_from, + row_count, roll_count, row_bumber, good_qty, defect_qty, + surface_loss_qty, poor_performance_qty, remark, packing_list, created_by, created_time + ) VALUES + + (#{item.site}, #{item.buNo}, #{item.orderNo}, #{item.seqNo}, #{item.rollNo}, #{item.recordType}, + #{item.fixtureNo}, #{item.shiftFrom}, #{item.rowCount}, + #{item.rollCount}, #{item.rowBumber}, #{item.goodQty}, #{item.defectQty}, + #{item.surfaceLossQty}, #{item.poorPerformanceQty}, #{item.remark}, + #{item.packingList}, #{item.createdBy}, GETDATE()) + + + + + UPDATE shift_change_detail_record + SET roll_no = #{rollNo} + WHERE site = #{site} + AND (bu_no = #{buNo} OR (bu_no IS NULL AND #{buNo} IS NULL)) + AND order_no = #{orderNo} + AND seq_no = #{seqNo} + AND record_type = #{recordType} + AND roll_no = '*' + AND row_bumber IN + + #{rowNumber} + + +