Commit ac71bdf8 authored by zhaochengming's avatar zhaochengming

赵呈明 --服务分类树

parent 98af6324
package com.pms.ocp.common.utils;
import org.apache.commons.lang3.RandomStringUtils;
import java.util.Random;
/**
* @author zhaochengming
* 随机生成字符串
*/
public class RandomStringUtil {
/**
* length 字符串长度
* @param length
* @return
*/
public static String getRandomString(int length){
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random=new Random();
StringBuffer sb=new StringBuffer();
for(int i=0;i<length;i++){
int number=random.nextInt(62);
sb.append(str.charAt(number));
}
return sb.toString();
}
}
package com.pms.ocp.controller;
import com.pms.ocp.model.dto.ApiParamDTO;
import com.pms.ocp.model.dto.ApiTreeGroupDto;
import com.pms.ocp.model.dto.OcpApiGroupDtos;
import com.pms.ocp.model.entity.OcpApiBase;
import com.pms.ocp.model.entity.OcpApiGroup;
import com.pms.ocp.model.vo.ResponseVO;
import com.pms.ocp.service.OcpApiTreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RequestMapping("/api-group/v1")
......@@ -52,8 +49,11 @@ public class OcpApiTreeController {
@PostMapping("/updatatree")
@ApiOperation("服务树分类--修改")
public ResponseVO updataTree(@RequestBody OcpApiGroup ocpApiGroup){
service.updataOcpTree(ocpApiGroup);
return ResponseVO.ok();
boolean flag = service.updataOcpTree(ocpApiGroup);
if (flag){
return ResponseVO.ok();
}
return ResponseVO.error("您输入的服务编码重复,请重新输入");
}
@PostMapping("/deletetree")
@ApiOperation("服务树分类--删除")
......
......@@ -2,6 +2,7 @@ package com.pms.ocp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pms.ocp.model.entity.Model;
import com.pms.ocp.model.entity.ModelProperty;
import org.apache.ibatis.annotations.Mapper;
/**
......
......@@ -4,6 +4,7 @@ package com.pms.ocp.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pms.ocp.model.dto.ApiTreeGroupDto;
import com.pms.ocp.model.dto.OcpApiGroupDtos;
import com.pms.ocp.model.entity.OcpApiBase;
import com.pms.ocp.model.entity.OcpApiGroup;
......@@ -25,7 +26,7 @@ public interface OcpApiTreeService extends IService<OcpApiGroup> {
*/
void updataOcpTree(OcpApiGroup ocpApiGroup);
boolean updataOcpTree(OcpApiGroup ocpApiGroup);
/**
* 删除服务分类
......
package com.pms.ocp.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pms.ocp.common.utils.RandomStringUtil;
import com.pms.ocp.mapper.OcpApiBaseMapper;
import com.pms.ocp.mapper.OcpApiTreeMapper;
import com.pms.ocp.model.dto.*;
import com.pms.ocp.model.entity.OcpApiBase;
import com.pms.ocp.model.entity.OcpApiGroup;
import com.pms.ocp.service.OcpApiTreeService;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -40,7 +42,7 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
//服务树分类对象
ApiTreeGroupDto apiTreeGroupList = new ApiTreeGroupDto();
//一级服务分类
//1中台层
List<OneTreeUpList> oneTreeUpLists = new ArrayList<>();
for (OcpApiGroup ocpApiGroup : ocpApiGroups) {
......@@ -49,10 +51,9 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
//一级服务对象
OneTreeUpList oneTreeUpList = new OneTreeUpList();
// 判断数据是否有上级服务分类
if ("".equals(ocpApiGroup.getApiGroupPcode())) {
if (ocpApiGroup.getApiGroupLevel() == 1) {
BeanUtils.copyProperties(ocpApiGroup, oneTreeUpList);
oneTreeUpLists.add(oneTreeUpList);
}
}
......@@ -60,7 +61,7 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
}
List<TwoDownList> twoDownLists = twoTreeLists(oneTreeUpLists, ocpApiGroups);
List<ThreeTreeList> threeTreeLists = threeTreeLists(twoDownLists, ocpApiGroups);
apiTreeGroupList.setOneupList(oneTreeUpLists);
apiTreeGroupList.setOneList(oneTreeUpLists);
apiTreeGroupList.setTwoList(twoDownLists);
apiTreeGroupList.setThreeList(threeTreeLists);
......@@ -68,55 +69,68 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
}
/**
* 二级目录
* 2中心层
* @param oneTreeUpLists
* @return
*/
public List<TwoDownList> twoTreeLists(List<OneTreeUpList> oneTreeUpLists,List<OcpApiGroup> ocpApiGroups){
List<OcpApiGroup> twolists = new ArrayList<>();
List<TwoDownList> twoTreeLists = new ArrayList<>();
//服务树全表数据
for (OneTreeUpList oneTreeUpList : oneTreeUpLists) {
String code = oneTreeUpList.getApiGroupCode();
for (OcpApiGroup ocpApiGroup : ocpApiGroups ) {
if (code.equals(ocpApiGroup.getApiGroupPcode())) {
TwoDownList twoDownList = new TwoDownList();
BeanUtils.copyProperties(ocpApiGroup,twoDownList);
twoTreeLists.add(twoDownList);
}
for (OcpApiGroup ocpApiGroup : ocpApiGroups) {
if (!(ocpApiGroup.getIsDelete() == 0)){
if (ocpApiGroup.getApiGroupLevel() == 2){
twolists.add(ocpApiGroup);
}else {
continue;
}
}
}
BeanUtils.copyProperties(twolists,twoTreeLists);
return twoTreeLists;
}
/**
* 三级目录
* 3服务组层
* @param twoDownLists
* @return
*/
public List<ThreeTreeList> threeTreeLists(List<TwoDownList> twoDownLists,List<OcpApiGroup> ocpApiGroups){
List<ThreeTreeList> threeTreeLists = new ArrayList<>();
for (TwoDownList twoDownList : twoDownLists) {
List<OcpApiGroup> threeLists = new ArrayList<>();
for (OcpApiGroup ocpApiGroup : ocpApiGroups) {
String code = twoDownList.getApiGroupCode();
if (code.equals(ocpApiGroup.getApiGroupPcode())){
ThreeTreeList threeTreeList = new ThreeTreeList();
BeanUtils.copyProperties(ocpApiGroup,threeTreeList);
threeTreeLists.add(threeTreeList);
/* threeTreeList.setThreeList(ocpApiGroup);
threeTreeLists.add(threeTreeList);*/
if (!(ocpApiGroup.getIsDelete() == 0)) {
if (ocpApiGroup.getApiGroupLevel() == 3){
threeLists.add(ocpApiGroup);
}
}else {
continue;
}
}
BeanUtils.copyProperties(threeLists,threeTreeLists);
}
return threeTreeLists;
}
/**
* 4服务层
* @param threeTreeLists
* @return
*/
public List<FourTreeList> fourTreeLists(List<ThreeTreeList> threeTreeLists,List<OcpApiGroup> ocpApiGroups){
List<FourTreeList> foureTreeList = new ArrayList<>();
List<OcpApiGroup> foureLists = new ArrayList<>();
for (OcpApiGroup ocpApiGroup : ocpApiGroups) {
if (!(ocpApiGroup.getIsDelete() == 0)) {
if (ocpApiGroup.getApiGroupLevel() == 4){
foureLists.add(ocpApiGroup);
}
}else {
continue;
}
BeanUtils.copyProperties(foureLists,foureTreeList);
}
return foureTreeList;
}
/**
......@@ -127,6 +141,8 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
@Override
public boolean insertTree(OcpApiGroupDtos ocpApiGroupDtos) {
String code = RandomStringUtil.getRandomString(6);
boolean flag = true;
List<OcpApiGroup> ocpApiGroups = mapper.selectList(null);
for (OcpApiGroup ocpApiGroup : ocpApiGroups) {
......@@ -139,16 +155,17 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
OcpApiBase ocpApiBase = new OcpApiBase();
ocpApiBase.setApiCode(ocpApiGroupDtos.getApiGroupCode());
BeanUtils.copyProperties(ocpApiGroupDtos, ocpApiBase);
ocpApiBase.setApiGroupCode(code);
ocpApiBase.setApiName("新增服务分类");
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
ocpApiBase.setApiMtime(timestamp);
ocpApiBase.setApiCtime(ocpApiGroupDtos.getApiGroupCtime());
ocpApiBase.setApiUserId(ocpApiGroupDtos.getApiGroupUserId());
ocpApiBase.setObjId("");
OcpApiGroup ocpApiGroup1 = new OcpApiGroup();
ocpApiGroup1.setObjId("");
BeanUtils.copyProperties(ocpApiGroupDtos, ocpApiGroup1);
ocpApiGroup1.setApiGroupCode(code);
ocpApiBaseMapper.insert(ocpApiBase);
mapper.insert(ocpApiGroup1);
......@@ -164,8 +181,18 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
* @param
*/
@Override
public void updataOcpTree(OcpApiGroup ocpApiGroup) {
public boolean updataOcpTree(OcpApiGroup ocpApiGroup) {
boolean falg = true;
List<OcpApiGroup> ocpApiGroups = mapper.selectList(null);
for (OcpApiGroup apiGroup : ocpApiGroups) {
String code = apiGroup.getApiGroupCode();
if (code == ocpApiGroup.getApiGroupCode()){
falg = false;
break;
}
}
mapper.updateById(ocpApiGroup);
return falg;
}
......@@ -179,7 +206,6 @@ public class OcpApiTreeServiceImpl extends ServiceImpl<OcpApiTreeMapper,OcpApiGr
public boolean deleteOcpTree(OcpApiGroup ocpApiGroup) {
String objId = ocpApiGroup.getObjId();
OcpApiGroup ocpApiGroup1 = mapper.selectById(objId);
if(StringUtils.isBlank(ocpApiGroup1.getApiGroupPcode())){
mapper.deleteById(objId);
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment