package com.zy.asrs.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.core.common.Cools; import com.zy.asrs.entity.*; import com.zy.asrs.mapper.AgvBasDevpMapper; import com.zy.asrs.service.*; import com.zy.common.model.AgvBasDevpDto; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; @Service @Transactional public class AgvBasDevpServiceImpl extends ServiceImpl implements AgvBasDevpService { @Autowired AgvBasDevpMapper agvBasDevpMapper; @Autowired AgvWrkMastService agvWrkMastService; @Autowired AgvWrkDetlService agvWrkDetlService; @Autowired AgvWaitPakinService agvWaitPakinService; @Autowired AgvLocDetlService agvLocDetlService; public void clearBasDevp(){ agvBasDevpMapper.deleteAll(); } public void initBasDevp(){ // //初始化1楼缓存货架站点 2排5列3层 // this.insertBatch(getCacheBasDevpList(1,2,1,5,1,3,1)); // //初始化3楼缓存货架站点 3排5列3层 // this.insertBatch(getCacheBasDevpList(5,9,1,5,1,3,3)); // //初始化3楼输送线工作站点 4个站点 // this.insertBatch(getLineBasDevpList()); //待包装成品存储区入库接驳位 this.insertBatch(getConnectionBasDevpList("DI",12,2,true,(short)1)); //待包装成品存储区出库接驳位 this.insertBatch(getConnectionBasDevpList("DO",8,2,false,(short)1)); //原材料入库接驳位 this.insertBatch(getConnectionBasDevpList("YI",14,2,true,(short)2)); //原材料出库接驳位 this.insertBatch(getConnectionBasDevpList("YO",18,2,false,(short)2)); //箱壳入库接驳位 this.insertBatch(getConnectionBasDevpList("XI",5,2,true,(short)3)); //箱壳出库接驳位 this.insertBatch(getConnectionBasDevpList("XO",12,2,false,(short)3)); } // private List getLineBasDevpList(){ // List agvBasDevpList = new ArrayList<>(); // Date now = new Date(); // for(int row=1; row<=4; row++){ // agvBasDevpList.add(getAgvBasDevp(row,1,1,3,"N",now)); // } // return agvBasDevpList; // } private List getConnectionBasDevpList(String type, int num, int floor, boolean inEnable, Short locType){ List agvBasDevpList = new ArrayList<>(); Date now = new Date(); for(int index=1; index<=num; index++){ agvBasDevpList.add(getAgvBasDevp(type,index,floor,inEnable,locType,now)); } return agvBasDevpList; } // //根据排列层获取AGV缓存货架站点列表 // private List getCacheBasDevpList(int rowIndex, int rowMax, int bayIndex, int bayMax, int levIndex, int levMax, int floor){ // List agvBasDevpList = new ArrayList<>(); // Date now = new Date(); // for(int row=rowIndex; row<=rowMax; row++){ // for(int bay=bayIndex; bay<=bayMax; bay++){ // for(int lev=levIndex; lev<=levMax; lev++){ // agvBasDevpList.add(getAgvBasDevp(row,bay,lev,floor,"Y",now)); // } // } // } // return agvBasDevpList; // } private AgvBasDevp getAgvBasDevp(int row, int bay, int lev, int floor, String cacheShelves, Date now){ AgvBasDevp agvBasDevp = new AgvBasDevp(); String devNo = "CS-" + floor + "0" + row + "-00" + bay + "-0" + lev + "@" + floor; String stationCode = "CS-" + floor + "0" + row; agvBasDevp.setDevNo(devNo); agvBasDevp.setStationCode(stationCode); agvBasDevp.setLocSts("O"); agvBasDevp.setCacheShelves(cacheShelves); agvBasDevp.setFloor(floor); agvBasDevp.setModiTime(now); agvBasDevp.setAppeTime(now); return agvBasDevp; } private AgvBasDevp getAgvBasDevp(String type, int index, int floor, boolean inEnable, Short locType, Date now){ AgvBasDevp agvBasDevp = new AgvBasDevp(); String no = index >= 10 ? index + "" : "0" + index; String devNo = type + "_" + no + "F" + floor; agvBasDevp.setDevNo(devNo); agvBasDevp.setLocSts("O"); agvBasDevp.setInEnable(inEnable ? "Y" : "N"); agvBasDevp.setOutEnable(inEnable ? "N" : "Y"); agvBasDevp.setFloor(floor); agvBasDevp.setLocType1(locType); agvBasDevp.setModiTime(now); agvBasDevp.setAppeTime(now); return agvBasDevp; } public void updateLocStsAndBarcodeByDevNo(String devNo, String locSts, String barcode, Short containerType){ AgvBasDevp agvBasDevp = this.selectById(devNo); agvBasDevp.setLocSts(locSts); agvBasDevp.setBarcode(barcode); agvBasDevp.setLocType2(containerType); this.updateById(agvBasDevp); } public Map getAgvBasDevpDtoByStationCode(String stationCode) { List> body = new ArrayList<>(); for(int i=3; i>=1; i--){ Wrapper wrapper = new EntityWrapper() .eq("station_code", stationCode) .like("dev_no", "0" + i + "@"); List list = this.selectCacheShelvesStationCodeByFloor(3); if(list.contains(stationCode)){ if(Cools.eq(stationCode,"CS-305") || Cools.eq(stationCode,"CS-306") || Cools.eq(stationCode,"CS-307")){ wrapper.orderBy("dev_no",false); } } List agvBasDevpList = this.selectList(wrapper); Map map = new HashMap<>(); List agvBasDevpDtoList = agvBasDevpList.stream().map(agvBasDevp -> { AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto(); BeanUtils.copyProperties(agvBasDevp, agvBasDevpDto); //如果工作位状态为0.空库位,则直接返回 if("O".equals(agvBasDevpDto.getLocSts())){ return agvBasDevpDto; } //一个工作位可能会对应多个工作档,显示工作状态最大的工作档 List agvWrkMasts = agvWrkMastService.selectList(new EntityWrapper() .eq("loc_no", agvBasDevpDto.getDevNo()) .or().eq("source_loc_no",agvBasDevpDto.getDevNo())); AgvWrkMast agvWrkMast = null; for (AgvWrkMast wrkMast : agvWrkMasts){ if(Cools.isEmpty(agvWrkMast)){ agvWrkMast = wrkMast; }else { if(agvWrkMast.getWrkSts() < wrkMast.getWrkSts()){ agvWrkMast = wrkMast; } } } agvBasDevpDto.setAgvWrkMast(agvWrkMast); if("F".equals(agvBasDevpDto.getLocSts()) || "R".equals(agvBasDevpDto.getLocSts())){ //AgvWaitPakin agvWaitPakin = agvWaitPakinService.selectOne(new EntityWrapper().eq("supp_code", agvBasDevpDto.getBarcode())); List agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper() .eq("supp_code", agvBasDevpDto.getBarcode())); //如果有入库通知档,则该工作位为入库作业 if(!Cools.isEmpty(agvWaitPakinList)){ //用于电视机显示 agvBasDevpDto.setAgvWaitPakins(agvWaitPakinList); //用于可视化站点显示 agvBasDevpDto.setAgvWaitPakin(agvWaitPakinList.get(0)); } //如果没有入库通知档,则该工作位为出库作业 if(Cools.isEmpty(agvWaitPakinList)){ List agvWrkDetlList = agvWrkDetlService.selectList(new EntityWrapper().eq("wrk_no", agvWrkMast.getWrkNo())); //agv站点可视化管理中的结余数量显示 for(AgvWrkDetl agvWrkDetl : agvWrkDetlList){ agvWrkDetl.setVolume(0.0); if(agvWrkMast.getIoType() == 103){ //寻找是否有相同物料的工作档明细,并返回数量之和 double anfme = getAllAnfmeInAgvWrkDetlList(agvWrkDetlList,agvWrkDetl); AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getSourceLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime()); //用于结余数量显示 agvWrkDetl.setVolume(agvLocDetl.getAnfme() - anfme); } if(agvWrkMast.getIoType() == 53){ AgvLocDetl agvLocDetl = agvLocDetlService.selectByMatnrAndBatchAndCsocodeAndisoCode(agvWrkMast.getLocNo(), agvWrkDetl.getMatnr(), agvWrkDetl.getBatch(), agvWrkDetl.getThreeCode(), agvWrkDetl.getDeadTime()); if(Cools.isEmpty(agvLocDetl)){ agvWrkDetl.setVolume(0.0); }else { agvWrkDetl.setVolume(agvLocDetl.getAnfme()); } } } if(!Cools.isEmpty(agvWrkDetlList)){ //用于电视机显示 agvBasDevpDto.setAgvWrkDetls(agvWrkDetlList); //用于可视化站点显示 agvBasDevpDto.setAgvWrkDetl(agvWrkDetlList.get(0)); } } } if(!Cools.isEmpty(agvWrkMast)){ setFlagForAgvBasDevpDto(agvWrkMast,agvBasDevpDto); } return agvBasDevpDto; }).collect(Collectors.toList()); map.put("loc",agvBasDevpDtoList); body.add(map); } Map result = new HashMap<>(); result.put("body", body); return result; } private double getAllAnfmeInAgvWrkDetlList(List agvWrkDetlList, AgvWrkDetl wd0) { double allAnfme = 0; for (AgvWrkDetl wd1 : agvWrkDetlList){ if(Cools.eq(wd0.getMatnr(),wd1.getMatnr()) && Cools.eq(wd0.getBatch(),wd1.getBatch()) && Cools.eq(wd0.getThreeCode(),wd1.getThreeCode()) && Cools.eq(wd0.getDeadTime(),wd1.getDeadTime())){ allAnfme += wd1.getAnfme(); } } return allAnfme; } private void setFlagForAgvBasDevpDto(AgvWrkMast agvWrkMast, AgvBasDevpDto agvBasDevpDto){ //当工作档类型为101.出库 并且 工作位状态为F.在库时,显示容器离场按钮 if(agvWrkMast.getIoType() == 101 && "F".equals(agvBasDevpDto.getLocSts())){ agvBasDevpDto.setContainerMoveOutFlag(true); } //当工作档类型为101.出库 并且 工作位状态为F.在库时,显示容器离场按钮 if(agvWrkMast.getIoType() == 110 && "D".equals(agvBasDevpDto.getLocSts())){ agvBasDevpDto.setContainerMoveOutFlag(true); } //当工作档类型为103.拣料出库 并且 工作位状态为F.在库时,显示拣料/盘点入库按钮 if(agvWrkMast.getIoType() == 103 && "F".equals(agvBasDevpDto.getLocSts())){ agvBasDevpDto.setPickInFlag(true); } //当工作档类型为107.盘点出库 并且 工作位状态为F.在库时,显示拣料/盘点入库按钮 if(agvWrkMast.getIoType() == 107 && "F".equals(agvBasDevpDto.getLocSts())){ agvBasDevpDto.setPickInFlag(true); } } public List getAvailableEmptyInSite() { return this.baseMapper.getAvailableEmptyInSite(); } public AgvBasDevp getByDevNo(String devNo) { return this.selectOne(new EntityWrapper().eq("dev_no",devNo)); } @Override public AgvBasDevp selectEmptyDevpByStation(String stationCode) { return this.selectOne(new EntityWrapper() .eq("station_code", stationCode) .eq("loc_sts", "O")); } @Override public List getBasDevpByNoCacheShelves() { return this.selectList(new EntityWrapper().eq("cache_shelves","N")); } @Override public List selectCacheShelvesStationCodeByFloor(int floor) { //Object o = this.selectList(new EntityWrapper().setSqlSelect("station_code").eq("floor",floor).eq("cache_shelves","Y").groupBy("station_code")); return this.baseMapper.selectCacheShelvesStationCodeByFloor(floor); } @Override public List selectCacheShelvesStationCodeByLocType(short locType) { return this.baseMapper.selectCacheShelvesStationCodeByLocType(locType); } public List> selectDevNoAndNumBystationCode(String stationCode){ return this.baseMapper.selectDevNoAndNumBystationCode(stationCode); } @Override public List selectAllStationCode() { return this.baseMapper.selectAllStationCode(); } @Override public AgvBasDevp selectByDevNo(String devNo) { return this.selectOne(new EntityWrapper().eq("dev_no",devNo)); } }