package com.zy.asrs.common.wms.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.zy.asrs.common.domain.dto.*;
|
import com.zy.asrs.common.domain.entity.StaDesc;
|
import com.zy.asrs.common.domain.enums.IoWorkType;
|
import com.zy.asrs.common.domain.enums.WorkNoType;
|
import com.zy.asrs.common.domain.param.FullStoreParam;
|
import com.zy.asrs.common.domain.param.LocDetlAdjustParam;
|
import com.zy.asrs.common.domain.param.StockOutParam;
|
import com.zy.asrs.common.sys.service.StaDescService;
|
import com.zy.asrs.common.utils.Utils;
|
import com.zy.asrs.common.wms.entity.*;
|
import com.zy.asrs.common.wms.service.*;
|
import com.zy.asrs.framework.common.BaseRes;
|
import com.zy.asrs.framework.common.Cools;
|
import com.zy.asrs.framework.exception.CoolException;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.*;
|
import java.util.concurrent.TimeUnit;
|
import java.util.stream.Collectors;
|
|
/**
|
* Created by vincent on 2020/6/11
|
*/
|
@Slf4j
|
@Service
|
public class WorkServiceImpl implements WorkService {
|
|
@Autowired
|
private BasDevpService basDevpService;
|
@Autowired
|
private CommonService commonService;
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private WrkDetlService wrkDetlService;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private MatService matService;
|
@Autowired
|
private OrderDetlService orderDetlService;
|
@Autowired
|
private WrkMastLogService wrkMastLogService;
|
@Autowired
|
private WrkDetlLogService wrkDetlLogService;
|
@Autowired
|
private StaDescService staDescService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
private AdjDetlService adjDetlService;
|
@Autowired
|
private OrderService orderService;
|
|
@Override
|
@Transactional
|
public String startupFullPutStore(FullStoreParam param, Long userId, Long hostId) {
|
// 参数非空判断
|
if (Cools.isEmpty(param.getDevpNo(), param.getList())) {
|
throw new CoolException(BaseRes.PARAM);
|
}
|
Date now = new Date();
|
LocTypeDto locTypeDto = new LocTypeDto();
|
locTypeDto.setLocType1(param.getLocType1());
|
locTypeDto.setLocRangeDto(param.getLocRangeDto());
|
List<String> matnrs = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatnr).distinct().collect(Collectors.toList());
|
String batch = param.getList().get(0).getBatch();
|
StartupDto dto = commonService.getLocNo(1, param.getDevpNo(), matnrs, batch, hostId, locTypeDto, 0);
|
// 生成工作号
|
int workNo = dto.getWorkNo();
|
// 生成工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(now);
|
wrkMast.setWrkSts(1L); // 工作状态:生成入库
|
wrkMast.setIoType(1); // 入出库状态:1.入库
|
wrkMast.setIoPri(13D); // 优先级:13
|
wrkMast.setSourceStaNo(dto.getSourceStaNo());
|
wrkMast.setStaNo(dto.getStaNo());
|
wrkMast.setLocNo(dto.getLocNo());
|
wrkMast.setBarcode(param.getBarcode()); // 托盘码
|
wrkMast.setFullPlt("Y"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk("N"); // 空板
|
wrkMast.setAppeUser(String.valueOf(userId));
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiUser(String.valueOf(userId));
|
wrkMast.setModiTime(now);
|
wrkMast.setHostId(hostId);
|
if (!wrkMastService.save(wrkMast)) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 生成工作档明细
|
List<DetlDto> detlDtos = new ArrayList<>();
|
param.getList().forEach(elem -> {
|
DetlDto detlDto = new DetlDto(elem.getMatnr(), elem.getBatch(), elem.getAnfme());
|
if (DetlDto.has(detlDtos, detlDto)) {
|
DetlDto detlDto1 = DetlDto.find(detlDtos, detlDto.getMatnr(), detlDto.getBatch());
|
assert detlDto1 != null;
|
detlDto1.setAnfme(detlDto1.getAnfme() + detlDto.getAnfme());
|
} else {
|
detlDtos.add(detlDto);
|
}
|
});
|
|
for (DetlDto detlDto : detlDtos) {
|
Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detlDto.getMatnr()).eq(Mat::getHostId, hostId));
|
if (Cools.isEmpty(mat)){
|
throw new CoolException(detlDto.getMatnr() + "商品维护失败");
|
}
|
// 保持工作档明细
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.sync(mat);
|
wrkDetl.setWrkNo(workNo);
|
wrkDetl.setIoTime(now);
|
wrkDetl.setBatch(detlDto.getBatch());
|
wrkDetl.setAnfme(detlDto.getAnfme()); // 数量
|
wrkDetl.setZpallet(param.getBarcode()); // 托盘条码
|
wrkDetl.setAppeUser(userId);
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setModiUser(userId);
|
wrkDetl.setModiTime(now);
|
wrkDetl.setWrkMastId(wrkMast.getId());
|
if (!wrkDetlService.save(wrkDetl)) {
|
throw new CoolException("保存工作明细失败");
|
}
|
}
|
|
// 更新目标库位状态
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, dto.getLocNo()).eq(LocMast::getHostId, hostId));
|
if (locMast.getLocSts().equals("O")){
|
locMast.setLocSts("S"); // S.入库预约
|
locMast.setModiUser(userId);
|
locMast.setModiTime(now);
|
if (!locMastService.updateById(locMast)){
|
throw new CoolException("改变库位状态失败");
|
}
|
} else {
|
throw new CoolException(dto.getLocNo()+"目标库位已被占用");
|
}
|
return dto.getLocNo();
|
}
|
|
@Override
|
@Transactional
|
public void startupFullTakeStore(StockOutParam param, Long userId, Long hostId) {
|
// 获取库位明细
|
List<LocDetlDto> locDetlDtos = new ArrayList<>();
|
for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
|
if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
|
LocDetl one = locDetlService.selectItem(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getBatch(), hostId);
|
if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
|
}
|
}
|
if (!locDetlDtos.isEmpty()) {
|
// 启动出库开始 101.出库
|
stockOut(param.getOutSite(), locDetlDtos, null, userId, hostId);
|
} else {
|
throw new CoolException("库存不存在");
|
}
|
}
|
|
@Override
|
@Transactional
|
public void stockOut(Integer staNo, List<LocDetlDto> locDetlDtos, IoWorkType ioWorkType, Long userId, Long hostId) {
|
Date now = new Date();
|
// 合并同类项
|
Set<String> locNos = new HashSet<>();
|
List<OutLocDto> dtos = new ArrayList<>();
|
for (LocDetlDto locDetlDto : locDetlDtos) {
|
String locNo = locDetlDto.getLocDetl().getLocNo();
|
if (locNos.contains(locNo)) {
|
for (OutLocDto dto : dtos) {
|
if (dto.getLocNo().equals(locNo)) {
|
dto.getLocDetlDtos().add(locDetlDto);
|
break;
|
}
|
}
|
} else {
|
locNos.add(locNo);
|
dtos.add(new OutLocDto(locNo, locDetlDto, hostId));
|
}
|
}
|
Integer ioType = null;
|
// 生成工作档
|
for (OutLocDto dto : dtos) {
|
// 判断入出库类型:101.全板出库 or 103.拣料出库
|
if (ioWorkType == null) {
|
ioType = dto.isAll() ? 101 : 103;
|
} else if (ioWorkType.equals(IoWorkType.CHECK_OUT)) {
|
ioType = 107;
|
}
|
assert ioType != null;
|
// 获取库位
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, dto.getLocNo()).eq(LocMast::getHostId, hostId));
|
// 获取路径
|
StaDesc staDesc = staDescService.getOne(new LambdaQueryWrapper<StaDesc>().eq(StaDesc::getTypeNo, ioType).eq(StaDesc::getDeviceStn, staNo).eq(StaDesc::getHostId, hostId));
|
// 生成工作号
|
int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
|
// 生成工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(now);
|
wrkMast.setWrkSts(101L); // 工作状态:101.生成出库
|
wrkMast.setIoType(ioType); // 入出库状态
|
wrkMast.setIoPri(13D); // 优先级:13
|
wrkMast.setSourceStaNo(staDesc.getDeviceStn()); // 源站
|
wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
|
wrkMast.setSourceLocNo(dto.getLocNo()); // 源库位
|
wrkMast.setFullPlt("Y"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk("N"); // 空板
|
wrkMast.setBarcode(locMast.getBarcode());
|
wrkMast.setAppeUser(String.valueOf(userId)); // 操作人员数据
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiUser(String.valueOf(userId));
|
wrkMast.setModiTime(now);
|
wrkMast.setHostId(hostId);
|
if (!wrkMastService.save(wrkMast)) {
|
throw new CoolException("保存工作档失败,出库库位号:" + dto.getLocNo());
|
}
|
// 生成工作档明细
|
for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
|
if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) {
|
continue;
|
}
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.sync(detlDto.getLocDetl());
|
wrkDetl.setOrderNo(""); // 手动出库不需要带出库存中的单据编号
|
wrkDetl.setWrkNo(workNo);
|
wrkDetl.setIoTime(now);
|
Double anfme = ioType == 101 ? detlDto.getLocDetl().getAnfme() : detlDto.getCount();
|
wrkDetl.setAnfme(anfme); // 数量
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setAppeUser(userId);
|
wrkDetl.setModiTime(now);
|
wrkDetl.setModiUser(userId);
|
wrkDetl.setHostId(hostId);
|
wrkDetl.setWrkMastId(wrkMast.getId());
|
if (!wrkDetlService.save(wrkDetl)) {
|
throw new CoolException("保存工作档明细失败");
|
}
|
}
|
// 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
|
locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, dto.getLocNo()).eq(LocMast::getHostId, hostId));
|
if (locMast.getLocSts().equals("F")) {
|
locMast.setLocSts(ioType == 101 ? "R" : "P");
|
locMast.setModiUser(userId);
|
locMast.setModiTime(now);
|
if (!locMastService.updateById(locMast)) {
|
throw new CoolException("预约库位状态失败,库位号:" + dto.getLocNo());
|
}
|
} else {
|
throw new CoolException(dto.getLocNo() + "库位不是在库状态");
|
}
|
}
|
}
|
|
@Override
|
@Transactional
|
public void stockOut(Integer staNo, TaskDto taskDto, Long userId, Long hostId) {
|
Date now = new Date();
|
List<LocDto> locDtos = taskDto.getLocDtos();
|
for (LocDto locDto : locDtos) {
|
if (!taskDto.getLocNo().equals(locDto.getLocNo()) && !taskDto.getStaNo().equals(locDto.getStaNo())) {
|
throw new CoolException("订单出库异常,请联系管理员");
|
}
|
}
|
// 获取库位
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>()
|
.eq(LocMast::getLocNo, taskDto.getLocNo())
|
.eq(LocMast::getHostId, hostId));
|
// 获取路径
|
int ioType = taskDto.isAll() ? 101 : 103;
|
// 获取路径
|
StaDesc staDesc = staDescService.getOne(new LambdaQueryWrapper<StaDesc>().eq(StaDesc::getTypeNo, ioType).eq(StaDesc::getDeviceStn, staNo).eq(StaDesc::getHostId, hostId));
|
// 生成工作号
|
int workNo = commonService.getWorkNo(WorkNoType.getWorkNoType(ioType));
|
// 生成工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(now);
|
wrkMast.setWrkSts(101L); // 工作状态:101.生成出库
|
wrkMast.setIoType(ioType); // 入出库状态
|
wrkMast.setIoPri(13D); // 优先级:13
|
wrkMast.setSourceStaNo(staDesc.getDeviceStn()); // 源站
|
wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
|
wrkMast.setSourceLocNo(taskDto.getLocNo()); // 源库位
|
wrkMast.setFullPlt("Y"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk("N"); // 空板
|
wrkMast.setBarcode(locMast.getBarcode());
|
wrkMast.setAppeUser(String.valueOf(userId)); // 操作人员数据
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiUser(String.valueOf(userId));
|
wrkMast.setModiTime(now);
|
wrkMast.setHostId(hostId);
|
if (!wrkMastService.save(wrkMast)) {
|
throw new CoolException("保存工作档失败,出库库位号:"+taskDto.getLocNo());
|
}
|
// 生成工作档明细
|
for (LocDto locDto : taskDto.getLocDtos()) {
|
if (locDto.getAnfme()==null || locDto.getAnfme() <= 0.0D) { continue; }
|
Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
.eq(Order::getOrderNo, locDto.getOrderNo())
|
.eq(Order::getHostId, hostId));
|
OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), locDto.getMatnr(), locDto.getBatch());
|
if (orderDetl == null) {
|
orderDetl = orderDetlService.selectItem(order.getId(), locDto.getMatnr(), null);
|
}
|
LocDetl locDetl = locDetlService.selectItem(locDto.getLocNo(), locDto.getMatnr(), locDto.getBatch(), hostId);
|
if (locDetl == null || locDetl.getAnfme() < locDto.getAnfme()) {
|
throw new CoolException(locDto.getLocNo() + "库位中" + locDto.getMatnr() + "商品库存不足!");
|
}
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.sync(orderDetl);
|
wrkDetl.setZpallet(wrkMast.getBarcode());
|
wrkDetl.setIoTime(now);
|
wrkDetl.setWrkNo(workNo);
|
wrkDetl.setBatch(locDto.getBatch());
|
wrkDetl.setOrderNo(locDto.getOrderNo());
|
wrkDetl.setAnfme(locDto.getAnfme()); // 数量
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setAppeUser(userId);
|
wrkDetl.setModiTime(now);
|
wrkDetl.setModiUser(userId);
|
wrkDetl.setHostId(hostId);
|
wrkDetl.setWrkMastId(wrkMast.getId());
|
if (!wrkDetlService.save(wrkDetl)) {
|
throw new CoolException("保存工作档明细失败");
|
}
|
// 修改订单明细
|
if (!orderDetlService.increase(orderDetl.getOrderId(), hostId, orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) {
|
throw new CoolException("修改订单明细数量失败");
|
}
|
orderService.updateSettle(orderDetl.getOrderId(), 2L, userId, hostId);
|
}
|
// 修改库位状态: F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
|
locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>()
|
.eq(LocMast::getLocNo, taskDto.getLocNo())
|
.eq(LocMast::getHostId, hostId));
|
if (locMast.getLocSts().equals("F")) {
|
locMast.setLocSts(ioType==101?"R":"P");
|
locMast.setModiUser(userId);
|
locMast.setModiTime(now);
|
if (!locMastService.updateById(locMast)) {
|
throw new CoolException("预约库位状态失败,库位号:"+taskDto.getLocNo());
|
}
|
} else {
|
throw new CoolException(taskDto.getLocNo() + "库位不是在库状态");
|
}
|
}
|
|
@Override
|
@Transactional
|
public void completeWrkMast(String workNo, Long userId, Long hostId) {
|
WrkMast wrkMast = wrkMastService.getOne(new LambdaQueryWrapper<WrkMast>().eq(WrkMast::getWrkNo, workNo).eq(WrkMast::getHostId, hostId));
|
if (Cools.isEmpty(wrkMast)){
|
throw new CoolException(workNo+"工作档不存在");
|
}
|
if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14) {
|
throw new CoolException("当前工作档已完成");
|
}
|
// 入库 + 库位转移
|
if (wrkMast.getWrkSts() < 99 || (wrkMast.getWrkSts() > 100 && wrkMast.getIoType()==11)) {
|
wrkMast.setWrkSts(99L);//99.入库完成
|
// 出库
|
} else if (wrkMast.getWrkSts() > 100) {
|
wrkMast.setWrkSts(199L);//199.出库完成
|
}
|
Date now = new Date();
|
wrkMast.setModiTime(now);
|
wrkMast.setModiUser(String.valueOf(userId));
|
// 完成操作人员记录
|
wrkMast.setManuType("手动完成");
|
if (!wrkMastService.updateById(wrkMast)) {
|
throw new CoolException("修改工作档失败");
|
}
|
}
|
|
@Override
|
@Transactional
|
public void cancelWrkMast(String workNo, Long userId, Long hostId) {
|
WrkMast wrkMast = wrkMastService.getOne(new LambdaQueryWrapper<WrkMast>().eq(WrkMast::getWrkNo, workNo).eq(WrkMast::getHostId, hostId));
|
if (Cools.isEmpty(wrkMast)) {
|
throw new CoolException(workNo + "工作档不存在");
|
}
|
String locNo = ""; // 待修改目标库位
|
String locSts = ""; // 待修改目标库位状态
|
// 入库取消(修改目标库位)
|
if (wrkMast.getWrkSts() < 99) {
|
locNo = wrkMast.getLocNo();
|
locSts = "O";
|
|
// 库位转移
|
if (wrkMast.getIoType() == 11) {
|
// 库位转移:源库位
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, wrkMast.getSourceLocNo()).eq(LocMast::getHostId, hostId));
|
if (Cools.isEmpty(locMast)) {
|
throw new CoolException("取消库位转移失败,源库位不存在:" + wrkMast.getSourceLocNo());
|
}
|
locMast.setLocSts("F");
|
locMast.setModiTime(new Date());
|
locMast.setModiUser(userId);
|
locMastService.updateById(locMast);
|
}
|
// 出库取消(修改源库位)
|
} else if (wrkMast.getWrkSts() > 100 && wrkMast.getWrkSts() != 199) {
|
locNo = wrkMast.getSourceLocNo();
|
// 出库 ===>> F.在库
|
if (wrkMast.getIoType() > 100 && wrkMast.getIoType() != 110) {
|
locSts = "F";
|
// 空板出库 ===>> D.空桶/空栈板
|
} else if (wrkMast.getIoType() == 110) {
|
locSts = "D";
|
// 库位转移 ===>> D.空桶/空栈板
|
} else if (wrkMast.getIoType() == 11) {
|
locSts = wrkMast.getFullPlt().equalsIgnoreCase("N") ? "D" : "F";
|
// 库位转移:目标库位
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, wrkMast.getLocNo()).eq(LocMast::getHostId, hostId));
|
if (Cools.isEmpty(locMast)) {
|
throw new CoolException("取消库位转移失败,目标库位不存在:" + wrkMast.getSourceLocNo());
|
}
|
locMast.setLocSts("O");
|
locMast.setModiTime(new Date());
|
locMast.setModiUser(userId);
|
locMastService.updateById(locMast);
|
}
|
} else {
|
throw new CoolException("当前工作状态无法取消");
|
}
|
// 订单关联
|
List<WrkDetl> wrkDetls = wrkDetlService.list(new LambdaQueryWrapper<WrkDetl>().eq(WrkDetl::getWrkNo, wrkMast.getWrkNo()).eq(WrkDetl::getHostId, hostId));
|
for (WrkDetl wrkDetl : wrkDetls) {
|
if (!Cools.isEmpty(wrkDetl.getOrderNo())) {
|
if (!orderDetlService.decrease(wrkDetl.getOrderNo(), hostId, wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) {
|
throw new CoolException("订单数据回滚失败");
|
}
|
}
|
}
|
// 取消操作人员记录
|
wrkMast.setManuType("手动取消");
|
wrkMast.setModiUser(String.valueOf(userId));
|
wrkMast.setModiTime(new Date());
|
if (!wrkMastService.updateById(wrkMast)) {
|
throw new CoolException("取消工作档失败");
|
}
|
// 保存工作主档历史档
|
if (!wrkMastLogService.saveToHistory(wrkMast.getId())) {
|
throw new CoolException("保存工作历史档失败, workNo = " + wrkMast.getWrkNo());
|
}
|
// 删除工作主档
|
boolean wrkMastRes = wrkMastService.removeById(wrkMast);
|
|
if (wrkMast.getIoType() != 10 && wrkMast.getIoType() != 110) {
|
// 保存工作明细档历史档
|
if (!wrkDetlLogService.saveToHistory(wrkMast.getWrkNo(), hostId)) {
|
throw new CoolException("保存工作明细历史档失败, workNo = " + wrkMast.getWrkNo());
|
}
|
// 删除工作档明细
|
boolean wrkDetlRes = wrkDetlService.remove(new LambdaQueryWrapper<WrkDetl>().eq(WrkDetl::getWrkNo, workNo).eq(WrkDetl::getHostId, hostId));
|
}
|
|
// 修改库位状态
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, locNo).eq(LocMast::getHostId, hostId));
|
if (Cools.isEmpty(locMast)) {
|
throw new CoolException("取消工作档失败,库位不存在:" + locNo);
|
}
|
locMast.setLocSts(locSts);
|
locMast.setModiTime(new Date());
|
locMast.setModiUser(userId);
|
boolean locMastRes = locMastService.updateById(locMast);
|
if (!wrkMastRes || !locMastRes) {
|
throw new CoolException("保存数据失败");
|
}
|
}
|
|
@Override
|
@Transactional
|
public void pickWrkMast(String workNo, Long userId, Long hostId) {
|
WrkMast wrkMast = wrkMastService.getOne(new LambdaQueryWrapper<WrkMast>().eq(WrkMast::getWrkNo, workNo).eq(WrkMast::getHostId, hostId));
|
if (Cools.isEmpty(wrkMast)) {
|
throw new CoolException(workNo + "工作档不存在");
|
}
|
// 入出库类型判断
|
if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107) {
|
throw new CoolException("当前入出库类型无法进行操作");
|
}
|
// 工作状态判断
|
if (wrkMast.getWrkSts() < 101 || wrkMast.getWrkSts() == 200) {
|
throw new CoolException("当前工作状态无法进行操作");
|
}
|
// 保存工作明细档历史档
|
// if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
|
// throw new CoolException("保存工作明细档历史档失败");
|
// }
|
// 保存工作主档历史档
|
if (!wrkMastLogService.saveToHistory(wrkMast.getId())) {
|
throw new CoolException("保存工作主档历史档失败");
|
}
|
// 获取目标站
|
LambdaQueryWrapper<StaDesc> wrapper = new LambdaQueryWrapper<StaDesc>()
|
.eq(StaDesc::getTypeNo, wrkMast.getIoType() - 50)
|
.eq(StaDesc::getStnNo, wrkMast.getStaNo()); // 作业站点 = 拣料出库的目标站
|
StaDesc staDesc = staDescService.getOne(wrapper);
|
if (Cools.isEmpty(staDesc)) {
|
throw new CoolException("入库路径不存在");
|
}
|
// 堆垛机站点(目标站)
|
Integer staNo = staDesc.getDeviceStn();
|
Date now = new Date();
|
// 更新工作档数据状态
|
wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
|
wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
|
wrkMast.setSourceStaNo(wrkMast.getStaNo()); // 源站
|
wrkMast.setStaNo(staNo); // 目标站
|
wrkMast.setLocNo(wrkMast.getSourceLocNo()); // 目标库位 = 出库时的源库位
|
wrkMast.setSourceLocNo(""); // 源库位清空
|
wrkMast.setModiTime(now);
|
wrkMast.setModiUser(String.valueOf(userId));
|
if (!wrkMastService.updateById(wrkMast)) {
|
throw new CoolException("更新工作档数据状态失败");
|
}
|
// 修改库位状态 Q.拣料/盘点/并板再入库
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, wrkMast.getLocNo()).eq(LocMast::getHostId, hostId));
|
locMast.setLocSts("Q");
|
locMast.setModiTime(now);
|
locMast.setModiUser(userId);
|
if (!locMastService.updateById(locMast)) {
|
throw new CoolException("修改库位状态失败");
|
}
|
}
|
|
@Override
|
@Transactional
|
public void adjustLocDetl(LocDetlAdjustParam param, Long userId, Long hostId) {
|
param.integrate();
|
LocMast locMast = locMastService.getOne(new LambdaQueryWrapper<LocMast>().eq(LocMast::getLocNo, param.getLocNo()).eq(LocMast::getHostId, hostId));
|
if (Cools.isEmpty(locMast)) {
|
throw new CoolException("库位不存在");
|
}
|
if (!(locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") || locMast.getLocSts().equals("O"))) {
|
throw new CoolException("当前库位不可调整!库位状态:" + locMast.getLocSts$());
|
}
|
|
Date now = new Date();
|
List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, param.getLocNo()).eq(LocDetl::getHostId, hostId));
|
|
List<LocDetlAdjustParam.LocDetlAdjust> list = param.getList();
|
|
// 修改数量
|
Iterator<LocDetl> iterator = locDetls.iterator();
|
while (iterator.hasNext()) {
|
LocDetl locDetl = iterator.next();
|
|
Iterator<LocDetlAdjustParam.LocDetlAdjust> iterator1 = list.iterator();
|
while (iterator1.hasNext()) {
|
LocDetlAdjustParam.LocDetlAdjust adjust = iterator1.next();
|
if (adjust.getCount() == 0) { continue; }
|
if (locDetl.getMatnr().equals(adjust.getMatnr()) && Cools.eq(locDetl.getBatch(), adjust.getBatch())) {
|
if (!locDetl.getAnfme().equals(adjust.getCount())) {
|
// todo 盘点记录
|
// 修改库存
|
if (!locDetlService.updateAnfme(adjust.getCount(), locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), hostId)) {
|
throw new CoolException(locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "序列码修改数量失败");
|
}
|
// 保存调整记录
|
AdjDetl adjDetl = new AdjDetl();
|
adjDetl.setLocNo(locDetl.getLocNo());
|
adjDetl.setMatnr(locDetl.getMatnr());
|
adjDetl.setBatch(locDetl.getBatch());
|
adjDetl.setOriQty(locDetl.getAnfme());
|
adjDetl.setAdjQty(adjust.getCount());
|
adjDetl.setModiTime(now);
|
adjDetl.setModiUser(userId);
|
adjDetl.setAppeTime(now);
|
adjDetl.setAppeUser(userId);
|
adjDetl.setHostId(hostId);
|
adjDetlService.save(adjDetl);
|
}
|
iterator.remove();
|
iterator1.remove();
|
}
|
}
|
}
|
|
// 删除库存
|
for (LocDetl locDetl : locDetls) {
|
// todo 盘点记录
|
if (!locDetlService.updateAnfme(-1.0D, locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(), hostId)) {
|
throw new CoolException("删除" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "序列码库存明细失败");
|
}
|
// 保存调整记录
|
AdjDetl adjDetl = new AdjDetl();
|
adjDetl.setLocNo(locDetl.getLocNo());
|
adjDetl.setMatnr(locDetl.getMatnr());
|
adjDetl.setBatch(locDetl.getBatch());
|
adjDetl.setOriQty(locDetl.getAnfme());
|
adjDetl.setAdjQty(0.0D);
|
adjDetl.setModiTime(now);
|
adjDetl.setModiUser(userId);
|
adjDetl.setAppeTime(now);
|
adjDetl.setAppeUser(userId);
|
adjDetl.setHostId(hostId);
|
adjDetlService.save(adjDetl);
|
}
|
|
// 添加库存
|
for (LocDetlAdjustParam.LocDetlAdjust adjust : list) {
|
if (adjust.getCount() == 0.0D) { continue; }
|
Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, adjust.getMatnr()).eq(Mat::getHostId, hostId));
|
LocDetl locDetl = new LocDetl();
|
locDetl.sync(mat);
|
locDetl.setBatch(adjust.getBatch());
|
locDetl.setLocNo(locMast.getLocNo());
|
locDetl.setAnfme(adjust.getCount()); // 数量
|
locDetl.setModiUser(userId); // 操作人员信息
|
locDetl.setModiTime(now);
|
locDetl.setAppeUser(userId);
|
locDetl.setAppeTime(now);
|
locDetl.setHostId(hostId);
|
if (!locDetlService.save(locDetl)) {
|
throw new CoolException("添加" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "序列码库存明细失败");
|
}
|
// 保存调整记录
|
AdjDetl adjDetl = new AdjDetl();
|
adjDetl.setLocNo(locMast.getLocNo());
|
adjDetl.setMatnr(adjust.getMatnr());
|
adjDetl.setBatch(adjust.getBatch());
|
adjDetl.setOriQty(0.0D);
|
adjDetl.setAdjQty(adjust.getCount());
|
adjDetl.setModiTime(now);
|
adjDetl.setModiUser(userId);
|
adjDetl.setAppeTime(now);
|
adjDetl.setAppeUser(userId);
|
adjDetl.setHostId(hostId);
|
adjDetlService.save(adjDetl);
|
}
|
// 修改库位状态
|
int count = locDetlService.count(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, locMast.getLocNo()).eq(LocDetl::getHostId, hostId));
|
if (locMast.getLocSts().equals("F")) {
|
if (count == 0) {
|
locMast.setLocSts("D");
|
}
|
}
|
if (locMast.getLocSts().equals("D") || locMast.getLocSts().equals("O")) {
|
if (count > 0) {
|
locMast.setLocSts("F");
|
}
|
}
|
locMast.setModiUser(userId);
|
locMast.setModiTime(new Date());
|
if (!locMastService.updateById(locMast)) {
|
throw new CoolException("更新库位状态失败");
|
}
|
}
|
|
@Override
|
@Transactional
|
public void locMove(String sourceLocNo, String locNo, Long userId, Long hostId) {
|
LocMast sourceLoc = locMastService.getOne(new LambdaQueryWrapper<LocMast>()
|
.eq(LocMast::getLocNo, sourceLocNo)
|
.eq(LocMast::getHostId, hostId));
|
List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>()
|
.eq(LocDetl::getLocNo, sourceLocNo)
|
.eq(LocDetl::getHostId, hostId));
|
if (Cools.isEmpty(sourceLoc)){
|
throw new CoolException("未找到库位");
|
}
|
LocMast loc = locMastService.getOne(new LambdaQueryWrapper<LocMast>()
|
.eq(LocMast::getLocNo, locNo)
|
.eq(LocMast::getHostId, hostId));
|
if (Cools.isEmpty(loc)){
|
throw new CoolException("未找到库位");
|
}
|
if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) {
|
// throw new CoolException("移转库位属于不同堆垛机"); todo:luxiaotao
|
}
|
Date now = new Date();
|
// 获取工作号
|
int workNo = commonService.getWorkNo(WorkNoType.PICK.type);
|
// 保存工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(now);
|
wrkMast.setWrkSts(101L); // 工作状态:101.生成出库任务
|
wrkMast.setIoType(11); // 入出库状态: 11.库格移载
|
wrkMast.setIoPri(10D);
|
wrkMast.setSourceLocNo(sourceLocNo); // 源库位
|
wrkMast.setLocNo(locNo); // 目标库位
|
wrkMast.setFullPlt(Cools.isEmpty(locDetls)?"N":"Y"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk(sourceLoc.getLocSts().equals("D")?"Y":"N"); // 空板
|
wrkMast.setBarcode(sourceLoc.getBarcode()); // 托盘码
|
wrkMast.setAppeUser(String.valueOf(userId));
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiUser(String.valueOf(userId));
|
wrkMast.setModiTime(now);
|
wrkMast.setHostId(hostId);
|
boolean res = wrkMastService.save(wrkMast);
|
if (!res) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 工作档明细保存
|
for (LocDetl locDetl : locDetls) {
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.sync(locDetl);
|
wrkDetl.setWrkNo(workNo);
|
wrkDetl.setIoTime(now);
|
wrkDetl.setAnfme(locDetl.getAnfme());
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setAppeUser(userId);
|
wrkDetl.setModiTime(now);
|
wrkDetl.setModiUser(userId);
|
wrkDetl.setHostId(hostId);
|
wrkDetl.setWrkMastId(wrkMast.getId());
|
if (!wrkDetlService.save(wrkDetl)) {
|
throw new CoolException("保存工作档明细失败");
|
}
|
}
|
// 修改源库位状态
|
if (sourceLoc.getLocSts().equals("D") || sourceLoc.getLocSts().equals("F")) {
|
sourceLoc.setLocSts("R"); // R.出库预约
|
sourceLoc.setModiUser(userId);
|
sourceLoc.setModiTime(now);
|
if (!locMastService.updateById(sourceLoc)){
|
throw new CoolException("更新源库位状态失败");
|
}
|
} else {
|
throw new CoolException(sourceLoc.getLocNo() + "源库位出库失败,状态:"+sourceLoc.getLocSts$());
|
}
|
// 修改目标库位状态
|
if (loc.getLocSts().equals("O")) {
|
loc.setLocSts("S"); // S.入库预约
|
loc.setModiTime(now);
|
loc.setModiUser(userId);
|
if (!locMastService.updateById(loc)) {
|
throw new CoolException("更新目标库位状态失败");
|
}
|
} else {
|
throw new CoolException("移转失败,目标库位状态:"+loc.getLocSts$());
|
}
|
}
|
}
|