From 6ab4623447b48d0707cd6e4cf7a9fcd61fc52b0f Mon Sep 17 00:00:00 2001 From: ludj Date: Mon, 15 May 2023 10:16:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=20=E7=94=B3=E8=AF=B7=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/ext/acs/service/AcsToWmsService.java | 7 +++ .../acs/service/impl/AcsToWmsServiceImpl.java | 47 ++++++++++++++----- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/AcsToWmsService.java b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/AcsToWmsService.java index f995719..4fa088b 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/AcsToWmsService.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/AcsToWmsService.java @@ -51,6 +51,13 @@ public interface AcsToWmsService { */ JSONObject apply(JSONObject param) ; + /** + * 带事务 + * @param param + * @return + */ + JSONObject transApply(JSONObject param) ; + /** * ACS机械手给WMS发送任务 * 组盘 diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java index c1e86e7..0a62afe 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java @@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.system.util.CodeUtil; @@ -36,12 +37,16 @@ import org.nl.wms.sch.task.send.material.YZSendMaterialTask; import org.nl.wms.sch.task.to.pack.BTHCToPackageTask; import org.nl.wms.sch.task.to.pack.FJToPackageTask; import org.nl.wms.sch.task.util.TaskUtils; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.lang.reflect.Method; import java.util.Map; +import java.util.concurrent.TimeUnit; @Service @RequiredArgsConstructor @@ -78,6 +83,11 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { private final SZCallMaterialTask szCallMaterialTask; + @Autowired + private RedissonClient redissonClient; + @Autowired + private AcsToWmsService acsToWmsService; + /** * task_id:任务标识 * task_code:任务编码 @@ -199,9 +209,29 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } + @Override + @SneakyThrows + public JSONObject apply(JSONObject jsonObject) { + String type = (String) jsonObject.get("type"); + RLock lock = redissonClient.getLock("acs_to_wms:" + type); + boolean tryLock = lock.tryLock(5, TimeUnit.SECONDS); + try { + if (tryLock) { + return acsToWmsService.transApply(jsonObject); + } + } finally { + if (tryLock) { + lock.unlock(); + } + } + + return null; + } + + @Override @Transactional(rollbackFor = Exception.class) - public JSONObject apply(JSONObject param) { + public JSONObject transApply(JSONObject param) { String point_code = param.getString("device_code"); String type = param.getString("type"); if (StrUtil.isBlank(type)) { @@ -232,6 +262,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { method_param.put("request_param", request_param); method_param.put("create_id", ACSSystem.id); method_param.put("create_name", ACSSystem.nick_name); + switch (type) { case "1": // 送料 @@ -801,8 +832,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { JSONObject data = null; if (!"0000".equals(vehicle_code)) { - data = WQLObject - .getWQLObject("st_ivt_vehicle_detail") + data = WQLObject.getWQLObject("st_ivt_vehicle_detail") .query("is_delete = '0' AND vehicle_type = '" + vehicle_type + "' AND vehicle_code = '" + vehicle_code + "'") .uniqueResult(0); } @@ -840,10 +870,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } else { update.put("vehicle_type", String.valueOf(Integer.parseInt(vehicle_type) + 2)); } - WQLObject - .getWQLObject("sch_base_point") - .update(update, "point_code = '" + point_code + "'"); - + WQLObject.getWQLObject("sch_base_point").update(update, "point_code = '" + point_code + "'"); JSONObject result = new JSONObject(); result.put("status", HttpStatus.OK.value()); @@ -890,8 +917,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { String vehicle_code = point.getString("vehicle_code"); JSONObject data = null; if (StrUtil.isNotBlank(vehicle_code) && !"0000".equals(vehicle_code)) { - data = WQL - .getWO("ACS_TO_WMS") + data = WQL.getWO("ACS_TO_WMS") .addParam("flag", "1") .addParam("vehicle_type", vehicle_type) .addParam("vehicle_code", vehicle_code) @@ -914,8 +940,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } boolean to_package = false; - JSONObject workorder = WQL - .getWO("ACS_TO_WMS") + JSONObject workorder = WQL.getWO("ACS_TO_WMS") .addParam("flag", "2") .addParam("vehicle_code", vehicle_code) .process()