From 9d58b51998420eb1eccd9e8ffaefb9a03f146365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Tue, 2 Dec 2025 15:11:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=AD=E6=9C=9F=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=AD=90=E8=B4=A6=E5=8F=B7=E8=83=BD=E7=BB=AD?= =?UTF-8?q?=E6=9C=9F=E7=9A=84=E9=99=90=E5=88=B6=EF=BC=8C=E6=89=80=E6=9C=89?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=95=86=E9=83=BD=E8=83=BD=E7=BB=AD=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AppUserServiceImpl.java | 121 +++++++++--------- 1 file changed, 59 insertions(+), 62 deletions(-) diff --git a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/AppUserServiceImpl.java b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/AppUserServiceImpl.java index 4b6d1382..9d083f8b 100644 --- a/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/AppUserServiceImpl.java +++ b/nflg-mobilebroken-repository/src/main/java/com/nflg/mobilebroken/repository/service/impl/AppUserServiceImpl.java @@ -36,7 +36,6 @@ import java.util.stream.Collectors; *

* 用户端-用户 服务实现类 *

- * * @author 曹鹏飞 * @since 2025-01-03 */ @@ -64,7 +63,7 @@ public class AppUserServiceImpl extends ServiceImpl impl private IAdminUserRoleMapService adminUserRoleMapService; @Resource - private IAdminRoleService roleService; + private IAdminRoleService roleService; @Resource private StringRedisTemplate stringRedisTemplate; @@ -83,7 +82,7 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public void disable(Integer id) { - AppUser user=new AppUser() + AppUser user = new AppUser() .setState(UserState.Disabled.getState()) .setUpdateBy(AppUserUtil.getUserName()) .setUpdateTime(LocalDateTime.now()) @@ -93,8 +92,8 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public AppUser resetPassword(Integer id, String password) { - String encodePassword=PASSWORDENCODER.encode(password); - AppUser user=getById(id); + String encodePassword = PASSWORDENCODER.encode(password); + AppUser user = getById(id); VUtils.trueThrowBusinessError(Objects.isNull(user)).throwMessage("用户不存在"); user.setState(UserState.ToBeActivated.getState()); user.setPassword(encodePassword); @@ -126,7 +125,7 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public void updatePassword(Integer userId, String password) { - AppUser user=getById(userId); + AppUser user = getById(userId); user.setPassword(PASSWORDENCODER.encode(password)).setUpdateBy(user.getName()).setUpdateTime(LocalDateTime.now()); updateById(user); } @@ -157,8 +156,8 @@ public class AppUserServiceImpl extends ServiceImpl impl .map(TBaseCustomer::getAgencyCompanyName).collect(Collectors.toList()))); } String encodePassword = PASSWORDENCODER.encode(request.getPassword()); - AppUser user=lambdaQuery().eq(AppUser::getLoginName, request.getLoginName()).one(); - if (Objects.nonNull(user)){ + AppUser user = lambdaQuery().eq(AppUser::getLoginName, request.getLoginName()).one(); + if (Objects.nonNull(user)) { VUtils.trueThrowBusinessError(!user.getIsDel()).throwMessage("登录名已存在"); user.setIsDel(false) .setName(request.getUserName()) @@ -176,7 +175,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .setState(UserState.ToBeActivated.getState()) .setExpireTime(LocalDate.of(LocalDateTime.now().getYear() + 1, 1, 1)); updateById(user); - }else { + } else { user = new AppUser() .setLoginName(request.getLoginName()) .setName(request.getUserName()) @@ -200,7 +199,7 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public List getChildren(AppUser primaryUser) { - if (!primaryUser.getIsPrimary()){ + if (!primaryUser.getIsPrimary()) { return Collections.emptyList(); } String[] companyIds = primaryUser.getCompanyId().split(","); @@ -217,7 +216,7 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public Boolean hasChildren(Integer id) { - AppUser primaryUser=getById(id); + AppUser primaryUser = getById(id); VUtils.trueThrowBusinessError(!primaryUser.getIsPrimary()).throwMessage("不是主账号"); String[] companyIds = primaryUser.getCompanyId().split(","); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -233,10 +232,10 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public List getSimpleUsers(Integer id) { - AppUser primaryUser=getById(id); + AppUser primaryUser = getById(id); List companyIds = Arrays.stream(primaryUser.getCompanyId().split(",")).map(Integer::parseInt).collect(Collectors.toList()); - List datas=new ArrayList<>(); - for (Integer companyId : companyIds){ + List datas = new ArrayList<>(); + for (Integer companyId : companyIds) { TBaseCustomer customer = customerService.getById(companyId); CompanyVO companyVO = new CompanyVO() .setId(customer.getId()) @@ -255,7 +254,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .set(AppUser::getUpdateTime, LocalDateTime.now()) .eq(AppUser::getId, id) .update(); - AppUser primaryUser=getById(id); + AppUser primaryUser = getById(id); if (primaryUser.getIsPrimary()) { List children = getChildren(primaryUser); if (CollectionUtil.isNotEmpty(children)) { @@ -270,19 +269,19 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public List getSimpleAreas(Integer userId) { - if (Objects.isNull(userId)){ + if (Objects.isNull(userId)) { List datas = adminAreaService.lambdaQuery().eq(TBaseArea::getAreaState, 1).eq(TBaseArea::getParentAreaRowId, 0).list(); List vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getAreaName())).collect(Collectors.toList()); vos.forEach(this::bindChildren); return vos; - }else { - AppUser user=getById(userId); - if (user.getIsPrimary()){ + } else { + AppUser user = getById(userId); + if (user.getIsPrimary()) { List datas = adminAreaService.lambdaQuery().eq(TBaseArea::getAreaState, 1).eq(TBaseArea::getParentAreaRowId, 0).list(); List vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getAreaName())).collect(Collectors.toList()); vos.forEach(this::bindChildren); return vos; - }else { + } else { List datas = appAreaService.lambdaQuery().eq(AppArea::getEnable, true).eq(AppArea::getParentId, 0).list(); List vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getName())).collect(Collectors.toList()); vos.forEach(this::bindChildren1); @@ -307,8 +306,8 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public Integer getPrimaryByChild(Integer userId) { - AppUser user=getById(userId); - AppUser primaryUser=getPrimaryByCompanyId(user.getCompanyId()); + AppUser user = getById(userId); + AppUser primaryUser = getPrimaryByCompanyId(user.getCompanyId()); return primaryUser.getId(); } @@ -351,19 +350,19 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public PageData searchAppUserForAdmin(SearchAppUserForAdminRequest request) { List datas = baseMapper.searchAppUserForAdmin(request); - List primarys=datas.stream().filter(AppUserForAdminVO::isPrimary).collect(Collectors.toList()); - List subs=datas.stream().filter(d->!d.isPrimary()).collect(Collectors.toList()); - subs.forEach(d->{ - AppUserForAdminVO primary=primarys.stream() - .filter(p-> Arrays.stream(p.getCompanyId().split(",")).anyMatch(c->c.equals(d.getCompanyId()))) + List primarys = datas.stream().filter(AppUserForAdminVO::isPrimary).collect(Collectors.toList()); + List subs = datas.stream().filter(d -> !d.isPrimary()).collect(Collectors.toList()); + subs.forEach(d -> { + AppUserForAdminVO primary = primarys.stream() + .filter(p -> Arrays.stream(p.getCompanyId().split(",")).anyMatch(c -> c.equals(d.getCompanyId()))) .findFirst().orElse(null); - if (Objects.isNull(primary)){ - AppUser appUser=getPrimaryByCompanyId(d.getCompanyId()); - List customers=customerService.lambdaQuery() + if (Objects.isNull(primary)) { + AppUser appUser = getPrimaryByCompanyId(d.getCompanyId()); + List customers = customerService.lambdaQuery() .in(TBaseCustomer::getId, Arrays.stream(appUser.getCompanyId().split(",")).map(Integer::parseInt).collect(Collectors.toList())) .list(); - String areaName=StrUtil.join(",",customers.stream().map(TBaseCustomer::getAreaName).flatMap(name->StrUtil.split(name, ",").stream()).collect(Collectors.toSet())); - primary=new AppUserForAdminVO() + String areaName = StrUtil.join(",", customers.stream().map(TBaseCustomer::getAreaName).flatMap(name -> StrUtil.split(name, ",").stream()).collect(Collectors.toSet())); + primary = new AppUserForAdminVO() .setPrimary(true) .setLoginName(appUser.getLoginName()) .setUserName(appUser.getName()) @@ -371,7 +370,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .setUserState(appUser.getState()) .setEmail(appUser.getEmail()) .setCompanyId(appUser.getCompanyId()) - .setCompanyName(StrUtil.join(",",customers.stream().map(TBaseCustomer::getAgencyCompanyName).collect(Collectors.toList()))) + .setCompanyName(StrUtil.join(",", customers.stream().map(TBaseCustomer::getAgencyCompanyName).collect(Collectors.toList()))) .setAreaName(areaName) .setCreateBy(appUser.getCreateBy()) .setCreateTime(appUser.getCreateTime()) @@ -379,7 +378,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .setUpdateTime(appUser.getUpdateTime()) .setExpireTime(appUser.getExpireTime()) .setId(appUser.getId()) - .setKey("u"+appUser.getId()) + .setKey("u" + appUser.getId()) .setLanguageCode(appUser.getLanguageCode()) .setLastLoginTime(appUser.getLastLoginTime()) .setName(appUser.getName()) @@ -406,7 +405,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .skip((long) (request.getPage() - 1) * request.getPageSize()) .limit(request.getPageSize()) .collect(Collectors.toList()); - page.forEach(it->{ + page.forEach(it -> { if (it.getKey().startsWith("u-")) { it.setRoles(getRoles(it.getId())); } @@ -454,7 +453,7 @@ public class AppUserServiceImpl extends ServiceImpl impl if (Objects.nonNull(d.getTitleId())) { title = positionService.getById(d.getTitleId()); } - AppUserForAdminVO vo= new AppUserForAdminVO() + AppUserForAdminVO vo = new AppUserForAdminVO() .setKey("u-" + d.getId()) .setId(d.getId()) .setAvatar(d.getAvatar()) @@ -479,9 +478,9 @@ public class AppUserServiceImpl extends ServiceImpl impl .setState(d.getExpireTime().isAfter(ChronoLocalDate.from(LocalDateTime.now())) ? 1 : 2) .setLastLoginTime(d.getLastLoginTime()) .setTitleId(d.getTitleId()) - .setTitle(Objects.isNull(title)?"":title.getPositionName()) + .setTitle(Objects.isNull(title) ? "" : title.getPositionName()) .setChildren(getChildrenOfAppUser(d.getId())); - AppUserApplyfor applyFor=appUserApplyforService.lambdaQuery() + AppUserApplyfor applyFor = appUserApplyforService.lambdaQuery() .eq(AppUserApplyfor::getUserId, d.getId()) .eq(AppUserApplyfor::getState, AppUserApplyForState.PENDINGAPPROVAL.getState().byteValue()) .ne(AppUserApplyfor::getType, AppUserApplyforType.ADD.getState().byteValue()) @@ -489,7 +488,7 @@ public class AppUserServiceImpl extends ServiceImpl impl if (Objects.nonNull(applyFor)) { vo.setKey("f-" + applyFor.getId()).setId(applyFor.getId()).setState(0); } - return (Objects.isNull(request.getState()) || Objects.equals(request.getState(), vo.getState()))? vo:null; + return (Objects.isNull(request.getState()) || Objects.equals(request.getState(), vo.getState())) ? vo : null; }); } @@ -549,9 +548,9 @@ public class AppUserServiceImpl extends ServiceImpl impl if (Objects.nonNull(d.getAreaId())) { areaName = appAreaService.getById(d.getAreaId()).getName(); } - TBaseCustomer customer=customerService.getById(Integer.valueOf(d.getCompanyId())); - TBasePosition title=positionService.getById(d.getTitleId()); - AppUserForAdminVO vo= new AppUserForAdminVO() + TBaseCustomer customer = customerService.getById(Integer.valueOf(d.getCompanyId())); + TBasePosition title = positionService.getById(d.getTitleId()); + AppUserForAdminVO vo = new AppUserForAdminVO() .setKey("u-" + d.getId()) .setId(d.getId()) .setAvatar(d.getAvatar()) @@ -577,7 +576,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .setUpdateTime(d.getUpdateTime()) .setState(d.getExpireTime().isAfter(ChronoLocalDate.from(LocalDateTime.now())) ? 1 : 2) .setLastLoginTime(d.getLastLoginTime()); - AppUserApplyfor applyFor=appUserApplyforService.lambdaQuery() + AppUserApplyfor applyFor = appUserApplyforService.lambdaQuery() .eq(AppUserApplyfor::getUserId, d.getId()) .eq(AppUserApplyfor::getState, AppUserApplyForState.PENDINGAPPROVAL.getState().byteValue()) .ne(AppUserApplyfor::getType, AppUserApplyforType.ADD.getState().byteValue()) @@ -599,7 +598,7 @@ public class AppUserServiceImpl extends ServiceImpl impl vos.addAll(applyforList.stream().map(d -> { AppArea area = appAreaService.getById(d.getAreaId()); TBaseCustomer company = customerService.getById(d.getCompanyId()); - TBasePosition title=positionService.getById(d.getTitleId()); + TBasePosition title = positionService.getById(d.getTitleId()); AppUser createdByUser = getById(d.getCreateBy()); return new AppUserForAdminVO() .setKey("f-" + d.getId()) @@ -632,11 +631,9 @@ public class AppUserServiceImpl extends ServiceImpl impl request.getIds().forEach(id -> { AppUser appUser = getById(id); VUtils.trueThrowBusinessError(Objects.isNull(appUser)) - .throwMessage("用户不存在"); + .throwMessage("用户不存在:" + id); VUtils.trueThrowBusinessError(Objects.equals(appUser.getState(), UserState.ToBeActivated.getState())) - .throwMessage(id + "未激活不能续期"); - VUtils.trueThrowBusinessError(Objects.equals(appUser.getIsPrimary(), false)) - .throwMessage(id + "不是主账号"); + .throwMessage(appUser.getName() + "未激活不能续期"); appUser.setExpireTime(appUser.getExpireTime().plusMonths(request.getMonth())); appUser.setUpdateBy(AdminUserUtil.getUserName()); appUser.setUpdateTime(now); @@ -683,15 +680,15 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public void activateUser(UserActivateRequest request) { - String code=""; + String code = ""; try { - code=StrUtil.str(Base64.getUrlDecoder().decode(request.getCode()), Charset.defaultCharset()); - }catch (IllegalArgumentException ex){ - log.error("无效的code:"+request.getCode()); - throw new NflgException(STATE.ParamErr,"无效的code:"+request.getCode()); + code = StrUtil.str(Base64.getUrlDecoder().decode(request.getCode()), Charset.defaultCharset()); + } catch (IllegalArgumentException ex) { + log.error("无效的code:" + request.getCode()); + throw new NflgException(STATE.ParamErr, "无效的code:" + request.getCode()); } - String email=code.split("\\|")[0]; - String type=code.split("\\|")[1]; + String email = code.split("\\|")[0]; + String type = code.split("\\|")[1]; if (StrUtil.equals("0", type)) { AppUser appUser = lambdaQuery() .eq(AppUser::getIsDel, false) @@ -706,12 +703,12 @@ public class AppUserServiceImpl extends ServiceImpl impl appUser.setPassword(PASSWORDENCODER.encode(request.getPassword())); appUser.setUpdateTime(LocalDateTime.now()); updateById(appUser); - }else if (StrUtil.equals("1", type)){ + } else if (StrUtil.equals("1", type)) { //修改邮箱 - code=stringRedisTemplate.opsForValue().get(Constant.REDIS_KEY_CHANGE_EMAIL_CODE + email); + code = stringRedisTemplate.opsForValue().get(Constant.REDIS_KEY_CHANGE_EMAIL_CODE + email); VUtils.trueThrowBusinessError(!StrUtil.equals(code, request.getRandomCode())) .throwMessage("无效的激活码"); - String email1=stringRedisTemplate.opsForValue().get(Constant.REDIS_KEY_CHANGE_EMAIL_CODE + code); + String email1 = stringRedisTemplate.opsForValue().get(Constant.REDIS_KEY_CHANGE_EMAIL_CODE + code); VUtils.trueThrowBusinessError(StrUtil.isBlank(email1)) .throwMessage("无效的激活码"); AppUser user = lambdaQuery().eq(AppUser::getIsDel, 0).eq(AppUser::getLoginName, email).one(); @@ -722,7 +719,7 @@ public class AppUserServiceImpl extends ServiceImpl impl .set(AppUser::getLoginName, email1) .set(AppUser::getState, UserState.Activated.getState()) .set(AppUser::getPassword, PASSWORDENCODER.encode(request.getPassword())) - .set(AppUser::getUpdateBy,user.getName()) + .set(AppUser::getUpdateBy, user.getName()) .set(AppUser::getUpdateTime, LocalDateTime.now()) .eq(AppUser::getIsDel, 0) .eq(AppUser::getLoginName, email) @@ -734,7 +731,7 @@ public class AppUserServiceImpl extends ServiceImpl impl public AppUser forgetPassword(String email, String password) { String encodePassword = PASSWORDENCODER.encode(password); AppUser user = lambdaQuery() - .eq(AppUser::getIsDel,false) + .eq(AppUser::getIsDel, false) .eq(AppUser::getLoginName, email) .one(); VUtils.trueThrowBusinessError(Objects.isNull(user)).throwMessage("用户不存在"); @@ -750,7 +747,7 @@ public class AppUserServiceImpl extends ServiceImpl impl @Override public AppUser getPrimaryByCompanyId(String companyId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(AppUser::getIsDel,false); + queryWrapper.eq(AppUser::getIsDel, false); queryWrapper.eq(AppUser::getIsPrimary, true); queryWrapper.apply("FIND_IN_SET({0}, company_id)>0", companyId); return getBaseMapper().selectOne(queryWrapper); @@ -758,7 +755,7 @@ public class AppUserServiceImpl extends ServiceImpl impl private List getByCompanyId(Integer companyId) { return lambdaQuery() - .eq(AppUser::getIsDel,false) + .eq(AppUser::getIsDel, false) .eq(AppUser::getCompanyId, companyId.toString()) // .eq(AppUser::getState, UserState.Activated.getState()) .eq(AppUser::getIsPrimary, false)