From ab14726215678ac69adfeafbd845ebc5b0776ea2 Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期二, 14 一月 2025 14:56:41 +0800
Subject: [PATCH] 优化订单同步逻辑及库位查找
---
src/main/java/com/zy/asrs/service/impl/AgvBasDevpServiceImpl.java | 300 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 271 insertions(+), 29 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/AgvBasDevpServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/AgvBasDevpServiceImpl.java
index fbecf3d..2242247 100644
--- a/src/main/java/com/zy/asrs/service/impl/AgvBasDevpServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/AgvBasDevpServiceImpl.java
@@ -1,16 +1,20 @@
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.zy.asrs.entity.AgvBasDevp;
+import com.core.common.Cools;
+import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.AgvBasDevpMapper;
-import com.zy.asrs.service.AgvBasDevpService;
+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.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
@Service
@Transactional
@@ -18,6 +22,14 @@
@Autowired
AgvBasDevpMapper agvBasDevpMapper;
+ @Autowired
+ AgvWrkMastService agvWrkMastService;
+ @Autowired
+ AgvWrkDetlService agvWrkDetlService;
+ @Autowired
+ AgvWaitPakinService agvWaitPakinService;
+ @Autowired
+ AgvLocDetlService agvLocDetlService;
public void clearBasDevp(){
agvBasDevpMapper.deleteAll();
@@ -25,38 +37,58 @@
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,7,1,5,1,3,3));
- //鍒濆鍖�3妤艰緭閫佺嚎宸ヤ綔绔欑偣 4涓珯鐐�
- this.insertBatch(getLineBasDevpList());
+// //鍒濆鍖�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));
+ //绠卞3鍏ュ簱鎺ラ┏浣�
+ this.insertBatch(getConnectionBasDevpList("XI",5,2,true,(short)3));
+ //绠卞3鍑哄簱鎺ラ┏浣�
+ this.insertBatch(getConnectionBasDevpList("XO",12,2,false,(short)3));
}
- private List<AgvBasDevp> getLineBasDevpList(){
+// private List<AgvBasDevp> getLineBasDevpList(){
+// List<AgvBasDevp> 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<AgvBasDevp> getConnectionBasDevpList(String type, int num, int floor, boolean inEnable, Short locType){
List<AgvBasDevp> agvBasDevpList = new ArrayList<>();
Date now = new Date();
- for(int row=1; row<=4; row++){
- agvBasDevpList.add(getAgvBasDevp(row,1,1,3,"N",now));
+ for(int index=1; index<=num; index++){
+ agvBasDevpList.add(getAgvBasDevp(type,index,floor,inEnable,locType,now));
}
return agvBasDevpList;
}
- //鏍规嵁鎺掑垪灞傝幏鍙朅GV缂撳瓨璐ф灦绔欑偣鍒楄〃
- private List<AgvBasDevp> getCacheBasDevpList(int rowIndex, int rowMax, int bayIndex, int bayMax, int levIndex, int levMax, int floor){
- List<AgvBasDevp> 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;
- }
+// //鏍规嵁鎺掑垪灞傝幏鍙朅GV缂撳瓨璐ф灦绔欑偣鍒楄〃
+// private List<AgvBasDevp> getCacheBasDevpList(int rowIndex, int rowMax, int bayIndex, int bayMax, int levIndex, int levMax, int floor){
+// List<AgvBasDevp> 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();
@@ -72,12 +104,222 @@
return agvBasDevp;
}
- public void updateLocStsAndBarcodeByDevNo(String devNo, String locSts, String barcode){
+ 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<String, Object> getAgvBasDevpDtoByStationCode(String stationCode) {
+
+ List<Map<String, Object>> body = new ArrayList<>();
+ for(int i=3; i>=1; i--){
+ Wrapper<AgvBasDevp> wrapper = new EntityWrapper<AgvBasDevp>()
+ .eq("station_code", stationCode)
+ .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<>();
+
+ List<AgvBasDevpDto> agvBasDevpDtoList = agvBasDevpList.stream().map(agvBasDevp -> {
+ AgvBasDevpDto agvBasDevpDto = new AgvBasDevpDto();
+ BeanUtils.copyProperties(agvBasDevp, agvBasDevpDto);
+
+ //濡傛灉宸ヤ綔浣嶇姸鎬佷负0.绌哄簱浣�,鍒欑洿鎺ヨ繑鍥�
+ if("O".equals(agvBasDevpDto.getLocSts())){
+ return agvBasDevpDto;
+ }
+
+ //涓�涓伐浣滀綅鍙兘浼氬搴斿涓伐浣滄。锛屾樉绀哄伐浣滅姸鎬佹渶澶х殑宸ヤ綔妗�
+ List<AgvWrkMast> agvWrkMasts = agvWrkMastService.selectList(new EntityWrapper<AgvWrkMast>()
+ .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<AgvWaitPakin>().eq("supp_code", agvBasDevpDto.getBarcode()));
+ List<AgvWaitPakin> agvWaitPakinList = agvWaitPakinService.selectList(new EntityWrapper<AgvWaitPakin>()
+ .eq("supp_code", agvBasDevpDto.getBarcode()));
+
+ //濡傛灉鏈夊叆搴撻�氱煡妗o紝鍒欒宸ヤ綔浣嶄负鍏ュ簱浣滀笟
+ if(!Cools.isEmpty(agvWaitPakinList)){
+ //鐢ㄤ簬鐢佃鏈烘樉绀�
+ agvBasDevpDto.setAgvWaitPakins(agvWaitPakinList);
+ //鐢ㄤ簬鍙鍖栫珯鐐规樉绀�
+ agvBasDevpDto.setAgvWaitPakin(agvWaitPakinList.get(0));
+ }
+
+ //濡傛灉娌℃湁鍏ュ簱閫氱煡妗o紝鍒欒宸ヤ綔浣嶄负鍑哄簱浣滀笟
+ 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){
+ //瀵绘壘鏄惁鏈夌浉鍚岀墿鏂欑殑宸ヤ綔妗f槑缁嗭紝骞惰繑鍥炴暟閲忎箣鍜�
+ 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<String, Object> result = new HashMap<>();
+ result.put("body", body);
+
+ 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枡鍑哄簱 骞朵笖 宸ヤ綔浣嶇姸鎬佷负F.鍦ㄥ簱鏃讹紝鏄剧ず鎷f枡/鐩樼偣鍏ュ簱鎸夐挳
+ if(agvWrkMast.getIoType() == 103 && "F".equals(agvBasDevpDto.getLocSts())){
+ agvBasDevpDto.setPickInFlag(true);
+ }
+ //褰撳伐浣滄。绫诲瀷涓�107.鐩樼偣鍑哄簱 骞朵笖 宸ヤ綔浣嶇姸鎬佷负F.鍦ㄥ簱鏃讹紝鏄剧ず鎷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);
+ }
+
+ @Override
+ public List<String> selectCacheShelvesStationCodeByLocType(short locType, int floor) {
+ return this.baseMapper.selectCacheShelvesStationCodeByLocType(locType,floor);
+ }
+ @Override
+ public List<String> selectCacheShelvesStationCodeByLocType2(short locType, int floor) {
+ return this.baseMapper.selectCacheShelvesStationCodeByLocType2(locType,floor);
+ }
+
+ public List<Map<String,Object>> selectDevNoAndNumBystationCode(String stationCode){
+ return this.baseMapper.selectDevNoAndNumBystationCode(stationCode);
+ }
+
+ @Override
+ public List<String> selectAllStationCode() {
+ return this.baseMapper.selectAllStationCode();
+ }
+
+ @Override
+ public AgvBasDevp selectByDevNo(String devNo) {
+ return this.selectOne(new EntityWrapper<AgvBasDevp>().eq("dev_no",devNo));
+ }
+
}
--
Gitblit v1.9.1