瀏覽代碼

Merge remote-tracking branch 'origin/master'

liuyc 1 年之前
父節點
當前提交
6577265c53

+ 16 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/ContractTreeDrawingsController.java

@@ -16,6 +16,7 @@
  */
 package org.springblade.business.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -83,4 +84,19 @@ public class ContractTreeDrawingsController extends BladeController {
         }
     }
 
+    /**
+     * 根据节点pkeyId查看图纸
+     */
+    @GetMapping("/getTreeDrawings")
+    @ApiOperationSupport(order = 2)
+    @ApiOperation(value = "获取节点图纸,传入接单PkeyId")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "primaryKeyId", value = "节点primaryKeyId", required = true)
+    })
+    public R<String> getTreeDrawings(Long primaryKeyId){
+        ContractTreeDrawings one = contractTreeDrawingsService.getOne(new LambdaQueryWrapper<ContractTreeDrawings>()
+                .eq(ContractTreeDrawings::getProcessId, primaryKeyId));
+        return R.data(one.getFileUrl());
+    }
+
 }

+ 1 - 1
blade-service/blade-land/src/main/java/org/springblade/land/controller/AgreementFileController.java

@@ -60,7 +60,7 @@ public class AgreementFileController {
             @ApiImplicitParam(name = "agreementId", value = "协议id", required = true)
     })
     public R<List<AgreementFile>> getFileList(Long agreementId) {
-        return R.data(fileService.list(new LambdaQueryWrapper<AgreementFile>().eq(AgreementFile::getAgreementId,agreementId)));
+        return R.data(fileService.getFileList(agreementId));
     }
 
 

+ 48 - 11
blade-service/blade-land/src/main/java/org/springblade/land/controller/CompensationInfoController.java

@@ -38,18 +38,33 @@ public class CompensationInfoController extends BladeController {
     private final ICompensationInfoService compensationInfoService;
 
 
+//    /**
+//     * 新增协议
+//     */
+//    @GetMapping("/add")
+//    @ApiOperationSupport(order = 1)
+//    @ApiOperation(value = "新增协议", notes = "返回协议id")
+//    @ApiImplicitParams({
+//            @ApiImplicitParam(name = "projectId", value = "项目id", required = true),
+//            @ApiImplicitParam(name = "areaId", value = "当前树节点id", required = true),
+//            @ApiImplicitParam(name = "type", value = "协议类型1征地补偿2坟地补偿3专项设施", required = true)
+//    })
+//    public R<Long> add(Long projectId,Long areaId,Integer type){
+//        return R.data(compensationInfoService.add(projectId,areaId,type));
+//    }
+
     /**
      * 新增协议
      */
     @GetMapping("/add")
     @ApiOperationSupport(order = 1)
-    @ApiOperation(value = "新增协议", notes = "返回协议id")
+    @ApiOperation(value = "新增协议", notes = "返回协议列表")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "projectId", value = "项目id", required = true),
             @ApiImplicitParam(name = "areaId", value = "当前树节点id", required = true),
             @ApiImplicitParam(name = "type", value = "协议类型1征地补偿2坟地补偿3专项设施", required = true)
     })
