| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.api.R; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | |
| | | 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.admin.response.MemberInfoDTO; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.join.MemberRoleJoinMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | 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.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.business.MemberService; |
| | | import com.doumee.service.business.impl.hksync.ferp.HkSyncOrgUserToHKServiceImpl; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import io.swagger.models.auth.In; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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; |
| | |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class DeviceRoleServiceImpl implements DeviceRoleService { |
| | | |
| | | @Autowired |
| | | private DeviceRoleMapper deviceRoleMapper; |
| | | @Autowired |
| | | private MemberService memberService; |
| | | private MemberCardMapper memberCardMapper; |
| | | @Autowired |
| | | private EmpowerMapper empowerMapper; |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | @Autowired |
| | | private MemberRoleJoinMapper memberRoleMapper; |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | |
| | | @Override |
| | | public Integer create(DeviceRole deviceRole) { |
| | | |
| | | if(Objects.isNull(deviceRole) |
| | | || StringUtils.isBlank(deviceRole.getName()) |
| | | || Objects.isNull(deviceRole.getType()) |
| | | || Objects.isNull(deviceRole.getIsDefault()) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | // 获取之前是否存在默认门禁组 |
| | | DeviceRole newDeviceRole = null; |
| | | if(Constants.ONE == deviceRole.getStatus() && null != deviceRole.getType()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getStatus(), deviceRole.getType()); |
| | | if(null != deviceRole.getType()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getType()); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | if(null != newDeviceRole) { |
| | | if(null != newDeviceRole && deviceRole.getIsDefault().equals(Constants.ZERO)) { |
| | | 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); |
| | | updateDeviceRole.setIsDefault(Constants.ONE); |
| | | deviceRoleMapper.updateById(updateDeviceRole); |
| | | } |
| | | DeviceRole insert = new DeviceRole(); |
| | |
| | | insert.setIsdeleted(Constants.ZERO); |
| | | insert.setRemark(deviceRole.getRemark()); |
| | | insert.setName(deviceRole.getName()); |
| | | insert.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); |
| | | insert.setIsDefault(deviceRole.getIsDefault()); |
| | | insert.setType(deviceRole.getType()); |
| | | insert.setDoorIds(deviceRole.getDoorIds()); |
| | | insert.setDoorNames(deviceRole.getDoorNames()); |
| | |
| | | |
| | | @Override |
| | | public void updateById(DeviceRole deviceRole) { |
| | | deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); |
| | | deviceRoleMapper.updateById(deviceRole); |
| | | DeviceRole model = deviceRoleMapper.selectById(deviceRole.getId()); |
| | | if(model == null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | DeviceRole newDeviceRole = null; |
| | | if(null != deviceRole.getType()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getType()); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | if(null != newDeviceRole && deviceRole.getIsDefault().equals(Constants.ZERO)) { |
| | | DeviceRole update = new DeviceRole(); |
| | | update.setEdirot(loginUserInfo.getId().toString()); |
| | | update.setEditDate(new Date()); |
| | | update.setId(newDeviceRole.getId()); |
| | | update.setIsDefault(Constants.ONE); |
| | | deviceRoleMapper.updateById(update); |
| | | } |
| | | int t = deviceRoleMapper.updateById(deviceRole); |
| | | if(t>0){ |
| | | Thread tt = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | startUpdateMemberEmpower(model,deviceRole); |
| | | }catch (Exception e){ |
| | | log.error("======门禁分组修改,更新人员权限失败==="+e.getMessage()); |
| | | } |
| | | } |
| | | }); |
| | | tt.start(); |
| | | } |
| | | } |
| | | @Override |
| | | public void updateMemberRole(DeviceRole deviceRole) { |
| | | deviceRole.setType("2"); |
| | | deviceRole.setIsdeleted(Constants.ZERO); |
| | | List<DeviceRole> list =findList(deviceRole); |
| | | if(list == null || list.size()==0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | for(DeviceRole model :list){ |
| | | updateMemberRoleDO(model); |
| | | } |
| | | } |
| | | public void updateMemberRoleDO(DeviceRole model) { |
| | | if(model.getDoorIds() == null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | String[] newIds =StringUtils.defaultString(model.getDoorIds()).split(","); |
| | | List<Integer> allids = getChangeIdsByArray(new String[]{},newIds);//最新设备 |
| | | List<MemberRole> memberRoleList = memberRoleMapper.selectList(new QueryWrapper<MemberRole>().lambda() |
| | | .eq(MemberRole::getRoleId,model.getId()) |
| | | .eq(MemberRole::getIsdeleted,Constants.ZERO) |
| | | ); |
| | | if(memberRoleList!=null && memberRoleList.size()>0) { |
| | | int num =1; |
| | | for (MemberRole memberRole : memberRoleList) { |
| | | Member member = memberMapper.selectById(memberRole.getMemberId()); |
| | | if(member==null || member.getIsdeleted().equals(Constants.ONE)){ |
| | | continue; |
| | | } |
| | | List<Integer> addIds = new ArrayList<>(); |
| | | for(Integer did : allids){ |
| | | Empower empower = empowerMapper.selectOne(new QueryWrapper<Empower>().lambda() |
| | | .eq(Empower::getMemberId,member.getId()) |
| | | .eq(Empower::getDeviceId,did ) |
| | | .orderByDesc(Empower::getId) |
| | | .last("limit 1")); |
| | | if(empower ==null || Constants.equalsInteger(empower.getIsdeleted(),Constants.ONE)){ |
| | | addIds.add(did); |
| | | } |
| | | } |
| | | try { |
| | | HkSyncOrgUserToHKServiceImpl.dealChangeDeviceRoleEmpower(member,addIds,null,deviceRoleMapper,empowerMapper,deviceMapper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | System.out.println("正在处理【"+model.getName()+"】======门禁数据【"+addIds.size()+"】====进度:【"+num+"|"+memberRoleList.size()+"】"); |
| | | num ++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新该权限下相关的人员最新全新下发 |
| | | * @param model |
| | | * @param deviceRole |
| | | */ |
| | | private void startUpdateMemberEmpower(DeviceRole model, DeviceRole deviceRole) { |
| | | String[] ids = StringUtils.defaultString(model.getDoorIds()).split(","); |
| | | String[] newIds =StringUtils.defaultString(deviceRole.getDoorIds()).split(","); |
| | | List<Integer> delIds = getChangeIdsByArray(newIds,ids);//删除的设备 |
| | | List<Integer> addIds = getChangeIdsByArray(ids,newIds);//最新设备 |
| | | if((addIds==null ||addIds.size()==0)&&( delIds ==null || delIds.size() == 0 )){ |
| | | //如果没有变化,不做处理 |
| | | return; |
| | | } |
| | | List<Integer> allids = getChangeIdsByArray(new String[]{},newIds);//最新设备 |
| | | List<MemberRole> memberRoleList = memberRoleMapper.selectList(new QueryWrapper<MemberRole>().lambda() |
| | | .eq(MemberRole::getRoleId,model.getId()) |
| | | .eq(MemberRole::getIsdeleted,Constants.ZERO) |
| | | ); |
| | | if(memberRoleList!=null && memberRoleList.size()>0){ |
| | | for(MemberRole memberRole : memberRoleList){ |
| | | //如果有人员授权了该权限 |
| | | Member member = memberMapper.selectById(memberRole.getMemberId()); |
| | | if(member==null || member.getIsdeleted().equals(Constants.ONE)){ |
| | | continue; |
| | | } |
| | | MPJLambdaWrapper<MemberRole> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.leftJoin(DeviceRole.class,DeviceRole::getId,MemberRole::getRoleId ); |
| | | queryWrapper.selectAll(MemberRole.class) |
| | | .selectAs(DeviceRole::getDoorIds, MemberRole::getDoorIds) |
| | | .eq(MemberRole::getMemberId,memberRole.getMemberId()) |
| | | .eq(MemberRole::getIsdeleted,Constants.ZERO) |
| | | .ne(MemberRole::getRoleId,deviceRole.getId()); |
| | | List<MemberRole> tLis = memberRoleMapper.selectJoinList(MemberRole.class,queryWrapper); |
| | | List<Integer> actDelIds = getActChangeDoorIds(tLis,delIds); |
| | | List<Integer> actAddIds = getActChangeDoorIds(tLis,allids); |
| | | HkSyncOrgUserToHKServiceImpl.dealChangeDeviceRoleEmpower(member,actAddIds,actDelIds,deviceRoleMapper,empowerMapper,deviceMapper); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据用户当前最新的门禁角色,查询实际应该删除或者增加的门禁点权限 |
| | | * @param tLis |
| | | * @param changeIds |
| | | * @return |
| | | */ |
| | | private List<Integer> getActChangeDoorIds(List<MemberRole> tLis, List<Integer> changeIds) { |
| | | List<Integer> list = new ArrayList<>(); |
| | | for(MemberRole memberRole : tLis){ |
| | | String[] ids = StringUtils.defaultString(memberRole.getDoorIds()).split(","); |
| | | if(ids!=null && ids.length>0){ |
| | | for (String s:ids){ |
| | | list.add(Integer.parseInt(s)); |
| | | } |
| | | } |
| | | } |
| | | List<Integer> actList = new ArrayList<>(); |
| | | if(list.size()>0){ |
| | | Flag: |
| | | for (Integer t : changeIds){ |
| | | for (Integer tt : list){ |
| | | if(Constants.equalsInteger(t,tt)){ |
| | | continue Flag; |
| | | } |
| | | } |
| | | actList.add(t); |
| | | } |
| | | } |
| | | return actList; |
| | | } |
| | | |
| | | private List<Integer> getChangeIdsByArray(String[] ids, String[] newIds) { |
| | | List<Integer> list = new ArrayList<>(); |
| | | if(newIds!=null){ |
| | | FLAG : |
| | | for(String s :newIds){ |
| | | for(String s1 :ids){ |
| | | if(StringUtils.equals(s,s1)){ |
| | | continue FLAG; |
| | | } |
| | | } |
| | | list.add(Integer.parseInt(s)); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | @Override |
| | | public void updateStatusById(DeviceRole deviceRole) { |
| | | // 获取之前是否存在默认门禁组 |
| | | DeviceRole newDeviceRole = null; |
| | | if(Constants.ONE == deviceRole.getStatus() && null != deviceRole.getType()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getStatus(), deviceRole.getType()); |
| | | if(null != deviceRole.getType()) { |
| | | newDeviceRole = getDeviceRole(deviceRole.getType()); |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | List<DeviceRole> deviceRoleList = new ArrayList<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | private DeviceRole getDeviceRole(Integer status, Integer type) { |
| | | private DeviceRole getDeviceRole(String 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); |
| | | .last(" limit 1"); |
| | | // 查询是否有默认门禁组,只能有一组默认门禁组 |
| | | DeviceRole getDeviceRole = deviceRoleMapper.selectOne(query); |
| | | return getDeviceRole; |
| | |
| | | IPage<DeviceRole> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<DeviceRole> queryWrapper = new QueryWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | pageWrap.getModel().setIsdeleted(Constants.ZERO); |
| | | queryWrapper.select("*,(select count(1) from member_role b where b.isdeleted=0 and b.role_id=device_role.id) as memberNum"); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.lambda().eq(DeviceRole::getId, pageWrap.getModel().getId()); |
| | | } |
| | |
| | | queryWrapper.lambda().eq(DeviceRole::getRemark, pageWrap.getModel().getRemark()); |
| | | } |
| | | if (pageWrap.getModel().getName() != null) { |
| | | queryWrapper.lambda().eq(DeviceRole::getName, pageWrap.getModel().getName()); |
| | | queryWrapper.lambda().like(DeviceRole::getName, pageWrap.getModel().getName()); |
| | | } |
| | | if (pageWrap.getModel().getIsDefault() != null) { |
| | | queryWrapper.lambda().eq(DeviceRole::getIsDefault, pageWrap.getModel().getIsDefault()); |
| | | } |
| | | if (pageWrap.getModel().getType() != null) { |
| | | queryWrapper.lambda().eq(DeviceRole::getType, pageWrap.getModel().getType()); |
| | | if (StringUtils.isNotBlank(pageWrap.getModel().getType())) { |
| | | if(pageWrap.getModel().getType().length() > 1) { |
| | | String[] types = pageWrap.getModel().getType().split(","); |
| | | queryWrapper.lambda().and(p-> p.eq(DeviceRole::getType, types[0]) |
| | | .or() |
| | | .eq(DeviceRole::getType, types[1])); |
| | | }else { |
| | | queryWrapper.lambda().eq(DeviceRole::getType, pageWrap.getModel().getType()); |
| | | } |
| | | } |
| | | if (pageWrap.getModel().getDoorIds() != null) { |
| | | queryWrapper.lambda().eq(DeviceRole::getDoorIds, pageWrap.getModel().getDoorIds()); |
| | |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | queryWrapper.lambda().orderByAsc( DeviceRole::getName); |
| | | IPage<DeviceRole> newPage = deviceRoleMapper.selectPage(page, queryWrapper); |
| | | if(null != newPage && newPage.getRecords().size() > 0) { |
| | | List<DeviceRole> deviceRoleList = newPage.getRecords(); |
| | | for (DeviceRole dto:deviceRoleList) { |
| | | List<DeviceRole> deviceRoleList = newPage.getRecords(); |
| | | /* for (DeviceRole dto:deviceRoleList) { |
| | | Member member = new Member(); |
| | | member.setIsdeleted(Constants.ZERO); |
| | | member.setRoleId(dto.getId()); |
| | | dto.setMemberNum((int) memberService.count(member)); |
| | | } |
| | | member.setRoleIdParam("["+dto.getId()+"]"); |
| | | dto.setMemberNum( memberMapper.selectCount(new QueryWrapper<>(member))); |
| | | }*/ |
| | | newPage.setRecords(deviceRoleList); |
| | | } |
| | | return PageData.from(newPage); |
| | |
| | | List<DeviceRole> deviceRoleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda() |
| | | .eq(DeviceRole::getType,type) |
| | | .eq(DeviceRole::getIsdeleted, Constants.ZERO) |
| | | .eq(DeviceRole::getStatus, Constants.ZERO) |
| | | .eq(DeviceRole::getStatus, Constants.ONE) |
| | | ); |
| | | List<DeviceRoleVO> deviceRoleVOList = new ArrayList<>(); |
| | | for (DeviceRole deviceRole:deviceRoleList) { |