ソースを参照

完善换炉接口以及向mqtt推送消息

lingpeng.li 3 週間 前
コミット
63984720e5

+ 38 - 36
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/controller/BilletHotsendBaseController.java

@@ -7,53 +7,55 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.modules.billetActual.entity.BilletHotsend;
+import org.jeecg.modules.billetActual.entity.FurnaceChangeData;
 import org.jeecg.modules.billetActual.service.IBilletHotsendBaseService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+
 /**
-* @Description: 钢坯热送基础信息
-* @Author: jeecg-boot
-* @Date:   2024-04-29
-* @Version: V1.0
-*/
-@Api(tags="钢坯热送基础信息")
+ * @Description: 钢坯热送基础信息
+ * @Author: jeecg-boot
+ * @Date: 2024-04-29
+ * @Version: V1.0
+ */
+@Api(tags = "钢坯热送基础信息")
 @RestController
 @RequestMapping("/billetHotsendBase/billetHotsendBase")
 @Slf4j
 public class BilletHotsendBaseController extends JeecgController<BilletHotsend, IBilletHotsendBaseService> {
 
-   @Autowired
-   private IBilletHotsendBaseService billetHotsendBaseService;
-
-   @ApiOperation(value="自动化新增5号机直轧棒1和6号机高线保存", notes="自动化新增5号机直轧棒1和6号机高线保存")
-   @PostMapping(value = "/autoAddRodLineCommon")
-   public Result<?> autoAddRodLineCommon(@RequestBody JSONObject jsonObject){
-      billetHotsendBaseService.autoAddRodLineCommon(jsonObject);
-      return Result.OK("自动化新增棒线测试成功!");
-   }
-
-   @ApiOperation(value="自动化5、6号机轧钢外运保存", notes="自动化5、6号机轧钢外运保存")
-   @PostMapping(value = "/autoAddRodLine")
-   public Result<?> autoAddRodLine(@RequestBody JSONObject jsonObject){
-      billetHotsendBaseService.autoAddRodLine(jsonObject);
-      return Result.OK("自动化新增棒线测试成功!");
-   }
-
-   @ApiOperation(value="自动化5、6号机轧钢外运轧钢外运直接发车", notes="自动化5、6号机轧钢外运轧钢外运直接发车")
-   @PostMapping(value = "/autoDirectDepart")
-   public Result<?> autoDirectDepart(@RequestBody JSONObject jsonObject){
-      billetHotsendBaseService.autoDepartTrucking(jsonObject);
-      return Result.OK("自动化轧钢外运直接发车成功!");
-   }
-
-   @ApiOperation(value="换炉推送消息", notes="换炉推送消息")
-   @PostMapping(value = "/furnaceChange")
-   public Result<?> furnaceChange(@RequestBody JSONObject jsonObject){
-      billetHotsendBaseService.furnaceChange(jsonObject);
-      return Result.OK("换炉推送消息成功!");
-   }
+    @Autowired
+    private IBilletHotsendBaseService billetHotsendBaseService;
+
+    @ApiOperation(value = "自动化新增5号机直轧棒1和6号机高线保存", notes = "自动化新增5号机直轧棒1和6号机高线保存")
+    @PostMapping(value = "/autoAddRodLineCommon")
+    public Result<?> autoAddRodLineCommon(@RequestBody JSONObject jsonObject) {
+        billetHotsendBaseService.autoAddRodLineCommon(jsonObject);
+        return Result.OK("自动化新增棒线测试成功!");
+    }
+
+    @ApiOperation(value = "自动化5、6号机轧钢外运保存", notes = "自动化5、6号机轧钢外运保存")
+    @PostMapping(value = "/autoAddRodLine")
+    public Result<?> autoAddRodLine(@RequestBody JSONObject jsonObject) {
+        billetHotsendBaseService.autoAddRodLine(jsonObject);
+        return Result.OK("自动化新增棒线测试成功!");
+    }
+
+    @ApiOperation(value = "自动化5、6号机轧钢外运轧钢外运直接发车", notes = "自动化5、6号机轧钢外运轧钢外运直接发车")
+    @PostMapping(value = "/autoDirectDepart")
+    public Result<?> autoDirectDepart(@RequestBody JSONObject jsonObject) {
+        billetHotsendBaseService.autoDepartTrucking(jsonObject);
+        return Result.OK("自动化轧钢外运直接发车成功!");
+    }
+
+    @ApiOperation(value = "换炉推送消息", notes = "换炉推送消息")
+    @PostMapping(value = "/furnaceChange")
+    public Result<?> furnaceChange(@RequestBody FurnaceChangeData data) {
+        billetHotsendBaseService.furnaceChange(data);
+        return Result.OK("换炉推送消息成功!");
+    }
 
 }

+ 16 - 0
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/entity/FurnaceChangeData.java

@@ -0,0 +1,16 @@
+package org.jeecg.modules.billetActual.entity;
+
+import lombok.Data;
+
+@Data
+public class FurnaceChangeData {
+
+    private String ccmNo;        // 铸机号
+    private String heatNo;       // 炉号
+    private String netWeight;    // 钢水毛重
+    private String ladleNo;      // 钢包号
+    private String grade;        // 钢种
+    private String startPourTime;// 开浇时间
+    private String spec;         // 规格
+    private String sendTime;     // 发送时间
+}

