From 973c131193c4dd3e4ed42518177a996a901037ec Mon Sep 17 00:00:00 2001
From: lishuai <260038442@qq.com>
Date: 星期五, 15 十二月 2023 17:57:01 +0800
Subject: [PATCH] 内部员工门禁组

---
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java |   85 +++++++++++++++++++++++++-----------------
 server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceRoleController.java             |   12 +++++-
 2 files changed, 60 insertions(+), 37 deletions(-)

diff --git a/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceRoleController.java b/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceRoleController.java
index 2a2f474..a3d415f 100644
--- a/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceRoleController.java
+++ b/server/dmvisit_admin/src/main/java/com/doumee/api/business/DeviceRoleController.java
@@ -33,7 +33,7 @@
     @PreventRepeat
     @ApiOperation("鏂板缓")
     @PostMapping("/create")
-    @RequiresPermissions("business:devicerole:create")
+    //@RequiresPermissions("business:devicerole:create")
     public ApiResponse create(@RequestBody DeviceRole deviceRole) {
         return ApiResponse.success(deviceRoleService.create(deviceRole));
     }
@@ -61,12 +61,20 @@
 
     @ApiOperation("鏍规嵁ID淇敼")
     @PostMapping("/updateById")
-    @RequiresPermissions("business:devicerole:update")
+    //@RequiresPermissions("business:devicerole:update")
     public ApiResponse updateById(@RequestBody DeviceRole deviceRole) {
         deviceRoleService.updateById(deviceRole);
         return ApiResponse.success(null);
     }
 
+    @ApiOperation("鏍规嵁ID淇敼榛樿闂ㄧ缁勭姸鎬�")
+    @PostMapping("/updateStatusById")
+    //@RequiresPermissions("business:devicerole:update")
+    public ApiResponse updateStatusById(@RequestBody DeviceRole deviceRole) {
+        deviceRoleService.updateStatusById(deviceRole);
+        return ApiResponse.success(null);
+    }
+
     @ApiOperation("鍒嗛〉鏌ヨ")
     @PostMapping("/page")
     @RequiresPermissions("business:devicerole:query")
diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
index 1deb2ac..225392d 100644
--- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
+++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
@@ -1,5 +1,6 @@
 package com.doumee.service.business.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.model.LoginUserInfo;
@@ -49,19 +50,23 @@
     @Override
     public Integer create(DeviceRole deviceRole) {
 
-        QueryWrapper<DeviceRole> query = new QueryWrapper<>();
-        query.lambda()
-                .eq(DeviceRole::getIsdeleted,Constants.ZERO)
-                .eq(DeviceRole::getType,deviceRole.getType())
-                .eq(DeviceRole::getStatus,Constants.ONE);
-        List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
-        if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
-            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"绠$悊鍐呴儴鍛樺伐鍙兘鏈変竴涓粯璁ら棬绂佺粍");
+        // 鑾峰彇涔嬪墠鏄惁瀛樺湪榛樿闂ㄧ缁�
+        DeviceRole newDeviceRole = null;
+        if(Constants.ONE == deviceRole.getStatus()) {
+            newDeviceRole = getDeviceRole(deviceRole.getStatus());
         }
-
         LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+        if(null != newDeviceRole) {
+            DeviceRole updateDeviceRole = new DeviceRole();
+            // 鑻ョ幇鍦ㄦ柊澧炴暟鎹缃粯璁ら棬绂佺粍锛涢偅涔堝厛鎶婁箣鍓嶇殑榛樿闂ㄧ缁勭姸鎬佹敼涓轰笉鏄粯璁ょ殑
+            updateDeviceRole.setId(newDeviceRole.getId());
+            updateDeviceRole.setEdirot(loginUserInfo.getId().toString());
+            updateDeviceRole.setEditDate(new Date());
+            updateDeviceRole.setIsdeleted(Constants.ONE);
+            updateDeviceRole.setStatus(Constants.ZERO);
+            deviceRoleMapper.updateById(updateDeviceRole);
+        }
         DeviceRole insert = new DeviceRole();
