Browse Source

原始记录添加炉号修正为对应的班组班别以及创建时间

lingpeng.li 2 weeks ago
parent
commit
b76572e030

+ 86 - 14
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/controller/BilletOriginalProductRecordController.java

@@ -136,30 +136,97 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 //	@RequiresPermissions("billetOriginalProductRecord:billet_original_product_record:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody BilletOriginalProductRecord billetOriginalProductRecord) {
-
 		String classShiftGroup = String.format("class:shift:group:%s", billetOriginalProductRecord.getCcmNo()); // 班组
 		String classShift = String.format("class:shift:%s", billetOriginalProductRecord.getCcmNo()); // 班别
 		String brandNum = String.format("billet:basic:info:brand:num:%s", billetOriginalProductRecord.getCcmNo()); // 牌号
-		String shift = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)) : "";
-		String shiftGroup = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)) : "";
-		String brandNumStr = !oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)) : "";
+
+		// 从 Redis 获取默认值
+		String redisShift = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)).isEmpty()
+				? oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)) : "";
+		String redisShiftGroup = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)).isEmpty()
+				? oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)) : "";
+
+		// 初始化最终使用的 shift 和 shiftGroup
+		String finalShift = redisShift;
+		String finalShiftGroup = redisShiftGroup;
+
+		// 处理 changeShiftId
+		String changeShiftId = billetOriginalProductRecord.getChangeShiftId(); // 假设实体有该字段
+		BilletHotsendChangeShift billetHotsendChangeShift = null;
+
+		if (StringUtils.isNotBlank(changeShiftId)) {
+			LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
+			queryWrapper.eq(BilletHotsendChangeShift::getId, changeShiftId)
+					.eq(BilletHotsendChangeShift::getCcmNo, billetOriginalProductRecord.getCcmNo());
+
+			billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
+
+			if (billetHotsendChangeShift != null) {
+				finalShift = billetHotsendChangeShift.getShift();
+				finalShiftGroup = billetHotsendChangeShift.getShiftGroup();
+			}
+		}
+
+		// 计算目标创建时间
+		Date targetCreateTime = new Date(); // 默认使用当前时间
+
+		// 只有当存在换班记录时才进行时间计算
+		if (billetHotsendChangeShift != null) {
+			String nextHeatNo = billetOriginalProductRecord.getNextHeatNo();
+			Date createTime = billetHotsendChangeShift.getCreateTime();
+
+			// 如果 changeShiftTime 为 null,则使用当前时间
+			Date changeShiftTime = billetHotsendChangeShift.getChangeShiftTime();
+			if (changeShiftTime == null) {
+				changeShiftTime = new Date();
+			}
+
+			// 构建基础查询条件
+			LambdaQueryWrapper<BilletOriginalProductRecord> timeQueryWrapper = new LambdaQueryWrapper<>();
+			timeQueryWrapper.between(BilletOriginalProductRecord::getCreateTime, createTime, changeShiftTime)
+					.eq(BilletOriginalProductRecord::getShift, finalShift)
+					.eq(BilletOriginalProductRecord::getShiftGroup, finalShiftGroup)
+					.orderByDesc(BilletOriginalProductRecord::getCreateTime)
+					.last("limit 1");
+
+			// 根据 heatNo 是否存在调整查询条件
+			if (StringUtils.isNotBlank(nextHeatNo)) {
+				timeQueryWrapper.eq(BilletOriginalProductRecord::getHeatNo, nextHeatNo);
+			}
+
+			// 查询最新的记录
+			BilletOriginalProductRecord latestRecord = billetOriginalProductRecordService.getOne(timeQueryWrapper);
+
+			if (latestRecord != null) {
+				Date latestCreateTime = latestRecord.getCreateTime();
+				if (StringUtils.isNotBlank(nextHeatNo)) {
+					// heatNo 存在,设置为比最新记录早1秒
+					targetCreateTime = new Date(latestCreateTime.getTime() - 1000);
+				} else {
+					// heatNo 不存在,设置为比最新记录晚1秒
+					targetCreateTime = new Date(latestCreateTime.getTime() + 1000);
+				}
+			}
+		}
+
 		// 通过铸机号、炉号、班组、班别 查询钢坯炉次传递单
 		LambdaQueryWrapper<BilletHotsend> lambdaQueryWrapper = new LambdaQueryWrapper<>();
 		lambdaQueryWrapper.eq(BilletHotsend::getHeatNo, billetOriginalProductRecord.getHeatNo())
