From 662a1de0fdb2b190cb63b692e5172097aed11269 Mon Sep 17 00:00:00 2001
From: wangmengzhao <1036088376@qq.com>
Date: 星期六, 09 十二月 2023 23:48:54 +0800
Subject: [PATCH] 设备安装查询的代码优化,打通emq与设备端数据交互与下发指令设备端接受,设备端大宋指令系统平台接收,设备安装/维修单定时任务调试20231209wmz

---
 wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceOrderController.java |  181 ++++++++++++++++++++------------------------
 1 files changed, 83 insertions(+), 98 deletions(-)

diff --git a/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceOrderController.java b/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceOrderController.java
index 27cd325..8af3746 100644
--- a/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceOrderController.java
+++ b/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/controller/DeviceOrderController.java
@@ -4,17 +4,14 @@
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.file.FileUploadUtils;
-import com.ruoyi.framework.web.service.TokenService;
-import com.ruoyi.iot.domain.Device;
 import com.ruoyi.iot.domain.DeviceOrder;
+import com.ruoyi.iot.domain.DeviceOrderTime;
 import com.ruoyi.iot.service.IDeviceOrderService;
-import com.ruoyi.iot.service.IDeviceService;
-import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.iot.service.IDeviceOrderTimeService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
@@ -26,14 +23,13 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.IOException;
 import java.util.List;
 
 /**
  * @author wmz
  * @version v1.0
  * @ClassName DeviceOrderController
- * @description 璁惧瀹夎controller
+ * @description 璁惧瀹夎鍗�/缁翠慨鍗昪ontroller
  * @createTime 2023/11/13 0:27
  */
 @Api(tags = "璁惧瀹夎淇℃伅")
@@ -47,17 +43,12 @@
     private IDeviceOrderService iDeviceOrderService;
 
     @Autowired
-    private IDeviceService deviceService;
-
-    @Autowired
-    private ISysUserService userService;
-
-    @Autowired
-    private TokenService tokenService;
+    private IDeviceOrderTimeService deviceOrderTimeService;
 
     /**
      * 鏌ヨ鍏ㄩ儴璁惧瀹夎鍗曡鍗曚俊鎭�
      *
+     * @param deviceOrder
      * @return
      * @throws Exception
      */
@@ -71,56 +62,81 @@
     }
 
     /**
+     * 鏍规嵁鐧诲綍鐨勮仈钀ュ晢鏌ヨ璁惧璁㈠崟瓒呮椂鐨勬椂闂撮棿闅�
+     *
+     * @param deviceOrderTime
+     * @return
+     * @throws Exception
+     */
+    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
+    @GetMapping("/selecttimeout")
+    @ApiOperation(value = "鏍规嵁鐧诲綍鐨勮仈钀ュ晢鏌ヨ璁惧璁㈠崟瓒呮椂鐨勬椂闂撮棿闅�")
+    public AjaxResult selectTimeout(DeviceOrderTime deviceOrderTime) throws Exception {
+        return deviceOrderTimeService.selectDeviceOrderTimeoutById(deviceOrderTime);
+    }
+
+    /**
+     * 鏍规嵁鐧诲綍鐨勮仈钀ュ晢淇敼璁惧璁㈠崟瓒呮椂鐨勬椂闂撮棿闅�
+     *
+     * @param deviceOrderTime
+     * @return
+     * @throws Exception
+     */
+    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
+    @Log(title = "鑱旇惀鍟嗙櫥褰曞悗淇敼璁惧璁㈠崟瓒呮椂鐨勬椂闂撮棿闅�", businessType = BusinessType.UPDATE)
+    @PutMapping("/updatetimeout")
+    @ApiOperation(value = "鏍规嵁鐧诲綍鐨勮仈钀ュ晢淇敼璁惧璁㈠崟瓒呮椂鐨勬椂闂撮棿闅�")
+    public AjaxResult assignDeviceOrderTimeout(DeviceOrderTime deviceOrderTime) throws Exception {
+        return deviceOrderTimeService.updateDeviceOrderTimeoutById(deviceOrderTime);
+    }
+
+
+    /**
+     * 瀹夎鍗�/缁翠慨鍗曞畬鎴愬悗鐢ㄦ埛鐨勮瘎浠�
+     *
+     * @param deviceOrder
+     * @return
+     * @throws Exception 鍙傛暟鏄畨瑁呭崟鐨刬d锛岀敤鎴风殑id,ordertype绫诲瀷
+     */
+    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
+    @PostMapping("/editDeviceOrderScore")
+    @Log(title = "瀹夎鍗�/缁翠慨鍗曞畬鎴愬悗鐢ㄦ埛娣诲姞璇勪环", businessType = BusinessType.UPDATE)
+    @ApiOperation(value = "瀹夎鍗�/缁翠慨鍗曞畬鎴愬悗鐢ㄦ埛鐨勮瘎浠�")
+    public AjaxResult updateDeviceOrderScoreAndComment(DeviceOrder deviceOrder) throws Exception {
+        return iDeviceOrderService.updateDeviceOrderScoreAndComment(deviceOrder);
+    }
+
+    /**
+     * 鏌ヨ鏈淳鍗�/宸叉淳鍗�/宸叉帴鍗�/宸插畬鎴愮殑瀹夎鍗�/缁翠慨鍗曟暟缁翠慨鍗曟暟閲�
+     *
+     * @param deviceOrder
+     * @return
+     * @throws Exception
+     */
+    @PreAuthorize("@ss.hasAnyPermi('iot:deviceOrder:list')")
+    @GetMapping("/get")
+    @ApiOperation(value = "鑾峰彇鏈淳鍗�/宸叉淳鍗�/宸叉帴鍗�/宸插畬鎴愮殑瀹夎鍗�/缁翠慨鍗曟暟閲�")
+    public AjaxResult selectDeviceOrderCount(DeviceOrder deviceOrder) throws Exception {
+        if (deviceOrder != null) {
+            return iDeviceOrderService.selectDeviceOrderCountByUndeliveredorders(deviceOrder);
+        } else {
+            return AjaxResult.error("鏈煡璇㈠埌鏈夊叧淇℃伅");
+        }
+    }
+
+    /**
      * 娣诲姞瀹夎璁惧璁㈠崟淇℃伅
      *
      * @param deviceOrder
      * @return
      * @throws Exception
      */
