huangjn преди 3 години
родител
ревизия
d52e257d62

+ 34 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/dto/TreeContractFirstDTO.java

@@ -0,0 +1,34 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.dto;
+
+import org.springblade.business.entity.TreeContractFirst;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 合同段划分树首件关联表数据传输对象实体类
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class TreeContractFirstDTO extends TreeContractFirst {
+	private static final long serialVersionUID = 1L;
+
+}

+ 67 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/TreeContractFirst.java

@@ -0,0 +1,67 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.springblade.core.mp.base.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 合同段划分树首件关联表实体类
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+@Data
+@TableName("u_tree_contract_first")
+@EqualsAndHashCode(callSuper = true)
+public class TreeContractFirst extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 项目ID
+     */
+    private Long projectId;
+
+    /**
+     * 合同段ID
+     */
+    private Long contractId;
+
+    /**
+     * wbs_tree_contract表p_key_id
+     */
+    private Long wbsNodeId;
+
+    public TreeContractFirst(Long projectId, Long contractId, Long wbsNodeId, Long userId, String deptId){
+        this.projectId = projectId;
+        this.contractId = contractId;
+        this.wbsNodeId = wbsNodeId;
+        this.setCreateUser(userId);
+        this.setCreateDept(deptId.contains(",") ? Long.parseLong(String.valueOf(deptId).split(",")[0]) : Long.parseLong(deptId));
+        this.setCreateTime(new Date());
+    }
+
+    public TreeContractFirst(){}
+
+}

+ 34 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/vo/TreeContractFirstVO.java

@@ -0,0 +1,34 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.vo;
+
+import org.springblade.business.entity.TreeContractFirst;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 合同段划分树首件关联表视图实体类
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class TreeContractFirstVO extends TreeContractFirst {
+	private static final long serialVersionUID = 1L;
+
+}

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

@@ -121,26 +121,26 @@ public class InformationWriteQueryController extends BladeController {
 		return R.data(this.wbsTreeContractClient.removeContractTreeNode(ids));
 	}
 
