Browse Source

中间计量申请,引用质检资料

qianxb 1 year ago
parent
commit
67e79fdd83

+ 27 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/dto/WbsNodeDTO.java

@@ -0,0 +1,27 @@
+package org.springblade.meter.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @Param
+ * @Author wangwl
+ * @Date 2024/2/1 15:49
+ **/
+@Data
+public class WbsNodeDTO {
+    @ApiModelProperty(value = "项目id")
+    private Long projectId;
+
+    @ApiModelProperty(value = "合同id")
+    private Long contractId;
+
+    @ApiModelProperty(value = "WBS树节点id")
+    private Long nodeId;
+
+    @ApiModelProperty("当前页")
+    private Integer current;
+
+    @ApiModelProperty("每页的数量")
+    private Integer size;
+}

+ 40 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/WbsFileVO.java

@@ -0,0 +1,40 @@
+package org.springblade.meter.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @Param   中间计量申请关联WBS树文件
+ * @Author wangwl
+ * @Date 2024/2/1 11:21
+ **/
+@Data
+public class WbsFileVO implements Serializable {
+
+
+    @ApiModelProperty(value = "部位名称")
+    private String partName;
+
+    @ApiModelProperty(value = "资料名称")
+    private String dataName;
+
+    @ApiModelProperty(value = "审批状态名称")
+    private String appStatusName;
+
+    @ApiModelProperty(value = "PDF路径")
+    private String pdfUrl;
+
+    @ApiModelProperty(value = "电签PDF路径")
+    private String eVisaPdfUrl;
+
+    @ApiModelProperty(value = "祖级节点")
+    private String ancestors;
+
+    @ApiModelProperty(value = "节点类型(工序)")
+    private Integer nodeType;
+
+    @ApiModelProperty(value = "当前节点名称")
+    private String nodeName;
+}

+ 53 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/WbsNodeVO.java

@@ -0,0 +1,53 @@
+package org.springblade.meter.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import lombok.Data;
+import org.springblade.core.tool.node.INode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Param   质检树使用
+ * @Author wangwl
+ * @Date 2024/2/1 14:53
+ **/
+@Data
+public class WbsNodeVO implements INode<WbsNodeVO> {
+    /**
+     * 主键ID
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    /**
+     * 父节点ID
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long parentId;
+
+    /**
+     * 子孙节点
+     */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private List<WbsNodeVO> children;
+
+    /**
+     * 是否有子孙节点
+     */
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private Boolean hasChildren;
+
+    @Override
+    public List<WbsNodeVO> getChildren() {
+        if (this.children == null) {
+            this.children = new ArrayList<>();
+        }
+        return this.children;
+    }
+
+    private Integer isData;
+    private Long pId;
+}

+ 17 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/MiddleMeterApplyController.java

@@ -26,6 +26,7 @@ import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.meter.dto.MiddleMeterApplyDTO;
+import org.springblade.meter.dto.WbsNodeDTO;
 import org.springblade.meter.vo.*;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.*;
@@ -240,4 +241,20 @@ public class MiddleMeterApplyController extends BladeController {
     public R<List<MeterInventoryVO>> getCurrentNodeAllForm(@RequestBody MiddleMeterApply middleMeterApply) {
         return R.data(middleMeterApplyService.getCurrentNodeAllForm(middleMeterApply));
     }
+
+    /**
+     * 获取当前WBS节点下的资料
+     */
+    @PostMapping("/getWbsNodeInfo")
+    @ApiOperationSupport(order = 13)
+    @ApiOperation(value = "获取WBS节点下,资料信息", notes = "返回WBS节点下,资料信息")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "contractId", value = "合同id", required = true),
+            @ApiImplicitParam(name = "projectId", value = "项目id", required = true),
+            @ApiImplicitParam(name = "nodeId", value = "WBS树节点id", required = true)
+    })
+    public R<IPage<WbsFileVO>> getWbsNodeInfo(@RequestBody WbsNodeDTO dto){
+        IPage<WbsFileVO> iPage = middleMeterApplyService.getWbsNodeInfo(dto);
+        return R.data(iPage);
+    }
 }

+ 11 - 2
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.java

@@ -19,6 +19,8 @@ package org.springblade.meter.mapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Param;
 import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.entity.WbsTreeContract;
+import org.springblade.meter.dto.WbsNodeDTO;
 import org.springblade.meter.entity.ChangeTokenForm;
 import org.springblade.meter.entity.ChangeTokenMeter;
 import org.springblade.meter.entity.MeterTreeContract;
