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.DetlDto; 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.*; /** * 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; @Override public StartupDto createWaitPainWrkMastStart(List 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 agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper().eq("zpallet", agvBasDevp.getBarcode())); //检索库位,选择合适的库位 AgvLocMast agvLocMast = agvCommonService.getLocNo(agvWaitPakinList, agvBasDevp.getFloor()); //生成工作档 AgvWrkMast wrkMast = createWrkMast(agvBasDevp, agvLocMast, now, userId); //生成工作档明细 createWrkDetl(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 agvWaitPakinList, AgvWrkMast wrkMast, Long userId){ List 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 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(1L); // 工作状态:生成入库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; } public static void main(String[] args) { Set set = new HashSet<>(); set.add(null); set.add(null); System.out.println(set.size()); } }