package com.engine.salary.wrapper; import com.api.browser.bean.SearchConditionGroup; import com.api.browser.bean.SearchConditionItem; import com.api.browser.bean.SearchConditionOption; import com.api.browser.util.ConditionFactory; import com.api.browser.util.ConditionType; import com.engine.core.impl.Service; import com.engine.salary.entity.salaryarchive.dto.SalaryArchiveTaxAgentFormDTO; import com.engine.salary.entity.salaryarchive.dto.SingleTaxAgentAdjustRecordListDTO; import com.engine.salary.entity.salaryarchive.dto.TaxAgentAdjustRecordListDTO; import com.engine.salary.entity.salaryarchive.param.SalaryArchiveTaxAgentSaveParam; import com.engine.salary.entity.salaryarchive.param.SingleTaxAgentAdjustRecordQueryParam; import com.engine.salary.entity.salaryarchive.param.TaxAgentAdjustRecordQueryParam; import com.engine.salary.entity.salaryarchive.po.SalaryArchiveTaxAgentPO; import com.engine.salary.entity.taxrate.TaxAgent; import com.engine.salary.enums.UserStatusEnum; import com.engine.salary.enums.salaryarchive.SalaryArchiveTaxAgentAdjustReasonEnum; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.service.SalaryArchiveTaxAgentService; import com.engine.salary.service.TaxAgentService; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.page.PageInfo; import com.google.common.collect.Lists; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.BeanUtils; import java.util.*; /** * 薪资档案-个税扣缴义务人 *

Copyright: Copyright (c) 2022

*

Company: 泛微软件

* * @author qiantao * @version 1.0 **/ public class SalaryArchiveTaxAgentWrapper extends Service { private SalaryArchiveTaxAgentService salaryArchiveTaxAgentService; private TaxAgentService taxAgentService; // @Resource // private SalaryBatchService salaryBatchService; // @Autowired // private ExecutorService taskExecutor; /** * 获取个税扣缴义务人调整表单 * 获取调整原因和扣税义务人列表 * * @param salaryArchiveId * @return */ public SalaryArchiveTaxAgentFormDTO getTaxAgentForm(Long salaryArchiveId) { if (salaryArchiveId == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100425, "薪资档案id不能为空")); } // 个税扣缴义务人下拉列表 Collection taxAgentList = taxAgentService.findAll(); // 构建表单 Map form = buildTaxAgentForm(taxAgentList, null, "", "", null); return SalaryArchiveTaxAgentFormDTO.builder() .salaryArchiveId(salaryArchiveId) .salaryArchiveTaxAgentForm(form) .build(); } private Map buildTaxAgentForm(Collection taxAgentList, Date effectiveTime, String adjustReason, String adjustBefore, Long adjustAfter) { // 个税扣缴义务人调整原因下拉列表 List salaryArchiveTaxAgentAdjustReasonEnums = Arrays.asList(SalaryArchiveTaxAgentAdjustReasonEnum.values()); ConditionFactory conditionFactory = new ConditionFactory(user); //条件组 List addGroups = new ArrayList(); List items = new ArrayList(); SearchConditionItem effectiveTimeItem = conditionFactory.createCondition(ConditionType.DATEPICKER, 502327, "effectiveTime"); effectiveTimeItem.setColSpan(1);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 effectiveTimeItem.setFieldcol(12); //条件输入框所占宽度,默认值18 effectiveTimeItem.setViewAttr(3); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 effectiveTimeItem.setLength(10); // 设置输入长度 effectiveTimeItem.setLabel("生效时间"); //设置文本值 这个将覆盖多语言标签的值 effectiveTimeItem.setRules("required"); //设置字段填入规则 items.add(effectiveTimeItem); SearchConditionItem adjustReasonItem = conditionFactory.createCondition(ConditionType.SELECT, 502227, "adjustReason"); List selectOptions = new ArrayList<>(); //设置选项值 Arrays.stream(SalaryArchiveTaxAgentAdjustReasonEnum.values()).forEach(r -> { if (r.getValue().equals(adjustReason)) { selectOptions.add(new SearchConditionOption(r.getValue(), r.getDefaultLabel(), true)); } selectOptions.add(new SearchConditionOption(r.getValue(), r.getDefaultLabel())); }); adjustReasonItem.setOptions(selectOptions); effectiveTimeItem.setColSpan(1); effectiveTimeItem.setFieldcol(12); effectiveTimeItem.setViewAttr(3); effectiveTimeItem.setLength(10); adjustReasonItem.setLabel("调整原因"); effectiveTimeItem.setRules("required"); //设置字段填入规则 items.add(adjustReasonItem); SearchConditionItem adjustBeforeItem = conditionFactory.createCondition(ConditionType.INPUT, 502327, "adjustBefore"); adjustBeforeItem.setColSpan(1);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 adjustBeforeItem.setFieldcol(12); //条件输入框所占宽度,默认值18 adjustBeforeItem.setViewAttr(1); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 adjustBeforeItem.setLength(10); // 设置输入长度 adjustBeforeItem.setLabel("调整前"); //设置文本值 这个将覆盖多语言标签的值 adjustBeforeItem.setRules("required"); //设置字段填入规则 adjustBeforeItem.setValue(adjustBefore); items.add(adjustBeforeItem); SearchConditionItem taxAgentItem = conditionFactory.createCondition(ConditionType.SELECT, 502227, "taxAgentId"); List taxAgentOptions = new ArrayList<>(); //设置选项值 taxAgentList.forEach(t -> { if (t.getId().equals(adjustAfter)) { taxAgentOptions.add(new SearchConditionOption(t.getId().toString(), t.getName(), true)); } taxAgentOptions.add(new SearchConditionOption(t.getId().toString(), t.getName())); }); adjustReasonItem.setOptions(selectOptions); effectiveTimeItem.setColSpan(1); effectiveTimeItem.setFieldcol(12); effectiveTimeItem.setViewAttr(3); effectiveTimeItem.setLength(10); adjustReasonItem.setLabel("调整后"); effectiveTimeItem.setRules("required"); //设置字段填入规则 items.add(taxAgentItem); addGroups.add(new SearchConditionGroup("表单", true, items)); Map map = new HashMap<>(); map.put("form", addGroups); return map; } /** * 通过薪资档案的个税扣缴义务人id获取个税扣缴义务人调整表单 * * @param salaryArchiveTaxAgentId * @return */ public SalaryArchiveTaxAgentFormDTO getTaxAgentFormBySalaryArchiveTaxAgentId(Long salaryArchiveTaxAgentId) { if (salaryArchiveTaxAgentId == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100489, "薪资档案的个税扣缴义务人id不能为空")); } SalaryArchiveTaxAgentPO salaryArchiveTaxAgent = salaryArchiveTaxAgentService.getById(salaryArchiveTaxAgentId); if (salaryArchiveTaxAgent == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100484, "该薪资档案的个税扣缴义务人的调整记录不存在")); } // 个税扣缴义务人下拉列表 Collection taxAgentList = taxAgentService.findAll(); // 调整前 String adjustBefore = ""; SalaryArchiveTaxAgentPO adjustBeforePo = salaryArchiveTaxAgentService.getAdjustBeforeTaxAgent(salaryArchiveTaxAgent); if (adjustBeforePo != null) { Optional optional = taxAgentList.stream().filter(f -> f.getId().equals(adjustBeforePo.getTaxAgentId())).findFirst(); adjustBefore = optional.isPresent() ? optional.get().getName() : ""; } Date effectiveTime = salaryArchiveTaxAgent.getEffectiveTime(); String adjustReason = salaryArchiveTaxAgent.getAdjustReason(); Long adjustAfter = salaryArchiveTaxAgent.getTaxAgentId(); // 构建表单 Map taxAgentForm = buildTaxAgentForm(taxAgentList, effectiveTime, adjustReason, adjustBefore, adjustAfter); return SalaryArchiveTaxAgentFormDTO.builder() .salaryArchiveId(salaryArchiveTaxAgent.getSalaryArchiveId()) .salaryArchiveTaxAgentForm(taxAgentForm) .build(); } /** * 保存个税扣缴义务人调整 * * @param saveParam * @return */ public String saveTaxAgent(SalaryArchiveTaxAgentSaveParam saveParam) { return salaryArchiveTaxAgentService.saveTaxAgent(saveParam); } /** * 删除个税扣缴义务人调整 * * @param salaryArchiveTaxAgentId * @return */ public String deleteTaxAgent(Long salaryArchiveTaxAgentId) { return salaryArchiveTaxAgentService.deleteTaxAgent(salaryArchiveTaxAgentId); } /** * 个税扣缴义务人调整记录列表 * * @param queryParam * @return */ public PageInfo adjustRecordList(TaxAgentAdjustRecordQueryParam queryParam) { // 个税扣缴义务人 Collection taxAgentList = taxAgentService.findAll(); List listAll = salaryArchiveTaxAgentService.taxAgentAdjustRecordList(TaxAgentAdjustRecordQueryParam.builder().build()); PageInfo page = salaryArchiveTaxAgentService.taxAgentAdjustRecordListPage(queryParam); List list = page.getList(); list.forEach(m -> { if (!org.springframework.util.CollectionUtils.isEmpty(listAll)) { listAll.removeIf(a -> a.getId().equals(m.getId())); } Optional optional = listAll.stream().filter(f -> f.getSalaryArchiveId().equals(m.getSalaryArchiveId())).findFirst(); m.setAdjustBefore(optional.isPresent() ? optional.get().getAdjustAfter() : ""); Optional optionalBefore = taxAgentList.stream().filter(t -> t.getId().toString().equals(m.getAdjustBefore())).findFirst(); m.setAdjustBefore(optionalBefore.isPresent() ? optionalBefore.get().getName() : ""); Optional optionalAfter = taxAgentList.stream().filter(t -> t.getId().toString().equals(m.getAdjustAfter())).findFirst(); m.setAdjustAfter(optionalAfter.isPresent() ? optionalAfter.get().getName() : ""); m.setEmployeeStatus(UserStatusEnum.getDefaultLabelByValue(Integer.parseInt(m.getEmployeeStatus()))); m.setAdjustReason(SalaryArchiveTaxAgentAdjustReasonEnum.getDefaultLabelByValue(m.getAdjustReason())); }); return page; } /** * 单个档案的个税扣缴义务人调整记录列表 * * @param queryParam * @return */ public PageInfo singleTaxAgentAdjustRecordList(SingleTaxAgentAdjustRecordQueryParam queryParam) { if (queryParam.getSalaryArchiveId() == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100425, "薪资档案id不能为空")); } TaxAgentAdjustRecordQueryParam adjustRecordQueryParam = new TaxAgentAdjustRecordQueryParam(); BeanUtils.copyProperties(queryParam, adjustRecordQueryParam); PageInfo page = salaryArchiveTaxAgentService.taxAgentAdjustRecordListPage(adjustRecordQueryParam); // 个税扣缴义务人 Collection taxAgentList = taxAgentService.findAll(); List listAll = salaryArchiveTaxAgentService.taxAgentAdjustRecordList(TaxAgentAdjustRecordQueryParam.builder().build()); List list = page.getList(); List resultList = Lists.newArrayList(); list.forEach(m -> { if (!org.springframework.util.CollectionUtils.isEmpty(listAll)) { listAll.removeIf(a -> a.getId().equals(m.getId())); } Optional optional = listAll.stream().filter(f -> f.getSalaryArchiveId().equals(m.getSalaryArchiveId())).findFirst(); m.setAdjustBefore(optional.isPresent() ? optional.get().getAdjustAfter() : ""); Optional optionalBefore = taxAgentList.stream().filter(t -> t.getId().toString().equals(m.getAdjustBefore())).findFirst(); m.setAdjustBefore(optionalBefore.isPresent() ? optionalBefore.get().getName() : ""); Optional optionalAfter = taxAgentList.stream().filter(t -> t.getId().toString().equals(m.getAdjustAfter())).findFirst(); m.setAdjustAfter(optionalAfter.isPresent() ? optionalAfter.get().getName() : ""); m.setAdjustReason(SalaryArchiveTaxAgentAdjustReasonEnum.getDefaultLabelByValue(m.getAdjustReason())); SingleTaxAgentAdjustRecordListDTO singleTaxAgentAdjustRecordList = new SingleTaxAgentAdjustRecordListDTO(); BeanUtils.copyProperties(m, singleTaxAgentAdjustRecordList); resultList.add(singleTaxAgentAdjustRecordList); }); // 获取当前已生效 SalaryArchiveTaxAgentPO salaryArchiveTaxAgent = salaryArchiveTaxAgentService.getEffectiveTaxAgent(queryParam.getSalaryArchiveId()); Date effectiveDate = (salaryArchiveTaxAgent == null ? null : salaryArchiveTaxAgent.getEffectiveTime()); // 行记录按钮权限控制 for (int i = 0; i < resultList.size(); i++) { SingleTaxAgentAdjustRecordListDTO singleTaxAgentAdjustRecord = resultList.get(i); if (effectiveDate != null && singleTaxAgentAdjustRecord.getEffectiveTime().before(effectiveDate)) { singleTaxAgentAdjustRecord.setCanOperator(Boolean.FALSE); } else { singleTaxAgentAdjustRecord.setCanOperator(Boolean.TRUE); } } PageInfo listPage = new PageInfo(resultList, SingleTaxAgentAdjustRecordListDTO.class); listPage.setTotal(page.getTotal()); listPage.setPageNum(page.getPageNum()); listPage.setPageSize(page.getPageSize()); return listPage; } /** * 导出个税扣缴义务人调整记录列表 * * @param queryParam * @return */ public XSSFWorkbook exportAdjustRecordList(TaxAgentAdjustRecordQueryParam queryParam) { return salaryArchiveTaxAgentService.exportAdjustRecordList(queryParam); } }