From 08e9a67dd679f311e79a27b04cd0c53a30b4bccf Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 04 六月 2026 18:33:22 +0800
Subject: [PATCH] aaa

---
 server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java |  228 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 169 insertions(+), 59 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
index 237ba6f..878c184 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -52,6 +52,9 @@
     @Autowired
     private CateParamSelectMapper cateParamSelectMapper;
 
+    @Autowired
+    private com.doumee.dao.business.GoodsMapper goodsMapper;
+
     @Override
     public Integer create(Category category) {
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
@@ -136,6 +139,7 @@
         category.setCreator(user.getId());
         category.setIsdeleted(Constants.ZERO);
         category.setCompanyId(user.getCompanyId());
+        category.setParentId(null);
         //澶勭悊鎷奸煶闂
         category.setPinyin(PinYinUtil.getFullSpell(category.getName()));
         category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName()));
@@ -227,8 +231,8 @@
             }
         }
 
-        this.dealCateAttr(category.getAttrFirstList(),Constants.ZERO,category.getId(),user);
-        this.dealCateAttr(category.getAttrSecondList(),Constants.ONE,category.getId(),user);
+//        this.dealCateAttr(category.getAttrFirstList(),Constants.ZERO,category.getId(),user);
+//        this.dealCateAttr(category.getAttrSecondList(),Constants.ONE,category.getId(),user);
 //        cateAttrMapper.delete(new QueryWrapper<CateAttr>().eq("CATEGORY_ID",category.getId()));
 //        List<CateAttr>  attrFirst = category.getAttrFirstList();
 //        if(!Objects.isNull(attrFirst)&&attrFirst.size()> Constants.ZERO){
@@ -292,20 +296,7 @@
         category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName()));
         categoryMapper.updateById(category);
         //澶勭悊灞炴�ч厤缃�
