Browse Source

房地产报告生成优化

wucl 1 day ago
parent
commit
e595a1a95e
23 changed files with 264 additions and 22 deletions
  1. 1 0
      biz-base/src/main/java/com/dayou/controller/DocumentProductionController.java
  2. 1 0
      biz-base/src/main/java/com/dayou/controller/GlobalConfigController.java
  3. 1 1
      common/src/main/java/com/dayou/constants/HouseGuarantyDoc.java
  4. 34 0
      common/src/main/java/com/dayou/utils/table/WordTableHelper.java
  5. 3 1
      dao/src/main/java/com/dayou/mapper/DocumentProductionMapper.java
  6. 2 0
      dao/src/main/java/com/dayou/mapper/GlobalConfigMapper.java
  7. 4 0
      dao/src/main/java/com/dayou/mapper/UserPostMapper.java
  8. 31 16
      dao/src/main/resources/mapper/DocumentProductionMapper.xml
  9. 11 0
      dao/src/main/resources/mapper/GlobalConfigMapper.xml
  10. 9 1
      dao/src/main/resources/mapper/HouseExcelDataMapper.xml
  11. 11 0
      dao/src/main/resources/mapper/UserPostMapper.xml
  12. 38 0
      domain/src/main/java/com/dayou/doc/house/GuarantyResultDO.java
  13. 5 0
      domain/src/main/java/com/dayou/dto/DocumentProductionQueryDTO.java
  14. 4 0
      domain/src/main/java/com/dayou/entity/DocumentProduction.java
  15. 2 0
      domain/src/main/java/com/dayou/entity/HouseExcelData.java
  16. 2 0
      service/src/main/java/com/dayou/service/GlobalConfigService.java
  17. 4 0
      service/src/main/java/com/dayou/service/UserService.java
  18. 9 1
      service/src/main/java/com/dayou/service/impl/DocumentProductionServiceImpl.java
  19. 10 0
      service/src/main/java/com/dayou/service/impl/GlobalConfigServiceImpl.java
  20. 44 0
      service/src/main/java/com/dayou/service/impl/HouseExcelDataServiceImpl.java
  21. 3 2
      service/src/main/java/com/dayou/service/impl/HouseGuarantyProcessServiceImpl.java
  22. 10 0
      service/src/main/java/com/dayou/service/impl/HouseGuarantyServiceImpl.java
  23. 25 0
      service/src/main/java/com/dayou/service/impl/UserServiceImpl.java

+ 1 - 0
biz-base/src/main/java/com/dayou/controller/DocumentProductionController.java

@@ -1,6 +1,7 @@
 package com.dayou.controller;
 
 
+import cn.dev33.satoken.annotation.SaCheckLogin;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.dayou.dto.DocumentProductionQueryDTO;
 import com.dayou.entity.DocumentProduction;

+ 1 - 0
biz-base/src/main/java/com/dayou/controller/GlobalConfigController.java

@@ -24,4 +24,5 @@ public class GlobalConfigController {
         List<GlobalConfig> ret = globalConfigService.getByType(type);
         return Result.build(ret);
     }
+
 }

+ 1 - 1
common/src/main/java/com/dayou/constants/HouseGuarantyDoc.java

