|
@@ -1,15 +1,11 @@
|
|
package com.ym.mec.biz.service.impl;
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import com.ym.mec.biz.dal.dao.GoodsCategoryDao;
|
|
import com.ym.mec.biz.dal.dao.GoodsCategoryDao;
|
|
|
|
+import com.ym.mec.biz.dal.dao.SubjectGoodsMapperDao;
|
|
import com.ym.mec.biz.dal.entity.GoodsCategory;
|
|
import com.ym.mec.biz.dal.entity.GoodsCategory;
|
|
-import com.ym.mec.biz.dal.entity.Subject;
|
|
|
|
-import com.ym.mec.biz.dal.enums.YesOrNoEnum;
|
|
|
|
-import com.ym.mec.biz.dal.page.GoodsCategoryQueryInfo;
|
|
|
|
import com.ym.mec.biz.service.GoodsCategoryService;
|
|
import com.ym.mec.biz.service.GoodsCategoryService;
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
-import com.ym.mec.common.page.PageInfo;
|
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
-
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -22,6 +18,8 @@ public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCate
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private GoodsCategoryDao goodsCategoryDao;
|
|
private GoodsCategoryDao goodsCategoryDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SubjectGoodsMapperDao subjectGoodsMapperDao;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public BaseDAO<Integer, GoodsCategory> getDAO() {
|
|
public BaseDAO<Integer, GoodsCategory> getDAO() {
|
|
@@ -30,60 +28,17 @@ public class GoodsCategoryServiceImpl extends BaseServiceImpl<Integer, GoodsCate
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public void add(GoodsCategory goodsCategory) {
|
|
|
|
- goodsCategoryDao.insert(goodsCategory);
|
|
|
|
- List<GoodsCategory> goodsCategories = goodsCategory.getGoodsCategories();
|
|
|
|
- goodsCategories.forEach(e->{
|
|
|
|
- e.setParentId(goodsCategory.getId());
|
|
|
|
- goodsCategoryDao.insert(e);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
public void upsetGoodsCategory(GoodsCategory goodsCategory) {
|
|
public void upsetGoodsCategory(GoodsCategory goodsCategory) {
|
|
- Integer parentId = upset(goodsCategory, null);
|
|
|
|
- List<GoodsCategory> goodsCategories = goodsCategory.getGoodsCategories();
|
|
|
|
- goodsCategories.forEach(e->{
|
|
|
|
- upset(e, parentId);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public PageInfo<GoodsCategory> queryTreePage(GoodsCategoryQueryInfo queryInfo) {
|
|
|
|
- PageInfo<GoodsCategory> pageInfo = queryPage(queryInfo);
|
|
|
|
- for (GoodsCategory goodsCategory:pageInfo.getRows()) {
|
|
|
|
- goodsCategory = getTree(goodsCategory,queryInfo.getStatus());
|
|
|
|
- }
|
|
|
|
- return pageInfo;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private GoodsCategory getTree(GoodsCategory goodsCategory, YesOrNoEnum yesOrNoEnum){
|
|
|
|
- //得到根节点对象
|
|
|
|
- //获取子节点list
|
|
|
|
- List<GoodsCategory> goodsCategories = goodsCategoryDao.findByParentId(goodsCategory.getId(),yesOrNoEnum);
|
|
|
|
- //如果存在子节点
|
|
|
|
- if(goodsCategories != null && goodsCategories.size() > 0) {
|
|
|
|
- //将子节点list放入父节点对象
|
|
|
|
- goodsCategory.setGoodsCategories(goodsCategories);
|
|
|
|
- //遍历子节点....
|
|
|
|
- for (GoodsCategory subject : goodsCategories) {
|
|
|
|
- getTree(subject,yesOrNoEnum);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return goodsCategory;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Integer upset(GoodsCategory goodsCategory, Integer parentId){
|
|
|
|
- if(parentId != null){
|
|
|
|
- goodsCategory.setParentId(parentId);
|
|
|
|
- }
|
|
|
|
|
|
+ goodsCategory.setParentId(0);
|
|
if(goodsCategory.getId() != null){
|
|
if(goodsCategory.getId() != null){
|
|
goodsCategory.setUpdateTime(new Date());
|
|
goodsCategory.setUpdateTime(new Date());
|
|
goodsCategoryDao.update(goodsCategory);
|
|
goodsCategoryDao.update(goodsCategory);
|
|
|
|
+ //删除关联
|
|
|
|
+ subjectGoodsMapperDao.delByGoodsCategoryId(goodsCategory.getId());
|
|
}else {
|
|
}else {
|
|
goodsCategoryDao.insert(goodsCategory);
|
|
goodsCategoryDao.insert(goodsCategory);
|
|
}
|
|
}
|
|
- return goodsCategory.getId();
|
|
|
|
|
|
+ List<Integer> subjectIds = goodsCategory.getSubjectIds();
|
|
|
|
+ subjectGoodsMapperDao.batchAdd(goodsCategory.getId(),subjectIds);
|
|
}
|
|
}
|
|
}
|
|
}
|