| | |
| | | @Autowired |
| | | private CateParamSelectMapper cateParamSelectMapper; |
| | | |
| | | @Autowired |
| | | private com.doumee.dao.business.GoodsMapper goodsMapper; |
| | | |
| | | @Override |
| | | public Integer create(Category category) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | |
| | | category.setCreator(user.getId()); |
| | | category.setIsdeleted(Constants.ZERO); |
| | | category.setCompanyId(user.getCompanyId()); |
| | | category.setParentId(null); |
| | | //处理拼音问题 |
| | | category.setPinyin(PinYinUtil.getFullSpell(category.getName())); |
| | | category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName())); |
| | |
| | | .eq("STATUS",Constants.ZERO) |
| | | .eq("ISDELETED",Constants.ZERO) |
| | | .eq("COMPANY_ID",user.getCompanyId()) |
| | | .isNull("PARENT_ID") |
| | | .orderByAsc(" SORTNUM "); |
| | | List<Category> list = categoryMapper.selectList(wrapper); |
| | | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | |
| | | c.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID",c.getId()) |
| | | .orderByAsc(" SORTNUM "))); |
| | | this.getParamSelect(c); |
| | | List<Category> children = categoryMapper.selectList(new QueryWrapper<Category>() |
| | | .eq("PARENT_ID", c.getId()) |
| | | .eq("STATUS", Constants.ZERO) |
| | | .eq("ISDELETED", Constants.ZERO) |
| | | .orderByAsc("SORTNUM") |
| | | .last(" limit 5 ")); |
| | | for (Category child : children) { |
| | | child.setPrefixUrl(prefixUrl); |
| | | } |
| | | c.setChildren(children); |
| | | } |
| | | return list; |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<Category> findTree(Category category) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | QueryWrapper<Category> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("STATUS", Constants.ZERO) |
| | | .eq("ISDELETED", Constants.ZERO) |
| | | .eq("COMPANY_ID", user.getCompanyId()) |
| | | .isNull("PARENT_ID") |
| | | .orderByAsc("SORTNUM"); |
| | | if (category != null && org.apache.commons.lang3.StringUtils.isNotBlank(category.getName())) { |
| | | wrapper.like("NAME", category.getName()); |
| | | } |
| | | if (category != null && category.getType() != null) { |
| | | wrapper.eq("TYPE", category.getType()); |
| | | } |
| | | List<Category> parents = categoryMapper.selectList(wrapper); |
| | | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode(); |
| | | for (Category parent : parents) { |
| | | parent.setPrefixUrl(prefixUrl); |
| | | parent.setBudgetList(cateBudgetMapper.selectList(new QueryWrapper<CateBudget>().eq("CATEGORY_ID", parent.getId()).orderByAsc(" SORTNUM "))); |
| | | List<Category> children = categoryMapper.selectList(new QueryWrapper<Category>() |
| | | .eq("PARENT_ID", parent.getId()) |
| | | .eq("ISDELETED", Constants.ZERO) |
| | | .orderByAsc("SORTNUM")); |
| | | for (Category child : children) { |
| | | child.setPrefixUrl(prefixUrl); |
| | | } |
| | | parent.setChildren(children); |
| | | } |
| | | return parents; |
| | | } |
| | | |
| | | @Override |
| | | public List<Category> findChildren(Integer parentId) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Category parent = categoryMapper.selectById(parentId); |
| | | if (parent == null || !user.getCompanyId().equals(parent.getCompanyId())) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "父级品类不存在"); |
| | | } |
| | | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode(); |
| | | List<Category> children = categoryMapper.selectList(new QueryWrapper<Category>() |
| | | .eq("PARENT_ID", parentId) |
| | | .eq("ISDELETED", Constants.ZERO) |
| | | .eq("STATUS", Constants.ZERO) |
| | | .orderByAsc("SORTNUM")); |
| | | children.forEach(c -> c.setPrefixUrl(prefixUrl)); |
| | | return children; |
| | | } |
| | | |
| | | @Override |
| | | public Integer createSubCategory(Category category) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if (category.getParentId() == null) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "父级品类不能为空"); |
| | | } |
| | | Category parent = categoryMapper.selectById(category.getParentId()); |
| | | if (parent == null || parent.getParentId() != null || !user.getCompanyId().equals(parent.getCompanyId())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "只能在有效的一级品类下创建子类别"); |
| | | } |
| | | 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.setType(parent.getType()); |
| | | category.setPinyin(PinYinUtil.getFullSpell(category.getName())); |
| | | category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName())); |
| | | categoryMapper.insert(category); |
| | | return category.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void updateSubCategory(Category category) { |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Category db = categoryMapper.selectById(category.getId()); |
| | | if (db == null || db.getParentId() == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "子类别不存在"); |
| | | } |
| | | 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.setEditDate(new Date()); |
| | | category.setEditor(user.getId()); |
| | | category.setPinyin(PinYinUtil.getFullSpell(category.getName())); |
| | | category.setShortPinyin(PinYinUtil.getFirstSpell(category.getName())); |
| | | categoryMapper.updateById(category); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteSubCategory(Integer id) { |
| | | Category category = categoryMapper.selectById(id); |
| | | if (category == null || category.getParentId() == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "子类别不存在"); |
| | | } |
| | | long goodsCount = goodsMapper.selectCount(new QueryWrapper<Goods>() |
| | | .eq("ISDELETED", Constants.ZERO) |
| | | .and(w -> w.eq("SUB_CATEGORY_ID", id).or().eq("CATEGORY_ID", id))); |
| | | if (goodsCount > 0) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "该子类别下存在关联商品,无法删除"); |
| | | } |
| | | category.setIsdeleted(Constants.ONE); |
| | | categoryMapper.updateById(category); |
| | | } |
| | | } |