diff --git a/src/com/engine/salary/biz/AddUpDeductionBiz.java b/src/com/engine/salary/biz/AddUpDeductionBiz.java index e5894f833..5276aa94e 100644 --- a/src/com/engine/salary/biz/AddUpDeductionBiz.java +++ b/src/com/engine/salary/biz/AddUpDeductionBiz.java @@ -6,13 +6,10 @@ import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO; import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO; import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam; import com.engine.salary.mapper.datacollection.AddUpDeductionMapper; +import com.engine.salary.util.excel.ExcelUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.ibatis.session.SqlSession; -import org.apache.poi.hssf.usermodel.*; -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 org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.conn.mybatis.MyBatisFactory; import weaver.general.BaseBean; import weaver.general.Util; @@ -60,6 +57,7 @@ public class AddUpDeductionBiz extends BaseBean { /** * 根据id获取 + * * @param id * @return */ @@ -75,10 +73,11 @@ public class AddUpDeductionBiz extends BaseBean { /** * 详情列表 + * * @param param * @return */ - public List recordList(AddUpDeductionQueryParam param){ + public List recordList(AddUpDeductionQueryParam param) { SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); try { AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class); @@ -99,7 +98,7 @@ public class AddUpDeductionBiz extends BaseBean { try { AddUpDeductionMapper mapper = sqlSession.getMapper(AddUpDeductionMapper.class); mapper.insertData(param); - sqlSession.commit(); + sqlSession.commit(); } finally { sqlSession.close(); } @@ -139,71 +138,22 @@ public class AddUpDeductionBiz extends BaseBean { } - /** - * excel标题 - */ - private final static List title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人"); - /** * 导出 * * @param param * @return */ - public HSSFWorkbook export(AddUpDeductionQueryParam param) { + public XSSFWorkbook export(AddUpDeductionQueryParam param) { + + //excel标题 + List title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人"); //获取操作按钮资源 - List> rowList = getExcelRowList(param); + List> rowList = getExcelRowList(title, param); //获取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; + return ExcelUtil.genWorkbook(rowList); } @@ -212,7 +162,7 @@ public class AddUpDeductionBiz extends BaseBean { * * @return 导出数据行集合 */ - private List> getExcelRowList(AddUpDeductionQueryParam param) { + private List> getExcelRowList(List title, AddUpDeductionQueryParam param) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); List list = list(param); final List> dataRowList = Optional.ofNullable(list) @@ -241,6 +191,67 @@ public class AddUpDeductionBiz extends BaseBean { return rowList; } + + /** + * 导出详情列表 + * + * @param param + * @return + */ + public XSSFWorkbook exportDetail(AddUpDeductionQueryParam param) { + + //获取操作按钮资源 + List> rowList = getExcelRowDetailList(param); + + //获取excel + return ExcelUtil.genWorkbook(rowList); + } + + + /** + * 导出详情 + * + * @param param + * @return + */ + private List> getExcelRowDetailList(AddUpDeductionQueryParam param) { + + //excel标题 + List title = Arrays.asList("姓名", "申报月份", "个税扣缴义务人", "部门", "工号", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人"); + + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); + //查询详细信息 + List list = recordList(param); + final List> dataRowList = Optional.ofNullable(list) + .map(List::stream) + .map(operatorStream -> operatorStream.map(dto -> { + List cellList = new ArrayList<>(); + cellList.add(Util.null2String(dto.getUsername())); + cellList.add(Util.null2String(dto.getDeclareMonth() == null ? "" : formatter.format(dto.getDeclareMonth()))); + cellList.add(Util.null2String(dto.getTaxAgentName())); + cellList.add(Util.null2String(dto.getDepartmentName())); + cellList.add(Util.null2String(dto.getJobNum())); + cellList.add(String.valueOf(dto.getAddUpChildEducation())); + cellList.add(String.valueOf(dto.getAddUpContinuingEducation())); + cellList.add(String.valueOf(dto.getAddUpHousingLoanInterest())); + cellList.add(String.valueOf(dto.getAddUpHousingRent())); + cellList.add(String.valueOf(dto.getAddUpSupportElderly())); + return cellList; + }).collect(Collectors.toList())) + .orElse(Collections.emptyList()); + + List> rowList = new ArrayList<>(); + rowList.add(title); + rowList.addAll(dataRowList); + return rowList; + } + + /** + * 处理导入数据 + * + * @param pos + */ public void handleImportData(List pos) { if (CollectionUtils.isEmpty(pos)) { return; diff --git a/src/com/engine/salary/biz/AddUpSituationBiz.java b/src/com/engine/salary/biz/AddUpSituationBiz.java index d00671659..85ada43a7 100644 --- a/src/com/engine/salary/biz/AddUpSituationBiz.java +++ b/src/com/engine/salary/biz/AddUpSituationBiz.java @@ -5,13 +5,10 @@ import com.engine.salary.entity.datacollection.dto.AddUpSituationDTO; import com.engine.salary.entity.datacollection.dto.AddUpSituationRecordDTO; import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam; import com.engine.salary.mapper.datacollection.AddUpSituationMapper; +import com.engine.salary.util.excel.ExcelUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.ibatis.session.SqlSession; -import org.apache.poi.hssf.usermodel.*; -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 org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.conn.mybatis.MyBatisFactory; import weaver.general.BaseBean; import weaver.general.Util; @@ -124,71 +121,19 @@ public class AddUpSituationBiz extends BaseBean { } - /** - * excel标题 - */ - private final static List title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计收入额", "累计减除费用", "累计社保个人合计", "累计公积金个人合计", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人", "累计企业(职业)年金及其他福利", "累计其他扣除", "累计免税收入", "累计准予扣除的捐赠额", "累计已预扣预缴税额"); - /** * 导出 * * @param param * @return */ - public HSSFWorkbook export(AddUpSituationQueryParam param) { + public XSSFWorkbook export(AddUpSituationQueryParam param) { //获取操作按钮资源 List> rowList = getExcelRowList(param); //获取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; + return ExcelUtil.genWorkbook(rowList); } @@ -198,6 +143,9 @@ public class AddUpSituationBiz extends BaseBean { * @return 导出数据行集合 */ private List> getExcelRowList(AddUpSituationQueryParam param) { + // excel标题 + final List title = Arrays.asList("姓名", "个税扣缴义务人", "部门", "手机号", "工号", "证件号码", "入职日期", "累计收入额", "累计减除费用", "累计社保个人合计", "累计公积金个人合计", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人", "累计企业(职业)年金及其他福利", "累计其他扣除", "累计免税收入", "累计准予扣除的捐赠额", "累计已预扣预缴税额"); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); List list = list(param); final List> dataRowList = Optional.ofNullable(list) @@ -235,6 +183,61 @@ public class AddUpSituationBiz extends BaseBean { return rowList; } + + /** + * 导出详情列表 + * + * @param param + * @return + */ + public XSSFWorkbook exportDetail(AddUpSituationQueryParam param) { + + //获取操作按钮资源 + List> rowList = getExcelRowDetailList(param); + + //获取excel + return ExcelUtil.genWorkbook(rowList); + } + + + /** + * 导出详情 + * + * @param param + * @return + */ + private List> getExcelRowDetailList(AddUpSituationQueryParam param) { + + //excel标题 + List title = Arrays.asList("税款所属期", "个税扣缴义务人", "部门", "工号", "累计子女教育", "累计继续教育", "累计住房贷款利息", "累计住房租金", "累计赡养老人"); + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); + //查询详细信息 + List list = recordList(param); + final List> dataRowList = Optional.ofNullable(list) + .map(List::stream) + .map(operatorStream -> operatorStream.map(dto -> { + List cellList = new ArrayList<>(); + cellList.add(Util.null2String(dto.getTaxYearMonth() == null ? "" : formatter.format(dto.getTaxYearMonth()))); + cellList.add(Util.null2String(dto.getTaxAgentName())); + cellList.add(Util.null2String(dto.getDepartmentName())); + cellList.add(Util.null2String(dto.getJobNum())); + cellList.add(String.valueOf(dto.getAddUpChildEducation())); + cellList.add(String.valueOf(dto.getAddUpContinuingEducation())); + cellList.add(String.valueOf(dto.getAddUpHousingLoanInterest())); + cellList.add(String.valueOf(dto.getAddUpHousingRent())); + cellList.add(String.valueOf(dto.getAddUpSupportElderly())); + return cellList; + }).collect(Collectors.toList())) + .orElse(Collections.emptyList()); + + List> rowList = new ArrayList<>(); + rowList.add(title); + rowList.addAll(dataRowList); + return rowList; + } + + public void handleImportData(List pos) { if (CollectionUtils.isEmpty(pos)) { return; diff --git a/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java b/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java index 7825ad2fd..8db98484f 100644 --- a/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java +++ b/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportCmd.java @@ -5,12 +5,12 @@ import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; import com.engine.salary.biz.AddUpDeductionBiz; import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.hrm.User; import java.util.Map; -public class AddUpDeductionExportCmd extends AbstractCommonCommand { +public class AddUpDeductionExportCmd extends AbstractCommonCommand { public AddUpDeductionExportCmd(Map params, User user) { this.user = user; @@ -23,11 +23,11 @@ public class AddUpDeductionExportCmd extends AbstractCommonCommand } @Override - public HSSFWorkbook execute(CommandContext commandContext) { + public XSSFWorkbook execute(CommandContext commandContext) { AddUpDeductionQueryParam addUpDeductionQueryParam = (AddUpDeductionQueryParam) params.get("addUpDeductionQueryParam"); AddUpDeductionBiz addUpDeductionBiz = new AddUpDeductionBiz(); - HSSFWorkbook workbook = addUpDeductionBiz.export(addUpDeductionQueryParam); + XSSFWorkbook workbook = addUpDeductionBiz.export(addUpDeductionQueryParam); return workbook; } diff --git a/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportDetailCmd.java b/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportDetailCmd.java new file mode 100644 index 000000000..04fe6dbdb --- /dev/null +++ b/src/com/engine/salary/cmd/datacollection/AddUpDeductionExportDetailCmd.java @@ -0,0 +1,46 @@ +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.AddUpDeductionBiz; +import com.engine.salary.entity.datacollection.AddUpDeduction; +import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam; +import com.engine.salary.exception.SalaryRunTimeException; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import weaver.hrm.User; + +import java.util.Map; + +public class AddUpDeductionExportDetailCmd extends AbstractCommonCommand { + + public AddUpDeductionExportDetailCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public XSSFWorkbook execute(CommandContext commandContext) { + AddUpDeductionQueryParam queryParam = (AddUpDeductionQueryParam) params.get("addUpDeductionQueryParam"); + AddUpDeductionBiz biz = new AddUpDeductionBiz(); + + Long id = queryParam.getAccumulatedSpecialAdditionalDeductionId(); + if (id == null) { + throw new SalaryRunTimeException("id不能为空"); + } + + AddUpDeduction po = biz.getById(id); + if (po == null) { + throw new SalaryRunTimeException(String.format("累计专项附加扣除不存在"+"[id:%s]", id)); + } + + XSSFWorkbook workbook = biz.exportDetail(queryParam); + + return workbook; + } +} diff --git a/src/com/engine/salary/cmd/datacollection/AddUpSituationExportCmd.java b/src/com/engine/salary/cmd/datacollection/AddUpSituationExportCmd.java index e4defac8b..f302c424f 100644 --- a/src/com/engine/salary/cmd/datacollection/AddUpSituationExportCmd.java +++ b/src/com/engine/salary/cmd/datacollection/AddUpSituationExportCmd.java @@ -5,12 +5,12 @@ import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; import com.engine.salary.biz.AddUpSituationBiz; import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.hrm.User; import java.util.Map; -public class AddUpSituationExportCmd extends AbstractCommonCommand { +public class AddUpSituationExportCmd extends AbstractCommonCommand { public AddUpSituationExportCmd(Map params, User user) { this.user = user; @@ -23,10 +23,10 @@ public class AddUpSituationExportCmd extends AbstractCommonCommand } @Override - public HSSFWorkbook execute(CommandContext commandContext) { + public XSSFWorkbook execute(CommandContext commandContext) { AddUpSituationQueryParam queryParam = (AddUpSituationQueryParam) params.get("queryParam"); AddUpSituationBiz biz = new AddUpSituationBiz(); - HSSFWorkbook workbook = biz.export(queryParam); + XSSFWorkbook workbook = biz.export(queryParam); return workbook; } } diff --git a/src/com/engine/salary/cmd/datacollection/AddUpSituationExportDetailCmd.java b/src/com/engine/salary/cmd/datacollection/AddUpSituationExportDetailCmd.java new file mode 100644 index 000000000..5a3bca6fe --- /dev/null +++ b/src/com/engine/salary/cmd/datacollection/AddUpSituationExportDetailCmd.java @@ -0,0 +1,46 @@ +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.entity.datacollection.AddUpSituation; +import com.engine.salary.entity.datacollection.param.AddUpSituationQueryParam; +import com.engine.salary.exception.SalaryRunTimeException; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import weaver.hrm.User; + +import java.util.Map; + +public class AddUpSituationExportDetailCmd extends AbstractCommonCommand { + + public AddUpSituationExportDetailCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public XSSFWorkbook execute(CommandContext commandContext) { + AddUpSituationQueryParam queryParam = (AddUpSituationQueryParam) params.get("queryParam"); + AddUpSituationBiz biz = new AddUpSituationBiz(); + + + Long id = queryParam.getAccumulatedSituationId(); + if (id == null) { + throw new SalaryRunTimeException("id不能为空"); + } + + AddUpSituation po = biz.getById(id); + if (po == null) { + throw new SalaryRunTimeException(String.format("累计情况不存在"+"[id:%s]", id)); + } + + XSSFWorkbook workbook = biz.exportDetail(queryParam); + return workbook; + } +} diff --git a/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml b/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml index 35858ef01..d67797bcc 100644 --- a/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml +++ b/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml @@ -288,7 +288,7 @@ , t1.declare_month, t1.employee_id, - e.lastname as usename, + e.lastname as username, d.departmentname AS departmentName, e.mobile, e.workcode as job_num, diff --git a/src/com/engine/salary/mapper/datacollection/AddUpSituationMapper.xml b/src/com/engine/salary/mapper/datacollection/AddUpSituationMapper.xml index bf4b0c1f0..4697648b4 100644 --- a/src/com/engine/salary/mapper/datacollection/AddUpSituationMapper.xml +++ b/src/com/engine/salary/mapper/datacollection/AddUpSituationMapper.xml @@ -620,7 +620,7 @@ (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation GROUP BY employee_id) t ON t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month LEFT JOIN hrmresource e ON e.id = t1.employee_id - LEFT JOIN hrmdepartment d ON d.id = e.department + LEFT JOIN hrmdepartment d ON d.id = e.departmentid LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id WHERE t1.delete_type = 0 @@ -639,7 +639,7 @@ (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation GROUP BY employee_id) t ON t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month LEFT JOIN hrmresource e ON e.id = t1.employee_id - LEFT JOIN hrmdepartment d ON d.id = e.department + LEFT JOIN hrmdepartment d ON d.id = e.departmentid LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id WHERE t1.delete_type = 0 @@ -658,7 +658,7 @@ (SELECT employee_id, MAX(tax_year_month) tax_year_month FROM hrsa_add_up_situation GROUP BY employee_id) t ON t.employee_id = t1.employee_id AND t.tax_year_month = t1.tax_year_month LEFT JOIN hrmresource e ON e.id = t1.employee_id - LEFT JOIN hrmdepartment d ON d.id = e.department + LEFT JOIN hrmdepartment d ON d.id = e.departmentid LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id WHERE t1.delete_type = 0 @@ -675,7 +675,7 @@ FROM hrsa_add_up_situation t1 LEFT JOIN hrmresource e ON e.id = t1.employee_id - LEFT JOIN hrmdepartment d ON d.id = e.department + LEFT JOIN hrmdepartment d ON d.id = e.departmentid LEFT JOIN hrsa_tax_agent t2 ON t1.tax_agent_id = t2.id WHERE t1.delete_type = 0 diff --git a/src/com/engine/salary/service/AddUpDeductionService.java b/src/com/engine/salary/service/AddUpDeductionService.java index 762e1eeac..734095142 100644 --- a/src/com/engine/salary/service/AddUpDeductionService.java +++ b/src/com/engine/salary/service/AddUpDeductionService.java @@ -1,6 +1,6 @@ package com.engine.salary.service; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.Map; @@ -8,7 +8,7 @@ public interface AddUpDeductionService { Map list(Map params); - HSSFWorkbook export(Map params); + XSSFWorkbook export(Map params); Map getSearchCondition(Map params); @@ -17,4 +17,6 @@ public interface AddUpDeductionService { Map getDetailList(Map params); Map preview(Map params); + + XSSFWorkbook exportDetail(Map map); } diff --git a/src/com/engine/salary/service/AddUpSituationService.java b/src/com/engine/salary/service/AddUpSituationService.java index 44e23fb07..1f1755612 100644 --- a/src/com/engine/salary/service/AddUpSituationService.java +++ b/src/com/engine/salary/service/AddUpSituationService.java @@ -1,6 +1,6 @@ package com.engine.salary.service; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.Map; @@ -8,9 +8,11 @@ public interface AddUpSituationService { Map list(Map params); - HSSFWorkbook export(Map params); + XSSFWorkbook export(Map params); Map getSearchCondition(Map params); Map importAddUpSituation(Map params); + + XSSFWorkbook exportDetail(Map params); } diff --git a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java index 204a4fcb1..571c25c54 100644 --- a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java +++ b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java @@ -3,7 +3,7 @@ package com.engine.salary.service.impl; import com.engine.core.impl.Service; import com.engine.salary.cmd.datacollection.*; import com.engine.salary.service.AddUpDeductionService; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.Map; @@ -15,7 +15,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction } @Override - public HSSFWorkbook export(Map params) { + public XSSFWorkbook export(Map params) { return commandExecutor.execute(new AddUpDeductionExportCmd(params, user)); } @@ -38,4 +38,9 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction public Map preview(Map params) { return commandExecutor.execute(new AddUpDeductionPreviewCmd(params, user)); } + + @Override + public XSSFWorkbook exportDetail(Map params) { + return commandExecutor.execute(new AddUpDeductionExportDetailCmd(params, user)); + } } diff --git a/src/com/engine/salary/service/impl/AddUpSituationServiceImpl.java b/src/com/engine/salary/service/impl/AddUpSituationServiceImpl.java index 28786debd..f18c9436f 100644 --- a/src/com/engine/salary/service/impl/AddUpSituationServiceImpl.java +++ b/src/com/engine/salary/service/impl/AddUpSituationServiceImpl.java @@ -1,12 +1,9 @@ package com.engine.salary.service.impl; import com.engine.core.impl.Service; -import com.engine.salary.cmd.datacollection.AddUpSituationExportCmd; -import com.engine.salary.cmd.datacollection.AddUpSituationGetSearchConditionCmd; -import com.engine.salary.cmd.datacollection.AddUpSituationImportCmd; -import com.engine.salary.cmd.datacollection.AddUpSituationListCmd; +import com.engine.salary.cmd.datacollection.*; import com.engine.salary.service.AddUpSituationService; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.Map; @@ -18,7 +15,7 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation } @Override - public HSSFWorkbook export(Map params) { + public XSSFWorkbook export(Map params) { return commandExecutor.execute(new AddUpSituationExportCmd(params, user)); } @@ -31,4 +28,9 @@ public class AddUpSituationServiceImpl extends Service implements AddUpSituation public Map importAddUpSituation(Map params) { return commandExecutor.execute(new AddUpSituationImportCmd(params, user)); } + + @Override + public XSSFWorkbook exportDetail(Map params) { + return commandExecutor.execute(new AddUpSituationExportDetailCmd(params, user)); + } } diff --git a/src/com/engine/salary/util/excel/ExcelUtil.java b/src/com/engine/salary/util/excel/ExcelUtil.java new file mode 100644 index 000000000..a9e85256a --- /dev/null +++ b/src/com/engine/salary/util/excel/ExcelUtil.java @@ -0,0 +1,64 @@ +package com.engine.salary.util.excel; + +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 org.apache.poi.xssf.usermodel.*; + +import java.util.List; + +public class ExcelUtil { + /** + * 生成excel + * @param rowList + * @return + */ + public static XSSFWorkbook genWorkbook(List> rowList) { + XSSFWorkbook workbook = new XSSFWorkbook(); + + // 设置title样式 + XSSFCellStyle titleCellStyle = workbook.createCellStyle(); + XSSFFont 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); + + + // 设置主体样式 + XSSFCellStyle cellStyle = workbook.createCellStyle(); + XSSFFont font = workbook.createFont(); + font.setFontName("宋体"); + font.setFontHeightInPoints((short) 10);// 设置字体大小 + cellStyle.setFont(font);// 选择需要用到的字体格式 + cellStyle.setWrapText(true); + + XSSFSheet sheet = workbook.createSheet("累计专项附加扣除明细"); + //自适应宽度 + sheet.autoSizeColumn(0, true); + //默认列宽 + sheet.setDefaultColumnWidth(20); + //默认行高 + sheet.setDefaultRowHeightInPoints(18); + + for (int rowIndex = 0; rowIndex < rowList.size(); rowIndex++) { + List infoList = rowList.get(rowIndex); + XSSFRow row = sheet.createRow(rowIndex); + for (int cellIndex = 0; cellIndex < infoList.size(); cellIndex++) { + XSSFCell 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; + } +} diff --git a/src/com/engine/salary/web/AddUpDeductionController.java b/src/com/engine/salary/web/AddUpDeductionController.java index 663949e3f..e4f54c114 100644 --- a/src/com/engine/salary/web/AddUpDeductionController.java +++ b/src/com/engine/salary/web/AddUpDeductionController.java @@ -10,6 +10,7 @@ import com.engine.salary.util.ResponseResult; import io.swagger.v3.oas.annotations.parameters.RequestBody; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.jetbrains.annotations.Nullable; import weaver.general.GCONST; import weaver.hrm.HrmUserVarify; @@ -110,7 +111,7 @@ public class AddUpDeductionController { Map map = ParamUtil.request2Map(request); map.put("addUpDeductionQueryParam", param); - HSSFWorkbook workbook = getService(user).export(map); + XSSFWorkbook workbook = getService(user).export(map); String fileName = null; try { @@ -130,6 +131,38 @@ public class AddUpDeductionController { .header("Cache-Control", "no-cache").build(); } + + @GET + @Path("/exportDetail") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response exportDetail(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + + AddUpDeductionQueryParam param = buildParam(request); + + Map map = ParamUtil.request2Map(request); + map.put("addUpDeductionQueryParam", param); + + XSSFWorkbook workbook = getService(user).exportDetail(map); + + String fileName = null; + try { + fileName = URLEncoder.encode("累计专项附加扣除明细.xlsx", "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + StreamingOutput output = outputStream -> { + workbook.write(outputStream); + outputStream.flush(); + }; + + response.setContentType("application/octet-stream"); + return Response.ok(output) + .header("Content-disposition", "attachment;filename=" + fileName) + .header("Cache-Control", "no-cache").build(); + } + @Nullable private AddUpDeductionQueryParam buildParam(HttpServletRequest request) { AddUpDeductionQueryParam param = new AddUpDeductionQueryParam(); diff --git a/src/com/engine/salary/web/AddUpSituationController.java b/src/com/engine/salary/web/AddUpSituationController.java index f81da7ece..7cb00e799 100644 --- a/src/com/engine/salary/web/AddUpSituationController.java +++ b/src/com/engine/salary/web/AddUpSituationController.java @@ -9,7 +9,7 @@ import com.engine.salary.service.impl.AddUpSituationServiceImpl; import com.engine.salary.util.ResponseResult; import io.swagger.v3.oas.annotations.parameters.RequestBody; import org.apache.commons.lang3.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.jetbrains.annotations.Nullable; import weaver.general.GCONST; import weaver.hrm.HrmUserVarify; @@ -106,9 +106,10 @@ public class AddUpSituationController { User user = HrmUserVarify.getUser(request, response); Map map = ParamUtil.request2Map(request); - map.put("queryParam", new AddUpSituationQueryParam()); + AddUpSituationQueryParam queryParam = buildParam(request); + map.put("queryParam", queryParam); - HSSFWorkbook workbook = getService(user).export(map); + XSSFWorkbook workbook = getService(user).export(map); String fileName = null; try { @@ -128,6 +129,43 @@ public class AddUpSituationController { .header("Cache-Control", "no-cache").build(); } + + /** + * 导出明细 + * + * @param + * @return + */ + @GET + @Path("/exportDetail") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response exportDetail(@Context HttpServletRequest request, @Context HttpServletResponse response) { + User user = HrmUserVarify.getUser(request, response); + + Map map = ParamUtil.request2Map(request); + AddUpSituationQueryParam queryParam = buildParam(request); + map.put("queryParam", queryParam); + + XSSFWorkbook workbook = getService(user).exportDetail(map); + + String fileName = null; + try { + fileName = URLEncoder.encode("累计情况明细.xlsx", "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + StreamingOutput output = outputStream -> { + workbook.write(outputStream); + outputStream.flush(); + }; + + response.setContentType("application/octet-stream"); + return Response.ok(output) + .header("Content-disposition", "attachment;filename=" + fileName) + .header("Cache-Control", "no-cache").build(); + } + @Nullable private AddUpSituationQueryParam buildParam(HttpServletRequest request) { AddUpSituationQueryParam param = new AddUpSituationQueryParam();