-	/**
-	 * 新增子节点
-	 * @param contractNodePrimaryKeyId 新增的节点所在位置,即当前点出菜单栏的节点PrimaryKeyId
-	 * @param projectNodePrimaryKeyId 被选中的新增节点
-	 * @return 新增结果
-	 */
-	@PostMapping("/saveContractTreeNode")
-	@ApiOperationSupport(order = 10)
-	@ApiOperation(value = "新增节点及其子节点")
-	@ApiImplicitParams({
-			@ApiImplicitParam(name = "contractNodePrimaryKeyId", value = "新增的节点所在位置,即当前点出菜单栏的节点PrimaryKeyId", required = true),
-			@ApiImplicitParam(name = "projectNodePrimaryKeyId", value = "被选中的新增节点", required = true)
-	})
-	public R<Boolean> saveContractTreeNode(@RequestParam String contractNodePrimaryKeyId, @RequestParam String projectNodePrimaryKeyId){
-		//先获取当前节点的信息
-		WbsTreeContract treeContract = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.parseLong(contractNodePrimaryKeyId));
-		//检查当前节点下是否添加了子节点
-
-		return null;
-	}
+//	/**
+//	 * 新增子节点
+//	 * @param contractNodePrimaryKeyId 新增的节点所在位置,即当前点出菜单栏的节点PrimaryKeyId
+//	 * @param projectNodePrimaryKeyId 被选中的新增节点
+//	 * @return 新增结果
+//	 */
+//	@PostMapping("/saveContractTreeNode")
+//	@ApiOperationSupport(order = 10)
+//	@ApiOperation(value = "新增节点及其子节点")
+//	@ApiImplicitParams({
+//			@ApiImplicitParam(name = "contractNodePrimaryKeyId", value = "新增的节点所在位置,即当前点出菜单栏的节点PrimaryKeyId", required = true),
+//			@ApiImplicitParam(name = "projectNodePrimaryKeyId", value = "被选中的新增节点", required = true)
+//	})
+//	public R<Boolean> saveContractTreeNode(@RequestParam String contractNodePrimaryKeyId, @RequestParam String projectNodePrimaryKeyId){
+//		//先获取当前节点的信息
+//		WbsTreeContract treeContract = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.parseLong(contractNodePrimaryKeyId));
+//		//检查当前节点下是否添加了子节点
+//
+//		return null;
+//	}
 
 	/**
 	 * 懒加载项目级工程划分树

+ 179 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/TreeContractFirstController.java

@@ -0,0 +1,179 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.controller;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import io.swagger.annotations.*;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import lombok.AllArgsConstructor;
+
+import org.apache.commons.lang.StringUtils;
+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.Func;
+import org.springblade.manager.entity.WbsTreeContract;
+import org.springblade.manager.feign.WbsTreeContractClient;
+import org.springblade.manager.vo.WbsTreeContractTreeVOS;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springblade.business.entity.TreeContractFirst;
+import org.springblade.business.service.ITreeContractFirstService;
+import org.springblade.core.boot.ctrl.BladeController;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 合同段划分树首件关联表 控制器
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/treeContractFirst")
+@Api(value = "合同段划分树首件关联表", tags = "合同段划分树首件关联表接口")
+public class TreeContractFirstController extends BladeController {
+
+	private final ITreeContractFirstService treeContractFirstService;
+
+	private final WbsTreeContractClient wbsTreeContractClient;
+
+	/**
+	 * 新增或删除 合同段划分树首件关联表
+	 */
+	@PostMapping("/saveOrDelete")
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "新增或删除 合同段划分树首件关联")
+	@ApiImplicitParams({
+			@ApiImplicitParam(name = "primaryKeyId", value = "标记为首件的节点primaryKeyId或pKeyId", required = true),
+			@ApiImplicitParam(name = "saveOrDeleted", value = "新增为0,删除为1", required = true)
+	})
+	public R<Boolean> saveOrDelete(@RequestParam String primaryKeyId, @RequestParam Integer saveOrDeleted) {
+		//获取当前操作用户
+		BladeUser user = AuthUtil.getUser();
+		//获取当前节点的信息
+		WbsTreeContract nodeData = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.valueOf(primaryKeyId));
+		if(nodeData == null){
+			return R.data(-1, false, "未找到当前节点");
+		}
+		//获取当前节点的所有父节点和子节点
+		StringBuilder parentIds = new StringBuilder(), childIds = new StringBuilder();
+		//获取父节点
+		this.currentNodeAllParent(parentIds, nodeData);
+		//获取子节点
+		this.currentNodeAllChild(childIds, nodeData);
+
+		//判断是新增还是删除
+		if(new Integer("0").equals(saveOrDeleted)){
+			//新增集合
+			List<TreeContractFirst> save = new ArrayList<>();
+			//新增当前节点
+			save.add(new TreeContractFirst(Long.parseLong(nodeData.getProjectId()), Long.parseLong(nodeData.getContractId()), nodeData.getPKeyId(), user.getUserId(), user.getDeptId()));
+			//新增当前节点下的子节点
+			if(StringUtils.isNotEmpty(childIds.toString()) && !",".equals(childIds.toString())){
+				String[] childArray = childIds.toString().split(",");
+				for(String child : childArray){
+					if(StringUtils.isNotEmpty(child)){
+						save.add(new TreeContractFirst(Long.parseLong(nodeData.getProjectId()), Long.parseLong(nodeData.getContractId()), Long.parseLong(child), user.getUserId(), user.getDeptId()));
+					}
+				}
+			}
+			//新增父节点
+			if(StringUtils.isNotEmpty(parentIds.toString()) && !",".equals(parentIds.toString())){
+				//新增父节点需要判断当前父节点是否已经被标记为首件
+				String[] parentIdArray = parentIds.toString().split(",");
+				for(String parentId : parentIdArray){
+					//判断是否被标记为首件
+					TreeContractFirst old = this.treeContractFirstService.getOne(Wrappers.<TreeContractFirst>lambdaQuery().eq(TreeContractFirst::getWbsNodeId, parentId).eq(TreeContractFirst::getIsDeleted, 0));
+					if(old == null){
+						//说明没有被标记,新增
+						save.add(new TreeContractFirst(Long.parseLong(nodeData.getProjectId()), Long.parseLong(nodeData.getContractId()), Long.parseLong(parentId), user.getUserId(), user.getDeptId()));
+					}
+				}
+			}
+			//最后操作落库
+			return R.data(this.treeContractFirstService.saveBatch(save));
+		} else {
+			//删除自身
+			boolean resultBol = this.treeContractFirstService.update(Wrappers.<TreeContractFirst>lambdaUpdate().set(TreeContractFirst::getIsDeleted, 1).eq(TreeContractFirst::getWbsNodeId, primaryKeyId));
+			//删除子节点
+			if(StringUtils.isNotEmpty(childIds.toString()) && !",".equals(childIds.toString())){
+				//存在子节点,均更改为删除状态
+				resultBol = this.treeContractFirstService.update(Wrappers.<TreeContractFirst>lambdaUpdate().set(TreeContractFirst::getIsDeleted, 1).in(TreeContractFirst::getWbsNodeId, Func.toLongList(childIds.toString())));
+			}
+			//删除父节点
+			if(StringUtils.isNotEmpty(parentIds.toString()) && !",".equals(parentIds.toString())){
+				//删除父节点情况相对复杂,需要判断对应节点下的是否还存在子节点处于首件状态,如果存在那么当前父节点就不能被删除掉
+				String[] parentIdArray = parentIds.toString().split(",");
+				//判断需要删除的节点集合
+				List<String> deleted = new ArrayList<>();
+				for(String parentId : parentIdArray){
+					if(StringUtils.isNotEmpty(parentId)){
+						//首先获取当前父节点的下一级子节点
+						WbsTreeContract parentNode = this.wbsTreeContractClient.getContractNodeByPrimaryKeyId(parentId);
+						List<WbsTreeContractTreeVOS> oneChild = this.wbsTreeContractClient.queryContractWbsTreeByContractIdAndType(nodeData.getContractId(), nodeData.getDeptCategory(), String.valueOf(parentNode.getId()));
+						List<String> ids = new ArrayList<>();
+						oneChild.forEach(child -> ids.add(child.getPrimaryKeyId()));
+						//判断是否存在首件标记
+						List<TreeContractFirst> result = this.treeContractFirstService.list(Wrappers.<TreeContractFirst>lambdaQuery().in(TreeContractFirst::getWbsNodeId, ids).eq(TreeContractFirst::getIsDeleted, 0));
+						if(result != null && result.size() != 0){
+							//result不为空且有数据,说明当前节点下的子节点仍存在除了 nodeData 外的节点处于首件标记,那么当前节点及其更上级节点都不能被取消首件标记,故直接中断循环
+							break;
+						} else {
+							//反之,说明当前节点下的子节点已经不存在处理首件标记的有效记录,则当前节点可以被取消首件标记
+							deleted.add(parentId);
+							//之后对当前节点的上一级做相同判断
+						}
+					}
+				}
+				//最后执行父节点删除
+				if(deleted.size() != 0){
+					resultBol = this.treeContractFirstService.update(Wrappers.<TreeContractFirst>lambdaUpdate().set(TreeContractFirst::getIsDeleted, 1).in(TreeContractFirst::getWbsNodeId, deleted));
+				}
+			}
+			return R.data(resultBol);
+		}
+	}
+
+	/**
+	 * 获取所有父节点
+	 */
+	private void currentNodeAllParent(StringBuilder parentIds, WbsTreeContract currentNode){
+		if(!"0".equals(String.valueOf(currentNode.getParentId()))){
+			//如果父节点不是0说明没到顶层
+			WbsTreeContract parentNode = this.wbsTreeContractClient.queryCurrentNodeAllParent(Long.parseLong(currentNode.getContractId()), currentNode.getParentId());
+			if(parentNode != null){
+				parentIds.append(",").append(parentNode.getPKeyId());
+				this.currentNodeAllParent(parentIds, parentNode);
+			}
+		}
+	}
+
+	/**
+	 * 获取所有子节点
+	 */
+	private void currentNodeAllChild(StringBuilder childIds, WbsTreeContract currentNode){
+		//获取所有子节点
+		List<WbsTreeContract> childList = this.wbsTreeContractClient.queryCurrentNodeAllChild(Long.parseLong(currentNode.getContractId()), currentNode.getId());
+		if(childList != null && childList.size() != 0){
+			childList.forEach(child -> childIds.append(",").append(child.getPKeyId()));
+		}
+	}
+
+}

