package com.engine.salary.service.impl; import com.engine.core.impl.Service; import com.engine.salary.biz.EmployBiz; import com.engine.salary.biz.OtherDeductionBiz; import com.engine.salary.cmd.datacollection.*; import com.engine.salary.entity.datacollection.DataCollectionEmployee; import com.engine.salary.entity.datacollection.dto.OtherDeductionListDTO; import com.engine.salary.entity.datacollection.param.OtherDeductionQueryParam; import com.engine.salary.entity.datacollection.po.OtherDeductionPO; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.mapper.datacollection.OtherDeductionMapper; import com.engine.salary.service.OtherDeductionService; import com.engine.salary.util.SalaryDateUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.engine.salary.util.excel.ExcelComment; import com.engine.salary.util.excel.ExcelUtil; import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.general.Util; import java.time.YearMonth; import java.util.*; import java.util.stream.Collectors; public class OtherDeductionServiceImpl extends Service implements OtherDeductionService { private OtherDeductionMapper getOtherDeductionMapper() { return MapperProxyFactory.getProxy(OtherDeductionMapper.class); } @Override public Map getSearchCondition(Map params) { return commandExecutor.execute(new OtherDeductionGetSearchConditionCmd(params, user)); } @Override public Map list(Map params) { return commandExecutor.execute(new OtherDeductionListCmd(params, user)); } @Override public Map preview(Map params) { return commandExecutor.execute(new OtherDeductionPreviewCmd(params, user)); } @Override public Map importData(Map params) { return commandExecutor.execute(new OtherDeductionImportCmd(params, user)); } @Override public XSSFWorkbook export(Map params) { OtherDeductionQueryParam OtherDeductionQueryParam = (OtherDeductionQueryParam) params.get("queryParam"); OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz(); XSSFWorkbook workbook = OtherDeductionBiz.export(OtherDeductionQueryParam); return workbook; // return commandExecutor.execute(new OtherDeductionExportCmd(params, user)); } @Override public XSSFWorkbook exportDetail(Map params) { OtherDeductionQueryParam queryParam = (OtherDeductionQueryParam) params.get("queryParam"); OtherDeductionBiz biz = new OtherDeductionBiz(); EmployBiz employBiz = new EmployBiz(); Long id = queryParam.getOtherTaxExemptDeductionId(); if (id == null) { throw new SalaryRunTimeException("id不能为空"); } OtherDeductionPO po = biz.getById(id); if (po == null) { throw new SalaryRunTimeException(String.format("其他免税扣除不存在"+"[id:%s]", id)); } List employeeList = employBiz.getEmployeeByIds(Collections.singletonList(po.getEmployeeId())); if (CollectionUtils.isEmpty(employeeList)) { throw new SalaryRunTimeException("员工信息不存在"); } //构建参数 queryParam.setEmployeeId(po.getEmployeeId()); //申报月份 List declareMonth = queryParam.getDeclareMonth(); if (CollectionUtils.isNotEmpty(declareMonth)) { queryParam.setDeclareMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList())); } return biz.exportDetail(queryParam); // return commandExecutor.execute(new OtherDeductionExportDetailCmd(params, user)); } @Override public Map getDetailList(Map params) { return commandExecutor.execute(new OtherDeductionGetDetailListCmd(params, user)); } @Override public List getOtherDeductionList(YearMonth declareMonth, List employeeIds) { if (declareMonth == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100342, "参数有误:申报月份必传")); } OtherDeductionBiz OtherDeductionBiz = new OtherDeductionBiz(); return OtherDeductionBiz.listSome(OtherDeductionPO.builder().declareMonth(SalaryDateUtil.toDateStartOfMonth(declareMonth)).employeeIds(employeeIds).build()); } @Override public XSSFWorkbook downloadTemplate(OtherDeductionQueryParam param) { // 1.工作簿名称 String sheetName = SalaryI18nUtil.getI18nLabel( 101604, "其他免税扣除导入模板"); String[] header = { SalaryI18nUtil.getI18nLabel( 85429, "姓名"), SalaryI18nUtil.getI18nLabel( 86184, "个税扣缴义务人"), SalaryI18nUtil.getI18nLabel( 86185, "部门"), SalaryI18nUtil.getI18nLabel( 86186, "手机号"), SalaryI18nUtil.getI18nLabel( 86317, "工号"), SalaryI18nUtil.getI18nLabel( 86318, "证件号码"), SalaryI18nUtil.getI18nLabel( 86319, "入职日期"), SalaryI18nUtil.getI18nLabel( 91238, "商业健康保险"), SalaryI18nUtil.getI18nLabel( 91239, "税延养老保险"), SalaryI18nUtil.getI18nLabel( 84500, "其他"), SalaryI18nUtil.getI18nLabel( 91240, "准予扣除的捐赠额") }; // 2.表头 List headerList = Arrays.asList(header); // 获取其他免税扣除 List list = getOtherDeductionMapper().list(param); // 人员信息赋值 list.stream().map(m->{ // todo 身份证号 m.setIdNo(""); return m; }).collect(Collectors.toList()); List> rows = new ArrayList<>(); rows.add(headerList); for (OtherDeductionListDTO dto : list) { List row = new ArrayList<>(); row.add(Util.null2String(dto.getUsername())); row.add(Util.null2String(dto.getTaxAgentName())); row.add(Util.null2String(dto.getDepartmentName())); row.add(Util.null2String(dto.getMobile())); row.add(Util.null2String(dto.getJobNum())); row.add(Util.null2String(dto.getIdNo())); row.add(Util.null2String(dto.getHiredate())); row.add(Util.null2String(dto.getBusinessHealthyInsurance())); row.add(Util.null2String(dto.getTaxDelayEndowmentInsurance())); row.add(Util.null2String(dto.getOtherDeduction())); row.add(Util.null2String(dto.getDeductionAllowedDonation())); rows.add(row); } // 3.表数据 // 4.注释 List excelComments = Lists.newArrayList(); excelComments.add(new ExcelComment(0, 0, 3, 2, SalaryI18nUtil.getI18nLabel(100344, "必填"))); excelComments.add(new ExcelComment(1, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填"))); excelComments.add(new ExcelComment(7, 0, 10, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字"))); excelComments.add(new ExcelComment(8, 0, 11, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字"))); excelComments.add(new ExcelComment(9, 0, 12, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字"))); excelComments.add(new ExcelComment(10, 0, 13, 2, SalaryI18nUtil.getI18nLabel(100344, "输入数字"))); XSSFWorkbook book = ExcelUtil.genWorkbookV2(rows, sheetName, excelComments); return book; } }