weaver-hrm-salary/src/com/engine/salary/cmd/datacollection/AddUpSituationImportCmd.java

317 lines
17 KiB
Java
Raw Normal View History

2022-03-09 16:40:14 +08:00
//package com.engine.salary.cmd.datacollection;
//
//import com.engine.common.biz.AbstractCommonCommand;
//import com.engine.common.entity.BizLogContext;
//import com.engine.core.interceptor.CommandContext;
//import com.engine.salary.biz.AddUpSituationBiz;
//import com.engine.salary.biz.TaxAgentBiz;
//import com.engine.salary.entity.datacollection.AddUpSituation;
//import com.engine.salary.entity.datacollection.DataCollectionEmployee;
//import com.engine.salary.entity.datacollection.dto.AddUpSituationDTO;
//import com.engine.salary.entity.datacollection.param.AddUpSituationImportParam;
//import com.engine.salary.entity.taxrate.TaxAgent;
//import com.engine.salary.exception.SalaryRunTimeException;
//import com.engine.salary.util.excel.ExcelParseHelper;
//import com.google.common.collect.Maps;
//import lombok.SneakyThrows;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.poi.util.IOUtils;
//import weaver.general.Util;
//import weaver.hrm.User;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.InputStream;
//import java.math.BigDecimal;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.engine.salary.constant.SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY;
//
//public class AddUpSituationImportCmd extends AbstractCommonCommand<Map<String, Object>> {
//
// protected HttpServletRequest request;
//
// public AddUpSituationImportCmd(Map<String, Object> params, User user) {
// this.user = user;
// this.params = params;
//
// }
//
// @Override
// public BizLogContext getLogContext() {
// return null;
// }
//
// @SneakyThrows
// @Override
// public Map<String, Object> execute(CommandContext commandContext) {
// Map<String, Object> apidatas = new HashMap<String, Object>();
// AddUpSituationBiz biz = new AddUpSituationBiz();
//
// //检验参数
// checkImportParam();
//
// //导入参数
// AddUpSituationImportParam importParam = (AddUpSituationImportParam) params.get("importParam");
// //excel文件id
// String imageId = Util.null2String(importParam.getImageId());
// //税款所属期
// String taxYearMonthStr = Util.null2String(importParam.getTaxYearMonth());
//
//
// InputStream fileInputStream = null;
// try {
//// fileInputStream = ImageFileManager.getInputStreamById(Integer.valueOf(imageId));
// fileInputStream = new FileInputStream("C:\\Users\\钱涛\\Desktop\\salary\\addUpSituation\\importTemplate.xlsx");
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// try {
//
// List<AddUpSituationDTO> excelDates = ExcelParseHelper.parse(fileInputStream, AddUpSituationDTO.class, 0, 1, 21, "template.xlsx");
//
// int total = excelDates.size();
// int index = 0;
// int successCount = 0;
// int errorCount = 0;
//
// //人员信息
//// List<DataCollectionEmployee> employees = biz.listEmployee();
// List<TaxAgent> taxAgents = new TaxAgentBiz().listAll();
//
// //税款所属期
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// Date taxYearMonth = simpleDateFormat.parse(taxYearMonthStr + "-01");
// Date now = new Date();
//
// // 错误excel内容
// List<Map> errorData = new ArrayList<>();
// //合规数据
// List<AddUpSituation> eligibleData = new ArrayList<>();
//
//
// for (int i = 0; i < excelDates.size(); i++) {
// //excel中的数据
// AddUpSituationDTO dto = excelDates.get(i);
// //待插入数据库对象
// AddUpSituation po = AddUpSituation.builder().tenantKey(DEFAULT_TENANT_KEY)
// .createTime(now)
// .updateTime(now)
// .creator((long) user.getUID())
// .year(Integer.valueOf(taxYearMonthStr.split("-")[0]))
// .taxYearMonth(taxYearMonth)
// .build();
//
//
// //异常点数量
// int errorSum = 0;
//
// //行号
// String rowIndex = String.format("第%s行", i + 2);
//
// //相同的姓名
// String userName = dto.getUsername();
// String deparmentName = dto.getDepartmentName();
// List<Long> employeeSameIds = employees.stream().filter(e -> (StringUtils.isBlank(userName) || Objects.equals(e.getUsername(), userName))
// && (StringUtils.isBlank(deparmentName) || Objects.equals(e.getDeparmentName(), deparmentName))).map(DataCollectionEmployee::getEmployeeId)
// .collect(Collectors.toList());
//
//
// if (StringUtils.isBlank(userName)) {
// //姓名 不能为空
// //错误消息对象
// Map<String, String> errorMessageMap = Maps.newHashMap();
// errorMessageMap.put("message", rowIndex + "姓名不能为空");
// errorData.add(errorMessageMap);
// errorSum += 1;
// } else if (CollectionUtils.isEmpty(employeeSameIds) || employeeSameIds.size() > 1) {
// Map<String, String> errorMessageMap = Maps.newHashMap();
// errorMessageMap.put("message", rowIndex + "员工信息不能为空且不可重复(姓名与部门同时确认唯一)");
// errorData.add(errorMessageMap);
// errorSum += 1;
// } else {
// Long employeeId = CollectionUtils.isNotEmpty(employeeSameIds) && employeeSameIds.size() == 1 ? employeeSameIds.get(0) : null;
// if (employeeId != null && employeeId > 0) {
// po.setEmployeeId(employeeId);
// } else {
// //姓名错误,系统内不存在该姓名
// Map<String, String> errorMessageMap = Maps.newHashMap();
// errorMessageMap.put("message", rowIndex + "姓名错误,系统内不存在该姓名");
// errorData.add(errorMessageMap);
// errorSum += 1;
// }
// }
//
//
// String taxAgentName = dto.getTaxAgentName();
// if (StringUtils.isBlank(taxAgentName)) {
// //个税扣缴义务人不能为空
// Map<String, String> errorMessageMap = Maps.newHashMap();
// errorMessageMap.put("message", rowIndex + "个税扣缴义务人不能为空");
// errorData.add(errorMessageMap);
// errorSum += 1;
// } else {
// Optional<TaxAgent> optionalTemp = taxAgents.stream().filter(m -> m.getName().equals(taxAgentName)).findFirst();
// if (optionalTemp.isPresent()) {
// po.setTaxAgentId(optionalTemp.get().getId());
// } else {
// //个税扣缴义务人不存在
// Map<String, String> errorMessageMap = Maps.newHashMap();
// errorMessageMap.put("message", rowIndex + "个税扣缴义务人不存在");
// errorData.add(errorMessageMap);
// errorSum += 1;
// }
// }
//
//// //todo 数字验证
//// if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86712, "累计收入额"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// dto.getAddUpChildEducation()
//// po.setAddUpIncome(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86711, "累计减除费用"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpSubtraction(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86710, "累计社保个人合计"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpSocialSecurityTotal(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86709, "累计公积金个人合计"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpAccumulationFundTotal(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86321, "累计子女教育"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpChildEducation(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86323, "累计继续教育"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpContinuingEducation(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86324, "累计住房贷款利息"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpHousingLoanInterest(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86325, "累计住房租金"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpHousingRent(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86326, "累计赡养老人"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpSupportElderly(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 90567, "累计企业(职业)年金及其他福利"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpEnterpriseAndOther(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 90569, "累计其他扣除"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpOtherDeduction(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86704, "累计免税收入"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpTaxExemptIncome(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86703, "累计准予扣除的捐赠额"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpAllowedDonation(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// } else if (key.toString().equals(SalaryI18nUtil.getI18nLabel(tenantKey, currentEmployeeId, 86702, "累计已预扣预缴税额"))) {
//// if (StringUtils.isNotEmpty(cellVal)) {
//// bigDecimalValue = bigDecimalVal(cellVal, excelComments, valI18n, errorCount+1, j);
//// po.setAddUpAdvanceTax(bigDecimalValue);
//// errorSum += StringUtils.isEmpty(bigDecimalValue)?1:0;
//// }
//// }
// //累计子女教育
// String addUpChildEducation = dto.getAddUpChildEducation();
// po.setAddUpChildEducation(Util.null2String(addUpChildEducation));
// //累计继续教育
// String addUpContinuingEducation = dto.getAddUpContinuingEducation();
// po.setAddUpContinuingEducation(Util.null2String(addUpContinuingEducation));
// //累计住房贷款利息
// String addUpHousingLoanInterest = dto.getAddUpHousingLoanInterest();
// po.setAddUpHousingLoanInterest(Util.null2String(addUpHousingLoanInterest));
// //累计住房租金
// String addUpHousingRent = dto.getAddUpHousingRent();
// po.setAddUpHousingRent(Util.null2String(addUpHousingRent));
// //累计赡养老人
// String addUpSupportElderly = dto.getAddUpSupportElderly();
// po.setAddUpSupportElderly(Util.null2String(addUpSupportElderly));
//
//
// if (errorSum == 0) {
// successCount += 1;
// // 合格数据
// eligibleData.add(po);
// } else {
// errorCount += 1;
// // 添加错误数据
// }
// }
//
// //入库
//// addUpDeductionBiz.handleImportData(eligibleData);
//
// apidatas.put("successCount", successCount);
// apidatas.put("errorCount", errorCount);
// apidatas.put("errorData", errorData);
//
// } finally {
// IOUtils.closeQuietly(fileInputStream);
// }
// return apidatas;
// }
//
// private void checkImportParam() {
//
// AddUpSituationImportParam importParam = (AddUpSituationImportParam) params.get("importParam");
//
// //excel文件id
// String imageId = Util.null2String(importParam.getImageId());
// //税款所属期
// String declareMonthStr = Util.null2String(importParam.getTaxYearMonth());
//
//
// if (StringUtils.isBlank(imageId)) {
// throw new SalaryRunTimeException("文件不存在");
// }
// if (StringUtils.isBlank(declareMonthStr)) {
// throw new SalaryRunTimeException("税款所属期为空");
// }
// }
//
//
//}