From b028ad6845fd0b658a16487218dcd68ecf6773eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E6=B6=9B?= <15850646081@163.com> Date: Thu, 3 Mar 2022 14:52:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8E=E7=8E=87=E4=BF=AE=E6=94=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/engine/salary/biz/TaxRateBiz.java | 26 +-- .../AddUpDeductionExportCmd.java | 31 +++ .../ExportDeclareRecordsProcess.java | 182 +++++++++++++++++- .../salary/web/AddUpDeductionController.java | 54 ++++-- 4 files changed, 258 insertions(+), 35 deletions(-) create mode 100644 src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java diff --git a/src/com/engine/salary/biz/TaxRateBiz.java b/src/com/engine/salary/biz/TaxRateBiz.java index e1f3eb817..fc53325b6 100644 --- a/src/com/engine/salary/biz/TaxRateBiz.java +++ b/src/com/engine/salary/biz/TaxRateBiz.java @@ -243,8 +243,8 @@ public class TaxRateBiz extends BaseBean { TaxRateDetailMapper taxRateDetailMapper = sqlSession.getMapper(TaxRateDetailMapper.class); // 查询是否存在指定的个税税率表 - TaxRateBase TaxRateBase = getById(updateParam.getTaxRateBatch().getId()); - if (Objects.isNull(TaxRateBase)) { + TaxRateBase taxRateBase = getById(updateParam.getTaxRateBatch().getId()); + if (Objects.isNull(taxRateBase)) { throw new SalaryRunTimeException("个税税率表不存在"); } // 个税税率表主表名称不允许重复 @@ -255,34 +255,34 @@ public class TaxRateBiz extends BaseBean { throw new SalaryRunTimeException("名称不允许重复"); } // 系统默认的个税税率表不允许编辑 - if (SalarySystemTypeEnum.parseByValue(TaxRateBase.getSystemType()) == SalarySystemTypeEnum.SYSTEM) { + if (SalarySystemTypeEnum.parseByValue(taxRateBase.getSystemType()) == SalarySystemTypeEnum.SYSTEM) { throw new SalaryRunTimeException("系统默认的个税税率表不允许编辑"); } // 更新个税税率表主表 TaxRateBase newTaxRateBase = new TaxRateBase(); - BeanUtils.copyProperties(TaxRateBase, newTaxRateBase); + BeanUtils.copyProperties(taxRateBase, newTaxRateBase); newTaxRateBase.setName(updateParam.getTaxRateBatch().getName()); newTaxRateBase.setDescription(updateParam.getTaxRateBatch().getDescription()); taxRateBaseMapper.updateIgnoreNull(newTaxRateBase); // 记录日志 // LoggerContext loggerContext = new LoggerContext<>(); -// loggerContext.setTargetId(String.valueOf(TaxRateBase.getId())); -// loggerContext.setTargetName(TaxRateBase.getName()); +// loggerContext.setTargetId(String.valueOf(taxRateBase.getId())); +// loggerContext.setTargetName(taxRateBase.getName()); // loggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); // loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(98108, "编辑个税税率表(基础信息)")); // loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(86124, "基础信息")); -// loggerContext.setOldValues(TaxRateBase); +// loggerContext.setOldValues(taxRateBase); // loggerContext.setNewValues(newTaxRateBase); // taxRateLoggerTemplate.write(loggerContext); // 更新个税税率表明细表-先删除后插入 - List taxRateDetailPOS = taxRateDetailMapper.listByBaseId(TaxRateBase.getId()); - taxRateDetailMapper.deleteByBatchIds(Collections.singleton(TaxRateBase.getId())); - List newTaxRateDetailPOS = TaxRateBO.convert2RecordPO(TaxRateBase.getId(), updateParam.getTaxRateRecords(), employeeId); - new TaxRateDetailBiz().saveBatch(taxRateDetailPOS); + List taxRateDetailPOS = taxRateDetailMapper.listByBaseId(taxRateBase.getId()); + taxRateDetailMapper.deleteByBatchIds(Collections.singleton(taxRateBase.getId())); + List newTaxRateDetailPOS = TaxRateBO.convert2RecordPO(taxRateBase.getId(), updateParam.getTaxRateRecords(), employeeId); + new TaxRateDetailBiz().saveBatch(newTaxRateDetailPOS); // 记录日志 // LoggerContext detailLoggerContext = new LoggerContext<>(); -// detailLoggerContext.setTargetId(String.valueOf(TaxRateBase.getId())); -// detailLoggerContext.setTargetName(TaxRateBase.getName()); +// detailLoggerContext.setTargetId(String.valueOf(taxRateBase.getId())); +// detailLoggerContext.setTargetName(taxRateBase.getName()); // detailLoggerContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); // detailLoggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(98128, "新增个税税率表(详细设置)")); // detailLoggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(96687, "详细设置")); diff --git a/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java b/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java new file mode 100644 index 000000000..7826a3e69 --- /dev/null +++ b/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java @@ -0,0 +1,31 @@ +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 weaver.hrm.User; + +import java.util.HashMap; +import java.util.Map; + +public class AddUpDeductionExportCmd extends AbstractCommonCommand> { + + public AddUpDeductionExportCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + Map apidatas = new HashMap(16); + + + + return apidatas; + } +} diff --git a/src/com/engine/salary/process/datacollection/ExportDeclareRecordsProcess.java b/src/com/engine/salary/process/datacollection/ExportDeclareRecordsProcess.java index 6c13c5522..25a640442 100644 --- a/src/com/engine/salary/process/datacollection/ExportDeclareRecordsProcess.java +++ b/src/com/engine/salary/process/datacollection/ExportDeclareRecordsProcess.java @@ -5,11 +5,12 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.engine.personalIncomeTax.biz.RecordsBiz; import com.engine.personalIncomeTax.enums.FormTypeEnum; -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.hssf.usermodel.*; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.FillPatternType; +import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.apache.poi.ss.usermodel.IndexedColors; import weaver.general.BaseBean; import weaver.general.GCONST; import weaver.general.Util; @@ -748,4 +749,177 @@ public class ExportDeclareRecordsProcess extends BaseBean { } return true; } + + + + + /** + * 解析操作按钮excel时sheet下标 + */ + private static final int OPERATOR_PARSE_EXCEL_SHEET_INDEX = 0; + + /** + * 解析操作按钮excel时开始行 + */ + private static final int OPERATOR_PARSE_EXCEL_BEGIN_ROW_INDEX = 1; + + /** + * 解析操作按钮excel时应有多少列 + */ + private static final int OPERATOR_PARSE_EXCEL_VALID_CELL_NUM = 5; + +// @Override +// public void importOperator(MultipartFile file, String tenantCode, String systemId) { +// +// //验证导入参数 +// if (file == null) { +// throw new OPERBIZException(OperatorExceptionCode.IMPORT_FILE_IS_EMPTY); +// } +// validOperator(tenantCode, systemId); +// +// //解析文件获取元素集合 +// List operatorList = ExcelParseHelper.parse(file, OperatorBaseDto.class, +// OPERATOR_PARSE_EXCEL_SHEET_INDEX, OPERATOR_PARSE_EXCEL_BEGIN_ROW_INDEX, OPERATOR_PARSE_EXCEL_VALID_CELL_NUM); +// //操作人 +// final String userId = JWTUtil.getUserId(); +// //当前时间 +// final long currentTime = new Date().getTime(); +// //操作集合 +// final List list = operatorList.stream() +// .peek(operator -> {//初始化值 +// operator.setTenantCode(tenantCode); +// operator.setSystemId(systemId); +// operator.setUseStatus(NORMAL_STATUS); +// operator.setCreateUser(userId); +// operator.setCreateTime(currentTime); +// operator.setUpdateUser(userId); +// operator.setUpdateTime(currentTime); +// }) +// .filter(operator -> StringUtils.isNoneBlank(operator.getOperatorFlag(), operator.getOperatorName(), operator.getIcon())) //过滤不合法元素 +// .collect(Collectors +// .collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(OperatorBaseDto::getOperatorFlag))), +// ArrayList::new)); +// +// //将操作按新增或更新分类 +// final Pair, List> operatorListPair = classifyOperator(tenantCode, systemId, list); +// final List addlist = operatorListPair.getLeft(); +// final List updateList = operatorListPair.getRight(); +// +// //批量新增 +// operatorDalService.batchAdd(this.convertListFromSource(addlist)); +// +// //逐条更新 +// updateList.forEach(operatorBaseDto -> operatorDalService.updateByFlag(this.convertBeanFromSource(operatorBaseDto))); +// } + + + + /** + * excel标题 + */ +// private final static List title = Arrays.asList("Operation identification", "Operation name", "Icon", "Sort number", "custom"); +// +// public HSSFWorkbook exportOperator(String tenantCode, String systemId) { +// +// +// +// //获取操作按钮资源 +//// List> rowList = getExcelRowList(tenantCode, systemId); +// +// //获取excel +// return getWorkbook(rowList); +// } + + /** + * 获取excel + * + * @param rowList 行列表 + * @return workbook + */ + private HSSFWorkbook getWorkbook(List> rowList) { + HSSFWorkbook workbook = new HSSFWorkbook(); + + // 设置title样式 + HSSFCellStyle titleCellStyle = workbook.createCellStyle(); + HSSFFont titleFont = workbook.createFont(); + titleFont.setFontName("仿宋"); + titleFont.setFontHeightInPoints((short) 15); + titleCellStyle.setFont(titleFont); + titleCellStyle.setAlignment(HorizontalAlignment.CENTER); + titleCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());//背景色 + titleCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + + + // 设置主体样式 + HSSFCellStyle cellStyle = workbook.createCellStyle(); + HSSFFont font = workbook.createFont(); + font.setFontName("宋体"); + font.setFontHeightInPoints((short) 10);// 设置字体大小 + cellStyle.setFont(font);// 选择需要用到的字体格式 + cellStyle.setWrapText(true); + + HSSFSheet sheet = workbook.createSheet("0"); + for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) { + List infoList = rowList.get(rowIndex); + HSSFRow row = sheet.createRow(rowIndex); + for (int cellIndex = 0; cellIndex < infoList.size(); cellIndex++) { + HSSFCell cell = row.createCell(cellIndex); + cell.setCellType(CellType.STRING); + if (rowIndex == 0) { + cell.setCellStyle(titleCellStyle); + } else { + cell.setCellStyle(cellStyle); + } + cell.setCellValue(infoList.get(cellIndex)); + sheet.setColumnWidth(cellIndex, 35 * 256); + } + } + return workbook; + } + + /** + * 获取excel数据行 + * + * @param tenantCode 租户 + * @param systemId 系统id + * @return 导出数据行集合 + */ +// private List> getExcelRowList(String tenantCode, String systemId) { +// final List operatorBaseDoList = operatorDalService.selectOperatorListInOneSystem(tenantCode, systemId, null); +// final List> dataRowList = Optional.ofNullable(operatorBaseDoList) +// .map(List::stream) +// .map(operatorStream -> operatorStream.map(operatorBaseDo -> { +// List cellList = new ArrayList<>(); +// cellList.add(operatorBaseDo.getOperatorFlag()); +// cellList.add(operatorBaseDo.getOperatorName()); +// cellList.add(operatorBaseDo.getIcon()); +// cellList.add(operatorBaseDo.getSort() == null ? "" : operatorBaseDo.getSort().toString()); +// cellList.add(operatorBaseDo.getCustom()); +// return cellList; +// }).collect(Collectors.toList())) +// .orElse(Collections.emptyList()); +// +// List> rowList = new ArrayList<>(); +// rowList.add(title); +// rowList.addAll(dataRowList); +// return rowList; +// } + + + + + + + + + + + + + + + + + + } diff --git a/src/com/engine/salary/web/AddUpDeductionController.java b/src/com/engine/salary/web/AddUpDeductionController.java index c6b9b06ce..b4e76ac9a 100644 --- a/src/com/engine/salary/web/AddUpDeductionController.java +++ b/src/com/engine/salary/web/AddUpDeductionController.java @@ -7,16 +7,19 @@ import com.engine.salary.service.AddUpDeductionService; import com.engine.salary.service.impl.AddUpDeductionServiceImpl; import com.engine.salary.util.ResponseResult; import io.swagger.v3.oas.annotations.parameters.RequestBody; +import weaver.general.GCONST; 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.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Map; public class AddUpDeductionController { @@ -36,24 +39,39 @@ public class AddUpDeductionController { } + @GET + @Path("/downloadTemplate") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response getAll() { + + //模板文件路径 + String templateFilePath = GCONST.getRootPath() + "hrm/resource/inputexcellfile/taxDeclareTemplate.xls"; + + File file = new File(templateFilePath); + + if (!file.exists()) { + return Response.status(Response.Status.NOT_FOUND).build(); + } + String fileName = null; + try { + fileName = URLEncoder.encode("累计专项附加扣除导入模板.xlsx", "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return Response + .ok(file) + .header("Content-disposition", "attachment;filename=" + fileName) + .header("Cache-Control", "no-cache").build(); + } + + + + // /** -// * 下载导入模板 +// * 导出 +// * @param queryParam // * @return // */ -// @POST() -// @Path("/downloadTemplate") -// @ApiOperation("下载导入模板") -// @WeaPermission -// public WeaResult> downloadTemplate(@RequestBody AddUpDeductionQueryParam queryParam) { -// return WeaResult.success(service.downloadTemplate(queryParam, UserContext.getCurrentEmployeeId(), TenantContext.getCurrentTenantKey())); -// } - - - /** - * 导出 - * @param queryParam - * @return - */ // @POST // @Path("/export") // @Produces(MediaType.APPLICATION_JSON)