2024-07-30 17:45:02 +08:00
|
|
|
package com.engine.salary.service.auth;
|
|
|
|
|
|
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
|
|
|
|
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
|
|
|
|
|
public void save(AuthDataSaveParam param) {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
Long roleId = param.getRoleId();
|
|
|
|
|
AuthRolePO rolePO = getAuthRoleMapper().getById(roleId);
|
|
|
|
|
if (rolePO == null) {
|
|
|
|
|
throw new SalaryRunTimeException("角色不存在!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
}
|