diff --git a/src/com/api/salary/web/SIArchiveActionAPIController.java b/src/com/api/salary/web/SIArchiveActionAPIController.java new file mode 100644 index 000000000..c130f6a8b --- /dev/null +++ b/src/com/api/salary/web/SIArchiveActionAPIController.java @@ -0,0 +1,14 @@ +package com.api.salary.web; + +import com.engine.salary.process.siArchives.SIArchiveActionAPI; + +import javax.ws.rs.Path; + +/** + * @Author: sy + * @Description: + * @Date: 2022/11/11 + **/ +@Path("/bs/hrmsalary/siArchiveAction") +public class SIArchiveActionAPIController extends SIArchiveActionAPI { +} diff --git a/src/com/engine/salary/biz/SIAccountBiz.java b/src/com/engine/salary/biz/SIAccountBiz.java index e68803787..52b76d7dc 100644 --- a/src/com/engine/salary/biz/SIAccountBiz.java +++ b/src/com/engine/salary/biz/SIAccountBiz.java @@ -230,6 +230,7 @@ public class SIAccountBiz extends Service { public void doAccounting(AccountParam param, Long employeeId, String tenantKey, String currentUserName) { + log.info("核算时间:{}, 核算月份:{}, 个税扣缴义务人:{}, 是否首次核算:{}", new Date(), param.getBillMonth(), param.getPaymentOrganization(), param.isFlag()); try { List ids; List validIds = new ArrayList<>(); @@ -405,13 +406,20 @@ public class SIAccountBiz extends Service { List list = MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).getListByEmployeeIdsAndBillMonth(ids, billMonth, param.getPaymentOrganization()); InsuranceAccountDetailTempPOEncrypt.decryptInsuranceAccountDetailTempPOList(list); Integer paymentStatus = 0; - getInsuranceAccountDetailMapper().batchDelAccountDetails(ids, billMonth, param.getPaymentOrganization(), paymentStatus); + log.info("核算明细临时表 hrsa_bill_detail_temp待处理数量:{}", list.size()); + List> partitionIds = Lists.partition((List) ids, 100); + log.info("bill_detail入库前删除数据数量:{}", ids.size()); + for (List part : partitionIds) { + getInsuranceAccountDetailMapper().batchDelAccountDetails(part, billMonth, param.getPaymentOrganization(), paymentStatus); + } + List collect = list.stream().map(item -> { InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO(); BeanUtils.copyProperties(item, insuranceAccountDetailPO); return insuranceAccountDetailPO; }).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(collect)) { + log.info("bill_detail入库数据数量:{}", collect.size()); batchSaveAccountInspectDetail(collect, billMonth, tenantKey); InsuranceAccountDetailPOEncrypt.encryptInsuranceAccountDetailPOList(collect); List> lists = splitDetailList(collect, 20); diff --git a/src/com/engine/salary/biz/SIArchivesBiz.java b/src/com/engine/salary/biz/SIArchivesBiz.java index e51c8d33e..dc4529180 100644 --- a/src/com/engine/salary/biz/SIArchivesBiz.java +++ b/src/com/engine/salary/biz/SIArchivesBiz.java @@ -1069,36 +1069,47 @@ public class SIArchivesBiz { Set socialSet = new HashSet<>(); Set fundSet = new HashSet<>(); Set otherSet = new HashSet<>(); + insuranceArchivesEmployeePOS.forEach(item -> { List socialList = socialSchemeMapper.getSocialByEmployeeId(Collections.singletonList(item.getEmployeeId())); InsuranceArchivesSocialSchemePOEncrypt.decryptList(socialList); - InsuranceArchivesSocialSchemePO socialItem = socialList.size() != 0 ? socialList.get(0) : null; +// InsuranceArchivesSocialSchemePO socialItem = socialList.size() != 0 ? socialList.get(0) : null; List fundList = fundSchemeMapper.getFundByEmployeeId(Collections.singletonList(item.getEmployeeId())); InsuranceArchivesFundSchemePOEncrypt.decryptList(fundList); - InsuranceArchivesFundSchemePO fundItem = fundList.size() != 0 ? fundList.get(0) : null; +// InsuranceArchivesFundSchemePO fundItem = fundList.size() != 0 ? fundList.get(0) : null; List otherList = otherSchemeMapper.getOtherByEmployeeId(Collections.singletonList(item.getEmployeeId())); InsuranceArchivesOtherSchemePOEncrypt.decryptList(otherList); - InsuranceArchivesOtherSchemePO otherItem = otherList.size() != 0 ? otherList.get(0) : null; - if (socialItem != null) { - Map socialJson = JSON.parseObject(socialItem.getSocialPaymentBaseString(), new TypeReference>() { - }); - if (socialJson != null) { - socialJson.forEach((k, v) -> socialSet.add(k)); +// InsuranceArchivesOtherSchemePO otherItem = otherList.size() != 0 ? otherList.get(0) : null; + if (socialList.size() > 0) { + for (InsuranceArchivesSocialSchemePO socialSchemePO : socialList) { + + Map socialJson = JSON.parseObject(socialSchemePO.getSocialPaymentBaseString(), new TypeReference>() { + }); + if (socialJson != null) { + socialJson.forEach((k, v) -> socialSet.add(k)); + } } + } - if (fundItem != null) { - Map fundJson = JSON.parseObject(fundItem.getFundPaymentBaseString(), new TypeReference>() { - }); - if (fundJson != null) { - fundJson.forEach((k, v) -> fundSet.add(k)); + if (fundList.size() > 0) { + for (InsuranceArchivesFundSchemePO fundSchemePO : fundList) { + Map fundJson = JSON.parseObject(fundSchemePO.getFundPaymentBaseString(), new TypeReference>() { + }); + if (fundJson != null) { + fundJson.forEach((k, v) -> fundSet.add(k)); + } } + } - if (otherItem != null) { - Map otherJson = JSON.parseObject(otherItem.getOtherPaymentBaseString(), new TypeReference>() { - }); - if (otherJson != null) { - otherJson.forEach((k, v) -> otherSet.add(k)); + if (otherList.size() > 0) { + for (InsuranceArchivesOtherSchemePO otherSchemePO : otherList) { + Map otherJson = JSON.parseObject(otherSchemePO.getOtherPaymentBaseString(), new TypeReference>() { + }); + if (otherJson != null) { + otherJson.forEach((k, v) -> otherSet.add(k)); + } } + } }); Map socialMap = new HashMap<>(); diff --git a/src/com/engine/salary/entity/siarchives/param/SIArchiveImportActionParam.java b/src/com/engine/salary/entity/siarchives/param/SIArchiveImportActionParam.java new file mode 100644 index 000000000..33ea12705 --- /dev/null +++ b/src/com/engine/salary/entity/siarchives/param/SIArchiveImportActionParam.java @@ -0,0 +1,39 @@ +package com.engine.salary.entity.siarchives.param; + +import com.engine.salary.enums.salaryarchive.SalaryArchiveImportTypeEnum; +import com.engine.salary.enums.siaccount.EmployeeStatusEnum; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * @Author: sy + * @Description: 社保福利档案导入处理参数(action使用) + * @Date: 2022/11/10 + **/ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SIArchiveImportActionParam { + + /** + * 导入类型 + * + * @see EmployeeStatusEnum + */ + + String runStatus; + + /** + * 导入数据 + * + */ + List> importDatas; + + private boolean addData; +} diff --git a/src/com/engine/salary/mapper/siaccount/InsuranceAccountDetailMapper.xml b/src/com/engine/salary/mapper/siaccount/InsuranceAccountDetailMapper.xml index 7d9189b4a..71b1b07c0 100644 --- a/src/com/engine/salary/mapper/siaccount/InsuranceAccountDetailMapper.xml +++ b/src/com/engine/salary/mapper/siaccount/InsuranceAccountDetailMapper.xml @@ -305,7 +305,7 @@ t.fund_per_json,t.fund_com_json,t.other_per_json, t.other_com_json,t.social_per_sum,t.social_com_sum, t.fund_per_sum,t.fund_com_sum,t.other_per_sum, - t.other_com_sum,t.per_sum,t.com_sum + t.other_com_sum,t.per_sum,t.com_sum,t.payment_organization FROM hrsa_bill_detail t WHERE t.delete_type = 0 @@ -320,7 +320,7 @@ t.fund_per_json,t.fund_com_json,t.other_per_json, t.other_com_json,t.social_per_sum,t.social_com_sum, t.fund_per_sum,t.fund_com_sum,t.other_per_sum, - t.other_com_sum,t.per_sum,t.com_sum + t.other_com_sum,t.per_sum,t.com_sum,t.payment_organization FROM hrsa_bill_detail t WHERE t.delete_type = 0 diff --git a/src/com/engine/salary/process/siArchives/SIArchiveActionAPI.java b/src/com/engine/salary/process/siArchives/SIArchiveActionAPI.java new file mode 100644 index 000000000..529f47139 --- /dev/null +++ b/src/com/engine/salary/process/siArchives/SIArchiveActionAPI.java @@ -0,0 +1,64 @@ +package com.engine.salary.process.siArchives; + +import com.engine.common.util.ServiceUtil; +import com.engine.salary.entity.siarchives.param.SIArchiveImportActionParam; +import com.engine.salary.enums.siaccount.EmployeeStatusEnum; +import com.engine.salary.service.SISchemeService; +import com.engine.salary.service.impl.SISchemeServiceImpl; +import com.engine.salary.util.ResponseResult; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import lombok.extern.slf4j.Slf4j; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + * @Author: sy + * @Description: 社保福利档案流程使用 + * @Date: 2022/11/10 + **/ +@Slf4j +public class SIArchiveActionAPI { + + private SISchemeService getService(User user) { + return ServiceUtil.getService(SISchemeServiceImpl.class,user); + } + + /** + * 前置校验、列表添加接口 + * @param importData + * @return + */ + @POST + @Path("/checkImportSIArchiveListAdd") + @Produces(MediaType.APPLICATION_JSON) + public String checkImportSIArchiveListAdd(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SIArchiveImportActionParam importData) { + User user = HrmUserVarify.getUser(request, response); + importData.setRunStatus(EmployeeStatusEnum.STAY_ADD.getValue()); + importData.setAddData(false); + return new ResponseResult>(user).run(getService(user)::checkSIArchiveAdd, importData); + } + + /** + * 新增社保福利档案 + * @param importData + * @return + */ + @POST + @Path("/addSIArchive") + @Produces(MediaType.APPLICATION_JSON) + public String addSIArchive(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SIArchiveImportActionParam importData) { + User user = HrmUserVarify.getUser(request, response); + importData.setRunStatus(EmployeeStatusEnum.STAY_ADD.getValue()); + importData.setAddData(true); + return new ResponseResult>(user).run(getService(user)::addSIArchive, importData); + } +} diff --git a/src/com/engine/salary/service/SIAccountService.java b/src/com/engine/salary/service/SIAccountService.java index 24aed75b8..f4cb5b59a 100644 --- a/src/com/engine/salary/service/SIAccountService.java +++ b/src/com/engine/salary/service/SIAccountService.java @@ -245,6 +245,11 @@ public interface SIAccountService { */ Map importExcelInsuranceDetail(ExcelInsuranceImportParam excelInsuranceImportParam); + /** + * 刷新_bill_batch表中的统计信息 + */ + void refreshBillBatch(Long paymentOrganization, String billMonth); + /** * 将通过id获取InsuranceAccountDetailPO中的社保、公积金、其他福利个人和公司缴纳数据 */ diff --git a/src/com/engine/salary/service/SISchemeService.java b/src/com/engine/salary/service/SISchemeService.java index 05c64c7fd..ebcf73858 100644 --- a/src/com/engine/salary/service/SISchemeService.java +++ b/src/com/engine/salary/service/SISchemeService.java @@ -2,6 +2,7 @@ package com.engine.salary.service; import com.cloudstore.eccom.pc.table.WeaTableColumn; import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; +import com.engine.salary.entity.siarchives.param.SIArchiveImportActionParam; import com.engine.salary.entity.siarchives.po.InsuranceArchivesEmployeePO; import com.engine.salary.entity.sischeme.dto.InsuranceSchemeListDTO; import com.engine.salary.entity.sischeme.param.InsuranceSchemeParam; @@ -69,4 +70,8 @@ public interface SISchemeService { Map batchImportEbatch(SISchemaImportParam param); XSSFWorkbook exportTemplate(InsuranceArchivesListParam param); + + Map checkSIArchiveAdd(SIArchiveImportActionParam siArchiveImportActionParam); + + Map addSIArchive(SIArchiveImportActionParam siArchiveImportActionParam); } diff --git a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java index 96f1e60ba..9019e07e5 100644 --- a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java @@ -74,6 +74,8 @@ import weaver.hrm.User; import java.io.InputStream; import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -1192,10 +1194,10 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { // 处理数值 List> data = ExcelParseHelper.parse2Map(sheet, 1); if (CollectionUtils.isEmpty(headers)) { - throw new RuntimeException("表头为空"); + throw new SalaryRunTimeException("表头为空"); } if (CollectionUtils.isEmpty(data)) { - throw new RuntimeException("无数据"); + throw new SalaryRunTimeException("无数据"); } //存储待更新的InsuranceAccountDetailPO数据 List updateInsuranceAccountDetailList = new ArrayList<>(); @@ -1331,6 +1333,45 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { getSiAccountBiz(user).updateByEmployeeIdAndBillMonth(po); } + //刷新hrsa_bill_batch中数据统计信息 + if (updateInsuranceAccountDetailList.size() > 0) { + ExecutorService taskExecutor = Executors.newCachedThreadPool(); + taskExecutor.execute(() -> { + Long paymentOrganization = updateInsuranceAccountDetailList.get(0).getPaymentOrganization(); + String billMonth = updateInsuranceAccountDetailList.get(0).getBillMonth(); + if (paymentOrganization != null && billMonth != null) { + InsuranceAccountDetailParam refreshParam =new InsuranceAccountDetailParam(); + refreshParam.setBillMonth(billMonth); + refreshParam.setPaymentOrganization(paymentOrganization.toString()); + PageInfo pageInfos = overView(refreshParam); + TaxAgentPO taxAgentPo = getTaxAgentMapper().getById(paymentOrganization); + if (taxAgentPo != null) { + List viewListDTOList = pageInfos.getList(); + viewListDTOList.stream().filter(f -> f.getPayOrg().equals(taxAgentPo.getName())).collect(Collectors.toList()); + InsuranceAccountBatchPO batchPO = getInsuranceAccountBatchMapper().getByBillMonth(billMonth, paymentOrganization); + batchPO = SiAccountEncrypt.decryptInsuranceAccountBatch(batchPO); + //更新 + if (viewListDTOList.size() > 0 && batchPO != null) { + InsuranceAccountViewListDTO viewListDTO = viewListDTOList.get(0); + batchPO.setSocialNum(viewListDTO.getSocialNum()); + batchPO.setFundNum(viewListDTO.getFundNum()); + batchPO.setOtherNum(viewListDTO.getOtherNum()); + + batchPO.setSocialPay(viewListDTO.getSocialPaySum().replace(",", "")); + batchPO.setFundPay(viewListDTO.getFundPaySum().replace(",", "")); + batchPO.setOtherPay(viewListDTO.getOtherPaySum().replace(",", "")); + + batchPO.setUpdateTime(new Date()); + batchPO = SiAccountEncrypt.encryptInsuranceAccountBatch(batchPO); + getInsuranceAccountBatchMapper().updateById(batchPO); + } + } + + } + }); + + } + apidatas.put("successCount", successCount); apidatas.put("errorCount", failCount); apidatas.put("errorData", excelComments); @@ -1842,10 +1883,10 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { // 处理数值 List> data = ExcelParseHelper.parse2Map(sheet, 1); if (CollectionUtils.isEmpty(headers)) { - throw new RuntimeException("表头为空"); + throw new SalaryRunTimeException("表头为空"); } if (CollectionUtils.isEmpty(data)) { - throw new RuntimeException("无数据"); + throw new SalaryRunTimeException("无数据"); } String billMonth = importParam.getBillMonth(); @@ -2148,6 +2189,45 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { return excelInsuranceDetailPO; } + /** + * 刷新_bill_batch表中的统计信息 + */ + @Override + public void refreshBillBatch(Long paymentOrganization, String billMonth) { + ExecutorService taskExecutor = Executors.newCachedThreadPool(); + taskExecutor.execute(() -> { + + if (paymentOrganization != null && billMonth != null) { + InsuranceAccountDetailParam refreshParam =new InsuranceAccountDetailParam(); + refreshParam.setBillMonth(billMonth); + refreshParam.setPaymentOrganization(paymentOrganization.toString()); + PageInfo pageInfos = overView(refreshParam); + TaxAgentPO taxAgentPo = getTaxAgentMapper().getById(paymentOrganization); + if (taxAgentPo != null) { + List viewListDTOList = pageInfos.getList(); + viewListDTOList.stream().filter(f -> f.getPayOrg().equals(taxAgentPo.getName())).collect(Collectors.toList()); + InsuranceAccountBatchPO batchPO = getInsuranceAccountBatchMapper().getByBillMonth(billMonth, paymentOrganization); + batchPO = SiAccountEncrypt.decryptInsuranceAccountBatch(batchPO); + //更新 + if (viewListDTOList.size() > 0 && batchPO != null) { + InsuranceAccountViewListDTO viewListDTO = viewListDTOList.get(0); + batchPO.setSocialNum(viewListDTO.getSocialNum()); + batchPO.setFundNum(viewListDTO.getFundNum()); + batchPO.setOtherNum(viewListDTO.getOtherNum()); + + batchPO.setSocialPay(viewListDTO.getSocialPaySum().replace(",", "")); + batchPO.setFundPay(viewListDTO.getFundPaySum().replace(",", "")); + batchPO.setOtherPay(viewListDTO.getOtherPaySum().replace(",", "")); + + batchPO.setUpdateTime(new Date()); + batchPO = SiAccountEncrypt.encryptInsuranceAccountBatch(batchPO); + getInsuranceAccountBatchMapper().updateById(batchPO); + } + } + + } + }); + } /** * 将通过id获取InsuranceAccountDetailPO中的社保、公积金、其他福利个人和公司缴纳数据 */ diff --git a/src/com/engine/salary/service/impl/SISchemeServiceImpl.java b/src/com/engine/salary/service/impl/SISchemeServiceImpl.java index 1a1ab9cdc..e8c454de5 100644 --- a/src/com/engine/salary/service/impl/SISchemeServiceImpl.java +++ b/src/com/engine/salary/service/impl/SISchemeServiceImpl.java @@ -17,8 +17,8 @@ import com.engine.salary.encrypt.siarchives.InsuranceArchivesOtherSchemePOEncryp import com.engine.salary.encrypt.siarchives.InsuranceArchivesSocialSchemePOEncrypt; import com.engine.salary.encrypt.sischeme.InsuranceSchemeDetailPOEncrypt; import com.engine.salary.entity.datacollection.DataCollectionEmployee; -import com.engine.salary.entity.salaryarchive.po.SalaryArchivePO; import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; +import com.engine.salary.entity.siarchives.param.SIArchiveImportActionParam; import com.engine.salary.entity.siarchives.po.*; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.sischeme.dto.InsuranceSchemeListDTO; @@ -64,11 +64,11 @@ import org.apache.commons.lang3.math.NumberUtils; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.xpath.operations.Bool; import weaver.file.ImageFileManager; import weaver.hrm.User; import java.io.InputStream; +import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -713,26 +713,55 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { public boolean singleAccountCheck(List> singleAccount, Map welfareMap, List insuranceArchivesAccountPOS, List employeeByIds, List> excelComments, int i, Map schemeNameIdMap, Map paymentNameIdMap, Long creator, int index, Boolean openDevolution, List taxAgentManageRangeEmployeeTree, String runStatus) { boolean isError = false; - String userName = (String) singleAccount.get(0).get(SalaryI18nUtil.getI18nLabel(85429, "姓名")); - String deparmentName = (String) singleAccount.get(1).get(SalaryI18nUtil.getI18nLabel(86185, "部门")); - String mobile = (String) singleAccount.get(2).get(SalaryI18nUtil.getI18nLabel(86186, "手机号")); - String userStatus = (String) singleAccount.get(3).get(SalaryI18nUtil.getI18nLabel(86187, "员工状态")); - String workcode = (String) singleAccount.get(4).get(SalaryI18nUtil.getI18nLabel(86317, "工号")); +// String userName = (String) singleAccount.get(0).get(SalaryI18nUtil.getI18nLabel(85429, "姓名")); +// String deparmentName = (String) singleAccount.get(1).get(SalaryI18nUtil.getI18nLabel(86185, "部门")); +// String mobile = (String) singleAccount.get(2).get(SalaryI18nUtil.getI18nLabel(86186, "手机号")); +// String userStatus = (String) singleAccount.get(3).get(SalaryI18nUtil.getI18nLabel(86187, "员工状态")); +// String workcode = (String) singleAccount.get(4).get(SalaryI18nUtil.getI18nLabel(86317, "工号")); + + Map userNameMap = findElement(singleAccount, SalaryI18nUtil.getI18nLabel(85429, "姓名")); + Map deparmentNameMap = findElement(singleAccount, SalaryI18nUtil.getI18nLabel(86185, "部门")); + Map mobileMap = findElement(singleAccount, SalaryI18nUtil.getI18nLabel(86186, "手机号")); + Map userStatusMap = findElement(singleAccount, SalaryI18nUtil.getI18nLabel(86187, "员工状态")); + Map workcodeMap = findElement(singleAccount, SalaryI18nUtil.getI18nLabel(86317, "工号")); + Map employeeIdMap = findElement(singleAccount, SalaryI18nUtil.getI18nLabel(86187, "员工id")); + + + String userName = (String) userNameMap.get(SalaryI18nUtil.getI18nLabel(85429, "姓名")); + String deparmentName = (String) deparmentNameMap.get(SalaryI18nUtil.getI18nLabel(86185, "部门")); + String mobile = (String) mobileMap.get(SalaryI18nUtil.getI18nLabel(86186, "手机号")); + String userStatus = (String) userStatusMap.get(SalaryI18nUtil.getI18nLabel(86187, "员工状态")); + String workcode = (String) workcodeMap.get(SalaryI18nUtil.getI18nLabel(86317, "工号")); + String toAddEmployeeId; + if (employeeIdMap.isEmpty()) { + toAddEmployeeId = null; + } else { + toAddEmployeeId = employeeIdMap.get(SalaryI18nUtil.getI18nLabel(86187, "员工id")).toString(); + } + + Long addEmployeeId = StringUtils.isNotBlank(toAddEmployeeId) ? Long.valueOf(toAddEmployeeId) : null; //查询对于人员信息导入筛选的全局配置 SalarySysConfPO salarySysConfPO = getSalarySysConfMapper().getOneByCode("matchEmployeeMode"); String confValue = (salarySysConfPO != null && salarySysConfPO.getConfValue() != null && !"".equals(salarySysConfPO.getConfValue())) ? salarySysConfPO.getConfValue() : "0"; String rowIndex = "第" + index + "行"; - //仅在全局人员筛选配置为“0”时,才对用户名、部门名称、手机号有要求 - if (StringUtils.isBlank(userName) && StringUtils.isBlank(deparmentName) && StringUtils.isBlank(mobile) && "0".equals(confValue)) { - Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + " 用户名、部门名称、手机号" + SalaryI18nUtil.getI18nLabel(100303, "不能同时为空")); - excelComments.add(errorMessageMap); - isError = true; + List employees = new ArrayList<>(); + //当新增数据中包含员工id信息时,直接根据员工id获取员工信息 + if (addEmployeeId == null) { + //仅在全局人员筛选配置为“0”时,才对用户名、部门名称、手机号有要求 + if (StringUtils.isBlank(userName) && StringUtils.isBlank(deparmentName) && StringUtils.isBlank(mobile) && "0".equals(confValue)) { + Map errorMessageMap = Maps.newHashMap(); + errorMessageMap.put("message", rowIndex + " 用户名、部门名称、手机号" + SalaryI18nUtil.getI18nLabel(100303, "不能同时为空")); + excelComments.add(errorMessageMap); + isError = true; + } + //筛选导入人员信息可以在人力资源池中匹配到的人员信息 + employees = getSalaryEmployeeService(user).matchImportEmployee(employeeByIds, userName, deparmentName, mobile, workcode, null); + } else { + employees = employeeByIds.stream().filter(f -> f.getEmployeeId().equals(addEmployeeId)).collect(Collectors.toList()); } - //筛选导入人员信息可以在人力资源池中匹配到的人员信息 - List employees = getSalaryEmployeeService(user).matchImportEmployee(employeeByIds, userName, deparmentName, mobile, workcode, null); + if (CollectionUtils.isEmpty(employees)) { Map errorMessageMap = Maps.newHashMap(); @@ -830,67 +859,67 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { String socialStartMonth = (String) socialStartTimeMap.get(SalaryI18nUtil.getI18nLabel(91319, "社保起始缴纳月")); -// if (StringUtils.isNotBlank(socialStartMonth) && socialStartMonth.length() > 7) { -// socialStartMonth = socialStartMonth.substring(0, 7); -// } - if (StringUtils.isNotBlank(socialStartMonth) && (!SalaryDateUtil.checkYearMonth(socialStartMonth) || socialStartMonth.length() != 7)) { + if (StringUtils.isNotBlank(socialStartMonth) && socialStartMonth.length() > 7) { + socialStartMonth = socialStartMonth.substring(0, 7); + } + if (StringUtils.isNotBlank(socialStartMonth) && !SalaryDateUtil.checkYearMonth(socialStartMonth)) { Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100315, "社保起始缴纳时间格式错误,正确格式为YYYY-MM")); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100315, "社保起始缴纳时间格式错误,正确格式为YYYY-MM或者yyyy-MM-dd")); excelComments.add(errorMessageMap); isError = true; } String socialEndMonth = (String) socialEndTimeMap.get(SalaryI18nUtil.getI18nLabel(91320, "社保最后缴纳月")); -// if (StringUtils.isNotBlank(socialEndMonth) && socialEndMonth.length() > 7) { -// socialEndMonth = socialEndMonth.substring(0, 7); -// } - if (StringUtils.isNotBlank(socialEndMonth) && (!SalaryDateUtil.checkYearMonth(socialEndMonth) || socialEndMonth.length() != 7)) { + if (StringUtils.isNotBlank(socialEndMonth) && socialEndMonth.length() > 7) { + socialEndMonth = socialEndMonth.substring(0, 7); + } + if (StringUtils.isNotBlank(socialEndMonth) && !SalaryDateUtil.checkYearMonth(socialEndMonth)) { Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100316, "社保最后缴纳时间格式错误,正确格式为YYYY-MM")); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100316, "社保最后缴纳时间格式错误,正确格式为YYYY-MM或者yyyy-MM-dd")); excelComments.add(errorMessageMap); isError = true; } String fundStartMonth = (String) fundStartTimeMap.get(SalaryI18nUtil.getI18nLabel(91483, "公积金起始缴纳月")); -// if (StringUtils.isNotBlank(fundStartMonth) && fundStartMonth.length() > 7) { -// fundStartMonth = fundStartMonth.substring(0, 7); -// } - if (StringUtils.isNotBlank(fundStartMonth) && (!SalaryDateUtil.checkYearMonth(fundStartMonth) || fundStartMonth.length() != 7)) { + if (StringUtils.isNotBlank(fundStartMonth) && fundStartMonth.length() > 7) { + fundStartMonth = fundStartMonth.substring(0, 7); + } + if (StringUtils.isNotBlank(fundStartMonth) && !SalaryDateUtil.checkYearMonth(fundStartMonth)) { Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100317, "公积金起始缴纳时间格式错误,正确格式为YYYY-MM")); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100317, "公积金起始缴纳时间格式错误,正确格式为YYYY-MM或者yyyy-MM-dd")); excelComments.add(errorMessageMap); isError = true; } String fundEndMonth = (String) fundEndTimeMap.get(SalaryI18nUtil.getI18nLabel(91484, "公积金最后缴纳月")); -// if (StringUtils.isNotBlank(fundEndMonth) && fundEndMonth.length() > 7) { -// fundEndMonth = fundEndMonth.substring(0, 7); -// } - if (StringUtils.isNotBlank(fundEndMonth) && (!SalaryDateUtil.checkYearMonth(fundEndMonth) || fundEndMonth.length() != 7)) { + if (StringUtils.isNotBlank(fundEndMonth) && fundEndMonth.length() > 7) { + fundEndMonth = fundEndMonth.substring(0, 7); + } + if (StringUtils.isNotBlank(fundEndMonth) && !SalaryDateUtil.checkYearMonth(fundEndMonth)) { Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100319, "公积金最后缴纳时间格式错误,正确格式为YYYY-MM")); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100319, "公积金最后缴纳时间格式错误,正确格式为YYYY-MM或者yyyy-MM-dd")); excelComments.add(errorMessageMap); isError = true; } String otherStartMonth = (String) otherStartTimeMap.get(SalaryI18nUtil.getI18nLabel(91490, "其他福利起始缴纳月")); -// if (StringUtils.isNotBlank(otherStartMonth) && otherStartMonth.length() > 7) { -// otherStartMonth = otherStartMonth.substring(0, 7); -// } - if (StringUtils.isNotBlank(otherStartMonth) && (!SalaryDateUtil.checkYearMonth(otherStartMonth) || otherStartMonth.length() != 7)) { + if (StringUtils.isNotBlank(otherStartMonth) && otherStartMonth.length() > 7) { + otherStartMonth = otherStartMonth.substring(0, 7); + } + if (StringUtils.isNotBlank(otherStartMonth) && !SalaryDateUtil.checkYearMonth(otherStartMonth)) { Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100320, "其他福利起始缴纳时间格式错误,正确格式为YYYY-MM")); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100320, "其他福利起始缴纳时间格式错误,正确格式为YYYY-MM或者yyyy-MM-dd")); excelComments.add(errorMessageMap); isError = true; } String otherEndMonth = (String) otherEndTimeMap.get(SalaryI18nUtil.getI18nLabel(91494, "其他福利最后缴纳月")); -// if (StringUtils.isNotBlank(otherEndMonth) && otherEndMonth.length() > 7) { -// otherEndMonth = otherEndMonth.substring(0, 7); -// } - if (StringUtils.isNotBlank(otherEndMonth) && (!SalaryDateUtil.checkYearMonth(otherEndMonth) || otherEndMonth.length() != 7)) { + if (StringUtils.isNotBlank(otherEndMonth) && otherEndMonth.length() > 7) { + otherEndMonth = otherEndMonth.substring(0, 7); + } + if (StringUtils.isNotBlank(otherEndMonth) && !SalaryDateUtil.checkYearMonth(otherEndMonth)) { Map errorMessageMap = Maps.newHashMap(); - errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100321, "其他福利最后缴纳时间格式错误,正确格式为YYYY-MM")); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100321, "其他福利最后缴纳时间格式错误,正确格式为YYYY-MM或者yyyy-MM-dd")); excelComments.add(errorMessageMap); isError = true; } @@ -908,7 +937,12 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { excelComments.add(errorMessageMap); isError = true; - } else { + } else if (StringUtils.isNotBlank((String) socialMap.get(SalaryI18nUtil.getI18nLabel(91323, "社保方案名称"))) && StringUtils.isBlank(socialStartMonth)) { + Map errorMessageMap = Maps.newHashMap(); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100322, "社保方案已设置,但未设置社保起始缴纳时间!")); + excelComments.add(errorMessageMap); + isError = true; + }else { insuranceArchivesSocialSchemePO = buildSocialPO(employeeId, welfareMap, singleAccount, schemeNameIdMap, paymentNameIdMap, creator); } if (StringUtils.isNotBlank((String) fundMap.get(SalaryI18nUtil.getI18nLabel(91485, "公积金方案名称"))) && schemeNameIdMap.get((String) fundMap.get(SalaryI18nUtil.getI18nLabel(91485, "公积金方案名称"))) == null) { @@ -925,7 +959,12 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { excelComments.add(errorMessageMap); isError = true; - }else { + } else if (StringUtils.isNotBlank((String) fundMap.get(SalaryI18nUtil.getI18nLabel(91485, "公积金方案名称"))) && StringUtils.isBlank(fundStartMonth)) { + Map errorMessageMap = Maps.newHashMap(); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100322, "公积金方案已设置,但未设置公积金起始缴纳时间!")); + excelComments.add(errorMessageMap); + isError = true; + } else { insuranceArchivesFundSchemePO = buildFundPO(employeeId, welfareMap, singleAccount, schemeNameIdMap, paymentNameIdMap, creator); } if (StringUtils.isNotBlank((String) otherMap.get(SalaryI18nUtil.getI18nLabel(91496, "其他福利方案名称"))) && schemeNameIdMap.get((String) otherMap.get(SalaryI18nUtil.getI18nLabel(91496, "其他福利方案名称"))) == null) { @@ -941,7 +980,12 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100322, "其他福利方案不属于其他福利类型")); excelComments.add(errorMessageMap); isError = true; - }else { + } else if (StringUtils.isNotBlank((String) otherMap.get(SalaryI18nUtil.getI18nLabel(91496, "其他福利方案名称"))) && StringUtils.isBlank(otherStartMonth)) { + Map errorMessageMap = Maps.newHashMap(); + errorMessageMap.put("message", rowIndex + SalaryI18nUtil.getI18nLabel(100322, "其他福利方案已设置,但未设置其他福利起始缴纳时间!")); + excelComments.add(errorMessageMap); + isError = true; + } else { insuranceArchivesOtherSchemePO = buildOtherPO(employeeId, welfareMap, singleAccount, schemeNameIdMap, paymentNameIdMap, creator); } /**************校验申报基数**************/ @@ -1045,7 +1089,8 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { continue; } if (findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")) != null) { - socialPaymentBase.put(String.valueOf(insuranceId), (String) findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")).get(welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数"))); + String itemValue = (String) findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")).get(welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")); + socialPaymentBase.put(String.valueOf(insuranceId), StringUtils.isBlank(itemValue) ? "0" : itemValue); } } insuranceArchivesSocialSchemePO.setSocialPaymentBaseString(JSON.toJSONString(socialPaymentBase)); @@ -1096,7 +1141,8 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { continue; } if (findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")) != null) { - socialPaymentBase.put(String.valueOf(insuranceId), (String) findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")).get(welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数"))); + String itemValue = (String) findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")).get(welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")); + socialPaymentBase.put(String.valueOf(insuranceId), StringUtils.isBlank(itemValue) ? "0" : itemValue); } } insuranceArchivesFundSchemePO.setFundPaymentBaseString(JSON.toJSONString(socialPaymentBase)); @@ -1143,7 +1189,8 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { continue; } if (findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")) != null) { - socialPaymentBase.put(String.valueOf(insuranceId), (String) findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")).get(welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数"))); + String itemValue = (String) findElement(singleAccount, welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")).get(welfareMap.get(insuranceId) + SalaryI18nUtil.getI18nLabel(100293, "申报基数")); + socialPaymentBase.put(String.valueOf(insuranceId), StringUtils.isBlank(itemValue) ? "0" : itemValue); } } insuranceArchivesOtherSchemePO.setOtherPaymentBaseString(JSON.toJSONString(socialPaymentBase)); @@ -1258,4 +1305,140 @@ public class SISchemeServiceImpl extends Service implements SISchemeService { } + /** + * 校验待新增的社保福利档案数据 + * @param siArchiveImportActionParam + * @return + */ + @Override + public Map checkSIArchiveAdd(SIArchiveImportActionParam siArchiveImportActionParam) { + siArchiveImportActionParam.setAddData(false); + return processAddSIArchive(siArchiveImportActionParam); + } + + /** + * 新增社保福利档案 + * @param siArchiveImportActionParam + * @return + */ + @Override + public Map addSIArchive(SIArchiveImportActionParam siArchiveImportActionParam) { + siArchiveImportActionParam.setAddData(true); + return processAddSIArchive(siArchiveImportActionParam); + } + + private Map processAddSIArchive(SIArchiveImportActionParam param) { + + ValidUtil.doValidator(param); + + if (StringUtils.isBlank(param.getRunStatus())) { + throw new SalaryRunTimeException("福利档案执行状态未在导入条件设置中添加!"); + } +// List excelSheets = message.getBatchFile().getExcelSheets(); + // 租户key +// String tenantKey = message.getTenantKey().toLowerCase(); + //操作员id + Long creator = (long) user.getUID(); + //获取所有福利类型的id-name结合 + Map schemeNameIdMap = schemeNameIdMap(); + Map welfareMap = welfareMap(); + // 获取所有个税扣缴义务人的名称和id的map + Map paymentNameIdMap; + //分权 + Boolean openDevolution = getTaxAgentService().isOpenDevolution(); + if (openDevolution) { + paymentNameIdMap = getTaxAgentService().listAllTaxAgentsAsAdmin((long) user.getUID()).stream().collect(Collectors.toMap(TaxAgentPO::getName, TaxAgentPO::getId)); + } else { + paymentNameIdMap = getTaxAgentService().listAll().stream().collect(Collectors.toMap(TaxAgentPO::getName, TaxAgentPO::getId)); + } + + //获取所以个税扣缴义务人树型 + List taxAgentManageRangeEmployeeTree = getTaxAgentService().listTaxAgentAndEmployeeTree(); + + // 获取所有人员信息 + List employeeByIds = employeeBiz.listEmployee(); + int total = 0; + + int index = 0; + int successCount = 0; + int errorCount = 0; + + // 待导入数据 + List insuranceArchivesAccountPOS = new ArrayList<>(); + + // 待导入数据 + InputStream fileInputStream = null; + try { + // 表头 + List headers = new ArrayList<>(); + if (param.getImportDatas().size() > 0) { + Map getHeadersMap = param.getImportDatas().get(0); + for (Map.Entry entry : getHeadersMap.entrySet()){ + headers.add(entry.getKey()); + } + } else { + throw new SalaryRunTimeException("新增福利档案数据为空!"); + } + + // 错误sheet数据 + List> errorData = new LinkedList<>(); + // 错误提示 + List> excelComments = new LinkedList<>(); + + // 处理数值 + List> data = param.getImportDatas(); + total = data.size(); + + //当前sheel的单行记录 + Map map; + for (int i = 0; i < data.size(); i++) { + index += 1; + map = data.get(i); + boolean isError; + List> singleAccount = new ArrayList<>(); + for (int j = 0; j < headers.size(); j++) { + //组装单条数据基础数据 + String key = headers.get(j); + if (key == null) { + continue; + } + Map cellData = new HashMap<>(); + cellData.put(key.toString(), Optional.ofNullable(map.get(key.toString())).orElse("").toString()); + cellData.put("index", j); + singleAccount.add(cellData); + } + + isError = singleAccountCheck(singleAccount, welfareMap, insuranceArchivesAccountPOS, employeeByIds, excelComments, errorCount + 1, schemeNameIdMap, paymentNameIdMap, creator, i + 2, openDevolution, taxAgentManageRangeEmployeeTree, param.getRunStatus()); + if (isError) { + errorCount += 1; + // 添加错误数据 + errorData.add(map); + } else { + successCount += 1; + } +// salaryBatchService.sendImportRate(message.getBizId(), total, index); + } + + // 如果sheet包含错误数据 +// if (CollectionUtils.isNotEmpty(errorData)) { +// salaryBatchService.createErrorExcelSheet(headers, errorData, excelSheet.getName(), excelComments, errorExcelSheets); +// } + + // 数据入库处理 + if (param.isAddData()) { + handleImportData(insuranceArchivesAccountPOS); + } + // 发送导入回调信息 +// salaryBatchService.sendImportCallBackInfo(message, successCount, errorCount, errorExcelSheets); + + Map apidatas = new HashMap(); + apidatas.put("successCount", successCount); + apidatas.put("errorCount", errorCount); + apidatas.put("errorData", excelComments); + return apidatas; + } finally { + IOUtils.closeQuietly(fileInputStream); + } + } + }