@@ -28,6 +30,7 @@ import org.springblade.meter.vo.*;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -69,11 +72,11 @@ public interface MiddleMeterApplyMapper extends BaseMapper<MiddleMeterApply> {
 
     BigDecimal getCurrentMeterMoney(@Param("contractId") Long contractId,@Param("contractPeriodId") Long contractPeriodId);
 
-    Integer getAllAPPly(@Param("contractId") Long contractId,@Param("contractPeriodId") Long contractPeriodId);
+    List<MiddleMeterApply> getAllAPPly(@Param("contractId") Long contractId,@Param("contractPeriodId") Long contractPeriodId);
 
     List<NodeSortVO> getLowestNodeBySort(@Param("contractId") Long contractId,@Param("nodeId") Long nodeId);
 
-    List<NodeSortVO> getAllNode(@Param("contractId") Long contractId);
+    List<WbsNodeVO> getAllNode(@Param("contractId") Long contractId);
 
     Set<ChangeTokenForm> getNodeToken(@Param("contractId") Long contractId,@Param("ids") List<Long> ids,@Param("nodeId") Long nodeId,@Param("bDate") String businessDate);
 
@@ -82,4 +85,10 @@ public interface MiddleMeterApplyMapper extends BaseMapper<MiddleMeterApply> {
     List<MiddleMeterApplyVO2> getAllAPPlyAndForm(@Param("ids") Set<Long> middleIds);
 
     void batchUpdateMiddle(@Param("list") List<MiddleMeterApplyVO2> vo2s);
+
+    List<WbsNodeVO> getAllChildNode(@Param("dto") WbsNodeDTO dto);
+
+    List<WbsFileVO> getNodeData(@Param("ids") List<Long> ids);
+
+    List<WbsTreeContract> getAllAncestors(@Param("ids") HashSet<Long> set, @Param("contractId") Long contractId);
 }

+ 56 - 8
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.xml

@@ -170,15 +170,8 @@
         from s_middle_meter_apply
         where contract_id = #{contractId} and is_deleted = 0 and contract_period_id = #{contractPeriodId} and approve_status != 3
     </select>
-    <select id="getAllAPPly" resultType="java.lang.Integer">
-        select count(1)
-        from s_middle_meter_apply
-        where contract_id = #{contractId} and contract_period_id = #{contractPeriodId}
-    </select>
 
-    <select id="getAllNode" resultType="org.springblade.meter.vo.NodeSortVO">
-        SELECT id,parent_id from m_wbs_tree_private  WHERE project_id  = 1578599210897772545 and is_deleted = 0 and type != 10 and wbs_type = 1
-    </select>
+
     <select id="getLowestNodeBySort" resultType="org.springblade.meter.vo.NodeSortVO">
         SELECT id,parent_id
         FROM s_meter_tree_contract mtc
@@ -223,6 +216,61 @@
     <select id="getContractInfo" resultType="org.springblade.manager.entity.ContractInfo">
         select * from m_contract_info where id = #{contractId}
     </select>
+    <select id="getAllAPPly" resultType="org.springblade.meter.entity.MiddleMeterApply">
+        select id,  SUBSTRING_INDEX(meter_number,"-",-1) as approveStatus
+        from s_middle_meter_apply
+        where contract_id = #{contractId} and contract_period_id = #{contractPeriodId} and is_deleted = 0
+    </select>
+    <select id="getAllNode" resultType="org.springblade.meter.vo.WbsNodeVO">
+        SELECT id,parent_id,p_key_id as pId,
+               (SELECT COUNT(1) from u_information_query uiq WHERE uiq.wbs_id = wtc.p_key_id) as isData
+        from m_wbs_tree_contract wtc
+        WHERE project_id  = 1630011899725201410 and contract_id = #{contractId} and is_deleted = 0 and type = 1
+          and (id = 1538783484087627777 or FIND_IN_SET(1538783484087627777, ancestors))
+        group by id
+        order by sort,create_time
+    </select>
+    <select id="getAllChildNode" resultType="org.springblade.meter.vo.WbsNodeVO">
+        SELECT id,parent_id,p_key_id as pId,
+               (SELECT COUNT(1) from u_information_query uiq WHERE uiq.wbs_id = wtc.p_key_id) as isData
+        from m_wbs_tree_contract wtc
+        WHERE project_id  = #{dto.projectId} and contract_id = #{dto.contractId} and is_deleted = 0 and type = 1
+          and (id = #{dto.nodeId} or FIND_IN_SET(#{dto.nodeId}, ancestors))
+        group by id
+        order by sort,create_time
+    </select>
+    <select id="getNodeData" resultType="org.springblade.meter.vo.WbsFileVO">
+        select name as dataName,pdf_url as pdfUrl,e_visa_pdf_url as eVisaPdfUrl,
+               (select node_type from m_wbs_tree_contract wtc where wtc.p_key_id = uiq.wbs_id) as nodeType,
+               (select ancestors from m_wbs_tree_contract wtc where wtc.p_key_id = uiq.wbs_id) as ancestors,
+               (select node_name from m_wbs_tree_contract wtc where wtc.p_key_id = uiq.wbs_id) as nodeName,
+               (CASE when status = 0 then '未上报' when status = 1 then '待审批' when status = 2 then '已审批'
+                    else '已废除' end) as appStatusName
+        from u_information_query uiq
+        where id in
+        (
+            select MAX(id) from u_information_query where  is_deleted = 0 and wbs_id in
+            <foreach collection="ids" item="id" open="(" close=")" separator=",">
+                    #{id}
+            </foreach>
+            group by wbs_id
+            order by create_time desc
+        )
+        order by FIELD(wbs_id,
+            <foreach collection="ids" item="id" separator=",">
+                #{id}
+            </foreach>
+        )
+
+    </select>
+    <select id="getAllAncestors" resultType="org.springblade.manager.entity.WbsTreeContract">
+        select * from m_wbs_tree_contract where contract_id = #{contractId} and is_deleted = 0
+        and id in
+        <foreach collection="ids" item="id" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+        group by id
+    </select>
 
 
 </mapper>

+ 3 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/service/IMiddleMeterApplyService.java

@@ -19,6 +19,7 @@ package org.springblade.meter.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.core.mp.support.Query;
 import org.springblade.meter.dto.MiddleMeterApplyDTO;
+import org.springblade.meter.dto.WbsNodeDTO;
 import org.springblade.meter.entity.MiddleMeterApply;
 import org.springblade.core.mp.base.BaseService;
 import org.springblade.meter.vo.*;
@@ -67,4 +68,6 @@ public interface IMiddleMeterApplyService extends BaseService<MiddleMeterApply>
     String test();
 
     List<MeterInventoryVO> getCurrentNodeAllForm(MiddleMeterApply middleMeterApply);
+
+    IPage<WbsFileVO> getWbsNodeInfo(WbsNodeDTO dto);
 }

+ 133 - 10
blade-service/blade-meter/src/main/java/org/springblade/meter/service/impl/MiddleMeterApplyServiceImpl.java

@@ -28,7 +28,9 @@ import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.ObjectUtil;
 import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.meter.dto.MiddleMeterApplyDTO;
+import org.springblade.meter.dto.WbsNodeDTO;
 import org.springblade.meter.entity.*;
 import org.springblade.meter.mapper.MiddleMeterApplyMapper;
 import org.springblade.meter.service.*;
@@ -44,10 +46,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -154,6 +153,8 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         if (dto.getBusinessDate() == null){
             throw new ServiceException("新增失败,请填写业务日期");
         }
+
+        dto.setMeterNumber(this.getMeterNumber(dto));
         //保存中间计量申请,设置计量金额为0,如果存在计量清单,则统计计量清单总金额
         MiddleMeterApply apply = new MiddleMeterApply();
         Long id = SnowFlakeUtil.getId();
@@ -503,8 +504,28 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         }
         str.append(contractMeterPeriod.getPeriodNumber()+"-");
         //获取流水号:当前合同段存在的当前计量期的申请单总数+1
