|
|
|
|
@@ -1,12 +1,15 @@
|
|
|
|
|
package org.nl.acs.device_driver.basedriver.belt_with_station;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
import org.nl.acs.agv.server.NDCAgvService;
|
|
|
|
|
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
|
|
|
|
|
import org.nl.acs.device.domain.Device;
|
|
|
|
|
@@ -25,14 +28,13 @@ import org.nl.acs.log.service.DeviceExecuteLogService;
|
|
|
|
|
import org.nl.acs.monitor.DeviceStageMonitor;
|
|
|
|
|
import org.nl.acs.opc.DeviceAppService;
|
|
|
|
|
import org.nl.acs.route.service.RouteLineService;
|
|
|
|
|
import org.nl.acs.route.service.dto.RouteLineDto;
|
|
|
|
|
import org.nl.acs.task.service.TaskService;
|
|
|
|
|
import org.nl.acs.task.service.dto.TaskDto;
|
|
|
|
|
import org.nl.config.SpringContextHolder;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关联驱动
|
|
|
|
|
@@ -129,86 +131,188 @@ public class WithStationDeviceDriver extends AbstractOpcDeviceDriver implements
|
|
|
|
|
device_code = this.getDeviceCode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//取关联设备 list 要求:先配置外侧的站点
|
|
|
|
|
//遍历
|
|
|
|
|
List<String> sddjExtraCodeList = this.getExtraDeviceCodes("link_device_code");
|
|
|
|
|
//只需要判断对接位就可以
|
|
|
|
|
for (int i = 0; i < 1; i++) {
|
|
|
|
|
Device sddjExtraCode1 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i));
|
|
|
|
|
Device sddjExtraCode2 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i+1));
|
|
|
|
|
Device sddjExtraCode2 = deviceAppservice.findDeviceByCode(sddjExtraCodeList.get(i + 1));
|
|
|
|
|
DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver1;
|
|
|
|
|
DoubleBeltConveyorDeviceDriver doubleBeltConveyorDeviceDriver2;
|
|
|
|
|
if (sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver && sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver ) {
|
|
|
|
|
if (sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver && sddjExtraCode1.getDeviceDriver() instanceof DoubleBeltConveyorDeviceDriver) {
|
|
|
|
|
doubleBeltConveyorDeviceDriver1 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode1.getDeviceDriver();
|
|
|
|
|
doubleBeltConveyorDeviceDriver2 = (DoubleBeltConveyorDeviceDriver) sddjExtraCode2.getDeviceDriver();
|
|
|
|
|
//判断输送线是否有任务,有任务进行创建指令。
|
|
|
|
|
List<TaskDto> taskDtos1 = taskServer.queryTaskByStartDeviceCode(doubleBeltConveyorDeviceDriver1.getDevice_code());
|
|
|
|
|
List<TaskDto> taskDtos2 = taskServer.queryTaskByStartDeviceCode(doubleBeltConveyorDeviceDriver2.getDevice_code());
|
|
|
|
|
if (CollectionUtil.isNotEmpty(taskDtos1) && CollectionUtil.isNotEmpty(taskDtos2)) {
|
|
|
|
|
if(doubleBeltConveyorDeviceDriver1.getMove() == 0){
|
|
|
|
|
requireSucess =false;
|
|
|
|
|
TaskDto taskDtos1 = taskServer.findByStartCodeAndReady(doubleBeltConveyorDeviceDriver1.getDevice_code());
|
|
|
|
|
TaskDto taskDtos2 = taskServer.findByStartCodeAndReady(doubleBeltConveyorDeviceDriver1.getDevice_code());
|
|
|
|
|
if (ObjectUtil.isNotEmpty(taskDtos1) && ObjectUtil.isNotEmpty(taskDtos2)) {
|
|
|
|
|
if (doubleBeltConveyorDeviceDriver1.getMove() == 0) {
|
|
|
|
|
requireSucess = false;
|
|
|
|
|
}
|
|
|
|
|
if(doubleBeltConveyorDeviceDriver2.getMove() == 0){
|
|
|
|
|
requireSucess =false;
|
|
|
|
|
if (doubleBeltConveyorDeviceDriver2.getMove() == 0) {
|
|
|
|
|
requireSucess = false;
|
|
|
|
|
}
|
|
|
|
|
//判断关联的输送线是否满足状态
|
|
|
|
|
if (doubleBeltConveyorDeviceDriver1.getMode() == 2 && doubleBeltConveyorDeviceDriver1.getMove() == 1 && !requireSucess &&doubleBeltConveyorDeviceDriver2.getMode() == 2 && doubleBeltConveyorDeviceDriver2.getMove() == 1
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否超过等待时间
|
|
|
|
|
if (System.currentTimeMillis() - doubleBeltConveyorDeviceDriver1.getInstruction_require_time().getTime()
|
|
|
|
|
> Integer.parseInt(this.getExtraValue().get("apply_time").toString()) * 1000) {
|
|
|
|
|
//否则对接位单独申请任务
|
|
|
|
|
JSONObject reqParam = new JSONObject();
|
|
|
|
|
reqParam.put("type", StatusEnum.HAIROU_LIKU_REQ.getCode());
|
|
|
|
|
reqParam.put("device_code_one", hailiangHrSsxDeviceDriver.getDevice_code());
|
|
|
|
|
reqParam.put("vehicle_code_one", hailiangHrSsxDeviceDriver.getBarcode());
|
|
|
|
|
log.info("单工位请求成功");
|
|
|
|
|
requireSucess = true;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//否则判断另一个位置
|
|
|
|
|
Device neiRouDevice = deviceAppservice.findDeviceByCode(haiRouDeviceCodeList.get(i+1));
|
|
|
|
|
if (neiRouDevice.getDeviceDriver() instanceof HailiangHrSsxDeviceDriver) {
|
|
|
|
|
hailiangHrSsxDeviceDriver2 = (HailiangHrSsxDeviceDriver) neiRouDevice.getDeviceDriver();
|
|
|
|
|
if (hailiangHrSsxDeviceDriver2.getMode() == 2 &&
|
|
|
|
|
hailiangHrSsxDeviceDriver2.getMove() == 1 &&
|
|
|
|
|
ObjectUtil.isNotEmpty(hailiangHrSsxDeviceDriver2.getBarcode())
|
|
|
|
|
) {
|
|
|
|
|
JSONObject reqParam = new JSONObject();
|
|
|
|
|
//半成品库任务
|
|
|
|
|
reqParam.put("type", StatusEnum.HAIROU_LIKU_REQ.getCode());
|
|
|
|
|
//具体海柔出入库任务类型
|
|
|
|
|
reqParam.put("item_type", DeviceEnum.getTypeByCode(hailiangHrSsxDeviceDriver.getDevice_code()));
|
|
|
|
|
reqParam.put("device_code_one", hailiangHrSsxDeviceDriver.getDevice_code());
|
|
|
|
|
reqParam.put("vehicle_code_one", hailiangHrSsxDeviceDriver.getBarcode());
|
|
|
|
|
reqParam.put("device_code_two", hailiangHrSsxDeviceDriver2.getDevice_code());
|
|
|
|
|
reqParam.put("vehicle_code_two", hailiangHrSsxDeviceDriver2.getBarcode());
|
|
|
|
|
//向lms请求任务
|
|
|
|
|
// 联调时加上
|
|
|
|
|
// HttpResponse httpResponse = acsToWmsService.applyTaskToWms(reqParam);
|
|
|
|
|
// if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
|
|
|
|
// requireSucess = true;
|
|
|
|
|
// }
|
|
|
|
|
log.info("双工位请求成功");
|
|
|
|
|
requireSucess = true;
|
|
|
|
|
}
|
|
|
|
|
//判断任务列是否相邻
|
|
|
|
|
String nextDeviceCode1 = taskDtos1.getNext_device_code();
|
|
|
|
|
String nextDeviceCode2 = taskDtos2.getNext_device_code();
|
|
|
|
|
if (StrUtil.contains(nextDeviceCode1, "-") && StrUtil.contains(nextDeviceCode2, "-")) {
|
|
|
|
|
String[] split1 = nextDeviceCode1.split("-");
|
|
|
|
|
String nextPointCodeDown = split1[0] + "-" + (Integer.parseInt(split1[1]) - 1) + "-" + split1[2];
|
|
|
|
|
String nextPointCodeUp = split1[0] + "-" + (Integer.parseInt(split1[1]) + 1) + "-" + split1[2];
|
|
|
|
|
if (!nextDeviceCode2.equals(nextPointCodeDown) || !nextDeviceCode2.equals(nextPointCodeUp)) {
|
|
|
|
|
//创建指令
|
|
|
|
|
if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) {
|
|
|
|
|
creatInstruction(taskDtos1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//todo 输出不满足的原因
|
|
|
|
|
|
|
|
|
|
requireSucess = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断关联的输送线是否满足状态
|
|
|
|
|
if (doubleBeltConveyorDeviceDriver1.getMode() == 2 && doubleBeltConveyorDeviceDriver1.getMove() == 1 && !requireSucess && doubleBeltConveyorDeviceDriver2.getMode() == 2 && doubleBeltConveyorDeviceDriver2.getMove() == 1) {
|
|
|
|
|
//判断是否大于等待时间
|
|
|
|
|
if (System.currentTimeMillis() - doubleBeltConveyorDeviceDriver1.getInstruction_require_time().getTime()
|
|
|
|
|
> Integer.parseInt(this.getExtraValue().get("apply_time").toString()) * 1000) {
|
|
|
|
|
//创建指令
|
|
|
|
|
if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) {
|
|
|
|
|
creatInstruction(taskDtos1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("单工位请求成功");
|
|
|
|
|
requireSucess = true;
|
|
|
|
|
} else {
|
|
|
|
|
//创建指令
|
|
|
|
|
if (ObjectUtil.isNotNull(taskDtos1) && "1".equals(taskDtos1.getTask_type())) {
|
|
|
|
|
creatInstruction(taskDtos1);
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtil.isNotNull(taskDtos2) && "1".equals(taskDtos1.getTask_type())) {
|
|
|
|
|
creatInstruction(taskDtos2);
|
|
|
|
|
}
|
|
|
|
|
log.info("双工位指令创建成功");
|
|
|
|
|
requireSucess = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void creatInstruction(TaskDto taskDtos1) {
|
|
|
|
|
|
|
|
|
|
//判断当前任务号是否存在指令
|
|
|
|
|
String taskid = taskDtos1.getTask_id();
|
|
|
|
|
String taskcode = taskDtos1.getTask_code();
|
|
|
|
|
String priority = taskDtos1.getPriority();
|
|
|
|
|
String start_point_code = taskDtos1.getStart_point_code();
|
|
|
|
|
String start_device_code = taskDtos1.getStart_device_code();
|
|
|
|
|
String route_plan_code = taskDtos1.getRoute_plan_code();
|
|
|
|
|
String next_device_code = "";
|
|
|
|
|
/**
|
|
|
|
|
* 开始平均分配
|
|
|
|
|
*/
|
|
|
|
|
String this_coevice_code = taskServer.queryAssignedByDevice(device_code, taskDtos1.getNext_device_code());
|
|
|
|
|
if (StrUtil.isEmpty(this_coevice_code)) {
|
|
|
|
|
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, taskDtos1.getNext_device_code(), route_plan_code);
|
|
|
|
|
RouteLineDto routeLineDto = shortPathsList.get(0);
|
|
|
|
|
|
|
|
|
|
String path = routeLineDto.getPath();
|
|
|
|
|
String type = routeLineDto.getType();
|
|
|
|
|
String[] str = path.split("->");
|
|
|
|
|
|
|
|
|
|
List<String> pathlist = Arrays.asList(str);
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (int m = 0; m < pathlist.size(); m++) {
|
|
|
|
|
if (pathlist.get(m).equals(start_device_code)) {
|
|
|
|
|
index = m + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
next_device_code = pathlist.get(index);
|
|
|
|
|
} else {
|
|
|
|
|
next_device_code = this_coevice_code;
|
|
|
|
|
}
|
|
|
|
|
//校验路由关系
|
|
|
|
|
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code);
|
|
|
|
|
if (ObjectUtils.isEmpty(shortPathsList) || shortPathsList.size() < 1) {
|
|
|
|
|
throw new RuntimeException("路由不通!");
|
|
|
|
|
}
|
|
|
|
|
Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code);
|
|
|
|
|
String next_point_code;
|
|
|
|
|
if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) {
|
|
|
|
|
next_point_code = taskDtos1.getTo_x() + "-" + taskDtos1.getTo_y() + "-" + taskDtos1.getTo_z();
|
|
|
|
|
} else {
|
|
|
|
|
next_point_code = next_device_code;
|
|
|
|
|
}
|
|
|
|
|
Instruction instdto = new Instruction();
|
|
|
|
|
instdto.setInstruction_id(IdUtil.simpleUUID());
|
|
|
|
|
instdto.setRoute_plan_code(route_plan_code);
|
|
|
|
|
instdto.setRemark(taskDtos1.getRemark());
|
|
|
|
|
instdto.setMaterial(taskDtos1.getMaterial());
|
|
|
|
|
instdto.setQuantity(taskDtos1.getQuantity());
|
|
|
|
|
instdto.setTask_id(taskid);
|
|
|
|
|
instdto.setTask_code(taskcode);
|
|
|
|
|
String now = DateUtil.now();
|
|
|
|
|
instdto.setCreate_time(now);
|
|
|
|
|
instdto.setCreate_by("auto");
|
|
|
|
|
instdto.setStart_device_code(start_device_code);
|
|
|
|
|
instdto.setNext_device_code(next_device_code);
|
|
|
|
|
instdto.setStart_point_code(start_point_code);
|
|
|
|
|
instdto.setNext_point_code(next_point_code);
|
|
|
|
|
instdto.setPriority(priority);
|
|
|
|
|
instdto.setInstruction_status("0");
|
|
|
|
|
instdto.setExecute_device_code(start_point_code);
|
|
|
|
|
log.error("=================================,{}", instdto.getCreate_by());
|
|
|
|
|
try {
|
|
|
|
|
instructionService.create(instdto);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error("指令创建失败!", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
taskDtos1.setTask_status("1");
|
|
|
|
|
taskServer.update(taskDtos1);
|
|
|
|
|
requireSucess = true;
|
|
|
|
|
Map map = new HashMap();
|
|
|
|
|
String next_addr = nextdevice.getExtraValue().get("address").toString();
|
|
|
|
|
map.put("to_target", next_addr);
|
|
|
|
|
map.put("to_task", instdto.getInstruction_code());
|
|
|
|
|
map.put("to_command", "1");
|
|
|
|
|
map.put("to_container_type", "1");
|
|
|
|
|
map.put("to_container_no", "1");
|
|
|
|
|
this.writing(map);
|
|
|
|
|
requireSucess = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void writing(Map<String, Object> map) {
|
|
|
|
|
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
|
|
|
|
|
Map<String, Object> itemMap = new LinkedHashMap<>();
|
|
|
|
|
map.forEach((key, value) -> {
|
|
|
|
|
if (ObjectUtil.isNotEmpty(value)) {
|
|
|
|
|
itemMap.put(getToParam() + key, value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (ObjectUtil.isNotEmpty(itemMap)) {
|
|
|
|
|
try {
|
|
|
|
|
this.checkcontrol(itemMap);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
try {
|
|
|
|
|
this.checkcontrol(itemMap);
|
|
|
|
|
} catch (Exception e1) {
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getToParam() {
|
|
|
|
|
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将扩展表中的字符串数据转换成集合
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getExtraDeviceCodes(String extraName) {
|
|
|
|
|
|