Browse Source

施工台账bug

Signed-off-by: liuyc <56808083@qq.com>
liuyc 11 months ago
parent
commit
3862f30fb7

+ 4 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/WbsTreeContractClient.java

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
+import java.util.Set;
 
 import static org.springblade.core.launch.constant.AppConstant.APPLICATION_NAME_PREFIX;
 
@@ -76,6 +77,9 @@ public interface WbsTreeContractClient {
     @GetMapping(API_PREFIX + "/getContractNodeByPrimaryKeyId")
     WbsTreeContract getContractNodeByPrimaryKeyId(@RequestParam String primaryKeyId);
 
+    @PostMapping(API_PREFIX + "/getContractNodeByPrimaryKeyIds")
+    List<WbsTreeContract> getContractNodeByPrimaryKeyIds(@RequestBody List<String> supplementPKeyIds);
+
     @PostMapping(API_PREFIX + "/removeContractTreeNode")
     Boolean removeContractTreeNode(@RequestBody List<String> ids);
 

+ 113 - 10
blade-service/blade-business/src/main/java/org/springblade/business/controller/ConstructionLedgerController.java

@@ -2,28 +2,36 @@ package org.springblade.business.controller;
 
 import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import io.swagger.annotations.*;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
 
 import javax.validation.Valid;
 
+import lombok.Data;
 import org.apache.commons.lang.StringUtils;
 import org.springblade.business.entity.ContractLog;
 import org.springblade.business.service.IContractLogWbsService;
 import org.springblade.business.service.IInformationQueryService;
 import org.springblade.business.vo.QueryProcessDataVO;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.ObjectUtil;
 import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.manager.feign.ContractClient;
 import org.springblade.manager.feign.WbsTreeContractClient;
 import org.springblade.manager.vo.WbsTreeContractTreeVOS;
+import org.springblade.manager.vo.WbsTreeContractVO8;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.RequestParam;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -33,10 +41,11 @@ import org.springblade.business.wrapper.ConstructionLedgerWrapper;
 import org.springblade.business.service.IConstructionLedgerService;
 import org.springblade.core.boot.ctrl.BladeController;
 
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
 import java.time.Duration;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -61,6 +70,8 @@ public class ConstructionLedgerController extends BladeController {
 
     private final IContractLogWbsService contractLogWbsService;
 
+    private final InformationWriteQueryController informationWriteQueryController;
+
     /**
      * 获取当前合同段的划分树
      *
@@ -103,9 +114,9 @@ public class ConstructionLedgerController extends BladeController {
     @PostMapping("/list")
     @ApiOperationSupport(order = 2)
     @ApiOperation(value = "分页(建议)", notes = "传入constructionLedger")
-    public R<IPage<ConstructionLedgerVO>> list(@Valid @RequestBody ConstructionLedgerVO vo) {
-//		ConstructionLedger ledger = new ConstructionLedger();
-//		BeanUtils.copyProperties(vo, ledger);
+    public R<IPage<ConstructionLedgerVO>> list(@Valid @RequestBody ConstructionLedgerVO vo) throws NoSuchFieldException, IllegalAccessException {
+        //ConstructionLedger ledger = new ConstructionLedger();
+        //BeanUtils.copyProperties(vo, ledger);
 
         Query query = new Query();
         query.setCurrent(vo.getCurrent());
@@ -119,8 +130,17 @@ public class ConstructionLedgerController extends BladeController {
             node = this.wbsTreeContractClient.getContractWbsTreeByContractIdAndId(Long.parseLong(vo.getWbsIds().get(0)), vo.getContractId());
         }
 
-        List<QueryProcessDataVO> queryDataResult;
-        if (!new Integer("6").equals(node.getNodeType()) && ObjectUtil.isNotEmpty(node.getMajorDataType())  && !Arrays.asList("1,2,3,4".split(",")).contains(node.getMajorDataType().toString())) {
+        if (node.getParentId().equals(0L)) {
+            throw new ServiceException("请从第三层级节点开始进行检索");
+        } else if (node.getAncestors().split(",").length == 2) {
+            WbsTreeContract root = wbsTreeContractClient.getContractWbsTreeByContractIdAndId(node.getParentId(), Long.parseLong(node.getContractId()));
+            if (root.getParentId().equals(0L)) {
+                throw new ServiceException("请从第三层级节点开始进行检索");
+            }
+        }
+
+        /*List<QueryProcessDataVO> queryDataResult;
+        if (!new Integer("6").equals(node.getNodeType()) && ObjectUtil.isNotEmpty(node.getMajorDataType()) && !Arrays.asList("1,2,3,4".split(",")).contains(node.getMajorDataType().toString())) {
             //非填报节点
             queryDataResult = this.informationQueryService.queryProcessDataByParentIdAndContractId(node.getId().toString(), 1, vo.getContractId().toString());
         } else {
@@ -128,6 +148,20 @@ public class ConstructionLedgerController extends BladeController {
             queryDataResult = this.informationQueryService.queryProcessDataByPrimaryKeyIdAndClassify(node.getPKeyId().toString(), 1);
         }
         vo.setWbsIds(queryDataResult.stream().map(QueryProcessDataVO::getPrimaryKeyId).distinct().collect(Collectors.toList()));
+        */
+
+        List<WbsTreeContractVO8> lowestNodes = new ArrayList<>();
+        WbsTreeContractVO8 vo8 = BeanUtil.copyProperties(node, WbsTreeContractVO8.class);
+        informationWriteQueryController.lowestNodesRecursively(lowestNodes, Collections.singleton(vo8), node.getContractId());
+
+        if (lowestNodes.size() <= 0) {
+            if (!node.getNodeType().equals(6)) {
+                return R.data(null);
+            }
+            vo.setWbsIds(Collections.singletonList(String.valueOf(node.getPKeyId())));
+        } else {
+            vo.setWbsIds(lowestNodes.stream().distinct().map(WbsTreeContractVO8::getPKeyId).map(String::valueOf).collect(Collectors.toList()));
+        }
 
         if (vo.getSiteStartTime() != null && vo.getSiteEndTime() != null) {
             pages = this.constructionLedgerService.page(Condition.getPage(query), Condition.getQueryWrapper(new ConstructionLedger()).lambda().in(ConstructionLedger::getWbsId, vo.getWbsIds()).between(ConstructionLedger::getSiteStartTime, vo.getSiteStartTime(), vo.getSiteEndTime()));
@@ -136,10 +170,30 @@ public class ConstructionLedgerController extends BladeController {
         }
 
         IPage<ConstructionLedgerVO> voiPage = ConstructionLedgerWrapper.build().pageVO(pages);
+        List<ConstructionLedgerVO> records = voiPage.getRecords();
+        if (records.size() <= 0) {
+            return R.data(null);
+        }
+
+        Set<String> collect = voiPage.getRecords().stream().map(ConstructionLedgerVO::getWbsId).map(String::valueOf).collect(Collectors.toSet());
+        List<String> wbsIds = vo.getWbsIds();
+        List<String> supplementPKeyIds = wbsIds.stream().filter(f -> !collect.contains(f)).distinct().collect(Collectors.toList());
+        if (supplementPKeyIds.size() > 0) {
+            supplementConstructionLedger(supplementPKeyIds, node);
+        }
 
+        //找到最开始的施工日志,如果存在数据则使用最开始的时间,如果没有再使用自定义编辑的时间
+        List<Long> param = voiPage.getRecords().stream().map(ConstructionLedgerVO::getWbsId).distinct().collect(Collectors.toList());
+
+        List<ContractLog> contractLogs = this.contractLogWbsService.queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(new ListDTO(param, 7, "OLD"));
+        Map<Long, ContractLog> maps = contractLogs.stream().collect(Collectors.toMap(ContractLog::getId, Function.identity()));
         voiPage.getRecords().forEach(vos -> {
+
+            vos.setStation(vos.getSite()); //TODO 暂时这样处理
+
             //找到最开始的施工日志,如果存在数据则使用最开始的时间,如果没有再使用自定义编辑的时间
-            ContractLog contractLog = this.contractLogWbsService.queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(vos.getWbsId().toString(), 7, "OLD");
+            //ContractLog contractLog = this.contractLogWbsService.queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(vos.getWbsId().toString(), 7, "OLD");
+            ContractLog contractLog = maps.getOrDefault(vos.getWbsId(), null);
             if (contractLog != null) {
                 //获取最开始的填报时间
                 String recordTime = contractLog.getRecordTime();
@@ -162,7 +216,6 @@ public class ConstructionLedgerController extends BladeController {
                 vos.setSiteTimeStr(DateUtil.format(vos.getSiteStartTime(), "yyyy-MM-dd"));
             }
 
-
             vos.setDetectionTimeStr(DateUtil.format(vos.getSiteEndTime(), "yyyy-MM-dd"));
             vos.setDetectionStartTimeValue(DateUtil.format(vos.getDetectionStartTime(), "yyyy-MM-dd"));
             vos.setDetectionEndTimeValue(DateUtil.format(vos.getDetectionEndTime(), "yyyy-MM-dd"));
@@ -180,6 +233,56 @@ public class ConstructionLedgerController extends BladeController {
         return R.data(voiPage);
     }
 
+    @Data
+    public class ListDTO implements Serializable {
+        List<Long> pKeyIds;
+        Integer classify;
+        String newOrOld;
+
+        public ListDTO(List<Long> pKeyIds, Integer classify, String newOrOld) {
+            this.pKeyIds = pKeyIds;
+            this.classify = classify;
+            this.newOrOld = newOrOld;
+        }
+    }
+
+    /**
+     * 增补台账
+     */
+    @Async
+    public void supplementConstructionLedger(List<String> supplementPKeyIds, WbsTreeContract node) {
+        List<ConstructionLedger> alreadyExistConstructionLedgers = constructionLedgerService.getBaseMapper().selectList(Wrappers.<ConstructionLedger>lambdaQuery().select(ConstructionLedger::getWbsId).in(ConstructionLedger::getWbsId, supplementPKeyIds));
+        if (!alreadyExistConstructionLedgers.isEmpty()) {
+            Set<String> wbsIds = alreadyExistConstructionLedgers.stream().map(ConstructionLedger::getWbsId).map(String::valueOf).collect(Collectors.toSet());
+            supplementPKeyIds.removeIf(wbsIds::contains);
+        }
+
+        if (supplementPKeyIds.size() > 0) {
+            List<WbsTreeContract> contractNodeByPrimaryKeyIds = wbsTreeContractClient.getContractNodeByPrimaryKeyIds(supplementPKeyIds); //只获取工序节点
+            if (contractNodeByPrimaryKeyIds.size() > 0) {
+                List<ConstructionLedger> constructionLedgers = new ArrayList<>();
+                for (WbsTreeContract wbsTreeContract : contractNodeByPrimaryKeyIds) {
+                    ConstructionLedger ledger = new ConstructionLedger();
+                    ledger.setId(SnowFlakeUtil.getId());
+                    ledger.setStation(ObjectUtil.isNotEmpty(wbsTreeContract.getFullName()) ? wbsTreeContract.getFullName() : wbsTreeContract.getNodeName());
+                    ledger.setSite(ObjectUtil.isNotEmpty(wbsTreeContract.getFullName()) ? wbsTreeContract.getFullName() : wbsTreeContract.getNodeName());
+
+                    ledger.setIsBeton(wbsTreeContract.getIsConcrete());
+                    ledger.setWbsId(wbsTreeContract.getPKeyId());
+
+                    ledger.setContractId(Long.parseLong(node.getContractId()));
+                    ledger.setProjectId(Long.parseLong(node.getProjectId()));
+                    ledger.setCreateTime(new Date());
+                    ledger.setCreateUser(AuthUtil.getUserId());
+                    ledger.setIsDeleted(0);
+
+                    constructionLedgers.add(ledger);
+                }
+                constructionLedgerService.saveBatch(constructionLedgers, 1000);
+            }
+        }
+    }
+
     /**
      * 新增
      */

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

@@ -3591,7 +3591,7 @@ public class InformationWriteQueryController extends BladeController {
      * @param lowestNodes 结果集
      * @param nodes       初始入参节点
      */
-    private void lowestNodesRecursively(List<WbsTreeContractVO8> lowestNodes, Set<WbsTreeContractVO8> nodes, String contractId) {
+    public 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) {

+ 2 - 1
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ContractLogWbsMapper.java

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * Mapper 接口
@@ -33,7 +34,7 @@ import java.util.List;
  */
 public interface ContractLogWbsMapper extends BaseMapper<ContractLogWbs> {
 
-    ContractLog queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(@Param("selectPrimaryKeyId") String selectPrimaryKeyId, @Param("classify") Integer classify, @Param("newOrOld") String newOrOld);
+    List<ContractLog> queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(@Param("param") List<Long> param, @Param("classify") Integer classify, @Param("newOrOld") String newOrOld);
 
     Integer countContractLogBySelectPrimaryKeyIdsAndClassify(@Param("primaryKeyIds") List<String> primaryKeyIds, @Param("classify") Integer classify);
 

+ 8 - 5
blade-service/blade-business/src/main/java/org/springblade/business/mapper/ContractLogWbsMapper.xml

@@ -42,13 +42,16 @@
 
     <select id="queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify" resultMap="contractLogResultMap">
         select
-        *
+            id,record_time
         from
-        u_contract_log
+            u_contract_log
         where
-        id in(
-        select contract_log_id from u_contract_log_wbs where is_deleted = 0 and tree_primary_key_id =
-        #{selectPrimaryKeyId}
+        id in (
+            select contract_log_id from u_contract_log_wbs
+            where is_deleted = 0 and tree_primary_key_id in
+            <foreach collection="param" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
         )
         and wbs_node_type = #{classify} and is_deleted = 0
         <choose>

+ 4 - 1
blade-service/blade-business/src/main/java/org/springblade/business/service/IContractLogWbsService.java

@@ -16,12 +16,15 @@
  */
 package org.springblade.business.service;
 
+import org.springblade.business.controller.ConstructionLedgerController;
 import org.springblade.business.entity.ContractLog;
 import org.springblade.business.entity.ContractLogWbs;
 import org.springblade.business.vo.ContractLogVO;
 import org.springblade.core.mp.base.BaseService;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 服务类
@@ -31,7 +34,7 @@ import java.util.List;
  */
 public interface IContractLogWbsService extends BaseService<ContractLogWbs> {
 
-    ContractLog queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(String selectPrimaryKeyId, Integer classify, String newOrOld);
+    List<ContractLog> queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(ConstructionLedgerController.ListDTO dto) throws NoSuchFieldException, IllegalAccessException;
 
     Integer countContractLogBySelectPrimaryKeyIdsAndClassify(List<String> selectPrimaryKeyIds, Integer classify);
 

+ 5 - 2
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/ContractLogWbsServiceImpl.java

@@ -19,6 +19,7 @@ package org.springblade.business.service.impl;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.springblade.business.controller.ConstructionLedgerController;
 import org.springblade.business.entity.ContractLog;
 import org.springblade.business.entity.ContractLogWbs;
 import org.springblade.business.vo.ContractLogVO;
@@ -27,8 +28,10 @@ import org.springblade.business.service.IContractLogWbsService;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -41,8 +44,8 @@ import java.util.stream.Collectors;
 public class ContractLogWbsServiceImpl extends BaseServiceImpl<ContractLogWbsMapper, ContractLogWbs> implements IContractLogWbsService {
 
     @Override
-    public ContractLog queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(String selectPrimaryKeyId, Integer classify, String newOrOld) {
-        return this.baseMapper.queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(selectPrimaryKeyId, classify, newOrOld);
+    public List<ContractLog> queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(ConstructionLedgerController.ListDTO obj){
+        return this.baseMapper.queryContractLogNewOrOldDataBySelectPrimaryKeyIdAndClassify(obj.getPKeyIds(), obj.getClassify(), obj.getNewOrOld());
     }
 
     @Override

+ 12 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/WbsTreeContractClientImpl.java

@@ -156,6 +156,14 @@ public class WbsTreeContractClientImpl implements WbsTreeContractClient {
         return this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, primaryKeyId));
     }
 
+    @Override
+    public List<WbsTreeContract> getContractNodeByPrimaryKeyIds(List<String> supplementPKeyIds) {
+        return wbsTreeContractService.getBaseMapper().selectList(Wrappers.<WbsTreeContract>lambdaQuery()
+                .select(WbsTreeContract::getIsConcrete, WbsTreeContract::getNodeName, WbsTreeContract::getFullName, WbsTreeContract::getPKeyId)
+                .eq(WbsTreeContract::getNodeType, 6)
+                .in(WbsTreeContract::getPKeyId, supplementPKeyIds));
+    }
+
     @Override
     public Boolean removeContractTreeNode(List<String> ids) {
         if (ids.size() > 0) {
@@ -395,6 +403,7 @@ public class WbsTreeContractClientImpl implements WbsTreeContractClient {
 
     /**
      * 根据pkid,找符合nodetype的祖先节点
+     *
      * @param pkeyId
      * @param nodeType
      * @return
@@ -409,7 +418,7 @@ public class WbsTreeContractClientImpl implements WbsTreeContractClient {
             String parentId = one.getParentId().toString();
             while (loop < max && StringUtils.isNotEquals(0, parentId)) {
                 WbsTreeContract next = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getContractId, one.getContractId()).eq(WbsTreeContract::getId, parentId));
-                if(next.getNodeType() <= nodeType){
+                if (next.getNodeType() <= nodeType) {
                     return next.getPKeyId();
                 }
                 parentId = next.getParentId().toString();
@@ -420,8 +429,8 @@ public class WbsTreeContractClientImpl implements WbsTreeContractClient {
     }
 
     @Override
-    public List<AppWbsTreeContractVO> searchNodeAllTableInfo(String primaryKeyId, String type, String contractId, String projectId,Long userId) {
-        List<AppWbsTreeContractVO> list = wbsTreeContractService.searchNodeAllTable(primaryKeyId+":"+userId, type, contractId, projectId,null);
+    public List<AppWbsTreeContractVO> searchNodeAllTableInfo(String primaryKeyId, String type, String contractId, String projectId, Long userId) {
+        List<AppWbsTreeContractVO> list = wbsTreeContractService.searchNodeAllTable(primaryKeyId + ":" + userId, type, contractId, projectId, null);
         return list;
     }
 

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

@@ -448,6 +448,8 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
                         /*ancestor*/
                         cObj.setAncestor(meterTreeContractNode.getAncestor() + "," + cObj.getParentId());
 
+                        cObj.setNodeCode(null);
+
                         baseMapper.insert(cObj);
                     }
 
@@ -505,6 +507,8 @@ public class MeterTreeContractServiceImpl extends BaseServiceImpl<MeterTreeContr
                             cObj.setAncestor(null); //后面重新计算子级ancestor
                         }
 
+                        cObj.setNodeCode(null);
+
                         meterTreeContractResultData.add(cObj);
                     }