Commit 450929e258dec4af0cd0519e23d1d4cf0bfac687

Authored by 谭毅彬
1 parent 01b22adb

对接WCS获取可用巷道API,并设置开关,开关开启时,获取可用巷道库存信息

Signed-off-by: TanYibin <5491541@qq.com>
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java
1 1 package org.jeecg.modules.wms.api.wcs.service;
2 2  
  3 +import java.util.List;
  4 +
3 5 import org.jeecg.common.api.vo.Result;
4 6 import org.jeecg.modules.wms.api.wcs.entity.MaterialInfoEntity;
5 7 import org.jeecg.modules.wms.api.wcs.entity.WarecellDomain;
... ... @@ -58,4 +60,13 @@ public interface WcsService {
58 60 */
59 61 Result manyEmptyOut(String zoneCode, String port, String warehouseCode);
60 62  
  63 + /**
  64 + * 获取可用巷道
  65 + * @author TanYibin
  66 + * @createDate 2023年10月16日
  67 + * @param zoneCode
  68 + * @return
  69 + */
  70 + Result<List<Integer>> getAvailableRowdway(String zoneCode);
  71 +
61 72 }
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java
... ... @@ -41,13 +41,16 @@ import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService;
41 41 import org.jeecg.utils.OkHttpUtils;
42 42 import org.jeecg.utils.StringUtils;
43 43 import org.jeecg.utils.constant.QuantityConstant;
  44 +import org.springframework.cache.annotation.Cacheable;
44 45 import org.springframework.stereotype.Service;
45 46 import org.springframework.transaction.annotation.Transactional;
46 47  
47 48 import com.alibaba.fastjson.JSON;
  49 +import com.alibaba.fastjson.TypeReference;
48 50 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
49 51 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
50 52  
  53 +import cn.hutool.core.collection.CollUtil;
51 54 import cn.monitor4all.logRecord.annotation.OperationLog;
52 55 import cn.monitor4all.logRecord.context.LogRecordContext;
53 56 import lombok.extern.slf4j.Slf4j;
... ... @@ -286,6 +289,34 @@ public class WcsServiceImpl implements WcsService {
286 289 log.info("完成分配库位,任务号:" + taskNo + ", 库位编码:" + locationCode);
287 290 return Result.OK(wcsTask);
288 291 }
  292 +
  293 + @Override
  294 + @Cacheable(cacheNames = "getAvailableRowdway#10", key = "#root.methodName + '_' + #zoneCode", unless = "#result == null ")
  295 + public Result<List<Integer>> getAvailableRowdway(String zoneCode) {
  296 + WcsTask wcsTask = new WcsTask();
  297 + wcsTask.setWarehouseCode(QuantityConstant.DEFAULT_WAREHOUSE);
  298 + List<Integer> resultList = CollUtil.newArrayList(1, 2, 3, 4);
  299 + String value = parameterConfigurationService.getValueByCode(QuantityConstant.RULE_CONNECT_WCS);
  300 + if (StringUtils.isEmpty(value)) {
  301 + throw new JeecgBootException("下发任务时,没有找到连接WCS的数据配置");
  302 + }
  303 + int connectWCS = Integer.parseInt(value);
  304 + if (connectWCS == QuantityConstant.RULE_WCS_CONNECT) {
  305 + String url = addressService.getUrlByParam(QuantityConstant.RULE_AVAILABLE_ROWDWAY, QuantityConstant.DEFAULT_WAREHOUSE, zoneCode);
  306 + String jsonParam = JSON.toJSONString(wcsTask);
  307 + String body = OkHttpUtils.sendPostByJsonStrFast(url, jsonParam);
  308 + if (StringUtils.isEmpty(body)) {
  309 + throw new JeecgBootException("接口地址错误或返回为空,url:" + url);
  310 + }
  311 + Result<List<Integer>> result = JSON.parseObject(body, new TypeReference<Result<List<Integer>>>() {});
  312 + if (result.getCode() != QuantityConstant.HTTP_OK) {
  313 + throw new JeecgBootException(result.getMessage());
  314 + } else {
  315 + return result;
  316 + }
  317 + }
  318 + return Result.OK(resultList);
  319 + }
289 320  
290 321 @Override
291 322 @Transactional(rollbackFor = Exception.class)
... ...
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/shipment/shipmentCombination/service/impl/ShipmentCombinationServiceImpl.java
... ... @@ -10,6 +10,7 @@ import javax.annotation.Resource;
10 10  
11 11 import org.jeecg.common.api.vo.Result;
12 12 import org.jeecg.common.exception.JeecgBootException;
  13 +import org.jeecg.modules.wms.api.wcs.service.WcsService;
13 14 import org.jeecg.modules.wms.config.container.entity.Container;
14 15 import org.jeecg.modules.wms.config.container.service.IContainerService;
15 16 import org.jeecg.modules.wms.config.location.entity.Location;
... ... @@ -48,12 +49,14 @@ import org.jeecg.utils.constant.QuantityConstant;
48 49 import org.springframework.beans.factory.annotation.Autowired;
49 50 import org.springframework.stereotype.Service;
50 51 import org.springframework.transaction.annotation.Transactional;
  52 +import org.springframework.util.CollectionUtils;
