MrShi
7 小时以前 e50954f0708ecbbc672352102ae3b24279d40cc1
server/services/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -11,7 +11,9 @@
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CategoryMapper;
import com.doumee.dao.business.PricingRuleMapper;
import com.doumee.dao.business.model.Category;
import com.doumee.dao.business.model.PricingRule;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.CategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -44,6 +46,9 @@
    private CategoryMapper categoryMapper;
    @Autowired
    private PricingRuleMapper pricingRuleMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Override
@@ -52,24 +57,17 @@
        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())) )
        || StringUtils.isBlank(category.getDetail())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        validateByType(category);
        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();
    }
@@ -102,19 +100,14 @@
                || 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())) )
                || StringUtils.isBlank(category.getDetail())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        validateByType(category);
        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
@@ -125,11 +118,7 @@
        }
        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);
    }
@@ -149,11 +138,8 @@
        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()
            String path  = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()
                    +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.CATEGORY_FILES).getCode();
            category.setIconFull(path + category.getIcon());
        }
@@ -219,19 +205,13 @@
        if (pageWrap.getModel().getIcon() != null) {
            queryWrapper.eq(Category::getIcon, pageWrap.getModel().getIcon());
        }
        if (pageWrap.getModel().getIsFixed() != null) {
            queryWrapper.eq(Category::getIsFixed, pageWrap.getModel().getIsFixed());
        }
        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()
            String path  = systemDictDataBiz.queryByCode(Constants.OSS,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());
                    }
@@ -256,12 +236,9 @@
                .orderByAsc(Category::getSortnum)
        );
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){
            String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode()
            String path  = systemDictDataBiz.queryByCode(Constants.OSS,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());
                }
@@ -270,5 +247,59 @@
        return categoryList;
    }
    @Override
    public List<Category> getCitySizeList(Integer cityId) {
        // 1. 查询该城市已配置的异地寄送规则(pricing_rule type=1),获取fieldA(物品尺寸主键)
        List<PricingRule> rules = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
                .eq(PricingRule::getDeleted, Constants.ZERO)
                .eq(PricingRule::getType, Constants.ONE)
                .eq(PricingRule::getCityId, cityId));
        if (CollectionUtils.isEmpty(rules)) {
            return java.util.Collections.emptyList();
        }
        List<Integer> sizeIds = new java.util.ArrayList<>();
        for (PricingRule rule : rules) {
            if (StringUtils.isNotBlank(rule.getFieldA())) {
                sizeIds.add(Integer.parseInt(rule.getFieldA()));
            }
        }
        if (sizeIds.isEmpty()) {
            return java.util.Collections.emptyList();
        }
        // 2. 查询对应的物品尺寸(category type=4)
        List<Category> sizeList = categoryMapper.selectList(new QueryWrapper<Category>().lambda()
                .eq(Category::getDeleted, Constants.ZERO)
                .eq(Category::getStatus, Constants.ZERO)
                .eq(Category::getType, Constants.FOUR)
                .in(Category::getId, sizeIds)
                .orderByAsc(Category::getSortnum));
        // 3. 拼接图标全路径
        if (!CollectionUtils.isEmpty(sizeList)) {
            String path = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.RESOURCE_PATH).getCode()
                    + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.CATEGORY_FILES).getCode();
            for (Category cate : sizeList) {
                if (StringUtils.isNotBlank(cate.getIcon())) {
                    cate.setIconFull(path + cate.getIcon());
                }
            }
        }
        return sizeList;
    }
    private void validateByType(Category category) {
        if (Constants.equalsInteger(category.getType(), Constants.ONE)) {
            if (StringUtils.isBlank(category.getOtherField())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "车辆类型必须填写附属字段");
            }
        } else if (Constants.equalsInteger(category.getType(), Constants.TWO)) {
            if (Objects.isNull(category.getRelationId())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "物品分类必须选择关联物品等级");
            }
        } else if (Constants.equalsInteger(category.getType(), Constants.FOUR)) {
            if (StringUtils.isBlank(category.getIcon())) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "物品尺寸必须上传图标");
            }
        }
    }
}