|
@@ -1,19 +1,29 @@
|
|
|
package org.jeecg.modules.actualControl.billetActual.billetActual.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+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.extension.service.impl.ServiceImpl;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletRulerConfig;
|
|
|
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.IBilletBasicInfoService;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.utils.MqttClientUtil;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetAssemblyNumber.entity.BilletAssemblyNumber;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetAssemblyNumber.mapper.BilletAssemblyNumberMapper;
|
|
|
+import org.jeecg.modules.actualControl.heatsActuals.entity.HeatsActuals;
|
|
|
import org.jeecg.modules.billet.billetHotsend.entity.RulerDefaultConfig;
|
|
|
import org.jeecg.modules.billet.billetHotsendConfig.entity.BilletHotsendTypeConfig;
|
|
|
import org.jeecg.modules.billet.billetHotsendConfig.service.IBilletHotsendTypeConfigService;
|
|
|
+import org.jeecg.modules.connConfig.mapper.ConfigMqttMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -28,6 +38,18 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
|
|
|
@Autowired
|
|
|
private IBilletHotsendTypeConfigService billetHotsendTypeConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BilletBasicInfoMapper billetBasicInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConfigMqttMapper configMqttMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BilletRulerConfigMapper billetRulerConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BilletAssemblyNumberMapper billetAssemblyNumberMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public void insertBatch(String sid, RulerDefaultConfig rulerDefaultConfig) {
|
|
|
for (int i = 0; i < 4; i++) {
|
|
@@ -38,6 +60,227 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void addB(BilletBasicInfo billetBasicInfo, Integer number) {
|
|
|
+ // 查询该炉号最后一条钢坯记录
|
|
|
+ BilletBasicInfo lastBilletBasicInfo = billetBasicInfoMapper.selectOne(
|
|
|
+ new QueryWrapper<BilletBasicInfo>()
|
|
|
+ .eq("ccm_no", billetBasicInfo.getCcmNo())
|
|
|
+ .eq("heat_no", billetBasicInfo.getHeatNo())
|
|
|
+ .orderByDesc("create_time").last("limit 1")
|
|
|
+ );
|
|
|
+ // 棒线标识
|
|
|
+ String belongTable = billetBasicInfo.getBelongTable();
|
|
|
+ String btchid = billetBasicInfo.getBhtcId();
|
|
|
+ if (oConvertUtils.isNotEmpty(lastBilletBasicInfo)) {
|
|
|
+ billetBasicInfo = lastBilletBasicInfo;
|
|
|
+ billetBasicInfo.setId(null);
|
|
|
+ billetBasicInfo.setCreateTime(null);
|
|
|
+ billetBasicInfo.setUpdateBy(null);
|
|
|
+ billetBasicInfo.setUpdateTime(null);
|
|
|
+ billetBasicInfo.setCreateBy(null);
|
|
|
+ billetBasicInfo.setCutStartTime(null);
|
|
|
+ billetBasicInfo.setCutStopTime(null);
|
|
|
+ billetBasicInfo.setBelongTable(null);
|
|
|
+ billetBasicInfo.setBhtcId(null);
|
|
|
+ } else {
|
|
|
+ // 处理炉次实绩
|
|
|
+ sendHeatsActuals(billetBasicInfo);
|
|
|
+ billetBasicInfo.setId(null);
|
|
|
+ billetBasicInfo.setHeatnoIndex(0);
|
|
|
+ billetBasicInfo.setBelongTable(null);
|
|
|
+ billetBasicInfo.setBhtcId(null);
|
|
|
+ // 随机生成坯号
|
|
|
+ String billetNo = generateUniqueBilletNo(billetBasicInfo.getCcmNo(), billetBasicInfo.getHeatNo());
|
|
|
+ billetBasicInfo.setBilletNo(billetNo);
|
|
|
+ }
|
|
|
+ // 查询定尺规则
|
|
|
+ LambdaQueryWrapper<BilletRulerConfig> queryWrapperbilletRulerConfig = new LambdaQueryWrapper<BilletRulerConfig>().eq(BilletRulerConfig::getLength, billetBasicInfo.getLength());
|
|
|
+ BilletRulerConfig billetRulerConfig = billetRulerConfigMapper.selectOne(queryWrapperbilletRulerConfig);
|
|
|
+ Double weight = 0.0;
|
|
|
+ if(oConvertUtils.isNotEmpty(billetRulerConfig)) {
|
|
|
+ weight = billetRulerConfig.getWeight();
|
|
|
+ }
|
|
|
+ billetBasicInfo.setBilletWeight(weight);
|
|
|
+ billetBasicInfo.setWeight(weight);
|
|
|
+ if (billetBasicInfo.getCcmNo() == 5) { // 5#
|
|
|
+ // 循环处理number
|
|
|
+ for (int i = 0; i < number; i++) {
|
|
|
+ BigDecimal nextBilletNo = new BigDecimal(billetBasicInfo.getBilletNo());
|
|
|
+ billetBasicInfo.setBilletNo(String.valueOf(nextBilletNo.add(BigDecimal.ONE)));
|
|
|
+ billetBasicInfo.setHeatnoIndex(billetBasicInfo.getHeatnoIndex() + 1);
|
|
|
+ // 将对象转换为 Map
|
|
|
+ Map<String, Object> map = JSON.parseObject(JSON.toJSONString(billetBasicInfo), Map.class);
|
|
|
+ // 创建 MqttClientUtil 实例并调用非静态方法 pushCData
|
|
|
+ MqttClientUtil mqttClientUtil = new MqttClientUtil();
|
|
|
+ // 钢坯实绩
|
|
|
+ mqttClientUtil.pushCData(configMqttMapper, map, "trace/performance/billet/add");
|
|
|
+ // #棒一数据处理
|
|
|
+ if ("roll_club_one".equals(belongTable) && oConvertUtils.isNotEmpty(btchid)){ // 5号机去棒一
|
|
|
+ sendRollClubOne(billetBasicInfo, btchid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (billetBasicInfo.getCcmNo() == 6) {
|
|
|
+ Integer heatnoIndex = billetBasicInfo.getHeatnoIndex();
|
|
|
+ // 确保每次循环正确更新 i 的值,并处理边界条件
|
|
|
+ for (int i = 0; i < number; i += 4) {
|
|
|
+ // 在此处添加具体的业务逻辑
|
|
|
+ String billetsNos = "";
|
|
|
+ String assemblyNumber = "";
|
|
|
+ Double weightAll = 0.0;
|
|
|
+ // 组坯号
|
|
|
+ assemblyNumber = generateUniqueAssemblyNumber(billetBasicInfo.getCcmNo(), billetBasicInfo.getHeatNo());
|
|
|
+ for (int j = 0; j < 4 && i + j < number ; j++) { // 4支处理
|
|
|
+ System.out.println("执行钢坯实绩:" + i + "-" + j);
|
|
|
+ BigDecimal nextBilletNo = new BigDecimal(billetBasicInfo.getBilletNo());
|
|
|
+ billetBasicInfo.setBilletNo(String.valueOf(nextBilletNo.add(BigDecimal.ONE)));
|
|
|
+ billetBasicInfo.setHeatnoIndex(heatnoIndex + 1);
|
|
|
+ billetBasicInfo.setAssemblyNumber(assemblyNumber);
|
|
|
+ // 将对象转换为 Map
|
|
|
+ Map<String, Object> map = JSON.parseObject(JSON.toJSONString(billetBasicInfo), Map.class);
|
|
|
+ // 创建 MqttClientUtil 实例并调用非静态方法 pushCData
|
|
|
+ MqttClientUtil mqttClientUtil = new MqttClientUtil();
|
|
|
+ // 钢坯实绩
|
|
|
+ mqttClientUtil.pushCData(configMqttMapper, map, "trace/performance/billet/add");
|
|
|
+ // 拼接坯号
|
|
|
+ billetsNos += billetBasicInfo.getBilletNo() + ",";
|
|
|
+ // 重量累加
|
|
|
+ weightAll += billetBasicInfo.getBilletWeight();
|
|
|
+ heatnoIndex = billetBasicInfo.getHeatnoIndex();
|
|
|
+ }
|
|
|
+ // #高线数据处理
|
|
|
+ if ("roll_height".equals(belongTable) && oConvertUtils.isNotEmpty(btchid)){ // 6号机去高线
|
|
|
+ // 处理字符串尾部的,
|
|
|
+ billetsNos = billetsNos.substring(0, billetsNos.length() - 1);
|
|
|
+ // 先处理组坯
|
|
|
+ sendAssemblyNumber(billetBasicInfo, billetsNos, assemblyNumber, weightAll);
|
|
|
+ // 在送往高线
|
|
|
+ sendRollHeight(billetBasicInfo, btchid, billetsNos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成高线逻辑
|
|
|
+ * @param billetBasicInfo
|
|
|
+ */
|
|
|
+ private void sendRollHeight(BilletBasicInfo billetBasicInfo, String btchid, String billetsNos){
|
|
|
+// 延迟1秒执行
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 定义一个空 map
|
|
|
+ Map<String, Object> mapSendInfo = new HashMap<>();
|
|
|
+ mapSendInfo.put("ccmNo", billetBasicInfo.getCcmNo()); // 铸机号
|
|
|
+ mapSendInfo.put("billetNos", billetsNos); // 坯号集合
|
|
|
+ mapSendInfo.put("destination", "高线"); // 高线
|
|
|
+ mapSendInfo.put("billetHotsendTypeConfigId", btchid); // 目的地id
|
|
|
+ Map<String, Object> mapBe = JSON.parseObject(JSON.toJSONString(mapSendInfo), Map.class);
|
|
|
+ // 创建 MqttClientUtil 实例并调用非静态方法 pushCData
|
|
|
+ MqttClientUtil mqttClientUtilBe = new MqttClientUtil();
|
|
|
+ mqttClientUtilBe.pushCData(configMqttMapper, mapBe, "syn/billetHotsendBase/save");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成组坯记录
|
|
|
+ * @param billetBasicInfo
|
|
|
+ */
|
|
|
+ private void sendAssemblyNumber(BilletBasicInfo billetBasicInfo, String billetsNos, String assemblyNumber, Double weightAll){
|
|
|
+ // 延迟1秒执行
|
|
|
+ try {
|
|
|
+ Thread.sleep(2000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 定义一个空 map
|
|
|
+ Map<String, Object> mapSendInfo = new HashMap<>();
|
|
|
+ mapSendInfo.put("heatNo", billetBasicInfo.getHeatNo()); // 炉号
|
|
|
+ mapSendInfo.put("ccmNo", billetBasicInfo.getCcmNo()); // 铸机号
|
|
|
+ mapSendInfo.put("billetsNo", billetsNos); // 坯号集合
|
|
|
+ mapSendInfo.put("assemblyNumber", assemblyNumber); // 组坯号
|
|
|
+ // 获取当前时间 2025-04-22 14:56:28
|
|
|
+ mapSendInfo.put("assemblyTime", new Date()); // 组坯时间
|
|
|
+ mapSendInfo.put("length", billetBasicInfo.getLength()); // 定尺
|
|
|
+ mapSendInfo.put("billetsNum", 4); // 数量
|
|
|
+ mapSendInfo.put("billetWeight", weightAll); // 重量
|
|
|
+ Map<String, Object> mapBe = JSON.parseObject(JSON.toJSONString(mapSendInfo), Map.class);
|
|
|
+ // 创建 MqttClientUtil 实例并调用非静态方法 pushCData
|
|
|
+ MqttClientUtil mqttClientUtilBe = new MqttClientUtil();
|
|
|
+ mqttClientUtilBe.pushCData(configMqttMapper, mapBe, "trace/billet/billetAssemblyNumber/add");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成棒一逻辑
|
|
|
+ * @param billetBasicInfo
|
|
|
+ */
|
|
|
+ private void sendRollClubOne(BilletBasicInfo billetBasicInfo, String btchid){
|
|
|
+// 延迟1秒执行
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 定义一个空 map
|
|
|
+ Map<String, Object> mapSendInfo = new HashMap<>();
|
|
|
+ mapSendInfo.put("ccmNo", billetBasicInfo.getCcmNo()); // 铸机号
|
|
|
+ mapSendInfo.put("billetNos", billetBasicInfo.getBilletNo()); // 坯号
|
|
|
+ mapSendInfo.put("destination", "棒一"); // 棒一
|
|
|
+ mapSendInfo.put("billetHotsendTypeConfigId", btchid); // 目的地id
|
|
|
+ Map<String, Object> mapBe = JSON.parseObject(JSON.toJSONString(mapSendInfo), Map.class);
|
|
|
+ // 创建 MqttClientUtil 实例并调用非静态方法 pushCData
|
|
|
+ MqttClientUtil mqttClientUtilBe = new MqttClientUtil();
|
|
|
+ mqttClientUtilBe.pushCData(configMqttMapper, mapBe, "syn/billetHotsendBase/save");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成炉次实绩
|
|
|
+ * @param billetBasicInfo
|
|
|
+ */
|
|
|
+ private void sendHeatsActuals(BilletBasicInfo billetBasicInfo){
|
|
|
+ HeatsActuals heatsActuals = new HeatsActuals();
|
|
|
+ heatsActuals.setHeatsCode(billetBasicInfo.getHeatNo());
|
|
|
+ heatsActuals.setCasterCode(String.valueOf(billetBasicInfo.getCcmNo()));
|
|
|
+ heatsActuals.setStartPourTime(DateTime.now());
|
|
|
+ heatsActuals.setFullLadleWeight(0.00);
|
|
|
+ heatsActuals.setEmptyLadleWeight(0.00);
|
|
|
+ heatsActuals.setMoltenSteelWeight(0.00);
|
|
|
+ heatsActuals.setOptype("0");
|
|
|
+ // 将对象转换为 Map
|
|
|
+ Map<String, Object> map = JSON.parseObject(JSON.toJSONString(heatsActuals), Map.class);
|
|
|
+ // 创建 MqttClientUtil 实例并调用非静态方法 pushCData
|
|
|
+ MqttClientUtil mqttClientUtil = new MqttClientUtil();
|
|
|
+ mqttClientUtil.pushCData(configMqttMapper, map, "trace/performance/converter/add");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成唯一的坯号
|
|
|
+ *
|
|
|
+ * @return 坯号
|
|
|
+ */
|
|
|
+ private String generateUniqueBilletNo(Integer ccmNo, String heatNo) {
|
|
|
+ String billetNo;
|
|
|
+ do {
|
|
|
+ billetNo = heatNo + (int)(Math.random() * 10000);
|
|
|
+ } while (billetBasicInfoMapper.exists(new QueryWrapper<BilletBasicInfo>().eq("billet_no", billetNo). eq("ccm_no", ccmNo)));
|
|
|
+ return billetNo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成唯一的组坯号
|
|
|
+ *
|
|
|
+ * @return 坯号
|
|
|
+ */
|
|
|
+ private String generateUniqueAssemblyNumber(Integer ccmNo, String heatNo) {
|
|
|
+ String assembly_number;
|
|
|
+ do {
|
|
|
+ assembly_number = heatNo + (int)(Math.random() * 1000000);
|
|
|
+ } while (billetAssemblyNumberMapper.exists(new QueryWrapper<BilletAssemblyNumber>().eq("assembly_number", assembly_number). eq("ccm_no", ccmNo)));
|
|
|
+ return assembly_number;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void addC(BilletBasicInfo billetBasicInfo) {
|
|
|
LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>().eq(BilletBasicInfo::getBilletNo, billetBasicInfo.getBilletNo());
|
|
@@ -69,4 +312,9 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
|
|
|
queryWrapper.eq(BilletHotsendTypeConfig::getCastMachine, ccmNo);
|
|
|
return billetHotsendTypeConfigService.list(queryWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean exists(QueryWrapper<BilletBasicInfo> eq) {
|
|
|
+ return baseMapper.selectCount(eq) > 0;
|
|
|
+ }
|
|
|
}
|