|
@ -1,6 +1,25 @@ |
|
|
package com.qs.serve.modules.sale.service.impl; |
|
|
package com.qs.serve.modules.sale.service.impl; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
|
import com.qs.serve.common.util.AuthContextUtils; |
|
|
|
|
|
import com.qs.serve.common.util.CodeGenUtil; |
|
|
|
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
|
|
|
import com.qs.serve.modules.bms.mapper.BmsSupplierMapper; |
|
|
|
|
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
|
|
|
|
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
|
|
|
|
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
|
|
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsCategoryMapper; |
|
|
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; |
|
|
|
|
|
import com.qs.serve.modules.goods.mapper.GoodsSpuMapper; |
|
|
|
|
|
import com.qs.serve.modules.sale.entity.SalePlanGoods; |
|
|
|
|
|
import com.qs.serve.modules.sale.entity.bo.SalePlanBo; |
|
|
|
|
|
import com.qs.serve.modules.sale.mapper.SalePlanGoodsMapper; |
|
|
|
|
|
import com.qs.serve.modules.sale.service.SalePlanGoodsService; |
|
|
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
|
|
import com.qs.serve.modules.sys.mapper.SysUserMapper; |
|
|
|
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.TbsActivityGoods; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.bo.TbsActivityGoodsBo; |
|
|
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; |
|
@ -8,6 +27,9 @@ import com.qs.serve.modules.sale.entity.SalePlan; |
|
|
import com.qs.serve.modules.sale.service.SalePlanService; |
|
|
import com.qs.serve.modules.sale.service.SalePlanService; |
|
|
import com.qs.serve.modules.sale.mapper.SalePlanMapper; |
|
|
import com.qs.serve.modules.sale.mapper.SalePlanMapper; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 销售计划 服务实现类 |
|
|
* 销售计划 服务实现类 |
|
|
* @author YenHex |
|
|
* @author YenHex |
|
@ -18,5 +40,97 @@ import com.qs.serve.modules.sale.mapper.SalePlanMapper; |
|
|
@AllArgsConstructor |
|
|
@AllArgsConstructor |
|
|
public class SalePlanServiceImpl extends ServiceImpl<SalePlanMapper,SalePlan> implements SalePlanService { |
|
|
public class SalePlanServiceImpl extends ServiceImpl<SalePlanMapper,SalePlan> implements SalePlanService { |
|
|
|
|
|
|
|
|
|
|
|
private final SysUserMapper sysUserMapper; |
|
|
|
|
|
private final BmsSupplierMapper supplierMapper; |
|
|
|
|
|
private final SalePlanGoodsMapper salePlanGoodsMapper; |
|
|
|
|
|
private final SalePlanGoodsService salePlanGoodsService; |
|
|
|
|
|
|
|
|
|
|
|
private final GoodsCategoryMapper goodsCategoryMapper; |
|
|
|
|
|
private final GoodsSpuMapper goodsSpuMapper; |
|
|
|
|
|
private final GoodsSkuMapper goodsSkuMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public SalePlan modify(SalePlanBo param) { |
|
|
|
|
|
String userId = AuthContextUtils.getSysUserId(); |
|
|
|
|
|
SysUser sysUser = sysUserMapper.selectById(userId); |
|
|
|
|
|
BmsSupplier supplier = supplierMapper.selectById(param.getSupplierId()); |
|
|
|
|
|
SalePlan salePlan = new SalePlan(); |
|
|
|
|
|
salePlan.setPlanTitle(param.getPlanTitle()); |
|
|
|
|
|
salePlan.setUserId(sysUser.getId()); |
|
|
|
|
|
salePlan.setUserCode(sysUser.getCode()); |
|
|
|
|
|
salePlan.setUserName(sysUser.getName()); |
|
|
|
|
|
salePlan.setSupplierId(supplier.getId()); |
|
|
|
|
|
salePlan.setSupplierCode(supplier.getCode()); |
|
|
|
|
|
salePlan.setSupplierName(supplier.getName()); |
|
|
|
|
|
if(param.getId()==null){ |
|
|
|
|
|
salePlan.setPlanCode(CodeGenUtil.generate(CodeGenUtil.SourceKey.SalePlan)); |
|
|
|
|
|
super.save(salePlan); |
|
|
|
|
|
}else { |
|
|
|
|
|
salePlan.setId(param.getId()); |
|
|
|
|
|
super.updateById(salePlan); |
|
|
|
|
|
//删除品类
|
|
|
|
|
|
salePlanGoodsMapper.deleteByPlanId(salePlan.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
List<SalePlanGoods> planGoodsList = this.buildPlanGoods(param.getGoodsItems(),param.getTargetType()); |
|
|
|
|
|
for (SalePlanGoods planGoods : planGoodsList) { |
|
|
|
|
|
planGoods.setPlanId(salePlan.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
salePlanGoodsService.saveBatch(planGoodsList); |
|
|
|
|
|
return salePlan; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<SalePlanGoods> buildPlanGoods(List<SalePlanBo.SalePlanGoodsItem> goodsItems,String goodsType){ |
|
|
|
|
|
List<SalePlanGoods> salePlanGoods = new ArrayList<>(); |
|
|
|
|
|
if(goodsType.equals(TbsGoodsType.spu.name())){ |
|
|
|
|
|
for (SalePlanBo.SalePlanGoodsItem goodsBo : goodsItems) { |
|
|
|
|
|
GoodsSpu goodsSpu = goodsSpuMapper.selectById(goodsBo.getTargetId()); |
|
|
|
|
|
GoodsCategory category1 = goodsCategoryMapper.selectById(goodsSpu.getCategoryFirst()); |
|
|
|
|
|
GoodsCategory category2 = goodsCategoryMapper.selectById(goodsSpu.getCategorySecond()); |
|
|
|
|
|
GoodsCategory category3 = goodsCategoryMapper.selectById(goodsSpu.getCategoryThird()); |
|
|
|
|
|
SalePlanGoods planGoods = new SalePlanGoods(); |
|
|
|
|
|
planGoods.setTargetType(goodsType); |
|
|
|
|
|
planGoods.setTargetId(goodsSpu.getId()); |
|
|
|
|
|
planGoods.setTargetCode(goodsSpu.getSpuCode()); |
|
|
|
|
|
planGoods.setTargetName(goodsSpu.getName()); |
|
|
|
|
|
planGoods.setTargetLevelPathIds(category1.getId()+"_"+category2.getId()+"_"+category3.getId()+"_"+goodsSpu.getId()); |
|
|
|
|
|
planGoods.setTargetLevelPathNames(category1.getName()+"_"+category2.getName()+"_"+category3.getName()+"_"+goodsSpu.getName()); |
|
|
|
|
|
planGoods.setQty(goodsBo.getQty()); |
|
|
|
|
|
salePlanGoods.add(planGoods); |
|
|
|
|
|
} |
|
|
|
|
|
}else if (goodsType.equals(TbsGoodsType.sku.name())){ |
|
|
|
|
|
for (SalePlanBo.SalePlanGoodsItem goodsBo : goodsItems) { |
|
|
|
|
|
GoodsSku sku = goodsSkuMapper.selectById(goodsBo.getTargetId()); |
|
|
|
|
|
GoodsSpu goodsSpu = goodsSpuMapper.selectById(sku.getSpuId()); |
|
|
|
|
|
GoodsCategory category1 = goodsCategoryMapper.selectById(goodsSpu.getCategoryFirst()); |
|
|
|
|
|
GoodsCategory category2 = goodsCategoryMapper.selectById(goodsSpu.getCategorySecond()); |
|
|
|
|
|
GoodsCategory category3 = goodsCategoryMapper.selectById(goodsSpu.getCategoryThird()); |
|
|
|
|
|
SalePlanGoods planGoods = new SalePlanGoods(); |
|
|
|
|
|
planGoods.setTargetType(goodsType); |
|
|
|
|
|
planGoods.setTargetId(sku.getId()); |
|
|
|
|
|
planGoods.setTargetCode(sku.getSkuCode()); |
|
|
|
|
|
planGoods.setTargetName(sku.getSpecInfos()); |
|
|
|
|
|
planGoods.setTargetLevelPathIds(category1.getId()+"_"+category2.getId()+"_"+category3.getId()+"_"+goodsSpu.getId()+"_"+sku.getId()); |
|
|
|
|
|
planGoods.setTargetLevelPathNames(category1.getName()+"_"+category2.getName()+"_"+category3.getName()+"_"+goodsSpu.getName()+"_"+sku.getSpecInfos()); |
|
|
|
|
|
planGoods.setQty(goodsBo.getQty()); |
|
|
|
|
|
salePlanGoods.add(planGoods); |
|
|
|
|
|
} |
|
|
|
|
|
}else { |
|
|
|
|
|
//品牌、品类、系列
|
|
|
|
|
|
for (SalePlanBo.SalePlanGoodsItem goodsBo : goodsItems) { |
|
|
|
|
|
GoodsCategory category = goodsCategoryMapper.selectById(goodsBo.getTargetId()); |
|
|
|
|
|
SalePlanGoods planGoods = new SalePlanGoods(); |
|
|
|
|
|
planGoods.setTargetType(goodsType); |
|
|
|
|
|
planGoods.setTargetId(category.getId()); |
|
|
|
|
|
planGoods.setTargetCode(category.getCode()); |
|
|
|
|
|
planGoods.setTargetName(category.getName()); |
|
|
|
|
|
planGoods.setTargetLevelPathIds(category.getLevelPath()); |
|
|
|
|
|
planGoods.setTargetLevelPathNames(category.getLevelPathNames()); |
|
|
|
|
|
planGoods.setQty(goodsBo.getQty()); |
|
|
|
|
|
salePlanGoods.add(planGoods); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return salePlanGoods; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|