weaver-hrm-salary/src/com/engine/salary/service/auth/AuthDataServiceImpl.java

158 lines
6.0 KiB
Java
Raw Normal View History

2024-07-30 17:45:02 +08:00
package com.engine.salary.service.auth;
2024-08-19 15:29:45 +08:00
import cn.hutool.core.collection.CollectionUtil;
2024-07-30 17:45:02 +08:00
import com.engine.core.impl.Service;
import com.engine.salary.constant.SalaryDefaultTenantConstant;
2024-09-02 10:22:42 +08:00
import com.engine.salary.entity.auth.dto.AuthRoleDataDTO;
2024-07-30 17:45:02 +08:00
import com.engine.salary.entity.auth.param.AuthDataSaveParam;
2024-08-06 10:46:33 +08:00
import com.engine.salary.entity.auth.param.AuthSyncParam;
2024-07-30 18:55:02 +08:00
import com.engine.salary.entity.auth.po.AuthDataPO;
import com.engine.salary.entity.auth.po.AuthRoleDataPO;
import com.engine.salary.entity.auth.po.AuthRolePO;
2024-07-30 17:45:02 +08:00
import com.engine.salary.enums.auth.DataLinkEnum;
import com.engine.salary.enums.auth.DataTargetTypeEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.auth.AuthDataMapper;
import com.engine.salary.mapper.auth.AuthRoleDataMapper;
import com.engine.salary.mapper.auth.AuthRoleEmpMapper;
import com.engine.salary.mapper.auth.AuthRoleMapper;
import com.engine.salary.util.db.IdGenerator;
import com.engine.salary.util.db.MapperProxyFactory;
import com.google.common.collect.Lists;
2024-07-30 18:55:02 +08:00
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
2024-07-30 17:45:02 +08:00
import java.util.stream.Collectors;
public class AuthDataServiceImpl extends Service implements AuthDataService {
private AuthDataMapper getAuthDataMapper() {
return MapperProxyFactory.getProxy(AuthDataMapper.class);
}
private AuthRoleMapper getAuthRoleMapper() {
return MapperProxyFactory.getProxy(AuthRoleMapper.class);
}
private AuthRoleEmpMapper getAuthRoleEmpMapper() {
return MapperProxyFactory.getProxy(AuthRoleEmpMapper.class);
}
2024-07-30 18:55:02 +08:00
2024-07-30 17:45:02 +08:00
private AuthRoleDataMapper getAuthRoleDataMapper() {
return MapperProxyFactory.getProxy(AuthRoleDataMapper.class);
}
@Override
public List<AuthDataPO> list(Long roleId) {
AuthRolePO rolePO = getAuthRoleMapper().getById(roleId);
if (rolePO == null) {
throw new SalaryRunTimeException("角色不存在!");
}
return getAuthDataMapper().listSome(AuthDataPO.builder().roleId(roleId).build());
}
@Override
2024-08-08 10:01:41 +08:00
public void save(List<AuthDataSaveParam> params) {
params.forEach(param -> {
Date now = new Date();
Long roleId = param.getRoleId();
AuthRolePO rolePO = getAuthRoleMapper().getById(roleId);
if (rolePO == null) {
throw new SalaryRunTimeException("角色不存在!");
}
2024-07-30 17:45:02 +08:00
2024-08-22 15:37:50 +08:00
if(param.getId() == null){
AuthDataPO dataPO = AuthDataPO.builder()
.id(IdGenerator.generate())
.roleId(param.getRoleId())
.link(param.getLink().getValue())
.targetType(param.getTargetType().getValue())
.target(param.getTarget())
.targetName(param.getTargetName())
.sortedIndex(param.getSortedIndex())
.creator((long) user.getUID())
.createTime(now)
.updateTime(now)
.deleteType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build();
getAuthDataMapper().insertIgnoreNull(dataPO);
}else{
getAuthDataMapper().getById(param.getId());
AuthDataPO dataPO = AuthDataPO.builder()
.id(param.getId())
.link(param.getLink().getValue())
.targetType(param.getTargetType().getValue())
.target(param.getTarget())
.targetName(param.getTargetName())
.sortedIndex(param.getSortedIndex())
.creator((long) user.getUID())
.updateTime(now)
.deleteType(0)
.build();
getAuthDataMapper().updateIgnoreNull(dataPO);
}
2024-08-08 10:01:41 +08:00
});
2024-07-30 17:45:02 +08:00
}
2024-08-19 15:29:45 +08:00
@Override
public void delete(List<Long> ids) {
if(CollectionUtil.isNotEmpty(ids)){
getAuthDataMapper().deleteByIds(ids);
}
}
2024-07-30 17:45:02 +08:00
@Override
2024-08-06 10:46:33 +08:00
public void sync(AuthSyncParam param) {
Long roleId = param.getRoleId();
2024-07-30 17:45:02 +08:00
Date now = new Date();
List<AuthDataPO> list = list(roleId);
2024-07-30 18:55:02 +08:00
Set<Long> ids = new HashSet<>();
2024-07-30 17:45:02 +08:00
for (int i = 0; i < list.size(); i++) {
AuthDataPO dataPO = list.get(i);
DataTargetTypeEnum dataTargetTypeEnum = DataTargetTypeEnum.parseByValue(dataPO.getTargetType());
DataLinkEnum dataLinkEnum = DataLinkEnum.parseByValue(dataPO.getLink());
Set<Long> empResult = dataTargetTypeEnum.getEmpIds(dataPO.getTarget());
if (i == 0) {
ids = empResult;
} else {
ids = dataLinkEnum.calculation(ids, empResult);
}
}
2024-07-30 18:55:02 +08:00
getAuthRoleDataMapper().deleteByRoleId(roleId);
List<AuthRoleDataPO> collect = ids.stream().map(empId ->
AuthRoleDataPO.builder()
.id(IdGenerator.generate())
.roleId(roleId)
.employeeId(empId)
.creator((long) user.getUID())
.createTime(now)
.updateTime(now)
.deleteType(0)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build())
2024-07-30 17:45:02 +08:00
.collect(Collectors.toList());
List<List<AuthRoleDataPO>> partition = Lists.partition(collect, 100);
2024-07-30 18:55:02 +08:00
partition.forEach(pos -> getAuthRoleDataMapper().batchInsert(pos));
2024-07-30 17:45:02 +08:00
}
2024-08-23 09:38:54 +08:00
@Override
public void deleteByRoleId(Long roleId) {
getAuthDataMapper().deleteByRoleId(roleId);
getAuthRoleDataMapper().deleteByRoleId(roleId);
}
2024-08-30 17:22:10 +08:00
@Override
2024-09-02 10:22:42 +08:00
public List<AuthRoleDataDTO> listRoleData(Long roleId) {
return getAuthRoleDataMapper().listRoleData(roleId);
2024-08-30 17:22:10 +08:00
}
2024-07-30 17:45:02 +08:00
}