From 2cf1565485060fd56e1f1f1cffbba7a4d70d42a6 Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期五, 11 四月 2025 11:06:22 +0800 Subject: [PATCH] 优化dnc,设备结构树查询,优化原有代码 --- lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java | 97 ++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 89 insertions(+), 8 deletions(-) diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java index 106de85..2518957 100644 --- a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserServiceImpl.java @@ -3,9 +3,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CacheConstant; import org.jeecg.common.constant.CommonConstant; @@ -26,6 +28,7 @@ import org.jeecg.modules.system.service.ISysUserService; import org.jeecg.modules.system.vo.MdcUserProVo; import org.jeecg.modules.system.vo.SysUserDepVo; +import org.jeecg.modules.system.vo.UserSelector; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -48,7 +51,7 @@ @Service @Slf4j public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { - + @Autowired private SysUserMapper userMapper; @Autowired @@ -79,6 +82,10 @@ MdcUserProductionMapper mdcUserProductionMapper; @Resource private ISysDictService sysDictService; + @Resource + private MdcProductionEquipmentMapper mdcProductionEquipmentMapper; + @Resource + private DncDevicePermissionMapper dncDevicePermissionMapper; @Override @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true) @@ -141,8 +148,8 @@ public SysUser getUserByName(String username) { return userMapper.getUserByName(username); } - - + + @Override @Transactional(rollbackFor = Exception.class) public void addUserWithRole(SysUser user, String roles) { @@ -203,7 +210,7 @@ roleIndex = list.get(0); } } - + //濡傛灉componentUrl涓虹┖锛屽垯杩斿洖绌� if(oConvertUtils.isEmpty(roleIndex.getComponent())){ return null; @@ -269,7 +276,7 @@ info.setSysUserName(sysUser.getRealname()); info.setSysOrgCode(sysUser.getOrgCode()); } - + //澶氶儴闂ㄦ敮鎸乮n鏌ヨ List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId()); List<String> sysMultiOrgCode = new ArrayList<String>(); @@ -285,7 +292,7 @@ } } info.setSysMultiOrgCode(sysMultiOrgCode); - + return info; } @@ -577,12 +584,24 @@ sysUserDepartMapper.insert(userDeaprt); } } + String[] arr = {}; //step.4 淇濆瓨鎵�灞炰骇绾� if (oConvertUtils.isNotEmpty(selectedProductions)) { - String[] arr = selectedProductions.split(","); + arr = selectedProductions.split(","); for (String productionId : arr) { MdcUserProduction mdcUserProduction = new MdcUserProduction(user.getId(), productionId); mdcUserProductionMapper.insert(mdcUserProduction); + } + } + //step.5 淇濆瓨璁惧鏉冮檺 + List<String> EquipmentIds= mdcProductionEquipmentMapper.selectList(new QueryWrapper<MdcProductionEquipment>().in("production_id",arr)) + .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList()); + if (oConvertUtils.isNotEmpty(EquipmentIds)) { + for (String equipmentId : EquipmentIds) { + DncDevicePermission dncDevicePermission=new DncDevicePermission(); + dncDevicePermission.setDeviceId(equipmentId); + dncDevicePermission.setUserId(user.getId()); + dncDevicePermissionMapper.insert(dncDevicePermission); } } } @@ -646,7 +665,20 @@ mdcUserProductionMapper.insert(mdcUserProduction); } } - //step.5 淇敼鎵嬫満鍙峰拰閭 + //step.5 淇敼璁惧鏉冮檺 + //鍏堝垹鍚庡姞 + dncDevicePermissionMapper.delete(new QueryWrapper<DncDevicePermission>().lambda().eq(DncDevicePermission::getUserId, user.getId())); + List<String> EquipmentIds= mdcProductionEquipmentMapper.selectList(new QueryWrapper<MdcProductionEquipment>().in("production_id",array)) + .stream().map(MdcProductionEquipment::getEquipmentId).collect(Collectors.toList()); + if (oConvertUtils.isNotEmpty(EquipmentIds)) { + for (String equipmentId : EquipmentIds) { + DncDevicePermission dncDevicePermission=new DncDevicePermission(); + dncDevicePermission.setDeviceId(equipmentId); + dncDevicePermission.setUserId(user.getId()); + dncDevicePermissionMapper.insert(dncDevicePermission); + } + } + //step.6 淇敼鎵嬫満鍙峰拰閭 // 鏇存柊鎵嬫満鍙枫�侀偖绠辩┖瀛楃涓蹭负 null userMapper.updateNullByEmptyString("email"); userMapper.updateNullByEmptyString("phone"); @@ -713,4 +745,53 @@ public List<SysUser> getEquipmentAdmin(String roleCode, String equipmentId) { return this.baseMapper.getEquipmentAdmin(roleCode, equipmentId); } + + @Override + public List<UserSelector> selectOperatorList(String equipmentCode, String productionId, String positionCode) { + LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysUser::getPost, positionCode); + if(StringUtils.isNotBlank(equipmentCode)) { + queryWrapper.and(q -> q.isNull(SysUser::getEquipmentIds).or().eq(SysUser::getEquipmentIds, "").or().like(SysUser::getEquipmentIds, equipmentCode)); + } + if(StringUtils.isNotBlank(productionId)) { + queryWrapper.exists("select 1 from mdc_user_production t where t.user_id=sys_user.id and t.pro_id={0}", productionId); + } + queryWrapper.eq(SysUser::getDelFlag, CommonConstant.DEL_FLAG_0); + queryWrapper.eq(SysUser::getStatus, CommonConstant.DEL_FLAG_1); + queryWrapper.orderByDesc(SysUser::getId); + List<SysUser> sysUsers = userMapper.selectList(queryWrapper); + List<UserSelector> collect = sysUsers.stream().map(user -> new UserSelector(user.getId(), user.getUsername(), user.getRealname())).collect(Collectors.toList()); + return collect; + } + + /** + * 鏍规嵁鐢ㄦ埛鍚嶆壒閲忚幏鍙栫湡瀹炲鍚嶆槧灏� + * @param userNames 鐢ㄦ埛鍚嶅垪琛� + * @return 鐢ㄦ埛鍚�->鐪熷疄濮撳悕鐨勬槧灏勶紙涓嶅瓨鍦ㄦ椂鍊间负null锛� + */ + @Override + public Map<String, String> getUserRealNamesByUserNames(List<String> userNames) { + if (CollectionUtils.isEmpty(userNames)) { + return Collections.emptyMap(); + } + + // 鍘婚噸骞惰繃婊ょ┖鍊� + Set<String> uniqueNames = userNames.stream() + .filter(StringUtils::isNotBlank) + .collect(Collectors.toSet()); + if (uniqueNames.isEmpty()) { + return Collections.emptyMap(); + } + + // 鎵归噺鏌ヨ锛堣嚜鍔ㄥ鐞咺N璇彞鍒嗙墖锛� + List<SysUser> users = userMapper.selectUsersByNames(new ArrayList<>(uniqueNames)); + + // 鏋勫缓鏄犲皠鍏崇郴 + return users.stream() + .collect(Collectors.toMap( + SysUser::getUsername, + SysUser::getRealname, + (existing, replacement) -> existing // 閲嶅閿鐞� + )); + } } -- Gitblit v1.9.3