From dc19e6b41d721836342e1219aa33087e57183417 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 19 十二月 2023 09:59:49 +0800
Subject: [PATCH] 海康接口对接开发
---
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java | 124 +++++++++++++++++++++++++++--------------
1 files changed, 82 insertions(+), 42 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 7449ddc..b802f7d 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,32 +1,41 @@
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;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
+import com.doumee.core.erp.model.openapi.request.RoleListRequest;
+import com.doumee.core.erp.model.openapi.response.DeviceListResponse;
+import com.doumee.core.erp.model.openapi.response.RoleListResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.DeviceMapper;
import com.doumee.dao.business.DeviceRoleMapper;
import com.doumee.dao.business.model.Device;
import com.doumee.dao.business.model.DeviceRole;
+import com.doumee.dao.business.model.Member;
import com.doumee.dao.web.response.DeviceRoleVO;
import com.doumee.service.business.DeviceRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.doumee.service.business.MemberService;
+import io.swagger.models.auth.In;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* 闂ㄧ瑙掕壊淇℃伅琛⊿ervice瀹炵幇
@@ -38,23 +47,30 @@
@Autowired
private DeviceRoleMapper deviceRoleMapper;
+ @Autowired
+ private MemberService memberService;
+
@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() && null != deviceRole.getType()) {
+ newDeviceRole = getDeviceRole(deviceRole.getStatus(), deviceRole.getType());
}
-
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());
@@ -98,39 +114,50 @@
@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.ONE == deviceRole.getStatus() && null != deviceRole.getType()) {
+ newDeviceRole = getDeviceRole(deviceRole.getStatus(), deviceRole.getType());
}
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, Integer type) {
+ LambdaQueryWrapper<DeviceRole> query = new LambdaQueryWrapper<>();
+ query.eq(DeviceRole::getIsdeleted,Constants.ZERO)
+ .eq(DeviceRole::getIsDefault,Constants.ZERO)
+ .eq(DeviceRole::getType,type)
+ .eq(DeviceRole::getStatus,status);
+ // 鏌ヨ鏄惁鏈夐粯璁ら棬绂佺粍锛屽彧鑳芥湁涓�缁勯粯璁ら棬绂佺粍
+ DeviceRole getDeviceRole = deviceRoleMapper.selectOne(query);
+ return getDeviceRole;
}
@Override
@@ -212,9 +239,6 @@
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());
@@ -222,7 +246,18 @@
queryWrapper.orderByAsc(sortData.getProperty());
}
}
- return PageData.from(deviceRoleMapper.selectPage(page, queryWrapper));
+ IPage<DeviceRole> newPage = deviceRoleMapper.selectPage(page, queryWrapper);
+ if(null != newPage && newPage.getRecords().size() > 0) {
+ List<DeviceRole> deviceRoleList = newPage.getRecords();
+ for (DeviceRole dto:deviceRoleList) {
+ Member member = new Member();
+ member.setIsdeleted(Constants.ZERO);
+ member.setRoleIdParam("["+dto.getId()+"]");
+ dto.setMemberNum((int) memberService.count(member));
+ }
+ newPage.setRecords(deviceRoleList);
+ }
+ return PageData.from(newPage);
}
@Override
@@ -248,4 +283,9 @@
}
+
+
+
+
+
}
--
Gitblit v1.9.3