|
|
|
|
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.inout.IoSplitCodeMapper;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicSkPrescribeDiEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicSkPrescribeEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiRelevanceEntity;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrder;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderBiz;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderCodeAuto;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderCodeMan;
|
|
|
|
|
import com.glxp.api.entity.inout.IoSplitCodeEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoSplitFifoCodeEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoSplitFifoInv;
|
|
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
|
|
import com.glxp.api.req.inout.IoSplitCodeRequest;
|
|
|
|
|
import com.glxp.api.service.basic.BasicSkPrescribeDiService;
|
|
|
|
|
import com.glxp.api.service.basic.BasicSkPrescribeService;
|
|
|
|
|
import com.glxp.api.service.basic.UdiRelevanceService;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectOrderBizService;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectOrderCodeAutoService;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectOrderCodeManService;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectOrderService;
|
|
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class IoSplitCodeService extends ServiceImpl<IoSplitCodeMapper, IoSplitCodeEntity> {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
BasicSkPrescribeDiService basicSkPrescribeDiService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitCodeMapper splitCodeMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitFifoCodeService splitFifoCodeService;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicSkPrescribeService basicSkPrescribeService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderService collectOrderService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderBizService collectOrderBizService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderCodeAutoService collectOrderCodeAutoService;
|
|
|
|
|
|
|
|
|
|
public List<IoSplitCodeEntity> filterList(IoSplitCodeRequest splitCodeRequest) {
|
|
|
|
|
if (splitCodeRequest == null) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (splitCodeRequest.getPage() != null) {
|
|
|
|
|
int offset = (splitCodeRequest.getPage() - 1) * splitCodeRequest.getLimit();
|
|
|
|
|
PageHelper.offsetPage(offset, splitCodeRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
return super.baseMapper.filterList(splitCodeRequest);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<IoSplitCodeEntity> findSplitCodes(Long relId, String batchNo, Long workPlaceCode) {
|
|
|
|
|
List<IoSplitCodeEntity> ioSplitCodeEntities = splitCodeMapper.selectList(new LambdaQueryWrapper<IoSplitCodeEntity>()
|
|
|
|
|
.eq(IoSplitCodeEntity::getRelId, relId)
|
|
|
|
|
.eq(StrUtil.isNotEmpty(batchNo), IoSplitCodeEntity::getBatchNo, batchNo)
|
|
|
|
|
.eq(workPlaceCode != null, IoSplitCodeEntity::getWorkPlaceCode, workPlaceCode)
|
|
|
|
|
.in(IoSplitCodeEntity::getStatus, 1, 2).orderByAsc(IoSplitCodeEntity::getInBactchNo));
|
|
|
|
|
return ioSplitCodeEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IoSplitCodeEntity findByCode(String code, Long workPlaceCode, String busType) {
|
|
|
|
|
List<IoSplitCodeEntity> ioSplitCodeEntities = splitCodeMapper.selectList(new LambdaQueryWrapper<IoSplitCodeEntity>()
|
|
|
|
|
.eq(IoSplitCodeEntity::getCode, code)
|
|
|
|
|
.eq(workPlaceCode != null, IoSplitCodeEntity::getWorkPlaceCode, workPlaceCode)
|
|
|
|
|
.in(IoSplitCodeEntity::getStatus, 1, 2).orderByAsc(IoSplitCodeEntity::getInBactchNo));
|
|
|
|
|
if (CollUtil.isNotEmpty(ioSplitCodeEntities))
|
|
|
|
|
return ioSplitCodeEntities.get(0);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处方自动赋码
|
|
|
|
|
*/
|
|
|
|
|
public void prescribeAutoTagCode(BasicSkPrescribeEntity basicSkPrescribeEntity) {
|
|
|
|
|
|
|
|
|
|
List<BasicSkPrescribeDiEntity> basicSkPrescribeDiEntities = basicSkPrescribeDiService.findByPrescribe(basicSkPrescribeEntity.getAdNum());
|
|
|
|
|
//处方赋码状态 1:未赋码,2:部分赋码,3:全部赋码
|
|
|
|
|
for (BasicSkPrescribeDiEntity basicSkPrescribeDiEntity : basicSkPrescribeDiEntities) {
|
|
|
|
|
|
|
|
|
|
//1.按照先进先出原则,查询拆零表,获取拆零表ID
|
|
|
|
|
List<IoSplitCodeEntity> ioSplitCodeEntities = findSplitCodes(basicSkPrescribeDiEntity.getRelId(), basicSkPrescribeDiEntity.getBatchNo(), basicSkPrescribeEntity.getWorkPlaceCode());
|
|
|
|
|
|
|
|
|
|
//2.如果拆零表为空,则自动从预出库队列中获拉取数据
|
|
|
|
|
if (CollUtil.isEmpty(ioSplitCodeEntities)) {
|
|
|
|
|
addFifoCode(basicSkPrescribeDiEntity.getRelId(), basicSkPrescribeDiEntity.getBatchNo(), IntUtil.value(basicSkPrescribeDiEntity.getMeasureCount()));
|
|
|
|
|
}
|
|
|
|
|
ioSplitCodeEntities = findSplitCodes(basicSkPrescribeDiEntity.getRelId(), basicSkPrescribeDiEntity.getBatchNo(), basicSkPrescribeEntity.getWorkPlaceCode());
|
|
|
|
|
|
|
|
|
|
//3.如果拆零表不为空,则开始扣除数量
|
|
|
|
|
int count = 0;
|
|
|
|
|
int unCount = 0; //剩余未扣减数量
|
|
|
|
|
unCount = IntUtil.value(basicSkPrescribeDiEntity.getMeasureCount());
|
|
|
|
|
for (IoSplitCodeEntity ioSplitCodeEntity : ioSplitCodeEntities) {
|
|
|
|
|
count = IntUtil.value(ioSplitCodeEntity.getRemainCount()) - unCount;
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(count);
|
|
|
|
|
break;
|
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
} else {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = -count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unCount > 0) {
|
|
|
|
|
//4.拆零表数量不足,则从预出库队列中获取数据
|
|
|
|
|
Integer fifoCount = addFifoCode(basicSkPrescribeDiEntity.getRelId(), basicSkPrescribeDiEntity.getBatchNo(), unCount);
|
|
|
|
|
if (fifoCount == 0) {
|
|
|
|
|
//预出库队列数量不足
|
|
|
|
|
basicSkPrescribeDiEntity.setTagStatus(2);
|
|
|
|
|
basicSkPrescribeDiEntity.setTagMsg("预出库队列码数量不足,赋码失败!");
|
|
|
|
|
} else {
|
|
|
|
|
//再次执行赋码
|
|
|
|
|
ioSplitCodeEntities = findSplitCodes(basicSkPrescribeDiEntity.getRelId(), basicSkPrescribeDiEntity.getBatchNo(), basicSkPrescribeEntity.getWorkPlaceCode());
|
|
|
|
|
for (IoSplitCodeEntity ioSplitCodeEntity : ioSplitCodeEntities) {
|
|
|
|
|
count = IntUtil.value(ioSplitCodeEntity.getRemainCount()) - unCount;
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(count);
|
|
|
|
|
break;
|
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
} else {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = -count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (unCount > 0) {
|
|
|
|
|
basicSkPrescribeDiEntity.setTagStatus(2);
|
|
|
|
|
basicSkPrescribeDiEntity.setTagMsg("预出库队列码数量不足,赋码失败!");
|
|
|
|
|
} else {
|
|
|
|
|
basicSkPrescribeDiEntity.setTagStatus(3);
|
|
|
|
|
basicSkPrescribeDiEntity.setTagMsg("赋码完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
basicSkPrescribeDiService.updateById(basicSkPrescribeDiEntity);
|
|
|
|
|
}
|
|
|
|
|
basicSkPrescribeEntity.setTagStatus(checkStatus1(basicSkPrescribeDiEntities));
|
|
|
|
|
basicSkPrescribeService.updateById(basicSkPrescribeEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 单据自动赋码
|
|
|
|
|
*/
|
|
|
|
|
public void orderAutoTagCode(IoCollectOrder collectOrder) {
|
|
|
|
|
|
|
|
|
|
List<IoCollectOrderBiz> collectOrderBizs = collectOrderBizService.listByBillNo(collectOrder.getBillNo());
|
|
|
|
|
//处方赋码状态 1:未赋码,2:部分赋码,3:全部赋码
|
|
|
|
|
for (IoCollectOrderBiz collectOrderBiz : collectOrderBizs) {
|
|
|
|
|
if (IntUtil.value(collectOrderBiz.getTagStatus()) == 3) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//1.按照先进先出原则,查询拆零表,获取拆零表ID
|
|
|
|
|
List<IoSplitCodeEntity> ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
|
|
|
|
|
//2.如果拆零表为空,则自动从预出库队列中获拉取数据
|
|
|
|
|
if (CollUtil.isEmpty(ioSplitCodeEntities)) {
|
|
|
|
|
addFifoCode(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), IntUtil.value(collectOrderBiz.getCount()));
|
|
|
|
|
ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
}
|
|
|
|
|
//3.如果拆零表不为空,则开始扣除数量
|
|
|
|
|
int count = 0;
|
|
|
|
|
int unCount = 0; //剩余未扣减数量
|
|
|
|
|
unCount = IntUtil.value(collectOrderBiz.getUnTagCount());
|
|
|
|
|
for (IoSplitCodeEntity ioSplitCodeEntity : ioSplitCodeEntities) {
|
|
|
|
|
count = IntUtil.value(ioSplitCodeEntity.getRemainCount()) - unCount;
|
|
|
|
|
collectOrderCodeAutoService.save(IoCollectOrderCodeAuto.builder()
|
|
|
|
|
.codeIdFk(ioSplitCodeEntity.getId())
|
|
|
|
|
.udiCode(ioSplitCodeEntity.getCode())
|
|
|
|
|
.orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.batchNo(ioSplitCodeEntity.getBatchNo())
|
|
|
|
|
.productDate(ioSplitCodeEntity.getProduceDate())
|
|
|
|
|
.expireDate(ioSplitCodeEntity.getExpireDate())
|
|
|
|
|
.serialNo(ioSplitCodeEntity.getSerialNo())
|
|
|
|
|
.relId(collectOrderBiz.getRelId())
|
|
|
|
|
.bizIdFk(collectOrderBiz.getId())
|
|
|
|
|
.fifoSplit(ioSplitCodeEntity.getFifoSplit())
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build());
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(count);
|
|
|
|
|
unCount = 0;
|
|
|
|
|
splitCodeMapper.updateById(ioSplitCodeEntity);
|
|
|
|
|
break;
|
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = 0;
|
|
|
|
|
} else {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = -count;
|
|
|
|
|
}
|
|
|
|
|
splitCodeMapper.updateById(ioSplitCodeEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unCount > 0) {
|
|
|
|
|
//4.拆零表数量不足,则从预出库队列中获取数据
|
|
|
|
|
Integer fifoCount = addFifoCode(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), unCount);
|
|
|
|
|
if (fifoCount == 0) {
|
|
|
|
|
//预出库队列数量不足
|
|
|
|
|
collectOrderBiz.setTagStatus(2);
|
|
|
|
|
collectOrderBiz.setTagMsg("预出库队列码数量不足,赋码失败!");
|
|
|
|
|
} else {
|
|
|
|
|
//再次执行赋码
|
|
|
|
|
ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
for (IoSplitCodeEntity ioSplitCodeEntity : ioSplitCodeEntities) {
|
|
|
|
|
count = IntUtil.value(ioSplitCodeEntity.getRemainCount()) - unCount;
|
|
|
|
|
collectOrderCodeAutoService.save(IoCollectOrderCodeAuto.builder()
|
|
|
|
|
.codeIdFk(ioSplitCodeEntity.getId())
|
|
|
|
|
.udiCode(ioSplitCodeEntity.getCode())
|
|
|
|
|
.orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.batchNo(ioSplitCodeEntity.getBatchNo())
|
|
|
|
|
.productDate(ioSplitCodeEntity.getProduceDate())
|
|
|
|
|
.expireDate(ioSplitCodeEntity.getExpireDate())
|
|
|
|
|
.serialNo(ioSplitCodeEntity.getSerialNo())
|
|
|
|
|
.relId(collectOrderBiz.getRelId())
|
|
|
|
|
.bizIdFk(collectOrderBiz.getId())
|
|
|
|
|
.fifoSplit(ioSplitCodeEntity.getFifoSplit())
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build());
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(count);
|
|
|
|
|
break;
|
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
} else {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = -count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (unCount > 0) {
|
|
|
|
|
collectOrderBiz.setTagStatus(2);
|
|
|
|
|
collectOrderBiz.setTagMsg("预出库队列码数量不足,赋码失败!");
|
|
|
|
|
} else {
|
|
|
|
|
collectOrderBiz.setTagStatus(3);
|
|
|
|
|
collectOrderBiz.setTagMsg("赋码完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
collectOrderBiz.setTagStatus(3);
|
|
|
|
|
collectOrderBiz.setTagMsg("赋码完成!");
|
|
|
|
|
}
|
|
|
|
|
collectOrderBiz.setUnTagCount(unCount);
|
|
|
|
|
collectOrderBizService.updateById(collectOrderBiz);
|
|
|
|
|
}
|
|
|
|
|
collectOrder.setSplitStatus(checkStatus(collectOrderBizs));
|
|
|
|
|
collectOrderService.updateById(collectOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void splitRemove(IoCollectOrderBiz collectOrderBiz, IoCollectOrder collectOrder) {
|
|
|
|
|
//1.按照先进先出原则,查询拆零表,获取拆零表ID
|
|
|
|
|
List<IoSplitCodeEntity> ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
|
|
|
|
|
//2.如果拆零表为空,则自动从预出库队列中获拉取数据
|
|
|
|
|
if (CollUtil.isEmpty(ioSplitCodeEntities)) {
|
|
|
|
|
addFifoCode(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), IntUtil.value(collectOrderBiz.getCount()));
|
|
|
|
|
ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
}
|
|
|
|
|
//3.如果拆零表不为空,则开始扣除数量
|
|
|
|
|
int count = 0;
|
|
|
|
|
int unCount = 0; //剩余未扣减数量
|
|
|
|
|
unCount = IntUtil.value(collectOrderBiz.getUnTagCount());
|
|
|
|
|
for (IoSplitCodeEntity ioSplitCodeEntity : ioSplitCodeEntities) {
|
|
|
|
|
count = IntUtil.value(ioSplitCodeEntity.getRemainCount()) - unCount;
|
|
|
|
|
collectOrderCodeAutoService.save(IoCollectOrderCodeAuto.builder()
|
|
|
|
|
.codeIdFk(ioSplitCodeEntity.getId())
|
|
|
|
|
.udiCode(ioSplitCodeEntity.getCode())
|
|
|
|
|
.orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.batchNo(ioSplitCodeEntity.getBatchNo())
|
|
|
|
|
.productDate(ioSplitCodeEntity.getProduceDate())
|
|
|
|
|
.expireDate(ioSplitCodeEntity.getExpireDate())
|
|
|
|
|
.serialNo(ioSplitCodeEntity.getSerialNo())
|
|
|
|
|
.relId(collectOrderBiz.getRelId())
|
|
|
|
|
.bizIdFk(collectOrderBiz.getId())
|
|
|
|
|
.fifoSplit(ioSplitCodeEntity.getFifoSplit())
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build());
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(count);
|
|
|
|
|
unCount = 0;
|
|
|
|
|
splitCodeMapper.updateById(ioSplitCodeEntity);
|
|
|
|
|
break;
|
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = 0;
|
|
|
|
|
} else {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = -count;
|
|
|
|
|
}
|
|
|
|
|
splitCodeMapper.updateById(ioSplitCodeEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unCount > 0) {
|
|
|
|
|
//4.拆零表数量不足,则从预出库队列中获取数据
|
|
|
|
|
Integer fifoCount = addFifoCode(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), unCount);
|
|
|
|
|
if (fifoCount == 0) {
|
|
|
|
|
//预出库队列数量不足
|
|
|
|
|
collectOrderBiz.setTagStatus(2);
|
|
|
|
|
collectOrderBiz.setTagMsg("预出库队列码数量不足,赋码失败!");
|
|
|
|
|
throw new JsonException(500, "提交失败,工位库存数量不足!");
|
|
|
|
|
} else {
|
|
|
|
|
//再次执行赋码
|
|
|
|
|
ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
for (IoSplitCodeEntity ioSplitCodeEntity : ioSplitCodeEntities) {
|
|
|
|
|
count = IntUtil.value(ioSplitCodeEntity.getRemainCount()) - unCount;
|
|
|
|
|
collectOrderCodeAutoService.save(IoCollectOrderCodeAuto.builder()
|
|
|
|
|
.codeIdFk(ioSplitCodeEntity.getId())
|
|
|
|
|
.udiCode(ioSplitCodeEntity.getCode())
|
|
|
|
|
.orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.batchNo(ioSplitCodeEntity.getBatchNo())
|
|
|
|
|
.productDate(ioSplitCodeEntity.getProduceDate())
|
|
|
|
|
.expireDate(ioSplitCodeEntity.getExpireDate())
|
|
|
|
|
.serialNo(ioSplitCodeEntity.getSerialNo())
|
|
|
|
|
.relId(collectOrderBiz.getRelId())
|
|
|
|
|
.bizIdFk(collectOrderBiz.getId())
|
|
|
|
|
.fifoSplit(ioSplitCodeEntity.getFifoSplit())
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build());
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(count);
|
|
|
|
|
break;
|
|
|
|
|
} else if (count == 0) {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
} else {
|
|
|
|
|
ioSplitCodeEntity.setRemainCount(0);
|
|
|
|
|
unCount = -count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (unCount > 0) {
|
|
|
|
|
collectOrderBiz.setTagStatus(2);
|
|
|
|
|
collectOrderBiz.setTagMsg("预出库队列码数量不足,赋码失败!");
|
|
|
|
|
throw new JsonException(500, "提交失败,工位库存数量不足!");
|
|
|
|
|
} else {
|
|
|
|
|
collectOrderBiz.setTagStatus(3);
|
|
|
|
|
collectOrderBiz.setTagMsg("赋码完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
collectOrderBiz.setTagStatus(3);
|
|
|
|
|
collectOrderBiz.setTagMsg("赋码完成!");
|
|
|
|
|
}
|
|
|
|
|
collectOrderBiz.setUnTagCount(unCount);
|
|
|
|
|
collectOrderBizService.updateById(collectOrderBiz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
UdiRelevanceService udiRelevanceService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderCodeManService collectOrderCodeManService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitCodeService splitCodeService;
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void finishAutoTagCode(IoCollectOrder collectOrder) {
|
|
|
|
|
List<IoCollectOrderBiz> collectOrderBizs = collectOrderBizService.listByBillNo(collectOrder.getBillNo());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果手动扫码判断该码是否在队列里,如果已在队列,则队列里剔除
|
|
|
|
|
List<IoCollectOrderCodeMan> collectOrderCodeMEN = collectOrderCodeManService.listByBillNo(collectOrder.getBillNo());
|
|
|
|
|
if (CollUtil.isNotEmpty(collectOrderCodeMEN)) {
|
|
|
|
|
for (IoCollectOrderCodeMan collectOrderCodeMan : collectOrderCodeMEN) {
|
|
|
|
|
IoSplitFifoCodeEntity splitFifoCodeEntity = splitFifoCodeService.findByCode(collectOrderCodeMan.getUdiCode(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
if (splitFifoCodeEntity != null) {
|
|
|
|
|
collectOrderCodeMan.setRemoveFlag(true);
|
|
|
|
|
if (IntUtil.value(splitFifoCodeEntity.getScanCount()) - IntUtil.value(collectOrderCodeMan.getScanCount()) <= 0) {
|
|
|
|
|
splitFifoCodeService.removeById(splitFifoCodeEntity.getId());
|
|
|
|
|
IoSplitFifoInv splitFifoInv = splitFifoInvService.findByFifoCode(splitFifoCodeEntity);
|
|
|
|
|
if (splitFifoInv != null) {
|
|
|
|
|
splitFifoInv.setOutCount(IntUtil.value(splitFifoInv.getOutCount()) + IntUtil.value(splitFifoCodeEntity.getTotalCount()));
|
|
|
|
|
int lockCount = IntUtil.value(splitFifoInv.getLockCount()) - IntUtil.value(splitFifoCodeEntity.getTotalCount());
|
|
|
|
|
splitFifoInv.setLockCount(lockCount > 0 ? lockCount : 0);
|
|
|
|
|
splitFifoInv.setReCount(IntUtil.value(splitFifoInv.getInCount()) - IntUtil.value(splitFifoInv.getOutCount()));
|
|
|
|
|
splitFifoInv.setAvailableCount(IntUtil.value(splitFifoInv.getInCount()) - IntUtil.value(splitFifoInv.getLockCount()) - IntUtil.value(splitFifoInv.getOutCount()));
|
|
|
|
|
splitFifoInvService.updateById(splitFifoInv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//队列码数量大于扫码数量更新数量(一般指无序列号)
|
|
|
|
|
UdiRelevanceEntity udiRelevanceEntity = udiRelevanceService.selectById(collectOrderCodeMan.getRelId());
|
|
|
|
|
int removeCount = IntUtil.value(collectOrderCodeMan.getScanCount()) * udiRelevanceEntity.getUseLeverCount();
|
|
|
|
|
splitFifoCodeService.updateById(IoSplitFifoCodeEntity.builder()
|
|
|
|
|
.id(splitFifoCodeEntity.getId())
|
|
|
|
|
.scanCount(IntUtil.value(splitFifoCodeEntity.getScanCount()) - IntUtil.value(collectOrderCodeMan.getScanCount()))
|
|
|
|
|
.totalCount(IntUtil.value(splitFifoCodeEntity.getTotalCount()) - removeCount)
|
|
|
|
|
.build());
|
|
|
|
|
|
|
|
|
|
IoSplitFifoInv splitFifoInv = splitFifoInvService.findByFifoCode(splitFifoCodeEntity);
|
|
|
|
|
if (splitFifoInv != null) {
|
|
|
|
|
splitFifoInv.setOutCount(IntUtil.value(splitFifoInv.getOutCount()) + removeCount);
|
|
|
|
|
splitFifoInv.setLockCount(IntUtil.value(splitFifoInv.getLockCount()) - removeCount);
|
|
|
|
|
splitFifoInv.setReCount(IntUtil.value(splitFifoInv.getInCount()) - IntUtil.value(splitFifoInv.getOutCount()));
|
|
|
|
|
splitFifoInv.setAvailableCount(IntUtil.value(splitFifoInv.getInCount()) - IntUtil.value(splitFifoInv.getLockCount()) - IntUtil.value(splitFifoInv.getOutCount()));
|
|
|
|
|
splitFifoInvService.updateById(splitFifoInv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<Integer> removeIds = new ArrayList<>();
|
|
|
|
|
for (IoCollectOrderBiz collectOrderBiz : collectOrderBizs) {
|
|
|
|
|
UdiRelevanceEntity udiRelevanceEntity = udiRelevanceService.selectById(collectOrderBiz.getRelId());
|
|
|
|
|
//去除掉已经手动扫码的数据,找出需要自动扫码的明细,执行上述的拆零或整取
|
|
|
|
|
int unTagCount = collectOrderBiz.getCount() - IntUtil.value(collectOrderBiz.getScanActCount());
|
|
|
|
|
if (unTagCount > 0) {
|
|
|
|
|
collectOrderBiz.setUnTagCount(unTagCount);
|
|
|
|
|
} else {
|
|
|
|
|
collectOrderBiz.setTagStatus(3);
|
|
|
|
|
//手动扫码时涉及到拆零时,把拆零剩余数量插入至拆零表里
|
|
|
|
|
if (unTagCount < 0) {
|
|
|
|
|
if (IntUtil.value(udiRelevanceEntity.getUseLeverCount()) > -unTagCount) {
|
|
|
|
|
|
|
|
|
|
Optional<IoCollectOrderCodeMan> firstMatch = collectOrderCodeMEN.stream()
|
|
|
|
|
.filter(item -> IntUtil.value(item.getRemoveFlag()))
|
|
|
|
|
.findFirst();
|
|
|
|
|
if (firstMatch.isPresent()) {
|
|
|
|
|
IoCollectOrderCodeMan result = firstMatch.get();
|
|
|
|
|
IoSplitCodeEntity ioSplitCodeEntity = IoSplitCodeEntity.builder().code(result.getUdiCode())
|
|
|
|
|
.errUdiCode(result.getUdiCode())
|
|
|
|
|
.orderId(result.getOrderIdFk())
|
|
|
|
|
.action(collectOrder.getBusType())
|
|
|
|
|
.relId(result.getRelId())
|
|
|
|
|
.nameCode(result.getNameCode())
|
|
|
|
|
.batchNo(result.getBatchNo())
|
|
|
|
|
.produceDate(result.getProductDate())
|
|
|
|
|
.expireDate(result.getExpireDate())
|
|
|
|
|
.serialNo(result.getSerialNo())
|
|
|
|
|
.scanCount(result.getScanCount())
|
|
|
|
|
.totalCount(result.getScanCount())
|
|
|
|
|
.workPlaceCode(collectOrder.getWorkPlaceCode())
|
|
|
|
|
.status(2)
|
|
|
|
|
.fifoSplit(1)
|
|
|
|
|
.createTime(new Date()).updateTime(new Date())
|
|
|
|
|
.remainCount(-unTagCount).build();
|
|
|
|
|
splitCodeService.save(ioSplitCodeEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int quotient = collectOrderBiz.getUnTagCount() / IntUtil.value(udiRelevanceEntity.getUseLeverCount());
|
|
|
|
|
int remainder = collectOrderBiz.getUnTagCount() % IntUtil.value(udiRelevanceEntity.getUseLeverCount());
|
|
|
|
|
//2.如果整盒,从工位队列扣除
|
|
|
|
|
if (quotient > 0) {
|
|
|
|
|
List<IoSplitFifoCodeEntity> ioSplitFifoCodeEntities = splitFifoCodeService.findByRelId(collectOrder.getWorkPlaceCode(), collectOrder.getBusType(), collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo());
|
|
|
|
|
if (ioSplitFifoCodeEntities.size() < quotient) {
|
|
|
|
|
throw new JsonException(500, "提交失败,工位库存数量不足!");
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < quotient; i++) {
|
|
|
|
|
IoSplitFifoCodeEntity splitFifoCodeEntity = ioSplitFifoCodeEntities.get(i);
|
|
|
|
|
removeIds.add(splitFifoCodeEntity.getId());
|
|
|
|
|
collectOrderBiz.setUnTagCount(IntUtil.value(collectOrderBiz.getUnTagCount()) - IntUtil.value(udiRelevanceEntity.getUseLeverCount()));
|
|
|
|
|
collectOrderCodeAutoService.save(IoCollectOrderCodeAuto.builder()
|
|
|
|
|
.codeIdFk(splitFifoCodeEntity.getId())
|
|
|
|
|
.udiCode(splitFifoCodeEntity.getCode())
|
|
|
|
|
.orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.batchNo(splitFifoCodeEntity.getBatchNo())
|
|
|
|
|
.productDate(splitFifoCodeEntity.getProduceDate())
|
|
|
|
|
.expireDate(splitFifoCodeEntity.getExpireDate())
|
|
|
|
|
.serialNo(splitFifoCodeEntity.getSerialNo())
|
|
|
|
|
.relId(collectOrderBiz.getRelId())
|
|
|
|
|
.bizIdFk(collectOrderBiz.getId())
|
|
|
|
|
.fifoSplit(splitFifoCodeEntity.getFifoSplit())
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//.如果拆零,拆零表扣除
|
|
|
|
|
if (remainder > 0) {
|
|
|
|
|
splitRemove(collectOrderBiz, collectOrder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 单据预赋码
|
|
|
|
|
*
|
|
|
|
|
* @param collectOrder
|
|
|
|
|
*/
|
|
|
|
|
public void preAutoTagCode(IoCollectOrder collectOrder) {
|
|
|
|
|
List<IoCollectOrderBiz> collectOrderBizs = collectOrderBizService.listByBillNo(collectOrder.getBillNo());
|
|
|
|
|
for (IoCollectOrderBiz collectOrderBiz : collectOrderBizs) {
|
|
|
|
|
List<IoSplitFifoCodeEntity> splitFifoCodeEntities =
|
|
|
|
|
splitFifoCodeService.findByRelId(collectOrder.getWorkPlaceCode(), collectOrder.getBusType(),
|
|
|
|
|
collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo());
|
|
|
|
|
int total = splitFifoCodeEntities.stream()
|
|
|
|
|
.mapToInt(IoSplitFifoCodeEntity::getTotalCount)
|
|
|
|
|
.sum();
|
|
|
|
|
|
|
|
|
|
List<IoSplitCodeEntity> splitCodeEntities = splitCodeService.findSplitCodes(collectOrderBiz.getRelId()
|
|
|
|
|
, collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
int splitTotal = splitCodeEntities.stream()
|
|
|
|
|
.mapToInt(IoSplitCodeEntity::getRemainCount)
|
|
|
|
|
.sum();
|
|
|
|
|
total = total + splitTotal;
|
|
|
|
|
if (total >= IntUtil.value(collectOrderBiz.getCount())) {
|
|
|
|
|
collectOrderBiz.setAutoTagStatus(2);
|
|
|
|
|
} else if (total > 0) {
|
|
|
|
|
collectOrderBiz.setAutoTagStatus(3);
|
|
|
|
|
} else
|
|
|
|
|
collectOrderBiz.setAutoTagStatus(1);
|
|
|
|
|
}
|
|
|
|
|
collectOrderBizService.updateBatchById(collectOrderBizs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 拆零单据撤回,则将拆零表剩余数量加回预出库队列
|
|
|
|
|
*
|
|
|
|
|
* @param collectOrder
|
|
|
|
|
*/
|
|
|
|
|
public void backSplit(IoCollectOrder collectOrder) {
|
|
|
|
|
List<IoCollectOrderBiz> collectOrderBizs = collectOrderBizService.listByBillNo(collectOrder.getBillNo());
|
|
|
|
|
for (IoCollectOrderBiz collectOrderBiz : collectOrderBizs) {
|
|
|
|
|
List<IoSplitCodeEntity> ioSplitCodeEntities = findSplitCodes(collectOrderBiz.getRelId(), collectOrderBiz.getBatchNo(), collectOrder.getWorkPlaceCode());
|
|
|
|
|
if (CollUtil.isNotEmpty(ioSplitCodeEntities)) {
|
|
|
|
|
IoSplitCodeEntity splitCodeEntity = ioSplitCodeEntities.get(0);
|
|
|
|
|
splitCodeEntity.setRemainCount(IntUtil.value(splitCodeEntity.getRemainCount()) + (IntUtil.value(collectOrderBiz.getCount()) - IntUtil.value(collectOrderBiz.getUnTagCount())));
|
|
|
|
|
splitCodeMapper.updateById(splitCodeEntity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitFifoInvService splitFifoInvService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从预出库队列里面取出数据,添加至拆零表
|
|
|
|
|
*/
|
|
|
|
|
public Integer addFifoCode(Long relId, String batchNo, Integer needCount) {
|
|
|
|
|
|
|
|
|
|
List<IoSplitFifoCodeEntity> splitFifoCodeEntities = splitFifoCodeService
|
|
|
|
|
.list(new LambdaQueryWrapper<IoSplitFifoCodeEntity>()
|
|
|
|
|
.eq(IoSplitFifoCodeEntity::getRelId, relId)
|
|
|
|
|
.eq(StrUtil.isNotEmpty(batchNo), IoSplitFifoCodeEntity::getBatchNo, batchNo)
|
|
|
|
|
.orderByAsc(IoSplitFifoCodeEntity::getInBactchNo)
|
|
|
|
|
);
|
|
|
|
|
Integer count = 0;
|
|
|
|
|
List<IoSplitCodeEntity> addSplitCodeEntities = new ArrayList<>();
|
|
|
|
|
List<Integer> removeIds = new ArrayList<>();
|
|
|
|
|
for (IoSplitFifoCodeEntity splitFifoCodeEntity : splitFifoCodeEntities) {
|
|
|
|
|
IoSplitCodeEntity splitCodeEntity = new IoSplitCodeEntity();
|
|
|
|
|
BeanUtils.copyProperties(splitFifoCodeEntity, splitCodeEntity);
|
|
|
|
|
if (IntUtil.value(splitFifoCodeEntity.getFifoSplit()) == 1) {
|
|
|
|
|
//拆零
|
|
|
|
|
count = IntUtil.value(splitFifoCodeEntity.getTotalCount()) + count;
|
|
|
|
|
splitCodeEntity.setRemainCount(splitCodeEntity.getTotalCount());
|
|
|
|
|
} else {
|
|
|
|
|
//整取
|
|
|
|
|
count = IntUtil.value(splitFifoCodeEntity.getScanCount()) + count;
|
|
|
|
|
splitCodeEntity.setRemainCount(splitCodeEntity.getScanCount());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
splitCodeEntity.setStatus(1);
|
|
|
|
|
splitCodeEntity.setFifoSplit(splitFifoCodeEntity.getFifoSplit());
|
|
|
|
|
splitCodeEntity.setId(null);
|
|
|
|
|
addSplitCodeEntities.add(splitCodeEntity);
|
|
|
|
|
removeIds.add(splitFifoCodeEntity.getId());
|
|
|
|
|
IoSplitFifoInv splitFifoInv = splitFifoInvService.findByFifoCode(splitFifoCodeEntity);
|
|
|
|
|
if (splitFifoInv != null) {
|
|
|
|
|
splitFifoInv.setOutCount(IntUtil.value(splitFifoInv.getOutCount()) + IntUtil.value(splitCodeEntity.getTotalCount()));
|
|
|
|
|
splitFifoInv.setLockCount(IntUtil.value(splitFifoInv.getLockCount()) - IntUtil.value(splitCodeEntity.getTotalCount()));
|
|
|
|
|
splitFifoInv.setReCount(IntUtil.value(splitFifoInv.getInCount() - IntUtil.value(splitFifoInv.getOutCount())));
|
|
|
|
|
splitFifoInv.setAvailableCount(IntUtil.value(splitFifoInv.getInCount() - IntUtil.value(splitFifoInv.getLockCount()) - IntUtil.value(splitFifoInv.getOutCount())));
|
|
|
|
|
splitFifoInvService.updateById(splitFifoInv);
|
|
|
|
|
}
|
|
|
|
|
if (count >= needCount) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (removeIds.size() > 0) {
|
|
|
|
|
splitFifoCodeService.removeByIds(removeIds);
|
|
|
|
|
}
|
|
|
|
|
if (addSplitCodeEntities.size() > 0) {
|
|
|
|
|
splitCodeMapper.insertBatch(addSplitCodeEntities);
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int checkStatus1(List<BasicSkPrescribeDiEntity> list) {
|
|
|
|
|
boolean hasTwo = false;
|
|
|
|
|
boolean hasOne = false;
|
|
|
|
|
for (BasicSkPrescribeDiEntity di : list) {
|
|
|
|
|
int tagStatus = di.getTagStatus();
|
|
|
|
|
if (tagStatus == 2) {
|
|
|
|
|
hasTwo = true;
|
|
|
|
|
} else if (tagStatus == 1) {
|
|
|
|
|
hasOne = true;
|
|
|
|
|
} else if (tagStatus != 3) {
|
|
|
|
|
throw new IllegalArgumentException("Invalid tagStatus value: " + tagStatus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasTwo) {
|
|
|
|
|
return 2;
|
|
|
|
|
} else if (hasOne) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int checkStatus(List<IoCollectOrderBiz> list) {
|
|
|
|
|
boolean hasTwo = false;
|
|
|
|
|
boolean hasOne = false;
|
|
|
|
|
boolean hasNone = true;
|
|
|
|
|
for (IoCollectOrderBiz di : list) {
|
|
|
|
|
int tagStatus = di.getTagStatus();
|
|
|
|
|
if (tagStatus == 2) {
|
|
|
|
|
hasTwo = true;
|
|
|
|
|
} else if (tagStatus == 1) {
|
|
|
|
|
hasOne = true;
|
|
|
|
|
} else if (tagStatus != 3) {
|
|
|
|
|
throw new IllegalArgumentException("Invalid tagStatus value: " + tagStatus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (IoCollectOrderBiz di : list) {
|
|
|
|
|
if (IntUtil.value(di.getCount()) != IntUtil.value(di.getUnTagCount())) {
|
|
|
|
|
hasNone = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasNone) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (hasTwo) {
|
|
|
|
|
return 2;
|
|
|
|
|
} else if (hasOne) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|