Commit da2c79fb authored by dongyu's avatar dongyu

供应商类型查询修改

parent da966f59
package com.supServer.project.controller;
import com.supServer.framework.web.domain.AjaxResult;
import com.supServer.project.entity.BizCategory;
import com.supServer.project.entity.vo.BizCategoryVo;
import com.supServer.project.service.BizCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
......@@ -30,9 +28,8 @@ public class BizCategoryController {
* 供应商类型查询
*/
@PostMapping("/list/tree")
public AjaxResult list (BizCategoryVo vo) {
AjaxResult ajaxResult = bizCategoryService.listTree(vo);
return AjaxResult.success(ajaxResult);
public AjaxResult list (@RequestBody BizCategoryVo vo) {
return bizCategoryService.listTree(vo);
}
}
......@@ -5,6 +5,7 @@ import com.supServer.project.entity.vo.BizCategoryVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigInteger;
import java.util.List;
@Mapper
......@@ -12,4 +13,8 @@ public interface BizCategoryMapper {
List<BizCategory> listTree(@Param("vo") BizCategoryVo vo);
List<BizCategory> oneLevels(@Param("vo") BizCategoryVo vo);
List<BizCategory> twoLevels(@Param("vo") List<BigInteger> vo);
}
package com.supServer.project.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.supServer.framework.web.domain.AjaxResult;
import com.supServer.project.entity.BizCategory;
import com.supServer.project.entity.vo.BizCategoryVo;
import com.supServer.project.mapper.BizCategoryMapper;
import com.supServer.project.service.BizCategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -22,18 +29,72 @@ public class BizCategoryServiceImpl implements BizCategoryService {
@Override
public AjaxResult listTree(BizCategoryVo vo) {
List<BizCategory> list=bizCategoryMapper.listTree(vo);
if (CollectionUtil.isEmpty(list)) {
return AjaxResult.success(list);
List<BizCategory> res;
List<BizCategory> list = CollUtil.newArrayList();
if (ObjectUtil.isNull(vo) || StringUtils.isBlank(vo.getName())){
List<BizCategory> bizCategories = bizCategoryMapper.listTree(vo);
list.addAll(bizCategories);
}else {
//一级目录
List<BizCategory> oneLevels = bizCategoryMapper.oneLevels(vo);
if(CollUtil.isNotEmpty(oneLevels)){
list.addAll(oneLevels);
//一级目录id集合
List<BigInteger> oneCodes = oneLevels.stream().map(BizCategory::getCode).distinct().collect(Collectors.toList());
//根据一级目录id集合 查找二级目录
List<BizCategory> twoLevels = bizCategoryMapper.twoLevels(oneCodes);
if (CollUtil.isNotEmpty(twoLevels)){
list.addAll(twoLevels);
//二级目录id集合
List<BigInteger> twoCodes = twoLevels.stream().map(BizCategory::getCode).distinct().collect(Collectors.toList());
//三级目录
List<BizCategory> threeLevels = bizCategoryMapper.twoLevels(twoCodes);
if (CollUtil.isNotEmpty(threeLevels)) list.addAll(threeLevels);
}
}
}
// 2 组装成父子的树形结构
List<BizCategory> level1Menus = list.stream().filter(bizCategory ->
bizCategory.getParentCode().equals(BigInteger.ZERO)
).map((menu) -> {
menu.setChildren(getChildrens(menu, list));
return menu;
}).collect(Collectors.toList());
return AjaxResult.success(level1Menus);
//配置
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// 自定义属性名 都要默认值的
treeNodeConfig.setIdKey("code");
treeNodeConfig.setParentIdKey("parentCode");
treeNodeConfig.setWeightKey("level");
treeNodeConfig.setNameKey("name");
treeNodeConfig.setChildrenKey("children");
//转换器
List<Tree<String>> treeNodes = TreeUtil.build(list, "0", treeNodeConfig,
(treeNode, tree) -> {
tree.setId(treeNode.getCode().toString());
tree.setParentId(treeNode.getParentCode().toString());
tree.setWeight(treeNode.getLevel());
tree.setName(treeNode.getName());
tree.putExtra("showStatus",treeNode.getShowStatus());
tree.putExtra("catId",treeNode.getCatId());
tree.putExtra("sort",treeNode.getSort());
tree.putExtra("mark",treeNode.getMark());
tree.putExtra("userId",treeNode.getUserId());
tree.putExtra("createTime",treeNode.getCreateTime());
tree.putExtra("updateTime",treeNode.getUpdateTime());
tree.putExtra("userName",treeNode.getUserName());
});
String jsonStr = JSONUtil.toJsonStr(treeNodes);
JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
res = JSONUtil.toList(jsonArray, BizCategory.class);
return AjaxResult.success(res);
// List<BizCategory> list=bizCategoryMapper.listTree(vo);
// if (CollectionUtil.isEmpty(list)) {
// return AjaxResult.success(list);
// }
// // 2 组装成父子的树形结构
// List<BizCategory> level1Menus = list.stream().filter(bizCategory ->
// bizCategory.getParentCode().equals(BigInteger.ZERO)
// ).map((menu) -> {
// menu.setChildren(getChildrens(menu, list));
// return menu;
// }).collect(Collectors.toList());
// return AjaxResult.success(level1Menus);
}
......
......@@ -31,4 +31,27 @@
</select>
<select id="oneLevels" parameterType="com.supServer.project.entity.vo.BizCategoryVo" resultMap="BizCategoryResult">
select bc.*
from biz_category bc
<where>
<if test="vo.name != null and vo.name != ''">
and bc.name like concat('%', #{vo.name}, '%')
</if>
and bc.show_status='1'
and bc.parent_code=0
</where>
</select>
<select id="twoLevels" parameterType="java.util.List" resultMap="BizCategoryResult">
select bc.*
from biz_category bc
where bc.parent_code in
<foreach collection="vo" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
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