jiangping
2023-09-19 0b9c144b5110a7e2a85b2e5581ef304bb81a3ebc
server/service/src/main/java/com/doumee/service/business/impl/BaseCategoryServiceImpl.java
@@ -7,6 +7,7 @@
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.PinYinUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.BaseCateParamMapper;
import com.doumee.dao.business.BaseCategoryMapper;
@@ -19,12 +20,15 @@
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
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.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -57,7 +61,7 @@
        BaseCategory baseCategory1 = baseCategoryMapper.selectOne(wrapper);
        if (Objects.nonNull(baseCategory1)){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息表");
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息已存在");
        }
        BaseCategory baseCategory2 = new BaseCategory();
        baseCategory2.setCreator(loginUserInfo.getId());
@@ -67,24 +71,22 @@
        baseCategory2.setIsdeleted(Constants.ZERO);
        baseCategory2.setName(baseCategory.getName());
        baseCategory2.setRemark(baseCategory.getRemark());
        baseCategory2.setAttrFirst(baseCategory.getAttrFirst());
        baseCategory2.setAttrSecond(baseCategory.getAttrSecond());
        baseCategory2.setStatus(baseCategory.getStatus());
        baseCategory2.setSortnum(baseCategory.getSortnum());
        baseCategory2.setImgurl(baseCategory.getImgurl());
        baseCategory2.setPinyin(baseCategory.getPinyin());
        baseCategory2.setShortPinyin(baseCategory.getShortPinyin());
        baseCategory2.setPinyin(PinYinUtil.getFullSpell(baseCategory.getName()));
        baseCategory2.setShortPinyin(PinYinUtil.getFirstSpell(baseCategory.getName()));
        baseCategory2.setPriceRate(baseCategory.getPriceRate());
        baseCategoryMapper.insert(baseCategory2);
        if (!CollectionUtils.isEmpty(baseCategory.getBaseCategoryRequestParamList())){
        if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){
            long count = baseCategory.getBaseCategoryRequestParamList().stream().map(s -> s.getName().trim()).distinct().count();
            long count = baseCategory.getBaseCateParamList().stream().map(s -> s.getName().trim()).distinct().count();
            if (baseCategory.getBaseCategoryRequestParamList().size() != count){
            if (baseCategory.getBaseCateParamList().size() != count){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"属性存在重复");
            }
            baseCategory.getBaseCategoryRequestParamList().forEach(s->{
            baseCategory.getBaseCateParamList().forEach(s->{
                BaseCateParam baseCateParam = new BaseCateParam();
                baseCateParam.setCreator(loginUserInfo.getId());
                baseCateParam.setCreateDate(new Date());
@@ -127,8 +129,9 @@
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        if (Objects.isNull(baseCategory.getId())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"品类主键缺失");
        if (Objects.isNull(baseCategory.getId())
                || Objects.isNull(baseCategory.getName())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>();
@@ -139,41 +142,61 @@
        if (Objects.nonNull(baseCategory1) && (!baseCategory1.getId().equals(baseCategory.getId()))){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"品类信息表");
        }
        if(baseCategory.getPriceRate() == null){
            baseCategory.setPriceRate(new BigDecimal(1.2));
        }
        UpdateWrapper<BaseCategory> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda()
                .eq(BaseCategory::getId,baseCategory.getId())
                .set(BaseCategory::getName,baseCategory.getName())
                .set(BaseCategory::getPinyin,PinYinUtil.getFullSpell(baseCategory.getName()))
                .set(BaseCategory::getShortPinyin,PinYinUtil.getFirstSpell(baseCategory.getName()))
                .set(BaseCategory::getImgurl,baseCategory.getImgurl())
                .set(BaseCategory::getPriceRate,baseCategory.getPriceRate())
                .set(BaseCategory::getSortnum,baseCategory.getSortnum());
        baseCategoryMapper.update(null,updateWrapper);
        if (!CollectionUtils.isEmpty(baseCategory.getBaseCategoryRequestParamList())){
        if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){
            long count = baseCategory.getBaseCategoryRequestParamList().stream().map(s -> s.getName().trim()).distinct().count();
            if (baseCategory.getBaseCategoryRequestParamList().size() != count){
            long count = baseCategory.getBaseCateParamList().stream().map(s -> s.getName().trim()).distinct().count();
            if (baseCategory.getBaseCateParamList().size() != count){
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"属性存在重复");
            }
            List<Integer> ids = new ArrayList<>();
            baseCategory.getBaseCateParamList().forEach(s->{
                if(s.getId() !=null){
                    ids. add(s.getId());
                }
            });
            QueryWrapper<BaseCateParam> baseCateParamQuery = new QueryWrapper<>();
            baseCateParamQuery.lambda()
                                .eq(BaseCateParam::getCategoryId,baseCategory.getId());
            baseCateParamQuery.lambda()
                                .notIn(ids!=null && ids.size()>0,BaseCateParam::getId,ids);
            //刪除逻辑
            baseCateParamMapper.delete(baseCateParamQuery);
            baseCategory.getBaseCategoryRequestParamList().forEach(s->{
            baseCategory.getBaseCateParamList().forEach(s->{
                BaseCateParam baseCateParam = new BaseCateParam();
                baseCateParam.setCreator(loginUserInfo.getId());
                baseCateParam.setCreateDate(new Date());
                baseCateParam.setEditor(loginUserInfo.getId());
                baseCateParam.setEditDate(new Date());
                baseCateParam.setIsdeleted(Constants.ZERO);
                baseCateParam.setName(s.getName());
                baseCateParam.setRemark(s.getRemark());
                baseCateParam.setStatus(s.getStatus());
                baseCateParam.setSortnum(s.getSortnum());
                baseCateParam.setCategoryId(baseCategory.getId());
                baseCateParamMapper.insert(baseCateParam);
                if(s.getId() !=null ){
                    //更新数据
                    baseCateParam.setEditor(loginUserInfo.getId());
                    baseCateParam.setEditDate(new Date());
                    baseCateParam.setId(s.getId());
                    baseCateParamMapper.updateById(baseCateParam);
                }else{
                    //新增
                    baseCateParam.setCreator(loginUserInfo.getId());
                    baseCateParam.setCreateDate(new Date());
                    baseCateParamMapper.insert(baseCateParam);
                }
            });
        }
@@ -183,6 +206,25 @@
    @Override
    public void updateById(BaseCategory baseCategory) {
        baseCategoryMapper.updateById(baseCategory);
    }
    @Override
    public void updateDisableById(BaseCategory baseCategory) {
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        if(baseCategory.getId() == null || baseCategory.getStatus() == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(!Constants.equalsInteger(baseCategory.getStatus(), Constants.ONE)
                && !Constants.equalsInteger(baseCategory.getStatus(), Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        BaseCategory param= new BaseCategory();
        param.setId(baseCategory.getId());
        param.setEditDate(new Date());
        param.setEditor(loginUserInfo.getId());
        param.setId(baseCategory.getId());
        param.setStatus(baseCategory.getStatus());
        baseCategoryMapper.updateById(param);
    }
    @Override
@@ -197,7 +239,14 @@
    @Override
    public BaseCategory findById(Integer id) {
        return baseCategoryMapper.selectById(id);
        BaseCategory  model = baseCategoryMapper.selectById(id);
        if(StringUtils.isNotBlank(model.getImgurl())){
            model.setImgfullurl(
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() +
                            systemDictDataBiz.queryByCode(Constants.OSS,Constants.CATEGORY_IMG).getCode() + model.getImgurl()
            );
        }
        return  model;
    }
    @Override
@@ -209,12 +258,16 @@
    @Override
    public List<BaseCategory> findList(BaseCategory baseCategory) {
        QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(baseCategory);
        wrapper.eq("ISDELETED",Constants.ZERO);
        wrapper.eq("STATUS",Constants.ZERO);
        List<BaseCategory> list = baseCategoryMapper.selectList(wrapper);
        list.forEach(i->{
            i.setImgfullurl(
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() +
                            systemDictDataBiz.queryByCode(Constants.OSS,Constants.CATEGORY_IMG).getCode() + i.getImgurl()
            );
            if(StringUtils.isNotBlank(i.getImgurl())){
                i.setImgfullurl(
                        systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode() +
                                systemDictDataBiz.queryByCode(Constants.OSS,Constants.CATEGORY_IMG).getCode() + i.getImgurl()
                );
            }
        });
        return list;
    }
@@ -245,7 +298,7 @@
            queryWrapper.lambda().eq(BaseCategory::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().eq(BaseCategory::getName, pageWrap.getModel().getName());
            queryWrapper.lambda().like(BaseCategory::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(BaseCategory::getRemark, pageWrap.getModel().getRemark());