+ 2 - 1
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/IBilletHotsendBaseService.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.billetActual.service;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.billetActual.entity.BilletHotsend;
+import org.jeecg.modules.billetActual.entity.FurnaceChangeData;
 
 /**
  * @Description: 钢坯热送基础信息
@@ -18,5 +19,5 @@ public interface IBilletHotsendBaseService extends IService<BilletHotsend> {
 
     void autoDepartTrucking(JSONObject jsonObject);
 
-    void furnaceChange(JSONObject jsonObject);
+    void furnaceChange(FurnaceChangeData data);
 }

+ 56 - 27
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/impl/BilletHotsendBaseServiceImpl.java

@@ -7,6 +7,7 @@ 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.exception.JeecgBootException;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.billetActual.entity.*;
@@ -59,6 +60,8 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.math.BigDecimal;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
@@ -74,6 +77,8 @@ import java.util.stream.Collectors;
 @Slf4j
 public class BilletHotsendBaseServiceImpl extends ServiceImpl<BilletHotsendBaseMapper, BilletHotsend> implements IBilletHotsendBaseService {
 
+	private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
 	@Autowired
 	private IStorageCarLogService storageCarLogService;
 	@Autowired
@@ -549,33 +554,57 @@ public class BilletHotsendBaseServiceImpl extends ServiceImpl<BilletHotsendBaseM
 
 	}
 
-
-	@Override
-	public void furnaceChange(JSONObject jsonObject) {
-		String ccmNo = jsonObject.getString("ccmNo");// 铸机号
-		String heatNo = jsonObject.getString("heatNo");// 炉号
-		if (oConvertUtils.isEmpty(ccmNo) || oConvertUtils.isEmpty(heatNo)){
-			log.info("{}{}", "换炉的铸机号跟炉号不能为空", jsonObject);
-			return;
-		}
-		// 发送mqtt消息
-		sendFurnaceChangeToMqtt(ccmNo, heatNo);
-	}
-
-	public void sendFurnaceChangeToMqtt(String ccmNo, String heatNo) {
-		try {
-			Map<String, Object> mapSendInfo = new HashMap<>();
-			mapSendInfo.put("ccmNo", ccmNo);
-			mapSendInfo.put("heatNo", heatNo);
-
-			// 执行MQTT推送,设置合理的超时时间
-			MqttClientUtil mqttClientUtilBe = new MqttClientUtil();
-			mqttClientUtilBe.pushCData(configMqttMapper, mapSendInfo, TopicType.SYN_PUSHBILLETHOTSEND_NEXTSEND.getTopicValue());
-			log.info("B端传递换炉参数,发送MQTT成功: {}", mapSendInfo);
-		} catch (Exception e) {
-			log.error("B端传递换炉参数,发送MQTT异常!", e);
-		}
-	}
+    @Override
+    public void furnaceChange(FurnaceChangeData data) {
+        String ccmNo = data.getCcmNo();   // 铸机号
+        String heatNo = data.getHeatNo(); // 炉号
+        String startPourTime = data.getStartPourTime(); // 开浇时间
+        if (oConvertUtils.isEmpty(ccmNo) || oConvertUtils.isEmpty(heatNo) || oConvertUtils.isEmpty(startPourTime)) {
+            throw new JeecgBootException("换炉失败:铸机号或炉号或开浇时间不能为空!");
+        }
+
+        // 构建最终要传递的对象
+        FurnaceChangeData finalData = new FurnaceChangeData();
+        finalData.setCcmNo(ccmNo);
+        finalData.setHeatNo(heatNo);
+        finalData.setStartPourTime(startPourTime);
+        finalData.setNetWeight(data.getNetWeight());
+        finalData.setLadleNo(data.getLadleNo());
+        finalData.setGrade(data.getGrade());
+        finalData.setSpec(data.getSpec());
+        finalData.setSendTime(formatDate(new Date()));
+
+        // 发送mqtt消息
+        sendFurnaceChangeToMqtt(finalData);
+    }
+
+    public void sendFurnaceChangeToMqtt(FurnaceChangeData data) {
+        try {
+            Map<String, Object> mapSendInfo = new HashMap<>();
+            mapSendInfo.put("netWeight", data.getNetWeight());
+            mapSendInfo.put("ladleNo", data.getLadleNo());
+            mapSendInfo.put("heatNo", data.getHeatNo());
+            mapSendInfo.put("grade", data.getGrade());
+            mapSendInfo.put("startPourTime", data.getStartPourTime());
+            mapSendInfo.put("spec", data.getSpec());
+            mapSendInfo.put("ccmNo", data.getCcmNo());
+            mapSendInfo.put("sendTime", data.getSendTime());
+
+            // 执行MQTT推送,设置合理的超时时间
+            MqttClientUtil mqttClientUtilBe = new MqttClientUtil();
+            mqttClientUtilBe.pushCData(configMqttMapper, mapSendInfo, TopicType.SYN_PUSHBILLETHOTSEND_NEXTSEND.getTopicValue());
+            log.info("B端传递换炉参数,发送MQTT成功: {}", mapSendInfo);
+        } catch (Exception e) {
+            log.error("B端传递换炉参数,发送MQTT异常!", e);
+        }
+    }
+
+    private String formatDate(Date date) {
+        return date != null ? date.toInstant()
+                .atZone(ZoneId.systemDefault())
+                .toLocalDateTime()
+                .format(DATETIME_FORMATTER) : null;
+    }
 
 
 	/**