7 changed files with 248 additions and 1 deletions
-
44src/main/java/com/gaotao/modules/schedule/entity/ShiftChangeDetailRecordEntity.java
-
22src/main/java/com/gaotao/modules/schedule/mapper/ShiftChangeDetailRecordMapper.java
-
12src/main/java/com/gaotao/modules/schedule/service/ShiftChangeDetailRecordService.java
-
18src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java
-
113src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeDetailRecordServiceImpl.java
-
5src/main/java/com/gaotao/modules/schedule/service/impl/ShiftChangeProductionReportServiceImpl.java
-
33src/main/resources/mapper/schedule/ShiftChangeDetailRecordMapper.xml
@ -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; |
||||
|
} |
||||
@ -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<ShiftChangeDetailRecordEntity> { |
||||
|
int batchInsert(@Param("list") List<ShiftChangeDetailRecordEntity> 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<Integer> rowNumbers); |
||||
|
} |
||||
@ -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<ShiftChangeProductionReportEntity> rows); |
||||
|
|
||||
|
void saveCreatedRollSnapshot(SearchScheduleData inData, String rollNo); |
||||
|
} |
||||
@ -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<ShiftChangeProductionReportEntity> rows) { |
||||
|
if (CollectionUtils.isEmpty(rows)) { |
||||
|
return; |
||||
|
} |
||||
|
List<ShiftChangeDetailRecordEntity> 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<ShiftChangeDetailRecordEntity> snapshots = new ArrayList<>(); |
||||
|
for (Map<String, Object> 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<Integer> 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<ShiftChangeDetailRecordEntity> 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); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?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.gaotao.modules.schedule.mapper.ShiftChangeDetailRecordMapper"> |
||||
|
<insert id="batchInsert"> |
||||
|
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 |
||||
|
<foreach collection="list" item="item" separator=","> |
||||
|
(#{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()) |
||||
|
</foreach> |
||||
|
</insert> |
||||
|
|
||||
|
<update id="fillRollNo"> |
||||
|
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 |
||||
|
<foreach collection="rowNumbers" item="rowNumber" open="(" separator="," close=")"> |
||||
|
#{rowNumber} |
||||
|
</foreach> |
||||
|
</update> |
||||
|
</mapper> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue