浏览代码

feat:"修改设备参数更改为MQTT"

soobin 5 天之前
父节点
当前提交
c05320a584

+ 1 - 1
src/main/java/com/szwl/aspect/MyWebMvcConfigurer.java

@@ -76,7 +76,7 @@ public class MyWebMvcConfigurer extends WebMvcConfigurationSupport {
         for (String path : new String[]{
                 "/tAdmin/getAdminList", "/tAdmin/getRelation",
                 "/tJoinpayMch/getOne",
-                "/tEquipment/findList",
+                "/tEquipment/list",
                 "/v2/api-docs","/tAdmin/getAdminOne/**",
                 "/tAdmin/getAdminVo",
                 "/tAdmin/getAdminByUsername","/tAdmin/getIdIfForeign", "/tAdmin/pageAdmin2"

+ 3 - 1
src/main/java/com/szwl/constant/OperationType.java

@@ -36,7 +36,9 @@ public enum OperationType implements IEnum<String> {
     OFFLINE("tuoji","脱机"),
     SLEEP_DESC("sleepDesc","修改睡眠描述"),
     UPDATE_LOGO("updateLogo","修改logo"),
-    PUSH_TIME_RULE("pushTimeRule","推送广告规则");
+    PUSH_TIME_RULE("pushTimeRule","推送广告规则"),
+    PARAM("Param", "参数设置"),
+    HUMIDITY_PARAMETERS("humidityParameters", "湿度参数");
 
     private String code;
 

+ 6 - 9
src/main/java/com/szwl/controller/IndexController.java

@@ -325,9 +325,8 @@ public class IndexController {
         String status = "0";
         LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
         query.like(TEquipment::getClientId, clientId);
-        List<TEquipment> list = equipmentService.list(query);
-        if (!list.isEmpty()) {
-            TEquipment equipment = list.get(0);
+        TEquipment equipment = equipmentService.getOne(query);
+        if (equipment != null) {
             if (equipment.getAdminId() != 31) {
                 if (!equipment.getClientId().substring(equipment.getClientId().length() - 3, equipment.getClientId().length()).equals("xxx")) {
                     String managerId1 = equipment.getManagerId();
@@ -347,7 +346,7 @@ public class IndexController {
         }
         LambdaQueryWrapper<TEquipmentApply> query1 = Wrappers.lambdaQuery();
         query1.eq(TEquipmentApply::getClientId, clientId);
-        query1.eq(TEquipmentApply::getStatusType, "1");
+        query1.eq(TEquipmentApply::getStatusType, 1);
         query1.eq(TEquipmentApply::getManagerId, managerId);
         String dateStr = "2022-12-28 00:00:00";
         //获得SimpleDateFormat类,我们转换为yyyy-MM-dd的时间格式
@@ -359,8 +358,8 @@ public class IndexController {
         } catch (ParseException e) {
             e.printStackTrace();
         }
-        List<TEquipmentApply> list1 = equipmentApplyService.list(query1);
-        if (list1.size() > 0) {
+        TEquipmentApply equipmentApplyOnly = equipmentApplyService.getOnly(query1);
+        if (equipmentApplyOnly != null) {
             return "重复申请";
         }
         TEquipmentApply equipmentApply = new TEquipmentApply();
@@ -1900,7 +1899,7 @@ public class IndexController {
             //旧优惠码
             return "0";
         }
-        if (promoCode.getDiscount() == 0) {
+        if (promoCode.getDiscount().equals(0)) {
             //0折
             return "0";
         }
@@ -2342,8 +2341,6 @@ public class IndexController {
                     }
                 }
             }
-//            if (equipmentDesc.getLanguage() == null || !(equipmentDesc.getLanguage().equals(language))) {
-//            }
             return "success";
         }
         return "fail";

文件差异内容过多而无法显示
+ 86 - 948
src/main/java/com/szwl/controller/TEquipmentController.java


+ 1 - 62
src/main/java/com/szwl/controller/TParametersController.java

@@ -101,68 +101,7 @@ public class TParametersController {
                         .setData("SUCCESS")
                         .setMessage("SUCCESS"));
     }
-
-
-//    @ApiOperation(value = "启用物料监控")
-//    @PostMapping("/enableMaterial")
-//    public ResponseModel<?> enableMaterial(@RequestBody TParameters parameters) {
-//        Long equipmentId = parameters.getEquipmentId();
-//        if (equipmentId == null) {
-//            return R.fail(ResponseCodesEnum.A0001, "设备id不能为空");
-//        }
-////        TParameters tParameters = tParametersService.getById(equipmentId);
-////        if (Objects.isNull(tParameters)) {
-////            TParameters tParameters1 = new TParameters();
-////        }
-//        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
-//        if (Objects.isNull(equipmentDesc)) {
-//            TEquipmentDesc tEquipmentDesc = new TEquipmentDesc();
-//            tEquipmentDesc.setEquipmentId(equipmentId);
-//            tEquipmentDesc.setIsMaterialUse("1");
-//            equipmentDescService.saveOrUpdate(tEquipmentDesc);
-//        } else {
-//            String isMaterialUse = equipmentDesc.getIsMaterialUse();
-//            if (StringUtils.isNotEmpty(isMaterialUse) && "1".equals(isMaterialUse)) {
-//                return R.ok(ResponseCodesEnum.ALL_OK, "已开启ENABLED");
-//            }
-//            equipmentDesc.setIsMaterialUse("1");
-//            equipmentDescService.saveOrUpdate(equipmentDesc);
-//        }
-//
-//        TEquipment equipment = tEquipmentService.getById(equipmentId);
-//        tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", "M502" + ":" + "1").toString());
-//
-//        return R.ok(ResponseCodesEnum.ALL_OK, "已发送Send");
-//    }
-
-    @ApiOperation(value = "物料监控")
-    @PostMapping("/enableMaterial")
-    public ResponseModel<?> enableMaterial(@RequestBody TParameters parameters) {
-        Long equipmentId = parameters.getEquipmentId();
-        if (equipmentId == null) {
-            return R.fail(ResponseCodesEnum.A0001, "设备id不能为空");
-        }
-        String materialMonitorStatus = parameters.getMaterialMonitorStatus();
-
-        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
-        if (Objects.isNull(equipmentDesc)) {
-            TEquipmentDesc tEquipmentDesc = new TEquipmentDesc();
-            tEquipmentDesc.setEquipmentId(equipmentId);
-            tEquipmentDesc.setIsMaterialUse("0"); // 默认未启用
-            equipmentDescService.saveOrUpdate(tEquipmentDesc);
-        }
-        TEquipment equipment = tEquipmentService.getById(equipmentId);
-        if ("1".equals(materialMonitorStatus)) { // 当前是开启状态,用户点击后通知关闭
-//            equipmentDesc.setIsMaterialUse("0");
-            tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", "M502" + ":" + "0").toString());
-            return R.ok(ResponseCodesEnum.ALL_OK, "已通知关闭");
-        } else { // 当前是未开启状态,用户点击后通知启用
-//            equipmentDesc.setIsMaterialUse("1");
-            tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", "M502" + ":" + "1").toString());
-            return R.ok(ResponseCodesEnum.ALL_OK, "已通知开启");
-        }
-
-    }
+    
 
 }
 

+ 5 - 5
src/main/java/com/szwl/controller/TPromoCodeController.java

@@ -210,7 +210,7 @@ public class TPromoCodeController {
             promoCode.setCode(Long.parseLong(code));
             promoCode.setAdminId(adminId);
             promoCode.setIsUse("0");
-            promoCode.setDiscount(0f);
+            promoCode.setDiscount(new BigDecimal(0));
             promoCode.setLastUseDate(lastUseDate);
             promoCode.setType("0");
             promoCode.setUserName(admin.getUsername());
@@ -244,7 +244,7 @@ public class TPromoCodeController {
         if (price > 100) {
             return R.fail(A0001);
         }
-        promoCode.setDiscount(Float.valueOf(price));
+        promoCode.setDiscount(new BigDecimal(price));
         promoCode.setType("2");
         Long data = Calendar.getInstance().getTimeInMillis();
         Long t = 3l;
@@ -326,7 +326,7 @@ public class TPromoCodeController {
     @ApiOperation(value = "添加优惠码")
     @GetMapping("/add")
     public ResponseModel<?> add(String addMode, String codeNum,
-                                Long adminId, int number, Float discount,
+                                Long adminId, int number, BigDecimal discount,
                                 Float month, String type, String frpCode) {
         if (discount == null || month == null || adminId == null || StringUtils.isEmpty(type)) {
             return R.fail(A0001);
@@ -403,7 +403,7 @@ public class TPromoCodeController {
             return R.fail("没有机器");
         }
         //0折优惠码需要支付
-        if (type.equals("0") && discount == 0) {
+        if (type.equals("0") && discount.equals(0)) {
             if (admin.getPromoCodeOpen() == null || admin.getPromoCodeOpen().equals("1")) {
                 Long equipmentId = equipment.getId();
                 Double money = null;
@@ -812,7 +812,7 @@ public class TPromoCodeController {
                 return null;
             }
             TPromoCode promoCode = list.get(0);
-            Float discount = promoCode.getDiscount();
+            BigDecimal discount = promoCode.getDiscount();
             String type = promoCode.getType();
             JSONObject kindData = new JSONObject();
             kindData.put("type", type.equals("1") ? type : "0");

+ 3 - 2
src/main/java/com/szwl/handle/ResponseMessageHandler.java

@@ -21,7 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 @Slf4j
 @Component
-public class ResponseMessageHandler implements MqttMessageHandler{
+public class ResponseMessageHandler implements MqttMessageHandler {
 
     @Resource
     private MessageLogService messageLogService;
@@ -49,7 +49,8 @@ public class ResponseMessageHandler implements MqttMessageHandler{
             Integer direction = messageLog.getDirection();
             if (direction != null && direction == 2) {
                 // 3. 主动上报消息,直接添加消息日志
-                if(!operationType.equals(OperationType.HEART.getCode())) {
+                if (!operationType.equals(OperationType.HEART.getCode())
+                        || !operationType.equals(OperationType.MACHINE_STATUS.getCode())) {
                     // 心跳不需要保存消息日志
                     messageLog.setMsgId(System.currentTimeMillis() + RandomUtil.randomNumbers(10));
                     messageLog.setCreatedAt(new Date());

+ 0 - 1
src/main/java/com/szwl/handle/response/LogMessageProcessor.java

@@ -49,7 +49,6 @@ public class LogMessageProcessor implements ResponseProcessor {
                 sendExecutor.execute(() -> {
                     // 推送消息
                     try {
-//                        equipmentService.sendRemoteMessage(clientId, OperationType.LOG, message, equipment.getAdminId());
                         equipmentService.responseSendMessage(messageLog, message, equipment.getAdminId());
                     } catch (Exception e) {
                         e.printStackTrace();

+ 73 - 0
src/main/java/com/szwl/handle/response/ParamProcessor.java

@@ -0,0 +1,73 @@
+package com.szwl.handle.response;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.szwl.constant.OperationType;
+import com.szwl.model.entity.MessageLog;
+import com.szwl.model.entity.TEquipment;
+import com.szwl.model.entity.TParameters;
+import com.szwl.service.TEquipmentService;
+import com.szwl.service.TParametersService;
+import org.apache.commons.math3.stat.descriptive.summary.Product;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class ParamProcessor implements ResponseProcessor {
+
+    @Autowired
+    private TEquipmentService tEquipmentService;
+
+    @Autowired
+    private TParametersService tParametersService;
+
+    @Override
+    public void process(MessageLog messageLog) {
+        Integer statusCode = messageLog.getStatusCode();
+        if (statusCode == 200) {
+            String clientId = messageLog.getClientId();
+            String responseContent = messageLog.getResponseContent();
+            LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
+            query.eq(TEquipment::getClientId, clientId);
+            TEquipment tEquipment = tEquipmentService.getOne(query);
+            if (tEquipment != null) {
+                try {
+                    // 转换为对象
+                    ObjectMapper objectMapper = new ObjectMapper();
+                    List<TParameters> tParameters = objectMapper.readValue(responseContent, new TypeReference<List<TParameters>>() {
+                    });
+                    for (TParameters tParameter : tParameters) {
+                        LambdaQueryWrapper<TParameters> queryWrapper = Wrappers.lambdaQuery();
+                        queryWrapper.eq(TParameters::getClientId, clientId);
+                        queryWrapper.eq(TParameters::getName, tParameter.getName());
+                        TParameters parameters = tParametersService.getOne(queryWrapper);
+                        if (parameters != null) {
+                            // 如果已存在参数
+                            parameters.setVal(tParameter.getVal());
+                            parameters.setModifyDate(new Date());
+                            tParametersService.updateById(parameters);
+                        } else {
+                            tParameter.setEquipmentId(tEquipment.getId());
+                            tParameter.setClientId(clientId);
+                            tParameter.setCreateDate(new Date());
+                            tParameter.setModifyDate(new Date());
+                            tParametersService.save(tParameter);
+                        }
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    @Override
+    public String getSupportedOperationType() {
+        return OperationType.PARAM.getCode();
+    }
+}

+ 3 - 48
src/main/java/com/szwl/model/bean/CommonParamVo.java

@@ -1,8 +1,11 @@
 package com.szwl.model.bean;
 
 
+import lombok.Data;
+
 import java.util.List;
 
+@Data
 public class CommonParamVo {
 
     private String name;
@@ -19,52 +22,4 @@ public class CommonParamVo {
 
     private String clientId;
 
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-
-    public String getClientId() {
-        return clientId;
-    }
-
-    public void setClientId(String clientId) {
-        this.clientId = clientId;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getVal() {
-        return val;
-    }
-
-    public void setVal(String val) {
-        this.val = val;
-    }
-
-    public List<CommonParamVo> getCommonParamVos() {
-        return commonParamVos;
-    }
-
-    public void setCommonParamVos(List<CommonParamVo> commonParamVos) {
-        this.commonParamVos = commonParamVos;
-    }
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
 }

+ 4 - 65
src/main/java/com/szwl/model/dto/PromoCodeTarget.java

@@ -1,13 +1,16 @@
 package com.szwl.model.dto;
 
 import cn.afterturn.easypoi.excel.annotation.Excel;
+import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
  * 国内优惠码导出
  * @author
  */
+@Data
 public class PromoCodeTarget {
 
     /**
@@ -26,7 +29,7 @@ public class PromoCodeTarget {
      * 优惠码类型
      */
     @Excel(name = "优惠码折扣/抵扣", width = 20.0D)
-    private Float discount;
+    private BigDecimal discount;
 
 
     /**
@@ -59,68 +62,4 @@ public class PromoCodeTarget {
      */
     @Excel(name = "使用机器", width = 20.0D)
     private String useBy;
-
-    public Long getCode() {
-        return code;
-    }
-
-    public void setCode(Long code) {
-        this.code = code;
-    }
-
-    public String getUserName() {
-        return userName;
-    }
-
-    public void setUserName(String userName) {
-        this.userName = userName;
-    }
-
-    public String getIsUse() {
-        return isUse;
-    }
-
-    public void setIsUse(String isUse) {
-        this.isUse = isUse;
-    }
-
-    public String getUseDate() {
-        return useDate;
-    }
-
-    public void setUseDate(String useDate) {
-        this.useDate = useDate;
-    }
-
-    public String getUseBy() {
-        return useBy;
-    }
-
-    public void setUseBy(String useBy) {
-        this.useBy = useBy;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public Float getDiscount() {
-        return discount;
-    }
-
-    public void setDiscount(Float discount) {
-        this.discount = discount;
-    }
-
-    public String getCreateDate() {
-        return createDate;
-    }
-
-    public void setCreateDate(String createDate) {
-        this.createDate = createDate;
-    }
 }

+ 3 - 1
src/main/java/com/szwl/model/dto/PromoCodeTargetEn.java

@@ -3,6 +3,8 @@ package com.szwl.model.dto;
 import cn.afterturn.easypoi.excel.annotation.Excel;
 import lombok.Data;
 
+import java.math.BigDecimal;
+
 /**
  * 国外优惠码导出
  * @author
@@ -26,7 +28,7 @@ public class PromoCodeTargetEn {
      * 优惠码类型
      */
     @Excel(name = "Credit/Discount value", width = 30.0D)
-    private Float discount;
+    private BigDecimal discount;
 
     /**
      * 所属商家

+ 3 - 1
src/main/java/com/szwl/model/entity/TPromoCode.java

@@ -1,6 +1,8 @@
 package com.szwl.model.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+
+import java.math.BigDecimal;
 import java.util.Date;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.io.Serializable;
@@ -52,7 +54,7 @@ public class TPromoCode implements Serializable {
     private Date lastUseDate;
 
     @ApiModelProperty(value = "优惠码折扣;")
-    private Float discount;
+    private BigDecimal discount;
 
     @ApiModelProperty(value = "类型,0或null:折扣优惠码;1:抵扣价优惠码;2:5元折扣优惠码")
     private String type;