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