From a5df54bc98fe875c4d17a865f3ee2b50f2e3fcff Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 10 Mar 2025 10:59:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=9A45420=EF=BC=8C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84NC=E5=A4=84=E7=90=86=EF=BC=8C2?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=90=8C=E6=97=B6=E6=93=8D=E4=BD=9C=EF=BC=8C?= =?UTF-8?q?=E4=BA=A7=E7=94=9F2=E7=AC=94move=E6=95=B0=E6=8D=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/busi/MesNcProcessingService.java | 24 ++++++++++++++++++++-- .../ext/mes/pcn/pojo/util/MesPcnExtConstWords.java | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesNcProcessingService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesNcProcessingService.java index e754a9f..97ffb2f 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesNcProcessingService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesNcProcessingService.java @@ -28,13 +28,16 @@ import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel; import cn.estsh.i3plus.pojo.mes.repository.*; import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; import cn.estsh.impp.framework.boot.exception.ImppBusiException; +import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ResultBean; import lombok.extern.slf4j.Slf4j; +import org.redisson.api.RLock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -127,6 +130,9 @@ public class MesNcProcessingService implements IMesNcProcessingService { @Autowired private IMesMoveRuleRepository mesMoveRuleRepository; + @Resource(name = "redisMesPcn") + private ImppRedis redisMesPcn; + @Override public ListPager queryPartInspectionByPager(MesPartInspection partInspection, Pager pager) { @@ -204,8 +210,22 @@ public class MesNcProcessingService implements IMesNcProcessingService { Integer type = model.getType(); MesDefectType person = StringUtil.isEmpty(model.getPerson())?new MesDefectType():model.getPerson(); - //保存数据 - saveDate(model, model.getPart(), type, person, org,model.getInventoryLocationCode(),isOrder); + final String redisKey = MesPcnExtConstWords.SAP_TRANS_JOB_LOCK_TAG + model.getSn(); + RLock rLock = (RLock) redisMesPcn.getLock(redisKey); + try { + //使用tryLock拿不到锁直接返回 + //rlock的leaseTime为-1,会每隔WatchdogTimeout秒去续约 + if (!rLock.tryLock()){ + throw new ImppBusiException(String.format("【%s】此条码正在处理中,不能并发执行!", model.getSn())); + } + + //保存数据 + saveDate(model, model.getPart(), type, person, org,model.getInventoryLocationCode(),isOrder); + } finally { + if (rLock.isHeldByCurrentThread()) { + rLock.unlock(); + } + } } else { Integer type = model.getType(); diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java index 076b45f..71e556c 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java @@ -806,4 +806,5 @@ public class MesPcnExtConstWords { //螺钉包保存生产版本标记 public static final String SAVE_PRODUCT_VERSION_FLAG = "ZFBT"; + public static final String SAP_TRANS_JOB_LOCK_TAG = "MES:JOB:MES_NC_PROCESSING_LOCK_TAG:"; }