jiangping
2023-09-19 bd732b4fea72b65aabade0dfb14ddb1346ad3f8f
server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -11,6 +11,7 @@
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CateAttrMapper;
import com.doumee.dao.business.CateParamMapper;
import com.doumee.dao.business.CateParamSelectMapper;
import com.doumee.dao.business.CategoryMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.CategoryService;
@@ -47,6 +48,9 @@
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private CateParamSelectMapper cateParamSelectMapper;
    @Override
    public Integer create(Category category) {
@@ -116,10 +120,56 @@
                cateBudgetMapper.insert(cateBudget);
            }
        }
        return category.getId();
    }
    @Override
    public Integer companyCreate(Category category) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(categoryMapper.selectCount(new QueryWrapper<Category>().eq("ISDELETED",Constants.ZERO)
                .eq("COMPANY_ID",user.getCompanyId()).eq("name",category.getName()))>0){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+category.getName()+"】已存在");
        };
        category.setStatus(Constants.ZERO);
        category.setCreateDate(new Date());
        category.setCreator(user.getId());
        category.setIsdeleted(Constants.ZERO);
        category.setCompanyId(user.getCompanyId());
        //处理拼音问题
        category.setPinyin(PinYinUtil.getFullSpell(category.getName()));
        category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName()));
        categoryMapper.insert(category);
        List<CateParam> paramList = category.getParamList();
        if(!Objects.isNull(paramList)&&paramList.size()> Constants.ZERO){
            for (int i = 0; i < paramList.size(); i++) {
                CateParam cateParam = paramList.get(i);
                cateParam.setCreator(user.getId());
                cateParam.setCreateDate(new Date());
                cateParam.setIsdeleted(Constants.ZERO);
                cateParam.setSortnum(i+Constants.ONE);
                cateParam.setStatus(Constants.ZERO);
                cateParam.setCategoryId(category.getId());
                cateParamMapper.insert(cateParam);
            }
        }
        List<CateBudget>  budgetList = category.getBudgetList();
        if(!Objects.isNull(budgetList)&&budgetList.size()> Constants.ZERO){
            for (int i = 0; i < budgetList.size(); i++) {
                CateBudget cateBudget = budgetList.get(i);
                cateBudget.setCreator(user.getId());
                cateBudget.setCreateDate(new Date());
                cateBudget.setIsdeleted(Constants.ZERO);
                cateBudget.setSortnum(i+Constants.ONE);
                cateBudget.setStatus(Constants.ZERO);
                cateBudget.setCategoryId(category.getId());
                cateBudgetMapper.insert(cateBudget);
            }
        }
        return category.getId();
    }
    @Override
    public void deleteById(Integer id) {
@@ -226,6 +276,53 @@
    }
    @Override
    public void companyUpdateById(Category category) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(categoryMapper.selectCount(new QueryWrapper<Category>().eq("ISDELETED",Constants.ZERO).eq("COMPANY_ID",user.getCompanyId())
                .ne("id",category.getId()).eq("name",category.getName()))>0){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+category.getName()+"】已存在");
        };
        category.setStatus(Constants.ZERO);
        category.setEditDate(new Date());
        category.setEditor(user.getId());
        category.setIsdeleted(Constants.ZERO);
        //处理拼音问题
        category.setPinyin(PinYinUtil.getFullSpell(category.getName()));
        category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName()));
        categoryMapper.updateById(category);
        //处理属性配置
        cateParamMapper.delete(new QueryWrapper<CateParam>().eq("CATEGORY_ID",category.getId()));
        List<CateParam> paramList = category.getParamList();
        if(!Objects.isNull(paramList)&&paramList.size()> Constants.ZERO){
            for (int i = 0; i < paramList.size(); i++) {
                CateParam cateParam = paramList.get(i);
                cateParam.setCreator(user.getId());
                cateParam.setCreateDate(new Date());
                cateParam.setIsdeleted(Constants.ZERO);
                cateParam.setSortnum(i+Constants.ONE);
                cateParam.setStatus(Constants.ZERO);
                cateParam.setCategoryId(category.getId());
                cateParamMapper.insert(cateParam);
            }
        }
        cateBudgetMapper.delete(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",category.getId()));
        List<CateBudget>  budgetList = category.getBudgetList();
        if(!Objects.isNull(budgetList)&&budgetList.size()> Constants.ZERO){
            for (int i = 0; i < budgetList.size(); i++) {
                CateBudget cateBudget = budgetList.get(i);
                cateBudget.setCreator(user.getId());
                cateBudget.setCreateDate(new Date());
                cateBudget.setIsdeleted(Constants.ZERO);
                cateBudget.setSortnum(i+Constants.ONE);
                cateBudget.setStatus(Constants.ZERO);
                cateBudget.setCategoryId(category.getId());
                cateBudgetMapper.insert(cateBudget);
            }
        }
    }
    public void dealCateAttr(List<CateAttr> cateAttrList,Integer type,Integer categoryId,LoginUserInfo user){
        List<CateAttr> oldCateAttrList = cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",categoryId).eq("TYPE",type));
        List<CateAttr> addCateAttr = new ArrayList<>();
@@ -302,13 +399,11 @@
    @Override
    public Category findById(Integer id) {
        Category category = categoryMapper.selectById(id);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
        category.setPrefixUrl(prefixUrl);
        category.setParamList(cateParamMapper.selectList(new QueryWrapper<CateParam>().eq("CATEGORY_ID",id).eq("ISDELETED",Constants.ZERO).orderByAsc(" SORTNUM ")));
        category.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",id).orderByAsc(" SORTNUM ")));
        category.setAttrSecondList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ONE).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",id).orderByAsc(" SORTNUM ")));
        category.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",id).eq("ISDELETED",Constants.ZERO).orderByAsc(" SORTNUM ")));
         category.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",id).eq("ISDELETED",Constants.ZERO).orderByAsc(" SORTNUM ")));
        return category;
    }
