1.完善添加设备领用详情接口逻辑

feature-order-fix
x_z 2 years ago
parent f10b0f29c1
commit 526bb57f63

@ -3,11 +3,14 @@ package com.glxp.api.admin.service.inventory.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.glxp.api.admin.constant.ConstantType;
import com.glxp.api.admin.dao.inventory.DeviceCollectOrderDetailDao;
import com.glxp.api.admin.dao.inventory.InvProductDao;
import com.glxp.api.admin.dao.inventory.InvProductDetailDao;
import com.glxp.api.admin.entity.basic.UdiEntity;
import com.glxp.api.admin.entity.inventory.DeviceCollectOrderDetailEntity;
import com.glxp.api.admin.entity.inventory.InvProductDetailEntity;
import com.glxp.api.admin.entity.inventory.InvProductEntity;
import com.glxp.api.admin.req.inventory.AddDeviceCollectOrderDetailRequest;
import com.glxp.api.admin.req.inventory.FilterDeviceCollectOrderDetailRequest;
import com.glxp.api.admin.req.inventory.FilterInvProductDetailRequest;
@ -24,7 +27,10 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -35,6 +41,8 @@ public class DeviceCollectOrderDetailServiceImpl implements DeviceCollectOrderDe
private DeviceCollectOrderDetailDao deviceCollectOrderDetailDao;
@Resource
private InvProductDetailDao invProductDetailDao;
@Resource
private InvProductDao invProductDao;
@Override
public List<DeviceCollectOrderDetailResponse> filterList(FilterDeviceCollectOrderDetailRequest detailRequest) {
@ -57,50 +65,115 @@ public class DeviceCollectOrderDetailServiceImpl implements DeviceCollectOrderDe
}
if (StrUtil.isNotBlank(addDetailRequest.getCode())) {
//通过条码添加
//设置库存详情查询参数
FilterInvProductDetailRequest invProductDetailRequest = new FilterInvProductDetailRequest();
invProductDetailRequest.setCode(addDetailRequest.getCode());
//判断是否有选入的仓库信息,如果没有,说明此条码仅存在一条仓库信息,直接使用即可
if (StrUtil.isNotBlank(addDetailRequest.getInvStorageCode())) {
invProductDetailRequest.setInvStorageCode(addDetailRequest.getInvStorageCode());
invProductDetailRequest.setInvWarehouseCode(addDetailRequest.getInvWarehouseCode());
invProductDetailRequest.setInvSpaceCode(addDetailRequest.getInvSpaceCode());
invProductDetailRequest.setInvStorageCode(addDetailRequest.getInvStorageCode());
invProductDetailRequest.setInvWarehouseCode(addDetailRequest.getInvWarehouseCode());
invProductDetailRequest.setInvSpaceCode(addDetailRequest.getInvSpaceCode());
}
//查询库存详情
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(invProductDetailRequest);
InvProductDetailEntity invProductDetailEntity = invProductDetailEntities.get(0);
//解析条码
UdiEntity udi = FilterUdiUtils.getUdi(addDetailRequest.getCode());
//构造设备领用详情参数
DeviceCollectOrderDetailEntity orderDetail = new DeviceCollectOrderDetailEntity();
orderDetail.setOrderIdFk(addDetailRequest.getOrderIdFk());
orderDetail.setOriginCode(addDetailRequest.getCode());
orderDetail.setInvStorageCode(invProductDetailEntity.getInvStorageCode());
orderDetail.setInvWarehouseCode(invProductDetailRequest.getInvWarehouseCode());
orderDetail.setInvSpaceCode(invProductDetailRequest.getInvSpaceCode());
orderDetail.setProductId(invProductDetailEntity.getProductIdFk());
orderDetail.setBatchNo(udi.getBatchNo());
orderDetail.setProduceDate(udi.getProduceDate());
orderDetail.setExpireDate(udi.getExpireDate());
//判断此条码有无序列号,如果有序列号,则直接使用此条码当做此设备的唯一码,没有则留空唯一码,待后续提交审核时再生成
if (StrUtil.isNotBlank(udi.getSerialNo())) {
orderDetail.setSerialNo(udi.getSerialNo());
orderDetail.setCode(addDetailRequest.getCode());
}
orderDetail.setUpdateTime(DateUtil.getDateTime());
DeviceCollectOrderDetailEntity orderDetail = getDeviceCollectOrderDetailEntity(addDetailRequest.getOrderIdFk(), addDetailRequest.getCode(), invProductDetailEntity);
deviceCollectOrderDetailDao.insert(orderDetail);
} else {
//通过选库存添加
//查询选中的库存信息
for (String invProductId : addDetailRequest.getInvProductIds()) {
InvProductEntity invProductEntity = invProductDao.selectById(invProductId);
//查询库存详情
FilterInvProductDetailRequest filterInvProductDetailRequest = new FilterInvProductDetailRequest();
filterInvProductDetailRequest.setProductIdFk(invProductEntity.getRelIdFk());
filterInvProductDetailRequest.setBatchNo(invProductEntity.getBatchNo());
filterInvProductDetailRequest.setInvStorageCode(invProductEntity.getInvStorageCode());
filterInvProductDetailRequest.setInvWarehouseCode(invProductEntity.getInvWarehouseCode());
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(filterInvProductDetailRequest);
//计算出在仓库中的设备
//提取库存详情中不同的码
List<String> codesList = invProductDetailEntities.stream().map(InvProductDetailEntity::getOriginCode).distinct().collect(Collectors.toList());
//初始化所有码数量集合
Map<String, Integer> codeMap = new HashMap<>(codesList.size());
codesList.forEach(code -> codeMap.put(code, 0));
//计算库存详情中的码明细,得出所有存在于库存中的码
for (InvProductDetailEntity invProductDetailEntity : invProductDetailEntities) {
Integer count = codeMap.get(invProductDetailEntity.getOriginCode());
if (invProductDetailEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
//入库,数量 +1
count = count + 1;
} else {
//出库, 数量 -1
count = count - 1;
}
codeMap.put(invProductDetailEntity.getOriginCode(), count);
}
//根据计算得出的,所有存在于库存中的码明细,生成设备领用记录详情
for (String code : codeMap.keySet()) {
if (codeMap.get(code) > 0) {
//查找此条码对应的库存详情数据,根据此库存详情数据,查找仓库货位等信息
InvProductDetailEntity invProductDetailEntity = new InvProductDetailEntity();
for (InvProductDetailEntity detailEntity : invProductDetailEntities) {
if (detailEntity.getCode().equals(code)) {
invProductDetailEntity = detailEntity;
break;
}
}
//此条码存在于库存中,解析条码生成设备领用记录详情
Integer count = codeMap.get(code);
if (count > 1) {
for (int i = 0; i < count; i++) {
DeviceCollectOrderDetailEntity orderDetail = getDeviceCollectOrderDetailEntity(addDetailRequest.getOrderIdFk(), code, invProductDetailEntity);
//插入设备领用记录详情
deviceCollectOrderDetailDao.insert(orderDetail);
}
} else {
getDeviceCollectOrderDetailEntity(addDetailRequest.getOrderIdFk(), code, invProductDetailEntity);
}
}
}
}
}
return ResultVOUtils.success("添加成功!");
}
/**
*
*
* @param orderIdFk
* @param code
* @param invProductDetailEntity
* @return
*/
private static DeviceCollectOrderDetailEntity getDeviceCollectOrderDetailEntity(String orderIdFk, String code, InvProductDetailEntity invProductDetailEntity) {
//此条码数量为多个,生成多条养护记录
UdiEntity udi = FilterUdiUtils.getUdi(code);
DeviceCollectOrderDetailEntity orderDetail = new DeviceCollectOrderDetailEntity();
orderDetail.setOrderIdFk(orderIdFk);
orderDetail.setOriginCode(code);
orderDetail.setProductId(invProductDetailEntity.getProductIdFk());
orderDetail.setNameCode(udi.getUdi());
orderDetail.setBatchNo(udi.getBatchNo());
orderDetail.setProduceDate(udi.getProduceDate());
orderDetail.setExpireDate(udi.getExpireDate());
//判断有无序列号如果有序列号则可以通过udi码来判定唯一直接使用udi码做唯一码
if (StrUtil.isNotBlank(udi.getSerialNo())) {
orderDetail.setSerialNo(udi.getSerialNo());
orderDetail.setCode(code);
}
String date = DateUtil.getDateTime();
orderDetail.setCreateTime(date);
orderDetail.setUpdateTime(date);
orderDetail.setInvStorageCode(invProductDetailEntity.getInvStorageCode());
orderDetail.setInvWarehouseCode(invProductDetailEntity.getInvWarehouseCode());
orderDetail.setInvSpaceCode(invProductDetailEntity.getInvSpaceCode());
return orderDetail;
}
@Override
public BaseResponse updateOrderDetail(DeviceCollectOrderDetailEntity detailEntity) {
if (null == detailEntity || null == detailEntity.getId()) {
@ -132,7 +205,7 @@ public class DeviceCollectOrderDetailServiceImpl implements DeviceCollectOrderDe
List<InvProductDetailEntity> invProductDetailEntities = invProductDetailDao.filterInvProductDetail(filterInvProductDetailRequest);
if (CollUtil.isNotEmpty(invProductDetailEntities)) {
if (invProductDetailEntities.size() > 1) {
return ResultVOUtils.error(ResultEnum.DATA_REPEAT,"此设备记录存在于多个仓库,请选择此设备当前所处仓库!");
return ResultVOUtils.error(ResultEnum.DATA_REPEAT, "此设备记录存在于多个仓库,请选择此设备当前所处仓库!");
} else {
return ResultVOUtils.success("校验成功!");
}

Loading…
Cancel
Save