feat(bid): 完成物料分类体系全功能开发
1. 新增物料分类删除校验,支持校验子分类和关联物料 2. 优化物料列表查询,支持按分类及其后代分类筛选 3. 重构物料详情和编辑页面,使用级联选择器选择分类 4. 新增分类管理页面,支持增删改查分类树形结构 5. 新增物料分类初始化SQL脚本,导入标准分类体系
This commit is contained in:
@@ -7,6 +7,12 @@ import java.util.List;
|
||||
public interface BizMaterialCategoryMapper {
|
||||
List<BizMaterialCategory> selectCategoryList();
|
||||
BizMaterialCategory selectCategoryById(@Param("categoryId") Long categoryId);
|
||||
/** 查询子分类数量 */
|
||||
int countChildren(@Param("parentId") Long parentId);
|
||||
/** 查询关联该分类的物料数量 */
|
||||
int countMaterials(@Param("categoryId") Long categoryId);
|
||||
/** 查询所有后代分类ID(通过ancestors LIKE) */
|
||||
List<Long> selectDescendantIds(@Param("ancestors") String ancestors);
|
||||
int insertCategory(BizMaterialCategory category);
|
||||
int updateCategory(BizMaterialCategory category);
|
||||
int deleteCategory(@Param("categoryId") Long categoryId);
|
||||
|
||||
@@ -7,5 +7,6 @@ public interface IBizMaterialCategoryService {
|
||||
List<BizMaterialCategory> selectCategoryList();
|
||||
int insertCategory(BizMaterialCategory category);
|
||||
int updateCategory(BizMaterialCategory category);
|
||||
int deleteCategory(Long categoryId);
|
||||
/** 删除分类(含子分类和物料校验) */
|
||||
int deleteCategory(Long categoryId) throws Exception;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,19 @@ public class BizMaterialCategoryServiceImpl implements IBizMaterialCategoryServi
|
||||
public int updateCategory(BizMaterialCategory cat) { return mapper.updateCategory(cat); }
|
||||
|
||||
@Override
|
||||
public int deleteCategory(Long categoryId) { return mapper.deleteCategory(categoryId); }
|
||||
public int deleteCategory(Long categoryId) throws Exception {
|
||||
// 校验子分类
|
||||
int childCount = mapper.countChildren(categoryId);
|
||||
if (childCount > 0) {
|
||||
throw new Exception("该分类下存在子分类,无法删除");
|
||||
}
|
||||
// 校验关联物料
|
||||
int materialCount = mapper.countMaterials(categoryId);
|
||||
if (materialCount > 0) {
|
||||
throw new Exception("该分类下存在物料,无法删除");
|
||||
}
|
||||
return mapper.deleteCategory(categoryId);
|
||||
}
|
||||
|
||||
private List<BizMaterialCategory> buildTree(List<BizMaterialCategory> all) {
|
||||
Map<Long, BizMaterialCategory> map = new LinkedHashMap<>();
|
||||
|
||||
@@ -16,6 +16,20 @@
|
||||
FROM biz_material_category WHERE category_id = #{categoryId}
|
||||
</select>
|
||||
|
||||
<select id="countChildren" resultType="int">
|
||||
SELECT COUNT(*) FROM biz_material_category WHERE parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="countMaterials" resultType="int">
|
||||
SELECT COUNT(*) FROM biz_material WHERE category_id = #{categoryId}
|
||||
</select>
|
||||
|
||||
<select id="selectDescendantIds" resultType="java.lang.Long">
|
||||
SELECT category_id FROM biz_material_category
|
||||
WHERE ancestors LIKE CONCAT(#{ancestors}, ',%')
|
||||
OR ancestors = #{ancestors}
|
||||
</select>
|
||||
|
||||
<insert id="insertCategory" useGeneratedKeys="true" keyProperty="categoryId">
|
||||
INSERT INTO biz_material_category (tenant_id,category_name,parent_id,ancestors,sort,status,create_by,create_time)
|
||||
VALUES (1,#{categoryName},#{parentId},#{ancestors},#{sort},#{status},#{createBy},NOW())
|
||||
|
||||
@@ -29,7 +29,16 @@
|
||||
LEFT JOIN biz_material_category c ON m.category_id = c.category_id
|
||||
<where>
|
||||
<if test="tenantId != null"> AND m.tenant_id = #{tenantId}</if>
|
||||
<if test="categoryId != null"> AND m.category_id = #{categoryId}</if>
|
||||
<if test="categoryId != null"> AND (
|
||||
m.category_id = #{categoryId}
|
||||
OR m.category_id IN (
|
||||
SELECT category_id FROM biz_material_category
|
||||
WHERE ancestors LIKE CONCAT(
|
||||
(SELECT ancestors FROM biz_material_category WHERE category_id = #{categoryId}),
|
||||
',%'
|
||||
)
|
||||
)
|
||||
)</if>
|
||||
<if test="materialCode != null and materialCode != ''"> AND m.material_code LIKE CONCAT('%',#{materialCode},'%')</if>
|
||||
<if test="materialName != null and materialName != ''"> AND m.material_name LIKE CONCAT('%',#{materialName},'%')</if>
|
||||
<if test="brand != null and brand != ''"> AND m.brand LIKE CONCAT('%',#{brand},'%')</if>
|
||||
|
||||
Reference in New Issue
Block a user