package com.zy.asrs.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.Cools;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.service.*;
|
import com.zy.common.model.StartupDto;
|
import com.zy.common.service.AgvCommonService;
|
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.Date;
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2020/6/11
|
*/
|
@Slf4j
|
@Service
|
@Transactional
|
public class AgvWorkServiceImpl implements AgvWorkService {
|
|
// 工作号生成规则默认类型
|
private static final int DEFAULT_WORK_NO_TYPE = 0;
|
// 库位排号分配默认类别
|
private static final int DEFAULT_ROW_NO_TYPE = 1;
|
@Autowired
|
private AgvWaitPakinService agvWaitPakinService;
|
@Autowired
|
private AgvBasDevpService agvBasDevpService;
|
@Autowired
|
private AgvLocMastService agvLockMastService;
|
@Autowired
|
private AgvCommonService agvCommonService;
|
@Autowired
|
private AgvWrkMastService agvWrkMastService;
|
@Autowired
|
private AgvWrkDetlService agvWrkDetlService;
|
@Autowired
|
private MatService matService;
|
|
@Override
|
public StartupDto createWaitPainWrkMastStart(List<AgvBasDevp> agvBasDevpList, Long userId) {
|
|
Date now = new Date();
|
|
agvBasDevpList.forEach(agvBasDevp -> {
|
if(Cools.isEmpty(agvBasDevp.getBarcode())){
|
throw new CoolException("选中的站点中含有位绑定托盘的站点,请重新选择");
|
}
|
|
if(!"F".equals(agvBasDevp.getLocSts())){
|
throw new CoolException("选中的站点中含有货位状态不为F.在库的站点,请重新选择");
|
}
|
|
List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>().eq("zpallet", agvBasDevp.getBarcode()));
|
|
//检索库位,选择合适的库位
|
AgvLocMast agvLocMast = agvCommonService.getLocNo(agvWaitPakinList, agvBasDevp.getFloor());
|
//生成工作档
|
AgvWrkMast wrkMast = createWrkMast(agvBasDevp, agvLocMast, now, userId);
|
//生成工作档明细
|
createWrkDetlReWrite(agvWaitPakinList,wrkMast,userId);
|
//更新源站点信息
|
updateAgvBasDevp(agvBasDevp);
|
//更新目标库位状态
|
updateAgvLocMast(agvLocMast);
|
|
});
|
|
return null;
|
}
|
|
/*
|
更新目标库位信息
|
*/
|
private void updateAgvLocMast(AgvLocMast locMast){
|
locMast.setLocSts("S");
|
agvLockMastService.updateById(locMast);
|
}
|
|
/*
|
更新源站点信息
|
*/
|
private void updateAgvBasDevp(AgvBasDevp agvBasDevp){
|
agvBasDevp.setLocSts("R");
|
agvBasDevpService.updateById(agvBasDevp);
|
}
|
|
/*
|
生成工作档明细
|
*/
|
/* private void createWrkDetl(List<AgvWaitPakin> agvWaitPakinList, AgvWrkMast wrkMast, Long userId){
|
List<DetlDto> detlDtos = new ArrayList<>();
|
agvWaitPakinList.forEach(agvWaitPakin -> {
|
DetlDto detlDto = new DetlDto(agvWaitPakin.getMatnr(), agvWaitPakin.getBatch(), agvWaitPakin.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);
|
}
|
});
|
agvWrkDetlService.createWorkDetail(wrkMast.getWrkNo(), detlDtos, wrkMast.getBarcode(), userId);
|
}*/
|
/*
|
生成工作档明细
|
*/
|
private void createWrkDetlReWrite(List<AgvWaitPakin> agvWaitPakinList, AgvWrkMast wrkMast, Long userId){
|
Date now = new Date();
|
agvWaitPakinList.stream().forEach(agvWaitPakin -> {
|
Mat mat = matService.selectByMatnr(agvWaitPakin.getMatnr());
|
if (Cools.isEmpty(mat)) {
|
throw new CoolException(agvWaitPakin.getMatnr() + "商品维护失败");
|
}
|
AgvWrkDetl wrkDetl = new AgvWrkDetl();
|
wrkDetl.sync(mat);
|
wrkDetl.setWrkNo(wrkMast.getWrkNo());
|
wrkDetl.setOrderNo(agvWaitPakin.getOrderNo());
|
wrkDetl.setIoTime(now);
|
wrkDetl.setBatch(agvWaitPakin.getBatch());
|
wrkDetl.setAnfme(agvWaitPakin.getAnfme()); // 数量
|
wrkDetl.setZpallet(agvWaitPakin.getZpallet()); // 托盘条码
|
wrkDetl.setAppeUser(userId);
|
wrkDetl.setAppeTime(now);
|
wrkDetl.setModiUser(userId);
|
wrkDetl.setModiTime(now);
|
if (!agvWrkDetlService.insert(wrkDetl)) {
|
throw new CoolException("保存工作明细失败");
|
}
|
});
|
}
|
|
/*
|
生成工作档
|
*/
|
private AgvWrkMast createWrkMast(AgvBasDevp agvBasDevp,AgvLocMast agvLocMast, Date now, Long userId){
|
AgvWrkMast wrkMast = new AgvWrkMast();
|
//生成工作号
|
int workNo = agvCommonService.getWorkNo(0);
|
wrkMast.setWrkNo(workNo);
|
wrkMast.setIoTime(new Date());
|
wrkMast.setWrkSts(201L); // 工作状态:201.生成入库任务ID
|
wrkMast.setIoType(1); // 入出库状态:1.入库
|
//生成优先级
|
wrkMast.setIoPri(300.0);
|
wrkMast.setSourceLocNo(agvBasDevp.getDevNo());
|
wrkMast.setLocNo(agvLocMast.getLocNo());
|
wrkMast.setBarcode(agvBasDevp.getBarcode());
|
wrkMast.setFullPlt("Y"); // 满板:Y
|
wrkMast.setPicking("N"); // 拣料
|
wrkMast.setExitMk("N"); // 退出
|
wrkMast.setEmptyMk("N"); // 空板
|
wrkMast.setLinkMis("N");
|
wrkMast.setAppeUser(userId);
|
wrkMast.setAppeTime(now);
|
wrkMast.setModiUser(userId);
|
wrkMast.setModiTime(now);
|
if (!agvWrkMastService.insert(wrkMast)) {
|
throw new CoolException("保存工作档失败");
|
}
|
return wrkMast;
|
|
}
|
}
|