package com.zy.common.web;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.common.R;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.entity.param.CombParam;
|
import com.zy.asrs.service.*;
|
import com.zy.asrs.utils.PostMesDataUtils;
|
import com.zy.common.CodeRes;
|
import com.zy.common.model.LocTypeDto;
|
import com.zy.common.model.StartupDto;
|
import com.zy.common.service.CommonService;
|
import com.zy.common.web.param.SearchLocParam;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* Created by vincent on 2020/10/30
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/rpc")
|
public class WcsController {
|
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private BasDevpService basDevpService;
|
@Autowired
|
private CommonService commonService;
|
@Autowired
|
private WrkDetlService wrkDetlService;
|
@Autowired
|
private LocMastService locMastService;
|
@Autowired
|
private WaitPakinService waitPakinService;
|
@Autowired
|
private LocDetlService locDetlService;
|
@Autowired
|
private TestMastService testMastService;
|
@Autowired
|
private MatService matService;
|
|
@Value("mes.url")
|
private String mesUrl;
|
|
@Value("mes.inPath")
|
private String inpath;
|
|
@PostMapping("/pakin/loc/v1")
|
@ResponseBody
|
public synchronized R getLocNo(@RequestBody SearchLocParam param) {
|
log.info("收到WCS入库接口请求====>>入参:{}", param);
|
if (Cools.isEmpty(param.getIoType())) {
|
return R.error("入出库类型不能为空");
|
}
|
if (Cools.isEmpty(param.getSourceStaNo())) {
|
return R.error("源站编号不能为空");
|
}
|
|
if (Cools.isEmpty(param.getPackNo())) {
|
return R.error("packNo不能为空");
|
}
|
Date now = new Date();
|
if (param.getSourceStaNo()==109){
|
try{
|
Mat mat = matService.selectByMatnr(param.getPackNo());
|
if (Cools.isEmpty(mat)){
|
return R.error("商品信息档案未查询到pack信息"+param.getPackNo());
|
}
|
WaitPakin waitPakin = new WaitPakin();
|
waitPakin.setMatnr(mat.getMatnr());// Pack码
|
waitPakin.setMaktx(mat.getMaktx());
|
waitPakin.setZpallet(param.getBarcode()); //托盘码
|
waitPakin.setIoStatus("N"); // 入出状态
|
waitPakin.setAnfme(1.0); // 数量
|
waitPakin.setStatus("Y"); // 状态
|
waitPakin.setManuDate(mat.getManuDate());
|
waitPakin.setAppeUser(null);
|
waitPakin.setAppeTime(now);
|
waitPakin.setModiUser(null);
|
waitPakin.setModiTime(now);
|
waitPakin.setDeadWarn(mat.getDeadWarn());
|
if (!waitPakinService.insert(waitPakin)) {
|
throw new CoolException("保存入库通知档失败");
|
}
|
}catch (Exception e){
|
|
}
|
}
|
List<WaitPakin> waitPakins = null;
|
if (param.getIoType() == 1) {
|
if (Cools.isEmpty(param.getBarcode())) {
|
return R.error("条码不能为空");
|
}
|
waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
|
if (Cools.isEmpty(waitPakins) || waitPakins.size()!=1) {
|
WrkMast wrkMast = wrkMastService.selectByBarcode(param.getBarcode());
|
if (wrkMast != null || waitPakins.size()!=1) {
|
return R.parse("600-重复组托");
|
}
|
return R.parse(CodeRes.NO_COMB_700);
|
}
|
int countWait = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",param.getBarcode())
|
.eq("io_status", "Y"));
|
int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode()));
|
int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode()));
|
if (countLoc > 0 || countWrk > 0 || countWait > 0) {
|
if (!Cools.isEmpty(waitPakins.get(0).getDeadWarn()) && waitPakins.get(0).getDeadWarn()!=0){
|
return R.error(CodeRes.EXIST_500);
|
}
|
}
|
}
|
if (Cools.isEmpty(param.getLocType1())){
|
param.setLocType1((short)1);
|
}
|
|
// 源站点状态检测
|
BasDevp sourceStaNo = basDevpService.checkSiteStatus(param.getSourceStaNo(), false);
|
// sourceStaNo.setLocType1(param.getLocType1());
|
sourceStaNo.setLocType1((short)1);
|
LocTypeDto locTypeDto = new LocTypeDto(sourceStaNo);
|
|
StartupDto dto = null;
|
switch (param.getIoType()) {
|
case 1://满托盘入库
|
assert waitPakins != null;
|
dto = startupFullPutStore(param.getSourceStaNo(), param.getBarcode(), locTypeDto, waitPakins);
|
break;
|
case 10://空托盘入库
|
dto = emptyPlateIn(param.getSourceStaNo(), locTypeDto, param.getBarcode());
|
break;
|
default:
|
break;
|
}
|
log.info("WCS入库接口返参:{},pack码:{}", dto, param.getBarcode());
|
return R.ok().add(dto);
|
}
|
|
/**
|
* 全板入库
|
*/
|
@Transactional
|
public StartupDto startupFullPutStore(Integer devpNo, String barcode, LocTypeDto locTypeDto, List<WaitPakin> waitPakins) {
|
// 源站点状态检测
|
BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo, true);
|
// 检索库位
|
List<String> matNos = waitPakins.stream().map(WaitPakin::getMatnr).distinct().collect(Collectors.toList());
|
StartupDto dto = commonService.getLocNo(1, 1, devpNo, matNos, locTypeDto,0);
|
int workNo = dto.getWorkNo();
|
Date now = new Date();
|
// 生成工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(new Date());
|
wrkMast.setWrkSts(2L); // 工作状态:生成入库ID
|
wrkMast.setIoType(1); // 入出库状态:1.入库
|
wrkMast.setIoPri(13D); // 优先级
|
wrkMast.setCrnNo(dto.getCrnNo());
|
wrkMast.setSourceStaNo(dto.getSourceStaNo());
|
wrkMast.setStaNo(dto.getStaNo());
|
wrkMast.setLocNo(dto.getLocNo());
|
wrkMast.setBarcode(barcode); // 托盘码
|
wrkMast.setFullPlt("Y"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk("N"); // 空板
|
wrkMast.setLinkMis("Y");
|
wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型
|
// 操作人员数据
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiTime(now);
|
boolean res = wrkMastService.insert(wrkMast);
|
if (!res) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 目标库位
|
LocMast locMast = locMastService.selectById(dto.getLocNo());
|
|
// 生成工作档明细
|
waitPakins.forEach(waitPakin -> {
|
WrkDetl wrkDetl = new WrkDetl();
|
wrkDetl.sync(waitPakin);
|
wrkDetl.setWrkNo(wrkMast.getWrkNo());
|
wrkDetl.setIoTime(wrkMast.getIoTime());
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setModiTime(now);
|
wrkDetl.setDeadWarn(waitPakin.getDeadWarn());
|
if (!wrkDetlService.insert(wrkDetl)) {
|
throw new CoolException("保存工作明细失败");
|
}
|
TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>().eq("barcode", wrkMast.getBarcode()));
|
|
if (Cools.isEmpty(testMast)){
|
//生成测试档
|
testMast=new TestMast();
|
testMast.setChannel(locMast.getChannel());
|
testMast.setUserId(locMast.getLocNo());
|
testMast.setStatus(1);
|
testMast.setBarcode(wrkDetl.getMatnr());
|
testMast.setLocNo(locMast.getLocNo());
|
testMast.setModiTime(now);
|
testMast.setAppeTime(now);
|
if (!testMastService.insert(testMast)){
|
throw new CoolException(wrkDetl.getMatnr()+"生成测试档失败");
|
}
|
}else {
|
throw new CoolException(wrkDetl.getMatnr()+"已存在测试档");
|
}
|
});
|
// 更新入库通知档 ioStatus ===>> Y
|
Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>()
|
.eq("zpallet", barcode);
|
WaitPakin setParam = new WaitPakin();
|
setParam.setLocNo(dto.getLocNo());
|
setParam.setIoStatus("Y");
|
setParam.setModiTime(now);
|
if (!waitPakinService.update(setParam, wrapper)) {
|
throw new CoolException("更新通知档失败");
|
}
|
// 更新源站点信息
|
sourceStaNo.setWrkNo(workNo);
|
sourceStaNo.setModiTime(now);
|
if (!basDevpService.updateById(sourceStaNo)){
|
throw new CoolException("更新源站失败");
|
}
|
// 更新目标库位状态
|
if (locMast.getLocSts().equals("O")){
|
locMast.setLocSts("S"); // S.入库预约
|
locMast.setModiTime(now);
|
if (!locMastService.updateById(locMast)){
|
throw new CoolException("改变库位状态失败");
|
}else{
|
if (locMast.getRow1()<3){
|
//1.扫码上报
|
CombParam combParam = new CombParam();
|
combParam.setPackNo(wrkMast.getBarcode());
|
combParam.setLocNo(wrkMast.getLocNo());
|
combParam.setPackSts(0);
|
combParam.setStepSts(1);
|
combParam.setRequestTime(DateUtils.convert(now));
|
new PostMesDataUtils().postMesData("MES系统",mesUrl,inpath,combParam);
|
}
|
}
|
} else {
|
throw new CoolException(dto.getLocNo()+"目标库位已被占用");
|
}
|
|
return dto;
|
}
|
|
@Transactional
|
public StartupDto emptyPlateIn(Integer devpNo, LocTypeDto locTypeDto, String barcode) {
|
// 源站点状态检测
|
BasDevp sourceStaNo = basDevpService.checkSiteStatus(devpNo, true);
|
// 检索库位
|
StartupDto dto = commonService.getLocNo(1, 10, devpNo, null, locTypeDto,0);
|
int workNo = dto.getWorkNo();
|
// 生成工作档
|
WrkMast wrkMast = new WrkMast();
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(new Date());
|
wrkMast.setWrkSts(2L); // 工作状态:生成入库ID
|
wrkMast.setIoType(10); // 入出库状态:10.空板入库
|
wrkMast.setIoPri(13D); // 优先级
|
wrkMast.setCrnNo(dto.getCrnNo());
|
wrkMast.setSourceStaNo(dto.getSourceStaNo());
|
wrkMast.setStaNo(dto.getStaNo());
|
wrkMast.setLocNo(dto.getLocNo());
|
wrkMast.setFullPlt("N"); // 满板
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk("Y"); // 空板
|
wrkMast.setLinkMis("Y");
|
wrkMast.setBarcode(barcode);
|
wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型
|
// 操作人员数据
|
wrkMast.setAppeTime(new Date());
|
wrkMast.setModiTime(new Date());
|
boolean res = wrkMastService.insert(wrkMast);
|
if (!res) {
|
throw new CoolException("保存工作档失败");
|
}
|
// 更新源站点信息
|
sourceStaNo.setWrkNo(workNo);
|
sourceStaNo.setModiTime(new Date());
|
if (!basDevpService.updateById(sourceStaNo)){
|
throw new CoolException("更新源站失败");
|
}
|
// 更新目标库位状态
|
LocMast locMast = locMastService.selectById(dto.getLocNo());
|
if (locMast.getLocSts().equals("O")){
|
locMast.setLocSts("S"); // S.入库预约
|
locMast.setModiTime(new Date());
|
if (!locMastService.updateById(locMast)){
|
throw new CoolException("改变库位状态失败");
|
}
|
} else {
|
throw new CoolException(dto.getLocNo()+"目标库位已被占用");
|
}
|
return dto;
|
}
|
|
}
|