@@ -320,31 +415,90 @@
    @Override
    public List<Category> findList(Category category) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<Category> wrapper = new QueryWrapper<>(category)
                .eq("STATUS",Constants.ZERO)
                .eq("ISDELETED",Constants.ZERO)
                .eq("COMPANY_ID",user.getCompanyId())
                .orderByAsc(" SORTNUM ");
        List<Category> list = categoryMapper.selectList(wrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
//        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
//                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
//        for (Category c:list) {
//            c.setPrefixUrl(prefixUrl);
//            c.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
//            c.setAttrSecondList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ONE).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
//            c.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
//        }
        return list;
    }
    @Override
    public List<Category> findListSaaS(Category category) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!user.getType().equals(Constants.UserType.ZHUBO.getKey())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户类别错误,非主播用户!");
        }
        QueryWrapper<Category> wrapper = new QueryWrapper<>(category)
                .eq("STATUS",Constants.ZERO)
                .eq("ISDELETED",Constants.ZERO)
                .eq("COMPANY_ID",user.getCompanyId())
                .orderByAsc(" SORTNUM ");
        List<Category> list = categoryMapper.selectList(wrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
        for (Category c:list) {
            c.setPrefixUrl(prefixUrl);
            c.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
            c.setAttrSecondList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ONE).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
//            c.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
//            c.setAttrSecondList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ONE).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
            c.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
            this.getParamSelect(c);
        }
        return list;
    }
    public void getParamSelect(Category category){
        List<CateParam> cateParamList =  cateParamMapper.selectList(new QueryWrapper<CateParam>()
                .eq("CATEGORY_ID",category.getId())
                .eq("ISSELECT",Constants.ONE)
                .eq("ISDELETED",Constants.ZERO)
                .orderByAsc(" SORTNUM ")
                .last(" limit 2 ")
        );
        if(!Objects.isNull(cateParamList)&&cateParamList.size()>Constants.ZERO){
            for (int i = 0; i < cateParamList.size(); i++) {
                CateParam cateParam = cateParamList.get(i);
                List<CateParamSelect> cateParamSelectList = cateParamSelectMapper.selectList(new QueryWrapper<CateParamSelect>()
                        .eq("PARAM_ID",cateParam.getId())
                        .eq("ISDELETED",Constants.ZERO));
                if(i==0){
                    category.setAttrFirst(cateParam.getName());
                    category.setCateParamFirstList(cateParamSelectList);
                }else if(i==1){
                    category.setAttrSecond(cateParam.getName());
                    category.setCateParamSecondList(cateParamSelectList);
                }
            }
        }
    }
    @Override
    public List<Category> findListForGoods(Integer goodsId) {
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<Category> wrapper = new QueryWrapper<Category>()
                .eq("STATUS",Constants.ZERO)
                .eq("ISDELETED",Constants.ZERO)
                .eq("COMPANY_ID",loginUserInfo.getCompanyId())
                .orderByAsc(" SORTNUM ");
        List<Category> list = categoryMapper.selectList(wrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
        for (Category c:list) {
            c.setPrefixUrl(prefixUrl);
            c.setAttrFirstList(cateAttrMapper.selectList(new QueryWrapper<CateAttr>().eq("TYPE",Constants.ZERO).eq("ISDELETED",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
@@ -370,10 +524,16 @@
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(Category::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.lambda().eq(Category::getType, pageWrap.getModel().getType());
        }
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.lambda().eq(Category::getCompanyId, pageWrap.getModel().getCompanyId());
        }
        queryWrapper.lambda().orderByAsc(Category::getSortnum);
        IPage<Category> categoryIPage = categoryMapper.selectPage(page, queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
        categoryIPage.getRecords().forEach(i->{
            i.setPrefixUrl(prefixUrl);
        });
@@ -385,4 +545,29 @@
        QueryWrapper<Category> wrapper = new QueryWrapper<>(category);
        return categoryMapper.selectCount(wrapper);
    }
    /**********************************************************************************/
    @Override
    public List<Category> companyFindList(Category category) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        QueryWrapper<Category> wrapper = new QueryWrapper<>(category)
                .eq("STATUS",Constants.ZERO)
                .eq("COMPANY_ID",user.getCompanyId())
                .eq("ISDELETED",Constants.ZERO)
                .orderByAsc(" SORTNUM ");
        List<Category> list = categoryMapper.selectList(wrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
        for (Category c:list) {
            c.setPrefixUrl(prefixUrl);
            c.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("STATUS",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc(" SORTNUM ")));
            c.setParamList(cateParamMapper.selectList(new QueryWrapper<CateParam>().eq("STATUS",Constants.ZERO).eq("CATEGORY_ID",c.getId()).orderByAsc("SORTNUM")));
        }
        return list;
    }
}