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