From 55b98737d5c4240b8035914a15e6975a9a71b447 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 22 四月 2025 15:45:20 +0800
Subject: [PATCH] 代码初始化
---
server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java | 127 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 125 insertions(+), 2 deletions(-)
diff --git a/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java b/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
index ce07a05..aa8d4d6 100644
--- a/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
+++ b/server/src/main/java/com/doumee/service/business/impl/CategoryServiceImpl.java
@@ -1,6 +1,7 @@
package com.doumee.service.business.impl;
import com.doumee.core.constants.Constants;
+import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
@@ -9,6 +10,10 @@
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CategoryMapper;
import com.doumee.dao.business.model.Category;
+import com.doumee.dao.business.model.Member;
+import com.doumee.dao.business.vo.CompanyTree;
+import com.doumee.dao.web.vo.CategoryVO;
+import com.doumee.dao.web.vo.CategoryVOTree;
import com.doumee.dao.business.model.Company;
import com.doumee.dao.business.model.Managers;
import com.doumee.dao.business.vo.CategoryTree;
@@ -26,9 +31,12 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Objects;
import java.util.UUID;
+import java.util.stream.Collectors;
/**
* 鍒嗙被淇℃伅琛⊿ervice瀹炵幇
@@ -64,7 +72,10 @@
if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鐖剁骇淇℃伅涓嶅瓨鍦▇");
}
-
+ if(Constants.equalsInteger(parent.getType(),Constants.FOUR) && parent.getParentId()!=null){
+ //濡傛灉鏄簩绾DA涓婚,鑷繁涓鸿瀵熼」
+ category.setType(Constants.SIX);
+ }
idPath = parent.getIdPath();
category.setIdPath(parent.getIdPath()+category.getId()+"/");
category.setNamePath(parent.getNamePath()+"/"+category.getName());
@@ -117,6 +128,9 @@
if( category.getId() == null){
throw new BusinessException(ResponseStatus.BAD_REQUEST);
}
+ if(Constants.equalsInteger(category.getId(),category.getParentId())){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝鐖剁骇涓嶈兘璁剧疆涓鸿嚜韬紒");
+ }
category.setType(null);//绫诲瀷涓嶆敮鎸佷慨鏀�
Category model = categoryMapper.selectById(category.getId());
if(model ==null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)) {
@@ -130,6 +144,8 @@
.eq(Category::getIsdeleted,Constants.ZERO)) >0){
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "瀵逛笉璧凤紝鍚嶇О涓嶈兘閲嶅~");
}*/
+ String oldIdPath = model.getIdPath();
+ String oldNamePath = model.getNamePath();
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
category.setIdPath(category.getId()+"/");//鍚嶇О璺緞
category.setNamePath(category.getName());//鍚嶇О璺緞
@@ -144,7 +160,25 @@
}
category.setEditDate(new Date());
category.setEditor(user.getId());
- categoryMapper.updateById(category);
+ categoryMapper.update(null,new UpdateWrapper<Category>().lambda()
+ .eq(Category::getId,category.getId())
+ .set(Category::getEditDate,category.getEditDate())
+ .set(Category::getEditor,category.getEditor())
+ .set(Category::getName,category.getName())
+ .set(Category::getParentId,category.getParentId())
+ .set(Category::getSortnum,category.getSortnum())
+ .set(Category::getRemark,category.getRemark())
+ .set(Category::getNamePath,category.getNamePath())
+ .set(Category::getIdPath,category.getId())
+ );
+ //淇敼鍏ㄩ儴涓嬬骇鐨勭紪鐮佸拰鍚嶇О璺緞
+ categoryMapper.update(null,new UpdateWrapper<Category>().lambda()
+ .likeRight(Category::getIdPath,oldIdPath)
+ .set(Category::getEditDate,category.getEditDate())
+ .set(Category::getEditor,category.getEditor())
+ .setSql("id_path=replace(id_path,'"+oldIdPath+"','"+category.getIdParentPath()+"')")
+ .setSql("name_path=replace(name_path,'"+oldNamePath+"/','"+category.getName()+"/')")
+ );
}
@Override
@@ -170,6 +204,7 @@
@Override
public List<Category> findList(Category category) {
+ category.setIsdeleted(Constants.ZERO);
MPJLambdaWrapper<Category> queryWrapper = new MPJLambdaWrapper<>();
queryWrapper.selectAll(Category.class);
queryWrapper.selectAs(SystemUser::getUsername,Category::getEditorName);
@@ -193,6 +228,7 @@
.eq(category.getType() != null, Category::getType, category.getType())
.eq(category.getParentId() != null, Category::getParentId, category.getParentId())
.eq(category.getNamePath() != null, Category::getNamePath, category.getNamePath())
+ .isNull(category.getIsRoot() != null &&category.getIsRoot().equals(Constants.ONE), Category::getParentId)
.eq(category.getIdPath() != null, Category::getIdPath, category.getIdPath())
.orderByAsc( Category::getSortnum);
return categoryMapper.selectJoinList(Category.class,queryWrapper);
@@ -256,4 +292,91 @@
return companyList;
}
+
+
+
+
+ @Override
+ public List<CategoryVO> getCategoryVOTree(String categoryType,Integer categoryId){
+ List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda()
+ .eq(Category::getIsdeleted, Constants.ZERO)
+ .in(Objects.nonNull(categoryType),Category::getType,categoryType.split(","))
+ .apply(Objects.nonNull(categoryId)," find_in_set("+categoryId+", REPLACE(ID_PATH,'/',',') ) ")
+ .orderByAsc(Category::getSortnum,Category::getId)
+ );
+ List<CategoryVO> categoryVOList = new ArrayList<>();
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){
+ for (Category category:categoryList) {
+ CategoryVO categoryVO = new CategoryVO();
+ categoryVO.setId(category.getId());
+ categoryVO.setName(category.getName());
+ categoryVO.setParentId(category.getParentId());
+ categoryVOList.add(categoryVO);
+ }
+ CategoryVOTree treeBuild = new CategoryVOTree(categoryVOList);
+ categoryVOList = treeBuild.buildTree();
+ }
+ return categoryVOList;
+ }
+
+
+ @Override
+ public List<CategoryVO> getCategoryVOForGCXTree(Integer categoryId){
+ List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda()
+ .eq(Category::getIsdeleted, Constants.ZERO)
+ .eq(Category::getType, Constants.FOUR)
+ .and( ms->ms.eq(Category::getId,categoryId).or().eq(Category::getParentId,categoryId))
+ .orderByAsc(Category::getSortnum,Category::getId)
+ );
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){
+ categoryList.addAll(
+ categoryMapper.selectList(new QueryWrapper<Category>().lambda()
+ .eq(Category::getIsdeleted, Constants.ZERO)
+ .eq(Category::getType, Constants.SIX)
+ .in(Category::getParentId,categoryList.stream().map(i->i.getId()).collect(Collectors.toList()))
+ .orderByAsc(Category::getSortnum,Category::getId))
+ );
+ }
+ List<CategoryVO> categoryVOList = new ArrayList<>();
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){
+ for (Category category:categoryList) {
+ CategoryVO categoryVO = new CategoryVO();
+ categoryVO.setId(category.getId());
+ categoryVO.setName(category.getName());
+ categoryVO.setParentId(category.getParentId());
+ categoryVOList.add(categoryVO);
+ }
+ CategoryVOTree treeBuild = new CategoryVOTree(categoryVOList);
+ categoryVOList = treeBuild.buildTree();
+ }
+ return categoryVOList;
+ }
+
+
+
+
+ @Override
+ public List<CategoryVO> getCategoryVOList(Integer categoryType,Integer isRoot){
+ List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().lambda()
+ .eq(Category::getIsdeleted, Constants.ZERO)
+ .eq(Objects.nonNull(categoryType),Category::getType,categoryType)
+ .isNull(Constants.equalsInteger(isRoot,Constants.ONE),Category::getParentId)
+ .orderByAsc(Category::getSortnum,Category::getId)
+ );
+ List<CategoryVO> categoryVOList = new ArrayList<>();
+ if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(categoryList)){
+ for (Category category:categoryList) {
+ CategoryVO categoryVO = new CategoryVO();
+ categoryVO.setId(category.getId());
+ categoryVO.setName(category.getName());
+ categoryVO.setParentId(category.getParentId());
+ categoryVOList.add(categoryVO);
+ }
+ }
+ return categoryVOList;
+ }
+
+
+
+
}
--
Gitblit v1.9.3