|
|
@ -1,17 +1,23 @@
|
|
|
|
package com.xjs.mall.ware.service.impl;
|
|
|
|
package com.xjs.mall.ware.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
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.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
|
|
|
|
|
|
import com.xjs.consts.WareConstant;
|
|
|
|
|
|
|
|
import com.xjs.exception.MallException;
|
|
|
|
import com.xjs.mall.ware.dao.PurchaseDao;
|
|
|
|
import com.xjs.mall.ware.dao.PurchaseDao;
|
|
|
|
import com.xjs.mall.ware.entity.PurchaseDetailEntity;
|
|
|
|
import com.xjs.mall.ware.entity.PurchaseDetailEntity;
|
|
|
|
import com.xjs.mall.ware.entity.PurchaseEntity;
|
|
|
|
import com.xjs.mall.ware.entity.PurchaseEntity;
|
|
|
|
|
|
|
|
import com.xjs.mall.ware.entity.WareInfoEntity;
|
|
|
|
import com.xjs.mall.ware.service.PurchaseDetailService;
|
|
|
|
import com.xjs.mall.ware.service.PurchaseDetailService;
|
|
|
|
import com.xjs.mall.ware.service.PurchaseService;
|
|
|
|
import com.xjs.mall.ware.service.PurchaseService;
|
|
|
|
|
|
|
|
import com.xjs.mall.ware.service.WareInfoService;
|
|
|
|
import com.xjs.mall.ware.vo.MergeVo;
|
|
|
|
import com.xjs.mall.ware.vo.MergeVo;
|
|
|
|
|
|
|
|
import com.xjs.mall.ware.vo.PurchaseVo;
|
|
|
|
import com.xjs.utils.PageUtils;
|
|
|
|
import com.xjs.utils.PageUtils;
|
|
|
|
import com.xjs.utils.Query;
|
|
|
|
import com.xjs.utils.Query;
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@ -21,8 +27,7 @@ import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static com.xjs.consts.WareConstant.PurchaseStatusEnum.ASSIGNED;
|
|
|
|
import static com.xjs.consts.WareConstant.PurchaseStatusEnum.*;
|
|
|
|
import static com.xjs.consts.WareConstant.PurchaseStatusEnum.CREATED;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service("purchaseService")
|
|
|
|
@Service("purchaseService")
|
|
|
@ -31,14 +36,35 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private PurchaseDetailService purchaseDetailService;
|
|
|
|
private PurchaseDetailService purchaseDetailService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private WareInfoService wareInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
|
public PageUtils queryPage(Map<String, Object> params) {
|
|
|
|
IPage<PurchaseEntity> page = this.page(
|
|
|
|
LambdaQueryWrapper<PurchaseEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
new Query<PurchaseEntity>().getPage(params),
|
|
|
|
|
|
|
|
new QueryWrapper<>()
|
|
|
|
String key = (String) params.get(Query.KEY_NAME);
|
|
|
|
);
|
|
|
|
wrapper.and(StringUtils.isNotEmpty(key), wr -> {
|
|
|
|
|
|
|
|
wr.like(PurchaseEntity::getAssigneeName, key).or()
|
|
|
|
|
|
|
|
.eq(PurchaseEntity::getPhone, key);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPage<PurchaseEntity> page = this.page(new Query<PurchaseEntity>().getPage(params), wrapper);
|
|
|
|
|
|
|
|
List<Object> collect = page.getRecords().stream().map(purchaseEntity -> {
|
|
|
|
|
|
|
|
PurchaseVo purchaseVo = new PurchaseVo();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(purchaseEntity,purchaseVo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (purchaseEntity.getWareId() != null) {
|
|
|
|
|
|
|
|
//获取仓库信息
|
|
|
|
|
|
|
|
WareInfoEntity wareInfoEntity = wareInfoService.getById(purchaseVo.getWareId());
|
|
|
|
|
|
|
|
purchaseVo.setWareName(wareInfoEntity.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return purchaseVo;
|
|
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PageUtils pageUtils = new PageUtils(page);
|
|
|
|
|
|
|
|
pageUtils.setList(collect);
|
|
|
|
return new PageUtils(page);
|
|
|
|
return new PageUtils(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -60,6 +86,7 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity
|
|
|
|
PurchaseEntity purchaseEntity = new PurchaseEntity();
|
|
|
|
PurchaseEntity purchaseEntity = new PurchaseEntity();
|
|
|
|
purchaseEntity.setCreateTime(new Date());
|
|
|
|
purchaseEntity.setCreateTime(new Date());
|
|
|
|
purchaseEntity.setUpdateTime(new Date());
|
|
|
|
purchaseEntity.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
purchaseEntity.setPriority(1); //设置优先级默认1
|
|
|
|
purchaseEntity.setStatus(CREATED.getCode()); //默认采购单状态
|
|
|
|
purchaseEntity.setStatus(CREATED.getCode()); //默认采购单状态
|
|
|
|
|
|
|
|
|
|
|
|
super.save(purchaseEntity);
|
|
|
|
super.save(purchaseEntity);
|
|
|
@ -67,8 +94,17 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity
|
|
|
|
purchaseId = purchaseEntity.getId();
|
|
|
|
purchaseId = purchaseEntity.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//合并采购单
|
|
|
|
// 确认采购单状态是 0 或 1 才可以合并
|
|
|
|
List<Long> items = mergeVo.getItems();
|
|
|
|
List<Long> items = mergeVo.getItems();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Long item : items) {
|
|
|
|
|
|
|
|
PurchaseDetailEntity entity = purchaseDetailService.getById(item);
|
|
|
|
|
|
|
|
if (!(entity.getStatus() == CREATED.getCode() || entity.getStatus() == ASSIGNED.getCode())) {
|
|
|
|
|
|
|
|
throw new MallException("采购单只有在新建或分配状态才能合并");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//合并采购单
|
|
|
|
Long finalPurchaseId = purchaseId;
|
|
|
|
Long finalPurchaseId = purchaseId;
|
|
|
|
|
|
|
|
|
|
|
|
List<PurchaseDetailEntity> collect = items.stream().map(i -> {
|
|
|
|
List<PurchaseDetailEntity> collect = items.stream().map(i -> {
|
|
|
@ -88,4 +124,34 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void received(List<Long> ids) {
|
|
|
|
|
|
|
|
//确认当前采购单是新建或者已分配状态
|
|
|
|
|
|
|
|
List<PurchaseEntity> collect = ids.stream().map(super::getById)
|
|
|
|
|
|
|
|
.filter(item ->
|
|
|
|
|
|
|
|
item.getStatus() == CREATED.getCode() || item.getStatus() == ASSIGNED.getCode()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.peek(item -> {
|
|
|
|
|
|
|
|
item.setStatus(RECEIVE.getCode());
|
|
|
|
|
|
|
|
item.setUpdateTime(new Date());
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//改变采购单的状态
|
|
|
|
|
|
|
|
super.updateBatchById(collect);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//改变采购项的状态
|
|
|
|
|
|
|
|
collect.forEach(item -> {
|
|
|
|
|
|
|
|
List<PurchaseDetailEntity> entities = purchaseDetailService.listDetailByPurchaseId(item.getId());
|
|
|
|
|
|
|
|
List<PurchaseDetailEntity> PurchaseDetailEntityList = entities.stream().map(entity -> {
|
|
|
|
|
|
|
|
PurchaseDetailEntity purchaseDetailEntity = new PurchaseDetailEntity();
|
|
|
|
|
|
|
|
purchaseDetailEntity.setId(entity.getId());
|
|
|
|
|
|
|
|
purchaseDetailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode());
|
|
|
|
|
|
|
|
return purchaseDetailEntity;
|
|
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
purchaseDetailService.updateBatchById(PurchaseDetailEntityList);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|