Browse Source

资料查询分页page接口bug

liuyc 1 year ago
parent
commit
b73a94651e

+ 14 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsTreeContractVO8.java

@@ -0,0 +1,14 @@
+package org.springblade.manager.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class WbsTreeContractVO8 implements Serializable {
+
+    private Long id;
+    private Long pKeyId;
+    private Integer hasChildren;
+
+}

+ 67 - 3
blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java

@@ -20,6 +20,7 @@ import org.springblade.business.feign.MessageWarningClient;
 import org.springblade.business.feign.OperationLogClient;
 import org.springblade.business.feign.RecycleBinClient;
 import org.springblade.business.feign.TaskClient;
+import org.springblade.business.mapper.InformationQueryMapper;
 import org.springblade.business.service.*;
 import org.springblade.business.socket.WebSocket;
 import org.springblade.business.utils.FileUtils;
@@ -45,6 +46,7 @@ import org.springblade.manager.entity.*;
 import org.springblade.manager.feign.*;
 import org.springblade.manager.vo.WbsTreeContractLazyVO;
 import org.springblade.manager.vo.WbsTreeContractTreeVOS;
+import org.springblade.manager.vo.WbsTreeContractVO8;
 import org.springblade.resource.feign.NewIOSSClient;
 import org.springblade.system.cache.ParamCache;
 import org.springblade.system.entity.DictBiz;
