Browse Source

mqtt 钢坯

guoqiang 7 months ago
parent
commit
b0f65fc2f8

+ 24 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/controller/BilletBasicInfoController.java

@@ -0,0 +1,24 @@
+package org.jeecg.modules.billetActual.controller;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.modules.billetActual.entity.BilletBasicInfo;
+import org.jeecg.modules.billetActual.service.IBilletBasicInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import io.swagger.annotations.Api;
+
+ /**
+ * @Description: 钢坯基础信息
+ * @Author: jeecg-boot
+ * @Date:   2024-05-16
+ * @Version: V1.0
+ */
+@Api(tags="钢坯基础信息")
+@RestController
+@RequestMapping("/actualControl/billetActual")
+@Slf4j
+public class BilletBasicInfoController extends JeecgController<BilletBasicInfo, IBilletBasicInfoService> {
+	@Autowired
+	private IBilletBasicInfoService billetBasicInfoService;
+}

+ 335 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/entity/BilletBasicInfo.java

@@ -0,0 +1,335 @@
+package org.jeecg.modules.billetActual.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @Description: 钢坯基础信息
+ * @Author: jeecg-boot
+ * @Date:   2024-05-16
+ * @Version: V1.0
+ */
+@TableName("billet_basic_info")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="billet_basic_info对象", description="铸坯实绩")
+public class BilletBasicInfo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+	/**主键*/
+	@TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "主键")
+    private String id;
+	/**创建人*/
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+	/**创建日期*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建日期")
+    private Date createTime;
+	/**更新人*/
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+	/**更新日期*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "更新日期")
+    private Date updateTime;
+	/**所属部门*/
+    @ApiModelProperty(value = "所属部门")
+    private String sysOrgCode;
+	/**炉号*/
+	@Excel(name = "炉号", width = 15)
+    @ApiModelProperty(value = "炉号",required = true)
+    private String heatNo;
+	/**铸机号*/
+	@Excel(name = "铸机号", width = 15)
+    @ApiModelProperty(value = "铸机号",required = true)
+    private Integer ccmNo;
+    /**流号*/
+    @Excel(name = "流号", width = 15)
+    @ApiModelProperty(value = "流号",required = true)
+    private Integer strandNo;
+    /**流号*/
+    @Excel(name = "拉速", width = 15)
+    @ApiModelProperty(value = "拉速",required = true)
+    private Integer castingSpeed;
+	/**流号*/
+	@Excel(name = "钢包号", width = 15)
+    @ApiModelProperty(value = "钢包号",required = true)
+    private Integer ladleNo;
+	/**支号*/
+	@Excel(name = "炉内顺序号", width = 15)
+    @ApiModelProperty(value = "炉内顺序号",required = true)
+    private Integer heatnoIndex;
+	/**钢种*/
+	@Excel(name = "钢种", width = 15)
+    @ApiModelProperty(value = "钢种",required = true)
+    private String grade;
+	/**定尺*/
+	@Excel(name = "定尺", width = 15)
+    @ApiModelProperty(value = "定尺",required = true)
+    private Integer length;
+	/**实际长度*/
+	@Excel(name = "实际长度", width = 15)
+    @ApiModelProperty(value = "实际长度",required = true)
+    private Integer actualLength;
+	/**宽度*/
+	@Excel(name = "宽度", width = 15)
+    @ApiModelProperty(value = "宽度",required = true)
+    private Integer width;
+	/**厚度*/
+	@Excel(name = "厚度", width = 15)
+    @ApiModelProperty(value = "厚度",required = true)
+    private Integer thickness;
+	/**规格*/
+	@Excel(name = "规格", width = 15)
+    @ApiModelProperty(value = "规格",required = true)
+    private String spec;
+	/**定重*/
+	@Excel(name = "定重", width = 15)
+    @ApiModelProperty(value = "定重",required = true)
+    private Float weight;
+	/**坯号*/
+	@Excel(name = "坯号", width = 15)
+    @ApiModelProperty(value = "坯号",required = true)
+    private String billetNo;
+    /**顺序号*/
+    @Excel(name = "流内顺序号", width = 15)
+    @ApiModelProperty(value = "流内顺序号",required = true)
+    private Integer strandnoIndex;
+    /**开始切割时间*/
+    @Excel(name = "开始切割时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "开始切割时间",required = true)
+    private Date cutStartTime;
+    /**停止切割时间*/
+    @Excel(name = "停止切割时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "停止切割时间",required = true)
+    private Date cutStopTime;
+    /**判级结果*/
+    @Excel(name = "判级结果", width = 15)
+    @ApiModelProperty(value = "判级结果",required = true)
+    private String ratingsResult;
+
+    public BilletBasicInfo() {
+    }
+
+    /**堆垛或车位关联id*/
+//    @Excel(name = "堆垛或车位关联id", width = 15)
+//    @ApiModelProperty(value = "堆垛或车位关联id")
+//    private String stackOrCarId;
+
+
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getCreateBy() {
+        return createBy;
+    }
+
+    public void setCreateBy(String createBy) {
+        this.createBy = createBy;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getUpdateBy() {
+        return updateBy;
+    }
+
+    public void setUpdateBy(String updateBy) {
+        this.updateBy = updateBy;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public String getSysOrgCode() {
+        return sysOrgCode;
+    }
+
+    public void setSysOrgCode(String sysOrgCode) {
+        this.sysOrgCode = sysOrgCode;
+    }
+
+    public String getHeatNo() {
+        return heatNo;
+    }
+
+    public void setHeatNo(String heatNo) {
+        this.heatNo = heatNo;
+    }
+
+    public Integer getCcmNo() {
+        return ccmNo;
+    }
+
+    public void setCcmNo(Integer ccmNo) {
+        this.ccmNo = ccmNo;
+    }
+
+    public Integer getStrandNo() {
+        return strandNo;
+    }
+
+    public void setStrandNo(Integer strandNo) {
+        this.strandNo = strandNo;
+    }
+
+    public Integer getLadleNo() {
+        return ladleNo;
+    }
+
+    public void setLadleNo(Integer ladleNo) {
+        this.ladleNo = ladleNo;
+    }
+
+    public Integer getCastingSpeed() {
+        return castingSpeed;
+    }
+
+    public void setCastingSpeed(Integer castingSpeed) {
+        this.castingSpeed = castingSpeed;
+    }
+
+    public Integer getHeatnoIndex() {
+        return heatnoIndex;
+    }
+
+    public void setHeatnoIndex(Integer heatnoIndex) {
+        this.heatnoIndex = heatnoIndex;
+    }
+
+    public String getGrade() {
+        return grade;
+    }
+
+    public void setGrade(String grade) {
+        this.grade = grade;
+    }
+
+    public Integer getLength() {
+        return length;
+    }
+
+    public void setLength(Integer length) {
+        this.length = length;
+    }
+
+    public Integer getActualLength() {
+        return actualLength;
+    }
+
+    public void setActualLength(Integer actualLength) {
+        this.actualLength = actualLength;
+    }
+
+    public Integer getWidth() {
+        return width;
+    }
+
+    public void setWidth(Integer width) {
+        this.width = width;
+    }
+
+    public Integer getThickness() {
+        return thickness;
+    }
+
+    public void setThickness(Integer thickness) {
+        this.thickness = thickness;
+    }
+
+    public String getSpec() {
+        return spec;
+    }
+
+    public void setSpec(String spec) {
+        this.spec = spec;
+    }
+
+    public Float getWeight() {
+        return weight;
+    }
+
+    public void setWeight(Float weight) {
+        this.weight = weight;
+    }
+
+    public String getBilletNo() {
+        return billetNo;
+    }
+
+    public void setBilletNo(String billetNo) {
+        this.billetNo = billetNo;
+    }
+
+    public Integer getStrandnoIndex() {
+        return strandnoIndex;
+    }
+
+    public void setStrandnoIndex(Integer strandnoIndex) {
+        this.strandnoIndex = strandnoIndex;
+    }
+
+    public Date getCutStartTime() {
+        return cutStartTime;
+    }
+
+    public void setCutStartTime(Date cutStartTime) {
+        this.cutStartTime = cutStartTime;
+    }
+
+    public Date getCutStopTime() {
+        return cutStopTime;
+    }
+
+    public void setCutStopTime(Date cutStopTime) {
+        this.cutStopTime = cutStopTime;
+    }
+
+    public String getRatingsResult() {
+        return ratingsResult;
+    }
+
+    public void setRatingsResult(String ratingsResult) {
+        this.ratingsResult = ratingsResult;
+    }
+}

+ 14 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/mapper/BilletBasicInfoMapper.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.billetActual.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.billetActual.entity.BilletBasicInfo;
+
+/**
+ * @Description: 钢坯基础信息
+ * @Author: jeecg-boot
+ * @Date:   2024-05-16
+ * @Version: V1.0
+ */
+public interface BilletBasicInfoMapper extends BaseMapper<BilletBasicInfo> {
+
+}

+ 5 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/mapper/xml/BilletBasicInfoMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletBasicInfoMapper">
+
+</mapper>

+ 16 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/IBilletBasicInfoService.java

@@ -0,0 +1,16 @@
+package org.jeecg.modules.billetActual.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.billetActual.entity.BilletBasicInfo;
+
+/**
+ * @Description: 钢坯基础信息
+ * @Author: jeecg-boot
+ * @Date:   2024-05-16
+ * @Version: V1.0
+ */
+public interface IBilletBasicInfoService extends IService<BilletBasicInfo> {
+
+    void addC(BilletBasicInfo billetBasicInfo);
+}

+ 33 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/impl/BilletBasicInfoServiceImpl.java

@@ -0,0 +1,33 @@
+package org.jeecg.modules.billetActual.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.billetActual.entity.BilletBasicInfo;
+import org.jeecg.modules.billetActual.mapper.BilletBasicInfoMapper;
+import org.jeecg.modules.billetActual.service.IBilletBasicInfoService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description: 钢坯基础信息
+ * @Author: jeecg-boot
+ * @Date:   2024-05-16
+ * @Version: V1.0
+ */
+@Service
+public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMapper, BilletBasicInfo> implements IBilletBasicInfoService {
+
+    @Override
+    public void addC(BilletBasicInfo billetBasicInfo) {
+        LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>().eq(BilletBasicInfo::getBilletNo, billetBasicInfo.getBilletNo());
+        BilletBasicInfo basicInfo = baseMapper.selectOne(queryWrapper);
+        if(oConvertUtils.isNotEmpty(basicInfo)&&oConvertUtils.isNotEmpty(basicInfo.getId())){
+            billetBasicInfo.setId(basicInfo.getId());
+            baseMapper.updateById(billetBasicInfo);
+        }else {
+            baseMapper.insert(billetBasicInfo);
+        }
+    }
+
+
+}

+ 13 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/push/utils/MqttClientCallback.java

@@ -2,8 +2,11 @@ package org.jeecg.modules.push.utils;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import lombok.extern.slf4j.Slf4j;
+import net.sf.json.JSONObject;
 import org.eclipse.paho.client.mqttv3.*;
 import org.jeecg.common.util.SpringContextHolder;
+import org.jeecg.modules.billetActual.entity.BilletBasicInfo;
+import org.jeecg.modules.billetActual.service.IBilletBasicInfoService;
 import org.jeecg.modules.connConfig.configMqtt.entity.MqttMsg;
 import org.jeecg.modules.connConfig.configMqtt.mapper.MqttMsgMapper;
 import org.springframework.data.mongodb.core.MongoTemplate;
@@ -41,6 +44,8 @@ public class MqttClientCallback implements MqttCallback, MqttCallbackExtended{
 
     private MongoTemplate mongoTemplate = SpringContextHolder.getBean(MongoTemplate.class);
 
+    private IBilletBasicInfoService billetBasicInfoService = SpringContextHolder.getBean(IBilletBasicInfoService.class);
+
     /**
      * MQTT 断开连接会执行此方法
      */
@@ -89,6 +94,14 @@ public class MqttClientCallback implements MqttCallback, MqttCallbackExtended{
         LambdaQueryWrapper<MqttMsg> eq = new LambdaQueryWrapper<MqttMsg>().eq(MqttMsg::getTopic, topic);
         mqttMsgMapper.delete(eq);
         mqttMsgMapper.insert(mqttMsg);
+        JSONObject jsonObject = JSONObject.fromObject(message.toString());
+        log.info("铸坯实绩");
+        // 铸坯实绩
+        if(topic.contains("trace/performance/billet/add")){
+            BilletBasicInfo billetBasicInfo = (BilletBasicInfo) JSONObject.toBean(jsonObject, BilletBasicInfo.class);
+            billetBasicInfoService.addC(billetBasicInfo);
+            return;
+        }
     }
 
     @Override

+ 70 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/watch/MqttGatherWatch.java

@@ -0,0 +1,70 @@
+package org.jeecg.modules.watch;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.paho.client.mqttv3.MqttClient;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.jeecg.modules.connConfig.configMqtt.entity.ConfigMqtt;
+import org.jeecg.modules.connConfig.configMqtt.mapper.ConfigMqttMapper;
+import org.jeecg.modules.push.utils.MqttClientUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@EnableAsync
+@Component
+@EnableScheduling
+public class MqttGatherWatch {
+
+    @Autowired
+    ConfigMqttMapper configMqttMapper;
+
+    @Autowired
+    MqttClientUtil mqttClientUtil;
+
+
+    @Scheduled(fixedDelay = 60000)
+    public void mqttWatch(){
+        mqtt();
+    }
+
+
+    //mqtt连接状态监测
+    public void mqtt(){
+        //获取所有需要订阅的mqtt配置
+        LambdaQueryWrapper<ConfigMqtt> eq = new LambdaQueryWrapper<ConfigMqtt>().ne(ConfigMqtt::getPushOrSub,"0");
+        List<ConfigMqtt> configMqtts = configMqttMapper.selectList(eq);
+        //遍历
+        for (ConfigMqtt configMqtt : configMqtts) {
+            //创建mqtt连接url
+            StringBuffer url = new StringBuffer();
+            url.append("tcp://").append(configMqtt.getIp()).append(":").append(configMqtt.getHost());
+            try {
+                //根据url从连接缓存池中拿去连接对象
+                MqttClient client = mqttClientUtil.mqttClients.get(url.toString());
+                //连接对象为空则说明并未订阅
+                if(client == null){
+                    //mqtt订阅操作
+                    mqttClientUtil.sub(configMqtt);
+                }else{
+                    //检测mqtt状态是否正常
+                    if(!client.isConnected()){
+                        //从连接缓存池中移除该连接
+                        mqttClientUtil.mqttClients.remove(url);
+                        //重新订阅
+                        mqttClientUtil.sub(configMqtt);
+                    }
+                }
+            } catch (MqttException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+}

+ 1 - 1
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/OpcGatherWatch.java

@@ -23,7 +23,7 @@ import java.util.List;
 @Slf4j
 @EnableAsync
 @Component
-@EnableScheduling
+//@EnableScheduling
 public class OpcGatherWatch {
 
     @Autowired

+ 2 - 0
jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

@@ -170,8 +170,10 @@ spring:
       datasource:
         master:
           url: jdbc:mysql://127.0.0.1:3306/lg?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+#          url: jdbc:mysql://123.57.213.14:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
           username: root
           password: '@qwe@123'
+#          password: 1qaz2wsx@..
           driver-class-name: com.mysql.cj.jdbc.Driver
           # 多数据源配置
           #multi-datasource1: