Pārlūkot izejas kodu

fix:"修复MQ消息乱码的问题"

soobin 3 mēneši atpakaļ
vecāks
revīzija
5990285265

+ 20 - 5
src/main/java/com/szwl/controller/TEquipmentDescController.java

@@ -14,11 +14,7 @@ import com.szwl.service.TEquipmentService;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -72,6 +68,25 @@ public class TEquipmentDescController {
         return R.ok("修改成功");
     }
 
+    @ApiOperation(value = "修改睡眠描述")
+    @GetMapping("/changeSleepDesc")
+    public ResponseModel<?> changeSleepDesc(@RequestBody TEquipmentDesc equipmentDesc) {
+        TEquipment equipment = tEquipmentService.getById(equipmentDesc.getEquipmentId());
+        if (equipment == null || equipment.getId() == null) {
+            return R.fail(ResponseCodesEnum.A0001, "找不到设备");
+        }
+        TEquipmentDesc tEquipmentDesc = equipmentDescService.getById(equipment.getId());
+        if (tEquipmentDesc != null) {
+            String sleepDesc = equipmentDesc.getSleepDesc();
+            tEquipmentDesc.setSleepDesc(sleepDesc);
+            equipmentDescService.updateById(tEquipmentDesc);
+            tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("sleepDesc", sleepDesc).toString());
+        } else {
+            return R.fail(ResponseCodesEnum.A0001, "找不到设备");
+        }
+        return R.ok("修改成功");
+    }
+
     @ApiOperation("开启或关闭清洗功能")
     @GetMapping("/updateCleanFunction")
     public ResponseModel<?> updateCleanFunction(String equipmentId, String cleanFunction) {

+ 1 - 2
src/main/java/com/szwl/controller/TLocationCheckController.java

@@ -173,7 +173,6 @@ public class TLocationCheckController {
     String username = locationCheck.getUsername();
     String clientId = locationCheck.getClientId();
     String country = locationCheck.getCountry(); // 国家
-//        String location = locationCheck.getLocation(); // 地区
 
     if (Objects.isNull(clientId)) {
       return R.fail("设备唯一码不能为空");
@@ -187,7 +186,7 @@ public class TLocationCheckController {
 
     Set<String> allowedUsers = new HashSet<>(
         Arrays.asList("sysMgtAcc", "jiang123", "shouhou121", "shouhou369", "shouhou397",
-            "shouhoumi", "zhl123", "ethan"));
+            "shouhoumi", "zhl123", "ethan", "debugUser"));
     if (!allowedUsers.contains(username)) {
       return R.fail("该账号无权操作");
     }

+ 1 - 0
src/main/java/com/szwl/controller/TProductController.java

@@ -71,6 +71,7 @@ public class TProductController {
         }
         LambdaQueryWrapper<TProduct> query = Wrappers.lambdaQuery();
         query.eq(TProduct::getEquipmentId,Long.valueOf(equipmentId));
+        query.orderByAsc(TProduct::getNo);
         List<TProduct> list = tProductService.list(query);
         return ResponseEntity.status(HttpStatus.OK)
                 .body(new ResultMessage().setCode(true).setData(list).setMessage("SUCCESS"));

+ 27 - 20
src/main/java/com/szwl/service/impl/TEquipmentServiceImpl.java

@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
@@ -32,7 +33,7 @@ import java.util.stream.Collectors;
 
 /**
  * <p>
- *  服务实现类
+ * 服务实现类
  * </p>
  *
  * @author wuhs
@@ -62,7 +63,7 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
     @Resource
     TWechatService wechatService;
 
-//    @Resource
+    //    @Resource
 //    private MqttService mqttService;
     private final MqttService mqttService;
 
@@ -79,9 +80,9 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
     @Override
     public String sentMessage(String clientId, String json) {
         LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
-        query.eq(TEquipment::getClientId,clientId);
+        query.eq(TEquipment::getClientId, clientId);
         List<TEquipment> equipmentList = tEquipmentMapper.selectList(query);
-        if(equipmentList.size()==0){
+        if (equipmentList.size() == 0) {
             return "该设备不存在";
         }
         TEquipment equipment = equipmentList.get(0);
@@ -90,16 +91,21 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
         }
         String channel = equipment.getChannel();
         String equimentType = equipment.getEquimentType();
-        if(StringUtils.isEmpty(channel)||channel.equals("1")||StringUtils.isEmpty(equimentType)){
+        if (StringUtils.isEmpty(channel) || channel.equals("1") || StringUtils.isEmpty(equimentType)) {
             //用个推
             PushUtils.push(equipment.getGtClientId(), "", "", json);
         }
-        if(StringUtils.isNotEmpty(channel)&&channel.equals("2")&&StringUtils.isNotEmpty(equimentType)){
+        if (StringUtils.isNotEmpty(channel) && channel.equals("2") && StringUtils.isNotEmpty(equimentType)) {
             //用Mq
             //1 创建消息
             MessageProperties messageProperties = new MessageProperties();
-            messageProperties.setContentType("text/plain");
-            org.springframework.amqp.core.Message message = new org.springframework.amqp.core.Message(json.getBytes(), messageProperties);
+//            messageProperties.setContentType("text/plain");
+            messageProperties.setContentType("application/json");  // 更改为JSON类型
+            messageProperties.setContentEncoding("UTF-8");  // 明确指定编码
+
+            // 将JSON字符串转为UTF-8字节数组
+            byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
+            org.springframework.amqp.core.Message message = new org.springframework.amqp.core.Message(jsonBytes, messageProperties);
             amqpTemplate.send(equimentType, clientId, message);
         }
         return "success";
@@ -363,27 +369,27 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
                     // 设备名称
                     String name = equipment.getName();
                     // 如果为空就拿设备编号后六位
-                    if(StringUtils.isEmpty(name)) {
+                    if (StringUtils.isEmpty(name)) {
                         name = equipment.getClientId().substring(equipment.getClientId().length() - 6);
                     }
                     String machineType = equipment.getMachineType();
                     if (StringUtils.isNotEmpty(machineType)) {
                         machineType = "0";
                     }
-                    if(wechat != null) {
+                    if (wechat != null) {
                         // 有绑定微信的话发公众号
                         String openId = wechat.getOpenId();
-                        wechatService.sendNetworkMessage(openId,equipment.getClientId(),name, ifForeign, companyType);
+                        wechatService.sendNetworkMessage(openId, equipment.getClientId(), name, ifForeign, companyType);
                         if ("1".equals(ifForeign)) {
                             // 国外再发邮件
                             String messageReceiver = equipment.getMessageReceiver();
-                            if(StringUtils.isNotEmpty(messageReceiver)) {
+                            if (StringUtils.isNotEmpty(messageReceiver)) {
                                 String[] split = messageReceiver.split(",");
                                 for (String s : split) {
                                     WechatSendUtil.sentEmail(s, name, timeZone, machineType);
                                 }
                             } else {
-                                if(StringUtils.isNotEmpty(admin.getEmail())){
+                                if (StringUtils.isNotEmpty(admin.getEmail())) {
                                     WechatSendUtil.sentEmail(admin.getEmail(), name, timeZone, machineType);
                                 }
                             }
@@ -395,13 +401,13 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
                         } else {
                             // 国外发送邮件
                             String messageReceiver = equipment.getMessageReceiver();
-                            if(StringUtils.isNotEmpty(messageReceiver)) {
+                            if (StringUtils.isNotEmpty(messageReceiver)) {
                                 String[] split = messageReceiver.split(",");
                                 for (String s : split) {
                                     WechatSendUtil.sentEmail(s, name, timeZone, machineType);
                                 }
                             } else {
-                                if(StringUtils.isNotEmpty(admin.getEmail())){
+                                if (StringUtils.isNotEmpty(admin.getEmail())) {
                                     WechatSendUtil.sentEmail(admin.getEmail(), name, timeZone, machineType);
                                 }
                             }
@@ -466,7 +472,7 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
 
     private String getInformText(String deviceId) {
         String sms = "";
-        if(StringUtils.isNotEmpty(deviceId)){
+        if (StringUtils.isNotEmpty(deviceId)) {
             sms = "【申泽智能】您好,您名下设备编号为" + deviceId + "的机器,花型数量已推送,请重新设置价格!";
         }
         return sms;
@@ -474,17 +480,18 @@ public class TEquipmentServiceImpl extends ServiceImpl<TEquipmentMapper, TEquipm
 
     /**
      * 根据经度获取时区
+     *
      * @param currentLon 当前经度
      * @return
      */
     public static int lateTimeZone(double currentLon) {
-        int timeZone ;
-        int shangValue = (int)(currentLon / 15);
-        double yushuValue =  Math.abs(currentLon % 15);
+        int timeZone;
+        int shangValue = (int) (currentLon / 15);
+        double yushuValue = Math.abs(currentLon % 15);
         if (yushuValue <= 7.5) {
             timeZone = shangValue;
         } else {
-            timeZone = shangValue +(currentLon > 0 ?  1 :-1);
+            timeZone = shangValue + (currentLon > 0 ? 1 : -1);
         }
         return timeZone;
     }