From bd6229ebd9cb543a22944ecb1142fad92b675dce Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 13 十月 2025 14:26:25 +0800
Subject: [PATCH] bug 修复

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

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
index 1120c1f..56d9001 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -1,7 +1,12 @@
 package com.doumee.service.business.impl;
 
 import com.alibaba.fastjson.JSONArray;
+import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.Constants;
+import com.doumee.core.constants.Constants;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.Utils;
@@ -16,12 +21,16 @@
 import com.github.yulichang.base.MPJBaseMapper;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
 import org.checkerframework.checker.units.qual.C;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * 鍒嗙被淇℃伅琛⊿ervice瀹炵幇
@@ -34,15 +43,42 @@
     @Autowired
     private CategoryMapper categoryMapper;
 
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
+
     @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
     public Integer create(Category category) {
+        if(Objects.isNull(category)
+        || Objects.isNull(category.getType())
+        || Objects.isNull(category.getName())
+        || (!Constants.equalsInteger(category.getType(),Constants.ZERO)&& CollectionUtils.isEmpty(category.getDetailList()))
+        || (Constants.equalsInteger(category.getType(),Constants.ONE) && (Objects.isNull(category.getIcon())||Objects.isNull(category.getIsFixed())) )
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        category.setDeleted(Constants.ZERO);
+        category.setCreateTime(new Date());
+        category.setCreateUser(loginUserInfo.getId());
+        category.setUpdateTime(new Date());
+        category.setUpdateUser(loginUserInfo.getId());
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList())
+                && !Constants.equalsInteger(category.getType(),Constants.THREE)){
+            category.setDetail(category.getDetailList().toJSONString());
+        }
+        if(!Constants.equalsInteger(category.getType(),Constants.ONE)){
+            category.setIsFixed(Constants.ZERO);
+        }
         categoryMapper.insert(category);
         return category.getId();
     }
 
     @Override
     public void deleteById(Integer id) {
-        categoryMapper.deleteById(id);
+        categoryMapper.update(new UpdateWrapper<Category>().lambda().set(Category::getDeleted,Constants.ONE).eq(Category::getId,id));
+
+//        categoryMapper.deleteById(id);
     }
 
     @Override
@@ -60,7 +96,40 @@
     }
 
     @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
     public void updateById(Category category) {
+        if(Objects.isNull(category)
+                || Objects.isNull(category.getId())
+                || Objects.isNull(category.getType())
+                || Objects.isNull(category.getName())
+                || (!Constants.equalsInteger(category.getType(),Constants.ZERO)&& CollectionUtils.isEmpty(category.getDetailList()))
+                || (Constants.equalsInteger(category.getType(),Constants.ONE) && (Objects.isNull(category.getIcon())||Objects.isNull(category.getIsFixed())) )
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        category.setUpdateTime(new Date());
+        category.setIsFixed(null);
+        category.setUpdateUser(loginUserInfo.getId());
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList())
+                && !Constants.equalsInteger(category.getType(),Constants.THREE)){
+            category.setDetail(category.getDetailList().toJSONString());
+        }
+        categoryMapper.updateById(category);
+    }
+    @Override
+    public void updateStatus(Category category) {
+        if(Objects.isNull(category)
+                || Objects.isNull(category.getId())){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        category.setUpdateTime(new Date());
+        category.setIsFixed(null);
+        category.setUpdateUser(loginUserInfo.getId());
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(category.getDetailList())){
+            category.setDetail(category.getDetailList().toJSONString());
+        }
         categoryMapper.updateById(category);
     }
 
@@ -76,7 +145,19 @@
 
     @Override
     public Category findById(Integer id) {
-        return categoryMapper.selectById(id);
+        Category category = categoryMapper.selectById(id);
+        if(Objects.isNull(category)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(StringUtils.isNotBlank(category.getDetail())){
+            category.setDetailList(JSONArray.parseArray(category.getDetail()));
+        }
+        if(StringUtils.isNotBlank(category.getIcon())){
+            String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode()
+                    +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode();
+            category.setIconFull(path + category.getIcon());
+        }
+        return category;
     }
 
     @Override
@@ -144,10 +225,15 @@
         queryWrapper.orderByAsc(Category::getSortnum);
         PageData<Category> result =PageData.from(categoryMapper.selectJoinPage(page, Category.class,queryWrapper));
         if(result!=null && result.getRecords()!=null){
+            String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode()
+                    +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode();
             for(Category cate : result.getRecords()){
                 try {
                     if(StringUtils.isNotBlank(cate.getDetail())){
                         cate.setDetailList(JSONArray.parseArray(cate.getDetail()));
+                    }
+                    if(StringUtils.isNotBlank(cate.getIcon())){
+                        cate.setIconFull(path + cate.getIcon());
                     }
                 }catch (Exception e){
 
@@ -162,4 +248,27 @@
         QueryWrapper<Category> wrapper = new QueryWrapper<>(category);
         return categoryMapper.selectCount(wrapper);
     }
+
+    @Override
+    public List<Category> getCategoryList(Integer type){
+        List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda().eq(Category::getDeleted,Constants.ZERO).eq(Category::getStatus,Constants.ZERO)
+                .eq(Objects.nonNull(type),Category::getType,type)
+                .orderByAsc(Category::getSortnum)
+        );
+        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){
+            String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode()
+                    +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode();
+            for (Category category:categoryList) {
+                if(StringUtils.isNotBlank(category.getDetail())){
+                    category.setDetailList(JSONArray.parseArray(category.getDetail()));
+                }
+                if(StringUtils.isNotBlank(category.getIcon())){
+                    category.setIconFull(path + category.getIcon());
+                }
+            }
+        }
+        return categoryList;
+    }
+
+
 }

--
Gitblit v1.9.3