weaver-hrm-salary/src/com/engine/salary/wrapper/TaxAgentWrapper.java

386 lines
16 KiB
Java
Raw Normal View History

2022-05-18 09:19:50 +08:00
package com.engine.salary.wrapper;
2022-05-19 16:36:18 +08:00
import com.cloudstore.eccom.pc.table.WeaTable;
import com.cloudstore.eccom.result.WeaResultMsg;
import com.engine.salary.entity.agency.po.PaymentAgencyPO;
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
import com.engine.salary.entity.taxagent.bo.TaxAgentBO;
2022-05-20 15:58:58 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeOptionDTO;
import com.engine.salary.entity.taxagent.dto.TaxAgentFormDTO;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeListDTO;
import com.engine.salary.entity.taxagent.param.TaxAgentAdminChangeCheckParam;
2022-05-19 14:50:01 +08:00
import com.engine.salary.entity.taxagent.param.TaxAgentQueryParam;
2022-05-19 16:36:18 +08:00
import com.engine.salary.entity.taxagent.param.TaxAgentRangeQueryParam;
import com.engine.salary.entity.taxagent.param.TaxAgentSaveParam;
2022-05-19 14:50:01 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentAdminPO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
2022-05-20 15:58:58 +08:00
import com.engine.salary.enums.UserStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
2022-05-19 16:36:18 +08:00
import com.engine.salary.service.*;
import com.engine.salary.util.SalaryAssert;
import com.engine.salary.util.SalaryI18nUtil;
2022-05-19 14:50:01 +08:00
import com.engine.salary.util.page.PageInfo;
2022-05-19 16:36:18 +08:00
import com.engine.salary.util.page.PageUtil;
2022-05-18 09:19:50 +08:00
import com.google.common.collect.Maps;
import com.weaver.common.component.browser.combination.TypesBrowserOption;
import com.weaver.common.component.form.WeaForm;
import com.weaver.common.component.form.item.WeaFormOption;
import com.weaver.common.hrm.domain.employee.HrmStatus;
import com.weaver.hrm.salary.entity.taxagent.dto.TaxAgentManageRangeFormDTO;
import com.weaver.hrm.salary.entity.taxagent.param.*;
import com.weaver.hrm.salary.service.*;
import com.weaver.hrm.salary.util.SalaryFormatUtil;
import com.weaver.teams.security.context.UserContext;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.BeanUtils;
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 TaxAgentWrapper {
2022-05-19 14:50:01 +08:00
2022-05-18 09:19:50 +08:00
private TaxAgentBaseService taxAgentBaseService;
2022-05-19 14:50:01 +08:00
2022-05-18 09:19:50 +08:00
private TaxAgentAdminService taxAgentAdminService;
2022-05-19 14:50:01 +08:00
private TaxAgentV2Service taxAgentService;
2022-05-19 16:36:18 +08:00
private SalaryEmployeeService employeeService;
2022-05-19 14:50:01 +08:00
private TaxAgentManageRangeService taxAgentManageRangeService;
private PaymentAgencyService paymentAgencyService;
private SIEmployeeStatusMapper siEmployeeStatusMapper;
private HrmCommonHrmStatusService hrmCommonHrmStatusService;
private HrmConfigSetCache hrmConfigSetCache;
2022-05-18 09:19:50 +08:00
/**
* 是否是薪酬模块总管理员
*
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public Boolean isChief(Long currentEmployeeId) {
return taxAgentService.isChief(currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 权限信息
*
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public Map<String, Boolean> permission(Long currentEmployeeId) {
2022-05-18 09:19:50 +08:00
Map<String, Boolean> resultMap = Maps.newHashMap();
2022-05-19 14:50:01 +08:00
Boolean isChief = isChief(currentEmployeeId);
Boolean isDefaultOpen = taxAgentService.isDefaultOpen(currentEmployeeId);
Boolean isAdminEnable = taxAgentService.isAdminEnable(currentEmployeeId);
2022-05-18 09:19:50 +08:00
resultMap.put("isChief", isChief);
resultMap.put("isDefaultOpen", isDefaultOpen);
resultMap.put("isAdminEnable", isAdminEnable);
return resultMap;
}
/**
* 个税口角义务人列表
*
* @param queryParam
* @param currentEmployeeId
* @return
*/
2022-05-20 15:58:58 +08:00
public Map<String, Object> list(TaxAgentQueryParam queryParam, Long currentEmployeeId) {
2022-05-18 09:19:50 +08:00
// 是否是总管理员
2022-05-19 14:50:01 +08:00
Boolean isChief = taxAgentService.isChief(currentEmployeeId);
2022-05-18 09:19:50 +08:00
// 是否开启分权
2022-05-19 14:50:01 +08:00
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
2022-05-18 09:19:50 +08:00
2022-05-19 14:50:01 +08:00
// List<PaymentAgencyPO> paymentAgencyPOS = paymentAgencyService.listAll(currentTenantKey);
2022-05-18 09:19:50 +08:00
2022-05-19 14:50:01 +08:00
PageInfo<TaxAgentPO> page = null;
2022-05-18 09:19:50 +08:00
if (isChief) {
2022-05-19 14:50:01 +08:00
page = taxAgentService.listPage(queryParam);
2022-05-18 09:19:50 +08:00
} else {
// 分权情况下,根据自己作为管理员过滤列表
if (isOpenDevolution) {
2022-05-19 14:50:01 +08:00
List<TaxAgentPO> list = taxAgentService.list(queryParam);
2022-05-18 09:19:50 +08:00
// 1.判断自己是否是管理员, 如果是管理员,就是能够操作所属个税扣缴义务人下的所有人的数据
2022-05-19 16:36:18 +08:00
List<TaxAgentAdminPO> taxAgentAdminList = taxAgentAdminService.listByTaxAgentIdsAndEmployeeId(list.stream().map(TaxAgentPO::getId).collect(Collectors.toList()), currentEmployeeId);
2022-05-18 09:19:50 +08:00
// 是管理员的列表
List<Long> adminTaxAgentIds = taxAgentAdminList.stream().map(TaxAgentAdminPO::getTaxAgentId).collect(Collectors.toList());
list = list.stream().filter(f -> adminTaxAgentIds.contains(f.getId())).collect(Collectors.toList());
2022-05-19 16:36:18 +08:00
// 分页参数
2022-05-18 09:19:50 +08:00
// 填充总数和当页数据
2022-05-19 16:36:18 +08:00
PageInfo<TaxAgentPO> dtoPage = PageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize());
2022-05-18 09:19:50 +08:00
dtoPage.setTotal(list.size());
2022-05-19 16:36:18 +08:00
dtoPage.setList(PageUtil.subList(dtoPage.getPageNum(), dtoPage.getSize(), list));
2022-05-18 09:19:50 +08:00
page = dtoPage;
}
}
2022-05-19 16:36:18 +08:00
PageInfo<Map<String, Object>> listPage = new PageInfo<>();
2022-05-18 09:19:50 +08:00
2022-05-19 16:36:18 +08:00
String setLabel = SalaryI18nUtil.getI18nLabel(94614, "设置");
2022-05-18 09:19:50 +08:00
if (isOpenDevolution) {
2022-05-19 16:36:18 +08:00
List<TaxAgentPO> list = page.getList();
List<Long> taxAgentIds = list.stream().map(TaxAgentPO::getId).collect(Collectors.toList());
2022-05-19 14:50:01 +08:00
List<TaxAgentAdminPO> taxAgentAdmins = taxAgentAdminService.listByTaxAgentIds(taxAgentIds);
2022-05-19 16:36:18 +08:00
List<DataCollectionEmployee> adminList = employeeService.listByIds(taxAgentAdmins.stream().map(TaxAgentAdminPO::getEmployeeId).distinct().collect(Collectors.toList()));
listPage.setList(TaxAgentBO.convertToTableListDTO(page.getList(), null, taxAgentAdmins, adminList, setLabel));
2022-05-18 09:19:50 +08:00
} else {
2022-05-19 16:36:18 +08:00
listPage.setList(TaxAgentBO.convertToTableListDTO(page.getList(), null, setLabel));
2022-05-18 09:19:50 +08:00
}
2022-05-19 16:36:18 +08:00
2022-05-18 09:19:50 +08:00
//构造表格
2022-05-20 15:58:58 +08:00
WeaTable weaTable = new WeaTable();
2022-05-19 16:36:18 +08:00
TaxAgentBO.buildTaxAgentTable(weaTable, isOpenDevolution);
2022-05-18 09:19:50 +08:00
if (isChief) {
// 在外展示操作按钮
2022-05-19 16:36:18 +08:00
// weaTable.getOperates().get(0).setOuter(Boolean.TRUE);
2022-05-18 09:19:50 +08:00
} else {
// 去掉增删改权限
2022-05-19 16:36:18 +08:00
weaTable.getOperates().getOperate().clear();
// weaTable.getCheckBoxPermission().clear();
2022-05-18 09:19:50 +08:00
}
2022-05-19 16:36:18 +08:00
WeaResultMsg result = new WeaResultMsg(false);
result.putAll(weaTable.makeDataResult());
result.success();
Map<String, Object> datas = new HashMap<>();
datas.put("pageInfo", listPage);
datas.put("dataKey", result.getResultMap());
return datas;
2022-05-18 09:19:50 +08:00
}
2022-05-19 14:50:01 +08:00
public List<Map<String, Object>> paymentAgencyList(TaxAgentQueryParam queryParam, Long currentEmployeeId) {
List<TaxAgentPO> taxAgentPOS = taxAgentService.listByIds(queryParam.getIds());
2022-05-18 09:19:50 +08:00
List<PaymentAgencyPO> paymentAgencyPOS = paymentAgencyService.listAll(currentTenantKey);
SalaryAssert.notEmpty(taxAgentPOS, "taxagent data is not exist");
TaxAgentPO taxAgentPO = taxAgentPOS.get(0);
return TaxAgentBO.buildPaymentAgency(taxAgentPO.getPaymentAgency(), paymentAgencyPOS);
}
2022-05-19 14:50:01 +08:00
public String paymentAgencySave(TaxAgentSaveParam param, Long currentEmploueeId) {
2022-05-19 16:36:18 +08:00
// List<TaxAgentPO> taxAgentPOS = taxAgentService.listByIds(Collections.singletonList(param.getId()));
// SalaryAssert.notEmpty(taxAgentPOS, "data is not exist");
// TaxAgentPO taxAgentPO = taxAgentPOS.get(0);
// List<String> errorList = new ArrayList<>();
// List<String> resultList = new ArrayList<>();
// if (StringUtils.isNotBlank(taxAgentPO.getPaymentAgency())) {
// List<String> originList = new ArrayList<>(Arrays.asList(taxAgentPO.getPaymentAgency().split(",")));
// List<String> list = new ArrayList<>(Arrays.asList(param.getPaymentAgency().split(",")));
// originList.removeAll(list);
// if (CollectionUtils.isNotEmpty(originList)) {
// originList.stream().forEach(e -> {
// List<InsuranceEmployeeStatusPO> employeeStatusPOS = new LambdaQueryChainWrapper<>(siEmployeeStatusMapper)
// .eq(InsuranceEmployeeStatusPO::getTenantKey)
// .eq(InsuranceEmployeeStatusPO::getPaymentAgency, Long.valueOf(e))
// .eq(InsuranceEmployeeStatusPO::getPaymentOrganization, param.getId())
// .list();
// if (CollectionUtils.isNotEmpty(employeeStatusPOS)) {
// errorList.add(e);
// }
// });
// }
// if (CollectionUtils.isNotEmpty(errorList)) {
// List<PaymentAgencyPO> paymentAgencyPOS = paymentAgencyService.listAll(currentTenantKey);
// errorList.forEach(e -> {
// Optional<PaymentAgencyPO> optionalPaymentAgencyPO = paymentAgencyPOS.stream().filter(po -> Objects.equals(e, String.valueOf(po.getId()))).findFirst();
// optionalPaymentAgencyPO.ifPresent(paymentAgencyPO -> resultList.add(paymentAgencyPO.getAgencyName()));
// });
// }
// }
// if (CollectionUtils.isNotEmpty(resultList)) {
// return SalaryI18nUtil.getI18nLabel(currentTenantKey, currentEmploueeId, 115128, "有员工在") + String.join(",", resultList) + SalaryI18nUtil.getI18nLabel(currentTenantKey,
// currentEmploueeId, 115129, "缴纳社保福利,不可取消关联");
// } else {
// taxAgentPO.setPaymentAgency(param.getPaymentAgency());
// taxAgentService.paymentAgencyUpdate(taxAgentPO, currentEmploueeId);
// }
2022-05-18 09:19:50 +08:00
return "";
}
/**
* 获取个税扣缴义务人表单
*
* @param id
* @return
*/
2022-05-20 15:58:58 +08:00
public TaxAgentFormDTO getFrom(Long id) {
2022-05-18 09:19:50 +08:00
TaxAgentFormDTO taxAgentFromDTO = new TaxAgentFormDTO();
if (id != null) {
2022-05-19 14:50:01 +08:00
TaxAgentPO taxAgent = taxAgentService.getById(id);
2022-05-18 09:19:50 +08:00
if (taxAgent == null) {
2022-05-20 15:58:58 +08:00
throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(100543, "个税扣缴人不存在") + "[id:%s]", id));
2022-05-18 09:19:50 +08:00
}
BeanUtils.copyProperties(taxAgent, taxAgentFromDTO);
}
// 是否开启分权
2022-05-20 15:58:58 +08:00
boolean isOpenDevolution = taxAgentBaseService.isOpenDevolution();
2022-05-18 09:19:50 +08:00
if (isOpenDevolution) {
2022-05-19 14:50:01 +08:00
List<TaxAgentAdminPO> admins = taxAgentAdminService.listByTaxAgentIds(Collections.singletonList(id));
2022-05-18 09:19:50 +08:00
// 目前是一个
TaxAgentEmployeeOptionDTO taxAgentEmployee = new TaxAgentEmployeeOptionDTO();
taxAgentEmployee.setId(CollectionUtils.isEmpty(admins) ? null : admins.get(0).getEmployeeId());
if (taxAgentEmployee.getId() != null) {
2022-05-20 15:58:58 +08:00
DataCollectionEmployee employee = employeeService.getEmployeeById(taxAgentEmployee.getId());
2022-05-18 09:19:50 +08:00
taxAgentEmployee.setContent(employee == null ? "" : employee.getUsername());
}
taxAgentFromDTO.setAdminUser(Collections.singletonList(taxAgentEmployee));
} else {
taxAgentFromDTO.setAdminUser(null);
}
2022-05-20 15:58:58 +08:00
return taxAgentFromDTO;
2022-05-18 09:19:50 +08:00
}
/**
* 保存个税扣缴义务人
*
* @param saveParam
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public String save(TaxAgentSaveParam saveParam, Long currentEmployeeId) {
return taxAgentService.save(saveParam, currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 编辑个税扣缴义务人
*
* @param saveParam
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public String update(TaxAgentSaveParam saveParam, Long currentEmployeeId) {
return taxAgentService.update(saveParam, currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 更换管理员校验
*
* @param checkParam
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public Boolean adminChangeCheck(TaxAgentAdminChangeCheckParam checkParam, Long currentEmployeeId) {
return taxAgentService.adminChangeCheck(checkParam, currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 删除个税扣缴义务人
*
* @param ids
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public String delete(Collection<Long> ids, Long currentEmployeeId) {
return taxAgentService.delete(ids, currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 个税扣缴义务人下拉列表
*
* @param currentEmployeeId
* @return
*/
2022-05-19 14:50:01 +08:00
public List<Map<String, Object>> selectList(Long currentEmployeeId) {
return taxAgentService.selectList(currentEmployeeId);
2022-05-18 09:19:50 +08:00
}
/**
* 范围列表
*
* @param queryParam
* @return
*/
2022-05-19 16:36:18 +08:00
public PageInfo<TaxAgentManageRangeListDTO> listRangeInclude(TaxAgentRangeQueryParam queryParam) {
PageInfo<TaxAgentManageRangeListDTO> listPage = taxAgentManageRangeService.listPageByParamAndIncludeType(queryParam, NumberUtils.INTEGER_ONE);
2022-05-20 15:58:58 +08:00
return listPage;
2022-05-18 09:19:50 +08:00
}
/**
* 范围排除列表
*
* @param queryParam
* @return
*/
2022-05-20 15:58:58 +08:00
public PageInfo<TaxAgentManageRangeListDTO> listRangeExclude(TaxAgentRangeQueryParam queryParam) {
PageInfo<TaxAgentManageRangeListDTO> listPage = taxAgentManageRangeService.listPageByParamAndIncludeType(queryParam, NumberUtils.INTEGER_ZERO);
return listPage;
2022-05-18 09:19:50 +08:00
}
/**
* 获取管理范围表单
*
* @return
*/
2022-05-20 15:58:58 +08:00
public WeaForm getRangeFrom() {
2022-05-18 09:19:50 +08:00
// 查询人员状态
2022-05-20 15:58:58 +08:00
List<UserStatusEnum> hrmStatusList = UserStatusEnum.getEffectiveList();
2022-05-18 09:19:50 +08:00
List<WeaFormOption> weaFormOptions = hrmStatusList.stream().map(hrmStatus -> {
WeaFormOption weaFormOption = new WeaFormOption();
weaFormOption.setId("" + hrmStatus.getCodeId());
weaFormOption.setContent(hrmStatus.getName());
return weaFormOption;
}).collect(Collectors.toList());
Long employeeId = UserContext.getCurrentEmployeeId();
List<TypesBrowserOption> browserOptions = new ArrayList<>();
2022-05-20 15:58:58 +08:00
browserOptions.add(new TypesBrowserOption("user", SalaryI18nUtil.getI18nLabel(1869, "人员")));
browserOptions.add(new TypesBrowserOption("dept", SalaryI18nUtil.getI18nLabel(1250, "部门")));
2022-05-19 14:50:01 +08:00
if (hrmConfigSetCache.isSubcompanySupport(tenantKey)) {
2022-05-20 15:58:58 +08:00
browserOptions.add(new TypesBrowserOption("subcompany", SalaryI18nUtil.getI18nLabel(107369, "分部")));
2022-05-18 09:19:50 +08:00
}
2022-05-20 15:58:58 +08:00
browserOptions.add(new TypesBrowserOption("position", SalaryI18nUtil.getI18nLabel(1245, "岗位")));
2022-05-18 09:19:50 +08:00
WeaForm weaForm = SalaryFormatUtil.<TaxAgentManageRangeFormDTO>getInstance().buildForm(TaxAgentManageRangeFormDTO.class, TaxAgentManageRangeFormDTO.builder().targetOptions(browserOptions).build());
weaForm.getItems().forEach((key, value) -> {
if (StringUtils.equals("employeeStatus", key)) {
value.setOptions(weaFormOptions);
}
});
return weaForm;
}
/**
* 保存管理范围
*
* @param saveParam
* @param employeeId
* @param tenantKey
* @return
*/
public String saveRange(TaxAgentRangeSaveParam saveParam, Long employeeId, String tenantKey) {
taxAgentManageRangeService.save(saveParam, employeeId, tenantKey);
return StringUtils.EMPTY;
}
/**
* 删除管理范围
*
* @param ids
* @param tenantKey
* @return
*/
public String deleteRange(Collection<Long> ids, Long employeeId, String tenantKey) {
taxAgentManageRangeService.deleteByIds(ids, employeeId, tenantKey);
return StringUtils.EMPTY;
}
}