新增员工角色权限非空判断

This commit is contained in:
xiaofajia 2024-10-31 10:53:00 +08:00
parent 3c1b2355db
commit c939fbe59b

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.staff.service.impl; package cn.iocoder.yudao.module.staff.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.BaseConstants; import cn.iocoder.yudao.common.BaseConstants;
import cn.iocoder.yudao.common.CommonErrorCodeConstants; import cn.iocoder.yudao.common.CommonErrorCodeConstants;
@ -125,7 +126,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
// 验证登录账号是否重复 // 验证登录账号是否重复
AdminUserRespDTO checkUserName = adminUserApi.getUserByUsername(staffRespVO.getLoginAccount()); AdminUserRespDTO checkUserName = adminUserApi.getUserByUsername(staffRespVO.getLoginAccount());
if (ObjectUtil.isNotEmpty(checkUserName)){ if (ObjectUtil.isNotEmpty(checkUserName)) {
throw exception(CommonErrorCodeConstants.LOGIN_ACCOUNT_EXIST); throw exception(CommonErrorCodeConstants.LOGIN_ACCOUNT_EXIST);
} }
@ -175,7 +176,10 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
// 新增角色权限 // 新增角色权限
Set<Long> roleIds = staffRespVO.getRoleIds().stream().collect(Collectors.toSet()); Set<Long> roleIds = staffRespVO.getRoleIds().stream().collect(Collectors.toSet());
permissionApi.assignUserRoleByRoleIds(userId, roleIds); // 非空判断
if (CollectionUtil.isNotEmpty(roleIds)) {
permissionApi.assignUserRoleByRoleIds(userId, roleIds);
}
/* 插入标签到业务标签表 */ /* 插入标签到业务标签表 */
if (ObjectUtil.isNotEmpty(staffRespVO.getLabelsArray())) { if (ObjectUtil.isNotEmpty(staffRespVO.getLabelsArray())) {
@ -235,10 +239,10 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
} }
/* 修改角色 */ /* 修改角色 */
if (ObjectUtil.isNotEmpty(staffRespVO.getRoleIds())){ if (ObjectUtil.isNotEmpty(staffRespVO.getRoleIds())) {
Set<Long> roleIdes = staffRespVO.getRoleIds().stream().collect(Collectors.toSet()); Set<Long> roleIdes = staffRespVO.getRoleIds().stream().collect(Collectors.toSet());
permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), roleIdes); permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), roleIdes);
}else { } else {
permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), null); permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), null);
} }
@ -279,16 +283,17 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
/** /**
* 删除员工信息通过用户id * 删除员工信息通过用户id
*
* @param userId 用户ID
* @author zcy * @author zcy
* @date 16:32 2024/8/6 * @date 16:32 2024/8/6
* @param userId 用户ID
**/ **/
@Override @Override
@DSTransactional @DSTransactional
public void deleteStaffByUserId(Long userId) { public void deleteStaffByUserId(Long userId) {
/* 获取删除记录详细信息 */ /* 获取删除记录详细信息 */
LambdaQueryWrapper<CompanyStaff> queryWrapper =new LambdaQueryWrapper<>(); LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CompanyStaff::getUserId,userId).last("limit 1"); queryWrapper.eq(CompanyStaff::getUserId, userId).last("limit 1");
CompanyStaff staff = baseMapper.selectOne(queryWrapper); CompanyStaff staff = baseMapper.selectOne(queryWrapper);
/* 验证是否已交接工作 */ /* 验证是否已交接工作 */
Boolean flag = staffChangeService.checkChangeStatus(staff.getUserId()); Boolean flag = staffChangeService.checkChangeStatus(staff.getUserId());
@ -416,9 +421,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/ **/
@Override @Override
public List<CompanyStaff> getStaffList(String query) { public List<CompanyStaff> getStaffList(String query) {
if (ObjectUtil.isNotEmpty(query)){ if (ObjectUtil.isNotEmpty(query)) {
return baseMapper.selectList(new LambdaQueryWrapper<CompanyStaff>() return baseMapper.selectList(new LambdaQueryWrapper<CompanyStaff>()
.like(CompanyStaff::getName,query) .like(CompanyStaff::getName, query)
.or() .or()
.like(CompanyStaff::getTel, query) .like(CompanyStaff::getTel, query)
); );
@ -532,9 +537,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
/** /**
* 新增推广记录---忽略租户 * 新增推广记录---忽略租户
* *
* @param dataFrom 客户来源 * @param dataFrom 客户来源
* @param uniqueCode 推广码 * @param uniqueCode 推广码
* @param user 被推广用户 * @param user 被推广用户
* @param promotionChannel 推广渠道 * @param promotionChannel 推广渠道
* @param registerTime 被推广用户注册的时间 * @param registerTime 被推广用户注册的时间
* @author vinjor-m * @author vinjor-m
@ -542,12 +547,12 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/ **/
@Override @Override
@TenantIgnore @TenantIgnore
public Boolean createPromotion(String dataFrom,String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime) { public Boolean createPromotion(String dataFrom, String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime) {
/*1.先查是否是员工推广 */ /*1.先查是否是员工推广 */
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>() LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>()
.eq(CompanyStaff::getUniqueCode,uniqueCode); .eq(CompanyStaff::getUniqueCode, uniqueCode);
List<CompanyStaff> staffList = this.list(queryWrapper); List<CompanyStaff> staffList = this.list(queryWrapper);
if(!staffList.isEmpty()){ if (!staffList.isEmpty()) {
//员工推广 //员工推广
CompanyStaff staff = staffList.get(0); CompanyStaff staff = staffList.get(0);
//查该客户是否已被该租户的员工推广过 //查该客户是否已被该租户的员工推广过
@ -556,7 +561,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
TenantUtils.execute(staff.getTenantId(), () -> { TenantUtils.execute(staff.getTenantId(), () -> {
thisCus[0] = customerMainService.getCustomerByUserId(user.getId()); thisCus[0] = customerMainService.getCustomerByUserId(user.getId());
}); });
if(null==thisCus[0]){ if (null == thisCus[0]) {
// 插入推广记录 // 插入推广记录
BasePromotion basePromotion = new BasePromotion(); BasePromotion basePromotion = new BasePromotion();
basePromotion.setOldUserId(staff.getUserId()); basePromotion.setOldUserId(staff.getUserId());
@ -568,9 +573,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
basePromotion.setUniqueCode(uniqueCode); basePromotion.setUniqueCode(uniqueCode);
basePromotionService.save(basePromotion); basePromotionService.save(basePromotion);
//将客户信息授权给员工所属的租户 //将客户信息授权给员工所属的租户
userCarService.empowerUserInfo(staff.getTenantId(),dataFrom,staff.getUserId(),user.getId(),InviterTypeEnum.STAFF.getCode()); userCarService.empowerUserInfo(staff.getTenantId(), dataFrom, staff.getUserId(), user.getId(), InviterTypeEnum.STAFF.getCode());
} }
}else{ } else {
/*2.不是员工推广,再查是否是客户推广*/ /*2.不是员工推广,再查是否是客户推广*/
} }
return true; return true;
@ -588,8 +593,8 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>() LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>()
.isNull(CompanyStaff::getUniqueCode); .isNull(CompanyStaff::getUniqueCode);
List<CompanyStaff> list = this.list(queryWrapper); List<CompanyStaff> list = this.list(queryWrapper);
if(!list.isEmpty()){ if (!list.isEmpty()) {
for (CompanyStaff staff:list){ for (CompanyStaff staff : list) {
try { try {
// 2 生成唯一推广码 // 2 生成唯一推广码
String uniqueCode = uniqueCodeService.createUniqueCode(); String uniqueCode = uniqueCodeService.createUniqueCode();
@ -597,7 +602,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT); throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT);
} }
staff.setUniqueCode(uniqueCode); staff.setUniqueCode(uniqueCode);
}catch (Exception e){ } catch (Exception e) {
//记录日志不能影响程序执行 //记录日志不能影响程序执行
log.error(e.getMessage()); log.error(e.getMessage());
} }