-				.eq(BilletHotsend::getShiftGroup, shiftGroup)
-				.eq(BilletHotsend::getShift, shift)
+				.eq(BilletHotsend::getShiftGroup, finalShiftGroup)
+				.eq(BilletHotsend::getShift, finalShift)
 				.eq(BilletHotsend::getCcmNo, billetOriginalProductRecord.getCcmNo()).last("limit 1");
 		BilletHotsend billetHotsendInfo = billetHotsendBaseService.getOne(lambdaQueryWrapper);
-		if(billetHotsendInfo == null){
 
+		if(billetHotsendInfo == null){
 			// 同步新增炉次传递单
 			BilletHotsend billetHotsend = new BilletHotsend();
 			billetHotsend.setId(String.valueOf(IdWorker.getId()));
 			billetHotsend.setCcmNo(billetOriginalProductRecord.getCcmNo());
 			billetHotsend.setHeatNo(billetOriginalProductRecord.getHeatNo());
-			billetHotsend.setShiftGroup(shiftGroup);
-			billetHotsend.setShift(shift);
-			billetHotsend.setBrandNum(brandNumStr);
+			billetHotsend.setShiftGroup(finalShiftGroup);
+			billetHotsend.setShift(finalShift);
+			billetHotsend.setBrandNum(!oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)).isEmpty()
+					? oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)) : "");
 			billetHotsend.setAmountTotal(0);
 			billetHotsend.setBlankOutput(0.0);
 			billetHotsend.setDecideWeight(0.0);
@@ -173,12 +240,15 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 			billetHotsend.setStackNum(0);
 			billetHotsend.setWasteNum(0);
 			billetHotsend.setIsUpd(false);
-			billetHotsend.setCreateTime(new Date());
+			billetHotsend.setCreateTime(targetCreateTime); // 设置计算好的创建时间
 			billetHotsendBaseService.save(billetHotsend);
 		}
-		billetOriginalProductRecord.setShift(shift);
-		billetOriginalProductRecord.setShiftGroup(shiftGroup);
-		billetOriginalProductRecord.setGrade(brandNumStr);
+
+		// 设置实体属性
+		billetOriginalProductRecord.setShift(finalShift);
+		billetOriginalProductRecord.setShiftGroup(finalShiftGroup);
+		billetOriginalProductRecord.setGrade(!oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)).isEmpty()
+				? oConvertUtils.getString(redisTemplate.opsForValue().get(brandNum)) : "");
 		billetOriginalProductRecord.setIsEditCharge("1");
 		billetOriginalProductRecord.setLength(null);
 		billetOriginalProductRecord.setRollClubOneDetails(null);
@@ -189,6 +259,8 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 		billetOriginalProductRecord.setStackLength(null);
 		billetOriginalProductRecord.setRemark(null);
 		billetOriginalProductRecord.setConfirmBy(null);
+		billetOriginalProductRecord.setCreateTime(targetCreateTime); // 设置计算好的创建时间
+
 		billetOriginalProductRecordService.save(billetOriginalProductRecord);
 		return Result.OK("添加成功!");
 	}

+ 15 - 4
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/entity/BilletOriginalProductRecord.java

@@ -4,12 +4,12 @@ import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.math.BigDecimal;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableLogic;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.annotation.*;
 import lombok.Data;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import org.jeecgframework.poi.excel.annotation.ExcelIgnore;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.jeecgframework.poi.excel.annotation.Excel;
 import org.jeecg.common.aspect.annotation.Dict;
@@ -187,4 +187,15 @@ public class BilletOriginalProductRecord implements Serializable {
     @ApiModelProperty(value = "备注")
     private String notes;
 
+    @ExcelIgnore
+    @TableField(exist = false)
+    private String changeShiftId;
+
+    @ExcelIgnore
+    @TableField(exist = false)
+    private String nextHeatNo;
+
+
+
+
 }