-    public R<Long> add(Long projectId,Long areaId,Integer type){
+    public R<List<AgreementLinkTable>> add(Long projectId,Long areaId,Integer type){
         return R.data(compensationInfoService.add(projectId,areaId,type));
     }
 
@@ -74,10 +89,10 @@ public class CompensationInfoController extends BladeController {
     @ApiOperationSupport(order = 3)
     @ApiOperation(value = "协议表单-生成html", notes = "协议表单-生成html")
     @ApiImplicitParams(value = {
-            @ApiImplicitParam(name = "id", value = "当前表单id", required = true)
+            @ApiImplicitParam(name = "tableId", value = "当前表单tableId", required = true)
     })
-    public R getExcelHtmlByBuss(Long id) throws Exception {
-        return compensationInfoService.getExcelHtmlByBuss(id);
+    public R getExcelHtmlByBuss(Long tableId) throws Exception {
+        return compensationInfoService.getExcelHtmlByBuss(tableId);
     }
 
 
@@ -88,10 +103,10 @@ public class CompensationInfoController extends BladeController {
     @ApiOperationSupport(order = 4)
     @ApiOperation(value = "协议表单-获取坐标位置", notes = "协议表单-获取坐标位置")
     @ApiImplicitParams(value = {
-            @ApiImplicitParam(name = "id", value = "当前表单id", required = true)
+            @ApiImplicitParam(name = "tableId", value = "当前表单的tableId", required = true)
     })
-    public R getHtmlBussCols(Long id) throws Exception {
-        return compensationInfoService.getHtmlBussCols(id);
+    public R getHtmlBussCols(Long tableId) throws Exception {
+        return compensationInfoService.getHtmlBussCols(tableId);
     }
 
     /**
@@ -102,11 +117,33 @@ public class CompensationInfoController extends BladeController {
     @ApiOperation(value = "协议表单-获取用户保存数据", notes = "协议表单-获取用户保存数据")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(name = "id", value = "当前表单的id", required = true),
+            @ApiImplicitParam(name = "tableId", value = "当前表单的tableId", required = true),
     })
-    public R getBussDataInfo(Long id) throws FileNotFoundException {
-        return compensationInfoService.getBussDataInfo(id);
+    public R getBussDataInfo(Long id,Long tableId)  {
+        return compensationInfoService.getBussDataInfo(id,tableId);
     }
 
+//    /**
+//     * 用户保存接口
+//     * @param dataInfo
+//     * @return
+//     * @throws Exception
+//     */
+//    @PostMapping("/save_buss_data")
+//    @ApiOperationSupport(order = 6)
+//    @ApiOperation(value = "填报页面数据保存", notes = "填报页面数据保存,返回当前协议id")
+//    @ApiImplicitParams(value = {
+//            @ApiImplicitParam(name = "projectId", value = "项目id", required = true),
+//            @ApiImplicitParam(name = "agreementId", value = "协议的id,修改时放的agreementId", required = true),
+//            @ApiImplicitParam(name = "linkId", value = "当前表单的id,修改时返回的id", required = true),
+//            @ApiImplicitParam(name = "areaId", value = "当前树节点id", required = true),
+//            @ApiImplicitParam(name = "tableId", value = "表单的tableId", required = true)
+//    })
+//    public R saveBussData(@Valid @RequestBody JSONObject dataInfo) throws Exception {
+//        return compensationInfoService.saveBussData(dataInfo);
+//    }
+
+
     /**
      * 用户保存接口
      * @param dataInfo
@@ -123,7 +160,7 @@ public class CompensationInfoController extends BladeController {
             @ApiImplicitParam(name = "areaId", value = "当前树节点id", required = true),
             @ApiImplicitParam(name = "tableId", value = "表单的tableId", required = true)
     })
-    public R saveBussData(@Valid @RequestBody JSONObject dataInfo) throws Exception {
+    public R saveBussData(@RequestBody JSONObject dataInfo){
         return compensationInfoService.saveBussData(dataInfo);
     }
 

+ 3 - 0
blade-service/blade-land/src/main/java/org/springblade/land/mapper/CompensationInfoMapper.java

@@ -81,4 +81,7 @@ public interface CompensationInfoMapper extends BaseMapper<CompensationInfo> {
     List<Long> getPdfIsNull(@Param("projectId") Long projectId);
 
     void deleteBatch(@Param("ids") List<Long> ids);
+
+    //根据tableId直接获取项目下表单
+    WbsTreePrivate getTableInfo(@Param("tableId") Long id);
 }

+ 3 - 0
blade-service/blade-land/src/main/java/org/springblade/land/mapper/CompensationInfoMapper.xml

@@ -105,6 +105,9 @@
     <select id="getPdfIsNull" resultType="java.lang.Long">
         select id from l_compensation_info where project_id = #{projectId} and merge_pdf_url is null
     </select>
+    <select id="getTableInfo" resultType="org.springblade.manager.entity.WbsTreePrivate">
+        SELECT * FROM m_wbs_tree_private WHERE init_table_id = #{tableId} limit 1
+    </select>
 
 
 </mapper>

+ 3 - 0
blade-service/blade-land/src/main/java/org/springblade/land/service/IAgreementFileService.java

@@ -23,6 +23,8 @@ import org.springblade.land.dto.SettlementIntervalDTO;
 import org.springblade.land.entity.AgreementFile;
 import org.springblade.land.entity.SettlementInterval;
 
+import java.util.List;
+
 
 /**
  *  服务类
@@ -33,4 +35,5 @@ import org.springblade.land.entity.SettlementInterval;
 public interface IAgreementFileService extends IService<AgreementFile> {
 
 
+    List<AgreementFile> getFileList(Long agreementId);
 }

+ 3 - 3
blade-service/blade-land/src/main/java/org/springblade/land/service/ICompensationInfoService.java

@@ -50,9 +50,9 @@ public interface ICompensationInfoService extends BaseService<CompensationInfo>
 
     R getHtmlBussCols(Long id) throws Exception;
 
-    R getBussDataInfo(Long linkId);
+    R getBussDataInfo(Long linkId,Long tableId);
 
-    R saveBussData(JSONObject dataInfo) throws Exception;
+    R saveBussData(JSONObject dataInfo);
 
     R getBussPdfDataInfo(Long id);
 
@@ -66,7 +66,7 @@ public interface ICompensationInfoService extends BaseService<CompensationInfo>
 
     IPage<CompensationInfo> page (Query query,CompensationInfo info);
 
-    Long add(Long projectId, Long areaId, Integer type);
+    List<AgreementLinkTable> add(Long projectId, Long areaId, Integer type);
 
     void remove(List<Long> ids);
 

+ 9 - 0
blade-service/blade-land/src/main/java/org/springblade/land/service/impl/AgreementFileServiceImpl.java

@@ -1,6 +1,7 @@
 package org.springblade.land.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.AllArgsConstructor;
 import org.springblade.core.log.exception.ServiceException;
@@ -22,4 +23,12 @@ import java.util.List;
 public class AgreementFileServiceImpl extends ServiceImpl<AgreementFileMapper, AgreementFile> implements IAgreementFileService {
 
 
+    @Override
+    public List<AgreementFile> getFileList(Long agreementId) {
+        if (agreementId == null){
+            throw new ServiceException("请先保存一次资料再上传附件");
+        }else {
+            return this.list(new LambdaQueryWrapper<AgreementFile>().eq(AgreementFile::getAgreementId,agreementId));
+        }
+    }
 }

+ 101 - 48
blade-service/blade-land/src/main/java/org/springblade/land/service/impl/CompensationInfoServiceImpl.java

@@ -96,7 +96,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
     @Override
     public R getExcelHtmlByBuss(Long id) throws Exception {
         //获取表单信息
-        AgreementLinkTable linkTable = linkTableService.getById(id);
+        WbsTreePrivate linkTable = baseMapper.getTableInfo(id);
         if (StringUtils.isBlank(linkTable.getHtmlUrl())){
             return R.fail("没有获取到表单!");
         }
@@ -111,7 +111,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         Document doc = Jsoup.parse(htmlString);
         Element table = doc.select("table").first();
         // 添加标题显示
-        ProjectInfo projectInfo = baseMapper.getProjectInfo(linkTable.getProjectId());
+        ProjectInfo projectInfo = baseMapper.getProjectInfo(Long.parseLong(linkTable.getProjectId()));
         Elements trs = table.select("tr");
         for (int i = 1; i < 6; i++) {
             Element tr = trs.get(i);
@@ -140,7 +140,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
         String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
         //获取表单信息
-        AgreementLinkTable linkTable = linkTableService.getById(id);
+        WbsTreePrivate linkTable = baseMapper.getTableInfo(id);
         String fileUrl = linkTable.getHtmlUrl();
         if (StringUtils.isBlank(fileUrl)){
             return R.fail("没有获取到表单!");
@@ -195,7 +195,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
      * 协议表单获取用户保存数据
      */
     @Override
-    public R getBussDataInfo(Long linkId) {
+    public R getBussDataInfo(Long linkId,Long tableId) {
         Map<String, Object> reData = new HashMap<>();
         //获取表单数据
         List<Map<String, Object>> mapList = baseMapper.getBussDataInfo(linkId);
@@ -207,10 +207,21 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         }
         //需要自动生成的字典集合,项目名称197
         List<Integer> buildDict = Arrays.asList(197);
+        String htmlUrl;
+        Long projectId;
         //获取当前表单
         AgreementLinkTable linkTable = linkTableService.getById(linkId);
+        //如果是新增,中间表是空的,就直接去获取项目下的表单配置
+        if (linkTable == null){
+            WbsTreePrivate wbs = baseMapper.getTableInfo(tableId);
+            htmlUrl = wbs.getHtmlUrl();
+            projectId = Long.parseLong(wbs.getProjectId());
+        }else {
+            htmlUrl = linkTable.getHtmlUrl();
+            projectId = linkTable.getProjectId();
+        }
         //获取当前表单配置字典
-        List<WbsFormElement> tableElement = baseMapper.getTableElement(Arrays.asList(linkTable.getTableId()));
+        List<WbsFormElement> tableElement = baseMapper.getTableElement(Arrays.asList(tableId));
         Map<Integer, List<WbsFormElement>> map = tableElement.stream().collect(Collectors.groupingBy(WbsFormElement::getDynamicDict));
         List<Integer> list = tableElement.stream().map(l -> l.getDynamicDict()).collect(Collectors.toList());
         //获取当前表单内需要自动生成的字典
@@ -219,7 +230,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         if (list.size() > 0) {
             Document doc = null;
             try {
-                doc = Jsoup.parse(new File(linkTable.getHtmlUrl()), "utf-8");
+                doc = Jsoup.parse(new File(htmlUrl), "utf-8");
 //                doc = Jsoup.parse(new File("C:\\Users\\泓创研发01\\Desktop\\privateUrl\\1704045947043971072.html"), "utf-8");
             } catch (IOException e) {
                 throw new ServiceException("解析表单html出错");
@@ -242,7 +253,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
                 switch (dict){
                     case 197 :
                         //项目名称
-                        String projectName = jdbcTemplate.queryForObject("select project_name from m_project_info where id = " + linkTable.getProjectId(), String.class);
+                        String projectName = jdbcTemplate.queryForObject("select project_name from m_project_info where id = " + projectId, String.class);
                         reData.put(key,projectName);
                         break;
                 }
@@ -256,7 +267,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
      */
     @Override
     @Transactional
-    public R saveBussData(JSONObject dataInfo) throws Exception {
+    public R saveBussData(JSONObject dataInfo){
         JSONArray dataArray = new JSONArray();
         if (dataInfo.containsKey("dataInfo")) { //节点保存
             JSONObject jsonObject = dataInfo.getJSONObject("dataInfo");
@@ -267,6 +278,61 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         JSONObject tableInfo1 = dataArray.getJSONObject(0);
         Long id = tableInfo1.getLong("agreementId");
         Long areaId = tableInfo1.getLong("areaId");
+        Long projectId = tableInfo1.getLong("projectId");
+        Integer agreeType = Math.toIntExact(tableInfo1.getLong("type"));
+        //如果id为null证明从来没保存过,先新增
+        if (id == null){
+            //补偿id
+            Long agreeId = SnowFlakeUtil.getId();
+            //先新增中间表
+            List<WbsTreePrivate> tables = baseMapper.getTables(projectId, agreeType);
+            //ExcelId与中间表id的映射
+            Map<Long,Long> map = new HashMap<>();
+            for (int i = 0; i < dataArray.size(); i++) {
+                JSONObject jsonObject = dataArray.getJSONObject(i);
+                map.put(jsonObject.getLong("tableId"),jsonObject.getLong("linkId"));
+            }
+            List<AgreementLinkTable> linkTables = tables.stream().map(l -> {
+                AgreementLinkTable table = new AgreementLinkTable();
+                table.setTableId(Long.parseLong(l.getInitTableId()));
+                table.setProjectId(projectId);
+                table.setTableDataId(SnowFlakeUtil.getId());
+                if (map.get(Long.parseLong(l.getInitTableId())) != null){
+                    table.setId(map.get(Long.parseLong(l.getInitTableId())));
+                }else {
+                    table.setId(SnowFlakeUtil.getId());
+                }
+                table.setAgreementId(agreeId);
+                table.setPrivateId(l.getId());
+                table.setSort(l.getSort());
+                table.setExcelId(l.getExcelId());
+                table.setHtmlUrl(l.getHtmlUrl());
+                table.setTableName(l.getNodeName());
+                return table;
+            }).collect(Collectors.toList());
+            id = agreeId;
+            linkTableService.saveBatch(linkTables);
+            for (int i = 0; i < dataArray.size(); i++) {
+                JSONObject jsonObject = dataArray.getJSONObject(i);
+                jsonObject.put("linkId",map.get(jsonObject.getLong("tableId")));
+            }
+            //再保存协议
+            CompensationInfo info = new CompensationInfo();
+            info.setId(agreeId);
+            info.setName("默认名称");
+            //获取当前节点名称
+            RegionTreeInfo treeInfo = treeInfoService.getById(areaId);
+            //获取编号
+            String num = getNumber(areaId);
+            info.setNumber(treeInfo.getAreaName()+num);
+            info.setAreaId(areaId);
+            info.setProjectId(projectId);
+            info.setType(agreeType);
+            info.setLandMoney(new BigDecimal(0));
+            info.setCropsMoney(new BigDecimal(0));
+            info.setAllMoney(new BigDecimal(0));
+            this.save(info);
+        }
         //中间表tableId与dataId的映射
         Map<Long,Long> linkMap = new HashMap<>();
         //获取表单id与数据id的映射
@@ -276,14 +342,18 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         }
         linkTables.stream().forEach(l->linkMap.put(l.getTableDataId(),l.getTableId()));
 
-        for (int i=0; i<dataArray.size();i++) {
-            JSONObject jsonObject = dataArray.getJSONObject(i);
-            //删除原来保存的数据
-            baseMapper.deleteOldData(jsonObject.getLong("linkId"));
-            this.SaveOneTabInfo(jsonObject);
+        try {
+            for (int i = 0; i < dataArray.size(); i++) {
+                JSONObject jsonObject = dataArray.getJSONObject(i);
+                //删除原来保存的数据
+                baseMapper.deleteOldData(jsonObject.getLong("linkId"));
+                this.SaveOneTabInfo(jsonObject);
+            }
+            //合并PDF
+            this.mergePdfs(id);
+        }catch (Exception e){
+            throw new ServiceException("合并PDF出现异常");
         }
-        //合并PDF
-        this.mergePdfs(id);
         //地类补偿金额
         BigDecimal b1 = new BigDecimal(0);
         //青苗
@@ -450,7 +520,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
         }
         //保存协议信息
         this.updateById(info);
-        return R.success("保存成功");
+        return R.data(200,id,"保存成功");
     }
 
     @Override
@@ -498,6 +568,9 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
     @Override
     public R updateCopeTab(Long id) {
         AgreementLinkTable linkTable = linkTableService.getById(id);
+        if (linkTable == null){
+            throw new ServiceException("请先保存一次表单再复制");
+        }
         AgreementLinkTable table = new AgreementLinkTable();
         BeanUtils.copyProperties(linkTable,table);
         table.setId(null);
@@ -514,53 +587,33 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
     @Override
     public IPage<CompensationInfo> page(Query query, CompensationInfo info) {
         //查看列表先删除之前未保存的补偿协议
-        List<Long> ids = baseMapper.getPdfIsNull(info.getProjectId());
-        if (ids != null && ids.size() > 0){
-            linkTableService.deleteByAgreementIds(ids);
-            baseMapper.deleteBatch(ids);
-        }
+//        List<Long> ids = baseMapper.getPdfIsNull(info.getProjectId());
+//        if (ids != null && ids.size() > 0){
+//            linkTableService.deleteByAgreementIds(ids);
+//            baseMapper.deleteBatch(ids);
+//        }
         IPage<CompensationInfo> iPage = new Page<>(query.getCurrent(),query.getSize());
         return baseMapper.page(iPage,info);
     }
 
+
     @Override
-    public Long add(Long projectId, Long areaId, Integer type) {
-        //新增复制
-        Long agreeId = SnowFlakeUtil.getId();
-        //先新增中间表,再复制
+    public List<AgreementLinkTable> add(Long projectId, Long areaId, Integer type) {
+        //获取列表
         List<WbsTreePrivate> tables = baseMapper.getTables(projectId, type);
         List<AgreementLinkTable> linkTables = tables.stream().map(l -> {
             AgreementLinkTable table = new AgreementLinkTable();
             table.setTableId(Long.parseLong(l.getInitTableId()));
             table.setProjectId(projectId);
-            table.setTableDataId(SnowFlakeUtil.getId());
-            table.setId(SnowFlakeUtil.getId());
-            table.setAgreementId(agreeId);
             table.setPrivateId(l.getId());
             table.setSort(l.getSort());
+            table.setId(SnowFlakeUtil.getId());
             table.setExcelId(l.getExcelId());
             table.setHtmlUrl(l.getHtmlUrl());
             table.setTableName(l.getNodeName());
             return table;
         }).collect(Collectors.toList());
-        linkTableService.saveBatch(linkTables);
-        //再保存协议
-        CompensationInfo info = new CompensationInfo();
-        info.setId(agreeId);
-        info.setName("默认名称");
-        //获取当前节点名称
-        RegionTreeInfo treeInfo = treeInfoService.getById(areaId);
-        //获取编号
-        String num = getNumber(areaId);
-        info.setNumber(treeInfo.getAreaName()+num);
-        info.setAreaId(areaId);
-        info.setProjectId(projectId);
-        info.setType(type);
-        info.setLandMoney(new BigDecimal(0));
-        info.setCropsMoney(new BigDecimal(0));
-        info.setAllMoney(new BigDecimal(0));
-        this.save(info);
-        return agreeId;
+        return linkTables;
     }
 
     /**
@@ -625,7 +678,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
     public void unSave(Long agreementId) {
         CompensationInfo info = this.getById(agreementId);
         //如果从未保存过,直接删除
-        if (StringUtils.isBlank(info.getMergePdfUrl())){
+        if (info != null && StringUtils.isBlank(info.getMergePdfUrl())){
             List<Long> list = Arrays.asList(agreementId);
             //删除中间表数据
             linkTableService.deleteByAgreementIds(list);
@@ -965,7 +1018,7 @@ public class CompensationInfoServiceImpl extends BaseServiceImpl<CompensationInf
             return R.fail("未获取到清表信息");
         }
         if (DataInfo == null) {
-            DataInfo = (Map<String, Object>) getBussDataInfo(id).getData();
+            DataInfo = (Map<String, Object>) getBussDataInfo(id,linkTable.getTableId()).getData();
         }
 
         //获取excel流 和 html流

+ 3 - 3
blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java

@@ -823,7 +823,7 @@ public static Map<String,List<Long>> relatedPages(List<FormData> curFormDatas ,L
      List<String> result = new ArrayList<>();
      if(Func.isNotBlank(treeCode)){
           /*字符总长度*/
-          int max =treeCode.length(),
+          int max =treeCode.length()-3,
           /*累计字符长度字符*/
            sum=0,
           /*第几次循环*/
@@ -836,8 +836,8 @@ public static Map<String,List<Long>> relatedPages(List<FormData> curFormDatas ,L
   }
 
 /*    public static void main(String[] args) {
-       // String s="003000004001000003";
-        String s="0";
+        *//*String s="003000004001000003";*//*
+        String s="00300";
         treeCodeSplit(s).forEach(System.out::println);
     }*/
 

+ 9 - 10
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/FormulaController.java

@@ -15,7 +15,6 @@ import com.mixsmart.utils.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
-import lombok.SneakyThrows;
 import org.springblade.common.utils.BaseUtils;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
@@ -35,7 +34,6 @@ import org.springblade.manager.formula.impl.CompositeDataAccess;
 import org.springblade.manager.formula.impl.StartupTimeListener;
 import org.springblade.manager.service.*;
 import org.springblade.manager.service.impl.FormulaServiceImpl;
-import org.springblade.manager.vo.AppWbsTreeContractVO;
 import org.springblade.manager.wrapper.FormulaWrapper;
 import org.springframework.beans.BeanUtils;
 import org.springframework.dao.EmptyResultDataAccessException;
@@ -44,7 +42,6 @@ import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
 import java.io.FileNotFoundException;
-import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.time.Instant;
 import java.time.ZoneId;
@@ -52,7 +49,6 @@ import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * @author yangyj
@@ -511,15 +507,17 @@ public class FormulaController {
             List<String> list = new ArrayList<>();
             if(Func.isNotBlank(one.getTreeCode())){
                 List<String> treeCodes= FormulaUtils.treeCodeSplit(one.getTreeCode());
-                treeCodes.remove(treeCodes.size()-1);
+                /*treeCodes.remove(treeCodes.size()-1);*/
                 List<WbsTreeContract> chains = this.wbsTreeContractService.list(Wrappers.<WbsTreeContract>lambdaQuery().in(WbsTreeContract::getTreeCode,treeCodes).eq(WbsTreeContract::getContractId,one.getContractId()));
                 if(chains.size()>0){
                     chains.add(one);
-                    chains.remove(0);
+                    WbsTreeContract level0= chains.remove(0);
                     ContractInfo info = contractInfoService.getById(one.getContractId());
-                    list.add(info.getContractName());
+                    list.add(info.getContractName()+"["+level0.getTreeCode()+"]");
                     chains.forEach(next->{
-                        list.add(Func.isNotBlank(next.getFullName()) ? next.getFullName() : next.getNodeName());
+                        String s=(Func.isNotBlank(next.getFullName()) ? next.getFullName() : next.getNodeName())+"["+next.getTreeCode()+"]";
+                        s=s.replaceAll("[\\t\\s\\n\\r]+","");
+                        list.add(s);
                     });
                 }
             }else{
@@ -533,14 +531,15 @@ public class FormulaController {
                         return R.fail("断链");
                     }
                     parentId = next.getParentId().toString();
-                    list.add(Func.isNotBlank(next.getFullName()) ? next.getFullName() : next.getNodeName());
+                    String s=Func.isNotBlank(next.getFullName()) ? next.getFullName() : next.getNodeName();
+                    s=s.replaceAll("[\\t\\s\\n\\r]+","");
+                    list.add(s);
                     loop++;
                 }
                 ContractInfo info = contractInfoService.getById(one.getContractId());
                 Collections.reverse(list);
                 list.set(0, info.getContractName());
             }
-
             final String[] indent = {"-"};
             String result = list.stream()
                     .map(item -> {

+ 60 - 37
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsParamController.java

@@ -21,6 +21,7 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.CollectionUtil;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringPool;
 import org.springblade.manager.dto.FormulaBean;
 import org.springblade.manager.dto.TreeNode;
 import org.springblade.manager.dto.WbsParamBean;
@@ -30,11 +31,16 @@ import org.springblade.manager.vo.ParamBean;
 import org.springblade.manager.vo.ParamSearch;
 import org.springblade.manager.wrapper.WbsParamWrapper;
 import org.springframework.beans.BeanUtils;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.data.redis.serializer.RedisSerializer;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
+
+import java.time.LocalDateTime;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 /**
@@ -50,6 +56,7 @@ public class WbsParamController {
     private final IWbsParamService service;
     private final JdbcTemplate jdbcTemplate;
     private final IFormulaService formulaService;
+    private final StringRedisTemplate redisTemplate;
     private final IElementFormulaMappingService elementFormulaMappingService;
 
 
@@ -593,24 +600,38 @@ public class WbsParamController {
     public R<Object> treeCode(Long contractId,Long projectId) {
         StopWatch stopWatch = new StopWatch();
         stopWatch.start("treeCode刷新");
-        List<Long> contractIds= new ArrayList<>();
+        Set<Long> contractIds=new HashSet<>();
         if(projectId!=null){
-            contractIds= this.jdbcTemplate.queryForList(" select id from m_contract_info where p_id="+projectId+" and is_deleted=0 ",Long.class);
+            contractIds= new HashSet<>(this.jdbcTemplate.queryForList(" select id from m_contract_info where p_id="+projectId+" and is_deleted=0 ",Long.class));
         }else if( contractId!=null){
             contractIds.add(contractId);
         }
         if(contractIds.size()>0){
-             for(Long id:contractIds){
-                    batchUpdate(id,true);
-             }
+            this.treeCodeUpdate(contractIds);
             stopWatch.stop();
             return R.success((stopWatch.getLastTaskName()+"执行用时:"+stopWatch.getTotalTimeMillis()));
         }
-        return R.fail("项目Id格式有问题");
+        return R.fail("执行失败");
+    }
+
+    /*把所有项目的合同段都刷新treeCode*/
+    @GetMapping("/tree-code-all")
+    public R<Object> treeCodeAll() {
+            return this.treeCodeUpdateProjectAllForJob();
+    }
+
 
+
+    @Scheduled(cron = " 0 0 3,13 * * ?")
+    public  void job(){
+        System.out.println("treeCode刷新任务开始"+ LocalDateTime.now());
+        if(!Optional.ofNullable(System.getProperty("os.name")).orElse(StringPool.EMPTY).equals("Linux")){
+              this.treeCodeUpdateProjectAllForJob();
+        }
     }
 
-    public void batchUpdate(Long id,boolean fast){
+
+    public void builder(Long id,List<String>sqlList){
         List<Map<String,Object>> treeNodeList= this.jdbcTemplate.queryForList("select node_name name,p_key_id value, id, parent_id parentId from m_wbs_tree_contract where contract_id="+id+" and is_deleted=0 and type=1 ");
         if(treeNodeList.size()>0){
             Map<Long,TreeNode<Long>> treeNodeMap = new HashMap<>(treeNodeList.size()*2);
@@ -633,37 +654,39 @@ public class WbsParamController {
                     tmp.setChildren(v);
                 }
             });
-            TreeNode<Long> top = treeNodeMap.get(topId);
-            if(fast){
-                List<String>sqlList=new ArrayList<>();
-                sqlBuilder2(top,sqlList,ZERO);
-                if(sqlList.size()>0){
-                    List<List<String>> sqlListSeg = BaseUtils.splitList(sqlList, 250);
-                    sqlListSeg.parallelStream().forEach(sql->{
-                        try {
-                            String joinSql=String.join(";",sql);
-                            this.jdbcTemplate.execute(joinSql);
-                        }catch (Exception e){
-                            e.printStackTrace();
-                        }
-                    });
-                }
-            }else{
-                List<Object[]> paramList = new ArrayList<>();
-                sqlBuilder(top,paramList,ZERO);
-                if(!paramList.isEmpty()){
-                    List<List<Object[]>> paramListSplit=BaseUtils.splitList(paramList,1000);
-                    String sqlTemplate="update m_wbs_tree_contract set tree_code = ? where p_key_id = ?";
-                    paramListSplit.parallelStream().forEach(sql->{
-                        try {
-                            this.jdbcTemplate.batchUpdate(sqlTemplate,sql);
-                        }catch (Exception e){
-                            e.printStackTrace();
-                        }
-                    });
+            sqlBuilder2(treeNodeMap.get(topId),sqlList,ZERO);
+        }
+    }
+
+    public void treeCodeUpdate(Set<Long> contractIds){
+        List<String>sqlList=new ArrayList<>();
+        contractIds.forEach(id->{
+            builder(id,sqlList);
+        });
+        if(sqlList.size()>0){
+            List<List<String>> sqlListSeg = BaseUtils.splitList(sqlList, 250);
+            sqlListSeg.parallelStream().forEach(sql->{
+                try {
+                    String joinSql=String.join(";",sql);
+                    this.jdbcTemplate.execute(joinSql);
+                }catch (Exception e){
+                    e.printStackTrace();
                 }
-            }
+            });
+        }
+    }
+
+    /**批量任務*/
+    public R<Object> treeCodeUpdateProjectAllForJob(){
+        StopWatch stopWatch = new StopWatch();
+        stopWatch.start("全部项目treeCode刷新");
+        Set<Long>  contractIds= new HashSet<>(this.jdbcTemplate.queryForList(" select id from m_contract_info where  is_deleted=0 ",Long.class));
+        if(contractIds.size()>0){
+            this.treeCodeUpdate(contractIds);
+            stopWatch.stop();
+            return R.success((stopWatch.getLastTaskName()+"执行用时:"+stopWatch.getTotalTimeMillis()));
         }
+        return R.fail("执行失败");
     }
 
     static String ZERO="0";