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

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;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.BaseConstants;
import cn.iocoder.yudao.common.CommonErrorCodeConstants;
@ -125,7 +126,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
// 验证登录账号是否重复
AdminUserRespDTO checkUserName = adminUserApi.getUserByUsername(staffRespVO.getLoginAccount());
if (ObjectUtil.isNotEmpty(checkUserName)){
if (ObjectUtil.isNotEmpty(checkUserName)) {
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());
// 非空判断
if (CollectionUtil.isNotEmpty(roleIds)) {
permissionApi.assignUserRoleByRoleIds(userId, roleIds);
}
/* 插入标签到业务标签表 */
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());
permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), roleIdes);
}else {
} else {
permissionApi.assignUserRoleByRoleIds(staffRespVO.getUserId(), null);
}
@ -279,16 +283,17 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
/**
* 删除员工信息通过用户id
*
* @param userId 用户ID
* @author zcy
* @date 16:32 2024/8/6
* @param userId 用户ID
**/
@Override
@DSTransactional
public void deleteStaffByUserId(Long userId) {
/* 获取删除记录详细信息 */
LambdaQueryWrapper<CompanyStaff> queryWrapper =new LambdaQueryWrapper<>();
queryWrapper.eq(CompanyStaff::getUserId,userId).last("limit 1");
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CompanyStaff::getUserId, userId).last("limit 1");
CompanyStaff staff = baseMapper.selectOne(queryWrapper);
/* 验证是否已交接工作 */
Boolean flag = staffChangeService.checkChangeStatus(staff.getUserId());
@ -416,9 +421,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/
@Override
public List<CompanyStaff> getStaffList(String query) {
if (ObjectUtil.isNotEmpty(query)){
if (ObjectUtil.isNotEmpty(query)) {
return baseMapper.selectList(new LambdaQueryWrapper<CompanyStaff>()
.like(CompanyStaff::getName,query)
.like(CompanyStaff::getName, query)
.or()
.like(CompanyStaff::getTel, query)
);
@ -542,12 +547,12 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/
@Override
@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.先查是否是员工推广 */
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>()
.eq(CompanyStaff::getUniqueCode,uniqueCode);
.eq(CompanyStaff::getUniqueCode, uniqueCode);
List<CompanyStaff> staffList = this.list(queryWrapper);
if(!staffList.isEmpty()){
if (!staffList.isEmpty()) {
//员工推广
CompanyStaff staff = staffList.get(0);
//查该客户是否已被该租户的员工推广过
@ -556,7 +561,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
TenantUtils.execute(staff.getTenantId(), () -> {
thisCus[0] = customerMainService.getCustomerByUserId(user.getId());
});
if(null==thisCus[0]){
if (null == thisCus[0]) {
// 插入推广记录
BasePromotion basePromotion = new BasePromotion();
basePromotion.setOldUserId(staff.getUserId());
@ -568,9 +573,9 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
basePromotion.setUniqueCode(uniqueCode);
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.不是员工推广,再查是否是客户推广*/
}
return true;
@ -588,8 +593,8 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>()
.isNull(CompanyStaff::getUniqueCode);
List<CompanyStaff> list = this.list(queryWrapper);
if(!list.isEmpty()){
for (CompanyStaff staff:list){
if (!list.isEmpty()) {
for (CompanyStaff staff : list) {
try {
// 2 生成唯一推广码
String uniqueCode = uniqueCodeService.createUniqueCode();
@ -597,7 +602,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT);
}
staff.setUniqueCode(uniqueCode);
}catch (Exception e){
} catch (Exception e) {
//记录日志不能影响程序执行
log.error(e.getMessage());
}