|  |  |  | 
|---|
|  |  |  | 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.AgvBasDevp; | 
|---|
|  |  |  | import com.zy.asrs.entity.AgvWaitPakin; | 
|---|
|  |  |  | import com.zy.asrs.entity.AgvWrkMast; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.mapper.AgvBasDevpMapper; | 
|---|
|  |  |  | import com.zy.asrs.service.AgvBasDevpService; | 
|---|
|  |  |  | import com.zy.asrs.service.AgvWaitPakinService; | 
|---|
|  |  |  | import com.zy.asrs.service.AgvWrkDetlService; | 
|---|
|  |  |  | import com.zy.asrs.service.AgvWrkMastService; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.common.model.AgvBasDevpDto; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | 
|---|
|  |  |  | AgvWrkDetlService agvWrkDetlService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | AgvWaitPakinService agvWaitPakinService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | AgvLocDetlService agvLocDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void clearBasDevp(){ | 
|---|
|  |  |  | agvBasDevpMapper.deleteAll(); | 
|---|
|  |  |  | 
|---|
|  |  |  | //初始化1楼缓存货架站点 2排5列3层 | 
|---|
|  |  |  | this.insertBatch(getCacheBasDevpList(1,2,1,5,1,3,1)); | 
|---|
|  |  |  | //初始化3楼缓存货架站点 3排5列3层 | 
|---|
|  |  |  | this.insertBatch(getCacheBasDevpList(5,7,1,5,1,3,3)); | 
|---|
|  |  |  | this.insertBatch(getCacheBasDevpList(5,9,1,5,1,3,3)); | 
|---|
|  |  |  | //初始化3楼输送线工作站点 4个站点 | 
|---|
|  |  |  | this.insertBatch(getLineBasDevpList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> body = new ArrayList<>(); | 
|---|
|  |  |  | for(int i=3; i>=1; i--){ | 
|---|
|  |  |  | List<AgvBasDevp> agvBasDevpList = this.selectList(new EntityWrapper<AgvBasDevp>() | 
|---|
|  |  |  | Wrapper<AgvBasDevp> wrapper = new EntityWrapper<AgvBasDevp>() | 
|---|
|  |  |  | .eq("station_code", stationCode) | 
|---|
|  |  |  | .like("dev_no","0"+ i +"@")); | 
|---|
|  |  |  | .like("dev_no", "0" + i + "@"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<String> 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<AgvBasDevp> agvBasDevpList = this.selectList(wrapper); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto(); | 
|---|
|  |  |  | BeanUtils.copyProperties(agvBasDevp, agvBasDevpDto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(agvBasDevpDto.getBarcode())) { | 
|---|
|  |  |  | //如果工作位状态为0.空库位,则直接返回 | 
|---|
|  |  |  | if("O".equals(agvBasDevpDto.getLocSts())){ | 
|---|
|  |  |  | return agvBasDevpDto; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvWaitPakin agvWaitPakin = agvWaitPakinService.selectOne(new EntityWrapper<AgvWaitPakin>() | 
|---|
|  |  |  | .eq("zpallet", agvBasDevpDto.getBarcode())); | 
|---|
|  |  |  | //一个工作位可能会对应多个工作档,显示工作状态最大的工作档 | 
|---|
|  |  |  | List<AgvWrkMast> agvWrkMasts = agvWrkMastService.selectList(new EntityWrapper<AgvWrkMast>() | 
|---|
|  |  |  | .eq("loc_no", agvBasDevpDto.getDevNo()) | 
|---|
|  |  |  | .or().eq("source_loc_no",agvBasDevpDto.getDevNo())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | agvBasDevpDto.setAgvWaitPakin(agvWaitPakin); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>() | 
|---|
|  |  |  | .eq("barcode", agvBasDevpDto.getBarcode())); | 
|---|
|  |  |  | 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<AgvWaitPakin>().eq("supp_code", agvBasDevpDto.getBarcode())); | 
|---|
|  |  |  | List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>() | 
|---|
|  |  |  | .eq("supp_code", agvBasDevpDto.getBarcode())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //如果有入库通知档,则该工作位为入库作业 | 
|---|
|  |  |  | if(!Cools.isEmpty(agvWaitPakinList)){ | 
|---|
|  |  |  | //用于电视机显示 | 
|---|
|  |  |  | agvBasDevpDto.setAgvWaitPakins(agvWaitPakinList); | 
|---|
|  |  |  | //用于可视化站点显示 | 
|---|
|  |  |  | agvBasDevpDto.setAgvWaitPakin(agvWaitPakinList.get(0)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //如果没有入库通知档,则该工作位为出库作业 | 
|---|
|  |  |  | if(Cools.isEmpty(agvWaitPakinList)){ | 
|---|
|  |  |  | List<AgvWrkDetl> agvWrkDetlList = agvWrkDetlService.selectList(new EntityWrapper<AgvWrkDetl>().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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private double getAllAnfmeInAgvWrkDetlList(List<AgvWrkDetl> 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<String> getAvailableEmptyInSite() { | 
|---|
|  |  |  | return this.baseMapper.getAvailableEmptyInSite(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public AgvBasDevp getByDevNo(String devNo) { | 
|---|
|  |  |  | return this.selectOne(new EntityWrapper<AgvBasDevp>().eq("dev_no",devNo)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public AgvBasDevp selectEmptyDevpByStation(String stationCode) { | 
|---|
|  |  |  | return this.selectOne(new EntityWrapper<AgvBasDevp>() | 
|---|
|  |  |  | .eq("station_code", stationCode) | 
|---|
|  |  |  | .eq("loc_sts", "O")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<AgvBasDevp> getBasDevpByNoCacheShelves() { | 
|---|
|  |  |  | return this.selectList(new EntityWrapper<AgvBasDevp>().eq("cache_shelves","N")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<String> selectCacheShelvesStationCodeByFloor(int floor) { | 
|---|
|  |  |  | //Object o = this.selectList(new EntityWrapper<AgvBasDevp>().setSqlSelect("station_code").eq("floor",floor).eq("cache_shelves","Y").groupBy("station_code")); | 
|---|
|  |  |  | return this.baseMapper.selectCacheShelvesStationCodeByFloor(floor); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<Map<String,Object>> selectDevNoAndNumBystationCode(String stationCode){ | 
|---|
|  |  |  | return this.baseMapper.selectDevNoAndNumBystationCode(stationCode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<String> selectAllStationCode() { | 
|---|
|  |  |  | return this.baseMapper.selectAllStationCode(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|