Commit 08e51347 authored by 胡秀武's avatar 胡秀武

胡秀武:模型分类bug修复

parent 363b84b9
package com.pms.ocp.common.utils;
import lombok.Data;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author huxiuwu
* @version 1.0
* @date 2022/3/14 15:38
*/
@Data
public class PageUtil<T> {
/**
* 实体类列表
*/
List<T> content;
/**
* 是否首页
*/
boolean first;
/**
* 是否尾页
*/
boolean last;
/**
* 总记录数
*/
Integer totalElements;
/**
* 总页数
*/
Integer totalPages;
Integer numberOfElements;
/**
* 每页记录数
*/
Integer size;
/**
* 当前页
*/
Integer number;
public void pageUtil(Integer page, Integer size, List<T> list) {
List<T> list1 = list.stream().skip((page - 1) * size).limit(size).collect(Collectors.toList());
int length = list.size();
this.first = (page == 0);//是否第一页
this.last = (page == (length - 1) / size);//是否最后一页
this.totalPages = ((length - 1) / size + 1);//总页数
this.totalElements = (length);//总elements
this.size = (size);//每页多少elements
this.content = (list1);//内容
this.numberOfElements = (list1.size());//当前页elements
this.number = (page);//当前页数,第一页是0
}
}
......@@ -50,7 +50,7 @@ public class ModelClassifyController {
**/
@ApiOperation("右侧子类详情列表")
@GetMapping("/subclassDetailsList")
public ResponseVO<PageInfo<OcpModelGroupVO>> subclassDetailsList(@RequestParam int currentPage,
public ResponseVO subclassDetailsList(@RequestParam int currentPage,
@RequestParam int pageSize,
@RequestParam(required = false,defaultValue = "") String parentGroupCode,
@RequestParam(required = false,defaultValue = "") String subclassGroupName
......
......@@ -35,10 +35,12 @@ public class TreeNode implements Serializable {
private String companyCode;
@ApiModelProperty("子类")
private List<TreeNode> children;
private int belongLevel;
@ApiModelProperty("子类")
private int belongLevel;
private List<TreeNode> children;
public String getCode() {
return code == null ? "":code;
......
......@@ -2,9 +2,8 @@ package com.pms.ocp.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pms.ocp.common.constants.CodeEnum;
import com.pms.ocp.common.utils.PageUtil;
import com.pms.ocp.mapper.ModelClassifyMapper;
import com.pms.ocp.model.entity.ModelClassify;
import com.pms.ocp.model.vo.OcpModelGroupVO;
......@@ -60,10 +59,10 @@ public class ModelClassifyServiceImpl implements ModelClassifyService {
* 的map.第二次是根据搜素框的值进行模糊查询
* @return pms.ocp.model.vo.ResponseVO
* @author huxiuwu
* @date 2022/3/9
* @date 2022/3/9 <PageInfo<OcpModelGroupVO>>
**/
@Override
public ResponseVO<PageInfo<OcpModelGroupVO>> subclassDetailsList(int currentPage,int pageSize,String parentGroupCode,String subclassGroupName) {
public ResponseVO subclassDetailsList(int currentPage,int pageSize,String parentGroupCode,String subclassGroupName) {
//查询所有
List<OcpModelGroupVO> ocpModelGroupVOList = this.selectByCondition(null,null);
//将查询到所有数据的list转换为key为分类code,value为本身的map
......@@ -71,14 +70,13 @@ public class ModelClassifyServiceImpl implements ModelClassifyService {
//根据key获取前端传入code的对象
OcpModelGroupVO ocpModelGroupVO = groupByCode.get(parentGroupCode);
//模糊查询
PageHelper.startPage(currentPage,pageSize);
List<OcpModelGroupVO> dimConditionList = this.selectByCondition(null,subclassGroupName);
//递归获取模糊查询后属于parentGroupCode子集
List<OcpModelGroupVO> childrenList = findChildren(dimConditionList, ocpModelGroupVO, new LinkedList<>());
PageInfo<OcpModelGroupVO> pageInfo = new PageInfo<>(childrenList);
return ResponseVO.ok(pageInfo);
PageUtil<OcpModelGroupVO> pageUtil = new PageUtil<>();
pageUtil.pageUtil(currentPage,pageSize,childrenList);
return ResponseVO.ok(pageUtil);
}
/**
* 修改
*
......@@ -117,25 +115,28 @@ public class ModelClassifyServiceImpl implements ModelClassifyService {
* 获取父节点下的所有子节点放入list中
* @author huxiuwu
* @date 2022/3/9
* @param groupList
* @param childList
* @param
* @param
* @param
* @return void
**/
private List<OcpModelGroupVO> findChildren(List<OcpModelGroupVO> groupList, OcpModelGroupVO parent,List<OcpModelGroupVO> childList) {
for (OcpModelGroupVO vo : groupList) {
//遍历出父id等于参数的id,add进子节点集合
if (parent!= null
&& parent.getModelGroupCode()
.equals(vo.getModelGroupPcode())) {
&& parent.getModelGroupCode()
.equals(vo.getModelGroupPcode())
&& !"".equals(parent.getModelGroupCode())) {
//递归遍历下一级
vo.setModelGroupPName(parent.getModelGroupName());
childList.add(vo);
childList = findChildren(groupList,vo,childList);
vo.setModelGroupPName(parent.getModelGroupName());
if (!childList.remove(vo)){
childList.add(vo);
}
findChildren(groupList, vo, childList);
}
}
return childList;
}
/**
* 构建树节点
* @author huxiuwu
......@@ -162,7 +163,6 @@ public class ModelClassifyServiceImpl implements ModelClassifyService {
//设置上级父类名称
node.setModelGroupPName(parent.getModelGroupName());
//说明他有父类其下子类都需要加一级
addLevel(node,treeNodes);
parent.getChildrenList().add(node);
continue;
}
......@@ -170,6 +170,7 @@ public class ModelClassifyServiceImpl implements ModelClassifyService {
}
return result;
}
/**
*
* @author huxiuwu
......
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