no message
parent
b288a4fab8
commit
8a8b403c0f
|
|
@ -14,7 +14,7 @@ public class ApiResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApiResult fail(String msg) {
|
public static ApiResult fail(String msg) {
|
||||||
return result(400, msg, null);
|
return result(400, msg == null ? "操作失败!" : msg, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApiResult success() {
|
public static ApiResult success() {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import com.youchain.appupdate.response.LesTask;
|
||||||
import com.youchain.businessdata.service.LesService;
|
import com.youchain.businessdata.service.LesService;
|
||||||
import com.youchain.exception.BadRequestException;
|
import com.youchain.exception.BadRequestException;
|
||||||
import com.youchain.utils.BizStatus;
|
import com.youchain.utils.BizStatus;
|
||||||
import com.youchain.utils.UrlApi;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
@ -23,6 +22,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -35,6 +35,12 @@ public class NioF3AppServiceImpl implements NioF3AppService {
|
||||||
private final AgvTaskService agvTaskService;
|
private final AgvTaskService agvTaskService;
|
||||||
private final KMReService kmReService;
|
private final KMReService kmReService;
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, String> LOCK_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private String getLockKey(String srcPositionCode) {
|
||||||
|
return LOCK_MAP.computeIfAbsent(srcPositionCode, k -> k);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
|
@ -48,15 +54,10 @@ public class NioF3AppServiceImpl implements NioF3AppService {
|
||||||
|
|
||||||
// 获取停靠点
|
// 获取停靠点
|
||||||
String beatCode = getBeatCode(lesList);
|
String beatCode = getBeatCode(lesList);
|
||||||
AgvTask agvTask;
|
|
||||||
synchronized (bindSmall.getSrcPositionCode().intern()) {
|
//创建任务
|
||||||
// 验证起点是否有Agv任务
|
AgvTask agvTask=createAgvTask(bindSmall.getSrcPositionCode(), lesIds, beatCode);
|
||||||
validateAgvTask(bindSmall.getSrcPositionCode());
|
|
||||||
// 生成任务
|
|
||||||
agvTask = agvTaskService.createAgvTask(BizStatus.OPEN, null, bindSmall.getSrcPositionCode(), beatCode, "TUGGER");
|
|
||||||
// 绑定任务
|
|
||||||
bindLesAgvTask(agvTask.getId(), lesIds);
|
|
||||||
}
|
|
||||||
// 下发任务
|
// 下发任务
|
||||||
kmReService.sendAgvTask(agvTask, kmReService.sendAgvTaskQYCJson(agvTask, bindSmall.getShooter(), null));
|
kmReService.sendAgvTask(agvTask, kmReService.sendAgvTaskQYCJson(agvTask, bindSmall.getShooter(), null));
|
||||||
}
|
}
|
||||||
|
|
@ -136,20 +137,27 @@ public class NioF3AppServiceImpl implements NioF3AppService {
|
||||||
//获取目标点位
|
//获取目标点位
|
||||||
String beatCode = getBeatCode(lesList);
|
String beatCode = getBeatCode(lesList);
|
||||||
|
|
||||||
AgvTask agvTask;
|
//创建任务
|
||||||
synchronized (bindLarge.getSrcPositionCode().intern()) {
|
AgvTask agvTask = createAgvTask(bindLarge.getSrcPositionCode(), lesIds, beatCode);
|
||||||
// 验证起点是否有Agv任务
|
|
||||||
validateAgvTask(bindLarge.getSrcPositionCode());
|
|
||||||
// 生成任务
|
|
||||||
agvTask = agvTaskService.createAgvTask(BizStatus.OPEN, null, bindLarge.getSrcPositionCode(), beatCode, "TUGGER");
|
|
||||||
// 绑定任务
|
|
||||||
bindLesAgvTask(agvTask.getId(), lesIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
//下发任务
|
//下发任务
|
||||||
kmReService.sendAgvTask(agvTask, kmReService.sendAgvTaskQYCJson(agvTask, boxNos.size(), dollyList));
|
kmReService.sendAgvTask(agvTask, kmReService.sendAgvTaskQYCJson(agvTask, boxNos.size(), dollyList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AgvTask createAgvTask(String srcPositionCode, List<Long> lesIds, String beatCode) {
|
||||||
|
String lockKey = getLockKey(srcPositionCode);
|
||||||
|
synchronized (lockKey) {
|
||||||
|
// 验证起点是否有Agv任务
|
||||||
|
validateAgvTask(srcPositionCode);
|
||||||
|
// 生成任务
|
||||||
|
AgvTask agvTask = agvTaskService.createAgvTask(BizStatus.OPEN, null, srcPositionCode, beatCode, "TUGGER");
|
||||||
|
// 绑定任务
|
||||||
|
bindLesAgvTask(agvTask.getId(), lesIds);
|
||||||
|
return agvTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证参数
|
* 验证参数
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.youchain.businessdata.repository;
|
||||||
import com.youchain.businessdata.domain.Les;
|
import com.youchain.businessdata.domain.Les;
|
||||||
import com.youchain.appupdate.response.LesTask;
|
import com.youchain.appupdate.response.LesTask;
|
||||||
import org.springframework.data.jpa.repository.*;
|
import org.springframework.data.jpa.repository.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface LesRepository extends JpaRepository<Les, Long>, JpaSpecificationExecutor<Les> {
|
public interface LesRepository extends JpaRepository<Les, Long>, JpaSpecificationExecutor<Les> {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import com.youchain.modules.system.repository.DictRepository;
|
||||||
import com.youchain.utils.*;
|
import com.youchain.utils.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -28,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLIntegrityConstraintViolationException;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -110,7 +109,6 @@ public class LesServiceImpl implements LesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void genAgvSchedulingTask(LesRequest lesRequest) {
|
public void genAgvSchedulingTask(LesRequest lesRequest) {
|
||||||
//验证参数有效性
|
//验证参数有效性
|
||||||
validateParams(lesRequest);
|
validateParams(lesRequest);
|
||||||
|
|
@ -128,8 +126,11 @@ public class LesServiceImpl implements LesService {
|
||||||
if (StringUtils.isNotEmpty(materialCode)) {
|
if (StringUtils.isNotEmpty(materialCode)) {
|
||||||
try {
|
try {
|
||||||
createLes(lesRequest, dstPoint);
|
createLes(lesRequest, dstPoint);
|
||||||
} catch (Exception e) {
|
} catch (DataIntegrityViolationException e) {
|
||||||
|
// 数据库唯一约束冲突
|
||||||
throw new BadRequestException(taskCode + "任务号系统已接收,请勿重复操作");
|
throw new BadRequestException(taskCode + "任务号系统已接收,请勿重复操作");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BadRequestException("创建任务失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//直接转发给AGV
|
//直接转发给AGV
|
||||||
|
|
@ -198,7 +199,7 @@ public class LesServiceImpl implements LesService {
|
||||||
String appId = jsonObject.getString("appId");
|
String appId = jsonObject.getString("appId");
|
||||||
String appSecret = jsonObject.getString("appSecret");
|
String appSecret = jsonObject.getString("appSecret");
|
||||||
|
|
||||||
//json参数
|
//jsonBody参数
|
||||||
String jsonBody = this.lesCallBackJson(les.getDstPositionCode(), les.getTaskCode());
|
String jsonBody = this.lesCallBackJson(les.getDstPositionCode(), les.getTaskCode());
|
||||||
|
|
||||||
//生成签名;
|
//生成签名;
|
||||||
|
|
|
||||||
|
|
@ -22,44 +22,41 @@ public class PostRequestSigner {
|
||||||
* @param appSecret 应用密钥
|
* @param appSecret 应用密钥
|
||||||
* @return 生成的签名字符串(小写)
|
* @return 生成的签名字符串(小写)
|
||||||
*/
|
*/
|
||||||
public static String generateSign(String host, String path,
|
public static String generateSign(String host, String path, String jsonBody, String appSecret) {
|
||||||
String jsonBody, String appSecret) {
|
|
||||||
try {
|
try {
|
||||||
// 1. 准备所有需要参与签名的参数
|
// 1. 构建签名源字符串
|
||||||
Map<String, String> allParams = new TreeMap<>(); // TreeMap会自动按key升序排序
|
String signSource = buildSignSource(host, path, jsonBody, appSecret);
|
||||||
|
|
||||||
// 添加JSON Body参数
|
|
||||||
if (StringUtils.isNotBlank(jsonBody)) {
|
|
||||||
allParams.put("jsonBody", jsonBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 拼接参数部分(key=value&key=value形式)
|
|
||||||
StringBuilder paramsStr = new StringBuilder();
|
|
||||||
for (Map.Entry<String, String> entry : allParams.entrySet()) {
|
|
||||||
if (paramsStr.length() > 0) {
|
|
||||||
paramsStr.append("&");
|
|
||||||
}
|
|
||||||
paramsStr.append(entry.getKey()).append("=").append(entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 构建完整的签名字符串
|
|
||||||
StringBuilder signSource = new StringBuilder();
|
|
||||||
signSource.append(path) // PATH
|
|
||||||
.append("POST") // HTTP方法(大写)
|
|
||||||
.append(host) // Host
|
|
||||||
.append("?").append(paramsStr.toString()) // 参数部分
|
|
||||||
.append(appSecret); // appSecret
|
|
||||||
|
|
||||||
|
|
||||||
log.info("签名生成: {}", signSource);
|
log.info("签名生成: {}", signSource);
|
||||||
// 4. 计算SHA256哈希并转为小写字符串
|
|
||||||
return sha256(signSource.toString());
|
// 2. 计算SHA256哈希
|
||||||
|
return sha256(signSource);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BadRequestException("生成签名失败: " + e.getMessage());
|
throw new BadRequestException("生成签名失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建签名源字符串
|
||||||
|
*/
|
||||||
|
private static String buildSignSource(String host, String path, String jsonBody, String appSecret) {
|
||||||
|
|
||||||
|
StringBuilder signSource = new StringBuilder();
|
||||||
|
|
||||||
|
signSource.append(path)
|
||||||
|
.append("POST")
|
||||||
|
.append(host);
|
||||||
|
|
||||||
|
// 只有当jsonBody不为空时才添加参数部分
|
||||||
|
if (StringUtils.isNotBlank(jsonBody)) {
|
||||||
|
signSource.append("?jsonBody=").append(jsonBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
signSource.append(appSecret);
|
||||||
|
|
||||||
|
return signSource.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算字符串的SHA256哈希值
|
* 计算字符串的SHA256哈希值
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue