|
@ -44,8 +44,6 @@ import java.util.concurrent.TimeUnit; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class AcsToWmsServiceImpl implements AcsToWmsService { |
|
|
public class AcsToWmsServiceImpl implements AcsToWmsService { |
|
|
|
|
|
|
|
|
private final RedissonClient redissonClient; |
|
|
|
|
|
|
|
|
|
|
|
private final HLCallEmptyTask hlCallEmptyTask; |
|
|
private final HLCallEmptyTask hlCallEmptyTask; |
|
|
|
|
|
|
|
|
private final HLSendMaterialTask hlSendMaterialTask; |
|
|
private final HLSendMaterialTask hlSendMaterialTask; |
|
@ -187,155 +185,142 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public JSONObject apply(JSONObject param) { |
|
|
public JSONObject apply(JSONObject param) { |
|
|
String point_code = param.getString("device_code"); |
|
|
String point_code = param.getString("device_code"); |
|
|
if (StrUtil.isBlank(point_code)) { |
|
|
|
|
|
throw new BadRequestException("点位不能为空!"); |
|
|
|
|
|
} |
|
|
|
|
|
String type = param.getString("type"); |
|
|
String type = param.getString("type"); |
|
|
if (StrUtil.isBlank(type)) { |
|
|
if (StrUtil.isBlank(type)) { |
|
|
throw new BadRequestException("任务类型不能为空!"); |
|
|
throw new BadRequestException("任务类型不能为空!"); |
|
|
} |
|
|
} |
|
|
RLock lock = redissonClient.getFairLock("acs_to_wms:" + point_code); |
|
|
String task_code; |
|
|
boolean try_lock = false; |
|
|
JSONObject point = param.getJSONObject("point"); |
|
|
String task_code = null; |
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
try { |
|
|
point = WQLObject |
|
|
try_lock = lock.tryLock(5, TimeUnit.SECONDS); |
|
|
.getWQLObject("sch_base_point") |
|
|
if (try_lock) { |
|
|
.query("is_used = '1' AND point_code = '" + point_code + "'") |
|
|
JSONObject point = param.getJSONObject("point"); |
|
|
.uniqueResult(0); |
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
point = WQLObject |
|
|
throw new BadRequestException("[" + point_code + "] 已删除或未启用!"); |
|
|
.getWQLObject("sch_base_point") |
|
|
} |
|
|
.query("is_used = '1' AND point_code = '" + point_code + "'") |
|
|
} |
|
|
.uniqueResult(0); |
|
|
TaskUtils.isLocked(point); |
|
|
if (ObjectUtil.isEmpty(point)) { |
|
|
|
|
|
throw new BadRequestException("[" + point_code + "] 已删除或未启用!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
TaskUtils.isLocked(point); |
|
|
|
|
|
|
|
|
|
|
|
Region region = Region.get(point.getString("region_code")); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject method_param = new JSONObject(); |
|
|
Region region = Region.get(point.getString("region_code")); |
|
|
method_param.put("point", point); |
|
|
|
|
|
method_param.put("create_mode", CreateMode.ACSSQ.value()); |
|
|
JSONObject method_param = new JSONObject(); |
|
|
String request_param = param.getString("request_param"); |
|
|
method_param.put("point", point); |
|
|
if (StrUtil.isBlank(request_param)) { |
|
|
method_param.put("create_mode", CreateMode.ACSSQ.value()); |
|
|
request_param = param.toJSONString(); |
|
|
String request_param = param.getString("request_param"); |
|
|
|
|
|
if (StrUtil.isBlank(request_param)) { |
|
|
|
|
|
request_param = param.toJSONString(); |
|
|
|
|
|
} |
|
|
|
|
|
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": |
|
|
|
|
|
// 送料
|
|
|
|
|
|
String vehicle_code = TaskUtils.formatVehicleCode(param.getString("vehicle_code")); |
|
|
|
|
|
if ("0000".equals(vehicle_code)) { |
|
|
|
|
|
throw new BadRequestException("载具编码不能为空!"); |
|
|
} |
|
|
} |
|
|
method_param.put("request_param", request_param); |
|
|
method_param.put("vehicle_code", vehicle_code); |
|
|
method_param.put("create_id", ACSSystem.id); |
|
|
|
|
|
method_param.put("create_name", ACSSystem.nick_name); |
|
|
switch (region) { |
|
|
switch (type) { |
|
|
case HL: |
|
|
case "1": |
|
|
|
|
|
// 送料
|
|
|
|
|
|
String vehicle_code = TaskUtils.formatVehicleCode(param.getString("vehicle_code")); |
|
|
|
|
|
if ("0000".equals(vehicle_code)) { |
|
|
|
|
|
throw new BadRequestException("载具编码不能为空!"); |
|
|
|
|
|
} |
|
|
|
|
|
method_param.put("vehicle_code", vehicle_code); |
|
|
|
|
|
|
|
|
|
|
|
switch (region) { |
|
|
|
|
|
case HL: |
|
|
|
|
|
JSONObject workorder = TaskUtils.hasWorkOrder(point); |
|
|
|
|
|
method_param.put("workorder", workorder); |
|
|
|
|
|
task_code = hlSendMaterialTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
case YZ: |
|
|
|
|
|
method_param.put("workorder", param.getJSONObject("workorder")); |
|
|
|
|
|
method_param.put("vd", param.getJSONObject("vd")); |
|
|
|
|
|
JSONObject device = WQLObject |
|
|
|
|
|
.getWQLObject("pdm_bi_device") |
|
|
|
|
|
.query("device_code = '" + point.getString("device_code") + "'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
method_param.put("device", device); |
|
|
|
|
|
task_code = yzSendMaterialTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
case SZ: |
|
|
|
|
|
WQLObject vd_table = WQLObject.getWQLObject("st_ivt_vehicle_detail"); |
|
|
|
|
|
JSONObject vd = vd_table |
|
|
|
|
|
.query("is_delete = '0' AND vehicle_type = '2' AND vehicle_code = '" + vehicle_code + "'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
if (ObjectUtil.isEmpty(vd)) { |
|
|
|
|
|
throw new BadRequestException("未找到 [" + vehicle_code + "] 的组盘信息!"); |
|
|
|
|
|
} |
|
|
|
|
|
vd.put("is_fire", "1"); |
|
|
|
|
|
vd.put("is_in_kiln", "0"); |
|
|
|
|
|
vd_table.update(vd); |
|
|
|
|
|
method_param.put("vd", vd); |
|
|
|
|
|
|
|
|
|
|
|
task_code = szSendMaterialTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起送料任务!"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case "2": |
|
|
|
|
|
// 叫料
|
|
|
|
|
|
JSONObject workorder = TaskUtils.hasWorkOrder(point); |
|
|
JSONObject workorder = TaskUtils.hasWorkOrder(point); |
|
|
method_param.put("workorder", workorder); |
|
|
method_param.put("workorder", workorder); |
|
|
|
|
|
task_code = hlSendMaterialTask.createTask(method_param); |
|
|
switch (region) { |
|
|
|
|
|
case FJ: |
|
|
|
|
|
task_code = fjCallMaterialTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起叫料任务!"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case "3": |
|
|
case YZ: |
|
|
// 送空
|
|
|
method_param.put("workorder", param.getJSONObject("workorder")); |
|
|
switch (region) { |
|
|
method_param.put("vd", param.getJSONObject("vd")); |
|
|
case FJ: |
|
|
task_code = yzSendMaterialTask.createTask(method_param); |
|
|
task_code = fjSendEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起送空任务!"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
break; |
|
|
case "4": |
|
|
case SZ: |
|
|
// 叫空
|
|
|
WQLObject vd_table = WQLObject.getWQLObject("st_ivt_vehicle_detail"); |
|
|
switch (region) { |
|
|
JSONObject vd = vd_table |
|
|
case HL: |
|
|
.query("is_delete = '0' AND vehicle_type = '2' AND vehicle_code = '" + vehicle_code + "'") |
|
|
String device_code = point.getString("device_code"); |
|
|
.uniqueResult(0); |
|
|
JSONObject work_order = WQLObject |
|
|
if (ObjectUtil.isEmpty(vd)) { |
|
|
.getWQLObject("pdm_bd_workorder") |
|
|
throw new BadRequestException("未找到 [" + vehicle_code + "] 的组盘信息!"); |
|
|
.query("is_delete = '0' AND device_code = '" + device_code + "' AND order_status = '3'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
method_param.put("workorder", work_order); |
|
|
|
|
|
task_code = hlCallEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
case YZ: |
|
|
|
|
|
device_code = point.getString("device_code"); |
|
|
|
|
|
work_order = WQLObject |
|
|
|
|
|
.getWQLObject("pdm_bd_workorder") |
|
|
|
|
|
.query("is_delete = '0' AND device_code = '" + device_code + "' AND order_status = '3'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
method_param.put("workorder", work_order); |
|
|
|
|
|
JSONObject device = WQLObject |
|
|
|
|
|
.getWQLObject("pdm_bi_device") |
|
|
|
|
|
.query("device_code = '" + device_code + "'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
method_param.put("device", device); |
|
|
|
|
|
task_code = yzCallEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
case GTK: |
|
|
|
|
|
task_code = gtkCallEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起叫空任务!"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
vd.put("is_fire", "1"); |
|
|
|
|
|
vd.put("is_in_kiln", "0"); |
|
|
|
|
|
vd_table.update(vd); |
|
|
|
|
|
method_param.put("vd", vd); |
|
|
|
|
|
|
|
|
|
|
|
task_code = szSendMaterialTask.createTask(method_param); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
throw new BadRequestException("未知任务类型!"); |
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起送料任务!"); |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
} catch (InterruptedException e) { |
|
|
case "2": |
|
|
log.error("lock fail!", e); |
|
|
// 叫料
|
|
|
} finally { |
|
|
JSONObject workorder = TaskUtils.hasWorkOrder(point); |
|
|
if (try_lock) { |
|
|
method_param.put("workorder", workorder); |
|
|
lock.unlock(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (region) { |
|
|
|
|
|
case FJ: |
|
|
|
|
|
task_code = fjCallMaterialTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起叫料任务!"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case "3": |
|
|
|
|
|
// 送空
|
|
|
|
|
|
vehicle_code = TaskUtils.formatVehicleCode(param.getString("vehicle_code")); |
|
|
|
|
|
if ("0000".equals(vehicle_code)) { |
|
|
|
|
|
vehicle_code = point.getString("vehicle_code"); |
|
|
|
|
|
if (StrUtil.isBlank(vehicle_code) || "0000".equals(vehicle_code)) { |
|
|
|
|
|
throw new BadRequestException("未知载具编码!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
method_param.put("vehicle_code", vehicle_code); |
|
|
|
|
|
|
|
|
|
|
|
switch (region) { |
|
|
|
|
|
case FJ: |
|
|
|
|
|
JSONObject vd_update = new JSONObject(); |
|
|
|
|
|
vd_update.put("is_delete", TrueOrFalse.TRUE.value()); |
|
|
|
|
|
WQLObject |
|
|
|
|
|
.getWQLObject("st_ivt_vehicle_detail") |
|
|
|
|
|
.update(vd_update, "vehicle_type = '2' AND vehicle_code = '" + vehicle_code + "'"); |
|
|
|
|
|
task_code = fjSendEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起送空任务!"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
case "4": |
|
|
|
|
|
// 叫空
|
|
|
|
|
|
switch (region) { |
|
|
|
|
|
case HL: |
|
|
|
|
|
String device_code = point.getString("device_code"); |
|
|
|
|
|
JSONObject work_order = WQLObject |
|
|
|
|
|
.getWQLObject("pdm_bd_workorder") |
|
|
|
|
|
.query("is_delete = '0' AND device_code = '" + device_code + "' AND order_status = '3'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
method_param.put("workorder", work_order); |
|
|
|
|
|
task_code = hlCallEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
case YZ: |
|
|
|
|
|
device_code = point.getString("device_code"); |
|
|
|
|
|
work_order = WQLObject |
|
|
|
|
|
.getWQLObject("pdm_bd_workorder") |
|
|
|
|
|
.query("is_delete = '0' AND device_code = '" + device_code + "' AND order_status = '3'") |
|
|
|
|
|
.uniqueResult(0); |
|
|
|
|
|
method_param.put("workorder", work_order); |
|
|
|
|
|
task_code = yzCallEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
case GTK: |
|
|
|
|
|
task_code = gtkCallEmptyTask.createTask(method_param); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("[" + region.label() + "] 不能发起叫空任务!"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BadRequestException("未知任务类型!"); |
|
|
|
|
|
} |
|
|
JSONObject result = new JSONObject(); |
|
|
JSONObject result = new JSONObject(); |
|
|
result.put("message", "申请任务成功,任务编码 [" + task_code + "]"); |
|
|
result.put("message", "申请任务成功,任务编码 [" + task_code + "]"); |
|
|
result.put("status", HttpStatus.OK.value()); |
|
|
result.put("status", HttpStatus.OK.value()); |
|
|