From be0e4466c64ab2def5d2f34fd9394927250153ab Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 06 十二月 2023 18:18:41 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java |   82 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 78 insertions(+), 4 deletions(-)

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 9409027..d94ffca 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,7 +1,11 @@
 package com.doumee.service.business.impl;
 
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.DeviceRoleMapper;
 import com.doumee.dao.business.model.DeviceRole;
@@ -10,10 +14,13 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.shiro.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
+
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -29,8 +36,40 @@
 
     @Override
     public Integer create(DeviceRole deviceRole) {
-        deviceRoleMapper.insert(deviceRole);
-        return deviceRole.getId();
+
+        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(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�");
+        }
+
+        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
+        DeviceRole insert = new DeviceRole();
+
+        insert.setCreator(loginUserInfo.getId().toString());
+        insert.setCreateDate(new Date());
+        insert.setEdirot(loginUserInfo.getId().toString());
+        insert.setEditDate(new Date());
+        insert.setIsdeleted(Constants.ZERO);
+        insert.setRemark(deviceRole.getRemark());
+        insert.setName(deviceRole.getName());
+        insert.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
+        insert.setType(deviceRole.getType());
+        insert.setDoorIds(deviceRole.getDoorIds());
+        insert.setDoorNames(deviceRole.getDoorNames());
+        insert.setParkIds(deviceRole.getParkIds());
+        insert.setParkNames(deviceRole.getParkNames());
+        insert.setStatus(deviceRole.getStatus());
+        insert.setHkId(deviceRole.getHkId());
+        insert.setHkStatus(deviceRole.getHkStatus());
+        insert.setHkDate(deviceRole.getHkDate());
+
+        deviceRoleMapper.insert(insert);
+        return insert.getId();
     }
 
     @Override
@@ -54,7 +93,39 @@
 
     @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(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�");
+        }
+        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);
     }
 
     @Override
@@ -83,7 +154,7 @@
         QueryWrapper<DeviceRole> wrapper = new QueryWrapper<>(deviceRole);
         return deviceRoleMapper.selectList(wrapper);
     }
-  
+
     @Override
     public PageData<DeviceRole> findPage(PageWrap<DeviceRole> pageWrap) {
         IPage<DeviceRole> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
@@ -136,6 +207,9 @@
         if (pageWrap.getModel().getStatus() != null) {
             queryWrapper.lambda().eq(DeviceRole::getStatus, pageWrap.getModel().getStatus());
         }
+
+        queryWrapper.select("t_aa.*," +
+                "(SELECT count(DISTINCT `KEY`) FROM `test` WHERE `test`.`key` = `t_aa`.id ) ");
         for(PageWrap.SortData sortData: pageWrap.getSorts()) {
             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                 queryWrapper.orderByDesc(sortData.getProperty());

--
Gitblit v1.9.3