|
@ -6,9 +6,13 @@ import com.qs.serve.common.util.Assert; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
import com.qs.serve.common.util.IdUtil; |
|
|
import com.qs.serve.common.util.IdUtil; |
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsAccount; |
|
|
|
|
|
import com.qs.serve.modules.bms.mapper.BmsAccountMapper; |
|
|
import com.qs.serve.modules.goods.common.GoodsConst; |
|
|
import com.qs.serve.modules.goods.common.GoodsConst; |
|
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
|
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsCategoryLevelBo; |
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsCategoryLevelBo; |
|
|
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; |
|
|
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsSpuMapper; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
@ -17,6 +21,7 @@ import com.qs.serve.modules.goods.service.GoodsCategoryService; |
|
|
import com.qs.serve.modules.goods.mapper.GoodsCategoryMapper; |
|
|
import com.qs.serve.modules.goods.mapper.GoodsCategoryMapper; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Arrays; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -30,6 +35,10 @@ import java.util.stream.Collectors; |
|
|
@AllArgsConstructor |
|
|
@AllArgsConstructor |
|
|
public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper,GoodsCategory> implements GoodsCategoryService { |
|
|
public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper,GoodsCategory> implements GoodsCategoryService { |
|
|
|
|
|
|
|
|
|
|
|
private final GoodsSkuMapper goodsSkuMapper; |
|
|
|
|
|
private final GoodsSpuMapper goodsSpuMapper; |
|
|
|
|
|
private final BmsAccountMapper accountMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public GoodsCategory getByCode(String code) { |
|
|
public GoodsCategory getByCode(String code) { |
|
|
LambdaQueryWrapper<GoodsCategory> lqw = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<GoodsCategory> lqw = new LambdaQueryWrapper<>(); |
|
@ -47,7 +56,21 @@ public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper,Go |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void modify(GoodsCategory category) { |
|
|
public void modify(GoodsCategory category) { |
|
|
GoodsCategory dbData = this.getById(category.getId()); |
|
|
BmsAccount bookAcc = accountMapper.selectOne(new LambdaQueryWrapper<BmsAccount>() |
|
|
|
|
|
.eq(BmsAccount::getBookCode,category.getBookBelong())); |
|
|
|
|
|
|
|
|
|
|
|
GoodsCategory dbData = null; |
|
|
|
|
|
if(category.getId()!=null){ |
|
|
|
|
|
dbData = this.getById(category.getId()); |
|
|
|
|
|
if(dbData==null){ |
|
|
|
|
|
Assert.throwEx("类目不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
if(bookAcc==null){ |
|
|
|
|
|
Assert.throwEx("账套不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
GoodsCategory parent = null; |
|
|
GoodsCategory parent = null; |
|
|
if( category.getParentId()!=null&&!category.getParentId().equals(0L)){ |
|
|
if( category.getParentId()!=null&&!category.getParentId().equals(0L)){ |
|
|
parent = this.getById(category.getParentId()); |
|
|
parent = this.getById(category.getParentId()); |
|
@ -59,15 +82,22 @@ public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper,Go |
|
|
if(category.getId()==null){ |
|
|
if(category.getId()==null){ |
|
|
this.save(category); |
|
|
this.save(category); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(parent==null){ |
|
|
if(parent==null){ |
|
|
category.setParentId(0L); |
|
|
category.setParentId(0L); |
|
|
category.setLevel(1); |
|
|
category.setLevel(1); |
|
|
category.setLevelPath(category.getId().toString()); |
|
|
category.setLevelPath(category.getId().toString()); |
|
|
category.setLevelPathNames(category.getName()); |
|
|
category.setLevelPathNames(category.getName()); |
|
|
|
|
|
|
|
|
|
|
|
category.setBookBelong(bookAcc.getBookCode()); |
|
|
|
|
|
category.setBookName(bookAcc.getBookName()); |
|
|
}else { |
|
|
}else { |
|
|
category.setLevel(parent.getLevel()+1); |
|
|
category.setLevel(parent.getLevel()+1); |
|
|
category.setLevelPathNames(parent.getLevelPathNames()+"_"+category.getName()); |
|
|
category.setLevelPathNames(parent.getLevelPathNames()+"_"+category.getName()); |
|
|
category.setLevelPath(parent.getLevelPath()+"_"+category.getId()); |
|
|
category.setLevelPath(parent.getLevelPath()+"_"+category.getId()); |
|
|
|
|
|
|
|
|
|
|
|
category.setBookBelong(parent.getBookBelong()); |
|
|
|
|
|
category.setBookName(parent.getBookName()); |
|
|
} |
|
|
} |
|
|
if(dbData==null){ |
|
|
if(dbData==null){ |
|
|
this.saveOrUpdate(category); |
|
|
this.saveOrUpdate(category); |
|
@ -75,13 +105,11 @@ public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper,Go |
|
|
//code不给修改
|
|
|
//code不给修改
|
|
|
category.setCode(null); |
|
|
category.setCode(null); |
|
|
this.updateById(category); |
|
|
this.updateById(category); |
|
|
boolean changePid = !dbData.getParentId().equals(category.getParentId()); |
|
|
GoodsCategory finalDbData = dbData; |
|
|
boolean changeName = !dbData.getName().equals(category.getName()); |
|
|
|
|
|
if(changePid||changeName){ |
|
|
|
|
|
LambdaQueryWrapper<GoodsCategory> lqw = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<GoodsCategory> lqw = new LambdaQueryWrapper<>(); |
|
|
lqw.and(v1->{ |
|
|
lqw.and(v1->{ |
|
|
v1.eq(GoodsCategory::getLevelPath,dbData.getLevelPath()) |
|
|
v1.eq(GoodsCategory::getLevelPath, finalDbData.getLevelPath()) |
|
|
.or().likeRight(GoodsCategory::getLevelPath,dbData.getLevelPath()+"_"); |
|
|
.or().likeRight(GoodsCategory::getLevelPath, finalDbData.getLevelPath()+"_"); |
|
|
}); |
|
|
}); |
|
|
List<GoodsCategory> childList = this.list(lqw); |
|
|
List<GoodsCategory> childList = this.list(lqw); |
|
|
int diffLevel = dbData.getLevel()-category.getLevel(); |
|
|
int diffLevel = dbData.getLevel()-category.getLevel(); |
|
@ -89,22 +117,29 @@ public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper,Go |
|
|
GoodsCategory par = new GoodsCategory(); |
|
|
GoodsCategory par = new GoodsCategory(); |
|
|
par.setId(obj.getId()); |
|
|
par.setId(obj.getId()); |
|
|
par.setLevel(obj.getLevel()+diffLevel); |
|
|
par.setLevel(obj.getLevel()+diffLevel); |
|
|
par.setLevelPathNames(obj.getLevelPathNames().replace(dbData.getLevelPathNames(),category.getLevelPathNames())); |
|
|
par.setLevelPathNames(obj.getLevelPathNames().replace(finalDbData.getLevelPathNames(),category.getLevelPathNames())); |
|
|
par.setLevelPath(obj.getLevelPath().replace(dbData.getLevelPath(),category.getLevelPath())); |
|
|
par.setLevelPath(obj.getLevelPath().replace(finalDbData.getLevelPath(),category.getLevelPath())); |
|
|
|
|
|
par.setBookBelong(category.getBookBelong()); |
|
|
|
|
|
par.setBookName(category.getBookName()); |
|
|
return par; |
|
|
return par; |
|
|
}).collect(Collectors.toList()); |
|
|
}).collect(Collectors.toList()); |
|
|
this.updateBatchById(categoryList); |
|
|
this.updateBatchById(categoryList); |
|
|
}else { |
|
|
|
|
|
//不进行更新
|
|
|
|
|
|
category.setParentId(null); |
|
|
|
|
|
category.setLevel(null); |
|
|
|
|
|
category.setLevelPathNames(null); |
|
|
|
|
|
category.setLevelPath(null); |
|
|
|
|
|
} |
|
|
} |
|
|
this.updateById(category); |
|
|
//更新SKU
|
|
|
|
|
|
List<Long> cateIds = Arrays.asList(category.getId()); |
|
|
} |
|
|
goodsSkuMapper.updateBookInfo(cateIds,bookAcc.getBookCode(),bookAcc.getBookName()); |
|
|
|
|
|
|
|
|
|
|
|
//更新SPU
|
|
|
|
|
|
GoodsSpu spuParam = new GoodsSpu(); |
|
|
|
|
|
spuParam.setBookBelong(bookAcc.getBookCode()); |
|
|
|
|
|
spuParam.setBookName(bookAcc.getBookName()); |
|
|
|
|
|
goodsSpuMapper.update(spuParam,new LambdaQueryWrapper<GoodsSpu>() |
|
|
|
|
|
.in(GoodsSpu::getCategoryFirst,cateIds) |
|
|
|
|
|
.or() |
|
|
|
|
|
.in(GoodsSpu::getCategorySecond,cateIds) |
|
|
|
|
|
.or() |
|
|
|
|
|
.in(GoodsSpu::getCategoryThird,cateIds) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|