-
         insert.setCreator(loginUserInfo.getId().toString());
         insert.setCreateDate(new Date());
         insert.setEdirot(loginUserInfo.getId().toString());
@@ -105,39 +110,49 @@
 
     @Override
     public void updateById(DeviceRole deviceRole) {
-
-        QueryWrapper<DeviceRole> query = new QueryWrapper<>();
-        query.lambda()
-                .eq(DeviceRole::getIsdeleted,Constants.ZERO)
-                .eq(DeviceRole::getType,deviceRole.getType())
-                .eq(DeviceRole::getStatus,Constants.ONE);
-        List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
-        if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
-            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"绠$悊鍐呴儴鍛樺伐鍙兘鏈変竴涓粯璁ら棬绂佺粍");
-        }
         deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
         deviceRoleMapper.updateById(deviceRole);
     }
 
     @Override
     public void updateStatusById(DeviceRole deviceRole) {
-        QueryWrapper<DeviceRole> query = new QueryWrapper<>();
-        query.lambda()
-                .eq(DeviceRole::getIsdeleted,Constants.ZERO)
-                .eq(DeviceRole::getType,deviceRole.getType())
-                .eq(DeviceRole::getStatus,Constants.ONE);
-        List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
-        if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
-            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"绠$悊鍐呴儴鍛樺伐鍙兘鏈変竴涓粯璁ら棬绂佺粍");
+        // 鑾峰彇涔嬪墠鏄惁瀛樺湪榛樿闂ㄧ缁�
+        DeviceRole newDeviceRole = null;
+        if(Constants.ZERO == deviceRole.getIsDefault()) {
+            newDeviceRole = getDeviceRole(deviceRole.getIsDefault());
         }
         LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
-        DeviceRole update = new DeviceRole();
-        update.setEdirot(loginUserInfo.getId().toString());
-        update.setEditDate(new Date());
-        update.setId(deviceRole.getId());
-        update.setStatus(deviceRole.getStatus());
-        update.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
-        deviceRoleMapper.updateById(update);
+        List<DeviceRole> deviceRoleList = new ArrayList<>();
+        if(null != newDeviceRole) {
+            DeviceRole update = new DeviceRole();
+            update.setEdirot(loginUserInfo.getId().toString());
+            update.setEditDate(new Date());
+            update.setId(newDeviceRole.getId());
+            update.setStatus(newDeviceRole.getStatus());
+            update.setIsDefault(Constants.ONE);
+            deviceRoleList.add(update);
+        }
+        DeviceRole updateTwo = new DeviceRole();
+        updateTwo.setEdirot(loginUserInfo.getId().toString());
+        updateTwo.setEditDate(new Date());
+        updateTwo.setId(deviceRole.getId());
+        updateTwo.setStatus(deviceRole.getStatus());
+        updateTwo.setIsDefault(deviceRole.getIsDefault());
+        deviceRoleList.add(updateTwo);
+        // 鏈�澶�2鏉★紝鎵�鏈夊氨娌℃湁鍐欐壒閲忎慨鏀逛簡
+        for (DeviceRole data:deviceRoleList) {
+            deviceRoleMapper.updateById(data);
+        }
+    }
+
+    private DeviceRole getDeviceRole(Integer status) {
+        LambdaQueryWrapper<DeviceRole> query = new LambdaQueryWrapper<>();
+        query.eq(DeviceRole::getIsdeleted,Constants.ZERO)
+                .eq(DeviceRole::getIsDefault,Constants.ZERO)
+                .eq(DeviceRole::getStatus,status);
+        // 鏌ヨ鏄惁鏈夐粯璁ら棬绂佺粍锛屽彧鑳芥湁涓�缁勯粯璁ら棬绂佺粍
+        DeviceRole getDeviceRole = deviceRoleMapper.selectOne(query);
+        return getDeviceRole;
     }
 
     @Override

--
Gitblit v1.9.3