@@ -93,6 +95,8 @@ public class InformationWriteQueryController extends BladeController {
 
     private final IInformationQueryService informationQueryService;
 
+    private final InformationQueryMapper informationQueryMapper;
+
     private final IInformationQueryFileService informationQueryFileService;
 
     private final IDictBizClient dictBizClient;
@@ -3513,16 +3517,49 @@ public class InformationWriteQueryController extends BladeController {
             node = this.wbsTreeContractClient.getContractWbsTreeByContractIdAndId(vo.getWbsId(), Long.parseLong(vo.getContractIdRelation()));
         }
         List<QueryProcessDataVO> queryDataResult = new ArrayList<>();
+        List<WbsTreeContractVO8> lowestNodes = new ArrayList<>();
         if (!new Integer("6").equals(node.getNodeType()) && !Arrays.asList("1,2,3,4".split(",")).contains(node.getMajorDataType() + "")) {
+            /**
+             * 更改逻辑
+             * 使用queryProcessDataByParentIdAndContractId_3中,通过pKeyId查询;
+             * 放弃使用queryProcessDataByParentIdAndContractIdTwo中,通过ancestors字段查询,ancestors有问题
+             * @author liuyc
+             * @date 2023年9月8日11:26:46
+             */
             //不是工序,则查询当前节点下的所有填报节点
             if (node.getParentId() == 0) {
-                queryDataResult = this.informationQueryService.queryProcessDataByParentIdAndContractIdTwo("", contract.getContractType(), StringUtils.isNotEmpty(vo.getContractIdRelation()) ? vo.getContractIdRelation() : vo.getContractId().toString());
+                //当前合同段最底层节点pKeyIds
+                List<WbsTreeContract> lowestNodesAll = jdbcTemplate.query("select a.p_key_id,a.id,(SELECT CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND b.contract_id = " + node.getContractId() + " AND b.status = 1 AND b.type = 1 AND b.is_deleted = 0) AS hasChildren from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + node.getContractId() + " HAVING hasChildren = 0", new BeanPropertyRowMapper<>(WbsTreeContract.class));
+                List<String> pKeyIds = lowestNodesAll.stream().map(WbsTreeContract::getPKeyId).map(String::valueOf).collect(Collectors.toList());
+                List<List<String>> partition = Lists.partition(pKeyIds, 1000);
+                for (List<String> items : partition) {
+                    //获取填报节点信息
+                    List<QueryProcessDataVO> result = this.informationQueryMapper.queryProcessDataByParentIdAndContractId_3(contract.getContractType(), items);
+                    if (result.size() > 0) {
+                        queryDataResult.addAll(result);
+                    }
+                }
+
+                //queryDataResult = this.informationQueryService.queryProcessDataByParentIdAndContractIdTwo("", contract.getContractType(), StringUtils.isNotEmpty(vo.getContractIdRelation()) ? vo.getContractIdRelation() : vo.getContractId().toString());
             } else {
-                queryDataResult = this.informationQueryService.queryProcessDataByParentIdAndContractIdTwo(node.getId().toString(), contract.getContractType(), StringUtils.isNotEmpty(vo.getContractIdRelation()) ? vo.getContractIdRelation() : vo.getContractId().toString());
+                //获取当前选择的节点下的所有最底层节点
+                WbsTreeContractVO8 vo8 = BeanUtil.copyProperties(node, WbsTreeContractVO8.class);
+                this.lowestNodesRecursively(lowestNodes, Collections.singleton(vo8), node.getContractId());
+                List<String> pKeyIds = lowestNodes.stream().map(WbsTreeContractVO8::getPKeyId).map(String::valueOf).collect(Collectors.toList());
+                List<List<String>> partition = Lists.partition(pKeyIds, 1000);
+                for (List<String> items : partition) {
+                    //获取填报节点信息
+                    List<QueryProcessDataVO> result = this.informationQueryMapper.queryProcessDataByParentIdAndContractId_3(contract.getContractType(), items);
+                    if (result.size() > 0) {
+                        queryDataResult.addAll(result);
+                    }
+                }
 
+                //queryDataResult = this.informationQueryService.queryProcessDataByParentIdAndContractIdTwo(node.getId().toString(), contract.getContractType(), StringUtils.isNotEmpty(vo.getContractIdRelation()) ? vo.getContractIdRelation() : vo.getContractId().toString());
             }
+
             //如果是首件列表请求,则删掉没有标记为首件的数据
-            if (queryDataResult != null && queryDataResult.size() > 0) {
+            if (queryDataResult.size() > 0) {
                 if (StringUtils.isNotEmpty(vo.getIsFirst())) {
                     if (StringUtils.isNotEmpty(vo.getFirstTitle())) {
                         queryDataResult = queryDataResult.stream().filter(qdr -> "3".equals(qdr.getQueryType())).collect(Collectors.toList());
@@ -3538,6 +3575,7 @@ public class InformationWriteQueryController extends BladeController {
                 submitNodeKeyIds.addAll(queryDataResult.stream().map(QueryProcessDataVO::getPrimaryKeyId).distinct().collect(Collectors.toList()));
             }
         }
+
         //设置进集合中
         vo.setWbsIds(submitNodeKeyIds);
         if (StringUtils.isNotEmpty(vo.getContractIdRelation())) {
@@ -3547,6 +3585,32 @@ public class InformationWriteQueryController extends BladeController {
         return R.data(this.informationQueryService.selectInformationQueryPage(Condition.getPage(query), vo, node));
     }
 
+
+    /**
+     * 获取一个节点下的所有最底层节点
+     *
+     * @param lowestNodes 结果集
+     * @param nodes       初始入参节点
+     */
+    private void lowestNodesRecursively(List<WbsTreeContractVO8> lowestNodes, Set<WbsTreeContractVO8> nodes, String contractId) {
+        if (nodes.size() > 0) {
+            Set<Long> ids = nodes.stream().map(WbsTreeContractVO8::getId).collect(Collectors.toSet());
+            if (ids.size() > 0) {
+                List<WbsTreeContractVO8> childNodes = jdbcTemplate.query("select a.p_key_id,a.id,(SELECT CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END FROM m_wbs_tree_contract b WHERE b.parent_id = a.id AND b.contract_id = " + contractId + " AND b.status = 1 AND b.type = 1 AND b.is_deleted = 0) AS hasChildren from m_wbs_tree_contract a where a.type = 1 and a.status = 1 and a.is_deleted = 0 and a.contract_id = " + contractId + " and a.parent_id in(" + StringUtils.join(ids, ",") + ")", new BeanPropertyRowMapper<>(WbsTreeContractVO8.class));
+                if (childNodes.size() > 0) {
+                    Set<WbsTreeContractVO8> lowestNode = childNodes.stream().filter(f -> f.getHasChildren().equals(0)).collect(Collectors.toSet());
+                    Set<WbsTreeContractVO8> noLowestNode = childNodes.stream().filter(f -> f.getHasChildren().equals(1)).collect(Collectors.toSet());
+                    if (lowestNode.size() > 0) { //最底层节点加入结果集
+                        lowestNodes.addAll(lowestNode);
+                    }
+                    if (noLowestNode.size() > 0) { //非最底层节点继续递归
+                        this.lowestNodesRecursively(lowestNodes, noLowestNode, contractId);
+                    }
+                }
+            }
+        }
+    }
+
     /**
      * 获取当前合同段的划分树
      *

+ 5 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/InformationQueryMapper.java

@@ -59,6 +59,11 @@ public interface InformationQueryMapper extends BaseMapper<InformationQuery> {
      */
     List<QueryProcessDataVO> queryProcessDataByParentIdAndContractIdTwo(@Param("parentId") String parentId, @Param("classify") Integer classify, @Param("contractId") String contractId);
 
+    /**
+     * 查询工序节点的填报记录3
+     */
+    List<QueryProcessDataVO> queryProcessDataByParentIdAndContractId_3(@Param("classify") Integer classify, @Param("list") List<String> list);
+
     /**
      * 查询工序节点的填报记录,资料进度使用
      */

+ 25 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/InformationQueryMapper.xml

@@ -831,6 +831,31 @@
           AND wtc.status = 1
     </select>
 
+    <select id="queryProcessDataByParentIdAndContractId_3" resultMap="queryProcessDataMap">
+        SELECT wtc.id                                                                                   AS treeId,
+               wtc.p_key_id,
+               wtc.ancestors,
+               wtc.major_data_type,
+               wtc.node_type                                                                            AS nodeType,
+               IFNULL(if(length(trim(wtc.full_name)) > 0, wtc.full_name, wtc.node_name), wtc.node_name) AS title,
+               wtc.parent_id                                                                            AS parentId,
+               uiq.id                                                                                   AS informationQueryId,
+               IFNULL(uiq.status, 0)                                                                    AS status,
+               uiq.type                                                                                 AS queryType,
+               case
+                   WHEN uiq.pdf_trial_url is null then 'false'
+                   ELSE 'true' end                                                                      AS isExperiment
+        FROM m_wbs_tree_contract AS wtc
+                 LEFT JOIN u_information_query AS uiq
+                           ON wtc.p_key_id = uiq.wbs_id AND uiq.classify = #{classify} and uiq.is_deleted = 0 and
+                              wtc.is_deleted = 0 and
+                              wtc.status = 1
+        WHERE wtc.p_key_id in
+        <foreach collection="list" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+    </select>
+
     <select id="queryProcessDataByParentIdAndContractIdThree" resultMap="queryProcessDataMap">
         SELECT wtc.id                                                                                   AS treeId,
                wtc.p_key_id,

+ 3 - 1
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/InformationQueryServiceImpl.java

@@ -516,7 +516,9 @@ public class InformationQueryServiceImpl extends BaseServiceImpl<InformationQuer
             List<InformationQueryVO> voResult = JSONArray.parseArray(JSONObject.toJSONString(result), InformationQueryVO.class);
             //处理流程状态
             voResult.forEach(vor -> {
-                vor.setStartTime(DateUtil.format(vor.getCreateTime(), "yyyy-MM-dd"));
+                if (ObjectUtil.isNotEmpty(vor.getCreateTime())) {
+                    vor.setStartTime(DateUtil.format(vor.getCreateTime(), "yyyy-MM-dd"));
+                }
                 vor.setTaskStatusStr(new Integer("0").equals(vor.getStatus()) ? "未上报" : new Integer("1").equals(vor.getStatus()) ? "待审批" : new Integer("2").equals(vor.getStatus()) ? "已审批" : "已废除");
                 try {
                     //填报人