| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @Service |
| | | @Slf4j |
| | | public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | |
| | | |
| | | @Autowired |
| | | private SysUserMapper userMapper; |
| | | @Autowired |
| | |
| | | MdcUserProductionMapper mdcUserProductionMapper; |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | @Resource |
| | | private MdcProductionEquipmentMapper mdcProductionEquipmentMapper; |
| | | @Resource |
| | | private DncDevicePermissionMapper dncDevicePermissionMapper; |
| | | |
| | | @Override |
| | | @CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true) |
| | |
| | | public SysUser getUserByName(String username) { |
| | | return userMapper.getUserByName(username); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addUserWithRole(SysUser user, String roles) { |
| | |
| | | roleIndex = list.get(0); |
| | | } |
| | | } |
| | | |
| | | |
| | | //如果componentUrl为空,则返回空 |
| | | if(oConvertUtils.isEmpty(roleIndex.getComponent())){ |
| | | return null; |
| | |
| | | info.setSysUserName(sysUser.getRealname()); |
| | | info.setSysOrgCode(sysUser.getOrgCode()); |
| | | } |
| | | |
| | | |
| | | //多部门支持in查询 |
| | | List<SysDepart> list = sysDepartMapper.queryUserDeparts(sysUser.getId()); |
| | | List<String> sysMultiOrgCode = new ArrayList<String>(); |
| | |
| | | } |
| | | } |
| | | info.setSysMultiOrgCode(sysMultiOrgCode); |
| | | |
| | | |
| | | return info; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result<?> checkUserIsEffective(SysUser sysUser) { |
| | | public Result<?> checkUserIsEffective(SysUser sysUser, String loginType) { |
| | | Result<?> result = new Result<Object>(); |
| | | //情况1:根据用户信息查询,该用户不存在 |
| | | if (sysUser == null) { |
| | |
| | | } |
| | | //情况4:根据用户信息查询,该用户密码系首次使用,需修改密码 |
| | | List<DictModel> dictList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_USER_FIRST_LOGIN); |
| | | if (dictList != null && !dictList.isEmpty()) { |
| | | if (!"terminal".equals(loginType) && dictList != null && !dictList.isEmpty()) { |
| | | if (CommonConstant.DEL_FLAG_1.equals(Integer.valueOf(dictList.get(0).getValue())) && CommonConstant.DEL_FLAG_1.equals(sysUser.getPasswordFlag())) { |
| | | baseCommonService.addLog("用户登录失败,用户名:" + sysUser.getUsername() + "系首次登录系统,请重置密码!", CommonConstant.LOG_TYPE_1, null); |
| | | result.setCode(5001); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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"); |
| | |
| | | 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; |
| | | } |
| | | |
| | | @Override |
| | | public List<UserSelector> selectOperatorList(String positionCode) { |
| | | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(SysUser::getPost, positionCode); |
| | | 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(); |
| | | } |
| | | |
| | | // 批量查询(自动处理IN语句分片) |
| | | List<SysUser> users = userMapper.selectUsersByNames(new ArrayList<>(uniqueNames)); |
| | | |
| | | // 构建映射关系 |
| | | return users.stream() |
| | | .collect(Collectors.toMap( |
| | | SysUser::getUsername, |
| | | SysUser::getRealname, |
| | | (existing, replacement) -> existing // 重复键处理 |
| | | )); |
| | | } |
| | | } |