Browse Source

抚慰金申请发放明细表-添加excel版

master
buaixuexideshitongxue 2 months ago
parent
commit
ed6a42fb41
  1. 86
      src/main/java/com/biutag/supervision/service/RpcComfortPacksService.java
  2. BIN
      src/main/resources/static/templates/ftl/4_抚慰金申请发放明细表.xlsx

86
src/main/java/com/biutag/supervision/service/RpcComfortPacksService.java

@ -7,6 +7,11 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -35,8 +40,7 @@ import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -61,6 +65,9 @@ public class RpcComfortPacksService extends ServiceImpl<RpcComfortPacksMapper, R
private final Template template5;
private final Template template6;
public RpcComfortPacksService(RpcApplyService rpcApplyService, RpcPacksComfortService rpcPacksComfortService, RpcRightPersonService rpcRightPersonService, FileService fileService, SupPoliceService policeService) throws IOException {
this.rpcApplyService = rpcApplyService;
this.rpcPacksComfortService = rpcPacksComfortService;
@ -78,6 +85,7 @@ public class RpcComfortPacksService extends ServiceImpl<RpcComfortPacksMapper, R
this.template3 = configuration.getTemplate("static/templates/ftl/3、维权抚慰登记表.xml", "UTF-8");
this.template4 = configuration.getTemplate("static/templates/ftl/4、抚慰金申请发放明细表.xml", "UTF-8");
this.template5 = configuration.getTemplate("static/templates/ftl/5、民警维权抚慰申请表.xml", "UTF-8");
this.template6 = configuration.getTemplate("static/templates/ftl/4_抚慰金申请发放明细表.xlsx", "UTF-8");
}
@ -113,6 +121,7 @@ public class RpcComfortPacksService extends ServiceImpl<RpcComfortPacksMapper, R
});
// 生成呈报文件
genReports(rpcComfortPacks, comfortPacksDto.getComforts());
// System.out.println(1/0);
return true;
}
@ -183,6 +192,9 @@ public class RpcComfortPacksService extends ServiceImpl<RpcComfortPacksMapper, R
.fluentPut("reportMoney", rpcComfortPacks.getReportMoney());
ByteArrayOutputStream os4 = new ByteArrayOutputStream();
template4.process(data4, new BufferedWriter(new OutputStreamWriter(os4, StandardCharsets.UTF_8)));
// 4、抚慰金申请发放明细表.xlsx
ByteArrayOutputStream os4Excel = buildPayDetailExcel(applyMonth, rpcComfortPacks.getReportMoney(), comforts);
// 5、民警维权抚慰申请表.xml
JSONObject data5 = new JSONObject()
@ -191,8 +203,8 @@ public class RpcComfortPacksService extends ServiceImpl<RpcComfortPacksMapper, R
template5.process(data5, new BufferedWriter(new OutputStreamWriter(os5, StandardCharsets.UTF_8)));
ByteArrayOutputStream zipOs = new ByteArrayOutputStream();
ZipUtil.zip(zipOs, Arrays.array("1、抚慰金审批签呈.doc", "2、抚慰金申报批处理表.doc", "3、维权抚慰登记表.doc", "4、抚慰金申请发放明细表.doc", "5、民警维权抚慰申请表.doc"),
Arrays.array(IoUtil.toStream(os1), IoUtil.toStream(os2), IoUtil.toStream(os3), IoUtil.toStream(os4), IoUtil.toStream(os5)));
ZipUtil.zip(zipOs, Arrays.array("1、抚慰金审批签呈.doc", "2、抚慰金申报批处理表.doc", "3、维权抚慰登记表.doc", "4、抚慰金申请发放明细表.doc", "5、民警维权抚慰申请表.doc","4、抚慰金申请发放明细表.xlsx"),
Arrays.array(IoUtil.toStream(os1), IoUtil.toStream(os2), IoUtil.toStream(os3), IoUtil.toStream(os4), IoUtil.toStream(os5), IoUtil.toStream(os4Excel)));
// 上传
ByteArrayInputStream zipIs = IoUtil.toStream(zipOs);
String filepath = fileService.upload(zipIs, zipIs.available(), "zip");
@ -200,4 +212,70 @@ public class RpcComfortPacksService extends ServiceImpl<RpcComfortPacksMapper, R
}
private ByteArrayOutputStream buildPayDetailExcel(String applyMonth,
Double reportMoney,
List<RpcApplyVo> comforts) throws IOException {
InputStream templateIs = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("static/templates/ftl/4_抚慰金申请发放明细表.xlsx");
if (templateIs == null) {
throw new FileNotFoundException("Excel模板不存在:templates/4_抚慰金申请发放明细表.xlsx");
}
// 1、单值变量(标题 + 合计)
Map<String, Object> vars = new HashMap<>();
vars.put("applyMonth", applyMonth);
vars.put("reportMoney", reportMoney == null ? 0D : reportMoney);
// 2、列表数据
List<Map<String, Object>> rows = new ArrayList<>();
for (int i = 0; i < comforts.size(); i++) {
RpcApplyVo it = comforts.get(i);
Map<String, Object> row = new HashMap<>();
row.put("rowNo", i + 1);
row.put("departFullName", it.getDepartFullName() == null ? "" : it.getDepartFullName());
row.put("applicantEmpName", it.getApplicantEmpName() == null ? "" : it.getApplicantEmpName());
row.put("idCode", it.getIdCode() == null ? "" : it.getIdCode());
row.put("bankBranch", it.getBankBranch() == null ? "" : it.getBankBranch());
row.put("bankCardAccount", it.getBankCardAccount() == null ? "" : it.getBankCardAccount());
row.put("mobile", it.getMobile() == null ? "" : it.getMobile());
// 金额:当前项目是用 injurySeverity 作为金额来源
Double money = 0D;
try {
if (it.getInjurySeverity() != null && !it.getInjurySeverity().isBlank()) {
money = Double.parseDouble(it.getInjurySeverity());
}
} catch (Exception ignore) {}
row.put("money", money);
rows.add(row);
}
// 3、 使用 EasyExcel + 模板填充
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (ExcelWriter writer = EasyExcel.write(os)
.withTemplate(templateIs)
.autoCloseStream(false)
.build()) {
WriteSheet sheet = EasyExcel.writerSheet(0).build();
// 先填单值
writer.fill(vars, sheet);
// 再填列表(必须 forceNewRow = true)
FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();
writer.fill(new FillWrapper("rpcApplys", rows), fillConfig, sheet);
} finally {
templateIs.close();
}
return os;
}
}

BIN
src/main/resources/static/templates/ftl/4_抚慰金申请发放明细表.xlsx

Binary file not shown.
Loading…
Cancel
Save