package com.zy.core.utils;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.Cools;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.BasCrnp;
|
import com.zy.asrs.entity.HttpRequestLog;
|
import com.zy.asrs.entity.WrkMast;
|
import com.zy.asrs.service.BasCrnpService;
|
import com.zy.asrs.service.HttpRequestLogService;
|
import com.zy.asrs.service.WrkMastService;
|
import com.zy.asrs.utils.Utils;
|
import com.zy.common.service.CommonService;
|
import com.zy.common.utils.HttpHandler;
|
import com.zy.core.News;
|
import com.zy.system.entity.Config;
|
import com.zy.system.service.ConfigService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
|
@Component
|
public class WmsOperateUtils {
|
|
@Autowired
|
private ConfigService configService;
|
@Autowired
|
private HttpRequestLogService httpRequestLogService;
|
@Autowired
|
private WrkMastService wrkMastService;
|
@Autowired
|
private CommonService commonService;
|
@Autowired
|
private BasCrnpService basCrnpService;
|
|
//申请入库任务
|
public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
|
String wmsUrl = null;
|
Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
|
if (wmsSystemUriConfig != null) {
|
wmsUrl = wmsSystemUriConfig.getValue();
|
}
|
|
if (wmsUrl == null) {
|
News.error("未配置WMS系统URI,配置文件Code编码:wmsSystemUri");
|
return null;
|
}
|
|
String wmsSystemInUrl = null;
|
Config wmsSystemInUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemInUrl"));
|
if (wmsSystemInUrlConfig != null) {
|
wmsSystemInUrl = wmsSystemInUrlConfig.getValue();
|
}
|
|
if(wmsSystemInUrlConfig == null){
|
News.error("未配置WMS入库接口地址,配置文件Code编码:wmsSystemInUrl");
|
return null;
|
}
|
|
HashMap<String, Object> requestParam = new HashMap<>();
|
String response = null;
|
try {
|
requestParam.put("barcode", barcode);
|
requestParam.put("sourceStaNo", sourceStaNo);
|
requestParam.put("locType1", locType1);
|
requestParam.put("row", Utils.getInTaskEnableRow());
|
|
response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath(wmsSystemInUrl)
|
.setJson(JSON.toJSONString(requestParam))
|
.build()
|
.doPost();
|
News.info("请求WMS接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
|
} catch (Exception e) {
|
News.error("请求WMS接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response, e);
|
} finally {
|
HttpRequestLog httpRequestLog = new HttpRequestLog();
|
httpRequestLog.setName(wmsUrl + wmsSystemInUrl);
|
httpRequestLog.setRequest(JSON.toJSONString(requestParam));
|
httpRequestLog.setResponse(response);
|
httpRequestLog.setCreateTime(new Date());
|
httpRequestLogService.insert(httpRequestLog);
|
}
|
return response;
|
}
|
|
//申请任务重新分配库位
|
public synchronized String applyReassignTaskLocNo(Integer taskNo) {
|
String wmsUrl = null;
|
Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
|
if (wmsSystemUriConfig != null) {
|
wmsUrl = wmsSystemUriConfig.getValue();
|
}
|
|
if (wmsUrl == null) {
|
News.error("未配置WMS系统URI,配置文件Code编码:wmsSystemUri");
|
return null;
|
}
|
|
String wmsSystemReassignInTaskUrl = null;
|
Config wmsSystemReassignInTaskUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
|
if (wmsSystemReassignInTaskUrlConfig != null) {
|
wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue();
|
}
|
|
if(wmsSystemReassignInTaskUrl == null){
|
News.error("未配置WMS任务重新分配入库库位接口地址,配置文件Code编码:wmsSystemReassignInTaskUrl");
|
return null;
|
}
|
|
WrkMast wrkMast = wrkMastService.selectByWorkNo(taskNo);
|
if (wrkMast == null) {
|
News.info("无法找到对应任务,工作号={}", taskNo);
|
return null;
|
}
|
|
HashMap<String, Object> requestParam = new HashMap<>();
|
String response = null;
|
try {
|
requestParam.put("taskNo", wrkMast.getWmsWrkNo());
|
requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(wrkMast.getCrnNo())));
|
|
response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath(wmsSystemReassignInTaskUrl)
|
.setJson(JSON.toJSONString(requestParam))
|
.build()
|
.doPost();
|
News.info("请求WMS接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
|
} catch (Exception e) {
|
News.error("请求WMS接口异常!!!url:{};request:{}; response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response, e);
|
} finally {
|
HttpRequestLog httpRequestLog = new HttpRequestLog();
|
httpRequestLog.setName(wmsUrl + wmsSystemReassignInTaskUrl);
|
httpRequestLog.setRequest(JSON.toJSONString(requestParam));
|
httpRequestLog.setResponse(response);
|
httpRequestLog.setCreateTime(new Date());
|
httpRequestLogService.insert(httpRequestLog);
|
}
|
return response;
|
}
|
|
//申请在库库位更换库位
|
public synchronized String applyChangeLocNo(String locNo) {
|
String wmsUrl = null;
|
Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
|
if (wmsSystemUriConfig != null) {
|
wmsUrl = wmsSystemUriConfig.getValue();
|
}
|
|
if (wmsUrl == null) {
|
News.error("未配置WMS系统URI,配置文件Code编码:wmsSystemUri");
|
return null;
|
}
|
|
String wmsSystemChangeLocNoUrl = null;
|
Config wmsSystemChangeLocNoUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
|
if (wmsSystemChangeLocNoUrlConfig != null) {
|
wmsSystemChangeLocNoUrl = wmsSystemChangeLocNoUrlConfig.getValue();
|
}
|
|
if(wmsSystemChangeLocNoUrl == null){
|
News.error("未配置申请在库库位更换库位接口地址,配置文件Code编码:wmsSystemChangeLocNoUrl");
|
return null;
|
}
|
|
Integer crnNo = commonService.findCrnNoByLocNo(locNo);
|
if (crnNo == null) {
|
return null;
|
}
|
BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
|
if (basCrnp == null) {
|
return null;
|
}
|
|
List<Integer> crnRows = new ArrayList<>();
|
List<List<Integer>> rowList = basCrnp.getControlRows$();
|
for (List<Integer> list : rowList) {
|
crnRows.addAll(list);
|
}
|
|
HashMap<String, Object> requestParam = new HashMap<>();
|
String response = null;
|
try {
|
requestParam.put("locNo", locNo);
|
requestParam.put("row", crnRows);
|
|
response = new HttpHandler.Builder()
|
.setUri(wmsUrl)
|
.setPath(wmsSystemChangeLocNoUrl)
|
.setJson(JSON.toJSONString(requestParam))
|
.build()
|
.doPost();
|
News.info("请求WMS接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
|
|
return response;
|
} catch (Exception e) {
|
News.error("请求WMS接口异常!!!url:{};request:{};response:{}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response, e);
|
} finally {
|
HttpRequestLog httpRequestLog = new HttpRequestLog();
|
httpRequestLog.setName(wmsUrl + wmsSystemChangeLocNoUrl);
|
httpRequestLog.setRequest(JSON.toJSONString(requestParam));
|
httpRequestLog.setResponse(response);
|
httpRequestLog.setCreateTime(new Date());
|
httpRequestLogService.insert(httpRequestLog);
|
}
|
return null;
|
}
|
|
}
|