From 9b00b80c926b3d1b38b7ef9b682ee097345dde3f Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 17 四月 2025 11:09:31 +0800
Subject: [PATCH] 代码初始化

---
 server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java b/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
index 928e60e..2221ec1 100644
--- a/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
+++ b/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -70,7 +70,10 @@
             if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
                 throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇淇℃伅涓嶅瓨鍦▇");
             }
-
+            if(Constants.equalsInteger(parent.getType(),Constants.FOUR) && parent.getParentId()!=null){
+                //濡傛灉鏄簩绾DA涓婚,鑷繁涓鸿瀵熼」
+                category.setType(Constants.SIX);
+            }
             idPath = parent.getIdPath();
             category.setIdPath(parent.getIdPath()+category.getId()+"/");
             category.setNamePath(parent.getNamePath()+"/"+category.getName());
@@ -123,6 +126,9 @@
         if( category.getId() == null){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST);
         }
+        if(Constants.equalsInteger(category.getId(),category.getParentId())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鐖剁骇涓嶈兘璁剧疆涓鸿嚜韬紒");
+        }
         category.setType(null);//绫诲瀷涓嶆敮鎸佷慨鏀�
         Category model = categoryMapper.selectById(category.getId());
         if(model ==null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)) {
@@ -136,6 +142,8 @@
                 .eq(Category::getIsdeleted,Constants.ZERO)) >0){
             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鍚嶇О涓嶈兘閲嶅~");
         }*/
+        String oldIdPath = model.getIdPath();
+        String oldNamePath = model.getNamePath();
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         category.setIdPath(category.getId()+"/");//鍚嶇О璺緞
         category.setNamePath(category.getName());//鍚嶇О璺緞
@@ -150,7 +158,25 @@
         }
         category.setEditDate(new Date());
         category.setEditor(user.getId());
-        categoryMapper.updateById(category);
+        categoryMapper.update(null,new UpdateWrapper<Category>().lambda()
+                        .eq(Category::getId,category.getId())
+                        .set(Category::getEditDate,category.getEditDate())
+                        .set(Category::getEditor,category.getEditor())
+                        .set(Category::getName,category.getName())
+                        .set(Category::getParentId,category.getParentId())
+                        .set(Category::getSortnum,category.getSortnum())
+                        .set(Category::getRemark,category.getRemark())
+                        .set(Category::getNamePath,category.getNamePath())
+                        .set(Category::getIdPath,category.getId())
+        );
+        //淇敼鍏ㄩ儴涓嬬骇鐨勭紪鐮佸拰鍚嶇О璺緞
+        categoryMapper.update(null,new UpdateWrapper<Category>().lambda()
+                .likeRight(Category::getIdPath,oldIdPath)
+                .set(Category::getEditDate,category.getEditDate())
+                .set(Category::getEditor,category.getEditor())
+                .setSql("id_path=replace(id_path,'"+oldIdPath+"','"+category.getIdParentPath()+"')")
+                .setSql("name_path=replace(name_path,'"+oldNamePath+"/','"+category.getName()+"/')")
+        );
     }
 
     @Override
@@ -176,6 +202,7 @@
 
     @Override
     public List<Category> findList(Category category) {
+        category.setIsdeleted(Constants.ZERO);
         MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>();
         queryWrapper.selectAll(Category.class);
         queryWrapper.selectAs(SystemUser::getUsername,Category::getEditorName);

--
Gitblit v1.9.3