-    @ApiOperation("娣诲姞瀹夎鍗�")
+    @ApiOperation("娣诲姞瀹夎鍗�/缁翠慨鍗�")
     @PreAuthorize("@ss.hasPermi('iot:device:add')")
-    @Log(title = "娣诲姞瀹夎鍗曚俊鎭�", businessType = BusinessType.INSERT)
+    @Log(title = "娣诲姞瀹夎鍗�/缁翠慨鍗曚俊鎭�", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@Validated @RequestBody DeviceOrder deviceOrder) throws Exception {
-        //鏇存柊璁㈠崟鐨勫垵濮嬪寲鐘舵��
-        if ("鏈寚娲�".equals(deviceOrder.getErectoName())) {
-            deviceOrder.setState(0);
-        } else {
-            deviceOrder.setState(1);
-        }
-        //鍒ゆ柇浼犺繃鏉ョ殑orderType鐨勫�兼槸鍚︿负2-缁翠慨
-        if ("2".equals(deviceOrder.getOrderType())) {
-            log.info("orderType{}", deviceOrder.getOrderType());
-            System.out.println(deviceOrder.getOrderType());
-            //鏇存柊璁㈠崟鐨勭敤鎴蜂俊鎭�
-            SysUser sysUser = getLoginUser().getUser();
-            deviceOrder.setCreateUserId(sysUser.getUserId());
-            //鎻掑叆缁翠慨鍗�
-            int rows = iDeviceOrderService.insertDeviceOrder(deviceOrder);
-            if (rows > 0) {
-                Device device1 = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId());
-                //鏇存柊褰撳墠璁惧鐨勬槸鍚︾淮淇俊鎭�-鏈淮淇�
-                Device device = new Device();
-                device.setDeviceId(deviceOrder.getDeviceId());
-                device.setRepairFlag(1);
-                device.setStatus(device1.getStatus());
-                deviceService.updateDevice(device);
-            }
-            return toAjax(rows);
-        }
-        //鏇存柊璁㈠崟鐨勭敤鎴蜂俊鎭�
-        SysUser sysUser = getLoginUser().getUser();
-        deviceOrder.setCreateUserId(sysUser.getUserId());
-        //鎻掑叆瀹夎璁㈠崟
-        int rows = iDeviceOrderService.insertDeviceOrder(deviceOrder);
-        if (rows > 0) {
-            //鏇存柊褰撳墠璁惧鐘舵�佷俊鎭�--瀹夎涓�
-            Device device = new Device();
-            device.setDeviceId(deviceOrder.getDeviceId());
-            device.setStatus(5);
-            deviceService.updateDevice(device);
-        }
-        return toAjax(rows);
+        return iDeviceOrderService.insertDeviceOrder(deviceOrder);
     }
 
     /**
@@ -135,28 +151,7 @@
     @Log(title = "淇敼璁惧璁㈠崟淇℃伅", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody DeviceOrder deviceOrder) throws Exception {
-        //鍒ゆ柇浼犺繃鏉ョ殑orderType鐨勫�兼槸鍚︿负1-瀹夎锛屽苟涓斿畨瑁呭崟鐨勭姸鎬佷负涓哄凡瀹屾垚锛屼慨鏀硅澶囩殑鐘舵�佷负绂荤嚎鐘舵��
-        if ("1".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) {
-            Device device = new Device();
-            device.setDeviceId(deviceOrder.getDeviceId());
-            //淇敼璁惧鐨勭姸鎬佷负绂荤嚎
-            device.setStatus(4);
-            deviceService.updateDevice(device);
-        }
-        //鍒ゆ柇浼犺繃鏉ョ殑orderType鐨勫�兼槸鍚︿负2-缁翠慨锛屽苟涓旂淮淇崟鐨勭姸鎬佷负涓哄凡瀹屾垚锛屼慨鏀硅澶囩殑鏄惁涓轰慨涓�0-宸茬淮淇�
-        if ("2".equals(deviceOrder.getOrderType()) && deviceOrder.getState() == 3) {
-            Device device1 = deviceService.selectDeviceByDeviceId(deviceOrder.getDeviceId());
-            Device device = new Device();
-            device.setDeviceId(deviceOrder.getDeviceId());
-            device.setRepairFlag(0);
-            device.setStatus(device1.getStatus());
-            deviceService.updateDevice(device);
-        }
-        //鑾峰彇淇敼璁㈠崟鐨勭敤鎴蜂俊鎭�
-        SysUser sysUser = getLoginUser().getUser();
-        //鎷垮埌淇敼瀹夎鍗曠殑鐢ㄦ埛id
-        deviceOrder.setUpdateUserId(sysUser.getUserId());
-        return toAjax(iDeviceOrderService.updateDeviceOrder(deviceOrder));
+        return iDeviceOrderService.updateDeviceOrder(deviceOrder);
     }
 
     /**
@@ -168,33 +163,23 @@
      */
     @PreAuthorize("@ss.hasPermi('iot:device:remove')")
     @Log(title = "鍒犻櫎璁惧璁㈠崟淇℃伅", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{deviceId}")
-    @ApiOperation("鍒犻櫎璁㈠崟淇℃伅")
-    public AjaxResult remove(@PathVariable("deviceId") Integer deviceId) throws Exception {
-        //鏍规嵁瑕佸垹闄ゅ畨瑁呭崟鐨刬d鏌ヨ鍑哄畨瑁呭崟淇℃伅
-        DeviceOrder deviceOrder = iDeviceOrderService.selectDeviceOrderById(deviceId);
-        SysUser user = getLoginUser().getUser();
-        //濡傛灉鏍规嵁鏌ヨ鍑烘潵鐨勫畨瑁呭崟瀵硅薄涓嶄负绌虹殑璇濓紝骞朵笖鐘舵�佺瓑浜庢湭娲惧崟鎵嶅彲浠ュ垹闄�
-        if (deviceOrder != null && deviceOrder.getState() == 0 && user.getUserId() != 1) {
-            //鏈淳鍗曠殑瀹夎鍗曞垹闄ゅ悗璁惧鐨勭姸鎬佹洿鏂颁负-鏈縺娲�
-            Device device = new Device();
-            device.setDeviceId(deviceOrder.getDeviceId());
-            device.setStatus(1);
-            deviceService.updateDevice(device);
-            int i = iDeviceOrderService.deleteDeviceOrderById(deviceOrder.getId());
-            return toAjax(i);
-        } else {
-            return AjaxResult.error();
-        }
+    @DeleteMapping("/{id}/{deviceId}")
+    @ApiOperation("鍒犻櫎璁惧璁㈠崟淇℃伅")
+    public AjaxResult remove(@PathVariable("id") Long id, @PathVariable("deviceId") Long deviceId) throws Exception {
+        return iDeviceOrderService.deleteDeviceOrderById(id, deviceId);
     }
 
     /**
-     * 瀹夎鍗曠淮淇崟鍥剧墖涓婁紶
+     * 瀹夎鍗�/缁翠慨鍗曞浘鐗囦笂浼�
+     *
+     * @param file
+     * @return
+     * @throws Exception
      */
 
-    @Log(title = "瀹夎鍗曞浘鐗囦笂浼�", businessType = BusinessType.INSERT)
+    @Log(title = "瀹夎鍗�/缁翠慨鍗曞浘鐗囦笂浼�", businessType = BusinessType.INSERT)
     @PostMapping("/profile/avatar")
-    @ApiOperation("瀹夎鍗曞浘鐗囦笂浼�")
+    @ApiOperation("瀹夎鍗�/缁翠慨鍗曞浘鐗囦笂浼�")
     public AjaxResult imgurl(@RequestParam("avatarfile") MultipartFile file) throws Exception {
         // 鍒ゆ柇澶村儚鏂囦欢涓嶄负绌�
         if (!file.isEmpty()) {

--
Gitblit v1.8.0