-        Integer count = baseMapper.getAllAPPly(apply.getContractId(),apply.getContractPeriodId());
-        str.append(count+1);
+        List<MiddleMeterApply> allAPPly = baseMapper.getAllAPPly(apply.getContractId(), apply.getContractPeriodId());
+        if (allAPPly.size() == 0){
+            str.append(1);
+        }else {
+            List<Integer> list = allAPPly.stream().filter(l -> l.getApproveStatus() != null).map(l -> l.getApproveStatus()).sorted().collect(Collectors.toList());
+            if (list.size() == 0 || list.get(0) != 1){
+                str.append(1);
+            }else {
+                for (int i = 0; i < list.size() - 1; i++) {
+                    Integer num = list.get(i);
+                    if (num == list.get(i+1)){
+                        throw new ServiceException("计量期期号出现相同,请联系管理员");
+                    }
+                    if (++num != list.get(i+1)){
+                        str.append(num);
+                        return str.toString();
+                    }
+                }
+                str.append(list.size()+1);
+            }
+
+        }
         return str.toString();
     }
 
@@ -560,20 +581,28 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
 
     @Override
     public String test() {
-        Long contractId = 1612329251049537537L;
+        Long contractId = 1632993681739259906L;
         //获取当前合同下所以计量单元
-        List<NodeSortVO> vos = baseMapper.getAllNode(contractId);
+        List<WbsNodeVO> vos = baseMapper.getAllNode(contractId);
         //转换为树
         Long l1 = System.currentTimeMillis();
-        List<NodeSortVO> list = ForestNodeMerger.merge(vos);
+        List<WbsNodeVO> list = ForestNodeMerger.merge(vos);
         Long l2 = System.currentTimeMillis();
         System.out.println("----------------------");
         System.out.println(l2-l1);
+        List<WbsNodeVO> list2 = new ArrayList<>();
+        for (WbsNodeVO vo : list) {
+            if (vo.getId() == 1538783484087627777L){
+                list2.add(vo);
+                break;
+            }
+        }
         //递归循环树,存在子节点就深入,不存在子节点就add后返回上一层
         List<Long> ids = new ArrayList<>();
         Long l3 = System.currentTimeMillis();
-        gatherSortNode(list,ids);
+        gatherSortNode2(list2, ids);
         Long l4 = System.currentTimeMillis();
+        //构造数据
         System.out.println("---------------");
         System.out.println(l4-l3);
         return "";
@@ -596,6 +625,89 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
         return voList;
     }
 
