|
|
@ -10,10 +10,7 @@ import com.qs.serve.common.model.enums.SystemModule; |
|
|
|
import com.qs.serve.common.util.*; |
|
|
|
import com.qs.serve.modules.goods.common.GoodsConst; |
|
|
|
import com.qs.serve.modules.goods.entity.*; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsSpuBatchTasteBo; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsSpuBo; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsSpuEditBo; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.GoodsSpuTasteBo; |
|
|
|
import com.qs.serve.modules.goods.entity.bo.*; |
|
|
|
import com.qs.serve.modules.goods.entity.dto.InventoryCusPrice; |
|
|
|
import com.qs.serve.modules.goods.entity.so.InventoryCusPriceQuery; |
|
|
|
import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; |
|
|
@ -96,12 +93,14 @@ public class GoodsSpuController { |
|
|
|
try { |
|
|
|
String supplierCode = param.getSupplierCode(); |
|
|
|
List<String> skuCodes = toSkuKeys.stream().map(OmsSpuToSkuKey::getInvCode).collect(Collectors.toList()); |
|
|
|
InventoryCusPriceQuery query = new InventoryCusPriceQuery(); |
|
|
|
query.setCusCode(supplierCode); |
|
|
|
query.setInvCodes(skuCodes); |
|
|
|
R<String> res = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价"); |
|
|
|
if(res.getStatus().equals(200)){ |
|
|
|
inventoryCusPrices = JsonUtil.jsonToList(res.getData(), InventoryCusPrice.class); |
|
|
|
if(skuCodes.size()>0){ |
|
|
|
InventoryCusPriceQuery query = new InventoryCusPriceQuery(); |
|
|
|
query.setCusCode(supplierCode); |
|
|
|
query.setInvCodes(skuCodes); |
|
|
|
R<String> res = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价"); |
|
|
|
if(res.getStatus().equals(200)){ |
|
|
|
inventoryCusPrices = JsonUtil.jsonToList(res.getData(), InventoryCusPrice.class); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("客户特殊价异常:{}",e.getMessage()); |
|
|
@ -279,6 +278,151 @@ public class GoodsSpuController { |
|
|
|
return R.ok(goodsSpuService.editTasteSpu(param)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入 |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/importSpu") |
|
|
|
@SysLog(module = SystemModule.GOODS, title = "import", biz = BizType.INSERT) |
|
|
|
public R<?> importSpu(@RequestBody @Valid GoodsSpuImportBo param){ |
|
|
|
final String UPDATE = "update"; |
|
|
|
final String DELETE = "delete"; |
|
|
|
final String SAVE = "save"; |
|
|
|
|
|
|
|
//导入
|
|
|
|
List<String> spuCodes = new ArrayList<>(); |
|
|
|
List<String> cateNames = new ArrayList<>(); |
|
|
|
for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { |
|
|
|
spuCodes.add(item.getSpuCode()); |
|
|
|
//删除只需要spu编码
|
|
|
|
if(StringUtils.hasText(item.getCategoryName())&&!item.getOpt().equals(DELETE)){ |
|
|
|
cateNames.add(item.getCategoryName()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(spuCodes.size()<1){ |
|
|
|
return R.error("获取SKU编码失败"); |
|
|
|
} |
|
|
|
LambdaQueryWrapper<GoodsSpu> spuLqw = new LambdaQueryWrapper<>(); |
|
|
|
spuLqw.in(GoodsSpu::getSpuCode,spuCodes); |
|
|
|
List<GoodsSpu> spuList = goodsSpuService.list(spuLqw); |
|
|
|
|
|
|
|
List<GoodsCategory> cateList = null; |
|
|
|
if(cateNames.size()>0){ |
|
|
|
LambdaQueryWrapper<GoodsCategory> cateLqw = new LambdaQueryWrapper<>(); |
|
|
|
cateLqw.in(GoodsCategory::getName,cateNames); |
|
|
|
cateLqw.eq(GoodsCategory::getLevel,3); |
|
|
|
cateList = goodsCategoryService.list(cateLqw); |
|
|
|
} |
|
|
|
|
|
|
|
boolean isError = false; |
|
|
|
for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { |
|
|
|
spuCodes.add(item.getSpuCode()); |
|
|
|
//更新或者保存,需要校验类目名称
|
|
|
|
if(StringUtils.hasText(item.getCategoryName())&&!item.getOpt().equals(DELETE)){ |
|
|
|
if(cateList==null){ |
|
|
|
isError = true; |
|
|
|
item.setErrMsg("["+item.getCategoryName()+"]类目不存在"); |
|
|
|
}else { |
|
|
|
String cateName = item.getCategoryName(); |
|
|
|
boolean existCate = cateList.stream().anyMatch(a->a.getName().equals(cateName)); |
|
|
|
if(!existCate){ |
|
|
|
isError = true; |
|
|
|
item.setErrMsg("["+item.getCategoryName()+"]类目不存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String spuCode = item.getSpuCode(); |
|
|
|
boolean existSpu = spuList.stream().anyMatch(a->a.getSpuCode().equals(spuCode)); |
|
|
|
|
|
|
|
if(existSpu&&item.getOpt().equals(SAVE)){ |
|
|
|
isError = true; |
|
|
|
item.setErrMsg("SKU编码已存在"); |
|
|
|
}else if(!existSpu && item.getOpt().equals(UPDATE)){ |
|
|
|
isError = true; |
|
|
|
item.setErrMsg("SKU编码不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(isError){ |
|
|
|
return R.error("数据异常",param); |
|
|
|
} |
|
|
|
|
|
|
|
List<Long> rmIds = new ArrayList<>(); |
|
|
|
List<GoodsSpu> spuUpdateList = new ArrayList<>(); |
|
|
|
List<GoodsSpu> spuSaveList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (GoodsSpuImportBo.SpuItem spuItem : param.getSpuList()) { |
|
|
|
|
|
|
|
if(spuItem.getOpt().equals(SAVE)){ |
|
|
|
GoodsSpu goodsSpu = new GoodsSpu(); |
|
|
|
goodsSpu.setSpuCode(spuItem.getSpuCode()); |
|
|
|
goodsSpu.setName(spuItem.getName()); |
|
|
|
//修改类目
|
|
|
|
this.toSetSpuCate(cateList, spuItem, goodsSpu); |
|
|
|
goodsSpu.setShelf(1); |
|
|
|
goodsSpu.setCostFlag(1); |
|
|
|
spuSaveList.add(goodsSpu); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
for (GoodsSpu spu : spuList) { |
|
|
|
if(spu.getSpuCode().equals(spuItem.getSpuCode())){ |
|
|
|
//删除
|
|
|
|
if(spuItem.getOpt().equals(DELETE)){ |
|
|
|
rmIds.add(spu.getId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
//更新start
|
|
|
|
if(StringUtils.hasText(spuItem.getName())){ |
|
|
|
spu.setName(spuItem.getName()); |
|
|
|
} |
|
|
|
//修改类目
|
|
|
|
this.toSetSpuCate(cateList, spuItem, spu); |
|
|
|
//关联
|
|
|
|
if(spuItem.getOpt().equals(UPDATE)){ |
|
|
|
spuUpdateList.add(spu); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(rmIds.size()>0){ |
|
|
|
goodsSpuService.removeBatchByIds(rmIds); |
|
|
|
} |
|
|
|
if(spuUpdateList.size()>0){ |
|
|
|
goodsSpuService.updateBatchById(spuUpdateList); |
|
|
|
} |
|
|
|
if(spuSaveList.size()>0){ |
|
|
|
goodsSpuService.saveBatch(spuSaveList); |
|
|
|
} |
|
|
|
|
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改类目 |
|
|
|
* @param cateList |
|
|
|
* @param spuItem |
|
|
|
* @param spu |
|
|
|
*/ |
|
|
|
private void toSetSpuCate(List<GoodsCategory> cateList, GoodsSpuImportBo.SpuItem spuItem, GoodsSpu spu) { |
|
|
|
if(cateList !=null){ |
|
|
|
for (GoodsCategory category : cateList) { |
|
|
|
if(category.getName().equals(spuItem.getCategoryName())){ |
|
|
|
String[] cateIds = category.getLevelPath().split("_"); |
|
|
|
if(cateIds.length==3){ |
|
|
|
spu.setCategoryFirst(cateIds[0]); |
|
|
|
spu.setCategorySecond(cateIds[1]); |
|
|
|
spu.setCategoryThird(cateIds[2]); |
|
|
|
spu.setCategoryLast(cateIds[2]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|