+ 33 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TreeContractFirstMapper.java

@@ -0,0 +1,33 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.mapper;
+
+import org.springblade.business.entity.TreeContractFirst;
+import org.springblade.business.vo.TreeContractFirstVO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import java.util.List;
+
+/**
+ * 合同段划分树首件关联表 Mapper 接口
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+public interface TreeContractFirstMapper extends BaseMapper<TreeContractFirst> {
+
+}

+ 20 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TreeContractFirstMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.business.mapper.TreeContractFirstMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="treeContractFirstResultMap" type="org.springblade.business.entity.TreeContractFirst">
+        <result column="id" property="id"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_dept" property="createDept"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="project_id" property="projectId"/>
+        <result column="contract_id" property="contractId"/>
+        <result column="wbs_node_id" property="wbsNodeId"/>
+    </resultMap>
+
+</mapper>

+ 30 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/ITreeContractFirstService.java

@@ -0,0 +1,30 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.service;
+
+import org.springblade.business.entity.TreeContractFirst;
+import org.springblade.core.mp.base.BaseService;
+
+/**
+ * 合同段划分树首件关联表 服务类
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+public interface ITreeContractFirstService extends BaseService<TreeContractFirst> {
+
+}

+ 34 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TreeContractFirstServiceImpl.java

@@ -0,0 +1,34 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.service.impl;
+
+import org.springblade.business.entity.TreeContractFirst;
+import org.springblade.business.mapper.TreeContractFirstMapper;
+import org.springblade.business.service.ITreeContractFirstService;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 合同段划分树首件关联表 服务实现类
+ *
+ * @author BladeX
+ * @since 2022-06-16
+ */
+@Service
+public class TreeContractFirstServiceImpl extends BaseServiceImpl<TreeContractFirstMapper, TreeContractFirst> implements ITreeContractFirstService {
+
+}