parent
14163a7341
commit
ddc6927910
@ -1,29 +1,91 @@
|
||||
package com.xjs.mall.ware.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xjs.mall.ware.dao.PurchaseDao;
|
||||
import com.xjs.mall.ware.entity.PurchaseDetailEntity;
|
||||
import com.xjs.mall.ware.entity.PurchaseEntity;
|
||||
import com.xjs.mall.ware.service.PurchaseDetailService;
|
||||
import com.xjs.mall.ware.service.PurchaseService;
|
||||
import com.xjs.mall.ware.vo.MergeVo;
|
||||
import com.xjs.utils.PageUtils;
|
||||
import com.xjs.utils.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.xjs.consts.WareConstant.PurchaseStatusEnum.ASSIGNED;
|
||||
import static com.xjs.consts.WareConstant.PurchaseStatusEnum.CREATED;
|
||||
|
||||
|
||||
@Service("purchaseService")
|
||||
@Transactional
|
||||
public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity> implements PurchaseService {
|
||||
|
||||
@Autowired
|
||||
private PurchaseDetailService purchaseDetailService;
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<PurchaseEntity> page = this.page(
|
||||
new Query<PurchaseEntity>().getPage(params),
|
||||
new QueryWrapper<PurchaseEntity>()
|
||||
new QueryWrapper<>()
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public PageUtils queryPageUnreceive(Map<String, Object> params) {
|
||||
LambdaQueryWrapper<PurchaseEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PurchaseEntity::getStatus, 0).or().eq(PurchaseEntity::getStatus, 1);
|
||||
|
||||
IPage<PurchaseEntity> page = this.page(new Query<PurchaseEntity>().getPage(params), wrapper);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergePurchase(MergeVo mergeVo) {
|
||||
Long purchaseId = mergeVo.getPurchaseId();
|
||||
//新建采购单
|
||||
if (purchaseId == null) {
|
||||
PurchaseEntity purchaseEntity = new PurchaseEntity();
|
||||
purchaseEntity.setCreateTime(new Date());
|
||||
purchaseEntity.setUpdateTime(new Date());
|
||||
purchaseEntity.setStatus(CREATED.getCode()); //默认采购单状态
|
||||
|
||||
super.save(purchaseEntity);
|
||||
|
||||
purchaseId = purchaseEntity.getId();
|
||||
}
|
||||
|
||||
//合并采购单
|
||||
List<Long> items = mergeVo.getItems();
|
||||
Long finalPurchaseId = purchaseId;
|
||||
|
||||
List<PurchaseDetailEntity> collect = items.stream().map(i -> {
|
||||
PurchaseDetailEntity detailEntity = new PurchaseDetailEntity();
|
||||
detailEntity.setId(i);
|
||||
detailEntity.setPurchaseId(finalPurchaseId);
|
||||
detailEntity.setStatus(ASSIGNED.getCode());
|
||||
return detailEntity;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
purchaseDetailService.updateBatchById(collect);
|
||||
|
||||
PurchaseEntity purchaseEntity = new PurchaseEntity();
|
||||
purchaseEntity.setId(purchaseId);
|
||||
purchaseEntity.setUpdateTime(new Date());
|
||||
super.updateById(purchaseEntity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.xjs.mall.ware.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 合并采购单vo
|
||||
*/
|
||||
@Data
|
||||
public class MergeVo {
|
||||
|
||||
private Long purchaseId; //整单id
|
||||
private List<Long> items;//[1,2,3,4] //合并项集合
|
||||
}
|
Loading…
Reference in new issue