jiangping
2025-07-15 fe386ee15e63214b6f9633f7622982fafac1dba6
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,15 @@
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.util.CollectionUtils;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
 * 分类信息表Service实现
@@ -34,15 +42,40 @@
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Override
    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())){
            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
@@ -61,6 +94,37 @@
    @Override
    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())){
            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 +140,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,11 +220,16 @@
        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){
                }