ソースを参照

优化中间计量申请按部位分页查询

qianxb 11 ヶ月 前
コミット
09e16f4cf3

+ 1 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/NodeSortVO.java

@@ -47,4 +47,5 @@ public class NodeSortVO implements INode<NodeSortVO> {
         }
         return this.children;
     }
+    private Integer LinkTotal;
 }

+ 6 - 1
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.java

@@ -29,6 +29,7 @@ import org.springblade.meter.vo.*;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -75,7 +76,7 @@ public interface MiddleMeterApplyMapper extends BaseMapper<MiddleMeterApply> {
 
     List<MiddleMeterApply> getAllAPPly(@Param("contractId") Long contractId,@Param("contractPeriodId") Long contractPeriodId);
 
-    List<NodeSortVO> getLowestNodeBySort(@Param("contractId") Long contractId,@Param("nodeId") Long nodeId);
+    List<NodeSortVO> getLowestNodeBySort(@Param("contractId") Long contractId,@Param("nodeId") Long nodeId,@Param("periodId") Long periodId);
 
     List<WbsNodeVO> getAllNode(@Param("contractId") Long contractId);
 
@@ -114,4 +115,8 @@ public interface MiddleMeterApplyMapper extends BaseMapper<MiddleMeterApply> {
     Integer getWbsLinkFileTotal(@Param("contractId")Long contractId,@Param("id") Long id);
 
     Integer getMeterWbsFileMaxType(@Param("contractId")Long contractId,@Param("id") Long id);
+
+    NodeSortVO getMeterById(@Param("meterId") Long contractUnitId);
+
+    List<NodeSortVO> getAllMeter(@Param("contractId") Long contractId,@Param("periodId") Long periodId);
 }

+ 35 - 9
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.xml

@@ -88,7 +88,10 @@
                     else '已废除' end as approveStatusName,
                (select period_number from s_contract_meter_period cmp where cmp.id = mma.contract_period_id) as periodNumber
         FROM s_middle_meter_apply mma
-        WHERE contract_id = #{apply.contractId} and is_deleted = 0 and contract_period_id = #{apply.contractPeriodId}
+        WHERE contract_id = #{apply.contractId} and is_deleted = 0
+        <if test="apply.contractPeriodId != -1">
+            and contract_period_id = #{apply.contractPeriodId}
+        </if>
               and contract_unit_id in (SELECT id FROM s_meter_tree_contract mtc
                     WHERE contract_id = #{apply.contractId} and is_deleted = 0
                     and (mtc.id = #{apply.contractUnitId} or FIND_IN_SET(#{apply.contractUnitId}, ancestor))
@@ -101,7 +104,11 @@
                     else '已废除' end as approveStatusName,
                (select period_number from s_contract_meter_period cmp where cmp.id = mma.contract_period_id) as periodNumber
         FROM s_middle_meter_apply mma
-        WHERE contract_id = #{apply.contractId} and is_deleted = 0 and contract_period_id = #{apply.contractPeriodId}
+        WHERE contract_id = #{apply.contractId} and is_deleted = 0
+        <if test="apply.contractPeriodId != -1">
+            and contract_period_id = #{apply.contractPeriodId}
+        </if>
+
           and contract_unit_id in (
                 <foreach collection="ids" item="id"  separator=",">
                     #{id}
@@ -111,7 +118,7 @@
             <foreach collection="ids" item="id"  separator=",">
                 #{id}
             </foreach>
-        )
+        ),create_time
 
     </select>
     <select id="meterPeriodAllForm" resultType="org.springblade.meter.vo.MeterInventoryDetailVO">
@@ -185,13 +192,15 @@
 
 
     <select id="getLowestNodeBySort" resultType="org.springblade.meter.vo.NodeSortVO">
-        SELECT id,parent_id
+        SELECT id,parent_id,
+            (select count(1) from s_middle_meter_apply mma
+                where mma.contract_id = #{contractId} and mma.is_deleted = 0 and mma.contract_unit_id = mtc.id
+                <if test="periodId != -1">
+                    and mma.contract_period_id = #{periodId}
+                </if>
+            ) as LinkTotal
         FROM s_meter_tree_contract mtc
-        WHERE is_deleted = 0 and contract_id = #{contractId}
-          and id in (SELECT id FROM s_meter_tree_contract mtc2
-                     WHERE mtc2.contract_id = #{contractId} and mtc2.is_deleted = 0
-                       and (mtc2.id = #{nodeId} or FIND_IN_SET(#{nodeId}, mtc2.ancestor))
-        )
+        WHERE  contract_id = #{contractId} and is_deleted = 0 and FIND_IN_SET(#{nodeId}, ancestor)
         ORDER BY mtc.sort,mtc.create_time
 
 
@@ -382,6 +391,23 @@
         from m_table_file where contract_id = #{contractId} and is_deleted = 0 and tab_id in
         (select wbs_tree_id from s_meter_tree_link_wbs_tree where  contract_id = #{contractId} and meter_tree_id = #{id})
     </select>
+    <select id="getMeterById" resultType="org.springblade.meter.vo.NodeSortVO">
+        SELECT id,parent_id
+        FROM s_meter_tree_contract mtc
+        WHERE id = #{meterId}
+    </select>
+    <select id="getAllMeter" resultType="org.springblade.meter.vo.NodeSortVO">
+        SELECT id,parent_id,
+               (select count(1) from s_middle_meter_apply mma
+                    where mma.contract_id = #{contractId} and mma.is_deleted = 0 and mma.contract_unit_id = mtc.id
+                <if test="periodId != -1">
+                    and mma.contract_period_id = #{periodId}
+                </if>
+                   ) as LinkTotal
+        FROM s_meter_tree_contract mtc
+        WHERE contract_id = #{contractId} and is_deleted = 0
+        ORDER BY -sort desc,create_time,node_name
+    </select>
 
 
 </mapper>

+ 0 - 2
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/MeterTreeContractServiceImpl.java

@@ -2121,8 +2121,6 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
                 //校验数据,导入没有挂载过的重复清单会当值新增一次,修改多次。没有挂载过的重复清单会修改多次。
                 //先提取没有挂载过的重复清单
                 Set<String> formNumbers = resultFormListUpdate.stream().filter(l -> l.getStatus() == 0).map(InventoryFormMeterVO::getFormNumber).collect(Collectors.toSet());
-                //新增的要从修改中删除,假定是直接新增这么多施工图
-                int adds = formNumbers.size();
                 Map<MeterImport3VO2, Long> map = resultFormListUpdate.stream().filter(l -> l.getStatus() == 1).collect(Collectors.groupingBy(l -> new MeterImport3VO2(l.getContractMeterId(), l.getContractFormId()), Collectors.counting()));
                 for (MeterImport3VO2 vo2 : map.keySet()) {
                     if (map.get(vo2) > 1){

+ 18 - 4
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/MiddleMeterApplyServiceImpl.java

@@ -46,6 +46,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StopWatch;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -524,8 +525,19 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
     public IPage<MiddleMeterApplyVO> page2(MiddleMeterApply middleMeterApply, Query query,Integer type) {
         IPage<MiddleMeterApplyVO> iPage = new Page<>(query.getCurrent(),query.getSize());
         if (type == 1){
-            //根据部位分页,先查出部位
-            List<NodeSortVO> vos = baseMapper.getLowestNodeBySort(middleMeterApply.getContractId(),middleMeterApply.getContractUnitId());
+            NodeSortVO vo = baseMapper.getMeterById(middleMeterApply.getContractUnitId());
+            List<NodeSortVO> vos = new ArrayList<>();
+            StopWatch stopWatch = new StopWatch();
+            stopWatch.start();
+            if (vo.getParentId() == 0){
+                vos = baseMapper.getAllMeter(middleMeterApply.getContractId(),middleMeterApply.getContractPeriodId());
+            }else {
+                //根据部位分页,先查出部位
+                vos.add(vo);
+                vos.addAll(baseMapper.getLowestNodeBySort(middleMeterApply.getContractId(), middleMeterApply.getContractUnitId(),middleMeterApply.getContractPeriodId()));
+            }
+            stopWatch.stop();
+            System.out.println(stopWatch.getTotalTimeMillis());
             //转换为树
             Long l1 = System.currentTimeMillis();
             List<NodeSortVO> list = ForestNodeMerger.merge(vos);
@@ -962,7 +974,7 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
     public IPage<MiddleMeterApplyVO3> dataLinkPage(MiddleMeterApply middleMeterApply, Query query) {
         IPage<MiddleMeterApplyVO3> iPage = new Page<>(query.getCurrent(),query.getSize());
         //根据部位分页,先查出部位
-        List<NodeSortVO> vos = baseMapper.getLowestNodeBySort(middleMeterApply.getContractId(),middleMeterApply.getContractUnitId());
+        List<NodeSortVO> vos = baseMapper.getLowestNodeBySort(middleMeterApply.getContractId(),middleMeterApply.getContractUnitId(), middleMeterApply.getContractPeriodId());
         //转换为树
         Long l1 = System.currentTimeMillis();
         List<NodeSortVO> list = ForestNodeMerger.merge(vos);
@@ -1389,7 +1401,9 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
     private void gatherSortNode(List<NodeSortVO> list,List<Long> ids){
         for (NodeSortVO vo : list) {
             if (vo.getChildren().size() == 0){
-                ids.add(vo.getId());
+                if (vo.getLinkTotal() > 0) {
+                    ids.add(vo.getId());
+                }
                 continue;
             }else {
                 gatherSortNode(vo.getChildren(), ids);