|
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
@@ -19,6 +21,8 @@ import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.Shipping
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletUseInfoService;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.vo.BilletPushResponse;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.vo.ShippingOrderVO;
|
|
|
+import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
|
|
|
+import org.jeecg.modules.billet.billetOriginalProductRecord.mapper.BilletOriginalProductRecordMapper;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBill;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
|
|
|
import org.jeecg.modules.billet.storageBill.mapper.StorageBillPrintMapper;
|
|
@@ -60,6 +64,9 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
@Autowired
|
|
|
private ShippingPushRecordMapper shippingPushRecordMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BilletOriginalProductRecordMapper billetOriginalProductRecordMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
public RedisTemplate redisTemplate;
|
|
|
|
|
@@ -84,6 +91,21 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Async("asyncExecutor")
|
|
|
+ public void saveBilletOneInfoAndDelayPush(BilletUseInfoAddDTO addDTO, BilletOriginalProductRecord billetOriginalProductRecord) {
|
|
|
+ try {
|
|
|
+ // 1. 先执行 saveBilletOneInfo 的逻辑
|
|
|
+ saveBilletOneInfo(addDTO);
|
|
|
+
|
|
|
+ // 2. 再延迟 3 秒后执行 delayPushOne
|
|
|
+ Thread.sleep(3_000);
|
|
|
+ delayPushOne(billetOriginalProductRecord);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("执行 saveBilletOneInfoAndDelayPush 异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -158,6 +180,78 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveBilletOneInfo(BilletUseInfoAddDTO batchDTO) {
|
|
|
+ List<BilletUseInfo> allUseInfoList = new ArrayList<>();
|
|
|
+ Set<String> allGeneratedNos = new HashSet<>();
|
|
|
+ List<String> usedBasicInfoIds = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, Integer> entry : batchDTO.getLengthToNumMap().entrySet()) {
|
|
|
+ String length = entry.getKey();
|
|
|
+ Integer needCount = entry.getValue();
|
|
|
+
|
|
|
+ // 查询未使用的钢坯
|
|
|
+ LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(BilletBasicInfo::getCcmNo, batchDTO.getCcmNo())
|
|
|
+ .eq(BilletBasicInfo::getHeatNo, batchDTO.getHeatNo())
|
|
|
+ .eq(BilletBasicInfo::getLength, Integer.valueOf(length))
|
|
|
+ .and(wrapper -> wrapper.ne(BilletBasicInfo::getUseStatus, 1).or().isNull(BilletBasicInfo::getUseStatus))
|
|
|
+ .last("LIMIT " + needCount); // 限制只查需要数量
|
|
|
+
|
|
|
+ List<BilletBasicInfo> billetBasicInfos = billetBasicInfoMapper.selectList(queryWrapper);
|
|
|
+ int existCount = billetBasicInfos.size();
|
|
|
+
|
|
|
+ // 只处理 needCount 以内的记录
|
|
|
+ int usedCount = Math.min(needCount, existCount);
|
|
|
+ for (int i = 0; i < usedCount; i++) {
|
|
|
+ BilletBasicInfo billet = billetBasicInfos.get(i);
|
|
|
+
|
|
|
+ BilletUseInfo useInfo = new BilletUseInfo();
|
|
|
+ useInfo.setBilletNo(billet.getBilletNo());
|
|
|
+ useInfo.setHeatNo(batchDTO.getHeatNo());
|
|
|
+ useInfo.setCcmNo(batchDTO.getCcmNo());
|
|
|
+ useInfo.setShift(batchDTO.getShift());
|
|
|
+ useInfo.setShiftGroup(batchDTO.getShiftGroup());
|
|
|
+ useInfo.setLength(Integer.valueOf(length));
|
|
|
+ useInfo.setRecordId(batchDTO.getRecordId());
|
|
|
+ allUseInfoList.add(useInfo);
|
|
|
+ usedBasicInfoIds.add(billet.getId());
|
|
|
+ allGeneratedNos.add(billet.getBilletNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果还不够,才补生成
|
|
|
+ int toGenerateCount = needCount - usedCount;
|
|
|
+ for (int i = 0; i < toGenerateCount; i++) {
|
|
|
+ String billetNo = generateUniqueBilletNo(batchDTO.getHeatNo(), batchDTO.getCcmNo(), allGeneratedNos);
|
|
|
+ allGeneratedNos.add(billetNo);
|
|
|
+
|
|
|
+ BilletUseInfo useInfo = new BilletUseInfo();
|
|
|
+ useInfo.setBilletNo(billetNo);
|
|
|
+ useInfo.setHeatNo(batchDTO.getHeatNo());
|
|
|
+ useInfo.setCcmNo(batchDTO.getCcmNo());
|
|
|
+ useInfo.setShift(batchDTO.getShift());
|
|
|
+ useInfo.setShiftGroup(batchDTO.getShiftGroup());
|
|
|
+ useInfo.setLength(Integer.valueOf(length));
|
|
|
+ useInfo.setRecordId(batchDTO.getRecordId());
|
|
|
+ allUseInfoList.add(useInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 批量保存
|
|
|
+ if (!allUseInfoList.isEmpty()) {
|
|
|
+ this.saveBatch(allUseInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量更新 useStatus
|
|
|
+ if (!usedBasicInfoIds.isEmpty()) {
|
|
|
+ LambdaUpdateWrapper<BilletBasicInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.in(BilletBasicInfo::getId, usedBasicInfoIds)
|
|
|
+ .set(BilletBasicInfo::getUseStatus, 1);
|
|
|
+ billetBasicInfoMapper.update(null, updateWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void delayPush(StorageBill storageBill) {
|
|
@@ -268,6 +362,135 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void delayPushOne(BilletOriginalProductRecord billetOriginalProductRecord) {
|
|
|
+
|
|
|
+ ShippingOrderVO shippingOrderVO = new ShippingOrderVO();
|
|
|
+
|
|
|
+ if ("5".equals(billetOriginalProductRecord.getCcmNo())) {
|
|
|
+ shippingOrderVO.setRollNo(convertRollNo("棒一"));
|
|
|
+ } else if ("6".equals(billetOriginalProductRecord.getCcmNo())) {
|
|
|
+ shippingOrderVO.setRollNo(convertRollNo("高线"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderName = billetOriginalProductRecord.getHeatNo() + "-" + billetOriginalProductRecord.getCcmNo() + "#" + convertShift(billetOriginalProductRecord.getShift()) + "-" + convertShiftGroup(billetOriginalProductRecord.getShiftGroup());
|
|
|
+ shippingOrderVO.setShippingOrder(orderName);
|
|
|
+ // 钢种牌号处理
|
|
|
+ String brandNum = Optional.ofNullable(billetOriginalProductRecord.getGrade())
|
|
|
+ .map(bn -> sysDictMapper.queryDictTextByKey("billet_spec", bn))
|
|
|
+ .orElseGet(() -> sysDictMapper.queryDictTextByKey("billet_spec", "5"));
|
|
|
+
|
|
|
+ shippingOrderVO.setSteelGrade(brandNum);
|
|
|
+ shippingOrderVO.setCcmNumber(billetOriginalProductRecord.getCcmNo());
|
|
|
+
|
|
|
+ shippingOrderVO.setTransportBilletType(2);
|
|
|
+
|
|
|
+ List<ShippingOrderVO.HeatInfo> list = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String, Integer> lengthGroupCountMap = new HashMap<>();
|
|
|
+
|
|
|
+ String detailJson = billetOriginalProductRecord.getRollClubOneDetails();
|
|
|
+ if (StringUtils.isNotBlank(detailJson)) {
|
|
|
+ try {
|
|
|
+ JsonNode rootNode = objectMapper.readTree(detailJson);
|
|
|
+
|
|
|
+ JsonNode lengthGroupNode = rootNode.get("lengthGroupCount");
|
|
|
+ if (lengthGroupNode != null && lengthGroupNode.isObject()) {
|
|
|
+ // 将 JsonNode 转换为 Map<String, Integer>
|
|
|
+ lengthGroupCountMap = objectMapper.convertValue(lengthGroupNode, new TypeReference<Map<String, Integer>>() {});
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("JSON 解析失败,数据:{}", detailJson, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 遍历处理每个键值对
|
|
|
+ for (Map.Entry<String, Integer> entry : lengthGroupCountMap.entrySet()) {
|
|
|
+ String length = entry.getKey();
|
|
|
+ Integer count = entry.getValue();
|
|
|
+
|
|
|
+ ShippingOrderVO.HeatInfo heatInfo = new ShippingOrderVO.HeatInfo();
|
|
|
+
|
|
|
+ heatInfo.setHeatNo(billetOriginalProductRecord.getHeatNo());
|
|
|
+ if ("5".equals(billetOriginalProductRecord.getCcmNo())) {
|
|
|
+ heatInfo.setConverterNo("bof5");
|
|
|
+ } else if ("6".equals(billetOriginalProductRecord.getCcmNo())) {
|
|
|
+ heatInfo.setConverterNo("bof6");
|
|
|
+ }
|
|
|
+
|
|
|
+ heatInfo.setLength(Integer.valueOf(length));
|
|
|
+
|
|
|
+ // 获取米重数据
|
|
|
+ String meterWeightKey = String.format("ccmno:meter:weight:%s", billetOriginalProductRecord.getCcmNo());
|
|
|
+ String mWeightStr = oConvertUtils.getString(redisTemplate.opsForValue().get(meterWeightKey));
|
|
|
+ BigDecimal meterWeightFactor = StringUtils.isNotEmpty(mWeightStr)
|
|
|
+ ? new BigDecimal(mWeightStr)
|
|
|
+ : new BigDecimal("0.2265"); // 如果没有米重数据,使用 0.2265 作为系数
|
|
|
+
|
|
|
+ // 1. 计算单支重量:(定尺 ÷ 1000) × 米重系数,保留三位小数
|
|
|
+ BigDecimal singleWeight = new BigDecimal(length)
|
|
|
+ .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
|
|
|
+ .multiply(meterWeightFactor)
|
|
|
+ .setScale(3, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ Integer perWeight = singleWeight.multiply(BigDecimal.valueOf(1000))
|
|
|
+ .setScale(0, RoundingMode.HALF_UP) // 四舍五入
|
|
|
+ .intValue(); // 转为整数
|
|
|
+
|
|
|
+ heatInfo.setPerWeight(perWeight);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<BilletOriginalProductRecord> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(BilletOriginalProductRecord::getId, billetOriginalProductRecord.getId());
|
|
|
+
|
|
|
+ if (0 == billetOriginalProductRecord.getIsHot()) {
|
|
|
+ heatInfo.setIsHot(0);
|
|
|
+ updateWrapper.set(BilletOriginalProductRecord::getColdSndNumber, orderName);
|
|
|
+ } else if (1 == billetOriginalProductRecord.getIsHot()) {
|
|
|
+ heatInfo.setIsHot(1);
|
|
|
+ updateWrapper.set(BilletOriginalProductRecord::getHeatSndNumber, orderName);
|
|
|
+ }
|
|
|
+
|
|
|
+ billetOriginalProductRecordMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BilletUseInfo> useInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ useInfoLambdaQueryWrapper.eq(BilletUseInfo::getCcmNo, billetOriginalProductRecord.getCcmNo())
|
|
|
+ .eq(BilletUseInfo::getShift, billetOriginalProductRecord.getShift())
|
|
|
+ .eq(BilletUseInfo::getShiftGroup, billetOriginalProductRecord.getShiftGroup())
|
|
|
+ .eq(BilletUseInfo::getHeatNo, billetOriginalProductRecord.getHeatNo())
|
|
|
+ .eq(BilletUseInfo::getLength, length)
|
|
|
+ .eq(BilletUseInfo::getRecordId, billetOriginalProductRecord.getId())
|
|
|
+ .orderByDesc(BilletUseInfo::getCreateTime);
|
|
|
+
|
|
|
+ List<BilletUseInfo> billetUseInfoList = this.list(useInfoLambdaQueryWrapper);
|
|
|
+
|
|
|
+ List<String> billetNoList = billetUseInfoList.stream()
|
|
|
+ .map(BilletUseInfo::getBilletNo) // 提取 billetNo 字段
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ heatInfo.setBilletList(billetNoList);
|
|
|
+
|
|
|
+ list.add(heatInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ shippingOrderVO.setDataList(list);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 远程调用
|
|
|
+ BilletPushResponse response = sendRequestAndLog(shippingOrderVO);
|
|
|
+ if (response != null) {
|
|
|
+ // 远程调用成功后,保存或更新推送日志
|
|
|
+ log.info("远程推送装运单接收接口成功!");
|
|
|
+ } else {
|
|
|
+ log.error("远程调用装运单接收接口失败!");
|
|
|
+ throw new RuntimeException("远程调用装运单接收接口失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private BilletPushResponse sendRequestAndLog(ShippingOrderVO request) {
|
|
|
final int maxRetries = 3;
|
|
@@ -276,7 +499,8 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
int attempt = 0;
|
|
|
while (attempt < maxRetries) {
|
|
|
try {
|
|
|
- String url = "http://192.168.0.111:8850/sr/exchange/receiveShippingOrder";
|
|
|
+ String url = "http://localhost:7005/actualControl/shippingPushRecord/receiveShippingOrder";
|
|
|
+// String url = "http://192.168.0.111:8850/sr/exchange/receiveShippingOrder";
|
|
|
ResponseEntity<BilletPushResponse> response = restTemplate.postForEntity(url, request, BilletPushResponse.class);
|
|
|
|
|
|
BilletPushResponse body = response.getBody();
|
|
@@ -358,6 +582,7 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
record.setConverterNo(heatInfo.getConverterNo());
|
|
|
record.setLength(heatInfo.getLength());
|
|
|
record.setPerWeight(heatInfo.getPerWeight());
|
|
|
+ record.setIsHot(heatInfo.getIsHot());
|
|
|
record.setRequestJson(objectMapper.writeValueAsString(request));
|
|
|
|
|
|
// 响应信息
|
|
@@ -380,6 +605,36 @@ public class BilletUseInfoServiceImpl extends ServiceImpl<BilletUseInfoMapper, B
|
|
|
return ROLL_NO_MAP.get(rawRollNo);
|
|
|
}
|
|
|
|
|
|
+ private String convertShift(String shift) {
|
|
|
+ if (!SHIFT_MAP.containsKey(shift)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return SHIFT_MAP.get(shift);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String convertShiftGroup(String shiftGroup) {
|
|
|
+ if (!SHIFT_GROUP_MAP.containsKey(shiftGroup)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return SHIFT_GROUP_MAP.get(shiftGroup);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final Map<String, String> SHIFT_MAP = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ SHIFT_MAP.put("0", "白班");
|
|
|
+ SHIFT_MAP.put("1", "夜班");
|
|
|
+ SHIFT_MAP.put("2", "中班");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final Map<String, String> SHIFT_GROUP_MAP = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ SHIFT_GROUP_MAP.put("0", "甲");
|
|
|
+ SHIFT_GROUP_MAP.put("1", "乙");
|
|
|
+ SHIFT_GROUP_MAP.put("2", "丙");
|
|
|
+ SHIFT_GROUP_MAP.put("3", "丁");
|
|
|
+ }
|
|
|
|
|
|
private static final Map<String, String> ROLL_NO_MAP = new HashMap<>();
|
|
|
|