add:pda获取acs指令列表,手工完成

This commit is contained in:
zhaoyf
2026-10-27 14:06:04 +08:00
parent 12bfa78e5e
commit f11fd7d55a
10 changed files with 574 additions and 0 deletions

View File

@@ -1,12 +1,15 @@
package org.nl.wms.ext_manage.api;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.exception.BadRequestException;
import org.nl.wms.ext_manage.enums.EXTConstant;
import org.nl.wms.ext_manage.util.AcsUtil;
import org.springframework.http.ResponseEntity;import org.nl.common.base.ResponseData;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* <p>
@@ -23,4 +26,26 @@ public class AcsApi {
public <T> ResponseEntity renotifyAcs(List<T> list) {
return AcsUtil.notifyAcs(EXTConstant.SEND_TASK_ACS_API, list);
}
/**
* 查询手动配送指令(执行中、未删除)
*
* @param params task_code/start_point_code/next_point_code/vehicle_code/manual
* @return {content:[], totalElements:0}
*/
public JSONObject queryManualDelivery(Map<String, Object> params) {
return AcsUtil.getAcs(EXTConstant.QUERY_MANUAL_DELIVERY_ACS_API, params);
}
/**
* 完成ACS指令
*
* @param instructionId 指令标识
*/
public void finishInstruction(String instructionId) {
if (instructionId == null || instructionId.trim().isEmpty()) {
throw new BadRequestException("指令ID不能为空");
}
AcsUtil.postAcs(EXTConstant.FINISH_INSTRUCTION_ACS_API + instructionId.trim());
}
}

View File

@@ -25,6 +25,16 @@ public class EXTConstant {
*/
public final static String SEND_TASK_ACS_API = "api/wms/task";
/**
* ACS查询手动配送指令(GET)
*/
public final static String QUERY_MANUAL_DELIVERY_ACS_API = "api/instruction/manualDelivery";
/**
* ACS指令完成(POST,后接指令ID)
*/
public final static String FINISH_INSTRUCTION_ACS_API = "api/instruction/finish/";
/**
* 中鼎查询库存接口地址
*/

View File

@@ -15,6 +15,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;import org.nl.common.base.ResponseData;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* <p>
* ACS工具类
@@ -74,4 +76,104 @@ public class AcsUtil {
}
}
/**
* 解析ACS请求地址(校验连接开关与地址参数)
*
* @param api ACS接口相对地址
*/
private static String resolveAcsUrl(String api) {
SysParamServiceImpl sysParamService = SpringContextHolder.getBean(SysParamServiceImpl.class);
Param isConnectAcs = sysParamService.findByCode(SysParamConstant.IS_CONNECT_ACS);
if (ObjectUtil.isEmpty(isConnectAcs)) {
throw new BadRequestException("系统参数表中:" + SysParamConstant.IS_CONNECT_ACS + "不存在");
}
if (isConnectAcs.getValue().equals(IOSConstant.IS_DELETE_NO)) {
throw new BadRequestException("未连接ACS系统,无法执行该操作");
}
Param acsUrlParam = sysParamService.findByCode(SysParamConstant.ACS_URL);
if (ObjectUtil.isEmpty(acsUrlParam)) {
throw new BadRequestException("系统参数表中:" + SysParamConstant.ACS_URL + "不存在");
}
return acsUrlParam.getValue() + api;
}
/**
* 校验ACS返回体:兼容 {status:200} 包装与直接返回业务对象两种格式
*/
private static JSONObject checkAcsBody(String bodyText) {
if (bodyText == null || bodyText.trim().isEmpty()) {
return new JSONObject();
}
JSONObject body;
try {
body = JSONObject.parseObject(bodyText);
} catch (Exception e) {
throw new BadRequestException("ACS返回结果解析失败:" + bodyText);
}
if (body != null && body.containsKey("status")) {
Integer status = body.getInteger("status");
if (!Integer.valueOf(HttpStatus.OK.value()).equals(status)) {
throw new BadRequestException("ACS处理失败:" + body.getString("message"));
}
}
return body == null ? new JSONObject() : body;
}
/**
* GET方式查询ACS接口
*
* @param api ACS接口相对地址
* @param params 查询参数(空值不传递)
* @return ACS返回体
*/
public static JSONObject getAcs(String api, Map<String, Object> params) {
String url = resolveAcsUrl(api);
log.info("查询ACS接口:{},参数:{}", url, params);
try {
HttpRequest request = HttpRequest.get(url).timeout(15000);
if (params != null) {
params.forEach((key, value) -> {
if (value != null && !String.valueOf(value).trim().isEmpty()) {
request.form(key, value);
}
});
}
HttpResponse response = request.execute();
if (response.getStatus() != HttpStatus.OK.value()) {
log.error("查询ACS失败,HTTP {},返回:{}", response.getStatus(), response.body());
throw new BadRequestException("查询ACS失败,HTTP " + response.getStatus());
}
return checkAcsBody(response.body());
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("连接ACS失败:{}", e.getMessage());
throw new BadRequestException("ACS通讯异常:" + e.getMessage());
}
}
/**
* POST方式调用ACS接口(无请求体)
*
* @param api ACS接口相对地址
* @return ACS返回体
*/
public static JSONObject postAcs(String api) {
String url = resolveAcsUrl(api);
log.info("调用ACS接口:{}", url);
try {
HttpResponse response = HttpRequest.post(url).timeout(15000).execute();
if (response.getStatus() != HttpStatus.OK.value()) {
log.error("调用ACS失败,HTTP {},返回:{}", response.getStatus(), response.body());
throw new BadRequestException("调用ACS失败,HTTP " + response.getStatus());
}
return checkAcsBody(response.body());
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
log.error("连接ACS失败:{}", e.getMessage());
throw new BadRequestException("ACS通讯异常:" + e.getMessage());
}
}
}

