| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | import static org.springblade.common.constant.CommonConstant.DEFAULT_PARAM_PASSWORD; |
| | |
| | | if (Func.isNotEmpty(user.getPassword())) { |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | } |
| | | // Integer userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount())); |
| | | // if (userCount > 0 && Func.isEmpty(user.getId())) { |
| | | // throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | // } |
| | | Integer userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount())); |
| | | if (userCount > 0 && Func.isEmpty(user.getId())) { |
| | | throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | } |
| | | boolean b = save(user) && submitUserDept(user); |
| | | String rtime = null; |
| | | if (null != user.getRtime()) { |
| | | rtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getRtime()); |
| | | } |
| | | user.setIsDeleted(0); |
| | | String s = "insert into blade_user(id,tenant_id,account,password,real_name,email,phone,sex,role_id,dept_id,cardid,nativePlace,nation," + |
| | | "politicaloutlook,healstats,height,address,registered,securitynumber,hold,status,dispatch) " + |
| | | "politicaloutlook,healstats,height,address,registered,securitynumber,hold,status,dispatch,jurisdiction,is_deleted) " + |
| | | "values(" + "'" + user.getId() + "'" + "," + "'" + user.getTenantId() + "'" + "," + "'" + user.getAccount() + "'" + "," + |
| | | "'" + user.getPassword() + "'" + "," + "'" + user.getRealName() + "'" + "," + |
| | | "'" + user.getEmail() + "'" + "," + "'" + user.getPhone() + "'" + "," + "'" + user.getSex() + "'" + "," + "'" + user.getRoleId() + "'" + |
| | |
| | | "'" + user.getSecuritynumber() + "'" + |
| | | "," + "'" + user.getHold() + "'" + |
| | | "," + "'" + user.getStatus() + "'" + |
| | | "," + "'" + user.getDispatch() + "'" + ")"; |
| | | "," + "'" + user.getDispatch() + "'"+ |
| | | "," + "'" + user.getJurisdiction() + "'"+ |
| | | "," + "'" + user.getIsDeleted() + "'" |
| | | + ")"; |
| | | FtpUtil.sqlFileUpload(s); |
| | | return b; |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateUser(User user) { |
| | | String tenantId = user.getTenantId(); |
| | | Integer userCount = baseMapper.selectCount( |
| | | Wrappers.<User>query().lambda() |
| | | .eq(User::getTenantId, tenantId) |
| | | .eq(User::getAccount, user.getAccount()) |
| | | .notIn(User::getId, user.getId()) |
| | | ); |
| | | if (userCount > 0) { |
| | | throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | } |
| | | // String tenantId = user.getTenantId(); |
| | | // Integer userCount = baseMapper.selectCount( |
| | | // Wrappers.<User>query().lambda() |
| | | // .eq(User::getTenantId, tenantId) |
| | | // .eq(User::getAccount, user.getAccount()) |
| | | // .notIn(User::getId, user.getId()) |
| | | // ); |
| | | // if (userCount > 0) { |
| | | // throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | // } |
| | | return updateUserInfo(user) && submitUserDept(user); |
| | | } |
| | | |
| | |
| | | public IPage<UserVO> selectUserPage(IPage<UserVO> page, User user, Long deptId, String tenantId) { |
| | | List<Long> deptIdList = SysCache.getDeptChildIds(deptId); |
| | | List<UserVO> users = baseMapper.selectUserPage(page, user, deptIdList, tenantId); |
| | | //遍历获取部门名称,角色名称 |
| | | users.forEach(userVO -> { |
| | | //查询当前部门名称及父级部门名称 |
| | | List<String> list = baseMapper.getDeptName(userVO.getDeptId()); |
| | | if (list.size()>1){ |
| | | if (null!=list.get(1) && list.get(1)!=""){ |
| | | userVO.setDeptName(list.get(1)+","+list.get(0)); |
| | | }else { |
| | | userVO.setDeptName(list.get(0)); |
| | | if(users.size()>0){ |
| | | //遍历获取部门名称,角色名称 |
| | | users.forEach(userVO -> { |
| | | //查询当前部门名称及父级部门名称 |
| | | if (null!=userVO.getDeptId()) { |
| | | List<String> list = baseMapper.getDeptName(userVO.getDeptId()); |
| | | if (list.size() > 1) { |
| | | if (null != list.get(1) && list.get(1) != "") { |
| | | userVO.setDeptName(list.get(1) + "," + list.get(0)); |
| | | } else { |
| | | userVO.setDeptName(list.get(0)); |
| | | } |
| | | } |
| | | if (list.size() == 1) { |
| | | userVO.setDeptName(list.get(0)); |
| | | } |
| | | } |
| | | } |
| | | if (list.size()==1){ |
| | | userVO.setDeptName(list.get(0)); |
| | | } |
| | | //查询角色名称 |
| | | List<String> asList = Arrays.asList(userVO.getRoleId().split(",")); |
| | | StringBuilder builder = new StringBuilder(); |
| | | asList.forEach(roleIs ->{ |
| | | Role role = roleService.getById(roleIs); |
| | | if (null!=role){ |
| | | builder.append(role.getRoleName()+","); |
| | | //查询角色名称 |
| | | if (null!=userVO.getRoleId()) { |
| | | List<String> asList = Arrays.asList(userVO.getRoleId().split(",")); |
| | | StringBuilder builder = new StringBuilder(); |
| | | asList.forEach(roleIs -> { |
| | | Role role = roleService.getById(roleIs); |
| | | if (null != role) { |
| | | builder.append(role.getRoleName() + ","); |
| | | } |
| | | }); |
| | | String substringRoleName = null; |
| | | if (builder.toString().length() > 0) { |
| | | substringRoleName = builder.toString().substring(0, builder.toString().length() - 1); |
| | | } |
| | | userVO.setRoleName(substringRoleName); |
| | | } |
| | | }); |
| | | String substringRoleName = builder.toString().substring(0, builder.toString().length() - 1); |
| | | userVO.setRoleName(substringRoleName); |
| | | }); |
| | | } |
| | | return page.setRecords(users); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importUser(List<UserExcel> data, Boolean isCovered) { |
| | | public void importUser(List<UserExcel> data, Boolean isCovered,String deptId) { |
| | | data.forEach(userExcel -> { |
| | | User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class)); |
| | | // 设置租户ID |
| | |
| | | } |
| | | } |
| | | //设置部门id |
| | | user.setDeptId(userDeptService.selectIn(user.getDeptId())); |
| | | String deptIds = userDeptService.selectIn(user.getDeptId()); |
| | | if (null!=deptIds && !deptIds.equals("")) { |
| | | if (null != deptId && !deptId.equals("")) { |
| | | if (!deptId.equals(deptIds)) { |
| | | throw new ServiceException("不能导入不是本公司的保安员数据!"); |
| | | } |
| | | } |
| | | user.setDeptId(deptIds); |
| | | } |
| | | //设置账号 |
| | | user.setAccount(user.getCardid()); |
| | | //获取默认密码配置 |
| | |
| | | public Integer selectCount(String account) { |
| | | return baseMapper.selectCountAccount(account); |
| | | } |
| | | |
| | | /** |
| | | * 查询用户表中未删除,未离职的用户信息 |
| | | * @param username |
| | | * @return |
| | | */ |
| | | @Override |
| | | public User getUserInfo(String username) { |
| | | return baseMapper.getUserInfo(username); |
| | | } |
| | | } |