|
@@ -1,28 +1,46 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aspose.words.Document;
|
|
|
+import com.aspose.words.ImportFormatMode;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckDetailService;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckParameterSetDetalService;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckParameterSetService;
|
|
|
-import com.rongwei.bsentity.domain.ZhcxCommissionCheckDetailDo;
|
|
|
-import com.rongwei.bsentity.domain.ZhcxCommissionCheckDo;
|
|
|
+import com.rongwei.bscommon.sys.dao.ZhcxCommissionCheckDetailDao;
|
|
|
+import com.rongwei.bscommon.sys.service.*;
|
|
|
+import com.rongwei.bsentity.domain.*;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxCommissionCheckDao;
|
|
|
-import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwei.bsentity.domain.ZhcxCommissionCheckParameterSetDetalDo;
|
|
|
import com.rongwei.bsentity.domain.ZhcxCommissionCheckParameterSetDo;
|
|
|
import com.rongwei.bsentity.dto.CheckDetailDTO;
|
|
|
import com.rongwei.bsentity.dto.CommissionCheckDTO;
|
|
|
+import com.rongwei.bsentity.vo.FormDataVO;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxCommissionCheckDetailWordVO;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxPersistentWordVO;
|
|
|
+import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
|
+import com.rongwei.rwadmincommon.system.service.SysDictService;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.DateUtils;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
|
|
|
+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 org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelExportUtil;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -33,6 +51,7 @@ import java.util.Objects;
|
|
|
* @since 2024-09-24
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCheckDao, ZhcxCommissionCheckDo> implements ZhcxCommissionCheckService {
|
|
|
|
|
|
@Autowired
|
|
@@ -44,6 +63,21 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
@Autowired
|
|
|
private ZhcxCommissionCheckParameterSetDetalService commissionCheckParameterSetDetalService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ZhcxCommissionCheckDetailDao zhcxCommissionCheckDetailDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ZhcxProjectManageService zhcxProjectManageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysFileItemService sysFileItemService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDictService sysDictService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExcelUtils excelUtils;
|
|
|
+
|
|
|
|
|
|
@Transactional(rollbackFor = {java. lang. Exception.class})
|
|
|
@Override
|
|
@@ -280,4 +314,178 @@ public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCh
|
|
|
commissionCheckParameterSetDetalService.updateById(detalDo);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int wordExport(Map<String, Object> map, HttpServletResponse response) {
|
|
|
+ Object projectObj = map.get("projectId");
|
|
|
+ Object machineNoObj = map.get("machineNo");
|
|
|
+ String day = DateUtils.format(new Date());
|
|
|
+ String projectId = (String) projectObj;
|
|
|
+ String machineNo = (String) machineNoObj;
|
|
|
+ ZhcxProjectManageDo projectManageDo = zhcxProjectManageService.getById(projectId);
|
|
|
+ List<ZhcxCommissionCheckDetailDo> list = zhcxCommissionCheckDetailDao.listData(map);
|
|
|
+ if(list.size() == 0){
|
|
|
+ return 1;
|
|
|
+ }else {
|
|
|
+ //根据分类分组
|
|
|
+ Map<String, List<ZhcxCommissionCheckDetailDo>> groupList = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZhcxCommissionCheckDetailDo::getOnelevelclassification));
|
|
|
+ SysFileItemDo fileItemDo = sysFileItemService.getById("d1b3271ce2ec45c2915f2dbcd819f45a");
|
|
|
+ final Document[] doc = {WordHelpUtils.getDoc(fileItemDo.getFullpath())};
|
|
|
+ AtomicInteger i = new AtomicInteger();
|
|
|
+ FormData formData = new FormData();
|
|
|
+ List<Map<String,Object>> mainDataList = new ArrayList<>();
|
|
|
+ Map<String,Object> mainMap = new HashMap<>(16);
|
|
|
+ String projectEnName = "";
|
|
|
+ if (StringUtils.isNotBlank(projectManageDo.getProjectEnName())){
|
|
|
+ projectEnName = projectManageDo.getProjectEnName();
|
|
|
+ }
|
|
|
+ mainMap.put("projectNames",projectManageDo.getProjectName()+projectEnName);
|
|
|
+ mainMap.put("projectCode",projectManageDo.getProjectCode());
|
|
|
+ mainMap.put("currentDate",day);
|
|
|
+ mainMap.put("machineNo",machineNo);
|
|
|
+ mainDataList.add(mainMap);
|
|
|
+ formData.setMainDataList(mainDataList);
|
|
|
+ doc[0] = ExcelExportUtil.fillWordDataByMap(fileItemDo.getFullpath(), formData);
|
|
|
+ List<JSONObject> resultType = zhcxCommissionCheckDetailDao.getResultDictList();
|
|
|
+ groupList.forEach((k, v) -> {
|
|
|
+ List<ZhcxCommissionCheckDetailWordVO> detailWordVOList = new ArrayList<>();
|
|
|
+ List<ZhcxCommissionCheckDetailDo> detailDos = v;
|
|
|
+ for (ZhcxCommissionCheckDetailDo detailDo:detailDos){
|
|
|
+ ZhcxCommissionCheckDetailWordVO checkDetailWordVO = new ZhcxCommissionCheckDetailWordVO();
|
|
|
+ checkDetailWordVO.setChapterno(detailDo.getChapterno());
|
|
|
+ checkDetailWordVO.setContent(detailDo.getChtestcontent()+detailDo.getEntitle());
|
|
|
+ String testresult = "";
|
|
|
+ String testdata = "";
|
|
|
+ if (StringUtils.isNotBlank(detailDo.getTestresult())){
|
|
|
+ testresult = resultType.stream().filter(dictDo -> detailDo.getTestresult().contains(dictDo.getString("VALUE"))).findFirst().get().getString("NAME").toString();
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(detailDo.getTestdata())){
|
|
|
+ testdata = detailDo.getTestdata();
|
|
|
+ }
|
|
|
+ checkDetailWordVO.setResult(testresult+testdata);
|
|
|
+ String testnotes = "";
|
|
|
+ if (StringUtils.isNotBlank(detailDo.getTestnotes())){
|
|
|
+ testnotes = detailDo.getTestnotes();
|
|
|
+ }
|
|
|
+ checkDetailWordVO.setTestnotes(testnotes);
|
|
|
+ detailWordVOList.add(checkDetailWordVO);
|
|
|
+ }
|
|
|
+ List<List<Map<String,Object>>> slaveTableDataList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> maps = convertNewList(detailWordVOList, ZhcxCommissionCheckDetailWordVO.class);
|
|
|
+ slaveTableDataList.add(maps);
|
|
|
+ FormDataVO formDataVo = new FormDataVO();
|
|
|
+ Map<String,Object> mainDetailMap = new HashMap<>(16);
|
|
|
+ List<Map<String,Object>> mainDetailDataList = new ArrayList<>();
|
|
|
+ mainDetailMap.put("chtitle",k);
|
|
|
+ mainDetailMap.put("entitle",v.get(0).getEntitle());
|
|
|
+ mainDetailDataList.add(mainDetailMap);
|
|
|
+ formDataVo.setMainDataList(mainDetailDataList);
|
|
|
+ formDataVo.setSlaveTableDataList(slaveTableDataList);
|
|
|
+ try {
|
|
|
+ SysFileItemDo fileTemp = sysFileItemService.getById("b199958d6ce64d4a9d36e9e9ac20ab59");
|
|
|
+ Document docTemp = fillWordDataByMap(fileTemp.getFullpath(), formDataVo);
|
|
|
+ doc[0].appendDocument(docTemp, ImportFormatMode.KEEP_DIFFERENT_STYLES);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("导出word失败:"+e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ doc[0].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));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("导出word失败:"+e);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private <T> List<Map<String, Object>> convertNewList(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
|
|
|
+ Class<? super T> superclass = clazz.getSuperclass();
|
|
|
+ Field[] declaredFields = superclass.getDeclaredFields();
|
|
|
+ Field[] fields = clazz.getDeclaredFields();
|
|
|
+ Field[] fields1 = Stream.concat(Arrays.stream(fields), Arrays.stream(declaredFields))
|
|
|
+ .toArray(Field[]::new);
|
|
|
+ for (Field field : fields1) {
|
|
|
+ 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, "/");
|
|
|
+ }
|
|
|
+ }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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充 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;
|
|
|
+ }
|
|
|
}
|