@@ -8,7 +8,7 @@ public class HouseGuarantyDoc {
     /**
      * 表单1
      */
-    public static final String COLLECT1_XLSX = "估价对象一览表_模版.xlsx";
+    public static final String COLLECT1_XLSX = "报告自动生成_模版1.0.xlsx";
 
     /**
      * 估价结果一览表sheet转的json文件

+ 34 - 0
common/src/main/java/com/dayou/utils/table/WordTableHelper.java

@@ -53,6 +53,40 @@ public class WordTableHelper {
         Elements td = document.select("table td");
         td.removeAttr("width");
         td.attr("style",TD_STYLE);
+
+        Elements rows = table.select("tr");
+
+
+        // 获取最后固定后五行
+        int size = rows.size();
+        int startIndex = size - 5;
+
+
+
+        for (int i=startIndex ; i < size; i++){
+            Element cols = rows.get(i);
+            Elements cels = cols.select("td, th");
+            cels.get(0).attr("colspan", "11");
+            cels.get(0).text(cels.get(0).text()+cels.get(1).text());
+            cels.get(1).remove();
+        }
+
+
+        Element firstRowOfMerge = rows.get(startIndex-1);
+        Elements cells = firstRowOfMerge.select("td, th");
+        if (!cells.isEmpty()){
+            cells.get(0).attr("rowspan", "6");
+            StringBuffer sb = new StringBuffer();
+            for (int i = startIndex-1 ; i < size; i++) {
+                String text = rows.get(i).select("td, th").get(0).html()+"<br>";
+                sb.append(text);
+                if (i!=startIndex-1){
+                    rows.get(i).select("td, th").get(0).remove();
+                }
+            }
+            cells.get(0).html(sb.toString());
+
+        }
         return document.body().html();
     }
 

+ 3 - 1
dao/src/main/java/com/dayou/mapper/DocumentProductionMapper.java

@@ -7,9 +7,11 @@ import com.dayou.entity.DocumentProduction;
 import com.dayou.entity.HouseGuarantyProcess;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 public interface DocumentProductionMapper extends BaseMapper<DocumentProduction> {
 
-    Page<DocumentProduction> getPage(Page page, @Param("dto") DocumentProductionQueryDTO dto);
+    Page<DocumentProduction> getPage(Page page, @Param("dto") DocumentProductionQueryDTO dto,@Param("userIds") List<Long> userIds);
 
     /**
      * 通过业务id获取文档信息

+ 2 - 0
dao/src/main/java/com/dayou/mapper/GlobalConfigMapper.java

@@ -8,4 +8,6 @@ import java.util.List;
 
 public interface GlobalConfigMapper extends BaseMapper<GlobalConfig> {
     List<GlobalConfig> getByType(@Param("type") String type);
+
+    String getValueByTypeAndKey(@Param("type") String type, @Param("key") String key);
 }

+ 4 - 0
dao/src/main/java/com/dayou/mapper/UserPostMapper.java

@@ -2,6 +2,9 @@ package com.dayou.mapper;
 
 import com.dayou.entity.UserPost;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface UserPostMapper extends BaseMapper<UserPost> {
 
+    List<Long> getUserByDepartment(@Param("departments") List<String> departments);
 }

+ 31 - 16
dao/src/main/resources/mapper/DocumentProductionMapper.xml

@@ -4,26 +4,41 @@
 
     <select id="getPage" parameterType="com.dayou.entity.DocumentProduction" resultType="com.dayou.entity.DocumentProduction">
         SELECT
-            id,
-            business_type,
-            business_cate,
-            business_id,
-            doc_type,
-            doc_no,
-            doc_name,
-            doc_url,
-            doc_version,
-            is_active,
-            create_time,
-            update_time,
-            consignor
+        dp.id,
+        dp.business_type,
+        dp.business_cate,
+        dp.business_id,
+        dp.doc_type,
+        dp.doc_no,
+        dp.doc_name,
+        dp.doc_url,
+        dp.doc_version,
+        dp.is_active,
+        dp.create_time,
+        dp.update_time,
+        dp.consignor,
+        u.name as createUserName
         FROM
-            document_production
+            document_production as dp
+                left join user u on u.id = dp.create_user_id
         WHERE business_type != 'ASSETS'
             <if test="dto != null and dto.docName != null ">
-                AND doc_name LIKE CONCAT('%', #{dto.docName}, '%')
+                AND dp.doc_name LIKE CONCAT('%', #{dto.docName}, '%')
             </if>
-            AND delete_status = 0 ORDER by update_time DESC
+            <if test="dto !=null and dto.state!=null and dto.state==true">
+                and dp.doc_url is not null
+            </if>
+            <if test="dto !=null and dto.state!=null and dto.state==false">
+                and dp.doc_url is null
+            </if>
+            <if test="userIds!=null and userIds.size()>0">
+                and dp.create_user_id in (
+                <foreach collection="userIds" item="item" index="index" separator=",">
+                    #{item}
+                </foreach>
+                )
+            </if>
+            AND dp.delete_status = 0 ORDER by dp.update_time DESC
     </select>
 
     <!--通过业务id获取文档信息-->

+ 11 - 0
dao/src/main/resources/mapper/GlobalConfigMapper.xml

@@ -19,4 +19,15 @@
             id DESC
     </select>
 
+    <select id="getValueByTypeAndKey" resultType="java.lang.String">
+        SELECT
+            `value`
+        FROM
+            global_config
+        WHERE
+            delete_status = 0
+          AND (
+            type = #{type} and `key` = #{key})
+    </select>
+
 </mapper>

+ 9 - 1
dao/src/main/resources/mapper/HouseExcelDataMapper.xml

@@ -105,7 +105,15 @@
             first_money,
             total_money,
             value_category,
-            doc_date
+            doc_date,
+            affix1,
+            affix2,
+            affix3,
+            affix4,
+            affix5,
+            affix6,
+            affix7,
+            affix8
         FROM
             house_excel_data
         WHERE

+ 11 - 0
dao/src/main/resources/mapper/UserPostMapper.xml

@@ -23,4 +23,15 @@
         user_oa_id, post_name, department_name, role
     </sql>
 
+    <select id="getUserByDepartment" parameterType="java.util.List" resultType="java.lang.Long">
+        SELECT
+            user_id
+        FROM
+            user_post
+        WHERE
+         <foreach collection="departments" separator="or" index="index" item="item">
+             department_name LIKE concat ('%',#{item},'%')
+         </foreach>
+    </select>
+
 </mapper>

+ 38 - 0
domain/src/main/java/com/dayou/doc/house/GuarantyResultDO.java

@@ -187,4 +187,42 @@ public class GuarantyResultDO {
 
     private String docDate;
 
+    /**
+     * 附件列表
+     */
+    private String affixs;
+
+    /**
+     *附件1名称
+     */
+    private String affix1;
+    /**
+     *附件2名称
+     */
+    private String affix2;
+    /**
+     *附件3名称
+     */
+    private String affix3;
+    /**
+     *附件4名称
+     */
+    private String affix4;
+    /**
+     *附件5名称
+     */
+    private String affix5;
+    /**
+     *附件6名称
+     */
+    private String affix6;
+    /**
+     *附件7名称
+     */
+    private String affix7;
+    /**
+     *附件8名称
+     */
+    private String affix8;
+
 }

