소스 검색

feat: "开启/关闭优化码"

Ritchie 1 년 전
부모
커밋
c74a0ca3eb
1개의 변경된 파일40개의 추가작업 그리고 25개의 파일을 삭제
  1. 40 25
      src/main/java/com/szwl/controller/TEquipmentController.java

+ 40 - 25
src/main/java/com/szwl/controller/TEquipmentController.java

@@ -81,6 +81,7 @@ public class TEquipmentController {
     private int j;
 
     private static final int TIMEOUT = 30000;  // 超时时间为30秒
+
     /**
      * @param adminName     商户的登录名
      * @param equipmentName 机器名称
@@ -96,11 +97,11 @@ public class TEquipmentController {
         LambdaQueryWrapper<TEquipment> query = Wrappers.lambdaQuery();
         TAdmin admin = tAdminService.getById(id);
         // 申泽管理员
-        if(id == 2738) {
+        if (id == 2738) {
             companyType = "0";
         }
         // 七云管理员
-        if(id == 2739) {
+        if (id == 2739) {
             companyType = "1";
         }
         Integer type = admin.getType();
@@ -153,10 +154,10 @@ public class TEquipmentController {
         }
         // 公司平台
         if (StringUtils.isNotEmpty(companyType)) {
-            if(companyType.equals("0")) {
+            if (companyType.equals("0")) {
                 query.isNull(TEquipment::getCompanyType)
                         .or().eq(TEquipment::getCompanyType, companyType);
-            }else {
+            } else {
                 query.eq(TEquipment::getCompanyType, companyType);
             }
         }
@@ -180,7 +181,7 @@ public class TEquipmentController {
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
             Date date = null;
             try {
-                date  = sdf.parse(todayDate);
+                date = sdf.parse(todayDate);
             } catch (ParseException e) {
                 e.printStackTrace();
             }
@@ -243,12 +244,12 @@ public class TEquipmentController {
         TEquipmentDTO equipmentDTO = new TEquipmentDTO();
 //        BeanUtils.copyProperties(equipment, equipmentDTO);
         BeanUtils.copyPropertiesIgnoreNull(equipment, equipmentDTO, true);
-        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipment.getId());
+        TEquipmentDesc equipmentDesc = equipmentDescService.getById(id);
         if (equipmentDesc != null) {
             equipmentDTO.setCouponStatus(equipmentDesc.getCouponStatus());
             equipmentDTO.setInDoor(equipmentDesc.getInDoor());
             equipmentDTO.setOutDoor(equipmentDesc.getOutDoor());
-            if(equipmentDesc.getFlowers() != null) {
+            if (equipmentDesc.getFlowers() != null) {
                 equipmentDTO.setFlowers(equipmentDesc.getFlowers());
             }
         }
@@ -772,14 +773,27 @@ public class TEquipmentController {
         if (equipment == null || equipment.getId() == null) {
             return R.fail(ResponseCodesEnum.A0001, "找不到设备");
         }
-//        tEquipmentService.sentMessage(equipment.getClientId(),PushUtils.buildJson("couponStatus", couponStatus).toString());
         TEquipmentDesc tEquipmentDesc = equipmentDescService.getById(equipment.getId());
-        if (tEquipmentDesc != null) {
-//            tEquipmentDesc.setCouponStatus(couponStatus);
-//            equipmentDescService.updateById(tEquipmentDesc);
-            tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("couponStatus", couponStatus).toString());
+
+        Long adminId = equipment.getAdminId();
+        LambdaQueryWrapper<TAdmin> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(TAdmin::getId, adminId);
+        TAdmin admin = tAdminService.getOne(wrapper);
+        Integer type = admin.getType();
+//        String ifForeign = admin.getIfForeign();
+//        if (type < 2 && "0".equals(ifForeign)) {
+        if (type < 2) {
+            if (tEquipmentDesc != null) {
+                tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("couponStatus", couponStatus).toString());
+                equipment.setCouponStatus(couponStatus);
+                tEquipmentService.saveOrUpdate(equipment);
+                tEquipmentDesc.setCouponStatus(couponStatus);
+                equipmentDescService.saveOrUpdate(tEquipmentDesc);
+            } else {
+                return R.fail(ResponseCodesEnum.A0001, "找不到设备描述");
+            }
         } else {
-            return R.fail(ResponseCodesEnum.A0001, "找不到设备");
+            return R.fail("仅管理员可操作");
         }
         return R.ok(null, "修改成功");
     }
@@ -856,7 +870,7 @@ public class TEquipmentController {
         String adminPwd = passwordParam.getAdminPwd();
         String guestPwd = passwordParam.getGuestPwd();
         TEquipment tEquipment = tEquipmentService.getById(equipmentId);
-        if(tEquipment==null) {
+        if (tEquipment == null) {
             return R.fail(ResponseCodesEnum.A0001, "找不到设备");
         }
         if (StringUtils.isNotEmpty(guestPwd)) {
@@ -879,7 +893,7 @@ public class TEquipmentController {
         String equipmentId = param.getEquipmentId();
         Long id = Long.valueOf(equipmentId);
         TEquipment equipment = tEquipmentService.getById(id);
-        tEquipmentService.sentMessage(equipment.getClientId(),PushUtils.buildJson("openDoor", "0").toString());
+        tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("openDoor", "0").toString());
 //        PushUtils.push(equipment.getGtClientId(), "", "", PushUtils.buildJson("openDoor", "0").toString());
         return ResponseEntity
                 .status(HttpStatus.OK)
@@ -1493,6 +1507,7 @@ public class TEquipmentController {
 
     /**
      * 下载日志
+     *
      * @param equipmentId
      * @param day
      * @param response
@@ -1504,18 +1519,18 @@ public class TEquipmentController {
 /*        if(day.length()!=8){
             return R.fail(A0001,"日期格式有误");
         }*/
-        if(StringUtils.isEmpty(equipmentId)) {
+        if (StringUtils.isEmpty(equipmentId)) {
             return R.fail(A0001);
         }
         TEquipment tEquipment = tEquipmentService.getById(equipmentId);
         if (tEquipment == null) {
-            return R.fail(A0001,"该设备不存在");
+            return R.fail(A0001, "该设备不存在");
         }
         String clientId = tEquipment.getClientId();
-        String kind = day+"-"+clientId;
-        String filepath = "/home/hboxs/log/"+kind+".txt";
+        String kind = day + "-" + clientId;
+        String filepath = "/home/hboxs/log/" + kind + ".txt";
         // 1.1 如果文件已存在,直接下载
-        if(Files.exists(Paths.get(filepath))) {
+        if (Files.exists(Paths.get(filepath))) {
 //            DownloadUtils.downloadFile(filepath, response);
 //            return R.ok();
             try {
@@ -1523,16 +1538,16 @@ public class TEquipmentController {
                 return R.ok();
             } catch (IOException e) {
                 e.printStackTrace();
-                return R.fail(B0004,"请重试");
+                return R.fail(B0004, "请重试");
             }
         }
         String channel = tEquipment.getChannel();
         String equimentType = tEquipment.getEquimentType();
-        if(StringUtils.isEmpty(channel)||channel.equals("1")||StringUtils.isEmpty(equimentType)){
+        if (StringUtils.isEmpty(channel) || channel.equals("1") || StringUtils.isEmpty(equimentType)) {
             //用个推
             PushUtils.push(tEquipment.getGtClientId(), "", "", PushUtils.buildJson("log", kind).toString());
         }
-        if(StringUtils.isNotEmpty(channel)&&channel.equals("2")&&StringUtils.isNotEmpty(equimentType)){
+        if (StringUtils.isNotEmpty(channel) && channel.equals("2") && StringUtils.isNotEmpty(equimentType)) {
             //用Mq
             tEquipmentService.sentMessage(tEquipment.getClientId(), PushUtils.buildJson("log", kind).toString());
         }
@@ -1553,7 +1568,7 @@ public class TEquipmentController {
                 // 文件存在,取消定时器
                 future.cancel(false);
                 break;
-            }else {
+            } else {
                 Thread.sleep(1000);
                 if (System.currentTimeMillis() - startTime >= TIMEOUT) {
                     // 超过最大等待时间,抛出异常
@@ -1592,7 +1607,7 @@ public class TEquipmentController {
     public ResponseModel<List<TEquipment>> findEquipmentByClientIds(@RequestParam("clientIds") List<String> clientIds) {
 
         LambdaQueryWrapper<TEquipment> wrapper = new LambdaQueryWrapper<>();
-        wrapper.in(TEquipment::getClientId,clientIds);
+        wrapper.in(TEquipment::getClientId, clientIds);
         List<TEquipment> list = tEquipmentService.list(wrapper);
         return R.ok(list);
     }