weaver-hrm-salary/src/com/engine/salary/entity/taxagent/bo/TaxAgentBO.java

435 lines
20 KiB
Java
Raw Normal View History

2022-05-18 09:19:50 +08:00
package com.engine.salary.entity.taxagent.bo;
2022-05-19 16:36:18 +08:00
import com.cloudstore.eccom.pc.table.WeaTable;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.pc.table.WeaTableOperate;
import com.cloudstore.eccom.pc.table.WeaTableOperates;
2022-05-18 09:19:50 +08:00
import com.engine.salary.constant.SalaryDefaultTenantConstant;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.agency.po.PaymentAgencyPO;
2022-05-18 09:19:50 +08:00
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
2022-05-24 09:14:26 +08:00
import com.engine.salary.entity.hrm.DeptInfo;
import com.engine.salary.entity.hrm.HrmStatus;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.hrm.PositionInfo;
2022-05-24 09:14:26 +08:00
import com.engine.salary.entity.hrm.SubCompanyInfo;
2022-05-18 09:19:50 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO;
2022-05-19 14:50:01 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentListDTO;
2022-05-18 09:19:50 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeListDTO;
import com.engine.salary.entity.taxagent.dto.TaxAgentSubAdminListDTO;
import com.engine.salary.entity.taxagent.param.TaxAgentManageRangeSaveParam;
import com.engine.salary.entity.taxagent.param.TaxAgentSaveParam;
import com.engine.salary.entity.taxagent.param.TaxAgentSubAdminRangeSaveParam;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentAdminPO;
2022-05-18 09:19:50 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentManageRangePO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.entity.taxagent.po.TaxAgentSubAdminPO;
import com.engine.salary.enums.salarysob.TargetTypeEnum;
import com.engine.salary.enums.taxagent.TaxAgentRangeTypeEnum;
import com.engine.salary.util.JsonUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
2022-05-19 16:36:18 +08:00
import dm.jdbc.util.IdGenerator;
2022-05-18 09:19:50 +08:00
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
2022-05-19 14:50:01 +08:00
* 个税扣缴义务人
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
2022-05-18 09:19:50 +08:00
public class TaxAgentBO {
@Override
public String toString() {
return "TaxAgentBO{}";
}
/**
* 根据个税扣缴义务人id和用户id判断是否匹配
*
* @param taxAgentEmployees
* @param taxAgentId
* @param employeeId
* @return
*/
public static boolean checkTaxAgentAndEmployee(List<TaxAgentEmployeeDTO> taxAgentEmployees, Long taxAgentId, Long employeeId) {
if (CollectionUtils.isEmpty(taxAgentEmployees) && taxAgentId == null) {
return false;
}
return taxAgentEmployees.stream().anyMatch(t -> t.getTaxAgentId().equals(taxAgentId) && employeeId.equals(t.getEmployeeId()));
}
/**
* 构建表格
*
* @param weaTable
* @param isOpenDevolution
*/
2022-05-19 16:36:18 +08:00
public static void buildTaxAgentTable(WeaTable weaTable, boolean isOpenDevolution) {
2022-05-18 09:19:50 +08:00
// 表格表头
List<WeaTableColumn> columns = new ArrayList<>();
2022-05-19 16:36:18 +08:00
String name = SalaryI18nUtil.getI18nLabel(91558, "个税扣缴义务人名称");
String employeeRange = SalaryI18nUtil.getI18nLabel(86125, "人员范围");
String admins = SalaryI18nUtil.getI18nLabel(106259, "管理员");
String subAdmins = SalaryI18nUtil.getI18nLabel(106283, "分管理员");
// String paymentAgency = SalaryI18nUtil.getI18nLabel(112448, "社保福利代缴机构");
String description = SalaryI18nUtil.getI18nLabel(84961, "备注");
2022-05-18 09:19:50 +08:00
if (isOpenDevolution) {
columns.add(new WeaTableColumn(name, "name", "20%"));
columns.add(new WeaTableColumn(employeeRange, "employeeRange", "20%"));
columns.add(new WeaTableColumn(admins, "admins", "20%"));
// columns.add(new WeaTableColumn(subAdmins, "subAdmins", "20%"));
2022-05-19 16:36:18 +08:00
// columns.add(new WeaTableColumn(paymentAgency, "paymentAgency", "30%"));
2022-05-18 09:19:50 +08:00
columns.add(new WeaTableColumn(description, "description", "20%"));
} else {
columns.add(new WeaTableColumn(name, "name", "40%"));
columns.add(new WeaTableColumn(employeeRange, "employeeRange", "20%"));
2022-05-19 16:36:18 +08:00
// columns.add(new WeaTableColumn(paymentAgency, "paymentAgency", "30%"));
2022-05-18 09:19:50 +08:00
columns.add(new WeaTableColumn(description, "description", "40%"));
}
weaTable.setColumns(columns);
2022-05-19 16:36:18 +08:00
WeaTableOperates operates = weaTable.getOperates();
operates.getOperate().add(new WeaTableOperate(SalaryI18nUtil.getI18nLabel(59943, "编辑"), null, "0"));
operates.getOperate().add(new WeaTableOperate(SalaryI18nUtil.getI18nLabel(59942, "删除"), null, "1"));
2022-05-18 09:19:50 +08:00
// if (isOpenDevolution) {
2022-05-19 16:36:18 +08:00
// operates.add(new WeaTableOperate(SalaryI18nUtil.getI18nLabel( 106247, "管理范围及分权设置"), 2));
2022-05-18 09:19:50 +08:00
// }
2022-05-19 16:36:18 +08:00
// weaTable.setOperatesPermission(getDefaultOperatesPermission(operates.getOperate().size(), size));
2022-05-18 09:19:50 +08:00
// weaTable.setCheckBoxPermission(getDefaultCheckBoxPermission(size));
//
// weaTable.setTableType(WeaTableTypeEnum.CHECKBOX);
}
2022-05-19 16:36:18 +08:00
// private static List<List<Permission>> getDefaultOperatesPermission(int operateSize, int recordSize) {
// List<List<Permission>> permissionList = Lists.newArrayList();
// for (int i = 0; i < recordSize; i++) {
// List<Permission> permissions = Lists.newArrayList();
// for (int j = 0; j < operateSize; j++) {
// permissions.add(new Permission(true, false));
// }
// permissionList.add(permissions);
// }
// return permissionList;
// }
//
// private static List<Permission> getDefaultCheckBoxPermission(int recordSize) {
// List<Permission> permissionList = Lists.newArrayList();
// for (int i = 0; i < recordSize; i++) {
// permissionList.add(new Permission(true, false));
// }
// return permissionList;
// }
2022-05-18 09:19:50 +08:00
/**
* 表数据转列表数据
*
* @param taxAgents
* @return
*/
2022-05-19 14:50:01 +08:00
public static List<TaxAgentListDTO> convertToListDTO(Collection<TaxAgentPO> taxAgents) {
2022-05-18 09:19:50 +08:00
if (CollectionUtils.isEmpty(taxAgents)) {
return Collections.emptyList();
}
return taxAgents.stream()
2022-05-19 16:36:18 +08:00
.map(e -> TaxAgentListDTO.builder()
.id(e.getId())
.name(e.getName())
.description(e.getDescription())
.build())
.collect(Collectors.toList());
2022-05-18 09:19:50 +08:00
}
/**
* 表数据转列表数据
*
* @param taxAgents
* @return
*/
public static List<Map<String, Object>> convertToTableListDTO(List<TaxAgentPO> taxAgents, List<PaymentAgencyPO> paymentAgencyPOS, String setLabel) {
return convertToTableListDTO(Boolean.FALSE, taxAgents, paymentAgencyPOS, null, null, setLabel);
}
/**
* 表数据转列表数据
*
* @param taxAgents
* @return
*/
public static List<Map<String, Object>> convertToTableListDTO(List<TaxAgentPO> taxAgents, List<PaymentAgencyPO> paymentAgencyPOS, List<TaxAgentAdminPO> taxAgentAdmins,
2022-05-19 16:36:18 +08:00
List<DataCollectionEmployee> adminList,
2022-05-18 09:19:50 +08:00
String setLabel) {
return convertToTableListDTO(Boolean.TRUE, taxAgents, paymentAgencyPOS, taxAgentAdmins, adminList, setLabel);
}
/**
* 表数据转列表数据
*
* @param taxAgents
* @param adminList
* @return
*/
public static List<Map<String, Object>> convertToTableListDTO(Boolean isDevolution, List<TaxAgentPO> taxAgents, List<PaymentAgencyPO> paymentAgencyPOS,
List<TaxAgentAdminPO> taxAgentAdmins,
2022-05-19 16:36:18 +08:00
List<DataCollectionEmployee> adminList, String setLabel) {
2022-05-18 09:19:50 +08:00
if (CollectionUtils.isEmpty(taxAgents)) {
return Collections.emptyList();
}
return taxAgents.stream()
2022-05-19 16:36:18 +08:00
.map(e -> {
Map<String, Object> map = new LinkedHashMap<>();
map.put("id", e.getId());
map.put("name", e.getName());
map.put("employeeRange", setLabel);
if (isDevolution) {
List<Long> empIds = taxAgentAdmins.stream().filter(t -> t.getTaxAgentId().equals(e.getId())).map(TaxAgentAdminPO::getEmployeeId).collect(Collectors.toList());
List<String> admins = adminList.stream().filter(a -> empIds.contains(a.getEmployeeId())).map(DataCollectionEmployee::getUsername).collect(Collectors.toList());
map.put("admins", CollectionUtils.isEmpty(admins) ? "" : Joiner.on(",").join((Iterable<?>) admins));
map.put("subAdmins", setLabel);
}
map.put("paymentAgency", buildPaymentAgency(e.getPaymentAgency(), paymentAgencyPOS));
map.put("description", e.getDescription());
return map;
}).collect(Collectors.toList());
2022-05-18 09:19:50 +08:00
}
public static List<Map<String, Object>> buildPaymentAgency(String originStr, List<PaymentAgencyPO> paymentAgencyPOS) {
List<Map<String, Object>> paymentAgencyList = new ArrayList<>();
if (CollectionUtils.isEmpty(paymentAgencyPOS)) {
return paymentAgencyList;
}
originStr = StringUtils.isBlank(originStr) ? "" : originStr;
String finalOriginStr = originStr;
return paymentAgencyPOS.stream().map(e -> {
HashMap<String, Object> temp = new HashMap<>();
temp.put("id", e.getId());
temp.put("agencyName", e.getAgencyName());
if (finalOriginStr.contains(String.valueOf(e.getId()))) {
temp.put("status", true);
} else {
temp.put("status", false);
}
return temp;
}).collect(Collectors.toList());
}
/**
* 保存参数转表数据
*
* @param saveParam
* @param employeeId
* @return
*/
public static TaxAgentPO convertToPO(TaxAgentSaveParam saveParam, Long employeeId) {
if (saveParam == null) {
return null;
}
Date now = new Date();
return TaxAgentPO.builder()
2022-05-19 16:36:18 +08:00
.id(saveParam.getId())
.name(saveParam.getName())
.description(saveParam.getDescription())
.createTime(now)
.updateTime(now)
.creator(employeeId)
2022-05-24 09:14:26 +08:00
.deleteType(0)
2022-05-19 16:36:18 +08:00
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build();
2022-05-18 09:19:50 +08:00
}
/**
* 表数据转列表数据分管理员
*
* @param list
* @param range
* @param subAdminList
* @return
*/
public static List<TaxAgentSubAdminListDTO> convertToSubAdminListDTO(List<TaxAgentSubAdminPO> list, String range, List<DataCollectionEmployee> subAdminList) {
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
return list.stream()
2022-05-19 16:36:18 +08:00
.map(e -> {
Optional<String> optionalUsername = subAdminList.stream().filter(a -> e.getEmployeeId().equals(a.getEmployeeId())).map(DataCollectionEmployee::getUsername).findFirst();
return TaxAgentSubAdminListDTO.builder()
.id(e.getId())
.subAdmin(optionalUsername.isPresent() ? optionalUsername.get() : "")
.range(range)
.description(e.getRemark())
.build();
})
.collect(Collectors.toList());
2022-05-18 09:19:50 +08:00
}
/**
* 管理范围列表转换
*
* @param taxAgentManageRanges
* @param employeeComInfos
* @param departmentComInfos
* @param subDepartmentComInfos
* @param positionComInfos
* @param hrmStatusList
* @return
*/
2022-05-19 16:36:18 +08:00
public static List<TaxAgentManageRangeListDTO> convert2ListDTO(List<TaxAgentManageRangePO> taxAgentManageRanges, List<DataCollectionEmployee> employeeComInfos,
2022-05-24 09:14:26 +08:00
List<DeptInfo> departmentComInfos, List<SubCompanyInfo> subDepartmentComInfos,
2022-05-19 16:36:18 +08:00
List<PositionInfo> positionComInfos, List<HrmStatus> hrmStatusList) {
2022-05-18 09:19:50 +08:00
if (CollectionUtils.isEmpty(taxAgentManageRanges)) {
return Collections.emptyList();
}
2022-05-19 16:36:18 +08:00
Map<Long, String> employeeComInfoMap = SalaryEntityUtil.convert2Map(employeeComInfos, DataCollectionEmployee::getEmployeeId, DataCollectionEmployee::getUsername);
2022-05-24 09:14:26 +08:00
Map<Long, String> departmentComInfoMap = SalaryEntityUtil.convert2Map(departmentComInfos, DeptInfo::getId, DeptInfo::getName);
Map<Long, String> subDepartmentComInfoMap = SalaryEntityUtil.convert2Map(subDepartmentComInfos, SubCompanyInfo::getId, SubCompanyInfo::getName);
Map<Long, String> positionComInfoMap = SalaryEntityUtil.convert2Map(positionComInfos, PositionInfo::getId, PositionInfo::getName);
2022-05-18 09:19:50 +08:00
2022-05-24 09:14:26 +08:00
Map<String, String> hrmStatusNameMap = SalaryEntityUtil.convert2Map(hrmStatusList, hrmStatus -> String.valueOf(hrmStatus.getId()), HrmStatus::getName);
2022-05-18 09:19:50 +08:00
return taxAgentManageRanges.stream()
2022-05-19 16:36:18 +08:00
.map(taxAgentManageRange -> {
TargetTypeEnum targetTypeEnum = TargetTypeEnum.parseByValue(taxAgentManageRange.getTargetType());
return TaxAgentManageRangeListDTO.builder()
.id(taxAgentManageRange.getId())
.targetType(targetTypeEnum)
.targetTypeName(Optional.ofNullable(targetTypeEnum)
.map(e -> SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel()))
.orElse(StringUtils.EMPTY))
.targetId(taxAgentManageRange.getTargetId())
.targetName(buildTargetName(taxAgentManageRange, employeeComInfoMap, departmentComInfoMap, subDepartmentComInfoMap, positionComInfoMap))
.employeeStatus(buildEmployeeStatus(hrmStatusNameMap, taxAgentManageRange.getEmployeeStatus()))
.build();
})
.collect(Collectors.toList());
2022-05-18 09:19:50 +08:00
}
private static String buildEmployeeStatus(Map<String, String> hrmStatusNameMap, String employeeStatus) {
List<String> employeeStatusList = JsonUtil.parseList(employeeStatus, String.class);
if (CollectionUtils.isEmpty(employeeStatusList)) {
return StringUtils.EMPTY;
}
return employeeStatusList.stream()
.map(hrmStatusNameMap::get)
.collect(Collectors.joining(","));
}
/**
* 构建对象名
*
* @param taxAgentManageRange
* @param employeeComInfoMap
* @param departmentComInfoMap
* @param subDepartmentComInfoMap
* @param positionComInfoMap
* @return
*/
private static String buildTargetName(TaxAgentManageRangePO taxAgentManageRange, Map<Long, String> employeeComInfoMap, Map<Long, String> departmentComInfoMap,
Map<Long, String> subDepartmentComInfoMap, Map<Long, String> positionComInfoMap) {
TargetTypeEnum targetTypeEnum = TargetTypeEnum.parseByValue(taxAgentManageRange.getTargetType());
if (Objects.isNull(targetTypeEnum)) {
return StringUtils.EMPTY;
}
switch (targetTypeEnum) {
case EMPLOYEE:
return employeeComInfoMap.getOrDefault(taxAgentManageRange.getTargetId(), StringUtils.EMPTY);
case DEPT:
return departmentComInfoMap.getOrDefault(taxAgentManageRange.getTargetId(), StringUtils.EMPTY);
case SUBCOMPANY:
return subDepartmentComInfoMap.getOrDefault(taxAgentManageRange.getTargetId(), StringUtils.EMPTY);
case POSITION:
return positionComInfoMap.getOrDefault(taxAgentManageRange.getTargetId(), StringUtils.EMPTY);
default:
return StringUtils.EMPTY;
}
}
2022-05-24 09:14:26 +08:00
public static Result handleTaxAgentRange(List<TaxAgentManageRangePO> taxAgentManageRanges, TaxAgentManageRangeSaveParam saveParam, Long taxAgentId, Long employeeId
) {
return handleManageRange(taxAgentManageRanges, saveParam, TaxAgentRangeTypeEnum.TAXAGENT, taxAgentId, 0L, employeeId);
2022-05-18 09:19:50 +08:00
}
public static Result handleSubAdminRange(List<TaxAgentManageRangePO> taxAgentManageRanges, TaxAgentManageRangeSaveParam saveParam, Long taxAgentId, Long subAdminId,
2022-05-24 09:14:26 +08:00
Long employeeId) {
return handleManageRange(taxAgentManageRanges, saveParam, TaxAgentRangeTypeEnum.SUBADMIN, taxAgentId, subAdminId, employeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 处理前端传回的保存参数转换成对应的po如果保存参数中的人员部门岗位等之前就已经添加过了就不需要再次保存了
*
* @param taxAgentManageRanges
* @param saveParam
* @param taxAgentId
* @param subAdminId
* @param employeeId
* @return
*/
private static Result handleManageRange(List<TaxAgentManageRangePO> taxAgentManageRanges, TaxAgentManageRangeSaveParam saveParam,
2022-05-24 09:14:26 +08:00
TaxAgentRangeTypeEnum rangeTypeEnum, Long taxAgentId, Long subAdminId, Long employeeId) {
2022-05-18 09:19:50 +08:00
Date now = new Date();
Result handleResult = Result.builder()
2022-05-19 16:36:18 +08:00
.needInsertTaxAgentManageRanges(Lists.newArrayList())
.needUpdateTaxAgentManageRanges(Lists.newArrayList())
.build();
2022-05-18 09:19:50 +08:00
if (CollectionUtils.isEmpty(saveParam.getTargetParams())) {
return handleResult;
}
Map<String, TaxAgentManageRangePO> taxAgentManageRangeMap = SalaryEntityUtil.convert2Map(taxAgentManageRanges,
2022-05-19 16:36:18 +08:00
e -> e.getIncludeType() + "-" + e.getTargetType() + "-" + e.getTargetId() + "-" + e.getRangeType());
2022-05-18 09:19:50 +08:00
for (TaxAgentSubAdminRangeSaveParam.TaxAgentSubAdminRangeTargetParam targetParam : saveParam.getTargetParams()) {
String key = saveParam.getIncludeType() + "-" + targetParam.getTargetType().getValue() + "-" + targetParam.getTargetId() + "-" + rangeTypeEnum.getValue();
if (taxAgentManageRangeMap.containsKey(key)) {
TaxAgentManageRangePO taxAgentManageRange = taxAgentManageRangeMap.get(key);
taxAgentManageRange.setEmployeeStatus(JsonUtil.toJsonString(saveParam.getEmployeeStatus()));
taxAgentManageRange.setUpdateTime(now);
handleResult.getNeedUpdateTaxAgentManageRanges().add(taxAgentManageRange);
continue;
}
TaxAgentManageRangePO taxAgentManageRange = TaxAgentManageRangePO.builder()
2022-05-19 16:36:18 +08:00
.id(IdGenerator.generate())
.taxAgentId(taxAgentId)
.taxAgentSubAdminId(subAdminId)
.rangeType(rangeTypeEnum.getValue())
.targetType(targetParam.getTargetType().getValue())
.targetId(targetParam.getTargetId())
.employeeStatus(JsonUtil.toJsonString(saveParam.getEmployeeStatus()))
.includeType(saveParam.getIncludeType())
.creator(employeeId)
.createTime(now)
.updateTime(now)
2022-05-24 09:14:26 +08:00
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
2022-05-19 16:36:18 +08:00
.deleteType(0)
.build();
2022-05-18 09:19:50 +08:00
handleResult.getNeedInsertTaxAgentManageRanges().add(taxAgentManageRange);
}
return handleResult;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Result {
/**
* 需要更新的人员范围
*/
private Collection<TaxAgentManageRangePO> needUpdateTaxAgentManageRanges;
/**
* 需要新增的人员范围
*/
private Collection<TaxAgentManageRangePO> needInsertTaxAgentManageRanges;
}
}