+ 5 - 0
domain/src/main/java/com/dayou/dto/DocumentProductionQueryDTO.java

@@ -18,4 +18,9 @@ public class DocumentProductionQueryDTO {
      * 文件名称
      */
     private String docName;
+
+    /**
+     * 完成状态
+     */
+    private Boolean state;
 }

+ 4 - 0
domain/src/main/java/com/dayou/entity/DocumentProduction.java

@@ -1,5 +1,6 @@
 package com.dayou.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.dayou.common.BaseEntity;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -74,4 +75,7 @@ public class DocumentProduction extends BaseEntity implements Serializable {
      */
     private Long businessSubId;
 
+    @TableField(exist = false)
+    private String createUserName;
+
 }

+ 2 - 0
domain/src/main/java/com/dayou/entity/HouseExcelData.java

@@ -466,4 +466,6 @@ public class HouseExcelData extends BaseEntity {
     private String totalMoney;
 
 
+
+
 }

+ 2 - 0
service/src/main/java/com/dayou/service/GlobalConfigService.java

@@ -8,4 +8,6 @@ import java.util.List;
 public interface GlobalConfigService extends IService<GlobalConfig> {
 
     List<GlobalConfig> getByType(String type);
+
+    String getValueByTypeAndKey(String type,String key);
 }