51 53  
52 54 import com.alibaba.fastjson.JSON;
53 55 import com.aliyun.oss.ServiceException;
54 56 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
55 57 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
56 58  
  59 +import cn.hutool.core.collection.CollUtil;
57 60 import cn.monitor4all.logRecord.annotation.OperationLog;
58 61 import cn.monitor4all.logRecord.context.LogRecordContext;
59 62 import lombok.extern.slf4j.Slf4j;
... ... @@ -67,37 +70,55 @@ public class ShipmentCombinationServiceImpl implements IShipmentCombinationServi
67 70  
68 71 @Autowired
69 72 private IShipmentCombinationService shipmentCombinationService;
  73 +
70 74 @Autowired
71 75 private IInventoryDetailService inventoryDetailService;
  76 +
72 77 @Autowired
73 78 private IShipmentHeaderService shipmentHeaderService;
  79 +
74 80 @Autowired
75 81 private IShipmentDetailService shipmentDetailService;
  82 +
76 83 @Autowired
77 84 private IReceiptContainerHeaderService receiptContainerHeaderService;
  85 +
78 86 @Autowired
79 87 private IShipmentContainerHeaderService shipmentContainerHeaderService;
  88 +
80 89 @Autowired
81 90 private IContainerService containerService;
  91 +
82 92 @Autowired
83 93 private ILocationService locationService;
  94 +
84 95 @Resource
85 96 private IZoneService zoneService;
  97 +
86 98 @Autowired
87 99 private IShipmentContainerDetailService shipmentContainerDetailService;
  100 +
88 101 @Autowired
89 102 private IMaterialService materialService;
  103 +
90 104 @Autowired
91 105 private IParameterConfigurationService parameterConfigurationService;
  106 +
92 107 @Autowired
93 108 private ITaskHeaderService taskHeaderService;
  109 +
94 110 @Autowired
95 111 private ITaskDetailService taskDetailService;
  112 +
96 113 @Autowired
97 114 private IInventoryHeaderService inventoryHeaderService;
  115 +
98 116 @Resource
99 117 private IInventoryTransactionService inventoryTransactionService;
100 118  
  119 + @Resource
  120 + private WcsService wcsService;
  121 +
101 122 /**
102 123 * 根据出库单详情,匹配到可用出库的库存详情
103 124 * 默认匹配条件是 仓库,货主,物料编码,库存状态,批次 是一致的就可以出库
... ... @@ -138,6 +159,14 @@ public class ShipmentCombinationServiceImpl implements IShipmentCombinationServi
138 159 }
139 160 }
140 161 List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
  162 + String availableRowdwayStatus = parameterConfigurationService.getValueByCode(QuantityConstant.AVAILABLE_ROWDWAY_OPEN);
  163 + if (!CollectionUtils.isEmpty(inventoryDetailList) && QuantityConstant.AVAILABLE_ROWDWAY_OPEN.equals(availableRowdwayStatus)) {
  164 + Result<List<Integer>> result = wcsService.getAvailableRowdway(zoneCode);
  165 + if (!result.isSuccess() || CollectionUtils.isEmpty(result.getResult())) {
  166 + return CollUtil.newArrayList();
  167 + }
  168 + inventoryDetailList = inventoryDetailList.stream().filter(t -> result.getResult().contains(t.getRoadWay())).collect(Collectors.toList());
  169 + }
141 170 return inventoryDetailList;
142 171 }
143 172  
... ...
huaheng-wms-core/src/main/java/org/jeecg/utils/OkHttpUtils.java
... ... @@ -41,7 +41,7 @@ public class OkHttpUtils {
41 41 /**
42 42 * 最多重试次数
43 43 */
44   - public final static int MAX_RENTRY_COUNT = 3;
  44 + public final static int MAX_RENTRY_COUNT = 1;
45 45  
46 46 /**
47 47 * 最大连接时间(秒)
... ... @@ -51,12 +51,12 @@ public class OkHttpUtils {
51 51 /**
52 52 * 最大读取时间(秒)
53 53 */
54   - public final static int READ_TIMEOUT = 30;
  54 + public final static int READ_TIMEOUT = 20;
55 55  
56 56 /**
57 57 * 最大写入时间(秒)
58 58 */
59   - public final static int WRITE_TIMEOUT = 30;
  59 + public final static int WRITE_TIMEOUT = 20;
60 60  
61 61 /**
62 62 * JSON格式
... ... @@ -72,6 +72,22 @@ public class OkHttpUtils {
72 72 * OkHTTP线程池空闲线程存活时间(秒)
73 73 */
74 74 public final static long KEEP_ALIVE_DURATION = 60;
  75 +
  76 + /**
  77 + * 最大读取时间(秒)
  78 + */
  79 + public final static int READ_TIMEOUT_FAST = 5;
  80 +
  81 + /**
  82 + * 最大写入时间(秒)
  83 + */
  84 + public final static int WRITE_TIMEOUT_FAST = 5;
  85 +
  86 + /**
  87 + * 最多重试次数
  88 + */
  89 + public final static int MAX_RENTRY_COUNT_FAST = 0;
  90 +
