feat: 续期移除只有子账号能续期的限制,所有代理商都能续期

This commit is contained in:
曹鹏飞 2025-12-02 15:11:34 +08:00
parent cfcde9db80
commit 9d58b51998
1 changed files with 59 additions and 62 deletions

View File

@ -36,7 +36,6 @@ import java.util.stream.Collectors;
* <p>
* 用户端-用户 服务实现类
* </p>
*
* @author 曹鹏飞
* @since 2025-01-03
*/
@ -64,7 +63,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
private IAdminUserRoleMapService adminUserRoleMapService;
@Resource
private IAdminRoleService roleService;
private IAdminRoleService roleService;
@Resource
private StringRedisTemplate stringRedisTemplate;
@ -83,7 +82,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> impl
@Override
public List<AppUser> 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<AppUserMapper, AppUser> 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<AppUser> queryWrapper = new LambdaQueryWrapper<>();
@ -233,10 +232,10 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
@Override
public List<CompanyVO> getSimpleUsers(Integer id) {
AppUser primaryUser=getById(id);
AppUser primaryUser = getById(id);
List<Integer> companyIds = Arrays.stream(primaryUser.getCompanyId().split(",")).map(Integer::parseInt).collect(Collectors.toList());
List<CompanyVO> datas=new ArrayList<>();
for (Integer companyId : companyIds){
List<CompanyVO> 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<AppUserMapper, AppUser> impl
.set(AppUser::getUpdateTime, LocalDateTime.now())
.eq(AppUser::getId, id)
.update();
AppUser primaryUser=getById(id);
AppUser primaryUser = getById(id);
if (primaryUser.getIsPrimary()) {
List<AppUser> children = getChildren(primaryUser);
if (CollectionUtil.isNotEmpty(children)) {
@ -270,19 +269,19 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
@Override
public List<AreaSimpleVO> getSimpleAreas(Integer userId) {
if (Objects.isNull(userId)){
if (Objects.isNull(userId)) {
List<TBaseArea> datas = adminAreaService.lambdaQuery().eq(TBaseArea::getAreaState, 1).eq(TBaseArea::getParentAreaRowId, 0).list();
List<AreaSimpleVO> 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<TBaseArea> datas = adminAreaService.lambdaQuery().eq(TBaseArea::getAreaState, 1).eq(TBaseArea::getParentAreaRowId, 0).list();
List<AreaSimpleVO> 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<AppArea> datas = appAreaService.lambdaQuery().eq(AppArea::getEnable, true).eq(AppArea::getParentId, 0).list();
List<AreaSimpleVO> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> impl
@Override
public PageData<AppUserForAdminVO> searchAppUserForAdmin(SearchAppUserForAdminRequest request) {
List<AppUserForAdminVO> datas = baseMapper.searchAppUserForAdmin(request);
List<AppUserForAdminVO> primarys=datas.stream().filter(AppUserForAdminVO::isPrimary).collect(Collectors.toList());
List<AppUserForAdminVO> 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<AppUserForAdminVO> primarys = datas.stream().filter(AppUserForAdminVO::isPrimary).collect(Collectors.toList());
List<AppUserForAdminVO> 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<TBaseCustomer> customers=customerService.lambdaQuery()
if (Objects.isNull(primary)) {
AppUser appUser = getPrimaryByCompanyId(d.getCompanyId());
List<TBaseCustomer> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> 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<AppUserMapper, AppUser> impl
@Override
public AppUser getPrimaryByCompanyId(String companyId) {
LambdaQueryWrapper<AppUser> 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<AppUserMapper, AppUser> impl
private List<AppUserVO> 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)