电商项目——初识电商——第一章——上篇
电商项目——分布式基础概念和电商项目微服务架构图,划分图的详解——第二章——上篇
电商项目——电商项目的虚拟机环境搭建_VirtualBox,Vagrant——第三章——上篇
电商项目——Linux虚拟机中安装docker,mysql,redis_VirtualBox——第四章——上篇
电商项目——电商项目的环境搭建_开发工具&环境搭建——第五章——上篇
电商项目——快速开发人人开源搭建后台管理系统&代码生成器逆向工程搭建——第六章——上篇
电商项目——分布式组件(SpringCloud Alibaba,SpringCloud)——第七章——上篇
电商项目——前端基础——第八章——上篇
电商项目——商品服务-API-三级分类——第九章——上篇
电商项目——商品服务-API-品牌管理——第十章——上篇
电商项目——商品服务-API-属性分组——第十一章——上篇
电商项目——商品服务-API-品牌管理——第十二章——上篇
电商项目——商品服务-API-平台属性——第十三章——上篇
电商项目——商品服务-API-新增商品——第十四章——上篇
电商项目——商品服务-API-商品管理——第十五章——上篇
电商项目——商品服务-API-仓库管理——第十六章——上篇
文章目录
- 1:整合ware服务&创建采购需求
- 2:查询库存&创建采购需求
- 3:合并采购需求
- 4:领取采购单
- 5:完成采购
- 6:商品管理-SPU规格维护
1:整合ware服务&创建采购需求
WareInfoController
@RestController
@RequestMapping("ware/wareinfo")
public class WareInfoController {
@Autowired
private WareInfoService wareInfoService;
/**
* 列表
*/
@RequestMapping("/list")
//@RequiresPermissions("ware:wareinfo:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = wareInfoService.queryPageByCondition(params);
return R.ok().put("page", page);
}
WareInfoServiceImpl
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)){
wrapper.eq("id",key).or().like("name",key).or().like("address",key).or().like("areacode",key);
}
IPage<WareInfoEntity> page = this.page(
new Query<WareInfoEntity>().getPage(params),
wrapper
);
return new PageUtils(page);
}
2:查询库存&创建采购需求
WareSkuController
@RestController
@RequestMapping("ware/waresku")
public class WareSkuController {
@Autowired
private WareSkuService wareSkuService;
/**
* 列表
*/
@RequestMapping("/list")
//@RequiresPermissions("ware:waresku:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = wareSkuService.queryPageByCondition(params);
return R.ok().put("page", page);
}
WareSkuServiceImpl
/**
* {
page: 1,//当前页码
limit: 10,//每页记录数
sidx: 'id',//排序字段
order: 'asc/desc',//排序方式
wareId: 123,//仓库id
skuId: 123//商品id
}
* @param params
* @return
*/
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
QueryWrapper<WareSkuEntity> wrapper = new QueryWrapper<>();
String wareId = (String) params.get("wareId");
if (!StringUtils.isEmpty(wareId)){
wrapper.eq("ware_Id",wareId);
}
String skuId = (String) params.get("skuId");
if (!StringUtils.isEmpty(skuId)){
wrapper.eq("sku_Id",skuId);
}
IPage<WareSkuEntity> page = this.page(
new Query<WareSkuEntity>().getPage(params),
wrapper
);
return new PageUtils(page);
}
PurchaseDetailController
@RestController
@RequestMapping("ware/purchasedetail")
public class PurchaseDetailController {
@Autowired
private PurchaseDetailService purchaseDetailService;
/**
* 列表
*/
@RequestMapping("/list")
//@RequiresPermissions("ware:purchasedetail:list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = purchaseDetailService.queryPageByCondition(params);
return R.ok().put("page", page);
}
PurchaseDetailServiceImpl
3:合并采购需求
前面我们创建了两个采购需求,接下来,我们要将这两个采购需求进行合并,成采购单
第一步:完成合并采购单功能
PurchaseController
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
@Autowired
private PurchaseService purchaseService;
/**
* 列表
*/
@RequestMapping("/unreceive/list")
//@RequiresPermissions("ware:purchase:list")
public R unreceiveList(@RequestParam Map<String, Object> params){
PageUtils page = purchaseService.queryPageUnreceiveList(params);
return R.ok().put("page", page);
}
PurchaseServiceImpl
@Override
public PageUtils queryPageUnreceiveList(Map<String, Object> params) {
QueryWrapper<PurchaseEntity> wrapper = new QueryWrapper<>();
//查询出1,0的数据为status
wrapper.eq("status",0).or().eq("status",1);
IPage<PurchaseEntity> page = this.page(
new Query<PurchaseEntity>().getPage(params),wrapper
);
return new PageUtils(page);
}
PurchaseController
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
@Autowired
private PurchaseService purchaseService;
@RequestMapping("/merge")
//@RequiresPermissions("ware:purchase:list")
public R merge(@RequestBody MergeVo mergeVo){
purchaseService.merge(mergeVo);
return R.ok();
}
PurchaseServiceImpl
@Service("purchaseService")
public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity> implements PurchaseService {
@Autowired
PurchaseDetailService purchaseDetailService;
@Transactional
@Override
public void merge(MergeVo mergeVo) {
Long purchaseId = mergeVo.getPurchaseId();
if (purchaseId==null){
PurchaseEntity purchaseEntity=new PurchaseEntity();
purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATE.getCode());
purchaseEntity.setUpdateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.save(purchaseEntity);
Long purchaseEntityId = purchaseEntity.getId();
}
List<Long> items=mergeVo.getItems();
Long finalPurchaseEntityId=purchaseId;
List<PurchaseDetailEntity> collect = items.stream().map(i -> {
PurchaseDetailEntity purchaseEntity = new PurchaseDetailEntity();
purchaseEntity.setStatus(WareConstant.PurchaseDetailsStatusEnum.ASSIGEND.getCode());
purchaseEntity.setPurchaseId(finalPurchaseEntityId);
purchaseEntity.setId(i);
return purchaseEntity;
}).collect(Collectors.toList());
purchaseDetailService.updateBatchById(collect);
}
4:领取采购单
PurchaseController
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
@Autowired
private PurchaseService purchaseService;
/**
* 领取采购单
* @param ids
* @return
*/
///ware/purchase/received
public R received(@RequestBody List<Long> ids){
purchaseService.received(ids);
return R.ok();
}
PurchaseServiceImpl
/**
*
* @param ids 采购单id
*/
@Override
public void received(List<Long> ids) {
//1:确认当前采购单是新建或者已分配状态
//把采购单的详细信息查出来
List<PurchaseEntity> purchaseEntities = ids.stream().map(id -> {
PurchaseEntity byId = this.getById(id);
return byId;
}).filter(item->{
if (item.getStatus()==WareConstant.PurchaseStatusEnum.CREATE.getCode()||
item.getStatus()==WareConstant.PurchaseStatusEnum.ASSIGEND.getCode() ){
return true;
}
return false;
}).map(items->{
items.setStatus(WareConstant.PurchaseStatusEnum.RECEIVE.getCode());
items.setUpdateTime(new Date());
return items;
}).collect(Collectors.toList());
//2:改变采购单的状态
this.updateBatchById(purchaseEntities);
//3:改变采购项的状态
purchaseEntities.forEach((item->{
List<PurchaseDetailEntity> entities= purchaseDetailService.listDetailByPurchaseId(item.getId());
List<PurchaseDetailEntity> purchaseDetailEntities = entities.stream().map(entitiess -> {
PurchaseDetailEntity purchaseDetailEntity = new PurchaseDetailEntity();
purchaseDetailEntity.setId(entitiess.getId());
purchaseDetailEntity.setStatus(WareConstant.PurchaseDetailsStatusEnum.BUYING.getCode());
return purchaseDetailEntity;
}).collect(Collectors.toList());
purchaseDetailService.updateBatchById(purchaseDetailEntities);
}));
}
5:完成采购
6:商品管理-SPU规格维护
AttrController
@RestController
@RequestMapping("product/attr")
public class AttrController {
@Autowired
private AttrService attrService;
@Autowired
ProductAttrValueService productAttrValueService;
@GetMapping("/base/listforspu/{spuId}")
public R baseAttrlistforspu(@PathVariable("spuId") Long spuId){
List<ProductAttrValueEntity> entities= productAttrValueService.baseAttrlistforspu(spuId);
return R.ok().put("data",entities);
}
ProductAttrValueServiceImpl
@Override
public List<ProductAttrValueEntity> baseAttrlistforspu(Long spuId) {
List<ProductAttrValueEntity> entities = this.baseMapper.selectList(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id", spuId));
return entities;
}
AttrController
@PostMapping("/update/{spuId}")
// @RequiresPermissions("product:attr:update")
public R updateSpuAttr(@RequestBody List<ProductAttrValueEntity> attr,@PathVariable("spuId") Long spuId){
productAttrValueService.updateSpuAttr(spuId,attr);
return R.ok();
}
ProductAttrValueServiceImpl
@Transactional
@Override
public void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> attr) {
//1:删除这个spuId之前对应的所有属性
this.baseMapper.delete(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id",spuId));
List<ProductAttrValueEntity> collect = attr.stream().map(item -> {
item.setSpuId(spuId);
return item;
}).collect(Collectors.toList());
this.saveBatch(collect);
}