View File

@@ -0,0 +1,46 @@
package org.nl.wms.pda_manage.acs_manage.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.base.ResponseData;
import org.nl.common.logging.annotation.Log;
import org.nl.wms.pda_manage.acs_manage.service.PdaAcsInstructionService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* 手持 ACS 任务(指令)查询与手工完成
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/pda/acs")
@Slf4j
@SaIgnore
public class PdaAcsInstructionController {
private final PdaAcsInstructionService acsInstructionService;
@GetMapping("/instructions")
@Log("PDA查询ACS手动配送指令")
@SaIgnore
public ResponseEntity<Object> instructions(@RequestParam(required = false) String taskCode,
@RequestParam(required = false) String startPointCode,
@RequestParam(required = false) String nextPointCode,
@RequestParam(required = false) String vehicleCode,
@RequestParam(required = false) String manual,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "20") int size) {
return ResponseData.build(acsInstructionService.listInstructions(taskCode, startPointCode, nextPointCode,
vehicleCode, manual, page, size), HttpStatus.OK);
}
@PostMapping("/finish/{instructionId}")
@Log("PDA手工完成ACS指令")
@SaIgnore
public ResponseEntity<Object> finish(@PathVariable String instructionId) {
acsInstructionService.finishInstruction(instructionId);
return ResponseData.build("指令已完成", HttpStatus.OK);
}
}

View File

@@ -0,0 +1,31 @@
package org.nl.wms.pda_manage.acs_manage.service;
import com.alibaba.fastjson.JSONObject;
/**
* 手持 ACS 指令查询与操作
*/
public interface PdaAcsInstructionService {
/**
* 查询ACS手动配送指令(执行中、未删除)
*
* @param taskCode 任务号(模糊)
* @param startPointCode 起点(模糊)
* @param nextPointCode 终点(模糊)
* @param vehicleCode 载具(模糊)
* @param manual 是否手工任务 0否1是,空为全部
* @param page 页码,从1开始
* @param size 每页条数
* @return {total, records}
*/
JSONObject listInstructions(String taskCode, String startPointCode, String nextPointCode,
String vehicleCode, String manual, int page, int size);
/**
* 手工完成ACS指令
*
* @param instructionId 指令标识
*/
void finishInstruction(String instructionId);
}

View File

@@ -0,0 +1,63 @@
package org.nl.wms.pda_manage.acs_manage.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.nl.wms.ext_manage.api.AcsApi;
import org.nl.wms.pda_manage.acs_manage.service.PdaAcsInstructionService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 手持 ACS 指令查询与操作实现
*/
@Service
public class PdaAcsInstructionServiceImpl implements PdaAcsInstructionService {
@Resource
private AcsApi acsApi;
@Override
public JSONObject listInstructions(String taskCode, String startPointCode, String nextPointCode,
String vehicleCode, String manual, int page, int size) {
Map<String, Object> params = new HashMap<>();
params.put("task_code", StringUtils.trimToNull(taskCode));
params.put("start_point_code", StringUtils.trimToNull(startPointCode));
params.put("next_point_code", StringUtils.trimToNull(nextPointCode));
params.put("vehicle_code", StringUtils.trimToNull(vehicleCode));
params.put("manual", StringUtils.trimToNull(manual));
JSONObject body = acsApi.queryManualDelivery(params);
// ACS 侧不分页,全量返回后按页码本地切片
JSONArray content = body == null ? null : body.getJSONArray("content");
List<JSONObject> all = new ArrayList<>();
if (content != null) {
for (int i = 0; i < content.size(); i++) {
all.add(content.getJSONObject(i));
}
}
int pageNo = page <= 0 ? 1 : page;
int pageSize = size <= 0 || size > 200 ? 20 : size;
int from = Math.min((pageNo - 1) * pageSize, all.size());
int to = Math.min(from + pageSize, all.size());
long total = 0;
if (body != null) {
total = body.getLongValue("totalElements");
}
JSONObject result = new JSONObject();
result.put("total", total > 0 ? total : all.size());
result.put("records", new ArrayList<>(all.subList(from, to)));
return result;
}
@Override
public void finishInstruction(String instructionId) {
acsApi.finishInstruction(instructionId);
}
}