package com.chinaztt.mes.production.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.util.BooleanUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.chinaztt.mes.basic.dto.LocationIfsMoveDTO;
|
import com.chinaztt.mes.basic.entity.Location;
|
import com.chinaztt.mes.basic.entity.Part;
|
import com.chinaztt.mes.basic.entity.Workstation;
|
import com.chinaztt.mes.basic.entity.WorkstationLocation;
|
import com.chinaztt.mes.basic.mapper.LocationMapper;
|
import com.chinaztt.mes.basic.mapper.PartMapper;
|
import com.chinaztt.mes.basic.mapper.WorkstationLocationMapper;
|
import com.chinaztt.mes.basic.mapper.WorkstationMapper;
|
import com.chinaztt.mes.basic.util.PartUtils;
|
import com.chinaztt.mes.common.constant.Constant;
|
import com.chinaztt.mes.plan.entity.MoStructureComponent;
|
import com.chinaztt.mes.production.dto.FeedingDTO;
|
import com.chinaztt.mes.production.dto.FeedingInDTO;
|
import com.chinaztt.mes.production.entity.Feeding;
|
import com.chinaztt.mes.production.entity.FeedingRecord;
|
import com.chinaztt.mes.production.entity.OperationTask;
|
import com.chinaztt.mes.production.mapper.FeedingMapper;
|
import com.chinaztt.mes.production.mapper.FeedingRecordMapper;
|
import com.chinaztt.mes.production.mapper.OperationTaskMapper;
|
import com.chinaztt.mes.production.service.FeedingService;
|
import com.chinaztt.mes.production.service.ProductMainService;
|
import com.chinaztt.mes.production.util.FeedingUtils;
|
import com.chinaztt.mes.quality.entity.ApplyPart;
|
import com.chinaztt.mes.quality.entity.Report;
|
import com.chinaztt.mes.quality.mapper.ApplyPartMapper;
|
import com.chinaztt.mes.quality.mapper.ReportMapper;
|
import com.chinaztt.mes.warehouse.dto.FeedingStockDTO;
|
import com.chinaztt.mes.warehouse.dto.StockDTO;
|
import com.chinaztt.mes.warehouse.entity.JoinStockOrder;
|
import com.chinaztt.mes.warehouse.entity.Stock;
|
import com.chinaztt.mes.warehouse.mapper.JoinStockOrderMapper;
|
import com.chinaztt.mes.warehouse.mapper.StockMapper;
|
import com.chinaztt.mes.warehouse.service.StockService;
|
import com.chinaztt.mes.warehouse.util.StockUtils;
|
import com.chinaztt.mes.warehouse.util.TransactionType;
|
import com.chinaztt.ztt.admin.api.feign.RemoteParamService;
|
import com.chinaztt.ztt.common.core.constant.SecurityConstants;
|
import com.chinaztt.ztt.common.core.util.R;
|
import lombok.AllArgsConstructor;
|
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 投料登记
|
*
|
* @author cxf
|
* @date 2020-11-12 10:48:37
|
*/
|
@Service
|
@AllArgsConstructor
|
@Transactional(rollbackFor = Exception.class)
|
public class FeedingServiceImpl extends ServiceImpl<FeedingMapper, Feeding> implements FeedingService {
|
private StockUtils stockUtils;
|
private FeedingUtils feedingUtils;
|
private FeedingRecordMapper feedingRecordMapper;
|
private StockMapper stockMapper;
|
private WorkstationLocationMapper workstationLocationMapper;
|
private WorkstationMapper workstationMapper;
|
private PartMapper partMapper;
|
private ApplyPartMapper applyPartMapper;
|
private ReportMapper reportMapper;
|
private PartUtils partUtils;
|
private JoinStockOrderMapper joinStockOrderMapper;
|
private OperationTaskMapper operationTaskMapper;
|
private LocationMapper locationMapper;
|
private ProductMainService productMainService;
|
private RemoteParamService remoteParamService;
|
private StockService stockService;
|
|
|
@Override
|
public List<FeedingDTO> getFeedingByWorkstationId(QueryWrapper<FeedingDTO> gen) {
|
return baseMapper.getFeedingByParam(gen);
|
}
|
|
/**
|
* 旧版本投料,将物料从线边仓或者预留投入到 投料登记中 再从投料登记中扣除数量 该方法暂停使用中
|
*
|
* @param feedingInDTO
|
* @return
|
*/
|
@Override
|
public boolean saveList(FeedingInDTO feedingInDTO) {
|
List<FeedingDTO> feedingList = feedingInDTO.getFeeds();
|
for (FeedingDTO feeding : feedingList) {
|
if ("joinStocker".equals(feedingInDTO.getFeedingFrom())) {
|
// 1.去修改预留中零件数量
|
JoinStockOrder joinStockOrder = joinStockOrderMapper.selectById(feeding.getJoinStockOrderId());
|
Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, joinStockOrder.getPartNo()));
|
feeding.setStockId(joinStockOrder.getStockId());
|
feeding.setPartId(part.getId());
|
stockUtils.joinStockerChange(feeding.getJoinStockOrderId(), feeding.getSuppliedQuantity());
|
}
|
if ("stocker".equals(feedingInDTO.getFeedingFrom())) {
|
// 1.去修改线边仓零件数量
|
stockUtils.updateById(feeding.getStockId(), feeding.getSuppliedQuantity().negate(), BigDecimal.ZERO, BigDecimal.ZERO, null, null, "FEED");
|
}
|
// 2.投料登记,保存投料记录
|
FeedingRecord feedingRecord = new FeedingRecord();
|
feedingRecord.setFeedingQuantity(feeding.getSuppliedQuantity());
|
// 2.1 根据工作站和零件\批次号去查询投料记录,如果存在就加上去
|
Feeding feedingExist = baseMapper.selectOne(Wrappers.<Feeding>lambdaQuery()
|
.eq(Feeding::getWorkstationId, feeding.getWorkstationId()).eq(Feeding::getPartId, feeding.getPartId())
|
.eq(Feeding::getPartBatchNo, feeding.getPartBatchNo()).eq(Feeding::getSystemNo, feeding.getSystemNo())
|
.eq(Feeding::getStockId, feeding.getStockId()));
|
if (feedingExist != null) {
|
feedingUtils.updateById(feedingExist.getId(), feedingRecord.getFeedingQuantity(), feedingRecord.getFeedingQuantity());
|
feedingRecord.setFeedingId(feedingExist.getId());
|
} else {
|
feeding.setResidualQuantity(feeding.getSuppliedQuantity());
|
baseMapper.insert(feeding);
|
feedingRecord.setFeedingId(feeding.getId());
|
}
|
// 2.2 保存投料记录
|
feedingRecordMapper.insert(feedingRecord);
|
}
|
return true;
|
}
|
|
/**
|
* 投料,将物料从线边仓或者预留 移库到已投料库位置中
|
*
|
* @param feedingInDTO
|
* @return
|
*/
|
@Override
|
public boolean feeding(FeedingInDTO feedingInDTO) {
|
|
String billNo = RandomStringUtils.random(10, true, true);
|
List<FeedingDTO> feedingList = feedingInDTO.getFeeds();
|
OperationTask operationTask = operationTaskMapper.selectById(feedingInDTO.getOperationTaskId());
|
if (operationTask == null) {
|
throw new RuntimeException("未找到工序任务");
|
}
|
Map<Long, List<MoStructureComponent>> componentList = productMainService.getComponentList(operationTask.getId());
|
if (componentList.isEmpty()) {
|
throw new RuntimeException("未找到所需物料");
|
}
|
// // 校验是否原材料检
|
// Part basicPart = partMapper.selectOne(new LambdaQueryWrapper<Part>().eq(Part::getPartNo, feedingList.get(0).getPartNo()));
|
// if (basicPart == null){
|
// throw new RuntimeException("零件不存在");
|
// }
|
// if (basicPart.getTestRuleType()!=null && basicPart.getTestRuleType() == 1){
|
// List<ApplyPart> applyParts = applyPartMapper.selectList(new LambdaQueryWrapper<ApplyPart>().eq(ApplyPart::getPartNo, basicPart.getPartNo()));
|
// if (CollectionUtil.isEmpty(applyParts)){
|
// throw new RuntimeException("请先进行原材料检");
|
// }
|
// List<Long> reportIds = applyParts.stream().map(ApplyPart::getReportId).collect(Collectors.toList());
|
//
|
// List<Report> reports = reportMapper.selectList(new LambdaQueryWrapper<Report>().in(Report::getId, reportIds));
|
// List<Report> collect = reports.stream().filter(e -> "01checked".equals(e.getCheckState())).collect(Collectors.toList());
|
// if (CollectionUtil.isEmpty(collect)){
|
// throw new RuntimeException("请先进行原材料检");
|
// }
|
// }
|
// 存在行项号进行ifs移库
|
List<Part> parts = null;
|
Long locationId = null;
|
if (!"erp".equals(feedingInDTO.getSource())) {
|
for (FeedingDTO feedingDTO : feedingList) {
|
if (!componentList.containsKey(feedingDTO.getPartId())) {
|
throw new RuntimeException(feedingDTO.getPartName() + "不在该工序所需物料中,请确认");
|
}
|
}
|
} else {
|
Set<Long> partIds = componentList.keySet();
|
parts = partMapper.selectBatchIds(partIds);
|
for (FeedingDTO feedingDTO : feedingList) {
|
if (parts.stream().noneMatch(e -> e.getPartNo().equals(feedingDTO.getPartNo()))) {
|
throw new RuntimeException(feedingDTO.getPartName() + "不在该工序所需物料中,请确认");
|
}
|
}
|
|
List<Location> locations = locationMapper.selectList(new LambdaQueryWrapper<Location>().eq(Location::getLocName, "erp入库库位").or().eq(Location::getLocName, "ERP入库库位"));
|
if (CollectionUtil.isEmpty(locations)) {
|
throw new RuntimeException("请取基础数据添加ERP入库库位");
|
}
|
locationId = locations.get(0).getId();
|
|
}
|
|
for (FeedingDTO feeding : feedingList) {
|
if ("joinStocker".equals(feedingInDTO.getFeedingFrom())) {
|
// 1.去修改预留中零件数量
|
JoinStockOrder joinStockOrder = joinStockOrderMapper.selectById(feeding.getJoinStockOrderId());
|
Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, joinStockOrder.getPartNo()));
|
feeding.setStockId(joinStockOrder.getStockId());
|
feeding.setPartId(part.getId());
|
stockUtils.joinStockerChange(feeding.getJoinStockOrderId(), feeding.getSuppliedQuantity());
|
}
|
if ("stocker".equals(feedingInDTO.getFeedingFrom())) {
|
// 2.去修改线边仓零件数量
|
// if(!"erp".equals(feedingInDTO.getSource())) {
|
stockUtils.updateById(feeding.getStockId(), feeding.getSuppliedQuantity().negate(), BigDecimal.ZERO,
|
BigDecimal.ZERO, null, billNo, "FEED");
|
// }else{
|
// StockDTO stockDTO = new StockDTO();
|
// stockDTO.setNum(feeding.getSuppliedQuantity());
|
// stockDTO.setPartNo(basicPart.getPartNo());
|
// stockDTO.setPartBatchNo("");
|
// R r = stockService.lockStore(stockDTO);
|
// if (r.getCode() != 0){
|
// throw new RuntimeException(r.getMsg());
|
// }
|
// }
|
}
|
// 3.移库将库存移到已投料库
|
if ("erp".equals(feedingInDTO.getSource())) {
|
Part part = parts.stream().filter(e -> e.getPartNo().equals(feeding.getPartNo())).findFirst().get();
|
// Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getPartBatchNo,feeding.getPartBatchNo()).eq(Stock::getPartId,part.getId()).eq(Stock::getLocationId,locationId));
|
// if (stock == null){
|
// throw new RuntimeException("mes 没有库存信息");
|
// }
|
// feeding.setStockId(stock.getId());
|
stockUtils.erpFeeding(feeding.getPartBatchNo(), feeding.getWorkstationId(), feeding.getSuppliedQuantity(), billNo, part);
|
} else {
|
stockUtils.feeding(feeding.getStockId(), feeding.getWorkstationId(), feeding.getSuppliedQuantity(), billNo, feedingInDTO.getSource());
|
}
|
}
|
// String feedCheck = remoteParamService.getByKey(Constant.FEED_IFS_NEED_SYNC, SecurityConstants.FROM_IN).getData();
|
// if (!StringUtils.equals(feedCheck, "false")) {
|
// this.ifsMove(feedingList, 1);
|
// }
|
return true;
|
}
|
|
/**
|
* type 1投料,2退料
|
*
|
* @param feedingList
|
*/
|
private void ifsMove(List<FeedingDTO> feedingList, Integer type) {
|
Location location = null;
|
// type 1 获取投料库位,2获取线边仓
|
if (type == 1) {
|
List<WorkstationLocation> locationList = workstationLocationMapper.selectList(Wrappers.<WorkstationLocation>lambdaQuery()
|
.eq(WorkstationLocation::getWorkstationId, feedingList.get(0).getWorkstationId())
|
.eq(WorkstationLocation::getLocationType, WorkstationLocation.FED_LOCATION));
|
if (CollectionUtils.isEmpty(locationList)) {
|
throw new RuntimeException("缺少已投料库位");
|
}
|
location = locationMapper.selectById(locationList.get(0).getLocationId());
|
} else {
|
//查询是否存在线边仓
|
//List<Location> locationList = locationMapper.getLocationByWorkstationId(feedingList.get(0).getWorkstationId(), WorkstationLocation.FEED_LOCATION);
|
//if (CollectionUtils.isEmpty(locationList)) {
|
// throw new RuntimeException("缺少线边仓");
|
//}
|
//location = locationList.get(0);
|
boolean present = feedingList.stream().anyMatch(f -> null == f.getReturnLocationId());
|
if (present) {
|
throw new RuntimeException("存在未选退料库位行");
|
}
|
}
|
List<StockDTO> stockList = new ArrayList<>();
|
LocationIfsMoveDTO moveDTO = new LocationIfsMoveDTO();
|
moveDTO.setRECORD_ID(UUID.randomUUID().toString().replace("-", ""));
|
List<LocationIfsMoveDTO.DataBean> dataBeans = new ArrayList<>();
|
moveDTO.setBATCH_INFO(dataBeans);
|
for (FeedingDTO feeding : feedingList) {
|
if (type == 2) {
|
location = locationMapper.selectById(feeding.getReturnLocationId());
|
}
|
StockDTO stock;
|
BigDecimal qty;
|
if (type == 1) {
|
qty = feeding.getSuppliedQuantity();
|
stock = BeanUtil.copyProperties(stockMapper.selectById(feeding.getStockId()), StockDTO.class);
|
} else {
|
qty = feeding.getReturnQuantity();
|
stock = BeanUtil.copyProperties(stockMapper.selectById(feeding.getId()), StockDTO.class);
|
}
|
|
// 是否工序库存为false执行ifs移库
|
// Part part = partMapper.selectById(stock.getPartId());
|
if (stock.getOperationStockStatus() != null && !stock.getOperationStockStatus()) {
|
if (location.getIfsLocation() != null) {
|
stock.setFeedQuantity(qty);
|
stockList.add(stock);
|
}
|
}
|
assembleMoveDataBean(dataBeans, stock, location);
|
}
|
if (stockList.size() > 0) {
|
// 调用ifs移库接口
|
stockUtils.feedingIfsMoveByDTO(stockList, moveDTO);
|
}
|
}
|
|
private void assembleMoveDataBean(List<LocationIfsMoveDTO.DataBean> dataBeans, StockDTO stock, Location location) {
|
// 库存件退料需要ifs移库
|
Part part = partMapper.selectById(stock.getPartId());
|
if (stock.getOperationStockStatus() == null) {
|
if (StringUtils.equals("3", part.getMaterialType())) {
|
stock.setOperationStockStatus(Boolean.FALSE);
|
}
|
}
|
if (BooleanUtil.isTrue(stock.getOperationStockStatus())) {
|
return;
|
}
|
Location nowLocation = locationMapper.selectById(stock.getLocationId());
|
if (nowLocation.getIfsLocation() == null) {
|
throw new RuntimeException("库存库位未绑定ifs库位");
|
}
|
|
LocationIfsMoveDTO.DataBean bean = new LocationIfsMoveDTO.DataBean();
|
bean.setPART_NO(part.getPartNo());
|
if (part.getLotTrackingIfs() != null && part.getLotTrackingIfs()) {
|
bean.setLOT_BATCH_NO(stock.getIfsBatchNo());
|
bean.setWAIV_DEV_REJ_NO(stock.getPartBatchNo());
|
} else {
|
bean.setLOT_BATCH_NO("*");
|
bean.setWAIV_DEV_REJ_NO("*");
|
}
|
bean.setMOVE_QTY(stock.getFeedQuantity());
|
bean.setLOCATION_NO(nowLocation.getIfsLocation());
|
bean.setTO_LOCATION_NO(location.getIfsLocation());
|
dataBeans.add(bean);
|
}
|
|
|
@Override
|
public boolean updateList(List<FeedingDTO> feedingList) {
|
for (FeedingDTO feedingDTO : feedingList) {
|
Feeding feeding = baseMapper.selectById(feedingDTO.getId());
|
// 1.去修改线边仓零件数量(PDA扫的erp库存就直接减去)
|
if (feeding.getStockId() != null) {
|
stockUtils.updateById(feeding.getStockId(), feedingDTO.getReturnQuantity(), BigDecimal.ZERO, BigDecimal.ZERO, null, null, "FEED");
|
}
|
// 2.保存投料记录
|
FeedingRecord feedingRecord = new FeedingRecord();
|
feedingRecord.setFeedingQuantity(feedingDTO.getReturnQuantity().negate());
|
feedingRecord.setFeedingId(feedingDTO.getId());
|
feedingRecordMapper.insert(feedingRecord);
|
// 3.更新投料
|
feedingUtils.updateById(feedingDTO.getId(), feedingDTO.getReturnQuantity().negate(), feedingDTO.getReturnQuantity().negate());
|
}
|
return true;
|
}
|
|
|
@Override
|
public boolean rejectFeeding(List<FeedingDTO> feedingList) {
|
for (FeedingDTO feedingDTO : feedingList) {
|
stockUtils.rejectFeeding(feedingDTO.getWorkstationId(), feedingDTO.getReturnQuantity(),
|
feedingDTO.getPartId(), feedingDTO.getPartBatchNo(), feedingDTO.getSystemNo(), feedingDTO.getId()
|
, feedingDTO.getReturnLocationId());
|
}
|
String feedCheck = remoteParamService.getByKey(Constant.FEED_IFS_NEED_SYNC, SecurityConstants.FROM_IN).getData();
|
if (!StringUtils.equals(feedCheck, "false")) {
|
this.ifsMove(feedingList, 2);
|
}
|
return true;
|
}
|
|
private Stock getOneStockByWorkstation(Long workStationId, Long partId, String partBatchNo, String systemNo) {
|
List<WorkstationLocation> locationList = workstationLocationMapper.selectList(Wrappers.<WorkstationLocation>lambdaQuery()
|
.eq(WorkstationLocation::getWorkstationId, workStationId)
|
.eq(WorkstationLocation::getLocationType, WorkstationLocation.FEED_LOCATION));
|
if (CollectionUtil.isEmpty(locationList)) {
|
throw new RuntimeException("该工作站尚未配置线边仓");
|
}
|
Set<Long> locationIds = locationList.stream().map(WorkstationLocation::getLocationId).collect(Collectors.toSet());
|
//根据机台绑定的库位,零件id,批次号去找到线边仓库存记录行
|
Stock stock = stockMapper.selectOne(Wrappers.<Stock>lambdaQuery()
|
.eq(Stock::getPartId, partId)
|
.eq(Stock::getPartBatchNo, partBatchNo)
|
.eq(Stock::getSystemNo, systemNo)
|
.in(Stock::getLocationId, locationIds));
|
return stock;
|
}
|
|
@Override
|
public List<JSONObject> pdaList(QueryWrapper<FeedingDTO> gen) {
|
return baseMapper.pdaList(gen);
|
}
|
|
/**
|
* 老的PDA投料
|
*
|
* @param feedingDTO
|
*/
|
@Override
|
public void pdaAdd(FeedingDTO feedingDTO) {
|
boolean partIsExist = getIdByNo(feedingDTO);
|
if (partIsExist) {
|
Stock stock = getOneStockByWorkstation(feedingDTO.getWorkstationId(), feedingDTO.getPartId(), feedingDTO.getPartBatchNo(), feedingDTO.getSystemNo());
|
if (stock != null) {
|
feedingDTO.setStockId(stock.getId());
|
// 1.去修改线边仓零件数量
|
stockUtils.updateById(stock.getId(), feedingDTO.getSuppliedQuantity().negate(), BigDecimal.ZERO, BigDecimal.ZERO, null, null, "FEED");
|
}
|
}
|
// 2.投料登记,保存投料记录
|
FeedingRecord feedingRecord = new FeedingRecord();
|
feedingRecord.setFeedingQuantity(feedingDTO.getSuppliedQuantity());
|
// 2.1 根据工作站和零件\批次号\系统号去查询投料记录,如果存在就加上去
|
Feeding feedingExist = baseMapper.selectOne(getQuery(feedingDTO));
|
if (feedingExist != null) {
|
feedingUtils.updateById(feedingExist.getId(), feedingRecord.getFeedingQuantity(), feedingRecord.getFeedingQuantity());
|
feedingRecord.setFeedingId(feedingExist.getId());
|
} else {
|
feedingDTO.setResidualQuantity(feedingDTO.getSuppliedQuantity());
|
baseMapper.insert(feedingDTO);
|
feedingRecord.setFeedingId(feedingDTO.getId());
|
}
|
// 2.2 保存投料记录
|
feedingRecordMapper.insert(feedingRecord);
|
}
|
|
@Override
|
public void pdaReturn(FeedingDTO feedingDTO) {
|
getIdByNo(feedingDTO);
|
Feeding feeding = baseMapper.selectOne(getQuery(feedingDTO));
|
if (feeding == null) {
|
throw new RuntimeException("投入物料不存在");
|
}
|
if (feeding.getStockId() != null) {
|
// 1.去修改线边仓零件数量
|
stockUtils.updateById(feeding.getStockId(), feedingDTO.getReturnQuantity(), null, BigDecimal.ZERO, BigDecimal.ZERO, null, "FEED");
|
}
|
// 2.保存投料记录
|
FeedingRecord feedingRecord = new FeedingRecord();
|
feedingRecord.setFeedingQuantity(feedingDTO.getReturnQuantity().negate());
|
feedingRecord.setFeedingId(feeding.getId());
|
feedingRecordMapper.insert(feedingRecord);
|
// 3.更新投料
|
feedingUtils.updateById(feeding.getId(), feedingDTO.getReturnQuantity().negate(), feedingDTO.getReturnQuantity().negate());
|
}
|
|
/**
|
* workstationNo
|
*
|
* @param feedingDTO
|
* @return
|
*/
|
public boolean getIdByNo(FeedingDTO feedingDTO) {
|
boolean result = true;
|
Workstation workstation = workstationMapper.selectOne(Wrappers.<Workstation>lambdaQuery().eq(Workstation::getWorkstationNo, feedingDTO.getWorkstationNo()));
|
if (workstation == null) {
|
throw new RuntimeException(feedingDTO.getWorkstationNo() + "工作站不存在");
|
} else {
|
feedingDTO.setWorkstationId(workstation.getId());
|
}
|
Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, feedingDTO.getPartNo()));
|
if (part == null) {
|
// 如果零件不存在,去erp接口查询零件,并生成零件
|
part = partUtils.getErpPartByPartNo(feedingDTO.getPartNo());
|
result = false;
|
}
|
feedingDTO.setPartId(part.getId());
|
return result;
|
}
|
|
/**
|
* 新的PDA投料
|
*
|
* @param feedingStockDTO
|
*/
|
@Override
|
public void pdaAdd(FeedingStockDTO feedingStockDTO) {
|
boolean partIsExist = getIdByNo(feedingStockDTO);
|
String billNo = RandomStringUtils.random(10, true, true);
|
if (partIsExist) {
|
Stock stock = getOneStockByWorkstation(feedingStockDTO.getWorkstationId(), feedingStockDTO.getPartId(), feedingStockDTO.getPartBatchNo(), feedingStockDTO.getSystemNo());
|
if (stock != null) {
|
List<WorkstationLocation> locationList = workstationLocationMapper.selectList(Wrappers.<WorkstationLocation>lambdaQuery()
|
.eq(WorkstationLocation::getWorkstationId, feedingStockDTO.getWorkstationId())
|
.eq(WorkstationLocation::getLocationType, WorkstationLocation.FED_LOCATION));
|
if (CollectionUtils.isEmpty(locationList)) {
|
throw new RuntimeException(feedingStockDTO.getWorkstationNo() + "缺少已投料库");
|
}
|
feedingStockDTO.setId(stock.getId());
|
// 1、去修改线边仓零件数量
|
stockUtils.updateById(stock.getId(), feedingStockDTO.getSuppliedQuantity().negate(), BigDecimal.ZERO,
|
BigDecimal.ZERO, null, billNo, "FEED");
|
// 2、查询已投未消耗的物料
|
Stock stockExist = stockMapper.selectOne(Wrappers.<Stock>lambdaQuery()
|
.eq(Stock::getLocationId, locationList.get(0).getLocationId())
|
.eq(Stock::getPartId, stock.getPartId())
|
.eq(Stock::getPartBatchNo, stock.getPartBatchNo())
|
.eq(Stock::getSystemNo, stock.getSystemNo()));
|
if (stockExist != null) {
|
stockUtils.updateById(stockExist.getId(), feedingStockDTO.getSuppliedQuantity(), BigDecimal.ZERO,
|
BigDecimal.ZERO, null, billNo, "FEED");
|
} else {
|
stockExist = new Stock();
|
stockExist.setPartId(stock.getPartId());
|
stockExist.setSystemNo(stock.getSystemNo());
|
stockExist.setPartBatchNo(stock.getPartBatchNo());
|
stockExist.setLocationId(locationList.get(0).getLocationId());
|
stockExist.setStockQuantity(feedingStockDTO.getSuppliedQuantity());
|
stockExist.setReserveQuantity(BigDecimal.ZERO);
|
stockExist.setAvailableStockQuantity(feedingStockDTO.getSuppliedQuantity());
|
stockExist.setOperationStockStatus(stock.getOperationStockStatus());
|
stockExist.setReelNumber(stock.getReelNumber());
|
stockExist.setIfsBatchNo(stock.getIfsBatchNo());
|
stockExist.setCustomerOrderNo(stock.getCustomerOrderNo());
|
stockExist.setMpsNo(stock.getMpsNo());
|
stockMapper.insert(stockExist);
|
stockUtils.createTransaction(BigDecimal.ZERO, stockExist.getStockQuantity(),
|
stockExist.getPartId(), locationList.get(0).getLocationId(), stockExist.getPartBatchNo(),
|
billNo, TransactionType.PRODUCT_FEEDING.getValue(), stockExist.getIfsBatchNo());
|
}
|
FeedingDTO feedingDTO = new FeedingDTO();
|
feedingDTO.setStockId(stock.getId());
|
feedingDTO.setWorkstationId(feedingStockDTO.getWorkstationId());
|
feedingDTO.setSuppliedQuantity(feedingStockDTO.getSuppliedQuantity());
|
ifsMove(Collections.singletonList(feedingDTO), 1);
|
}
|
}
|
}
|
|
/**
|
* @param feedingStockDTO
|
*/
|
@Override
|
public void pdaReturn(FeedingStockDTO feedingStockDTO) {
|
getIdByNo(feedingStockDTO);
|
//被退库位
|
WorkstationLocation workstationLocationFrom = workstationLocationMapper.selectOne(Wrappers.<WorkstationLocation>lambdaQuery()
|
.eq(WorkstationLocation::getLocationType, WorkstationLocation.FED_LOCATION)
|
.eq(WorkstationLocation::getWorkstationId, feedingStockDTO.getWorkstationId()));
|
Stock stockfrom = stockMapper.selectOne(Wrappers.<Stock>lambdaQuery()
|
.eq(Stock::getPartBatchNo, feedingStockDTO.getPartBatchNo())
|
.eq(Stock::getSystemNo, feedingStockDTO.getSystemNo())
|
.eq(Stock::getLocationId, workstationLocationFrom.getLocationId())
|
.eq(Stock::getPartId, feedingStockDTO.getPartId()));
|
if (null == stockfrom) {
|
throw new RuntimeException("退库物料丢失");
|
}
|
stockUtils.updateById(stockfrom.getId(), feedingStockDTO.getReturnQuantity().negate(), BigDecimal.ZERO, BigDecimal.ZERO, null, null, TransactionType.PRODUCT_CANCEL.getValue());
|
//退入库位
|
WorkstationLocation workstationLocationTo = workstationLocationMapper.selectOne(Wrappers.<WorkstationLocation>lambdaQuery()
|
.eq(WorkstationLocation::getLocationType, WorkstationLocation.FEED_LOCATION)
|
.eq(WorkstationLocation::getWorkstationId, feedingStockDTO.getWorkstationId()));
|
Stock stockTo = stockMapper.selectOne(Wrappers.<Stock>lambdaQuery()
|
.eq(Stock::getPartBatchNo, feedingStockDTO.getPartBatchNo())
|
.eq(Stock::getSystemNo, feedingStockDTO.getSystemNo())
|
.eq(Stock::getLocationId, workstationLocationTo.getLocationId())
|
.eq(Stock::getPartId, feedingStockDTO.getPartId()));
|
stockUtils.updateById(stockTo.getId(), feedingStockDTO.getReturnQuantity(), BigDecimal.ZERO, BigDecimal.ZERO, null, null, TransactionType.PRODUCT_CANCEL.getValue());
|
}
|
|
@Override
|
public List<Location> getReturnLocations(Long workstationId) {
|
return locationMapper.getReturnLocationByWorkstationId(workstationId,
|
Arrays.asList(WorkstationLocation.FEED_LOCATION, WorkstationLocation.PENDING_LOCATION));
|
}
|
|
/**
|
* workstationNo
|
*
|
* @param feedingStockDTO
|
* @return
|
*/
|
public boolean getIdByNo(FeedingStockDTO feedingStockDTO) {
|
boolean result = true;
|
Workstation workstation = workstationMapper.selectOne(Wrappers.<Workstation>lambdaQuery().eq(Workstation::getWorkstationNo, feedingStockDTO.getWorkstationNo()));
|
if (workstation == null) {
|
throw new RuntimeException(feedingStockDTO.getWorkstationNo() + "工作站不存在");
|
} else {
|
feedingStockDTO.setWorkstationId(workstation.getId());
|
}
|
Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, feedingStockDTO.getPartNo()));
|
if (part == null) {
|
// 如果零件不存在,去erp接口查询零件,并生成零件
|
part = partUtils.getErpPartByPartNo(feedingStockDTO.getPartNo());
|
result = false;
|
}
|
feedingStockDTO.setPartId(part.getId());
|
return result;
|
}
|
|
private LambdaQueryWrapper<Feeding> getQuery(FeedingDTO feedingDTO) {
|
LambdaQueryWrapper<Feeding> wrapper = Wrappers.<Feeding>lambdaQuery()
|
.eq(Feeding::getWorkstationId, feedingDTO.getWorkstationId()).eq(Feeding::getPartId, feedingDTO.getPartId())
|
.eq(Feeding::getPartBatchNo, feedingDTO.getPartBatchNo());
|
if (StringUtils.isNotBlank(feedingDTO.getSystemNo())) {
|
wrapper = wrapper.eq(Feeding::getSystemNo, feedingDTO.getSystemNo());
|
}
|
if (feedingDTO.getStockId() != null) {
|
wrapper = wrapper.eq(Feeding::getStockId, feedingDTO.getStockId());
|
}
|
return wrapper;
|
}
|
}
|