75 91  
76 92 private static final String CONTENT_TYPE = "Content-Type";
77 93  
... ... @@ -81,6 +97,12 @@ public class OkHttpUtils {
81 97 .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new OkHttpUtils.OkhttpInterceptor(MAX_RENTRY_COUNT)) // 过滤器,设置最大重试次数
82 98 .retryOnConnectionFailure(false).connectionPool(new ConnectionPool(MAX_IDLE_CONNECTIONS, KEEP_ALIVE_DURATION, TimeUnit.SECONDS)).build();
83 99  
  100 + /** 访问接口参数配置 */
  101 + private final static OkHttpClient HTTP_CLIENT_FAST =
  102 + new OkHttpClient.Builder().connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS).readTimeout(READ_TIMEOUT_FAST, TimeUnit.SECONDS)
  103 + .writeTimeout(WRITE_TIMEOUT_FAST, TimeUnit.SECONDS).addInterceptor(new OkHttpUtils.OkhttpInterceptor(MAX_RENTRY_COUNT_FAST)) // 过滤器,设置最大重试次数
  104 + .retryOnConnectionFailure(false).connectionPool(new ConnectionPool(MAX_IDLE_CONNECTIONS, KEEP_ALIVE_DURATION, TimeUnit.SECONDS)).build();
  105 +
84 106 /**
85 107 * 向指定 URL 发送GET方法的请求
86 108 * @param url 发送请求的 URL
... ... @@ -171,6 +193,50 @@ public class OkHttpUtils {
171 193 }
172 194 return result;
173 195 }
  196 +
  197 + /**
  198 + * JSONString形式发送POST请求
  199 + * @throws Exception
  200 + * @throws IOException
  201 + */
  202 + public static String sendPostByJsonStrFast(String url, Map<String, String> headers, String jsonString) {
  203 + String result = null;
  204 + if (StringUtils.isEmpty(url)) {
  205 + return result;
  206 + }
  207 + ApiLog apiLog = new ApiLog();
  208 + headers.put("Accept", "application/json");// 设置接收数据的格式
  209 + headers.put("Content-Type", "application/json");// 设置发送数据的格式
  210 + Request.Builder builder = new Request.Builder();
  211 + buildHeader(builder, headers);
  212 + RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, jsonString);
  213 + Request request = builder.url(url).post(body).build();
  214 + Response response = null;
  215 + try {
  216 + ApiLoggerAspect.initApiLog(apiLog, request, jsonString);
  217 + response = HTTP_CLIENT_FAST.newCall(request).execute();
  218 + result = response.body().string();
  219 + } catch (Exception e) {
  220 + String errorString = StrUtil.format("执行POST请求异常,url: {},{}", url, ExceptionUtil.getMessage(e));
  221 + log.error(errorString, e);
  222 + ApiLoggerAspect.setApiLogException(apiLog, e);
  223 + throw new JeecgBootException(errorString, e);
  224 + } finally {
  225 + ApiLoggerAspect.finishApiLog(apiLog, response, result);
  226 + }
  227 + // 调用成功
  228 + if (response.isSuccessful() && Objects.nonNull(response.body())) {
  229 + log.info("执行POST请求成功,url: {},result: {}", url, result);
  230 + } else {
  231 + throw new JeecgBootException(StrUtil.format("执行POST请求失败,url: {},responseCode: {},responseMessage: {}", url, JSON.toJSONString(headers), jsonString,
  232 + response.code(), response.message()));
  233 + }
  234 + return result;
  235 + }
  236 +
  237 + public static String sendPostByJsonStrFast(String url, String jsonString) {
  238 + return sendPostByJsonStrFast(url, new HashMap<String, String>(), jsonString);
  239 + }
174 240  
175 241 /**
176 242 * 设置请求头
... ...
huaheng-wms-core/src/main/java/org/jeecg/utils/constant/QuantityConstant.java
... ... @@ -511,6 +511,15 @@ public class QuantityConstant {
511 511 * 出库依赖库区
512 512 */
513 513 public static final int SHIPMENT_BY_ZONE = 1;
  514 +
  515 + /** 获取可用巷道:关 */
  516 + public static final String AVAILABLE_ROWDWAY_CLOSE = "0";
  517 +
  518 + /** 获取可用巷道:开 */
  519 + public static final String AVAILABLE_ROWDWAY_OPEN = "1";
  520 +
  521 + /** 获取可用巷道:开 */
  522 + public static final String RULE_AVAILABLE_ROWDWAY = "RULE_AVAILABLE_ROWDWAY";
514 523  
515 524 public static final int RULE_TASK_NOT_CLEAR = 0;
516 525 public static final int RULE_TASK_AllOW_CLEAR = 1;
... ...