|
@@ -0,0 +1,478 @@
|
|
|
+package com.rongwei.bscommon.sys.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.aspose.words.*;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.rongwei.bscommon.sys.dao.ZhcxPersistentManageDao;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxPersistentManageService;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxPersistentManageDo;
|
|
|
+import com.rongwei.bsentity.vo.FormDataVO;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxPersistentWordVO;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelExportUtil;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.utils.WordHelpUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.vo.FormData;
|
|
|
+import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zhuang
|
|
|
+ */
|
|
|
+@Service()
|
|
|
+@Slf4j
|
|
|
+public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentManageDao, ZhcxPersistentManageDo> implements ZhcxPersistentManageService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ZhcxPersistentManageDao zhcxPersistentManageDao;
|
|
|
+ @Autowired
|
|
|
+ private SysFileItemService sysFileItemService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int wordExport(Map<String, Object> map, HttpServletResponse response) {
|
|
|
+ Object periodObj = map.get("period");
|
|
|
+ Object yearObj = map.get("year");
|
|
|
+ Object paramsObj = map.get("params");
|
|
|
+ if(ObjectUtil.isEmpty(periodObj)){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if(!ObjectUtil.isEmpty(paramsObj)){
|
|
|
+ String params = (String) map.get("params");
|
|
|
+ map.put("params",params.replaceAll("=-=", "and"));
|
|
|
+ }else{
|
|
|
+ map.remove("params");
|
|
|
+ }
|
|
|
+ String period = (String) periodObj;
|
|
|
+ String year = (String) yearObj;
|
|
|
+ map.put("period","第"+period+"期");
|
|
|
+ List<ZhcxPersistentManageDo> list = zhcxPersistentManageDao.listData(map);
|
|
|
+ if(list.size() > 0){
|
|
|
+ Map<String, List<ZhcxPersistentManageDo>> groupList = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFill));
|
|
|
+ Date[] weekDates = getWeekDates(Integer.parseInt(year), Integer.parseInt(period));
|
|
|
+ Date startDate = weekDates[0];
|
|
|
+ String reStartTime = DateUtil.format(startDate, "yyyy/MM/dd");
|
|
|
+ Date endDate = weekDates[1];
|
|
|
+ String reEndTime = DateUtil.format(endDate, "yyyy/MM/dd");
|
|
|
+ //final Document[] doc = {null};
|
|
|
+ SysFileItemDo fileItemDo = sysFileItemService.getById("bc1bfcf5a4a44e9bb2c5881815d3aad0");
|
|
|
+ final Document[] doc = {WordHelpUtils.getDoc(fileItemDo.getFullpath())};
|
|
|
+ AtomicInteger i = new AtomicInteger();
|
|
|
+ groupList.forEach((k, v) -> {
|
|
|
+ FormData formData = new FormData();
|
|
|
+ List<Map<String,Object>> mainDataList = new ArrayList<>();
|
|
|
+ List<List<Map<String,Object>>> slaveTableDataList = new ArrayList<>();
|
|
|
+ Map<String,Object> mainMap = new HashMap<>(16);
|
|
|
+ mainMap.put("checkDate",reStartTime+"-"+reEndTime);
|
|
|
+ mainMap.put("type",k);
|
|
|
+ mainMap.put("period","第"+period+"期");
|
|
|
+ Map<String, BigDecimal> totalAmountByCategory = v.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ ZhcxPersistentManageDo::getType,
|
|
|
+ Collectors.reducing(BigDecimal.ZERO, this::safeGetAmount, BigDecimal::add)
|
|
|
+ ));
|
|
|
+ Map<String, List<ZhcxPersistentManageDo>> subList = v.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getType));
|
|
|
+ List<ZhcxPersistentManageDo> rewardList = new ArrayList<>();
|
|
|
+ List<ZhcxPersistentManageDo> punishList = new ArrayList<>();
|
|
|
+ subList.forEach((k1, v1) -> {
|
|
|
+ if(k1.contains("奖励")){
|
|
|
+ mainMap.put("rewardCount",v1.size());
|
|
|
+ rewardList.addAll(v1);
|
|
|
+ }else{
|
|
|
+ mainMap.put("punishCount",v1.size());
|
|
|
+ punishList.addAll(v1);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ totalAmountByCategory.forEach((k1, v1) -> {
|
|
|
+ if(k1.contains("奖励")){
|
|
|
+ mainMap.put("rewardAmount",v1);
|
|
|
+ }else{
|
|
|
+ mainMap.put("punishAmount",v1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Map<String, Object>> rewardMaps = convertList(rewardList, ZhcxPersistentManageDo.class);
|
|
|
+ List<Map<String, Object>> punishMaps = convertList(punishList, ZhcxPersistentManageDo.class);
|
|
|
+ slaveTableDataList.add(rewardMaps);
|
|
|
+ slaveTableDataList.add(punishMaps);
|
|
|
+ mainDataList.add(mainMap);
|
|
|
+ formData.setMainDataList(mainDataList);
|
|
|
+ formData.setSlaveTableDataList(slaveTableDataList);
|
|
|
+ if (k.contains("焊缝一次成型不打磨奖励报告")) {
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("b39c12eeb3464596b70f1ce4e96b922f");
|
|
|
+ try {
|
|
|
+ if(ObjectUtil.isNull(doc[0])) {
|
|
|
+ doc[0] = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ } else {
|
|
|
+ Document docTemp = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ doc[0].appendDocument(docTemp, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("顽症导出word失败:"+e);
|
|
|
+ }
|
|
|
+ }else if (k.contains("构件油漆后损伤专项督查")){
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("427ec6c843914718ad12359c8cf70da7");
|
|
|
+ try {
|
|
|
+ if(ObjectUtil.isNull(doc[0])) {
|
|
|
+ doc[0] = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ } else {
|
|
|
+ Document docTemp = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ doc[0].appendDocument(docTemp, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("顽症导出word失败:"+e);
|
|
|
+ }
|
|
|
+ }else if (k.contains("构件“不落地”专项督查")){
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("fe6181ceba7b444299046dfcc5b20a48");
|
|
|
+ try {
|
|
|
+ if(ObjectUtil.isNull(doc[0])) {
|
|
|
+ doc[0] = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ } else {
|
|
|
+ Document docTemp = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ doc[0].appendDocument(docTemp, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("顽症导出word失败:"+e);
|
|
|
+ }
|
|
|
+ }else if (k.contains("“工完料净场地清”专项督查")){
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("d0f806c658104eeda1f46a592ca824f2");
|
|
|
+ try {
|
|
|
+ if(ObjectUtil.isNull(doc[0])) {
|
|
|
+ doc[0] = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ } else {
|
|
|
+ Document docTemp = ExcelExportUtil.fillWordDataByMap(fileTemp.getFullpath(), formData);
|
|
|
+ doc[0].appendDocument(docTemp, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("顽症导出word失败:"+e);
|
|
|
+ }
|
|
|
+ }else if (k.contains("每周质量顽症督查")){
|
|
|
+ FormDataVO formDataVo = new FormDataVO();
|
|
|
+ formDataVo.setMainDataList(mainDataList);
|
|
|
+
|
|
|
+ map.put("type","每周质量顽症督查");
|
|
|
+ List<ZhcxPersistentWordVO> zhcxPersistentManageDos = zhcxPersistentManageDao.groupByList(map);
|
|
|
+ List<ZhcxPersistentWordVO> listData = new ArrayList<>();
|
|
|
+ zhcxPersistentManageDos.forEach(ev->{
|
|
|
+ if("处罚".equals(ev.getType())){
|
|
|
+ ev.setPunishAmount(ev.getAmount());
|
|
|
+ ev.setPunishCount(ev.getCount());
|
|
|
+ listData.add(ev);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ zhcxPersistentManageDos.forEach(ev->{
|
|
|
+ if("奖励".equals(ev.getType())){
|
|
|
+ listData.forEach(item->{
|
|
|
+ if(item.getFirstorgname().equals(ev.getFirstorgname())){
|
|
|
+ item.setRewardAmount(ev.getAmount());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Map<String, Object>> maps = convertList(listData, ZhcxPersistentWordVO.class);
|
|
|
+ slaveTableDataList.clear();
|
|
|
+ slaveTableDataList.add(maps);
|
|
|
+ formDataVo.setSlaveTableDataList(slaveTableDataList);
|
|
|
+ try {
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("dc0d69edf9e64f1abd151b1441411002");
|
|
|
+ if(ObjectUtil.isNull(doc[0])) {
|
|
|
+ doc[0] = fillWordDataByMap(fileTemp.getFullpath(), formDataVo);
|
|
|
+ } else {
|
|
|
+ Document docTemp = fillWordDataByMap(fileTemp.getFullpath(), formDataVo);
|
|
|
+ doc[0].appendDocument(docTemp, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("顽症导出word失败:"+e);
|
|
|
+ }
|
|
|
+ Map<String, List<ZhcxPersistentManageDo>> typeList = v.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getType));
|
|
|
+ typeList.forEach((k1, v1) -> {
|
|
|
+ Map<String, List<ZhcxPersistentManageDo>> collect = v1.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgname));
|
|
|
+ try {
|
|
|
+ Document docDetail = null;
|
|
|
+
|
|
|
+ if (k1.contains("处罚")) {
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("fc9d0bd3d7354037afa6092d6a64ed5a");
|
|
|
+ docDetail = WordHelpUtils.getDoc(fileTemp.getFullpath());
|
|
|
+ }else{
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("73ae110bb9e84aeab985c14d4678670b");
|
|
|
+ docDetail = WordHelpUtils.getDoc(fileTemp.getFullpath());
|
|
|
+ }
|
|
|
+ //如果要以动态形式创建一个文档,最常用的方式是使用DocumentBuilder来增加内容。
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(docDetail);
|
|
|
+ //将光标移动到该处
|
|
|
+ builder.moveToDocumentEnd();
|
|
|
+
|
|
|
+ //循环动态添加表格
|
|
|
+ createTable(builder,docDetail,collect,"table1",0);
|
|
|
+
|
|
|
+ DocumentBuilder builder3 = new DocumentBuilder(doc[0]);
|
|
|
+ builder3.moveToDocumentEnd();
|
|
|
+ // 插入换行符,确保第二个文档内容在新行开始
|
|
|
+ builder3.writeln();
|
|
|
+ builder3.insertDocument(docDetail, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ i.getAndIncrement();
|
|
|
+ if(i.get() < groupList.size() - 1) {
|
|
|
+ if (!ObjectUtil.isNull(doc[0])) {
|
|
|
+ WordHelpUtils.addPageBreak(doc[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ doc[0].updateFields();
|
|
|
+ response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + "测试1");
|
|
|
+ doc[0].save(response.getOutputStream(), com.aspose.words.SaveOptions.createSaveOptions(com.aspose.words.SaveFormat.DOCX));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("顽症导出word失败:"+e);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充 word 模板(map数据格式)
|
|
|
+ * @param file word二进制
|
|
|
+ * @param formData 填充表单数据
|
|
|
+ */
|
|
|
+ private Document fillWordDataByMap(String file, FormDataVO formData){
|
|
|
+ //获取word文档
|
|
|
+ Document doc = WordHelpUtils.getDoc(file);
|
|
|
+ //初始化设置
|
|
|
+ WordHelpUtils.initDoc(doc);
|
|
|
+
|
|
|
+ //填充表单数据
|
|
|
+ fillFormData(doc, formData);
|
|
|
+ WordHelpUtils.mergeAfter(doc);
|
|
|
+ return doc;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Document fillFormData(Document doc, FormDataVO formData) {
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotEmpty(formData.getMainDataList())) {
|
|
|
+ for(Map<String,Object> map : formData.getMainDataList()) {
|
|
|
+ //填充主表数据
|
|
|
+ WordHelpUtils.fillData(doc, map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //填充多个从表格数据
|
|
|
+ if(ObjectUtil.isNotEmpty(formData.getSlaveTableDataList())) {
|
|
|
+ int i=0;
|
|
|
+ for(List<Map<String,Object>> list :formData.getSlaveTableDataList()) {
|
|
|
+ i++;
|
|
|
+ WordHelpUtils.fillData(doc, list, "List" + i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return doc;
|
|
|
+ }
|
|
|
+ public static int I = 0;
|
|
|
+ public static int Q = 0;
|
|
|
+ private void createTable(DocumentBuilder builder, Document doc, Map<String, List<ZhcxPersistentManageDo>> gxyItemDataMap, String bookmarkName, int index) throws Exception {
|
|
|
+ //将list转为根据grade分组K的map,因为要按照K去动态复制多个表格。
|
|
|
+ I =gxyItemDataMap.size()+1;
|
|
|
+ Q =gxyItemDataMap.size()+1;
|
|
|
+
|
|
|
+ /*1: 动态复制表格模板 {根据Map的长度大小来复制每行单元格}*/
|
|
|
+ if (gxyItemDataMap.size()!=0){
|
|
|
+ for (int i =0;i<gxyItemDataMap.size()-1;i++){
|
|
|
+ addtable(doc); //动态生成表格
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*3: 插入数据和将表移动到题注下*/
|
|
|
+ //final int[] idx = {0};
|
|
|
+ int idx2 = 0;
|
|
|
+ for (Map.Entry<String, List<ZhcxPersistentManageDo>> entry : gxyItemDataMap.entrySet()) {
|
|
|
+ Q = Q - 1;
|
|
|
+ addexcel(doc,entry.getKey(), idx2,entry.getValue());
|
|
|
+ System.out.println("Index = " + index + ", Key = " + entry.getKey() + ", Value = " + entry.getValue());
|
|
|
+ idx2++;
|
|
|
+ }
|
|
|
+ NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
|
|
|
+ if(tables.getCount() > 0){
|
|
|
+ // 第一个表格
|
|
|
+ Table mainTable = (Table) tables.get(0);
|
|
|
+ // 遍历剩下的9个表格
|
|
|
+ for (int i = 1; i < tables.getCount(); i++) {
|
|
|
+ Table currentTable = (Table) tables.get(i);
|
|
|
+
|
|
|
+ // 将当前表格的所有行添加到第一个表格中
|
|
|
+ while (currentTable.hasChildNodes()) {
|
|
|
+ mainTable.getRows().add(currentTable.getFirstRow());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除当前表格
|
|
|
+ currentTable.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ builder.moveToDocumentEnd();//光标结束
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @Description: 向已有表格模板插入数据
|
|
|
+ * @Param: doc、index、List<GxyItemData>
|
|
|
+ */
|
|
|
+ private void addexcel(Document doc, String k, int index, List<ZhcxPersistentManageDo> staff)throws Exception{
|
|
|
+ //根据索引获得表格
|
|
|
+ Table table = (Table) doc.getChild(NodeType.TABLE, index, true);
|
|
|
+ Row titleRow = table.getFirstRow();
|
|
|
+ Range range1 = titleRow.getRange();
|
|
|
+ range1.replace("title",k);
|
|
|
+ int i = 0;
|
|
|
+ for (ZhcxPersistentManageDo staf : staff) { // 替换变量
|
|
|
+ i++;
|
|
|
+ Row newRow = table.getLastRow();
|
|
|
+ Node deepClone = table.getLastRow().deepClone(true); //得到最后一行
|
|
|
+ Range range = table.getLastRow().getRange();//得到值
|
|
|
+ String sitepic = staf.getSitepic() == null ?"":staf.getSitepic();
|
|
|
+ String projectcode = staf.getProjectcode()== null ?"":staf.getProjectcode();
|
|
|
+ String projectename = staf.getProjectename()== null ?"":staf.getProjectename();
|
|
|
+ String content = staf.getContent()== null ?"":staf.getContent();
|
|
|
+ String baseinfonum = staf.getBaseinfonum()== null ?"":staf.getBaseinfonum();
|
|
|
+ String subcontractename = staf.getSubcontractename() == null ? "" : staf.getSubcontractename();
|
|
|
+ BigDecimal amount = staf.getAmount();
|
|
|
+ String rectifystatus = staf.getRectifystatus();
|
|
|
+ if(StringUtils.isNotBlank(sitepic)){
|
|
|
+ String[] splits = StringUtils.toString(sitepic, "").split("\\^_\\^");
|
|
|
+ String[] imgIds = splits[0].split("-;-");
|
|
|
+ SysFileItemDo fileItemDo = sysFileItemService.getById(imgIds[1]);
|
|
|
+ if(fileItemDo != null){
|
|
|
+ BufferedInputStream inputStream = FileUtil.getInputStream(fileItemDo.getFullpath());
|
|
|
+ // 使用DocumentBuilder插入图片
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(doc);
|
|
|
+
|
|
|
+ // 找到包含"pic"的占位符的单元格
|
|
|
+ Cell cellWithPicPlaceholder = null;
|
|
|
+ for (Cell cell : newRow.getCells()) {
|
|
|
+ if (cell.getRange().getText().contains("pic")) {
|
|
|
+ cellWithPicPlaceholder = cell;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cellWithPicPlaceholder != null) {
|
|
|
+ // 清除占位符
|
|
|
+ cellWithPicPlaceholder.getRange().replace("pic", "");
|
|
|
+ // 移动到单元格并插入图片
|
|
|
+ builder.moveTo(cellWithPicPlaceholder.getFirstParagraph());
|
|
|
+ builder.insertImage(inputStream, 100, 80); // 设置图片宽度和高度
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ range.replace("index",String.valueOf(i));
|
|
|
+ range.replace("pic", sitepic);
|
|
|
+ range.replace("content",projectcode+projectename+content);
|
|
|
+ range.replace("code", baseinfonum);
|
|
|
+ if (amount != null) {
|
|
|
+ range.replace("amount", String.valueOf(amount));
|
|
|
+ }
|
|
|
+ if("未整改".equals(rectifystatus)){
|
|
|
+ rectifystatus = "/";
|
|
|
+ }
|
|
|
+ range.replace("status",rectifystatus );
|
|
|
+ range.replace("dept", staf.getFirstorgname()+staf.getSecondorgname()+subcontractename);
|
|
|
+ table.getRows().add(deepClone);
|
|
|
+ }
|
|
|
+ table.getLastRow().remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 动态复制表格
|
|
|
+ * @Param: doc
|
|
|
+ * @return:
|
|
|
+ */
|
|
|
+ public static void addtable(Document doc) throws Exception{
|
|
|
+ //获取第一个表格
|
|
|
+ Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
|
|
|
+ //创建段落
|
|
|
+ Paragraph lastParagraph = new Paragraph(doc);
|
|
|
+ //第一个表格末尾加段落
|
|
|
+ table.getParentNode().insertAfter(lastParagraph, table);
|
|
|
+ Table cloneTable = (Table)table.deepClone(true);
|
|
|
+ table.getParentNode().insertAfter(cloneTable,lastParagraph);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 安全获取金额,处理null值
|
|
|
+ private BigDecimal safeGetAmount(ZhcxPersistentManageDo obj) {
|
|
|
+ // 你可以根据实际情况改变这个方法,以适应不同的错误处理策略。
|
|
|
+ BigDecimal amount = obj.getAmount();
|
|
|
+ return amount != null ? amount : BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> List<Map<String, Object>> convertList(List<T> objectList, Class<T> clazz) {
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ int index = 0;
|
|
|
+ for (T obj : objectList) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ // 获取对象的所有字段并将其转换为Map
|
|
|
+ Field[] fields = clazz.getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ field.setAccessible(true); // 设置字段可访问
|
|
|
+ String fieldName = field.getName();
|
|
|
+ Object value;
|
|
|
+ try {
|
|
|
+ value = field.get(obj);
|
|
|
+ map.put(fieldName, value);
|
|
|
+ if(fieldName == "sitepic"){
|
|
|
+ if(value != null){
|
|
|
+ String value1 = (String) value;
|
|
|
+ if(StringUtils.isNotBlank(value1)){
|
|
|
+ String[] split = value1.split("\\^_\\^");
|
|
|
+ map.put(fieldName, split[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(fieldName == "rectifystatus"){
|
|
|
+ if(!"已整改".equals(value)){
|
|
|
+ map.put(fieldName, "/");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ map.put("index",index);
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ return mapList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date[] getWeekDates(int year, int week) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.YEAR, year);
|
|
|
+ calendar.set(Calendar.WEEK_OF_YEAR, week);
|
|
|
+ calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
|
|
|
+
|
|
|
+ Date startDate = calendar.getTime();
|
|
|
+ calendar.add(Calendar.DAY_OF_WEEK, 6);
|
|
|
+ Date endDate = calendar.getTime();
|
|
|
+
|
|
|
+ return new Date[]{startDate, endDate};
|
|
|
+ }
|
|
|
+}
|