|
|
|
|
package com.glxp.api.service.inout;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
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 io.swagger.models.auth.In;
|
|
|
|
|
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> {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitFifoCodeMapper splitFifoCodeMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
SysWorkplaceService sysWorkplaceService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderMapper collectOrderMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderBizMapper collectOrderBizMapper;
|
|
|
|
|
|
|
|
|
|
public List<IoSplitCodeResponse> filterGroupList(IoSplitFifoCodeRequest splitFifoCodeRequest) {
|
|
|
|
|
if (splitFifoCodeRequest == null) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (splitFifoCodeRequest.getPage() != null) {
|
|
|
|
|
int offset = (splitFifoCodeRequest.getPage() - 1) * splitFifoCodeRequest.getLimit();
|
|
|
|
|
PageHelper.offsetPage(offset, splitFifoCodeRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
return super.baseMapper.filterGroupList(splitFifoCodeRequest);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<IoSplitCodeResponse> filterList(IoSplitFifoCodeRequest splitFifoCodeRequest) {
|
|
|
|
|
if (splitFifoCodeRequest == null) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (splitFifoCodeRequest.getPage() != null) {
|
|
|
|
|
int offset = (splitFifoCodeRequest.getPage() - 1) * splitFifoCodeRequest.getLimit();
|
|
|
|
|
PageHelper.offsetPage(offset, splitFifoCodeRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
return super.baseMapper.filterList(splitFifoCodeRequest);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean isExitCode(String code, Long workPlaceCode) {
|
|
|
|
|
return splitFifoCodeMapper.exists(
|
|
|
|
|
new LambdaQueryWrapper<IoSplitFifoCodeEntity>()
|
|
|
|
|
.eq(IoSplitFifoCodeEntity::getCode, code)
|
|
|
|
|
.eq(workPlaceCode != null, IoSplitFifoCodeEntity::getWorkPlaceCode, workPlaceCode)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IoSplitFifoCodeEntity findByCode(String code, Long workPlaceCode) {
|
|
|
|
|
return splitFifoCodeMapper.selectOne(
|
|
|
|
|
new LambdaQueryWrapper<IoSplitFifoCodeEntity>()
|
|
|
|
|
.eq(IoSplitFifoCodeEntity::getCode, code)
|
|
|
|
|
.eq(workPlaceCode != null, IoSplitFifoCodeEntity::getWorkPlaceCode, workPlaceCode)
|
|
|
|
|
.last("limit 1")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 库存量提醒
|
|
|
|
|
*
|
|
|
|
|
* @param workPlaceCode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String findInvRemind(Long workPlaceCode) {
|
|
|
|
|
final String[] msg = {"当前工位存量提醒:"};
|
|
|
|
|
SysWorkplace workplace = sysWorkplaceService.getWorkplace(workPlaceCode);
|
|
|
|
|
if (workplace == null) throw new JsonException("未找到匹配工位");
|
|
|
|
|
Integer invRemindNumber = workplace.getInvRemindNumber();
|
|
|
|
|
|
|
|
|
|
List<IoSplitCodeResponse> invReminds = splitFifoCodeMapper.findInvRemind(workPlaceCode);
|
|
|
|
|
if (CollUtil.isEmpty(invReminds)) {
|
|
|
|
|
return "当前工位存量提醒:" + "0";
|
|
|
|
|
}
|
|
|
|
|
invReminds.forEach(item -> {
|
|
|
|
|
Integer groupCount = item.getGroupCount();
|
|
|
|
|
if (groupCount < invRemindNumber) {
|
|
|
|
|
String cpmctymc = item.getCpmctymc();
|
|
|
|
|
String batchNo = item.getBatchNo();
|
|
|
|
|
if (StrUtil.isBlank(batchNo)) {
|
|
|
|
|
msg[0] = msg[0] + cpmctymc + "存量为:" + groupCount;
|
|
|
|
|
} else {
|
|
|
|
|
msg[0] = msg[0] + cpmctymc + "[" + batchNo + "]存量为:" + groupCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return msg[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 预分配库存
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@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);
|
|
|
|
|
collectOrderRequest.setTagStatus(1);
|
|
|
|
|
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上的 缺少存量数
|
|
|
|
|
Integer invAlert = autoAllocationWorkPace(splitMap, bizList);
|
|
|
|
|
collectOrderMapper.updateInvAlert(order.getId(),invAlert);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 自动分配 工位存量、更新splitMap、更新 bizList上的 缺少存量数
|
|
|
|
|
* @param splitMap
|
|
|
|
|
* @param bizList
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
Integer autoAllocationWorkPace(Map<Long, List<IoSplitCodeResponse>> splitMap, List<CollectOrderBizResponse> bizList) {
|
|
|
|
|
Integer invAlert = 1;
|
|
|
|
|
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);
|
|
|
|
|
invAlert = 2;
|
|
|
|
|
}else {
|
|
|
|
|
collectOrderBizMapper.updateAutoResCount(bizId,collectOrderBizResponse.getCount());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return invAlert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|