-        cateParamMapper.delete(new QueryWrapper<CateParam>().eq("CATEGORY_ID",category.getId()));
-        List<CateParam> paramList = category.getParamList();
-        if(!Objects.isNull(paramList)&&paramList.size()> Constants.ZERO){
-            for (int i = 0; i < paramList.size(); i++) {
-                CateParam cateParam = paramList.get(i);
-                cateParam.setCreator(user.getId());
-                cateParam.setCreateDate(new Date());
-                cateParam.setIsdeleted(Constants.ZERO);
-                cateParam.setSortnum(i+Constants.ONE);
-                cateParam.setStatus(Constants.ZERO);
-                cateParam.setCategoryId(category.getId());
-                cateParamMapper.insert(cateParam);
-            }
-        }
+        this.dealCateParam(category.getParamList(),category.getId(),user);
         cateBudgetMapper.delete(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",category.getId()));
         List<CateBudget>  budgetList = category.getBudgetList();
         if(!Objects.isNull(budgetList)&&budgetList.size()> Constants.ZERO){
@@ -323,60 +314,54 @@
     }
 
 
-    public void dealCateAttr(List<CateAttr> cateAttrList,Integer type,Integer categoryId,LoginUserInfo user){
-        List<CateAttr> oldCateAttrList = cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",categoryId).eq("TYPE",type));
-        List<CateAttr> addCateAttr = new ArrayList<>();
-        List<CateAttr> updCateAttr = new ArrayList<>();
-        List<CateAttr> delCateAttr = new ArrayList<>();
-        for (CateAttr oldCateAttr:oldCateAttrList) {
+    public void dealCateParam(List<CateParam> cateParamList,Integer categoryId,LoginUserInfo userInfo ){
+        List<CateParam> oldCateParamList = cateParamMapper.selectList(new QueryWrapper<CateParam>()
+                .eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",categoryId));
+        List<CateParam> updCateParam = new ArrayList<>();
+        List<CateParam> delCateParam = new ArrayList<>();
+        for (CateParam oldCateParam:oldCateParamList) {
             Boolean flag = false;
-            for (CateAttr cateAttr:cateAttrList) {
-                if(oldCateAttr.getName().equals(cateAttr.getName())){
-                    updCateAttr.add(oldCateAttr);
+            for (CateParam cateParam:cateParamList) {
+                if(oldCateParam.getId().equals(cateParam.getId())){
+                    updCateParam.add(cateParam);
                     flag = true;
                     break;
                 }
             }
             if(!flag){
-                delCateAttr.add(oldCateAttr);
+                delCateParam.add(oldCateParam);
             }
         }
-        CateAttr maxCateAttr = cateAttrMapper.selectOne(new QueryWrapper<CateAttr>().eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",categoryId).eq("TYPE",type).orderByDesc(" SORTNUM ").last(" limit 1  "));
+        CateParam maxCateParam = cateParamMapper.selectOne(new QueryWrapper<CateParam>().eq("ISDELETED",Constants.ZERO)
+                .eq("CATEGORY_ID",categoryId).orderByDesc(" SORTNUM ").last(" limit 1  "));
         Integer nextSortNum = 0;
-        if(!Objects.isNull(maxCateAttr)){
-            nextSortNum = maxCateAttr.getSortnum();
+        if(!Objects.isNull(maxCateParam)){
+            nextSortNum = maxCateParam.getSortnum();
         }
-        //澶勭悊鏂板鏁版嵁
-        for (CateAttr cateAttr:cateAttrList) {
-            Boolean flag = false;
-            for (CateAttr oldCateAttr:oldCateAttrList) {
-                if(cateAttr.getName().equals(oldCateAttr.getName())){
-                    flag = true;
-                    break;
-                }
-            }
-            if(!flag){
-                nextSortNum = nextSortNum + 1;
-                cateAttr.setCreator(user.getId());
-                cateAttr.setCreateDate(new Date());
-                cateAttr.setIsdeleted(Constants.ZERO);
-                cateAttr.setSortnum(nextSortNum);
-                cateAttr.setStatus(Constants.ZERO);
-                cateAttr.setCategoryId(categoryId);
-                cateAttr.setType(type);
-                addCateAttr.add(cateAttr);
+        for (CateParam cateParam:cateParamList) {
+            if(Objects.isNull(cateParam.getId())){
+                nextSortNum ++ ;
+                cateParam.setCreator(userInfo.getId());
+                cateParam.setCreateDate(new Date());
+                cateParam.setIsdeleted(Constants.ZERO);
+                cateParam.setSortnum(nextSortNum);
+                cateParam.setStatus(Constants.ZERO);
+                cateParam.setCategoryId(categoryId);
+                cateParamMapper.insert(cateParam);
             }
         }
-        addCateAttr.forEach(i->{
-            cateAttrMapper.insert(i);
+        delCateParam.forEach(i->{
+            cateParamMapper.deleteById(i.getId());
         });
-        delCateAttr.forEach(i->{
-            i.setIsdeleted(Constants.ONE);
+        updCateParam.forEach(i->{
             i.setEditDate(new Date());
-            i.setEditor(user.getId());
-            cateAttrMapper.updateById(i);
+            i.setEditor(userInfo.getId());
+            cateParamMapper.updateById(i);
         });
+
+
     }
+
 
     @Override
     public void updateDisableById(Category category) {
@@ -445,16 +430,26 @@
                 .eq("STATUS",Constants.ZERO)
                 .eq("ISDELETED",Constants.ZERO)
                 .eq("COMPANY_ID",user.getCompanyId())
+                .isNull("PARENT_ID")
                 .orderByAsc(" SORTNUM ");
         List<Category> list = categoryMapper.selectList(wrapper);
         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
         for (Category c:list) {
             c.setPrefixUrl(prefixUrl);
-//            c.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
-//            c.setAttrSecondList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ONE).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
-            c.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
+            c.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",c.getId())
+                    .orderByAsc(" SORTNUM ")));
             this.getParamSelect(c);
+            List<Category> children = categoryMapper.selectList(new QueryWrapper<Category>()
+                    .eq("PARENT_ID", c.getId())
+                    .eq("STATUS", Constants.ZERO)
+                    .eq("ISDELETED", Constants.ZERO)
+                    .orderByAsc("SORTNUM")
+                    .last(" limit 5 "));
+            for (Category child : children) {
+                child.setPrefixUrl(prefixUrl);
+            }
+            c.setChildren(children);
         }
         return list;
     }
@@ -465,6 +460,7 @@
                 .eq("CATEGORY_ID",category.getId())
                 .eq("ISSELECT",Constants.ONE)
                 .eq("ISDELETED",Constants.ZERO)
+                .eq("ISSHOW",Constants.ONE)
                 .orderByAsc(" SORTNUM ")
                 .last(" limit 2 ")
         );
@@ -504,8 +500,12 @@
             c.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
             c.setAttrSecondList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ONE).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
             c.setParamList(cateParamMapper.selectList(new QueryWrapper<CateParam>()
-                            .select(" * , ( select gp.VAL from goods_param gp where gp.GOODS_ID = "+goodsId+" and gp.PRAMA_ID = cate_param.id limit 1 )  as val ")
-                    .eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
+                        .select(" * , ( select gp.VAL from goods_param gp where gp.GOODS_ID = "+goodsId+" and gp.PRAMA_ID = cate_param.id limit 1 )  as val ")
+                    .eq("CATEGORY_ID",c.getId())
+                    .eq("ISSHOW",Constants.ONE)
+                    .eq("STATUS",Constants.ZERO)
+                    .eq("ISDELETED",Constants.ZERO)
+                    .orderByAsc(" SORTNUM ")));
         }
         return list;
     }
@@ -570,4 +570,114 @@
 
 
 
+    @Override
+    public List<Category> findTree(Category category) {
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        QueryWrapper<Category> wrapper = new QueryWrapper<>();
+        wrapper.eq("STATUS", Constants.ZERO)
+                .eq("ISDELETED", Constants.ZERO)
+                .eq("COMPANY_ID", user.getCompanyId())
+                .isNull("PARENT_ID")
+                .orderByAsc("SORTNUM");
+        if (category != null && org.apache.commons.lang3.StringUtils.isNotBlank(category.getName())) {
+            wrapper.like("NAME", category.getName());
+        }
+        if (category != null && category.getType() != null) {
+            wrapper.eq("TYPE", category.getType());
+        }
+        List<Category> parents = categoryMapper.selectList(wrapper);
+        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
+                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
+        for (Category parent : parents) {
+            parent.setPrefixUrl(prefixUrl);
+            parent.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID", parent.getId()).orderByAsc(" SORTNUM ")));
+            List<Category> children = categoryMapper.selectList(new QueryWrapper<Category>()
+                    .eq("PARENT_ID", parent.getId())
+                    .eq("ISDELETED", Constants.ZERO)
+                    .orderByAsc("SORTNUM"));
+            for (Category child : children) {
+                child.setPrefixUrl(prefixUrl);
+            }
+            parent.setChildren(children);
+        }
+        return parents;
+    }
+
+    @Override
+    public List<Category> findChildren(Integer parentId) {
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        Category parent = categoryMapper.selectById(parentId);
+        if (parent == null || !user.getCompanyId().equals(parent.getCompanyId())) {
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "鐖剁骇鍝佺被涓嶅瓨鍦�");
+        }
+        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
+                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
+        List<Category> children = categoryMapper.selectList(new QueryWrapper<Category>()
+                .eq("PARENT_ID", parentId)
+                .eq("ISDELETED", Constants.ZERO)
+                .eq("STATUS", Constants.ZERO)
+                .orderByAsc("SORTNUM"));
+        children.forEach(c -> c.setPrefixUrl(prefixUrl));
+        return children;
+    }
+
+    @Override
+    public Integer createSubCategory(Category category) {
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if (category.getParentId() == null) {
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鐖剁骇鍝佺被涓嶈兘涓虹┖");
+        }
+        Category parent = categoryMapper.selectById(category.getParentId());
+        if (parent == null || parent.getParentId() != null || !user.getCompanyId().equals(parent.getCompanyId())) {
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鍙兘鍦ㄦ湁鏁堢殑涓�绾у搧绫讳笅鍒涘缓瀛愮被鍒�");
+        }
+        if (categoryMapper.selectCount(new QueryWrapper<Category>().eq("ISDELETED", Constants.ZERO)
+                .eq("COMPANY_ID", user.getCompanyId()).eq("name", category.getName())) > 0) {
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "銆�" + category.getName() + "銆戝凡瀛樺湪");
+        }
+        category.setStatus(Constants.ZERO);
+        category.setCreateDate(new Date());
+        category.setCreator(user.getId());
+        category.setIsdeleted(Constants.ZERO);
+        category.setCompanyId(user.getCompanyId());
+        category.setType(parent.getType());
+        category.setPinyin(PinYinUtil.getFullSpell(category.getName()));
+        category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName()));
+        categoryMapper.insert(category);
+        return category.getId();
+    }
+
+    @Override
+    public void updateSubCategory(Category category) {
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        Category db = categoryMapper.selectById(category.getId());
+        if (db == null || db.getParentId() == null) {
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀛愮被鍒笉瀛樺湪");
+        }
+        if (categoryMapper.selectCount(new QueryWrapper<Category>().eq("ISDELETED", Constants.ZERO)
+                .eq("COMPANY_ID", user.getCompanyId()).ne("id", category.getId()).eq("name", category.getName())) > 0) {
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "銆�" + category.getName() + "銆戝凡瀛樺湪");
+        }
+        category.setEditDate(new Date());
+        category.setEditor(user.getId());
+        category.setPinyin(PinYinUtil.getFullSpell(category.getName()));
+        category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName()));
+        categoryMapper.updateById(category);
+    }
+
+    @Override
+    public void deleteSubCategory(Integer id) {
+        Category category = categoryMapper.selectById(id);
+        if (category == null || category.getParentId() == null) {
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "瀛愮被鍒笉瀛樺湪");
+        }
+        long goodsCount = goodsMapper.selectCount(new QueryWrapper<Goods>()
+                .eq("ISDELETED", Constants.ZERO)
+                .and(w -> w.eq("SUB_CATEGORY_ID", id).or().eq("CATEGORY_ID", id)));
+        if (goodsCount > 0) {
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "璇ュ瓙绫诲埆涓嬪瓨鍦ㄥ叧鑱斿晢鍝侊紝鏃犳硶鍒犻櫎");
+        }
+        category.setIsdeleted(Constants.ONE);
+        categoryMapper.updateById(category);
+    }
 }

--
Gitblit v1.9.3