فهرست منبع

顽症-导出

zhuang 2 ماه پیش
والد
کامیت
76f05f7994

+ 347 - 398
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxPersistentManageServiceImpl.java

@@ -17,6 +17,7 @@ import com.rongwei.bscommon.sys.dao.ZhcxPersistentManageDao;
 import com.rongwei.bscommon.sys.service.ZhcxDeptPeopleCountService;
 import com.rongwei.bscommon.sys.service.ZhcxPersistentManageService;
 import com.rongwei.bsentity.domain.*;
+import com.rongwei.bsentity.dto.PersistentDeptDto;
 import com.rongwei.bsentity.dto.ZhcxPersistentManageDto;
 import com.rongwei.bsentity.dto.ZhcxPersistentReportDto;
 import com.rongwei.bsentity.vo.FormDataVO;
@@ -44,6 +45,7 @@ import org.springframework.web.client.RestTemplate;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedInputStream;
+import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -104,294 +106,192 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
             throw new CustomException("当前周期暂无数据");
         }
         if (list.size() > 0) {
-            list.forEach(ev -> {
-                String sitepic = ev.getSitepic();
-                BigDecimal punishconfirmamount = ev.getPunishconfirmamount();
-                String type = ev.getType();
-                if (type.contains("处罚") && punishconfirmamount != null) {
-                    ev.setAmount(punishconfirmamount);
-                }
-                if (StringUtils.isNotBlank(sitepic)) {
-                    String[] splits = sitepic.split("\\^_\\^");
-                    Optional<String> firstId = Arrays.stream(splits)
-                            .filter(s -> s.contains(".jpg")
-                                    || s.contains(".jpeg")
-                                    || s.contains(".png"))
-                            .findFirst();
-                    if (firstId.isPresent()) {
-                        ev.setSitepic(firstId.get());
-                    }
-                }
-            });
-            Map<String, List<ZhcxPersistentManageDo>> groupList = list.stream()
-                    .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFill));
+            long productionCount = list.stream()
+                    .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                    .count();
+
+            long selfDeptCount = list.stream()
+                    .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                    .count();
+
+            long punishmentCount = list.stream()
+                    .filter(item -> "处罚".equals(item.getType()))
+                    .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
+                    .count();
             Date[] weekDates = getWeekDates(Integer.parseInt(year), Integer.parseInt(period));
             Date startDate = weekDates[0];
