## 商品专区分类

This commit is contained in:
zhangheng 2025-10-27 15:22:35 +08:00
parent 99b1c66e32
commit 3444a192e9
6 changed files with 173 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.sale.product.controller.manage.params.AreaClassifyParam;
import com.hzs.sale.product.service.IBdAreaClassifyService;
import com.hzs.sale.product.vo.AreaClassifyTreeVo;
import com.hzs.sale.product.vo.AreaClassifyVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -42,6 +43,21 @@ public class ApiAreaClassifyController extends BaseController {
return AjaxResult.success(list);
}
/**
* 查询分类列表(拼接树形结构)
* @param areaClassifyParam
* @return
*/
@GetMapping("/listTree")
public AjaxResult listTree(AreaClassifyParam areaClassifyParam) {
areaClassifyParam.setEnableState(EYesNo.YES.getIntValue());
areaClassifyParam.setPkCountry(SecurityUtils.getPkCountry());
List<Tree<String>> treeList = iBdAreaClassifyService.selectByAreaClassifyListAll(areaClassifyParam);
return AjaxResult.success(treeList);
}
/**
* 查询第一层分类

View File

@ -4,6 +4,7 @@ package com.hzs.sale.product.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzs.common.domain.sale.product.BdAreaClassify;
import com.hzs.sale.product.controller.manage.params.AreaClassifyParam;
import com.hzs.sale.product.vo.AreaClassifyTreeVo;
import com.hzs.sale.product.vo.AreaClassifyVo;
import java.util.List;
@ -23,4 +24,6 @@ public interface BdAreaClassifyMapper extends BaseMapper<BdAreaClassify> {
* @return
*/
List<AreaClassifyVo> selectByAreaClassifyList(AreaClassifyParam areaClassifyParam);
List<AreaClassifyTreeVo> selectByAreaClassifyListAll(AreaClassifyParam areaClassifyParam);
}

View File

@ -1,8 +1,10 @@
package com.hzs.sale.product.service;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hzs.common.domain.sale.product.BdAreaClassify;
import com.hzs.sale.product.controller.manage.params.AreaClassifyParam;
import com.hzs.sale.product.vo.AreaClassifyTreeVo;
import com.hzs.sale.product.vo.AreaClassifyVo;
import com.hzs.system.sys.dto.LoginUser;
@ -51,4 +53,6 @@ public interface IBdAreaClassifyService extends IService<BdAreaClassify> {
* @param pkId
*/
void deleteAreaClassify(Integer pkId);
List<Tree<String>> selectByAreaClassifyListAll(AreaClassifyParam areaClassifyParam);
}

View File

@ -1,6 +1,8 @@
package com.hzs.sale.product.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EDelFlag;
@ -11,15 +13,15 @@ import com.hzs.sale.product.controller.manage.params.AreaClassifyParam;
import com.hzs.sale.product.mapper.BdAreaClassifyMapper;
import com.hzs.sale.product.service.IBdAreaClassifyService;
import com.hzs.sale.product.service.IBdAreaClassifySpecialAreaService;
import com.hzs.sale.product.vo.AreaClassifyTreeVo;
import com.hzs.sale.product.vo.AreaClassifyVo;
import com.hzs.system.sys.dto.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* 商品分类 服务实现类
@ -108,4 +110,31 @@ public class BdAreaClassifyServiceImpl extends ServiceImpl<BdAreaClassifyMapper,
iBdAreaClassifySpecialAreaService.deleteByAreaClassifyPk(pkId);
}
@Override
public List<Tree<String>> selectByAreaClassifyListAll(AreaClassifyParam areaClassifyParam) {
List<AreaClassifyTreeVo> flatList = baseMapper.selectByAreaClassifyListAll(areaClassifyParam);
flatList.forEach(vo -> {
vo.setId(String.valueOf(vo.getPkId()));
vo.setParentId(vo.getPkParent() != 0L ? String.valueOf(vo.getPkParent()) : "0");
});
return TreeUtil.build(flatList, "0", (node, tree) -> {
tree.setId(node.getId());
tree.setParentId(node.getParentId());
tree.setName(node.getClassifyName());
tree.putExtra("classifyImg",node.getClassifyImg());
tree.putExtra("classifyName",node.getClassifyName());
tree.putExtra("creationTime",node.getCreationTime());
tree.putExtra("enableState",node.getEnableState());
tree.putExtra("hierarchy",node.getHierarchy());
tree.putExtra("pkCountry",node.getPkCountry());
tree.putExtra("pkCreator",node.getPkCreator());
tree.putExtra("pkId",node.getPkId());
tree.putExtra("pkParent",node.getPkParent());
tree.putExtra("sort",node.getSort());
});
}
}

View File

@ -0,0 +1,81 @@
package com.hzs.sale.product.vo;
import com.hzs.common.core.web.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class AreaClassifyTreeVo extends BaseEntity implements Serializable {
/**
* 主键
*/
private Integer pkId;
/**
* 所属专区
*/
private List<Integer> specialArea;
/**
* 分类名称
*/
private String classifyName;
/**
* 排序
*/
private Integer sort;
/**
* 上级专区主键
*/
private Long pkParent;
/**
* 分类图片
*/
private String classifyImg;
/**
* 是否启用
*/
private Integer enableState;
/**
* 层级 0 表示 第一层
*/
private Integer hierarchy;
/**
* 上级分类名称
*/
private String parentClassifyName;
/**
* 下级数量
*/
private Integer levelCount;
/**
* 是否推荐 0 推荐 1 不推荐
*/
private Integer isRecommend;
private String id;
private String parentId;
private List<AreaClassifyTreeVo> children = new ArrayList<>();
private AreaClassifyTreeVo Extra;
}

View File

@ -73,5 +73,42 @@
</if>
order by ac.SORT desc
</select>
<select id="selectByAreaClassifyListAll" resultType="com.hzs.sale.product.vo.AreaClassifyTreeVo">
select ac.*,pac.CLASSIFY_NAME parentClassifyName from BD_AREA_CLASSIFY ac
left join BD_AREA_CLASSIFY pac on pac.PK_ID = ac.PK_PARENT
where ac.DEL_FLAG = 0
<if test="pkCountry != null">
and ac.PK_COUNTRY = #{pkCountry}
</if>
<if test="enableState != null">
AND ac.ENABLE_STATE = #{enableState}
</if>
<if test="specialArea != null">
AND (
(select count(csa.PK_ID) from BD_AREA_CLASSIFY_SPECIAL_AREA csa where csa.SPECIAL_AREA = #{specialArea} and csa.PK_AREA_CLASSIFY =
ac.PK_ID ) > 0
or
(
select count(t.PK_ID)
from BD_AREA_CLASSIFY t
where (select count(csa.PK_ID) from BD_AREA_CLASSIFY_SPECIAL_AREA csa where csa.SPECIAL_AREA = #{specialArea} and csa.PK_AREA_CLASSIFY =
t.PK_ID) > 0
start with t.pk_id = ac.PK_ID
connect by t.pk_id = prior t.pk_parent
) > 0
)
</if>
<if test="hierarchy != null">
AND ac.HIERARCHY = #{hierarchy}
</if>
<if test="isRecommend != null">
AND ac.IS_RECOMMEND = #{isRecommend}
</if>
<if test="classifyName != null and classifyName !='' ">
AND ac.CLASSIFY_NAME like #{classifyName}||'%'
</if>
order by ac.SORT desc
</select>
</mapper>