jihs преди 4 години
родител
ревизия
4d3fb6a022

+ 73 - 2
src/main/java/org/jeecg/common/dto/archives/ProPlanListRespDTO.java

@@ -3,6 +3,11 @@ package org.jeecg.common.dto.archives;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import org.jeecg.modules.archives.entity.ProjectManageBusinessOther;
+
+import java.util.List;
 
 /**
  * @Author jihaosen
@@ -10,7 +15,6 @@ import lombok.Data;
  */
 
 @ApiModel("项目档案计划列表参数请求")
-@Data
 public class ProPlanListRespDTO {
     @ApiModelProperty("id")
     private String id;
@@ -19,12 +23,79 @@ public class ProPlanListRespDTO {
     @ApiModelProperty("里程碑名称")
     private String milesName;
 
+    private String key;
+    private String title;
+    private String parentId;
+    private boolean isLeaf;
+   @Getter
+   @Setter
+    private List<ProPlanListRespDTO> children;
     public ProPlanListRespDTO() {
     }
 
-    public ProPlanListRespDTO(String id, String muilesId, String milesName) {
+    public ProPlanListRespDTO(ProjectManageBusinessOther other) {
+        this.id = other.getId();
+        this.muilesId = other.getMuilesId();
+        this.milesName = other.getMuilesName();
+        this.key = other.getKeyId();
+        this.title = other.getMuilesName();
+        this.parentId = other.getParentId();
+        this.isLeaf = false;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
         this.id = id;
+    }
+
+    public String getMuilesId() {
+        return muilesId;
+    }
+
+    public void setMuilesId(String muilesId) {
         this.muilesId = muilesId;
+    }
+
+    public String getMilesName() {
+        return milesName;
+    }
+
+    public void setMilesName(String milesName) {
         this.milesName = milesName;
     }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(String parentId) {
+        this.parentId = parentId;
+    }
+
+    public boolean getIsLeaf() {
+        return isLeaf;
+    }
+
+    public void setIsLeaf(boolean isLeaf) {
+        this.isLeaf = isLeaf;
+    }
 }

+ 58 - 5
src/main/java/org/jeecg/modules/archives/controller/ProjectManageArchivesController.java

@@ -15,6 +15,7 @@ import org.jeecg.common.dto.archives.ProArchivesAddReqDTO;
 import org.jeecg.common.dto.archives.ProArchivesAddRespDTO;
 import org.jeecg.common.dto.archives.ProPlanListReqDTO;
 import org.jeecg.common.dto.archives.ProPlanListRespDTO;
+import org.jeecg.common.dto.basedata.ArchivesMilestoneListRespDTO;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.modules.archives.entity.ProjectManageArchives;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -24,8 +25,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.modules.archives.entity.ProjectManageBusinessOther;
 import org.jeecg.modules.archives.service.ProjectManageArchivesService;
 import org.jeecg.modules.archives.service.ProjectManageBusinessOtherService;
+import org.jeecg.modules.basedata.entity.BaseArchivesMilestone;
 import org.jeecg.modules.payment.service.ManagerPaymentAndReceiptSlipService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -34,6 +37,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
    * @Author jihaosen
@@ -295,7 +300,8 @@ public class ProjectManageArchivesController {
 
 	@ApiOperation(value = "项目档案计划列表查询", notes = "根据主表id查询项目档案计划列表")
 	@ApiImplicitParams({
-			@ApiImplicitParam(name="id", value="id",required=true, dataType="String")
+			@ApiImplicitParam(name="id", value="id",required=true, dataType="String"),
+			@ApiImplicitParam(name="planType", value="计划类型",required=true, dataType="String")
 	})
 	@GetMapping(value = "/getPlanListById")
 	public Result<List<ProPlanListRespDTO>> getListById(@Valid ProPlanListReqDTO reqDTO, BindingResult bindingResult) {
@@ -313,10 +319,8 @@ public class ProjectManageArchivesController {
 					.eq("plan_type", reqDTO.getPlanType());
 
 			   List<ProjectManageBusinessOther> list = projectManageBusinessOtherService.list(queryWrapper);
-               List<ProPlanListRespDTO> respDTOS = Lists.newArrayList();
-               for(ProjectManageBusinessOther other : list){
-				   respDTOS.add(new ProPlanListRespDTO(other.getId(), other.getMuilesId(), other.getMuilesName()));
-			   }
+			   list.sort((x, y) -> Integer.compare(x.getSort(), y.getSort()));
+			   List<ProPlanListRespDTO> respDTOS = getTreeList(list);
 				result.setResult(respDTOS);
 				result.setSuccess(true);
 		}
@@ -327,4 +331,53 @@ public class ProjectManageArchivesController {
 			}
 		return result;
 	}
+
+
+
+	/**
+	 * @desc 将计划列表转成树状结构
+	 */
+	private List<ProPlanListRespDTO> getTreeList( List<ProjectManageBusinessOther> list) {
+		List<ProPlanListRespDTO> resp = Lists.newArrayList();
+		//根据parentId分组
+		Map<String, List<ProjectManageBusinessOther>> postMap = list.stream().collect(Collectors.groupingBy(ProjectManageBusinessOther :: getParentId));
+		List<ProjectManageBusinessOther>  baseArchivesMilestones = postMap.get("0");
+		if(CollectionUtils.isEmpty(baseArchivesMilestones)){
+			return null;
+		}
+		for(ProjectManageBusinessOther other : baseArchivesMilestones){
+			ProPlanListRespDTO respDTO = new ProPlanListRespDTO(other);
+			respDTO.setChildren(getChildes(list, respDTO.getKey(), postMap));
+			//判断是否为末节点
+			List<ProjectManageBusinessOther> posts = postMap.get(respDTO.getKey());
+			if(CollectionUtils.isEmpty(posts)){
+				respDTO.setIsLeaf(true);
+				respDTO.setChildren(null);
+			}
+			resp.add(respDTO);
+		}
+		return resp;
+	}
+
+	/**
+	 * @desc 获取子节点数据
+	 */
+	private List<ProPlanListRespDTO> getChildes(List<ProjectManageBusinessOther> list, String key, Map<String, List<ProjectManageBusinessOther>> postMap) {
+		List<ProPlanListRespDTO> resp = Lists.newArrayList();
+		for(ProjectManageBusinessOther other : list){
+			if(other.getParentId().equals(key)){
+				ProPlanListRespDTO respDTO = new ProPlanListRespDTO(other);
+				respDTO.setChildren(getChildes(list, respDTO.getKey(), postMap));
+				//判断是否为末节点
+				List<ProjectManageBusinessOther> posts = postMap.get(respDTO.getKey());
+				if(CollectionUtils.isEmpty(posts)){
+					respDTO.setIsLeaf(true);
+					respDTO.setChildren(null);
+				}
+				resp.add(respDTO);
+			}
+		}
+		return resp;
+	}
+
 }