From d8228730095cdcaccb40dd2dc290fc44779e340a Mon Sep 17 00:00:00 2001
From: wangmengzhao <1036088376@qq.com>
Date: 星期三, 13 十二月 2023 22:21:52 +0800
Subject: [PATCH] 滤芯寿命清单列表接口编写20231213wmz

---
 wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 1 deletions(-)

diff --git a/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java b/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java
index 0f8bb5f..7a2a1b4 100644
--- a/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java
+++ b/wumei-smart-master/springboot/wumei-iot/src/main/java/com/ruoyi/iot/service/impl/DeviceServiceImpl.java
@@ -4,8 +4,10 @@
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysRole;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
@@ -25,6 +27,7 @@
 import com.ruoyi.iot.service.IDeviceService;
 import com.ruoyi.iot.service.IProductService;
 import com.ruoyi.iot.service.IToolService;
+import com.ruoyi.system.mapper.SysDeptMapper;
 import com.ruoyi.system.service.ISysUserService;
 import org.quartz.SchedulerException;
 import org.slf4j.Logger;
@@ -36,6 +39,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -84,6 +88,9 @@
     @Autowired
     @Lazy
     private EmqxService emqxService;
+
+    @Autowired
+    private SysDeptMapper sysDeptMapper;
 
     /**
      * 鏌ヨ璁惧
@@ -146,6 +153,43 @@
     }
 
     /**
+     * 鏌ヨ鎬昏澶囨暟锛堝彴锛�
+     *
+     * @param id
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public AjaxResult selectDeviceCount(int id) throws Exception {
+        //鏍规嵁鐢ㄦ埛鐧诲綍鐨勮鑹茶韩浠芥煡璇㈡�昏澶囨暟锛堝彴锛�
+        int count = deviceMapper.selectDeviceCount(id);
+        //鏍规嵁鐧诲綍鐢ㄦ埛鐨勮鑹茶韩浠芥煡璇㈣澶囩殑浣跨敤浜烘暟
+        int total = deviceMapper.selectUserDeviceByCount(id);
+        AjaxResult ajax = new AjaxResult();
+        ajax.put("deviceCount", count);
+        ajax.put("userTotal", total);
+        return AjaxResult.success("鏌ヨ鎴愬姛", ajax);
+    }
+
+    /**
+     * 鏍规嵁鐧诲綍鐢ㄦ埛鐨刬d鏌ヨ璁惧鐨勪娇鐢ㄤ汉鏁�
+     *
+     * @param id
+     * @return
+     * @throws Exception
+     */
+
+    @Override
+    public int selectUserDeviceByCount(int id) throws Exception {
+        return deviceMapper.selectUserDeviceByCount(id);
+    }
+
+    @Override
+    public List<Device> selectDeviceAll() throws Exception {
+        return deviceMapper.selectDeviceAll();
+    }
+
+    /**
      * 鏍规嵁璁惧缂栧彿鏌ヨ绠�浠嬭澶�
      *
      * @param serialNumber 璁惧涓婚敭
@@ -200,6 +244,7 @@
         // 鏌ヨ鐗╂ā鍨�
         String thingsModels = thingsModelService.getCacheThingsModelByProductId(input.getProductId());
         JSONObject thingsModelObject = JSONObject.parseObject(thingsModels);
+        //ThingsModelValueItemDto鈥斺�旂墿妯″瀷
         List<ThingsModelValueItemDto> valueList = null;
         if (type == 1) {
             JSONArray properties = thingsModelObject.getJSONArray("properties");
@@ -211,6 +256,7 @@
 
         // 鏌ヨ鐗╂ā鍨嬪��
         ThingsModelValuesOutput deviceThings = deviceMapper.selectDeviceThingsModelValueBySerialNumber(input.getDeviceNumber());
+        //鐗╂ā鍨嬪�肩殑椤光�斺�擳hingsModelValueItem
         List<ThingsModelValueItem> thingsModelValues = JSONObject.parseArray(deviceThings.getThingsModelValue(), ThingsModelValueItem.class);
 
         for (int i = 0; i < input.getThingsModelValueRemarkItem().size(); i++) {
@@ -356,17 +402,36 @@
      * @return 璁惧
      */
     @Override
