|
@@ -1,16 +1,25 @@
|
|
|
package org.jeecg.modules.billet.storageBill.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
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.ObjectMapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
|
|
|
+import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
|
|
|
+import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
|
|
|
import org.jeecg.modules.billet.stackingAndLoadingVehicles.entity.StackingAndLoadingVehicles;
|
|
|
import org.jeecg.modules.billet.stackingAndLoadingVehicles.mapper.StackingAndLoadingVehiclesMapper;
|
|
|
+import org.jeecg.modules.billet.stackingAndLoadingVehicles.service.IStackingAndLoadingVehiclesService;
|
|
|
import org.jeecg.modules.billet.storageBill.dto.StorageBillPrintAddDTO;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBill;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
|
|
@@ -22,7 +31,9 @@ import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoDetailVO;
|
|
|
import org.jeecg.modules.billet.storageBill.vo.StorageCenterHeatNoInvoicingVO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
@@ -39,6 +50,7 @@ import java.util.stream.Collectors;
|
|
|
* @Date: 2025-06-16
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMapper, StorageBillPrint> implements IStorageBillPrintService {
|
|
|
|
|
@@ -51,6 +63,21 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
|
|
|
@Autowired
|
|
|
private StackingAndLoadingVehiclesMapper stackingAndLoadingVehiclesMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendTypeConfigService billetHotsendTypeConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendBaseService billetHotsendBaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IStackingAndLoadingVehiclesService stackingAndLoadingVehiclesService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StorageBillPrintMapper storageBillPrintMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RedisTemplate redisTemplate;
|
|
|
+
|
|
|
@Override
|
|
|
public void saveStorageBillPrint(StorageBillPrintAddDTO addDTO) {
|
|
|
if (addDTO.getStorageBillId() == null) {
|
|
@@ -147,7 +174,7 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
|
|
|
if (StringUtils.isNotBlank(entity.getHeatNo())) {
|
|
|
try {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- Map<String, Integer> heatNoMap = objectMapper.readValue(entity.getHeatNo(), new TypeReference<Map<String, Integer>>() {
|
|
|
+ Map<String, Integer> heatNoMap = objectMapper.readValue(entity.getHeatNo(), new com.fasterxml.jackson.core.type.TypeReference<Map<String, Integer>>() {
|
|
|
});
|
|
|
vo.setHeatNo(heatNoMap);
|
|
|
} catch (JsonProcessingException e) {
|
|
@@ -1662,4 +1689,183 @@ public class StorageBillPrintServiceImpl extends ServiceImpl<StorageBillPrintMap
|
|
|
|
|
|
return storageCenterHeatNoDetailVO;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public JSONObject loadingHandle(StorageBillPrintAddDTO addDTO) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ List<String> skippedHeatNos = new ArrayList<>();
|
|
|
+
|
|
|
+ // 根据 billetHotsendTypeConfigId 查询基础垛位信息
|
|
|
+ BilletHotsendTypeConfig billetHotsendTypeConfig = billetHotsendTypeConfigService.getByParam(addDTO);
|
|
|
+
|
|
|
+ // 查询是否已存在打印记录
|
|
|
+ List<StorageBillPrint> existingPrints = storageBillPrintMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<StorageBillPrint>()
|
|
|
+ .eq(StorageBillPrint::getStorageBillId, addDTO.getStorageBillId())
|
|
|
+ );
|
|
|
+ boolean alreadyPrinted = !existingPrints.isEmpty();
|
|
|
+
|
|
|
+ // 查询最新的储运单
|
|
|
+ StorageBill storageBill = storageBillMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<StorageBill>()
|
|
|
+ .eq(StorageBill::getId, addDTO.getStorageBillId())
|
|
|
+ .orderByDesc(StorageBill::getCreateTime)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (storageBill == null) {
|
|
|
+ result.put("fail", "未找到对应储运单");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map.Entry<String, Integer> entry : addDTO.getHeatNo().entrySet()) {
|
|
|
+ String heatNo = entry.getKey();
|
|
|
+ Integer currentCount = entry.getValue();
|
|
|
+
|
|
|
+ if (currentCount == null || currentCount <= 0) {
|
|
|
+ skippedHeatNos.add(heatNo + "(支数无效)");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int delta = currentCount;
|
|
|
+
|
|
|
+ if (alreadyPrinted) {
|
|
|
+ // 汇总历史支数
|
|
|
+ int previousCount = existingPrints.stream()
|
|
|
+ .mapToInt(print -> {
|
|
|
+ try {
|
|
|
+ Map<String, Integer> heatNoMap = JSON.parseObject(
|
|
|
+ print.getHeatNo(),
|
|
|
+ new TypeReference<Map<String, Integer>>() {
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return heatNoMap.getOrDefault(heatNo, 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .sum();
|
|
|
+
|
|
|
+ delta = currentCount - previousCount;
|
|
|
+
|
|
|
+ if (delta <= 0) {
|
|
|
+ skippedHeatNos.add(heatNo + "(未增加)");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (delta % 4 != 0) {
|
|
|
+ skippedHeatNos.add(heatNo + "(增量非4倍数,剩余: " + delta + ")");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 首次:支数必须为4的倍数
|
|
|
+ if (currentCount % 4 != 0) {
|
|
|
+ skippedHeatNos.add(heatNo + "(支数非4倍数)");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int fetchCount = delta / 4;
|
|
|
+
|
|
|
+ // 获取传递单
|
|
|
+ BilletHotsend billetHotsend = billetHotsendBaseService.getOne(
|
|
|
+ new LambdaQueryWrapper<BilletHotsend>()
|
|
|
+ .eq(BilletHotsend::getCcmNo, addDTO.getCcmNo())
|
|
|
+ .eq(BilletHotsend::getHeatNo, heatNo)
|
|
|
+ .orderByDesc(BilletHotsend::getCreateTime)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+
|
|
|
+ // 查询垛位
|
|
|
+ List<StackingAndLoadingVehicles> vehicles = stackingAndLoadingVehiclesService.list(
|
|
|
+ new LambdaQueryWrapper<StackingAndLoadingVehicles>()
|
|
|
+ .eq(StackingAndLoadingVehicles::getCcmNo, addDTO.getCcmNo())
|
|
|
+ .eq(StackingAndLoadingVehicles::getHeatNo, heatNo)
|
|
|
+ .eq(StackingAndLoadingVehicles::getSize, addDTO.getSize())
|
|
|
+ .orderByDesc(StackingAndLoadingVehicles::getLayer)
|
|
|
+ .orderByDesc(StackingAndLoadingVehicles::getAddress)
|
|
|
+ );
|
|
|
+
|
|
|
+ int availableCount = vehicles.size();
|
|
|
+ int processCount = Math.min(fetchCount, availableCount);
|
|
|
+
|
|
|
+ if (processCount == 0) {
|
|
|
+ skippedHeatNos.add(heatNo + "(可用垛位不足)");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<StackingAndLoadingVehicles> selected = new ArrayList<>(vehicles.subList(0, processCount));
|
|
|
+ vehicles.subList(0, processCount).clear();
|
|
|
+
|
|
|
+ // 执行堆垛逻辑
|
|
|
+ handleStackDepartCommon(billetHotsend, selected, addDTO, billetHotsendTypeConfig, storageBill);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("success", "堆垛保存完成");
|
|
|
+// if (!skippedHeatNos.isEmpty()) {
|
|
|
+// result.put("skipped", "跳过炉号: " + String.join(",", skippedHeatNos));
|
|
|
+// }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 堆垛保存、堆垛发车公共处理
|
|
|
+ *
|
|
|
+ * @param billetHotsend
|
|
|
+ * @param stackingAndLoadingVehiclesList
|
|
|
+ * @param addDTO
|
|
|
+ * @param billetHotsendTypeConfig
|
|
|
+ * @param storageBill
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void handleStackDepartCommon(BilletHotsend billetHotsend, List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList, StorageBillPrintAddDTO addDTO, BilletHotsendTypeConfig billetHotsendTypeConfig, StorageBill storageBill) {
|
|
|
+
|
|
|
+ // 根据铸机号、位置、层数、类型配置ID更新 初始化容器中的垛位信息
|
|
|
+ List<String> ids = stackingAndLoadingVehiclesList.stream().map(StackingAndLoadingVehicles::getId).collect(Collectors.toList());
|
|
|
+ // 创建更新包装器
|
|
|
+ LambdaUpdateWrapper<StackingAndLoadingVehicles> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.in(StackingAndLoadingVehicles::getId, ids)
|
|
|
+ .set(StackingAndLoadingVehicles::getBilletNos, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getSpec, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getSteel, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getSize, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getShift, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getHeatNo, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getCreateDate, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getShiftGroup, null)
|
|
|
+ .set(StackingAndLoadingVehicles::getUpdateTime, new Date());
|
|
|
+ // 执行批量更新
|
|
|
+ stackingAndLoadingVehiclesMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据班组班别对钢坯信息进行分组
|
|
|
+ *
|
|
|
+ * @param stackingAndLoadingVehiclesList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map<String, List<StackingAndLoadingVehicles>> groupByShiftAttributes(List<StackingAndLoadingVehicles> stackingAndLoadingVehiclesList) {
|
|
|
+ return stackingAndLoadingVehiclesList.stream().collect(Collectors.groupingBy(stackingAndLoadingVehicles -> stackingAndLoadingVehicles.getHeatNo() + "," + stackingAndLoadingVehicles.getShiftGroup() + "," + stackingAndLoadingVehicles.getShift()));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Integer safeToInteger(String str) {
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(str);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ try {
|
|
|
+ // 尝试转成小数再取整
|
|
|
+ return new BigDecimal(str).intValue();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|