-            String reStartTime = DateUtil.format(startDate, "yyyy/MM/dd");
+            String reStartTime = DateUtil.format(startDate, "yyyy年MM月dd日");
+            String topTime = DateUtil.format(startDate, "yyyyMM");
+
+            String reStartDate = DateUtil.format(startDate, "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);
-                    }
+            String reEndTime = DateUtil.format(endDate, "MM月dd日");
+            String bottomTime = DateUtil.format(endDate, "yyyy年MM月dd日");
+
+
+            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("checkStartDate",reStartTime);
+            mainMap.put("checkEndDate",reEndTime);
+            mainMap.put("topTime",topTime);
+            mainMap.put("bottomTime",bottomTime);
+            mainMap.put("period",period);
+            mainMap.put("productionCount",productionCount);
+            mainMap.put("selfDeptCount",selfDeptCount);
+            mainMap.put("punishmentCount",punishmentCount);
+            mainMap.put("leftDate",reStartDate);
+            mainMap.put("rightDate",reEndTime);
+            mainMap.put("year",year);
+            Map<String, List<ZhcxPersistentManageDo>> collect =
+                    list.stream().collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgid));
+            List<PersistentDeptDto> deptDtoList = new ArrayList<>();
+            collect.forEach((k,v)->{
+                long param1 = v.stream()
+                        .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                        .count();
+                long param2 = v.stream()
+                        .filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                        .filter(item -> "处罚".equals(item.getType()))
+                        .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
+                        .count();
+                long param3 = v.stream()
+                        .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                        .count();
+                long param4 = v.stream()
+                        .filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                        .filter(item -> "处罚".equals(item.getType()))
+                        .filter(item -> item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
+                        .count();
+                BigDecimal param5 = v.stream()
+                        .filter(item -> "处罚".equals(item.getType()))
+                        .map(ZhcxPersistentManageDo::getAmount)
+                        .filter(Objects::nonNull)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+                PersistentDeptDto dto = new PersistentDeptDto();
+                dto.setDutyDeptName(v.get(0).getFirstorgname());
+                dto.setSelfDeptCount(param1);
+                dto.setSelfDeptPunishCount(param2);
+                dto.setProductionCount(param3);
+                dto.setProductionPunishCount(param4);
+                dto.setPunishmentAmount(param5);
+                BigDecimal ratio = BigDecimal.ZERO;
+                ratio = BigDecimal.valueOf(param2)
+                        .divide(BigDecimal.valueOf(param1), 4, RoundingMode.HALF_UP)
+                        .multiply(BigDecimal.valueOf(100))
+                        .setScale(2, RoundingMode.HALF_UP);
+                dto.setRate(ratio);
+                deptDtoList.add(dto);
+            });
+            String deptNames = deptDtoList.stream()
+                    .sorted(Comparator.comparing(PersistentDeptDto::getRate))
+                    .limit(3)
+                    .map(PersistentDeptDto::getDutyDeptName)
+                    .collect(Collectors.joining("、"));
+            mainMap.put("checkDept",deptNames);
+            if (deptDtoList.size() > 0) {
+                PersistentDeptDto totalDto = new PersistentDeptDto();
+                totalDto.setDutyDeptName("合计");
+                totalDto.setSelfDeptCount(deptDtoList.stream().mapToLong(PersistentDeptDto::getSelfDeptCount).sum());
+                totalDto.setSelfDeptPunishCount(deptDtoList.stream().mapToLong(PersistentDeptDto::getSelfDeptPunishCount).sum());
+                totalDto.setProductionCount(deptDtoList.stream().mapToLong(PersistentDeptDto::getProductionCount).sum());
+                totalDto.setProductionPunishCount(deptDtoList.stream().mapToLong(PersistentDeptDto::getProductionPunishCount).sum());
+                totalDto.setPunishmentAmount(deptDtoList.stream()
+                        .map(PersistentDeptDto::getPunishmentAmount)
+                        .filter(Objects::nonNull)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add));
+                deptDtoList.add(totalDto);
+            }
+            mainDataList.add(mainMap);
+            List<Map<String, Object>> listMap = convertList(deptDtoList, PersistentDeptDto.class);
+            slaveTableDataList.add(listMap);
+            formData.setMainDataList(mainDataList);
+            formData.setSlaveTableDataList(slaveTableDataList);
+            SysFileItemDo fileItemDo = sysFileItemService.getById("fa503bfe611147f0ae1b8760b3b69264");
+            //final Document[] doc = {WordHelpUtils.getDoc(fileItemDo.getFullpath())};
+            Document doc = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
+            SysFileItemDo fileItemDo2 = sysFileItemService.getById("50bf832943164750b818b284a74af700");
+            Document doc2 = WordHelpUtils.getDoc(fileItemDo2.getFullpath());
+            long pcount = list.stream()
+                    .filter(item -> "处罚".equals(item.getType())
+                            && StringUtils.isNotBlank(item.getSitepic())
+                            && item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0
+                            && "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())).count();
+            BigDecimal ppunishAmount = list.stream()
+                    .filter(item -> "处罚".equals(item.getType())
+                            && "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid()))
+                    .map(ZhcxPersistentManageDo::getAmount)
+                    .filter(Objects::nonNull)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            try {
+                doc2.getMailMerge().execute(
+                        new String[]{"picCount", "punishAmount",
+                                "period", "topTime",
+                                "year", "leftDate",
+                                "rightDate", "checkStartDate", "checkEndDate","bottomTime"},
+                        new Object[]{pcount, ppunishAmount,period,topTime,year,reStartDate,reEndTime,reStartTime,reEndTime,bottomTime}
+                );
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            List<ZhcxPersistentManageDo> collect3 = list.stream().filter(item -> "0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())
+                            && "处罚".equals(item.getType()) && item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
+                    .sorted(Comparator.comparing(ZhcxPersistentManageDo::getFirstorgid))
+                    .collect(Collectors.toList());
+            if(collect3.size() >0){
+                try {
 
-                });
-                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("油漆“零破坏”专项")) {
-                    FormDataVO formDataVo = new FormDataVO();
-                    formDataVo.setMainDataList(mainDataList);
-
-                    map.put("type", k);
-                    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);
-                        }
-                    });
-                    List<Map<String, Object>> maps = convertList(listData, ZhcxPersistentWordVO.class);
-                    slaveTableDataList.clear();
-                    slaveTableDataList.add(maps);
-                    formDataVo.setSlaveTableDataList(slaveTableDataList);
-                    try {
-                        SysFileItemDo fileTemp = sysFileItemService.getById("9aebb0bd84d8471b8ed954f5557cb775");
-                        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));
-                    List<ZhcxPersistentManageDo> punishListData = new ArrayList<>();
-                    typeList.forEach((k1, v1) -> {
-                        if (k1.contains("处罚")) {
-                            punishListData.addAll(v1);
-                        }
-                    });
-                    if (punishListData.size() > 0) {
-                        initWeekWord(doc, punishListData, "692aacdfda804e989cc880bfe2d8b764");
-                    }
-                } else if (k.contains("面漆后动火")) {
-                    FormDataVO formDataVo = new FormDataVO();
-                    formDataVo.setMainDataList(mainDataList);
-
-                    map.put("type", k);
-                    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);
-                        }
-                    });
-                    List<Map<String, Object>> maps = convertList(listData, ZhcxPersistentWordVO.class);
-                    slaveTableDataList.clear();
-                    slaveTableDataList.add(maps);
-                    formDataVo.setSlaveTableDataList(slaveTableDataList);
-                    try {
-                        SysFileItemDo fileTemp = sysFileItemService.getById("70fc8489a6604473a5b745e3b9e8fffb");
-                        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));
-                    List<ZhcxPersistentManageDo> punishListData = new ArrayList<>();
-                    typeList.forEach((k1, v1) -> {
-                        if (k1.contains("处罚")) {
-                            punishListData.addAll(v1);
-                        }
-                    });
-                    if (punishListData.size() > 0) {
-                        initWeekWord(doc, punishListData, "bc5442ad2f924f7fa17f1949ec8ebc8c");
-                    }
-                } 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);
-                        }
-                        if (rewardList.size() > 0) {
-                            initWeekWord(doc, rewardList, "a808c450f6484ae18baa5afc4a8fc112");
-                        }
-                    } 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);
-                        }
-                        if (rewardList.size() > 0) {
-                            initWeekWord(doc, rewardList, "0291bfa0b2b04293a1e25d42b07b5e33");
-                        }
-                    } 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);
-                        }
-                        if (rewardList.size() > 0) {
-                            initWeekWord(doc, rewardList, "5b054a5cb2d84bd4b355eadd668fc6e6");
-                        }
-                    } 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());
-                                }
-                            });
-                            boolean b = listData.stream().anyMatch(item -> {
-                                if (item.getFirstorgname().equals(ev.getFirstorgname())) {
-                                    return true;
-                                } else {
-                                    return false;
-                                }
-                            });
-                            if (!b) {
-                                ev.setRewardAmount(ev.getAmount());
-                                listData.add(ev);
-                            }
-                        }
-                    });
-                    List<Map<String, Object>> maps = convertList(listData, ZhcxPersistentWordVO.class);
-                    slaveTableDataList.clear();
-                    slaveTableDataList.add(maps);
-                    formDataVo.setSlaveTableDataList(slaveTableDataList);
+                    DocumentBuilder builder = new DocumentBuilder(doc2);
+                    builder.moveToDocumentEnd();
+                    createTable(builder,doc2,collect3);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+                //initWeekWord(doc, collect3,"a808c450f6484ae18baa5afc4a8fc112");
+            }
+            try {
+                doc.appendDocument(doc2,ImportFormatMode.KEEP_DIFFERENT_STYLES);
+                Map<String, List<ZhcxPersistentManageDo>> collect1 = list.stream().filter(item -> !"0f11e70cd21843ee998a1ce5279028eb".equals(item.getBelongorgid())
+                                && "处罚".equals(item.getType())
+                                && item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0)
+                        .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgid));
+                SysFileItemDo fileItemDo3 = sysFileItemService.getById("b0c5f7b64f9a43bd88711c3c62d870ab");
+                collect1.forEach((k2,v2)->{
+                    Document doc3 = WordHelpUtils.getDoc(fileItemDo3.getFullpath());
+                    String firstorgname = v2.get(0).getFirstorgname();
                     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);
-                        }
+                        long pcount2 = v2.stream()
+                                .filter(item -> "处罚".equals(item.getType())
+                                        && item.getAmount() != null && item.getAmount().compareTo(BigDecimal.ZERO) > 0
+                                        && StringUtils.isNotBlank(item.getSitepic())).count();
+                        BigDecimal ppunishAmount2 = v2.stream()
+                                .filter(item -> "处罚".equals(item.getType()))
+                                .map(ZhcxPersistentManageDo::getAmount)
+                                .filter(Objects::nonNull)
+                                .reduce(BigDecimal.ZERO, BigDecimal::add);
+                        doc3.getMailMerge().execute(
+                                new String[]{"picCount", "punishAmount",
+                                        "period", "topTime",
+                                        "year", "leftDate",
+                                        "rightDate", "checkStartDate", "checkEndDate","firstOrgName","bottomTime"},
+                                new Object[]{pcount2, ppunishAmount2,period,topTime,year,reStartDate,reEndTime,reStartTime,reEndTime,firstorgname,bottomTime}
+                        );
+                        DocumentBuilder builder = new DocumentBuilder(doc3);
+                        builder.moveToDocumentEnd();
+                        createTable(builder,doc3,v2);
+                        doc.appendDocument(doc3,ImportFormatMode.KEEP_DIFFERENT_STYLES);
                     } catch (Exception e) {
-                        log.info("顽症导出word失败:" + e);
-                    }
-                    Map<String, List<ZhcxPersistentManageDo>> typeList = v.stream()
-                            .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getType));
-                    List<ZhcxPersistentManageDo> rewardListData = new ArrayList<>();
-                    List<ZhcxPersistentManageDo> punishListData = new ArrayList<>();
-                    typeList.forEach((k1, v1) -> {
-                        if (k1.contains("处罚")) {
-                            punishListData.addAll(v1);
-                        } else {
-                            rewardListData.addAll(v1);
-                        }
-                    });
-                    if (punishListData.size() > 0) {
-                        initWeekWord(doc, punishListData, "fc9d0bd3d7354037afa6092d6a64ed5a");
-                    }
-                    if (rewardListData.size() > 0) {
-                        initWeekWord(doc, rewardListData, "73ae110bb9e84aeab985c14d4678670b");
+                        e.printStackTrace();
                     }