-    public List<DeviceShortOutput> selectDeviceShortList(Device device) {
+    public List<DeviceShortOutput> selectDeviceShortList(Device device, boolean repairFlag) {
         SysUser user = getLoginUser().getUser();
         List<SysRole> roles = user.getRoles();
         for (int i = 0; i < roles.size(); i++) {
             if (roles.get(i).getRoleKey().equals("tenant")) {
                 // 绉熸埛鏌ョ湅浜у搧涓嬫墍鏈夎澶�
                 device.setTenantId(user.getUserId());
+                if (repairFlag == true) {
+                    device.setInstallFlag(1);
+                }
                 break;
             } else if (roles.get(i).getRoleKey().equals("general")) {
                 // 鐢ㄦ埛鏌ョ湅鑷繁璁惧
                 device.setUserId(user.getUserId());
+                if (repairFlag == true) {
+                    device.setInstallFlag(1);
+                }
+                break;
+            } else if (roles.get(i).getRoleKey().equals("tenanthelper")) {
+                //鑱旇惀鍟嗗悎浼欎汉鏌ョ湅璁惧
+                //鑱旇惀鍟嗗悎浼欎汉闇�瑕佹牴鎹粬鑷繁鐨剈serid鍘绘煡璇粬涓婄骇鐨勭敤鎴蜂俊鎭紝tenantid鏄鎴穒d鍜屼粬鐨勪竴绾ц仈钀ュ晢鎵�鎷ユ湁鐨勮澶�
+                //閫氳繃鐢ㄦ埛ID鏌ヨ鐢ㄦ埛鏍规嵁褰撳墠鐧诲綍鐨勮仈钀ュ晢鍚堜紮浜哄幓鏌ヨ浠栫殑涓婄骇閮ㄩ棬id鏄嚑锛屽啀閫氳繃浠栫殑涓婄骇閮ㄩ棬id鍘绘煡璇㈡墍瀵瑰簲鐨勪竴绾ц仈钀ュ晢鍜屾墍瀵瑰簲鐨則enantid
+                SysUser sysUser = userService.selectUserById(user.getUserId());//鎷垮埌鎵�鍦ㄧ殑閮ㄩ棬id
+                SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId());  //鏍规嵁閮ㄩ棬id鍘绘煡璇俊鎭緱鍒扮埗绾х殑閮ㄩ棬id
+                SysDept sysDeptParent = sysDeptMapper.selectDeptById(sysDept.getParentId());  //鏍规嵁鐖剁骇閮ㄩ棬鐨刬d鍘绘煡璇俊鎭�
+                SysUser sysUserDept = userService.selectUserByDeptId(sysDeptParent.getDeptId());//鏍规嵁寰楀埌鐨勭埗绾х殑閮ㄩ棬id鍘籹ys_user琛ㄩ噷闈㈡煡璇粬鐨勭敤鎴蜂俊鎭�
+                device.setTenantId(sysUserDept.getUserId());
+                if (repairFlag == true) {
+                    device.setInstallFlag(1);
+                }
                 break;
             }
         }
@@ -977,6 +1042,43 @@
         return i;
     }
 
+    @Override
+    public int updateDeviceUserBySN(List<String> snList, Long userId) {
+        LoginUser loginUser = getLoginUser();
+        List<Device> deviceList = snList.stream().map(s -> {
+            Device device = new Device();
+            device.setSerialNumber(s.trim());
+            return device;
+        }).collect(Collectors.toList());
+        int i = 0;
+        for (Device device : deviceList) {
+            //鍒ゆ柇璁惧鏄惁瀛樺湪
+            Device deviceTmp = deviceMapper.selectShortDeviceBySerialNumber(device.getSerialNumber());
+            if (deviceTmp == null) return -1;
+            //鍒ゆ柇璁惧鏄笉鏄凡缁忓垎浜�
+            List<DeviceUser> deviceUserList = deviceUserMapper.selectDeviceUserByDeviceId(deviceTmp.getDeviceId());
+            for (DeviceUser deviceUserTmp : deviceUserList) {
+                if (deviceUserTmp.getUserId() == userId && deviceUserTmp.getIsOwner() == 0)
+                    return -2;
+            }
+
+            //鏇存柊璁惧琛�
+            device.setUserId(userId);
+            device.setUserName(loginUser.getUsername());
+            deviceMapper.updateDeviceBySerialNumber(device);
+            //鏇存柊璁惧瀵瑰簲鐨勪富浜鸿〃
+            DeviceUser deviceUser = new DeviceUser();
+            deviceUser.setUserId(userId);
+            deviceUser.setUserName(loginUser.getUsername());
+            //deviceUser.setPhonenumber(loginUser.getp);
+            deviceUser.setUpdateTime(DateUtils.getNowDate());
+            deviceUser.setDeviceId(deviceTmp.getDeviceId());
+            deviceUserMapper.updateDeviceUserInit(deviceUser);
+            i++;
+        }
+        return i;
+    }
+
     /**
      * 鍒犻櫎璁惧
      *

--
Gitblit v1.8.0