project-admin/src/main/java/com/project/admin/controller/system/SysProfileController.java
@@ -136,30 +136,48 @@ * 更换手机号 */ @Log(title = "更换手机号", businessType = BusinessType.UPDATE) @PostMapping("/updatePhone/{phone}") public AjaxResult updatePhone(@PathVariable String phone) @PostMapping("/updatePhone/{phone}/{companyId}") public AjaxResult updatePhone(@PathVariable String phone, @PathVariable String companyId) { if (StringUtils.isEmpty(phone)){ return error("请填写手机号"); } LoginUser loginUser = SecurityUtils.getLoginUser(); SysUser user = userService.selectUserById(SecurityUtils.getUserId()); if ("02".equals(user.getUserType()) && StringUtils.isNotEmpty(companyId)){//企业 //多企业账户更换号码 //新号码不存在, SysUser one = userService.getOne(userService.lq().eq(SysUser::getPhonenumber, phone)); if (one!=null && !"02".equals(one.getUserType())){ return error("该手机号不是企业号码范围,请更换号码"); } if (companyService.count(SysCompany::getCompanyPhone, user.getPhonenumber())==1){ userService.deleteUserByCompanyPhone(user.getPhonenumber()); } if (one==null){ //不存在,添加企业账户 SysCompany company = companyService.getById(Long.parseLong(companyId)); company.setCompanyPhone(phone); companyService.addCompanyUser(company, 1); } //修改企业电话 companyService.update(companyService.lu().set(SysCompany::getCompanyPhone, phone).eq(SysCompany::getCompanyId, Long.parseLong(companyId))); return success(1); } user.setPhonenumber(phone); if (StringUtils.isNotEmpty(user.getPhonenumber()) && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); } if (userService.resetPhone(user.getUserId(), phone) > 0) { // 更新缓存 loginUser.getUser().setUserName(phone); loginUser.getUser().setPhonenumber(phone); tokenService.setLoginUser(loginUser); if ("02".equals(user.getUserType())){ companyService.update(companyService.lu().set(SysCompany::getCompanyPhone, phone).eq(SysCompany::getCompanyId, user.getDeptId())); } return success(); return success(0); } return error("修改密码异常,请联系管理员"); } project-system/src/main/java/com/project/system/service/ISysCompanyService.java
@@ -78,4 +78,12 @@ */ Boolean saveImport(SysCompanyResultVo resultVo); /** * 添加企业账户 * @param entity 企业 * @param isImport 是否导入:1是,0否 */ void addCompanyUser(SysCompany entity, Integer isImport); } project-system/src/main/java/com/project/system/service/ISysUserService.java
@@ -211,10 +211,10 @@ /** * 根据机构id清除用户 * @param deptId 机构id * @param phone 企业phone * @return 结果 */ public int deleteUserByDeptId(Long deptId); public int deleteUserByCompanyPhone(String phone); /** * 获取角色标识人手机号 project-system/src/main/java/com/project/system/service/impl/SysCompanyServiceImpl.java
@@ -62,9 +62,10 @@ SysCompany add = Convert.convert(SysCompany.class, bo); add.setCompanyStatus(1); validEntityBeforeSave(add); add.setCompanyStatus(0); boolean save = this.save(add); addCompanyUser(add, 0); if (isAddUser(bo.getCompanyPhone())){ addCompanyUser(add, 0); } return save; } @@ -76,11 +77,15 @@ SysCompany update = Convert.convert(SysCompany.class, bo); validEntityBeforeSave(update); if (!old.getCompanyPhone().equals(update.getCompanyPhone())){ boolean delUser = delCompanyUser(old.getCompanyId()); if (!delUser) { throw new BaseException("原企业用户清除失败,请联系管理员!"); if (this.count(SysCompany::getCompanyPhone, old.getCompanyPhone())==1){ boolean delUser = delCompanyUser(old.getCompanyPhone()); if (!delUser) { throw new BaseException("原企业用户清除失败,请联系管理员!"); } } this.addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0); if (isAddUser(update.getCompanyPhone())){ addCompanyUser(update, update.getCompanyStatus()==0 ? 1 : 0); } } return this.updateById(update); } @@ -103,7 +108,7 @@ public Boolean deleteByIds(Collection<Long> ids) { for (Long id : ids) { boolean b = delCompanyUser(id); boolean b = delCompanyUser(this.getById(id).getCompanyPhone()); if (!b) { throw new BaseException(String.format("原企业 %1$s 用户清除失败,请联系管理员!", id)); } @@ -153,7 +158,9 @@ List<SysCompany> companies = Convert.toList(SysCompany.class, resultVo.getVoList()); boolean b = this.saveOrUpdateBatch(companies); for (SysCompany company : companies) { addCompanyUser(company,1); if (isAddUser(company.getCompanyPhone())){ addCompanyUser(company,1); } } return b; } @@ -168,6 +175,7 @@ private void validEntityBeforeSave(SysCompany entity) { entity.setIsImport(0); if (StringUtils.isEmpty(entity.getCompanyImg())){ throw new BaseException(String.format("%1$s,请上传营业执照", entity.getCompanyName())); } @@ -195,15 +203,8 @@ if (nameCount>0){ throw new BaseException(String.format("%1$s,企业名已存在!", entity.getCompanyName())); } int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); if (phoneCount>0){ throw new BaseException(String.format("%1$s,企业联系电话已存在!", entity.getCompanyName())); } SysUser user = new SysUser(); user.setPhonenumber(entity.getCompanyPhone()); if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { throw new BaseException(String.format("%1$s,企业联系电话已存在,请更换手机号!", entity.getCompanyName())); } } else { int codeCount = this.count(lq().eq(SysCompany::getCompanyCode, entity.getCompanyCode()).ne(SysCompany::getCompanyId,entity.getCompanyId())); if (codeCount>0){ @@ -212,10 +213,6 @@ int nameCount = this.count(lq().eq(SysCompany::getCompanyName, entity.getCompanyName()).ne(SysCompany::getCompanyId,entity.getCompanyId())); if (nameCount>0){ throw new BaseException(String.format("%1$s,企业名已存在!", entity.getCompanyName())); } int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone()).ne(SysCompany::getCompanyId,entity.getCompanyId())); if (phoneCount>0){ throw new BaseException(String.format("%1$s,企业联系电话已存在!", entity.getCompanyName())); } } } @@ -235,6 +232,10 @@ } if (StringUtils.isEmpty(entity.getCompanyPhone())){ errorList.add(new ImportError(3, "请填写企业联系人电话!")); } else { if (entity.getCompanyPhone().length()!=11){ errorList.add(new ImportError(3, "请填写正确手机号!")); } } if (StringUtils.isEmpty(entity.getCompanyAddress())){ errorList.add(new ImportError(4, "请填写企业地址!")); @@ -247,15 +248,6 @@ if (nameCount>0){ errorList.add(new ImportError(0, "企业名已存在!")); } int phoneCount = this.count(lq().eq(SysCompany::getCompanyPhone, entity.getCompanyPhone())); SysUser user = new SysUser(); user.setPhonenumber(entity.getCompanyPhone()); if (UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { errorList.add(new ImportError(3, "企业联系电话系统中已存在,请更换电话!")); } if (phoneCount>0){ errorList.add(new ImportError(3, "企业联系电话已存在!")); } entity.setCheckStatus(2); } @@ -264,7 +256,8 @@ * @param entity 企业信息 */ @Async protected void addCompanyUser(SysCompany entity, Integer isImport) @Override public void addCompanyUser(SysCompany entity, Integer isImport) { SysUser user = new SysUser(); @@ -308,11 +301,11 @@ /** * 删除企业用户 * @param companyId 企业id * @param companyPhone 企业id */ protected boolean delCompanyUser(Long companyId) protected boolean delCompanyUser(String companyPhone) { return userService.deleteUserByDeptId(companyId)>0; return userService.deleteUserByCompanyPhone(companyPhone)>0; } /** @@ -346,4 +339,9 @@ } return qw; } private Boolean isAddUser(String phone) { return userService.count(userService.lq().eq(SysUser::getUserName, phone).eq(SysUser::getDelFlag,0))==0; } } project-system/src/main/java/com/project/system/service/impl/SysUserDeptServiceImpl.java
@@ -96,7 +96,7 @@ vo.setDeptId(sysDept.getDeptId()); vo.setDeptName(sysDept.getDeptName()); List<SysDept> list = deptService.list(deptService.lq().eq(SysDept::getParentId, deptId)); List<SysDept> list = deptService.list(deptService.lq().eq(SysDept::getParentId, deptId).eq(SysDept::getDelFlag, 0)); List<SysUserDeptTreeVo> child = Convert.toList(SysUserDeptTreeVo.class, list); vo.setChild(child); return vo; project-system/src/main/java/com/project/system/service/impl/SysUserServiceImpl.java
@@ -574,14 +574,14 @@ /** * 批量删除用户信息 * * @param deptId 需要删除的用户ID * @param phone 需要删除的用户ID * @return 结果 */ @Override @Transactional public int deleteUserByDeptId(Long deptId) public int deleteUserByCompanyPhone(String phone) { List<SysUser> sysUsers = userMapper.selectList(new LambdaQueryWrapper<SysUser>().eq(SysUser::getDeptId, deptId)); List<SysUser> sysUsers = userMapper.selectList(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, phone)); Long[] ids = sysUsers.stream().map(SysUser::getUserId).toArray(Long[]::new); return this.deleteUserByIds(ids); }