Browse Source

确认原始记录时,同步更新送样卡记录表

lingpeng.li 1 week ago
parent
commit
7798a8510f

+ 90 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/controller/BilletHotsendChangeShiftController.java

@@ -1,10 +1,12 @@
 package org.jeecg.modules.billet.billetHotsendChangeShift.controller;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -38,6 +40,8 @@ import org.jeecg.modules.billet.rollHeight.entity.RollHeightDetails;
 import org.jeecg.modules.billet.rollHeight.service.IRollHeightDetailsService;
 import org.jeecg.modules.billet.rollOutShipp.entity.RollOutShippDetails;
 import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippDetailsService;
+import org.jeecg.modules.billet.sampleCardDeliveryRecord.entity.SampleCardDeliveryRecord;
+import org.jeecg.modules.billet.sampleCardDeliveryRecord.service.ISampleCardDeliveryRecordService;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingUpLog;
 import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingUpLogService;
 import org.jeecg.modules.billet.storageBill.entity.OnDutyLiftingBillDetails;
@@ -50,6 +54,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
@@ -57,8 +62,10 @@ import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.DecimalFormat;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.YearMonth;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -111,6 +118,12 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 	@Autowired
 	private IRollDeputyCrossDetailsService rollDeputyCrossDetailsService;
 
+	@Autowired
+	private ISampleCardDeliveryRecordService sampleCardDeliveryRecordService;
+
+	@Autowired
+	private RestTemplate restTemplate;
+
 	/**
 	 * 分页列表查询
 	 *
@@ -186,6 +199,10 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 		if(billetHotsendChangeShiftInfo == null) {
 			return Result.error("未找到对应数据!");
 		}
+
+		// 记录旧状态
+		Integer oldConfirmStatus = billetHotsendChangeShiftInfo.getConfirmStatus();
+
 		if (oConvertUtils.isNotEmpty(billetHotsendChangeShift.getSizeInfo())){
 			billetHotsendChangeShiftInfo.setSizeInfo(billetHotsendChangeShift.getSizeInfo());
 		}
@@ -196,6 +213,79 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 			billetHotsendChangeShiftInfo.setConfirmStatus(billetHotsendChangeShift.getConfirmStatus());
 		}
 		billetHotsendChangeShiftService.updateById(billetHotsendChangeShiftInfo);
+
+		final String URL = "http://localhost:7005/billet/billetOriginalProductRecord/queryBilletRecordByCcmNo?queryType=2&ccmNo=%s&changeShiftId=%s";
+
+
+		// 如果从 1 更新为 2,则触发查询与数据更新逻辑
+		if (oldConfirmStatus != null && oldConfirmStatus == 1
+				&& billetHotsendChangeShift.getConfirmStatus() != null
+				&& billetHotsendChangeShift.getConfirmStatus() == 2) {
+
+			String ccmNo = billetHotsendChangeShiftInfo.getCcmNo();
+			String changeShiftId = billetHotsendChangeShiftInfo.getId();
+			String requestUrl = String.format(URL, ccmNo, changeShiftId);
+
+			try {
+				Result<?> result = restTemplate.getForObject(requestUrl, Result.class);
+				if (result != null && result.isSuccess()) {
+					@SuppressWarnings("unchecked")
+					JSONObject jsonObject = new JSONObject((Map<String, Object>) result.getResult());
+
+					Integer confirmStatus = jsonObject.getInteger("confirmStatus");
+					if (confirmStatus != null && confirmStatus == 3) {
+						log.info("ccmNo={} 的数据已确认,跳过新增与更新。", ccmNo);
+						return Result.OK("操作成功!");
+					}
+
+					JSONArray jsonArray = jsonObject.getJSONArray("billetOriginalProductRecordList");
+					List<SampleCardDeliveryRecord> recordsToSave = new ArrayList<>();
+					List<SampleCardDeliveryRecord> recordsToUpdate = new ArrayList<>();
+
+					for (int i = 0; i < jsonArray.size(); i++) {
+						JSONObject json = jsonArray.getJSONObject(i);
+						SampleCardDeliveryRecord record = json.toJavaObject(SampleCardDeliveryRecord.class);
+
+						Date createDate = DateUtils.str2Date(json.getString("createTime"), DateUtils.datetimeFormat.get());
+						LocalDate createLocalDate = createDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+
+						LambdaQueryWrapper<SampleCardDeliveryRecord> wrapper = new LambdaQueryWrapper<>();
+						wrapper.eq(SampleCardDeliveryRecord::getCcmNo, record.getCcmNo())
+								.eq(SampleCardDeliveryRecord::getHeatNo, record.getHeatNo())
+								.eq(SampleCardDeliveryRecord::getShift, record.getShift())
+								.eq(SampleCardDeliveryRecord::getShiftGroup, record.getShiftGroup())
+								.between(SampleCardDeliveryRecord::getCreateTime,
+										Date.from(createLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()),
+										Date.from(createLocalDate.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusNanos(1).toInstant()))
+								.last("LIMIT 1");
+
+						SampleCardDeliveryRecord existRecord = sampleCardDeliveryRecordService.getOne(wrapper, false);
+
+						if (existRecord == null) {
+							record.setId(String.valueOf(IdWorker.getId()));
+							recordsToSave.add(record);
+						} else {
+							record.setId(existRecord.getId());
+							recordsToUpdate.add(record);
+						}
+					}
+
+					if (!recordsToSave.isEmpty()) {
+						sampleCardDeliveryRecordService.saveBatch(recordsToSave);
+					}
+
+					if (!recordsToUpdate.isEmpty()) {
+						sampleCardDeliveryRecordService.updateBatchById(recordsToUpdate);
+					}
+
+				} else {
+					log.warn("接口请求失败:{}", result != null ? result.getMessage() : "null response");
+				}
+			} catch (Exception e) {
+				log.error("同步 SampleCardDeliveryRecord 出错,ccmNo={}, id={}", ccmNo, changeShiftId, e);
+			}
+		}
+
 		return Result.OK("操作成功!");
 	}
 	

+ 2 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -1993,8 +1993,8 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 		// 查询最新的 StorageBill
 		LambdaQueryWrapper<StorageBill> queryWrapper = new LambdaQueryWrapper<>();
 		queryWrapper.eq(StorageBill::getPositionNum, positionNum);
-		// 车位不等于 2铸机号 加铸机号条件
-		if (!positionNum.equals("2")) {
+		// 车位不等于 2跟4时 铸机号 加铸机号条件
+		if (!"2".equals(positionNum) && !"4".equals(positionNum)) {
 			queryWrapper.eq(StorageBill::getCcmNo, ccmNo);
 		}
 		queryWrapper.orderByDesc(StorageBill::getCreateTime).last("LIMIT 1");