|
|
|
@ -6,18 +6,30 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.dao.auth.SysWorkplaceDao;
|
|
|
|
|
import com.glxp.api.dao.collect.IoCollectOrderBizMapper;
|
|
|
|
|
import com.glxp.api.dao.collect.IoCollectOrderMapper;
|
|
|
|
|
import com.glxp.api.dao.inout.IoSplitFifoCodeMapper;
|
|
|
|
|
import com.glxp.api.entity.auth.SysWorkplace;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiRelevanceEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoSplitFifoCodeEntity;
|
|
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
|
|
import com.glxp.api.req.collect.CollectOrderBizRequest;
|
|
|
|
|
import com.glxp.api.req.collect.CollectOrderRequest;
|
|
|
|
|
import com.glxp.api.req.dev.DeviceChangeOrderParam;
|
|
|
|
|
import com.glxp.api.req.inout.IoSplitFifoCodeRequest;
|
|
|
|
|
import com.glxp.api.res.collect.CollectOrderBizResponse;
|
|
|
|
|
import com.glxp.api.res.collect.IoCollectOrderResponse;
|
|
|
|
|
import com.glxp.api.res.inout.IoSplitCodeResponse;
|
|
|
|
|
import com.glxp.api.service.auth.SysWorkplaceService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class IoSplitFifoCodeService extends ServiceImpl<IoSplitFifoCodeMapper, IoSplitFifoCodeEntity> {
|
|
|
|
@ -26,6 +38,10 @@ public class IoSplitFifoCodeService extends ServiceImpl<IoSplitFifoCodeMapper, I
|
|
|
|
|
IoSplitFifoCodeMapper splitFifoCodeMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
SysWorkplaceService sysWorkplaceService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderMapper collectOrderMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderBizMapper collectOrderBizMapper;
|
|
|
|
|
|
|
|
|
|
public List<IoSplitCodeResponse> filterGroupList(IoSplitFifoCodeRequest splitFifoCodeRequest) {
|
|
|
|
|
if (splitFifoCodeRequest == null) {
|
|
|
|
@ -103,19 +119,83 @@ public class IoSplitFifoCodeService extends ServiceImpl<IoSplitFifoCodeMapper, I
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 预分配库存 todo
|
|
|
|
|
* 预分配库存
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void preAllotInv(String workPaceCode) {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void preAllotInv(Long workPaceCode) {
|
|
|
|
|
if (workPaceCode == null || workPaceCode == 0l) return;
|
|
|
|
|
|
|
|
|
|
//1. 查询出当前工位的未分配的库存
|
|
|
|
|
|
|
|
|
|
IoSplitFifoCodeRequest splitFifoCodeRequest = new IoSplitFifoCodeRequest();
|
|
|
|
|
splitFifoCodeRequest.setWorkPlaceCode(workPaceCode);
|
|
|
|
|
List<IoSplitCodeResponse> ioSplitCodeResponses = this.baseMapper.filterGroupList(splitFifoCodeRequest);
|
|
|
|
|
if (CollUtil.isEmpty(ioSplitCodeResponses)) return;
|
|
|
|
|
Map<Long, List<IoSplitCodeResponse>> splitMap = ioSplitCodeResponses.stream().collect(Collectors.groupingBy(IoSplitCodeResponse::getRelId));
|
|
|
|
|
|
|
|
|
|
//2.遍历当前工位待处理的单据,根据orderTime排序
|
|
|
|
|
|
|
|
|
|
CollectOrderRequest collectOrderRequest = new CollectOrderRequest();
|
|
|
|
|
collectOrderRequest.setWorkPlaceCode(workPaceCode);
|
|
|
|
|
List<IoCollectOrderResponse> orderList = collectOrderMapper.filterList(collectOrderRequest);
|
|
|
|
|
if (CollUtil.isEmpty(orderList)) return;
|
|
|
|
|
|
|
|
|
|
//3.为每个单据底下的单据详情分配数量
|
|
|
|
|
for (int i = 0; i < orderList.size(); i++) {
|
|
|
|
|
IoCollectOrderResponse order = orderList.get(i);
|
|
|
|
|
CollectOrderBizRequest bizRequest = new CollectOrderBizRequest();
|
|
|
|
|
bizRequest.setOrderIdFk(String.valueOf(order.getId()));
|
|
|
|
|
List<CollectOrderBizResponse> bizList = collectOrderBizMapper.filterList(bizRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(bizList)){
|
|
|
|
|
//自动分配 工位存量、更新splitMap、更新 bizList上的 缺少存量数
|
|
|
|
|
autoAllocationWorkPace(splitMap,bizList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 自动分配 工位存量、更新splitMap、更新 bizList上的 缺少存量数
|
|
|
|
|
* @param splitMap
|
|
|
|
|
* @param bizList
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
void autoAllocationWorkPace(Map<Long, List<IoSplitCodeResponse>> splitMap, List<CollectOrderBizResponse> bizList) {
|
|
|
|
|
for (int i = 0; i < bizList.size(); i++) {
|
|
|
|
|
CollectOrderBizResponse collectOrderBizResponse = bizList.get(i);
|
|
|
|
|
Long relId = collectOrderBizResponse.getRelId();
|
|
|
|
|
String batchNo = collectOrderBizResponse.getBatchNo();
|
|
|
|
|
Integer count = collectOrderBizResponse.getCount(); //当前明细 需要的数量
|
|
|
|
|
Long bizId = collectOrderBizResponse.getId();
|
|
|
|
|
|
|
|
|
|
List<IoSplitCodeResponse> ioSplitCodeResponses = splitMap.get(relId);
|
|
|
|
|
List<IoSplitCodeResponse> newioSplitCodeResponses = new ArrayList<>(ioSplitCodeResponses.size());
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(ioSplitCodeResponses)){
|
|
|
|
|
for (int j = 0; j < ioSplitCodeResponses.size() ; j++) {
|
|
|
|
|
IoSplitCodeResponse ioSplit = ioSplitCodeResponses.get(j);
|
|
|
|
|
Integer totalCount = ioSplit.getTotalCount();
|
|
|
|
|
if ((StrUtil.isBlank(batchNo) || batchNo.equals(ioSplit.getBatchNo())) && count > 0 && totalCount >0){
|
|
|
|
|
Integer resCount = totalCount - count;//预分配后剩余 工位存量
|
|
|
|
|
if(resCount >= 0){//足够分配
|
|
|
|
|
count = 0;
|
|
|
|
|
ioSplit.setTotalCount(resCount);
|
|
|
|
|
}else {//不够分配
|
|
|
|
|
count = -resCount;
|
|
|
|
|
ioSplit.setTotalCount(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
newioSplitCodeResponses.add(ioSplit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
splitMap.put(relId,newioSplitCodeResponses);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count > 0){//不够分配
|
|
|
|
|
collectOrderBizMapper.updateAutoResCount(bizId,-count);
|
|
|
|
|
}else {
|
|
|
|
|
collectOrderBizMapper.updateAutoResCount(bizId,collectOrderBizResponse.getCount());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|