opt: redission锁
This commit is contained in:
@@ -497,8 +497,13 @@ public class PdaProductionServiceImpl implements PdaProductionService {
|
|||||||
* 入库
|
* 入库
|
||||||
* @param param
|
* @param param
|
||||||
*/
|
*/
|
||||||
|
@SneakyThrows
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void productionInStorage(JSONObject param, SchBasePoint point) {
|
public void productionInStorage(JSONObject param, SchBasePoint point) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:productionInStorage");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
// 入库库区
|
// 入库库区
|
||||||
String inSect = point.getIn_sect();
|
String inSect = point.getIn_sect();
|
||||||
if (ObjectUtil.isEmpty(inSect)) {
|
if (ObjectUtil.isEmpty(inSect)) {
|
||||||
@@ -528,7 +533,14 @@ public class PdaProductionServiceImpl implements PdaProductionService {
|
|||||||
// 3 创建任务
|
// 3 创建任务
|
||||||
Map<String, Object> jsonMst = defaultPdaBuildParam.buildTaskData(point, invId);
|
Map<String, Object> jsonMst = defaultPdaBuildParam.buildTaskData(point, invId);
|
||||||
rawAssistIStorService.divPoint(jsonMst);
|
rawAssistIStorService.divPoint(jsonMst);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@@ -695,9 +707,14 @@ public class PdaProductionServiceImpl implements PdaProductionService {
|
|||||||
return PdaResponse.requestParamOk(res);
|
return PdaResponse.requestParamOk(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public PdaResponse manualInbound(JSONObject param) {
|
public PdaResponse manualInbound(JSONObject param) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:manualInbound");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
assertNotBlankJson(param, "当前点位不能为空!", "row", "current_point", "vehicle_code");
|
assertNotBlankJson(param, "当前点位不能为空!", "row", "current_point", "vehicle_code");
|
||||||
JSONObject row = param.getJSONObject("row");
|
JSONObject row = param.getJSONObject("row");
|
||||||
String currentPoint = param.getString("current_point");
|
String currentPoint = param.getString("current_point");
|
||||||
@@ -730,11 +747,24 @@ public class PdaProductionServiceImpl implements PdaProductionService {
|
|||||||
// 3 创建任务
|
// 3 创建任务
|
||||||
Map<String, Object> jsonMst = defaultPdaBuildParam.buildTaskData(startPoint, invId);
|
Map<String, Object> jsonMst = defaultPdaBuildParam.buildTaskData(startPoint, invId);
|
||||||
rawAssistIStorService.divPoint(jsonMst);
|
rawAssistIStorService.divPoint(jsonMst);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
return PdaResponse.requestOk();
|
return PdaResponse.requestOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public PdaResponse manualOutbound(JSONObject param) {
|
public PdaResponse manualOutbound(JSONObject param) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:manualOutbound");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
assertNotBlankJson(param, "当前点位不能为空!", "row", "current_point", "vehicle_code");
|
assertNotBlankJson(param, "当前点位不能为空!", "row", "current_point", "vehicle_code");
|
||||||
JSONObject row = param.getJSONObject("row");
|
JSONObject row = param.getJSONObject("row");
|
||||||
String currentPoint = param.getString("current_point");
|
String currentPoint = param.getString("current_point");
|
||||||
@@ -781,6 +811,14 @@ public class PdaProductionServiceImpl implements PdaProductionService {
|
|||||||
ext.put("target", row.getString("station"));
|
ext.put("target", row.getString("station"));
|
||||||
AbstractTask coatingUpTask = taskFactory.getTask("CoatingUpTask");
|
AbstractTask coatingUpTask = taskFactory.getTask("CoatingUpTask");
|
||||||
coatingUpTask.create(ext);
|
coatingUpTask.create(ext);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
return PdaResponse.requestOk();
|
return PdaResponse.requestOk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.nl.wms.sch_manage.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.nl.common.exception.BadRequestException;
|
import org.nl.common.exception.BadRequestException;
|
||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.config.IdUtil;
|
import org.nl.config.IdUtil;
|
||||||
@@ -19,12 +20,15 @@ import org.nl.wms.sch_manage.service.util.tasks.WrappingDownTask;
|
|||||||
import org.nl.wms.sch_manage.service.util.tasks.WrappingUpTask;
|
import org.nl.wms.sch_manage.service.util.tasks.WrappingUpTask;
|
||||||
import org.nl.wms.warehouse_management.service.IMdPbGroupplateService;
|
import org.nl.wms.warehouse_management.service.IMdPbGroupplateService;
|
||||||
import org.nl.wms.warehouse_management.service.dao.GroupPlate;
|
import org.nl.wms.warehouse_management.service.dao.GroupPlate;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -51,10 +55,17 @@ public class SecondaryPackagingServiceImpl implements SecondaryPackagingService
|
|||||||
private EmptyDiskConveyTask emptyDiskConveyTask;
|
private EmptyDiskConveyTask emptyDiskConveyTask;
|
||||||
@Resource(name = "EmptyDiskEnterTask")
|
@Resource(name = "EmptyDiskEnterTask")
|
||||||
private EmptyDiskEnterTask emptyDiskEnterTask;
|
private EmptyDiskEnterTask emptyDiskEnterTask;
|
||||||
|
@Resource
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void palletizingDown(JSONObject param) {
|
public void palletizingDown(JSONObject param) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:palletizingDown");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
// device_code、material_code、qty、vehicle_seq、pcsn、cases
|
// device_code、material_code、qty、vehicle_seq、pcsn、cases
|
||||||
MdMeMaterialbase materialCode = materialbaseService.getByCode(param.getString("material_code"));
|
MdMeMaterialbase materialCode = materialbaseService.getByCode(param.getString("material_code"));
|
||||||
// 组盘
|
// 组盘
|
||||||
@@ -84,10 +95,23 @@ public class SecondaryPackagingServiceImpl implements SecondaryPackagingService
|
|||||||
param.put("vehicle_code", groupPlate.getVehicle_code());
|
param.put("vehicle_code", groupPlate.getVehicle_code());
|
||||||
AbstractTask palletizingDownTask = taskFactory.getTask("PalletizingDownTask");
|
AbstractTask palletizingDownTask = taskFactory.getTask("PalletizingDownTask");
|
||||||
palletizingDownTask.create(param);
|
palletizingDownTask.create(param);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void wrappingCall(JSONObject param) {
|
public void wrappingCall(JSONObject param) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:wrappingCall");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
// 校验任务
|
// 校验任务
|
||||||
Integer num = taskService.haveTaskAll(param.getString("device_code"));
|
Integer num = taskService.haveTaskAll(param.getString("device_code"));
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
@@ -95,10 +119,23 @@ public class SecondaryPackagingServiceImpl implements SecondaryPackagingService
|
|||||||
}
|
}
|
||||||
param.put("config_code", "WrappingUpTask");
|
param.put("config_code", "WrappingUpTask");
|
||||||
wrappingUpTask.create(param);
|
wrappingUpTask.create(param);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void wrappingDown(JSONObject param) {
|
public void wrappingDown(JSONObject param) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:wrappingDown");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
// 校验任务
|
// 校验任务
|
||||||
Integer num = taskService.haveTaskAll(param.getString("device_code"));
|
Integer num = taskService.haveTaskAll(param.getString("device_code"));
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
@@ -106,10 +143,23 @@ public class SecondaryPackagingServiceImpl implements SecondaryPackagingService
|
|||||||
}
|
}
|
||||||
param.put("config_code", "WrappingDownTask");
|
param.put("config_code", "WrappingDownTask");
|
||||||
wrappingDownTask.create(param);
|
wrappingDownTask.create(param);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void palletizingCallEmpty(JSONObject param) {
|
public void palletizingCallEmpty(JSONObject param) {
|
||||||
|
RLock lock = redissonClient.getLock("lock:palletizingCallEmpty");
|
||||||
|
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||||
|
try {
|
||||||
|
if (tryLock) {
|
||||||
// 空盘进入任务、空盘运输任务、
|
// 空盘进入任务、空盘运输任务、
|
||||||
// 校验任务
|
// 校验任务
|
||||||
Integer num = taskService.haveTaskAll(param.getString("device_code"));
|
Integer num = taskService.haveTaskAll(param.getString("device_code"));
|
||||||
@@ -130,5 +180,13 @@ public class SecondaryPackagingServiceImpl implements SecondaryPackagingService
|
|||||||
param.put("point_code2", param.getString("device_code"));
|
param.put("point_code2", param.getString("device_code"));
|
||||||
param.put("config_code", "EmptyDiskEnterTask");
|
param.put("config_code", "EmptyDiskEnterTask");
|
||||||
emptyDiskConveyTask.create(param);
|
emptyDiskConveyTask.create(param);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("速度太快啦,稍后再试...");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tryLock) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user