调度系统接口开发
This commit is contained in:
92
src/main/java/com/zg/common/utils/http/OkHttpUtils.java
Normal file
92
src/main/java/com/zg/common/utils/http/OkHttpUtils.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.zg.common.utils.http;
|
||||
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class OkHttpUtils {
|
||||
|
||||
// 通用客户端配置:10 秒连接,15 秒读/写
|
||||
private static final OkHttpClient client = new OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(15, TimeUnit.SECONDS)
|
||||
.writeTimeout(15, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
|
||||
private static final MediaType FORM = MediaType.get("application/x-www-form-urlencoded");
|
||||
|
||||
/**
|
||||
* GET 请求(不带 header)
|
||||
*/
|
||||
public static String get(String url) {
|
||||
Request request = new Request.Builder().url(url).get().build();
|
||||
return execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET 请求(带自定义 header)
|
||||
*/
|
||||
public static String getWithHeaders(String url, Map<String, String> headers) {
|
||||
Request.Builder builder = new Request.Builder().url(url);
|
||||
if (headers != null) {
|
||||
headers.forEach(builder::addHeader);
|
||||
}
|
||||
return execute(builder.get().build());
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求(表单提交)
|
||||
*/
|
||||
public static String postForm(String url, Map<String, String> formParams) {
|
||||
FormBody.Builder formBuilder = new FormBody.Builder();
|
||||
if (formParams != null) {
|
||||
formParams.forEach(formBuilder::add);
|
||||
}
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(formBuilder.build())
|
||||
.build();
|
||||
return execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求(JSON 提交)
|
||||
*/
|
||||
public static String postJson(String url, String jsonBody) {
|
||||
RequestBody body = RequestBody.create(jsonBody, JSON);
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(body)
|
||||
.build();
|
||||
return execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求(JSON + header)
|
||||
*/
|
||||
public static String postJsonWithHeaders(String url, String jsonBody, Map<String, String> headers) {
|
||||
RequestBody body = RequestBody.create(jsonBody, JSON);
|
||||
Request.Builder builder = new Request.Builder().url(url).post(body);
|
||||
if (headers != null) {
|
||||
headers.forEach(builder::addHeader);
|
||||
}
|
||||
return execute(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行请求
|
||||
*/
|
||||
private static String execute(Request request) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new RuntimeException("请求失败,状态码:" + response.code());
|
||||
}
|
||||
return response.body() != null ? response.body().string() : "";
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("请求异常:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,8 +83,9 @@ public class AgvTaskResultController extends BaseController {
|
||||
if (StringUtils.isBlank(dto.getTaskNo())) {
|
||||
throw new ServiceException("taskNo 不能为空");
|
||||
}
|
||||
agvTaskResultService.handleUpGoods(dto.getTaskNo(), dto.getMaterialStatus());
|
||||
return AjaxResult.success("上架任务已提交至WCS");
|
||||
// 返回 taskId
|
||||
String taskId = agvTaskResultService.handleUpGoods(dto.getTaskNo(), dto.getMaterialStatus());
|
||||
return AjaxResult.success("上架任务已提交至WCS").put("taskId", taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package com.zg.project.wisdom.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.zg.framework.aspectj.lang.annotation.Excel;
|
||||
import com.zg.framework.web.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.zg.framework.aspectj.lang.annotation.Excel;
|
||||
import com.zg.framework.web.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
@@ -13,13 +21,15 @@ public class WcsTaskResult extends BaseEntity {
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 请求ID */
|
||||
/** 请求ID(立库传的是 taskID) */
|
||||
@JsonProperty("taskID")
|
||||
@Excel(name = "请求ID")
|
||||
private String taskId;
|
||||
|
||||
/** 状态 */
|
||||
/** 状态(立库传的是 TaskStatus) */
|
||||
@JsonProperty("TaskStatus")
|
||||
@Excel(name = "状态")
|
||||
private String TaskStatus;
|
||||
private String taskStatus;
|
||||
|
||||
/** 说明 */
|
||||
@Excel(name = "状态说明")
|
||||
@@ -59,7 +69,6 @@ public class WcsTaskResult extends BaseEntity {
|
||||
private String isDelete;
|
||||
|
||||
// Getter / Setter
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -77,11 +86,11 @@ public class WcsTaskResult extends BaseEntity {
|
||||
}
|
||||
|
||||
public String getTaskStatus() {
|
||||
return TaskStatus;
|
||||
return taskStatus;
|
||||
}
|
||||
|
||||
public void setTaskStatus(String TaskStatus) {
|
||||
this.TaskStatus = TaskStatus;
|
||||
public void setTaskStatus(String taskStatus) {
|
||||
this.taskStatus = taskStatus;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
@@ -167,21 +176,21 @@ public class WcsTaskResult extends BaseEntity {
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("taskId", getTaskId())
|
||||
.append("TaskStatus", getTaskStatus())
|
||||
.append("msg", getMsg())
|
||||
.append("jobId", getJobId())
|
||||
.append("owner", getOwner())
|
||||
.append("type", getType())
|
||||
.append("priority", getPriority())
|
||||
.append("sourceName", getSourceName())
|
||||
.append("targetName", getTargetName())
|
||||
.append("isDelete", getIsDelete())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
.append("id", getId())
|
||||
.append("taskId", getTaskId())
|
||||
.append("taskStatus", getTaskStatus())
|
||||
.append("msg", getMsg())
|
||||
.append("jobId", getJobId())
|
||||
.append("owner", getOwner())
|
||||
.append("type", getType())
|
||||
.append("priority", getPriority())
|
||||
.append("sourceName", getSourceName())
|
||||
.append("targetName", getTargetName())
|
||||
.append("isDelete", getIsDelete())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,40 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AgvDTO {
|
||||
|
||||
/** 请求ID(唯一标识此次任务,建议格式:任务号 + 两位后缀) */
|
||||
private String requestId;
|
||||
|
||||
/** 任务编号(可与 requestId 相同,也可为空) */
|
||||
private String taskId;
|
||||
|
||||
/** 作业ID(AGV/WCS系统生成的作业单号) */
|
||||
private String jobId;
|
||||
|
||||
/** 所属者(AGV/WCS系统标识的任务所属单位或系统) */
|
||||
private String owner;
|
||||
|
||||
/** 任务类型(如“inbound”、“outbound”、“move”等) */
|
||||
private String type;
|
||||
|
||||
/** 优先级(如“normal”、“high”等) */
|
||||
private String priority;
|
||||
|
||||
/** 起始位置(如库位编号、货位编码等) */
|
||||
private String sourceName;
|
||||
|
||||
/** 目标位置(如目标库位、货架位置等) */
|
||||
private String targetName;
|
||||
|
||||
/** 创建时间(可传 ISO8601 字符串,也可为空) */
|
||||
private String createdAt;
|
||||
|
||||
/** 更新时间(可传 ISO8601 字符串,也可为空) */
|
||||
private String updatedAt;
|
||||
|
||||
/** 当前状态(必须传。可选值包括:CREATED、ALLOCATED、WAITING_PICK_UP、PICK_UP_COMPLETED、WAITING_TAKE_DOWN、END_ARRIVE、TAKE_DOWN_COMPLETED、FINISHED、FAILURE、PROCESSING 等) */
|
||||
private String status;
|
||||
|
||||
/** 状态说明(可传入本状态的文字描述,例如“任务已完成”) */
|
||||
private String msg;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ package com.zg.project.wisdom.mapper;
|
||||
|
||||
import com.zg.project.wisdom.domain.AgyWcs;
|
||||
|
||||
public interface AgyWcsMapper {
|
||||
int insertAgyWcs(AgyWcs aw);
|
||||
public interface AgvWcsMapper {
|
||||
int insertAgvWcs(AgyWcs aw);
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public interface DdTaskMapper {
|
||||
/**
|
||||
* 根据任务编号更新任务状态
|
||||
*/
|
||||
void updateTaskStatusByTaskNo(String taskNo, int i);
|
||||
int updateTaskStatusByTaskNo(@Param("taskNo") String taskNo, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 根据任务编号查询调度任务
|
||||
|
||||
@@ -28,9 +28,13 @@ public interface IAgvTaskResultService {
|
||||
/** 处理AGV回调 */
|
||||
void handleAgvCallback(AgvDTO dto);
|
||||
|
||||
|
||||
/** 上架 */
|
||||
void handleUpGoods(String taskNo,Integer materialStatus );
|
||||
/**
|
||||
* 上架任务处理(调用 WCS)
|
||||
* @param taskNo 调度任务编号
|
||||
* @param materialStatus 物料状态(0=空托盘,1=有货)
|
||||
* @return 上架任务 taskId
|
||||
*/
|
||||
String handleUpGoods(String taskNo, Integer materialStatus);
|
||||
|
||||
/** 下架 */
|
||||
void handleOutGoods(OutGoodsDTO dto);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.zg.project.wisdom.service;
|
||||
|
||||
import com.zg.framework.web.domain.AjaxResult;
|
||||
import com.zg.project.wisdom.domain.DdTask;
|
||||
import com.zg.project.wisdom.domain.dto.TaskExecuteDTO;
|
||||
import com.zg.project.wisdom.domain.vo.TaskExecuteResultVO;
|
||||
@@ -45,6 +44,8 @@ public interface IDdTaskService {
|
||||
int deleteDdTaskById(Long id);
|
||||
/**
|
||||
* 执行任务
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
TaskExecuteResultVO executeTask(TaskExecuteDTO dto);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.zg.common.utils.DateUtils;
|
||||
import com.zg.common.utils.SecurityUtils;
|
||||
import com.zg.common.utils.StringUtils;
|
||||
import com.zg.common.utils.http.HttpUtils;
|
||||
import com.zg.common.utils.http.OkHttpUtils;
|
||||
import com.zg.project.information.mapper.MtdMapper;
|
||||
import com.zg.project.wisdom.domain.AgvTaskResult;
|
||||
import com.zg.project.wisdom.domain.AgyWcs;
|
||||
@@ -15,7 +16,7 @@ import com.zg.project.wisdom.domain.WcsTaskResult;
|
||||
import com.zg.project.wisdom.domain.dto.AgvDTO;
|
||||
import com.zg.project.wisdom.domain.dto.OutGoodsDTO;
|
||||
import com.zg.project.wisdom.mapper.AgvTaskResultMapper;
|
||||
import com.zg.project.wisdom.mapper.AgyWcsMapper;
|
||||
import com.zg.project.wisdom.mapper.AgvWcsMapper;
|
||||
import com.zg.project.wisdom.mapper.DdTaskMapper;
|
||||
import com.zg.project.wisdom.mapper.WcsTaskResultMapper;
|
||||
import com.zg.project.wisdom.service.IAgvTaskResultService;
|
||||
@@ -46,20 +47,20 @@ public class AgvTaskResultServiceImpl implements IAgvTaskResultService {
|
||||
private MtdMapper mtdMapper;
|
||||
|
||||
@Autowired
|
||||
private AgyWcsMapper agyWcsMapper;
|
||||
private AgvWcsMapper agyWcsMapper;
|
||||
|
||||
// @Value("${agv.job.create-url}")
|
||||
// private String agvJobCreateUrl;
|
||||
//
|
||||
// @Value("${wcs.job.create-url}")
|
||||
// private String wcsJobCreateUrl;
|
||||
|
||||
@Value("${mock.agv-job-create-url}")
|
||||
@Value("${agv.job.create-url}")
|
||||
private String agvJobCreateUrl;
|
||||
|
||||
@Value("${mock.wcs-job-create-url}")
|
||||
@Value("${wcs.job.create-url}")
|
||||
private String wcsJobCreateUrl;
|
||||
|
||||
// @Value("${mock.agv-job-create-url}")
|
||||
// private String agvJobCreateUrl;
|
||||
//
|
||||
// @Value("${mock.wcs-job-create-url}")
|
||||
// private String wcsJobCreateUrl;
|
||||
|
||||
|
||||
@Override
|
||||
public AgvTaskResult selectAgvTaskResultById(Long id) {
|
||||
@@ -123,8 +124,8 @@ public class AgvTaskResultServiceImpl implements IAgvTaskResultService {
|
||||
|
||||
agvTaskResultMapper.insertAgvTaskResult(result);
|
||||
|
||||
// 如果状态为 FINISHED,则将 dd_task 中状态置为 2(已完成)
|
||||
if ("FINISHED".equalsIgnoreCase(dto.getStatus())) {
|
||||
// 如果状态为 TAKE_DOWN_COMPLETED,则将 dd_task 中状态置为 2(已完成)
|
||||
if ("TAKE_DOWN_COMPLETED".equalsIgnoreCase(dto.getStatus())) {
|
||||
ddTaskMapper.updateTaskStatusByTaskNo(taskNo, 2);
|
||||
}
|
||||
|
||||
@@ -135,8 +136,7 @@ public class AgvTaskResultServiceImpl implements IAgvTaskResultService {
|
||||
* @param
|
||||
*/
|
||||
@Override
|
||||
public void handleUpGoods(String taskNo, Integer materialStatus) {
|
||||
String userId = SecurityUtils.getUserId().toString();
|
||||
public String handleUpGoods(String taskNo, Integer materialStatus) {
|
||||
Date now = DateUtils.getNowDate();
|
||||
|
||||
// 1. 查询调度任务
|
||||
@@ -146,12 +146,11 @@ public class AgvTaskResultServiceImpl implements IAgvTaskResultService {
|
||||
}
|
||||
|
||||
// 2. 构造 WCS 请求参数
|
||||
String taskId = taskNo + "21"; // 上架任务编号(taskNo + 21)
|
||||
String taskId = taskNo + "21"; // 上架任务编号(WCS)
|
||||
|
||||
JSONObject wcsParam = new JSONObject();
|
||||
wcsParam.put("TaskID", taskId);
|
||||
wcsParam.put("TrayNo", ""); // 固定空
|
||||
|
||||
wcsParam.put("TrayNo", "");
|
||||
wcsParam.put("Materialstatus", materialStatus);
|
||||
|
||||
if (materialStatus != null && materialStatus == 1) {
|
||||
@@ -166,41 +165,50 @@ public class AgvTaskResultServiceImpl implements IAgvTaskResultService {
|
||||
wcsParam.put("Quantity", "");
|
||||
}
|
||||
|
||||
wcsParam.put("Mlocation", ddTask.getSourceName());
|
||||
wcsParam.put("Tlocation", ddTask.getTargetName());
|
||||
wcsParam.put("Mlocation", ddTask.getTargetName());
|
||||
wcsParam.put("Tlocation", ddTask.getSourceName());
|
||||
|
||||
log.info("[上架] 调用 WCS 接口参数: {}", wcsParam.toJSONString());
|
||||
|
||||
// 3. 发起调用
|
||||
String wcsResp = OkHttpUtils.postJson(wcsJobCreateUrl, wcsParam.toJSONString());
|
||||
|
||||
log.info("[上架] 调用 WCS 接口: {}", wcsParam.toJSONString());
|
||||
String wcsResp = HttpUtils.sendPost(wcsJobCreateUrl, wcsParam.toJSONString());
|
||||
if (StringUtils.isBlank(wcsResp)) {
|
||||
throw new ServiceException("WCS 接口无响应");
|
||||
}
|
||||
|
||||
JSONObject json = JSON.parseObject(wcsResp);
|
||||
if (!Objects.equals(json.getInteger("code"), 0)) {
|
||||
throw new ServiceException("WCS 上架失败:" + json.getString("msg"));
|
||||
|
||||
if (!json.containsKey("result")) {
|
||||
throw new ServiceException("WCS 返回格式异常:" + wcsResp);
|
||||
}
|
||||
|
||||
// 3. 写入 WCS 执行结果记录
|
||||
String result = json.getString("result");
|
||||
if (!"success".equalsIgnoreCase(result)) {
|
||||
throw new ServiceException("WCS 上架失败:" + json.getString("errorMessage"));
|
||||
}
|
||||
|
||||
// 4. 插入执行记录
|
||||
WcsTaskResult wcs = new WcsTaskResult();
|
||||
wcs.setTaskId(taskId);
|
||||
wcs.setTaskStatus("1"); // 等待WCS回调
|
||||
wcs.setMsg(json.getString("msg"));
|
||||
wcs.setTaskStatus("0"); // 成功
|
||||
wcs.setMsg(json.getString("errorMessage"));
|
||||
wcs.setOwner("wms");
|
||||
wcs.setType("1"); // 上架
|
||||
wcs.setType("1");
|
||||
wcs.setPriority("1");
|
||||
wcs.setSourceName(ddTask.getSourceName());
|
||||
wcs.setTargetName(ddTask.getTargetName());
|
||||
wcs.setIsDelete("0");
|
||||
wcs.setCreateBy(userId);
|
||||
wcs.setCreateTime(now);
|
||||
wcs.setUpdateTime(now);
|
||||
wcsTaskResultMapper.insertWcsTaskResult(wcs);
|
||||
|
||||
log.info("[上架] 执行成功,任务 {} 状态已更新为已完成", taskNo);
|
||||
|
||||
// ✅ 返回 taskId
|
||||
return taskId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 货物下架
|
||||
* @param
|
||||
@@ -310,7 +318,7 @@ public class AgvTaskResultServiceImpl implements IAgvTaskResultService {
|
||||
AgyWcs mapping = new AgyWcs();
|
||||
mapping.setRequestId(agvRequestId);
|
||||
mapping.setTaskId(wcsTaskId);
|
||||
agyWcsMapper.insertAgyWcs(mapping);
|
||||
agyWcsMapper.insertAgvWcs(mapping);
|
||||
|
||||
log.info("[下架] AGV 搬运任务提交成功");
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.zg.common.exception.ServiceException;
|
||||
import com.zg.common.utils.DateUtils;
|
||||
import com.zg.common.utils.SecurityUtils;
|
||||
import com.zg.common.utils.StringUtils;
|
||||
import com.zg.common.utils.http.HttpUtils;
|
||||
import com.zg.common.utils.http.OkHttpUtils;
|
||||
import com.zg.project.information.mapper.MtdMapper;
|
||||
import com.zg.project.wisdom.domain.AgvTaskResult;
|
||||
import com.zg.project.wisdom.domain.AgyWcs;
|
||||
@@ -15,7 +15,7 @@ import com.zg.project.wisdom.domain.WcsTaskResult;
|
||||
import com.zg.project.wisdom.domain.dto.TaskExecuteDTO;
|
||||
import com.zg.project.wisdom.domain.vo.TaskExecuteResultVO;
|
||||
import com.zg.project.wisdom.mapper.AgvTaskResultMapper;
|
||||
import com.zg.project.wisdom.mapper.AgyWcsMapper;
|
||||
import com.zg.project.wisdom.mapper.AgvWcsMapper;
|
||||
import com.zg.project.wisdom.mapper.DdTaskMapper;
|
||||
import com.zg.project.wisdom.mapper.WcsTaskResultMapper;
|
||||
import com.zg.project.wisdom.service.IDdTaskService;
|
||||
@@ -49,7 +49,7 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
private MtdMapper mtdMapper;
|
||||
|
||||
@Autowired
|
||||
private AgyWcsMapper agyWcsMapper;
|
||||
private AgvWcsMapper agyWcsMapper;
|
||||
//
|
||||
@Value("${agv.job.create-url}")
|
||||
private String agvJobCreateUrl;
|
||||
@@ -57,6 +57,9 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
@Value("${wcs.job.create-url}")
|
||||
private String wcsJobCreateUrl;
|
||||
|
||||
@Value("${wcs.job.chuku-url}")
|
||||
private String wcsJobChukuUrl;
|
||||
|
||||
// @Value("${mock.agv-job-create-url}")
|
||||
// private String agvJobCreateUrl;
|
||||
//
|
||||
@@ -126,6 +129,8 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -151,8 +156,8 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
String requestId = null;
|
||||
String taskIdParam = null;
|
||||
String response;
|
||||
int code;
|
||||
String msg;
|
||||
int code = 200;
|
||||
String userId = SecurityUtils.getUserId().toString();
|
||||
Date now = DateUtils.getNowDate();
|
||||
|
||||
@@ -161,7 +166,7 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
taskIdParam = taskNo + "22";
|
||||
JSONObject wcsParam = new JSONObject();
|
||||
wcsParam.put("TaskID", taskIdParam);
|
||||
wcsParam.put("TaskType", 2);
|
||||
wcsParam.put("TaskType", 1);
|
||||
wcsParam.put("Mlocation", task.getSourceName());
|
||||
wcsParam.put("TrayNo", "");
|
||||
wcsParam.put("Materialstatus", materialStatus);
|
||||
@@ -181,21 +186,24 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
}
|
||||
|
||||
log.info("[任务执行] 出库 → 调用WCS,taskId={}, param={}", taskIdParam, wcsParam);
|
||||
response = HttpUtils.sendPostJson(wcsJobCreateUrl, wcsParam.toJSONString());
|
||||
response = OkHttpUtils.postJson(wcsJobChukuUrl, wcsParam.toJSONString());
|
||||
|
||||
if (StringUtils.isBlank(response)) {
|
||||
throw new ServiceException("WCS 无响应或返回为空");
|
||||
}
|
||||
|
||||
JSONObject respJson;
|
||||
try {
|
||||
respJson = JSON.parseObject(response);
|
||||
code = respJson.getInteger("code");
|
||||
msg = respJson.getString("msg");
|
||||
String result = respJson.getString("result");
|
||||
msg = respJson.getString("errorMessage");
|
||||
if (!"success".equalsIgnoreCase(result)) {
|
||||
throw new ServiceException("WCS任务执行失败: " + msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("WCS响应解析失败: " + response);
|
||||
}
|
||||
|
||||
if (code != 200) {
|
||||
throw new ServiceException("WCS任务执行失败: " + msg);
|
||||
}
|
||||
|
||||
WcsTaskResult wcs = new WcsTaskResult();
|
||||
wcs.setTaskId(taskIdParam);
|
||||
wcs.setTaskStatus("1");
|
||||
@@ -211,19 +219,19 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
wcs.setUpdateTime(now);
|
||||
wcsTaskResultMapper.insertWcsTaskResult(wcs);
|
||||
|
||||
// 调用 AGV
|
||||
// 调用 AGV(使用 OkHttpUtils)
|
||||
requestId = taskNo + "12";
|
||||
JSONObject agvParam = new JSONObject();
|
||||
agvParam.put("owner", "wms");
|
||||
agvParam.put("type", "1");
|
||||
agvParam.put("priority", 1);
|
||||
agvParam.put("sourceName", task.getSourceName());
|
||||
agvParam.put("sourceName", "v01-010101");
|
||||
agvParam.put("targetName", targetName);
|
||||
agvParam.put("taskNo", taskNo);
|
||||
agvParam.put("requestId", requestId);
|
||||
|
||||
log.info("[任务执行] 出库 → 调用AGV,requestId={}, param={}", requestId, agvParam);
|
||||
response = HttpUtils.sendPostJson(agvJobCreateUrl, agvParam.toJSONString());
|
||||
response = OkHttpUtils.postJson(agvJobCreateUrl, agvParam.toJSONString());
|
||||
|
||||
try {
|
||||
respJson = JSON.parseObject(response);
|
||||
@@ -256,10 +264,10 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
AgyWcs mapping = new AgyWcs();
|
||||
mapping.setRequestId(requestId);
|
||||
mapping.setTaskId(taskIdParam);
|
||||
agyWcsMapper.insertAgyWcs(mapping);
|
||||
agyWcsMapper.insertAgvWcs(mapping);
|
||||
|
||||
} else {
|
||||
// 入库/移库任务 → 调用 AGV
|
||||
// 入库/移库任务 → 调用 AGV(使用 OkHttpUtils)
|
||||
requestId = taskNo + ("0".equals(taskType) ? "11" : "12");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("owner", "wms");
|
||||
@@ -271,7 +279,7 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
param.put("requestId", requestId);
|
||||
|
||||
log.info("[任务执行] 类型={}(AGV),requestId={}, param={}", taskType, requestId, param);
|
||||
response = HttpUtils.sendPostJson(agvJobCreateUrl, param.toJSONString());
|
||||
response = OkHttpUtils.postJson(agvJobCreateUrl, param.toJSONString());
|
||||
|
||||
JSONObject respJson;
|
||||
try {
|
||||
@@ -316,4 +324,4 @@ public class DdTaskServiceImpl implements IDdTaskService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,8 @@ public class WcsTaskResultServiceImpl implements IWcsTaskResultService {
|
||||
result.setTaskId(taskId);
|
||||
result.setTaskStatus(dto.getTaskStatus());
|
||||
result.setMsg(dto.getMsg());
|
||||
result.setJobId(dto.getJobId());
|
||||
result.setOwner(dto.getOwner());
|
||||
result.setType(dto.getType());
|
||||
result.setPriority(dto.getPriority());
|
||||
result.setSourceName(dto.getSourceName());
|
||||
result.setTargetName(dto.getTargetName());
|
||||
result.setCreateBy("wcs");
|
||||
result.setCreateTime(DateUtils.getNowDate());
|
||||
result.setUpdateTime(DateUtils.getNowDate());
|
||||
result.setIsDelete("0");
|
||||
|
||||
wcsTaskResultMapper.insertWcsTaskResult(result);
|
||||
|
||||
@@ -6,8 +6,8 @@ spring:
|
||||
druid:
|
||||
# 主库数据源
|
||||
master:
|
||||
# url: jdbc:mysql://192.168.1.20:3306/wisdom?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://192.168.1.251:3306/wisdom?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://192.168.1.20:3306/wisdom?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# url: jdbc:mysql://192.168.1.251:3306/wisdom?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
# url: jdbc:mysql://localhost:3306/wisdom?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: shzg
|
||||
|
||||
@@ -68,8 +68,8 @@ spring:
|
||||
# redis 配置
|
||||
redis:
|
||||
# 地址
|
||||
# host: 192.168.1.20
|
||||
host: 192.168.1.251
|
||||
host: 192.168.1.20
|
||||
# host: 192.168.1.251
|
||||
# host: localhost
|
||||
# 端口,默认为6379
|
||||
port: 6379
|
||||
@@ -150,8 +150,8 @@ agv:
|
||||
|
||||
wcs:
|
||||
job:
|
||||
create-url: http://192.168.1.230:8188/wcs/task/create
|
||||
|
||||
create-url: http://192.168.1.137:6060/API/Ruku # WCS入库任务接口
|
||||
chuku-url: http://192.168.1.137:6060/API/Chuku # WCS出库任务接口
|
||||
#rfid:
|
||||
# device:
|
||||
# conn-id: 192.168.1.88:9090
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.zg.project.wisdom.mapper.AgyWcsMapper">
|
||||
<mapper namespace="com.zg.project.wisdom.mapper.AgvWcsMapper">
|
||||
|
||||
<resultMap id="AgyWcsResultMap" type="com.zg.project.wisdom.domain.AgyWcs">
|
||||
<id property="id" column="id"/>
|
||||
@@ -12,8 +12,8 @@
|
||||
</resultMap>
|
||||
|
||||
<!-- 插入 AGV-WCS 映射关系 -->
|
||||
<insert id="insertAgyWcs" parameterType="com.zg.project.wisdom.domain.AgyWcs">
|
||||
INSERT INTO agy_wcs (requestId, TaskID)
|
||||
<insert id="insertAgvWcs" parameterType="com.zg.project.wisdom.domain.AgyWcs">
|
||||
INSERT INTO agv_wcs (requestId, TaskID)
|
||||
VALUES (#{requestId}, #{taskId})
|
||||
</insert>
|
||||
|
||||
|
||||
@@ -29,34 +29,18 @@
|
||||
task_id,
|
||||
task_status,
|
||||
msg,
|
||||
job_id,
|
||||
owner,
|
||||
type,
|
||||
priority,
|
||||
source_name,
|
||||
target_name,
|
||||
create_time,
|
||||
update_time,
|
||||
is_delete,
|
||||
create_by,
|
||||
update_by
|
||||
create_by
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
#{taskId},
|
||||
#{TaskStatus},
|
||||
#{taskStatus},
|
||||
#{msg},
|
||||
#{jobId},
|
||||
#{owner},
|
||||
#{type},
|
||||
#{priority},
|
||||
#{sourceName},
|
||||
#{targetName},
|
||||
#{createTime},
|
||||
#{updateTime},
|
||||
#{isDelete},
|
||||
#{createBy},
|
||||
#{updateBy}
|
||||
#{createBy}
|
||||
)
|
||||
</insert>
|
||||
|
||||
@@ -64,7 +48,7 @@
|
||||
SELECT COUNT(*)
|
||||
FROM wcs_task_result
|
||||
WHERE task_id = #{taskId}
|
||||
AND TaskStatus = '1'
|
||||
AND task_status = '1'
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user