From 08e9a67dd679f311e79a27b04cd0c53a30b4bccf Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 04 六月 2026 18:33:22 +0800
Subject: [PATCH] aaa
---
server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java | 125 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 125 insertions(+), 0 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
index 1497b58..878c184 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -52,6 +52,9 @@
@Autowired
private CateParamSelectMapper cateParamSelectMapper;
+ @Autowired
+ private com.doumee.dao.business.GoodsMapper goodsMapper;
+
@Override
public Integer create(Category category) {
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
@@ -136,6 +139,7 @@
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()));
@@ -426,6 +430,7 @@
.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()
@@ -435,6 +440,16 @@
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;
}
@@ -555,4 +570,114 @@
+ @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);
+ }
}
--
Gitblit v1.9.3