+    /**
+     * 获取当前WBS节点下的资料
+     */
+    @Override
+    public  IPage<WbsFileVO> getWbsNodeInfo(WbsNodeDTO dto) {
+        if (dto.getCurrent() == null || dto.getSize() == null){
+            throw new ServiceException("请传入分页信息");
+        }
+        Integer current = dto.getCurrent();
+        Integer size = dto.getSize();
+        Integer start = (current-1) * size;
+        Integer end = current * size;
+        //获取当前合同节点下所有子节点
+        List<WbsNodeVO> vos = baseMapper.getAllChildNode(dto);
+        List<WbsNodeVO> list = ForestNodeMerger.merge(vos);
+        List<WbsNodeVO> list2 = new ArrayList<>();
+        for (WbsNodeVO vo : list) {
+            if (vo.getId().equals(dto.getNodeId())){
+                list2.add(vo);
+                break;
+            }
+        }
+        if (list2.size() == 0){
+            throw new ServiceException("获取首节点错误");
+        }
+        List<Long> ids = new ArrayList<>();
+        gatherSortNode2(list2, ids);
+        IPage<WbsFileVO> iPage = new Page<WbsFileVO>(current,size);
+        iPage.setTotal(ids.size());
+        if (ids.size() == 0){
+            iPage.setRecords(null);
+            iPage.setPages(1);
+        }else {
+            if (ids.size() <= size){
+                iPage.setPages(1);
+            }else {
+                iPage.setPages((int) Math.ceil(new Double(ids.size()) / new Double(size)));
+                if (ids.size() < end) {
+                    ids = ids.subList(start,ids.size());
+                }else {
+                    ids = ids.subList(start,end);
+                }
+            }
+        }
+        //查询节点资料
+        List<WbsFileVO> voList = baseMapper.getNodeData(ids);
+        //节点划分
+        if (voList.size() != 0){
+            StringBuilder str = new StringBuilder();
+            for (WbsFileVO vo : voList) {
+                str.append(vo.getAncestors()+",");
+            }
+            str.deleteCharAt(str.length() -1);
+            List<Long> longs = Func.toLongList(str.toString());
+            HashSet<Long> set = new HashSet<>(longs);
+            List<WbsTreeContract> infoList = baseMapper.getAllAncestors(set,dto.getContractId());
+            if (infoList.size() == 0){
+                throw new ServiceException("未获取到节点划分信息");
+            }
+            Map<Long, WbsTreeContract> map = infoList.stream().collect(Collectors.toMap(l -> l.getId(), l -> l));
+            for (WbsFileVO vo : voList) {
+                List<Long> longList = Func.toLongList(vo.getAncestors());
+                Collections.reverse(longList);
+                StringBuilder str2 = new StringBuilder();
+                if (vo.getNodeType() == 6){
+                    for (Long aLong : longList) {
+                        WbsTreeContract info = map.get(aLong);
+                        str2.append(info.getNodeName()+"/");
+                        if (info.getNodeType() == 4){
+                            break;
+                        }
+                    }
+                    str2.deleteCharAt(str2.length() -1);
+                }else {
+                    str2.append(vo.getNodeName());
+                }
+                vo.setPartName(str2.toString());
+            }
+        }
+        iPage.setRecords(voList);
+        return iPage;
+    }
+
     //递归方法
     private void gatherSortNode(List<NodeSortVO> list,List<Long> ids){
         for (NodeSortVO vo : list) {
@@ -607,4 +719,15 @@ public class MiddleMeterApplyServiceImpl extends BaseServiceImpl<MiddleMeterAppl
             }
         }
     }
+    //质检WBS树专用,可能会设置条件,不重载
+    private void gatherSortNode2(List<WbsNodeVO> list,List<Long> ids){
+        for (WbsNodeVO vo : list) {
+            if (vo.getChildren().size() == 0 && vo.getIsData() > 0){
+                ids.add(vo.getPId());
+                continue;
+            }else {
+                gatherSortNode2(vo.getChildren(), ids);
+            }
+        }
+    }
 }