|
@@ -0,0 +1,167 @@
|
|
|
|
+package com.dayou.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
+import com.aspose.cells.SaveFormat;
|
|
|
|
+import com.aspose.cells.Workbook;
|
|
|
|
+import com.aspose.words.Document;
|
|
|
|
+import com.aspose.words.DocumentBuilder;
|
|
|
|
+import com.aspose.words.Paragraph;
|
|
|
|
+import com.dayou.config.FileNetConfig;
|
|
|
|
+import com.dayou.doc.house.ConsignorLetterDO;
|
|
|
|
+import com.dayou.entity.HouseGuarantyProcess;
|
|
|
|
+import com.dayou.exception.ErrorCode;
|
|
|
|
+import com.dayou.service.HouseGuarantyProcessService;
|
|
|
|
+import com.dayou.service.HouseGuarantyService;
|
|
|
|
+import com.dayou.utils.AsposeWordUtil;
|
|
|
|
+import com.dayou.utils.EasyExcelUtil;
|
|
|
|
+import com.dayou.utils.HouseDocumentUtil;
|
|
|
|
+import com.dayou.utils.JsonUtil;
|
|
|
|
+import com.dayou.utils.table.WordTableHelper;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+import static com.dayou.constants.HouseGuarantyDoc.*;
|
|
|
|
+import static com.dayou.enums.HouseTargetTableColumn.ID;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class HouseGuarantyServiceImpl implements HouseGuarantyService {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private WordTableHelper wordTableHelper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private HouseGuarantyProcessService houseGuarantyProcessService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FileNetConfig fileNetConfig;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String createTableWord(String html,String homePath) {
|
|
|
|
+ html = wordTableHelper.htmlTableFormat(html);
|
|
|
|
+ HouseGuarantyProcess hgp = new HouseGuarantyProcess();
|
|
|
|
+ hgp.setHome(homePath);
|
|
|
|
+ hgp.setTargetsHtml(html);
|
|
|
|
+ houseGuarantyProcessService.save(hgp);
|
|
|
|
+ return wordTableHelper.createTableWord(html, fileNetConfig.getBaseDir() + homePath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean analysisCollect1(Long id) {
|
|
|
|
+ HouseGuarantyProcess process = houseGuarantyProcessService.getById(id);
|
|
|
|
+ String home = fileNetConfig.getBaseDir() + process.getHome();
|
|
|
|
+ try {
|
|
|
|
+ Workbook workbook = new Workbook( home + COLLECT1_XLSX);
|
|
|
|
+ workbook.save(home+ COLLECT1_JSON, SaveFormat.JSON);
|
|
|
|
+ JSONArray array = JsonUtil.file2JsonArray(home + COLLECT1_JSON, TARGETS_TABLE_ZH);
|
|
|
|
+ //解析估价对象json
|
|
|
|
+ JSONArray xArray = HouseDocumentUtil.houseTargetsFormat(array);
|
|
|
|
+ //纯估价对象
|
|
|
|
+ JsonUtil.jsonArray2File(xArray,home + TARGETS_JSON);
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"Json文件读取错误");
|
|
|
|
+ return Boolean.FALSE;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String genConsignorLetter(Long id) {
|
|
|
|
+ HouseGuarantyProcess process = houseGuarantyProcessService.getById(id);
|
|
|
|
+ String home = fileNetConfig.getBaseDir() + process.getHome();
|
|
|
|
+ try {
|
|
|
|
+ // 读取估价对象地址
|
|
|
|
+ JSONArray array = JsonUtil.file2JsonArray(home + TARGETS_JSON);
|
|
|
|
+
|
|
|
|
+ //读取基本信息
|
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(home + COLLECT1_XLSX);
|
|
|
|
+ Map<String, String> valueMap = EasyExcelUtil.getExcelCellValue(workbook, BASE_INFO_ZH);
|
|
|
|
+ ConsignorLetterDO clDO = JSON.parseObject(JSON.toJSONString(valueMap), ConsignorLetterDO.class);
|
|
|
|
+ clDO.setProjectName(HouseDocumentUtil.getProjectName(array));
|
|
|
|
+ Map<Object, List<Object>> collect = array.stream().collect(Collectors.groupingBy(x -> ((JSONObject) x).get(ID.getZhName())));
|
|
|
|
+ String actDesc = "";
|
|
|
|
+ int index = 1;
|
|
|
|
+ int mapSize = collect.size();
|
|
|
|
+ for (Map.Entry<Object, List<Object>> entry : collect.entrySet()) {
|
|
|
|
+ List<Object> value = entry.getValue();
|
|
|
|
+ JSONArray xArray = new JSONArray(value);
|
|
|
|
+ String actAddress = HouseDocumentUtil.getTargetDescription(xArray);
|
|
|
|
+ //添加换行符
|
|
|
|
+ if (index != mapSize){
|
|
|
|
+ actAddress += "\n";
|
|
|
|
+ }
|
|
|
|
+ actDesc += actAddress;
|
|
|
|
+ index ++;
|
|
|
|
+ }
|
|
|
|
+ clDO.setActDesc(actDesc);
|
|
|
|
+ String ownShipUser = HouseDocumentUtil.getOwnShipUser(array);
|
|
|
|
+
|
|
|
|
+ if (!"".equals(ownShipUser) && !ownShipUser.contains(clDO.getConsignor())){
|
|
|
|
+ clDO.setBlank("");
|
|
|
|
+ clDO.setOwnship("不动产权利人:");
|
|
|
|
+ clDO.setOwnshipUser(ownShipUser);
|
|
|
|
+ }
|
|
|
|
+ byte[] tmplWordByte = Files.readAllBytes(Paths.get(fileNetConfig.getBaseDir()
|
|
|
|
+ + fileNetConfig.getHouseGuarantyTemplatePath() + CONSIGNOR_LETTER_TEMPLATE));
|
|
|
|
+ byte[] resultWordByte = AsposeWordUtil.fillWordDataByDomain(tmplWordByte, clDO);
|
|
|
|
+ String consignorLetterName = home + System.currentTimeMillis() + ".docx";
|
|
|
|
+ File resultFile = new File(consignorLetterName);
|
|
|
|
+ FileOutputStream fos = new FileOutputStream(resultFile);
|
|
|
|
+ fos.write(resultWordByte);
|
|
|
|
+ fos.close();
|
|
|
|
+ insetTargetTableWord(consignorLetterName,home + TARGETS_DOCX);
|
|
|
|
+ return consignorLetterName;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 插入估价结果一览表word文件
|
|
|
|
+ * @param mainWordPath
|
|
|
|
+ * @param tableWordPath
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private void insetTargetTableWord(String mainWordPath,String tableWordPath) throws Exception{
|
|
|
|
+ // 主word文件
|
|
|
|
+ Document mainDoc = new Document(mainWordPath);
|
|
|
|
+
|
|
|
|
+ //删除空白行
|
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(mainDoc);
|
|
|
|
+ builder.moveToMergeField("blank");
|
|
|
|
+ Paragraph currentParagraph2 = builder.getCurrentParagraph();
|
|
|
|
+ if (currentParagraph2.getParentNode() != null){
|
|
|
|
+ currentParagraph2.remove();
|
|
|
|
+ }
|
|
|
|
+ builder.moveToMergeField("ownship");
|
|
|
|
+ Paragraph currentParagraph = builder.getCurrentParagraph();
|
|
|
|
+ if (currentParagraph.getParentNode() != null){
|
|
|
|
+ currentParagraph.remove();
|
|
|
|
+ }
|
|
|
|
+ builder.moveToMergeField("ownshipUser");
|
|
|
|
+ Paragraph currentParagraph1 = builder.getCurrentParagraph();
|
|
|
|
+ if (currentParagraph1.getParentNode() != null){
|
|
|
|
+ currentParagraph1.remove();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 需要插入的word文件
|
|
|
|
+ Document subDoc = new Document(tableWordPath);
|
|
|
|
+
|
|
|
|
+ mainDoc = AsposeWordUtil.insertDocumentAfterBookMark(mainDoc, subDoc, "targetTable", false);
|
|
|
|
+ // 保存文件
|
|
|
|
+ mainDoc.save(mainWordPath);
|
|
|
|
+ }
|
|
|
|
+}
|