+                });
 
-                }
-                i.getAndIncrement();
-                if (i.get() < groupList.size() - 1) {
-                    if (!ObjectUtil.isNull(doc[0])) {
-                        WordHelpUtils.addPageBreak(doc[0]);
-                    }
-                }
-            });
-            try {
-                doc[0].updateFields();
+
+                doc.updateFields();
                 response.setContentType("application/octet-stream;charset=ISO8859-1");
                 response.setHeader("Content-Disposition", "attachment;filename=" + "报告");
-                doc[0].save(response.getOutputStream(), com.aspose.words.SaveOptions.createSaveOptions(com.aspose.words.SaveFormat.DOCX));
+                doc.save(response.getOutputStream(), com.aspose.words.SaveOptions.createSaveOptions(com.aspose.words.SaveFormat.DOCX));
             } catch (Exception e) {
                 log.error("顽症导出word失败:" + e);
                 throw new CustomException("导出失败");
@@ -772,32 +672,32 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
                 .doubleValue();
     }
 
-    private void initWeekWord(Document[] doc, List<ZhcxPersistentManageDo> rewardListData, String tempId) {
-        if (rewardListData.size() > 0) {
-            Map<String, List<ZhcxPersistentManageDo>> collect = rewardListData.stream()
-                    .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgname));
-            try {
-                Document docDetail = null;
-                SysFileItemDo fileTemp = sysFileItemService.getById(tempId);
-                docDetail = WordHelpUtils.getDoc(fileTemp.getFullpath());
-                //如果要以动态形式创建一个文档,最常用的方式是使用DocumentBuilder来增加内容。
-                DocumentBuilder builder = new DocumentBuilder(docDetail);
-                //将光标移动到该处
-                builder.moveToDocumentEnd();
-                String fill = rewardListData.get(0).getFill();
-                //循环动态添加表格
-                createTable(builder, docDetail, collect, "table1", 0, fill);
-
-                DocumentBuilder builder3 = new DocumentBuilder(doc[0]);
-                builder3.moveToDocumentEnd();
-                // 插入换行符,确保第二个文档内容在新行开始
-                builder3.writeln();
-                builder3.insertDocument(docDetail, ImportFormatMode.KEEP_DIFFERENT_STYLES);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
+//    private void initWeekWord(Document[] doc, List<ZhcxPersistentManageDo> rewardListData, String tempId) {
+//        if (rewardListData.size() > 0) {
+//            Map<String, List<ZhcxPersistentManageDo>> collect = rewardListData.stream()
+//                    .collect(Collectors.groupingBy(ZhcxPersistentManageDo::getFirstorgname));
+//            try {
+//                Document docDetail = null;
+//                SysFileItemDo fileTemp = sysFileItemService.getById(tempId);
+//                docDetail = WordHelpUtils.getDoc(fileTemp.getFullpath());
+//                //如果要以动态形式创建一个文档,最常用的方式是使用DocumentBuilder来增加内容。
+//                DocumentBuilder builder = new DocumentBuilder(docDetail);
+//                //将光标移动到该处
+//                builder.moveToDocumentEnd();
+//                String fill = rewardListData.get(0).getFill();
+//                //循环动态添加表格
+//                createTable(builder, docDetail, collect, "table1", 0, fill);
+//
+//                DocumentBuilder builder3 = new DocumentBuilder(doc[0]);
+//                builder3.moveToDocumentEnd();
+//                // 插入换行符,确保第二个文档内容在新行开始
+//                builder3.writeln();
+//                builder3.insertDocument(docDetail, ImportFormatMode.KEEP_DIFFERENT_STYLES);
+//            } catch (Exception e) {
+//                e.printStackTrace();
+//            }
+//        }
+//    }
 
 
     /**
@@ -841,49 +741,27 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
     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, String fill) throws Exception {
-        //将list转为根据grade分组K的map,因为要按照K去动态复制多个表格。
-        I = gxyItemDataMap.size() + 1;
-        Q = gxyItemDataMap.size() + 1;
+    private void createTable(DocumentBuilder builder, Document doc, List<ZhcxPersistentManageDo> dataList) throws Exception {
+        // 动态复制模板表格
 
-        /*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;
-            if (fill.contains("每周质量顽症督查") || fill.contains("油漆“零破坏”专项") || fill.contains("面漆后动火")) {
-                addexcel(doc, entry.getKey(), idx2, entry.getValue());
-            } else {
-                addexcel(doc, null, idx2, entry.getValue());
-            }
-            System.out.println("Index = " + index + ", Key = " + entry.getKey() + ", Value = " + entry.getValue());
-            idx2++;
-        }
+
+        addexcel(doc, null, idx2, dataList);
+
+        // 多表合并成一个表(可选)
         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();
+                currentTable.remove(); // 删除多余表
             }
         }
-        builder.moveToDocumentEnd();//光标结束
+
+        builder.moveToDocumentEnd(); // 光标移到末尾
     }
 
     /**
@@ -891,82 +769,153 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
      * @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();
-        if (StringUtils.isNotBlank(k)) {
-            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();
-            String remark = staf.getRemark() == null ? "" : staf.getRemark();
-            BigDecimal amount = staf.getAmount();
-            String rectifystatus = staf.getRectifystatus();
+        Range titleRange = table.getFirstRow().getRange();
+
+        // 模板行:默认最后两行是一个“图+文”模板
+        List<Row> templateRows = new ArrayList<>();
+        // 模板最后两行用于图文模板结构
+        Row templatePicRow = table.getRows().get(table.getRows().getCount() - 2);
+        Row templateTextRow = table.getLastRow();
+
+        // 删除模板行,避免重复
+        templatePicRow.remove();
+        templateTextRow.remove();
+
+        int i = 1;
+        for (ZhcxPersistentManageDo staf : staff) {
+            // 克隆行
+            Row picRow = (Row) templatePicRow.deepClone(true);
+            Row textRow = (Row) templateTextRow.deepClone(true);
+            // 插入图片
+            String sitepic = staf.getSitepic();
+            Cell cell = picRow.getCells().get(0);
+            cell.getRange().replace("pic", ""); // 清除占位符
             if (StringUtils.isNotBlank(sitepic)) {
-                String[] splits = StringUtils.toString(sitepic, "").split("\\^_\\^");
-                Optional<String> firstId = Arrays.stream(splits)
-                        .filter(s -> s.contains(".jpg")
-                                || s.contains(".jpeg")
-                                || s.contains(".png"))
-                        .findFirst();
-                if (firstId.isPresent()) {
-                    String[] imgIds = firstId.get().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;
-                            }
+                String[] splits = sitepic.split("\\^_\\^");
+                if (splits.length > 0) {
+                    String[] imgIds = splits[0].split("-;-");
+                    if (imgIds.length > 1) {
+                        SysFileItemDo fileItemDo = sysFileItemService.getById(imgIds[1]);
+
+                        if (fileItemDo != null) {
+                            InputStream inputStream = FileUtil.getInputStream(fileItemDo.getFullpath());
+                            DocumentBuilder builder = new DocumentBuilder(doc);
+//                            Cell cellWithPicPlaceholder = null;
+//                            for (Cell cell : picRow.getCells()) {
+//                                if (cell.getRange().getText().contains("pic")) {
+//                                    cellWithPicPlaceholder = cell;
+//                                    break;
+//                                }
+//                            }
+//                            if (cellWithPicPlaceholder != null) {
+//                                // 清除占位符
+//                                cellWithPicPlaceholder.getRange().replace("pic", "");
+//                                // 移动到单元格并插入图片
+//                                builder.moveTo(cellWithPicPlaceholder.getFirstParagraph());
+//                                builder.insertImage(inputStream, 200, 120); // 设置图片宽度和高度
+//                            }
+
+
+                            builder.moveTo(cell.getFirstParagraph());
+                            builder.insertImage(inputStream, 200, 120);
                         }
-
-                        if (cellWithPicPlaceholder != null) {
-                            // 清除占位符
-                            cellWithPicPlaceholder.getRange().replace("pic", "");
-                            // 移动到单元格并插入图片
-                            builder.moveTo(cellWithPicPlaceholder.getFirstParagraph());
-                            builder.insertImage(inputStream, 100, 80); // 设置图片宽度和高度
+                    }
+                }
+            }
+            String afterPic = staf.getAfterrectifypic();
+            Cell cell2 = picRow.getCells().get(1);
+            cell2.getRange().replace("afterpic", ""); // 清除占位符
+            if (StringUtils.isNotBlank(afterPic)) {
+                String[] splits = afterPic.split("\\^_\\^");
+                if (splits.length > 0) {
+                    String[] imgIds = splits[0].split("-;-");
+                    if (imgIds.length > 1) {
+                        SysFileItemDo fileItemDo = sysFileItemService.getById(imgIds[1]);
+
+                        if (fileItemDo != null) {
+                            InputStream inputStream = FileUtil.getInputStream(fileItemDo.getFullpath());
+                            DocumentBuilder builder = new DocumentBuilder(doc);
+
+                            builder.moveTo(cell2.getFirstParagraph());
+                            builder.insertImage(inputStream, 200, 120);
+//                            Cell cellWithPicPlaceholder = null;
+//                            for (Cell cell : picRow.getCells()) {
+//                                if (cell.getRange().getText().contains("afterpic")) {
+//                                    cellWithPicPlaceholder = cell;
+//                                    break;
+//                                }
+//                            }
+//                            if (cellWithPicPlaceholder != null) {
+//                                // 清除占位符
+//                                cellWithPicPlaceholder.getRange().replace("afterpic", "");
+//                                // 移动到单元格并插入图片
+//                                builder.moveTo(cellWithPicPlaceholder.getFirstParagraph());
+//                                builder.insertImage(inputStream, 200, 120); // 设置图片宽度和高度
+//                            }
                         }
                     }
                 }
             }
-            range.replace("index", String.valueOf(i));
-            range.replace("pic", "");
-            range.replace("content", projectcode + projectename + content);
-            range.replace("code", baseinfonum);
-            range.replace("remark", remark);
+
+            // 替换文字变量
+            Range textRange = textRow.getRange();
+            String content = staf.getContent() == null ?"":staf.getContent();
+            String qualityawardname = staf.getQualityawardname() == null ?"":staf.getQualityawardname();
+            String baseInfoNum = staf.getBaseinfonum() == null ?"":staf.getBaseinfonum();
+            String subname = staf.getSubcontractname() == null ?"":staf.getSubcontractname();
+            String firstorgname = staf.getFirstorgname() == null ?"":staf.getFirstorgname();
+            String checkname = staf.getConfirmusername() == null ?"":staf.getConfirmusername();
+            String rectifyStatus = staf.getRectifystatus() == null ?"":staf.getRectifystatus();
+            String confirmdate = staf.getConfirmdate() == null ?"":DateUtil.format(staf.getConfirmdate(), "yyyy/MM/dd");
+            BigDecimal amount = staf.getAmount() == null ?BigDecimal.ZERO:staf.getAmount();
+            textRange.replace("content", content);
+            textRange.replace("tl", qualityawardname);
+            textRange.replace("ts", baseInfoNum);
             if (amount != null) {
-                range.replace("amount", String.valueOf(amount));
-            } else {
-                range.replace("amount", "");
+                textRange.replace("amount", String.valueOf(amount));
+            }else{
+                textRange.replace("amount", "");
             }
-            if ("未整改".equals(rectifystatus)) {
-                rectifystatus = "/";
+            for (Paragraph para : (Iterable<Paragraph>) textRow.getChildNodes(NodeType.PARAGRAPH, true)) {
+                if (para.getText().contains("checkbox")) {
+                    para.getRuns().clear(); // 清空原有内容
+
+                    DocumentBuilder builder = new DocumentBuilder(doc);
+                    builder.moveTo(para);
+
+                    // 插入 “完成” 项
+                    Run cb1 = new Run(doc, "整改完成情况: 完成 ");
+                    Run chk1 = new Run(doc, "已整改".equals(rectifyStatus) ? "☑" : "☐");
+                    chk1.getFont().setName("Segoe UI Symbol");
+                    builder.insertNode(cb1);
+                    builder.insertNode(chk1);
+
+                    builder.write("    ");
+
+                    // 插入 “未完成” 项
+                    Run cb2 = new Run(doc, "未完成 ");
+                    Run chk2 = new Run(doc, "未整改".equals(rectifyStatus) ? "☑" : "☐");
+                    chk2.getFont().setName("Segoe UI Symbol");
+                    builder.insertNode(cb2);
+                    builder.insertNode(chk2);
+
+
+                    break; // 只处理第一个包含 checkbox 的段落
+                }
             }
-            range.replace("status", rectifystatus);
-            range.replace("dept", staf.getFirstorgname() + staf.getSecondorgname() + subcontractename);
-            table.getRows().add(deepClone);
+            textRange.replace("subname", subname);
+            textRange.replace("deptname", firstorgname);
+            textRange.replace("checker",checkname);
+            textRange.replace("completeDate",confirmdate);
+
+            table.getRows().add(picRow);
+            table.getRows().add(textRow);
+            i++;
         }
-        table.getLastRow().remove();
     }
 
+
     /**
      * @Description: 动态复制表格
      * @Param: doc

+ 50 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/SystemDownloadDir.java

@@ -0,0 +1,50 @@
+package com.rongwei.bscommon.sys.utils;
+
+import java.io.File;
+
+public class SystemDownloadDir {
+    // 获取系统默认的下载目录
+    public static String getSystemDownloadPath() {
+        String userHome = System.getProperty("user.home");
+        String os = System.getProperty("os.name").toLowerCase();
+        String downloadDir;
+
+        if (os.contains("win")) {
+            // Windows 系统:C:\Users\<用户名>\Downloads
+            downloadDir = userHome + "\\Downloads";
+        } else if (os.contains("mac")) {
+            // macOS 系统:/Users/<用户名>/Downloads
+            downloadDir = userHome + "/Downloads";
+        } else {
+            // Linux 系统:/home/<用户名>/Downloads 或 /home/<用户名>/下载
+            // 尝试读取 Linux 的 XDG 用户目录配置
+            String xdgDownloadDir = getLinuxDownloadDir(userHome);
+            downloadDir = (xdgDownloadDir != null) ? xdgDownloadDir : userHome + "/Downloads";
+        }
+
+        return downloadDir;
+    }
+
+    // Linux 系统:通过解析 ~/.config/user-dirs.dirs 获取下载目录
+    private static String getLinuxDownloadDir(String userHome) {
+        try {
+            File configFile = new File(userHome, ".config/user-dirs.dirs");
+            if (configFile.exists()) {
+                // 读取文件内容,查找 XDG_DOWNLOAD_DIR
+                String content = new String(java.nio.file.Files.readAllBytes(configFile.toPath()));
+                for (String line : content.split("\n")) {
+                    if (line.startsWith("XDG_DOWNLOAD_DIR")) {
+                        String path = line.split("=")[1]
+                                .replace("\"", "")
+                                .replace("$HOME", userHome)
+                                .trim();
+                        return path;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 33 - 0
business-entity/src/main/java/com/rongwei/bsentity/dto/PersistentDeptDto.java

@@ -0,0 +1,33 @@
+package com.rongwei.bsentity.dto;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.*;
+
+import java.math.BigDecimal;
+
+@Setter
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class PersistentDeptDto {
+
+    /**
+     * 责任部门
+     */
+    private String dutyDeptName;
+
+    private Long selfDeptCount;
+    private Long selfDeptPunishCount;
+
+    private Long productionCount;
+    private Long productionPunishCount;
+
+    private BigDecimal punishmentAmount;
+
+    @JsonIgnore
+    private BigDecimal rate;
+}