+ 4 - 0
service/src/main/java/com/dayou/service/UserService.java

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
+import java.util.List;
+
 /**
  * <p>
  * 服务类
@@ -25,4 +27,6 @@ public interface UserService extends IService<User> {
 
     Boolean delete(Long id);
 
+    List<Long> queryDepartmentMember();
+
 }

+ 9 - 1
service/src/main/java/com/dayou/service/impl/DocumentProductionServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dayou.auth.extra.LoginUserInfo;
 import com.dayou.dto.DocumentProductionQueryDTO;
 import com.dayou.entity.DocumentProduction;
 import com.dayou.enums.BusinessEnum;
@@ -12,10 +13,13 @@ import com.dayou.enums.DocumentType;
 import com.dayou.mapper.DocumentProductionMapper;
 import com.dayou.service.DocumentProductionService;
 import com.dayou.service.HouseExcelDataService;
+import com.dayou.service.UserService;
 import com.dayou.vo.HouseGuarantyBaseVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 import static com.dayou.enums.BusinessEnum.HouseSubBusiness.GUARANTY;
 
 @Service
@@ -28,9 +32,13 @@ public class DocumentProductionServiceImpl extends ServiceImpl<DocumentProductio
     @Autowired
     private HouseExcelDataService houseExcelDataService;
 
+    @Autowired
+    private UserService userService;
+
     @Override
     public Page<DocumentProduction> getPage(DocumentProductionQueryDTO dto, Page page) {
-        return  documentProductionMapper.getPage(page,dto);
+        List<Long> userIds = userService.queryDepartmentMember();
+        return  documentProductionMapper.getPage(page,dto,userIds);
     }
 
     /**

+ 10 - 0
service/src/main/java/com/dayou/service/impl/GlobalConfigServiceImpl.java

@@ -1,5 +1,6 @@
 package com.dayou.service.impl;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dayou.common.BaseEntity;
@@ -21,4 +22,13 @@ public class GlobalConfigServiceImpl extends ServiceImpl<GlobalConfigMapper, Glo
     public List<GlobalConfig> getByType(String type) {
         return globalConfigMapper.getByType(type);
     }
+
+    @Override
+    public String getValueByTypeAndKey(String type, String key) {
+        if (StrUtil.isNotBlank(type) && StrUtil.isNotBlank(key)){
+            key = key.replaceAll(" ","");
+        }
+        return globalConfigMapper.getValueByTypeAndKey(type,key);
+    }
+
 }

+ 44 - 0
service/src/main/java/com/dayou/service/impl/HouseExcelDataServiceImpl.java

@@ -18,6 +18,7 @@ import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.HouseExcelDataMapper;
 import com.dayou.mapper.HouseGuarantyAreaMapper;
 import com.dayou.service.CertificateFixedAssetsService;
+import com.dayou.service.GlobalConfigService;
 import com.dayou.service.HouseExcelDataService;
 import com.dayou.service.HouseGuarantyAreaService;
 import com.dayou.utils.EasyExcelUtil;
@@ -46,6 +47,8 @@ public class HouseExcelDataServiceImpl extends ServiceImpl<HouseExcelDataMapper,
     private HouseExcelDataMapper houseExcelDataMapper;
     @Autowired
     private HouseGuarantyAreaService houseGuarantyAreaService;
+    @Autowired
+    private GlobalConfigService globalConfigService;
 
     @Override
     public Long analysisOriginExcelData(MultipartFile excel,String path) {
@@ -220,6 +223,42 @@ public class HouseExcelDataServiceImpl extends ServiceImpl<HouseExcelDataMapper,
 
         }
         guarantyResultDO.setAreaInfo(docContent.toString());
+        //动态附件列表
+        StringBuffer affixs = new StringBuffer();
+        int index = 1;
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix1())){
+            affixs.append(index+". "+guarantyResultDO.getAffix1()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix2())){
+            affixs.append(index+". "+guarantyResultDO.getAffix2()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix3())){
+            affixs.append(index+". "+guarantyResultDO.getAffix3()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix4())){
+            affixs.append(index+". "+guarantyResultDO.getAffix4()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix5())){
+            affixs.append(index+". "+guarantyResultDO.getAffix5()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix6())){
+            affixs.append(index+". "+guarantyResultDO.getAffix6()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix7())){
+            affixs.append(index+". "+guarantyResultDO.getAffix7()).append("\n");
+            index++;
+        }
+        if (StrUtil.isNotBlank(guarantyResultDO.getAffix8())){
+            affixs.append(index+". "+guarantyResultDO.getAffix8()).append("\n");
+            index++;
+        }
+        guarantyResultDO.setAffixs(affixs.toString());
         return guarantyResultDO;
     }
 
@@ -263,6 +302,11 @@ public class HouseExcelDataServiceImpl extends ServiceImpl<HouseExcelDataMapper,
      */
     private Long doMainContent(XSSFWorkbook workbook,String path ){
         Map<String, String> excelData = EasyExcelUtil.readExcelData(workbook, "正文内容", 1);
+        //获取估价师注册号
+        String appraiser1 = excelData.get("appraiser1");
+        String appraiser2 = excelData.get("appraiser2");
+        excelData.put("appraNo1",globalConfigService.getValueByTypeAndKey("APPRAISER",appraiser1));
+        excelData.put("appraNo2",globalConfigService.getValueByTypeAndKey("APPRAISER",appraiser2));
         HouseExcelData houseExcelData = BeanUtil.fillBeanWithMap(excelData, new HouseExcelData(), true);
         houseExcelData.setBusinessType(BusinessEnum.HouseSubBusiness.GUARANTY.getCode());
         houseExcelData.setUploadUserId(StpUtil.getLoginIdAsLong());

+ 3 - 2
service/src/main/java/com/dayou/service/impl/HouseGuarantyProcessServiceImpl.java

@@ -94,8 +94,9 @@ public class HouseGuarantyProcessServiceImpl extends ServiceImpl<HouseGuarantyPr
         Document cosignorDocument = new Document(baseDir+consignorLetter.getDocUrl());
         Document explainDocument = new Document(baseDir+explain.getDocUrl());
         Document resultDocument = new Document(baseDir+resultReport.getDocUrl());
-        cosignorDocument.appendDocument(explainDocument, ImportFormatMode.KEEP_SOURCE_FORMATTING);
-        cosignorDocument.appendDocument(resultDocument,ImportFormatMode.KEEP_SOURCE_FORMATTING);
+        cosignorDocument.appendDocument(explainDocument, ImportFormatMode.USE_DESTINATION_STYLES);
+        cosignorDocument.appendDocument(resultDocument,ImportFormatMode.USE_DESTINATION_STYLES);
+
         String subUrl = home +"FINAL_REPORT"+System.currentTimeMillis() + ".docx";
         String guarantyResultName = baseDir + subUrl;
         cosignorDocument.save(guarantyResultName);

+ 10 - 0
service/src/main/java/com/dayou/service/impl/HouseGuarantyServiceImpl.java

@@ -109,6 +109,7 @@ public class HouseGuarantyServiceImpl implements HouseGuarantyService {
             fos.write(resultWordByte);
             fos.close();
             insetTable2Word(baseDir + consignorLetterName,baseDir+docHome + TARGETS_DOCX,"targetTable");
+            removeLastPage(baseDir + consignorLetterName);
             return houseGuarantyProcessService.update(new LambdaUpdateWrapper<HouseGuarantyProcess>().set(HouseGuarantyProcess::getDocUrl, consignorLetterName)
                 .eq(BaseEntity::getId, processId));
         } catch (IOException e) {
@@ -223,6 +224,15 @@ public class HouseGuarantyServiceImpl implements HouseGuarantyService {
         mainDoc.save(mainWordPath);
     }
 
+    private void removeLastPage(String wordPath) throws Exception {
+        // 主word文件
+        Document doc = new Document(wordPath);
+        SectionCollection sections = doc.getSections();
+        Section[] array = sections.toArray();
+        array[array.length-1].remove();
+        doc.save(wordPath);
+    }
+
 
     private DocumentProduction buildDocumentProduction(Long id,String docName,String docNo,String consignor){
         DocumentProduction dp = new DocumentProduction();

+ 25 - 0
service/src/main/java/com/dayou/service/impl/UserServiceImpl.java

@@ -1,9 +1,15 @@
 package com.dayou.service.impl;
 
+import cn.dev33.satoken.stp.StpUtil;
+import com.alibaba.fastjson2.JSON;
+import com.dayou.auth.extra.LoginUserInfo;
 import com.dayou.entity.User;
+import com.dayou.entity.UserPost;
 import com.dayou.mapper.UserMapper;
+import com.dayou.mapper.UserPostMapper;
 import com.dayou.service.UserService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -12,6 +18,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.ArrayList;
 import org.springframework.transaction.annotation.Transactional;
@@ -27,6 +36,8 @@ import org.springframework.transaction.annotation.Transactional;
 @Service
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
 
+    @Autowired
+    private UserPostMapper userPostMapper;
 
     @Override
     @SuppressWarnings("unchecked")
@@ -55,4 +66,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         //逻辑删除
         return this.removeById(id);
     }
+
+    @Override
+    public List<Long> queryDepartmentMember() {
+        long userId = StpUtil.getLoginIdAsLong();
+        UserPost userPost = userPostMapper.selectOne(new LambdaQueryWrapper<UserPost>().eq(UserPost::getUserId, userId));
+        String postNameList = userPost.getPostName();
+        List<String> posts = JSON.parseArray(postNameList, String.class);
+        if (posts.contains("评估部经理")){
+            String departmentNameList = userPost.getDepartmentName();
+            List<String> departments = JSON.parseArray(departmentNameList, String.class);
+            return  userPostMapper.getUserByDepartment(departments);
+        }
+        return Arrays.asList(userId);
+    }
 }