java 商品类目 递归
程序员文章站
2022-03-31 10:07:19
...
点击父类目查询出来下面的所有类目的编号
private List<String> findGoodsDirectoryNoListByParentNo(String directoryNo,List<String> dirNoList){
if(directoryNo==null||directoryNo.equals("")){
return dirNoList;
}else{
if(!dirNoList.contains(directoryNo)){
dirNoList.add(directoryNo);
}
}
try{
GoodsDirectoryDO gdo=goodsDirectoryService.getDirectoryNo(directoryNo);
int maxRank=goodsDirectoryService.maxRank();
if(gdo!=null&&gdo.getRank()!=null){
if(maxRank==gdo.getRank()){
if(!dirNoList.contains(directoryNo)){
dirNoList.add(directoryNo);
}
}else if(gdo.getRank()<maxRank){
if(goodsDirectoryService.getEntityByParentNo(directoryNo)!=null&&goodsDirectoryService.getEntityByParentNo(directoryNo).size()>0){
for(GoodsDirectoryDO d:goodsDirectoryService.getEntityByParentNo(directoryNo)){
if(!dirNoList.contains(d.getDirectoryNo())){
dirNoList.add(d.getDirectoryNo());
}
findGoodsDirectoryNoListByParentNo(d.getDirectoryNo(),dirNoList);
}
}else {
if(!dirNoList.contains(directoryNo)){
dirNoList.add(directoryNo);
}
}
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
return dirNoList;
}
}
mapper代码
<select id="getEntityByParentNo" resultType="com.zscat.erp.domain.GoodsDirectoryDO" parameterType="String">
select `id`,`directory_no`,`directory_name`,`directory_parent_no`,`rank` from erp_goods_directory where directory_parent_no = #{value}
</select>
<select id="maxRank" resultType="int">
select MAX(rank) from erp_goods_directory
</select>
数据库建表语句
CREATE TABLE `erp_goods_directory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`directory_no` varchar(225) DEFAULT NULL COMMENT '类目编号',
`directory_name` varchar(225) DEFAULT NULL COMMENT '类目名称',
`directory_parent_no` varchar(225) DEFAULT NULL COMMENT '类目父级编码',
`directory_parent_name` varchar(225) DEFAULT NULL COMMENT '类目父级名称',
`rank` int(11) DEFAULT NULL COMMENT '级别',
`wms_directory_id` bigint(20) DEFAULT NULL COMMENT 'wms商品类目id',
PRIMARY KEY (`id`),
KEY `index_name_directory_no` (`directory_no`)
) ENGINE=InnoDB AUTO_INCREMENT=169 DEFAULT CHARSET=utf8;
上一篇: 最容易犯的HTML标签错误写法_HTML/Xhtml_网页制作
下一篇: STL deque源码剖析