|
@@ -1,20 +1,42 @@
|
|
|
package org.jeecg.modules.actualControl.billetActual.billetActual.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfoException;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletBasicInfoExceptionMapper;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletBasicInfoMapper;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletRulerConfigMapper;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoExceptionService;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetAssemblyNumber.entity.BilletAssemblyNumber;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetAssemblyNumber.mapper.BilletAssemblyNumberMapper;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetAssemblyNumber.service.IBilletAssemblyNumberService;
|
|
|
+import org.jeecg.modules.actualControl.heatsActuals.entity.HeatsActuals;
|
|
|
+import org.jeecg.modules.actualControl.heatsActuals.mapper.HeatsActualsMapper;
|
|
|
+import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.mapper.BilletHotsendBaseMapper;
|
|
|
+import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
|
|
|
+import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
|
|
|
+import org.jeecg.modules.connConfig.mapper.ConfigMqttMapper;
|
|
|
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 java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 钢坯实绩异常表
|
|
@@ -26,7 +48,217 @@ import java.util.Date;
|
|
|
@Slf4j
|
|
|
public class BilletBasicInfoExceptionServiceImpl extends ServiceImpl<BilletBasicInfoExceptionMapper, BilletBasicInfoException> implements IBilletBasicInfoExceptionService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendTypeConfigService billetHotsendTypeConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletBasicInfoService billetBasicInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConfigMqttMapper configMqttMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BilletRulerConfigMapper billetRulerConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IBilletAssemblyNumberService billetAssemblyNumberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ HeatsActualsMapper heatsActualsMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendBaseService billetHotsendBaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IHeatsActualsService heatsActualsService;
|
|
|
+
|
|
|
@Autowired
|
|
|
RedisTemplate redisTemplate;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void assemblyHandle(String ccmNo) {
|
|
|
+
|
|
|
+ String classShiftGroup = String.format("class:shift:group:%s", ccmNo); // 班组
|
|
|
+ String classShift = String.format("class:shift:%s", ccmNo); // 班
|
|
|
+
|
|
|
+ String classShiftStr = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)) : "";
|
|
|
+ String classShiftGroupStr = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)) : "";
|
|
|
+
|
|
|
+ log.info("{}{}", "钢坯实绩接收时缓存中的班组班别:", classShiftGroupStr + " " + classShiftStr);
|
|
|
+
|
|
|
+ if (oConvertUtils.isEmpty(classShiftStr) || oConvertUtils.isEmpty(classShiftGroupStr)) {
|
|
|
+ log.info("{}{}", "钢坯实绩接收时缓存中的班组班别为空!", ccmNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 根据ccmNo、班别、班组查询钢坯实绩异常表
|
|
|
+ LambdaQueryWrapper<BilletBasicInfoException> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(BilletBasicInfoException::getCcmNo, ccmNo)
|
|
|
+ .eq(BilletBasicInfoException::getShift, classShiftStr)
|
|
|
+ .eq(BilletBasicInfoException::getShiftGroup, classShiftGroupStr);
|
|
|
+ queryWrapper.orderByDesc(BilletBasicInfoException::getCreateTime);
|
|
|
+ List<BilletBasicInfoException> billetBasicInfoExceptionList = baseMapper.selectList(queryWrapper);
|
|
|
+ if (oConvertUtils.listIsEmpty(billetBasicInfoExceptionList) || billetBasicInfoExceptionList.size() < 4) {
|
|
|
+ log.info("{}{}", "钢坯实绩异常表数据不足4条!", ccmNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BilletBasicInfo> billetBasicInfoList = new ArrayList<>();
|
|
|
+ billetBasicInfoExceptionList.forEach(x -> {
|
|
|
+ BilletBasicInfo billetBasicInfo = new BilletBasicInfo();
|
|
|
+ BeanUtils.copyProperties(x, billetBasicInfo);
|
|
|
+ billetBasicInfo.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ billetBasicInfoList.add(billetBasicInfo);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 根据ccmNo、班别、班组查询钢坯炉次传递单表
|
|
|
+ LambdaQueryWrapper<BilletHotsend> billetHotsendLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ billetHotsendLambdaQueryWrapper.eq(BilletHotsend::getCcmNo, ccmNo)
|
|
|
+ .eq(BilletHotsend::getShift, classShiftStr)
|
|
|
+ .eq(BilletHotsend::getShiftGroup, classShiftGroupStr)
|
|
|
+ .orderByDesc(BilletHotsend::getCreateTime);
|
|
|
+ List<BilletHotsend> billetHotsendList = billetHotsendBaseService.list(billetHotsendLambdaQueryWrapper);
|
|
|
+ if (oConvertUtils.listIsEmpty(billetHotsendList)) {
|
|
|
+ log.info("{}{}", "当班炉次传递单为空,无法组批!", ccmNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BilletHotsend secondLastBilletHotsend;
|
|
|
+ // 获取第二条炉次传递单数据
|
|
|
+ if (billetHotsendList.size() >= 2) {
|
|
|
+ secondLastBilletHotsend = billetHotsendList.get(1);
|
|
|
+ } else {
|
|
|
+ log.info("{}", "列表中数据不足,无法获取倒数第二条记录");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String heatNo = secondLastBilletHotsend.getHeatNo();
|
|
|
+ // 根据ccmno、heatNo获取钢坯实绩最新的一条
|
|
|
+ LambdaQueryWrapper<BilletBasicInfo> billetBasicInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ billetBasicInfoLambdaQueryWrapper.eq(BilletBasicInfo::getCcmNo, Integer.valueOf(ccmNo))
|
|
|
+ .eq(BilletBasicInfo::getHeatNo, heatNo)
|
|
|
+ .orderByDesc(BilletBasicInfo::getCreateTime).last("limit 1");
|
|
|
+ BilletBasicInfo billetBasicInfo = billetBasicInfoService.getOne(billetBasicInfoLambdaQueryWrapper);
|
|
|
+ if (oConvertUtils.isEmpty(billetBasicInfo)) {
|
|
|
+ log.info("{}{}", "获取指定炉号最新一条钢坯实绩数据为空!", ccmNo + " && " + heatNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取钢包号
|
|
|
+ String ladleNo = billetBasicInfo.getLadleNo();
|
|
|
+ // 获取炉内顺序号
|
|
|
+ int heatnoIndex = billetBasicInfo.getHeatnoIndex();
|
|
|
+ // 收集最终要移除的钢坯实绩异常数据
|
|
|
+ List<String> removeBilletBasicInfoExceptionIds = new ArrayList<>();
|
|
|
+ // 收集所有需要组批完成后的钢坯实绩信息
|
|
|
+ List<BilletBasicInfo> saveBilletBasicInfoList = new ArrayList<>();
|
|
|
+ // 收集组批实绩
|
|
|
+ List<BilletAssemblyNumber> billetAssemblyNumberList = new ArrayList<>();
|
|
|
+ int size = billetBasicInfoList.size();
|
|
|
+ int maxProcessed = (size / 4) * 4; // 计算可处理的最大4的倍数
|
|
|
+ for (int i = 0; i < maxProcessed; i += 4) {
|
|
|
+ int start = i;
|
|
|
+ int end = Math.min(i + 4, maxProcessed);
|
|
|
+ // 生成组批号(优化:直接生成随机数,避免雪花算法开销)
|
|
|
+ String assemblyNumber = generateUniqueAssemblyNumber(ccmNo, heatNo);
|
|
|
+ // 为当前分组的4条记录设置相同组批号,并添加到更新列表
|
|
|
+ List<BilletBasicInfo> assemblyData = billetBasicInfoList.subList(start, end);
|
|
|
+ List<String> idList = assemblyData.stream()
|
|
|
+ .map(BilletBasicInfo::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 记录当前批次的起始索引值
|
|
|
+ final int baseIndex = heatnoIndex + i;
|
|
|
+ assemblyData.forEach(item -> {
|
|
|
+ String billetNo = generateUniqueBilletNo(Integer.valueOf(ccmNo), heatNo);
|
|
|
+ item.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ item.setBilletNo(billetNo);
|
|
|
+ item.setAssemblyNumber(assemblyNumber);
|
|
|
+ item.setHeatNo(heatNo);
|
|
|
+ item.setLadleNo(ladleNo);
|
|
|
+ item.setStrandnoIndex(item.getStrandnoIndex() + 1);
|
|
|
+ item.setShift(classShiftStr);
|
|
|
+ item.setShiftGroup(classShiftGroupStr);
|
|
|
+ // 从baseIndex开始递增设置HeatnoIndex
|
|
|
+ int indexValue = baseIndex + assemblyData.indexOf(item);
|
|
|
+ item.setHeatnoIndex(indexValue);
|
|
|
+ });
|
|
|
+ // 将处理后的4条数据的坯号用逗号连接
|
|
|
+ String joinedBilletNos = assemblyData.stream()
|
|
|
+ .map(BilletBasicInfo::getBilletNo)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ // 创建BilletAssemblyNumber记录并添加到列表
|
|
|
+ BilletAssemblyNumber billetAssemblyNumber = new BilletAssemblyNumber();
|
|
|
+ billetAssemblyNumber.setAssemblyNumber(assemblyNumber);
|
|
|
+ billetAssemblyNumber.setHeatNo(heatNo);
|
|
|
+ billetAssemblyNumber.setCcmNo(billetBasicInfo.getCcmNo()); // 使用第一条数据的ccmNo
|
|
|
+ billetAssemblyNumber.setLength(billetBasicInfo.getLength());
|
|
|
+ billetAssemblyNumber.setShift(classShiftStr);
|
|
|
+ billetAssemblyNumber.setShiftGroup(classShiftGroupStr);
|
|
|
+ billetAssemblyNumber.setAssemblyTime(new Date());
|
|
|
+ billetAssemblyNumber.setBilletsNo(joinedBilletNos); // 添加拼接的坯号
|
|
|
+ double totalBilletWeight = assemblyData.stream()
|
|
|
+ .mapToDouble(BilletBasicInfo::getBilletWeight)
|
|
|
+ .sum();
|
|
|
+ billetAssemblyNumber.setBilletWeight(totalBilletWeight);
|
|
|
+
|
|
|
+ // 收集组批实绩信息
|
|
|
+ billetAssemblyNumberList.add(billetAssemblyNumber);
|
|
|
+
|
|
|
+ // 收集钢坯实绩信息
|
|
|
+ saveBilletBasicInfoList.addAll(assemblyData);
|
|
|
+
|
|
|
+ // 收集组批成功后,需要移除的钢坯实绩异常数据
|
|
|
+ removeBilletBasicInfoExceptionIds.addAll(idList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量保存钢坯实绩
|
|
|
+ billetBasicInfoService.saveBatch(saveBilletBasicInfoList);
|
|
|
+
|
|
|
+ // 保存组批实绩
|
|
|
+ billetAssemblyNumberService.saveBatch(billetAssemblyNumberList);
|
|
|
+
|
|
|
+ // 更新炉次传递单中的数量和总重
|
|
|
+ double totalBilletWeight = saveBilletBasicInfoList.stream()
|
|
|
+ .mapToDouble(BilletBasicInfo::getBilletWeight)
|
|
|
+ .sum();
|
|
|
+ secondLastBilletHotsend.setBlankOutput(totalBilletWeight);
|
|
|
+ secondLastBilletHotsend.setAmountTotal(saveBilletBasicInfoList.size());
|
|
|
+ billetHotsendBaseService.updateById(secondLastBilletHotsend);
|
|
|
+
|
|
|
+ // 更新炉次实绩中的总重和数量
|
|
|
+ HeatsActuals heatsActuals = heatsActualsService.getOne(new LambdaQueryWrapper<HeatsActuals>()
|
|
|
+ .eq(HeatsActuals::getHeatsCode, heatNo)
|
|
|
+ .eq(HeatsActuals::getCasterCode, ccmNo));
|
|
|
+ if (heatsActuals != null){
|
|
|
+ heatsActuals.setBlankOutput(totalBilletWeight);
|
|
|
+ heatsActuals.setBilletSum(saveBilletBasicInfoList.size());
|
|
|
+ heatsActualsService.updateById(heatsActuals);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 移除组批成功的钢坯实绩异常数据
|
|
|
+ if (oConvertUtils.listIsNotEmpty(removeBilletBasicInfoExceptionIds)){
|
|
|
+ baseMapper.deleteBatchIds(removeBilletBasicInfoExceptionIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成唯一的坯号
|
|
|
+ *
|
|
|
+ * @return 坯号
|
|
|
+ */
|
|
|
+ private String generateUniqueBilletNo(Integer ccmNo, String heatNo) {
|
|
|
+ String billetNo;
|
|
|
+ do {
|
|
|
+ billetNo = heatNo + String.format("%04d", (int)(Math.random() * 10000));
|
|
|
+ } while (billetBasicInfoService.exists(new QueryWrapper<BilletBasicInfo>().eq("billet_no", billetNo). eq("ccm_no", ccmNo)));
|
|
|
+ return billetNo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成唯一的组坯号
|
|
|
+ *
|
|
|
+ * @return 坯号
|
|
|
+ */
|
|
|
+ private String generateUniqueAssemblyNumber(String ccmNo, String heatNo) {
|
|
|
+ String assembly_number;
|
|
|
+ do {
|
|
|
+ assembly_number = heatNo + String.format("%07d", (int)(Math.random() * 10000000));
|
|
|
+ } while (billetAssemblyNumberService.checkAssemblyNumberNumber(ccmNo, assembly_number));
|
|
|
+ return assembly_number;
|
|
|
+ }
|
|
|
}
|