gengby
2 years ago
20 changed files with 1389 additions and 67 deletions
@ -0,0 +1,69 @@ |
|||
package org.nl.acs.device_driver; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author: geng by |
|||
* @createDate: 2022/11/17 |
|||
*/ |
|||
public class RouteUtil { |
|||
|
|||
public static List<String> getRouteList(String start_device_code, String next_device_code) { |
|||
Map<String, List<String>> listMap = getRouteByCode(start_device_code, next_device_code); |
|||
return listMap.get(start_device_code); |
|||
} |
|||
|
|||
public static Map<String, List<String>> getRouteByCode(String start_device_code, String next_device_code) { |
|||
String first_device_code = start_device_code.substring(0, 1); |
|||
Map<String, List<String>> map = new HashMap<>(); |
|||
List<String> list = new ArrayList<>(); |
|||
if (!StrUtil.equals(first_device_code, "D")) { |
|||
list.add(first_device_code + "03"); |
|||
list.add(first_device_code + "04"); |
|||
list.add(first_device_code + "02"); |
|||
list.add(first_device_code + "03"); |
|||
list.add(first_device_code + "04"); |
|||
list.add(first_device_code + "01"); |
|||
map.put(first_device_code + "01", list); |
|||
list = new ArrayList<>(); |
|||
list.add(first_device_code + "02"); |
|||
list.add(first_device_code + "03"); |
|||
list.add(first_device_code + "04"); |
|||
list.add(first_device_code + "01"); |
|||
map.put(first_device_code + "03", list); |
|||
list = new ArrayList<>(); |
|||
list.add(first_device_code + "04"); |
|||
list.add(first_device_code + "01"); |
|||
map.put(first_device_code + "02", list); |
|||
} else { |
|||
if (StrUtil.equals(next_device_code, "D02")) { |
|||
list = new ArrayList<>(); |
|||
list.add(first_device_code + "03"); |
|||
list.add(first_device_code + "01"); |
|||
map.put(first_device_code + "01", list); |
|||
} else if (StrUtil.equals(next_device_code, "D03")) { |
|||
list = new ArrayList<>(); |
|||
list.add(first_device_code + "02"); |
|||
list.add(first_device_code + "01"); |
|||
map.put(first_device_code + "01", list); |
|||
} |
|||
} |
|||
return map; |
|||
} |
|||
|
|||
public static String getDeviceCode(String address) { |
|||
String device_code = ""; |
|||
if (address.contains("INGET") || address.contains("INPUT")) { |
|||
device_code = address.substring(0, address.length() - 5); |
|||
} else if (address.contains("OUTGET") || address.contains("OUTPUT")) { |
|||
device_code = address.substring(0, address.length() - 6); |
|||
} |
|||
return device_code; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,82 @@ |
|||
package org.nl.acs.device_driver.maGang; |
|||
|
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDto; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
@Slf4j |
|||
@Data |
|||
public class ItemProtocol { |
|||
|
|||
public static String item_heartbeat = "heartbeat"; |
|||
public static String item_mode = "mode"; |
|||
public static String item_move = "move"; |
|||
public static String item_action = "action"; |
|||
public static String item_error = "error"; |
|||
|
|||
|
|||
public static String item_to_command = "to_command"; |
|||
|
|||
|
|||
private MaGangConveyorDeviceDriver driver; |
|||
|
|||
public ItemProtocol(MaGangConveyorDeviceDriver driver) { |
|||
this.driver = driver; |
|||
} |
|||
|
|||
public int getItem_heartbeat() { |
|||
return this.getOpcIntegerValue(item_heartbeat); |
|||
} |
|||
|
|||
public int getItem_mode() { |
|||
return this.getOpcIntegerValue(item_mode); |
|||
} |
|||
|
|||
public int getItem_move() { |
|||
return this.getOpcIntegerValue(item_move); |
|||
} |
|||
|
|||
public int getItem_error() { |
|||
return this.getOpcIntegerValue(item_error); |
|||
} |
|||
|
|||
public int getItem_action() { |
|||
return this.getOpcIntegerValue(item_action); |
|||
} |
|||
|
|||
Boolean isonline; |
|||
|
|||
public int getOpcIntegerValue(String protocol) { |
|||
Integer value = this.driver.getIntegeregerValue(protocol); |
|||
if (value == null) { |
|||
setIsonline(false); |
|||
} else { |
|||
setIsonline(true); |
|||
return value; |
|||
} |
|||
return 0; |
|||
|
|||
} |
|||
|
|||
public static List<ItemDto> getReadableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); |
|||
list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); |
|||
list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); |
|||
list.add(new ItemDto(item_action, "取放信号", "DB600.B4")); |
|||
list.add(new ItemDto(item_error, "故障", "DB600.B5")); |
|||
return list; |
|||
} |
|||
|
|||
public static List<ItemDto> getWriteableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); |
|||
return list; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
@ -0,0 +1,60 @@ |
|||
package org.nl.acs.device_driver.maGang; |
|||
|
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDto; |
|||
import org.nl.acs.device_driver.DeviceDriver; |
|||
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; |
|||
import org.nl.acs.opc.Device; |
|||
import org.nl.acs.opc.DeviceType; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 马钢输送站点 |
|||
*/ |
|||
@Service |
|||
public class MaGangConveyorDefination implements OpcDeviceDriverDefination { |
|||
@Override |
|||
public String getDriverCode() { |
|||
return "magang_conveyor_control"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverName() { |
|||
return "马钢输送站点"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverDescription() { |
|||
return "马钢输送站点"; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceDriver getDriverInstance(Device device) { |
|||
return (new MaGangConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); |
|||
} |
|||
|
|||
@Override |
|||
public Class<? extends DeviceDriver> getDeviceDriverType() { |
|||
return MaGangConveyorDeviceDriver.class; |
|||
} |
|||
|
|||
@Override |
|||
public List<DeviceType> getFitDeviceTypes() { |
|||
List<DeviceType> types = new LinkedList(); |
|||
types.add(DeviceType.conveyor); |
|||
return types; |
|||
} |
|||
|
|||
@Override |
|||
public List<ItemDto> getReadableItemDtos() { |
|||
return ItemProtocol.getReadableItemDtos(); |
|||
} |
|||
|
|||
@Override |
|||
public List<ItemDto> getWriteableItemDtos() { |
|||
return ItemProtocol.getWriteableItemDtos(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,305 @@ |
|||
package org.nl.acs.device_driver.maGang; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.Data; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.agv.server.AgvService; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; |
|||
import org.nl.acs.device.service.DeviceService; |
|||
import org.nl.acs.device_driver.DeviceDriver; |
|||
import org.nl.acs.device_driver.RouteableDeviceDriver; |
|||
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; |
|||
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; |
|||
import org.nl.acs.ext.wms.service.AcsToWmsService; |
|||
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; |
|||
import org.nl.acs.instruction.service.InstructionService; |
|||
import org.nl.acs.instruction.service.dto.Instruction; |
|||
import org.nl.acs.log.service.DeviceExecuteLogService; |
|||
import org.nl.acs.monitor.DeviceStageMonitor; |
|||
import org.nl.acs.opc.Device; |
|||
import org.nl.acs.opc.DeviceAppService; |
|||
import org.nl.acs.route.service.RouteLineService; |
|||
import org.nl.acs.task.service.TaskService; |
|||
import org.nl.acs.task.service.dto.TaskDto; |
|||
import org.nl.modules.system.service.ParamService; |
|||
import org.nl.modules.system.util.CodeUtil; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
import org.openscada.opc.lib.da.Server; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
import java.util.*; |
|||
|
|||
/** |
|||
* 马钢输送站点 |
|||
*/ |
|||
@Slf4j |
|||
@Data |
|||
@RequiredArgsConstructor |
|||
public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { |
|||
|
|||
protected ItemProtocol itemProtocol = new ItemProtocol(this); |
|||
@Autowired |
|||
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); |
|||
@Autowired |
|||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|||
@Autowired |
|||
DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); |
|||
@Autowired |
|||
TaskService taskserver = SpringContextHolder.getBean(TaskService.class); |
|||
@Autowired |
|||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); |
|||
@Autowired |
|||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); |
|||
@Autowired |
|||
ParamService paramService = SpringContextHolder.getBean(ParamService.class); |
|||
@Autowired |
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); |
|||
@Autowired |
|||
AgvService agvService = SpringContextHolder.getBean(AgvService.class); |
|||
|
|||
private Date instruction_require_time = new Date(); |
|||
private Date instruction_finished_time = new Date(); |
|||
private Date instruction_apply_time = new Date(); |
|||
private int instruction_require_time_out = 3000; |
|||
|
|||
int heartbeat = 0; |
|||
//工作模式
|
|||
int mode = 0; |
|||
int last_mode = 0; |
|||
|
|||
//光电信号
|
|||
int move = 0; |
|||
int last_move = 0; |
|||
|
|||
//动作信号
|
|||
int action = 0; |
|||
int last_action = 0; |
|||
|
|||
//报警信号
|
|||
int error = 0; |
|||
int last_error = 0; |
|||
|
|||
Boolean isonline = true; |
|||
Boolean iserror = false; |
|||
|
|||
//1-执行任务;2-取货完成;3-放货完成;
|
|||
int flag; |
|||
|
|||
|
|||
|
|||
String device_code; |
|||
|
|||
@Override |
|||
public Device getDevice() { |
|||
return this.device; |
|||
} |
|||
|
|||
//请求成功标记
|
|||
Boolean requireSucess = false; |
|||
|
|||
@Override |
|||
public void execute() throws Exception { |
|||
String message = null; |
|||
device_code = this.getDeviceCode(); |
|||
heartbeat = this.itemProtocol.getItem_heartbeat(); |
|||
mode = this.itemProtocol.getItem_mode(); |
|||
move = this.itemProtocol.getItem_move(); |
|||
action = this.itemProtocol.getItem_action(); |
|||
error = this.itemProtocol.getItem_error(); |
|||
if (mode != last_mode) { |
|||
if (mode == 3){ |
|||
this.setRequireSucess(false); |
|||
} |
|||
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); |
|||
} |
|||
if (move != last_move) { |
|||
logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); |
|||
} |
|||
if (action != last_action) { |
|||
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); |
|||
} |
|||
if (error != last_error) { |
|||
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); |
|||
} |
|||
if (!this.itemProtocol.getIsonline()) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "信号量同步异常"; |
|||
//未联机
|
|||
} else if (mode == 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "未联机"; |
|||
//有报警
|
|||
} else if (error != 0) { |
|||
this.setIsonline(false); |
|||
this.setIserror(true); |
|||
message = "有报警"; |
|||
//无报警
|
|||
} else { |
|||
this.setIsonline(true); |
|||
this.setIserror(false); |
|||
message = ""; |
|||
Instruction instruction = null; |
|||
List toInstructions; |
|||
if (mode == 3 && !requireSucess){ |
|||
instruction_require(); |
|||
} |
|||
} |
|||
|
|||
last_mode = mode; |
|||
last_move = move; |
|||
last_error = error; |
|||
last_action = action; |
|||
} |
|||
|
|||
public synchronized boolean instruction_require() throws Exception { |
|||
Date date = new Date(); |
|||
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { |
|||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|||
return false; |
|||
} else { |
|||
this.instruction_require_time = date; |
|||
List<String> link_device_codes = this.getExtraDeviceCodes("link_device_code"); |
|||
String next_device_code = ""; |
|||
MaGangConveyorDeviceDriver maGangConveyorDeviceDriver; |
|||
for (int i = 0; i < link_device_codes.size(); i++) { |
|||
String link_device_code = link_device_codes.get(i); |
|||
Device device = deviceAppservice.findDeviceByCode(link_device_code); |
|||
if (device.getDeviceDriver() instanceof MaGangConveyorDeviceDriver){ |
|||
maGangConveyorDeviceDriver = (MaGangConveyorDeviceDriver) device.getDeviceDriver(); |
|||
if (maGangConveyorDeviceDriver.getMove() == 0){ |
|||
next_device_code = link_device_code; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
if (StrUtil.isEmpty(next_device_code)){ |
|||
return false; |
|||
} |
|||
TaskDto taskDto = new TaskDto(); |
|||
String now = DateUtil.now(); |
|||
taskDto.setTask_id(IdUtil.simpleUUID()); |
|||
taskDto.setTask_code(CodeUtil.getNewCode("TASK_NO")); |
|||
taskDto.setTask_type("1"); |
|||
taskDto.setRoute_plan_code("normal"); |
|||
taskDto.setTask_status("0"); |
|||
taskDto.setPriority("101"); |
|||
taskDto.setAgv_system_type("1"); |
|||
taskDto.setStart_device_code(this.getDevice().getDevice_code()); |
|||
taskDto.setStart_point_code(this.getDevice().getDevice_code()); |
|||
taskDto.setNext_point_code(next_device_code); |
|||
taskDto.setNext_point_code(next_device_code); |
|||
taskDto.setCreate_by(this.getDevice().getDevice_code()); |
|||
taskDto.setUpdate_by(this.getDevice().getDevice_code()); |
|||
taskDto.setUpdate_time(now); |
|||
taskDto.setCreate_time(now); |
|||
try { |
|||
taskserver.create(taskDto); |
|||
} catch (Exception e) { |
|||
logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); |
|||
} |
|||
logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务成功"); |
|||
this.writing(1); |
|||
this.setRequireSucess(true); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
protected void thingToNothing() { |
|||
|
|||
} |
|||
|
|||
//将扩展表中的字符串数据转换成集合
|
|||
public List<String> getExtraDeviceCodes(String extraName) { |
|||
String extraValue = (String) this.getDevice().getExtraValue().get(extraName); |
|||
String devicesString = extraValue.substring(1, extraValue.length() - 1); |
|||
List<String> devicesList = new ArrayList<>(); |
|||
String[] devices = devicesString.split(","); |
|||
for (int i = 0; i < devices.length; i++) { |
|||
String s = devices[i].replace("\"", "").replace("\"", ""); |
|||
devicesList.add(s); |
|||
} |
|||
return devicesList; |
|||
} |
|||
|
|||
public void writing(int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, command); |
|||
ReadUtil.write(itemMap, server); |
|||
} |
|||
|
|||
public void writing(int type, int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
if (type == 1) { |
|||
itemMap.put(to_command, command); |
|||
log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command); |
|||
} |
|||
ReadUtil.write(itemMap, server); |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject getDeviceStatusName() { |
|||
JSONObject jo = new JSONObject(); |
|||
String mode = ""; |
|||
String action = ""; |
|||
String move = ""; |
|||
if (this.getMode() == 0) { |
|||
mode = "未联机"; |
|||
} else if (this.getMode() == 1) { |
|||
mode = "单机"; |
|||
} else if (this.getMode() == 2) { |
|||
mode = "联机"; |
|||
} else if (this.getMode() == 3) { |
|||
mode = "运行中"; |
|||
} |
|||
|
|||
if (this.getAction() == 0) { |
|||
action = "禁止取放"; |
|||
} else if (this.getAction() == 1) { |
|||
action = "允许取货"; |
|||
} else if (this.getAction() == 2) { |
|||
action = "允许放货"; |
|||
} else if (this.getAction() == 3) { |
|||
action = "允许取放"; |
|||
} |
|||
|
|||
|
|||
if (this.getMove() == 0) { |
|||
move = "无货"; |
|||
} else if (this.getMove() == 1) { |
|||
move = "有货"; |
|||
} else if (this.getMove() == 2) { |
|||
move = "有托盘有货"; |
|||
} |
|||
jo.put("device_name", this.getDevice().getDevice_name()); |
|||
jo.put("mode", mode); |
|||
jo.put("move", move); |
|||
jo.put("action", action); |
|||
jo.put("isOnline", this.getIsonline()); |
|||
jo.put("error", this.getError()); |
|||
jo.put("isError", this.getIserror()); |
|||
return jo; |
|||
} |
|||
|
|||
@Override |
|||
public void setDeviceStatus(JSONObject data) { |
|||
|
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
|
|||
package org.nl.acs.ext.wms.rest; |
|||
|
|||
|
|||
import cn.dev33.satoken.annotation.SaIgnore; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.ext.wms.service.AgvToAcsService; |
|||
import org.nl.modules.logging.annotation.Log; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
@Api(tags = "wms接口") |
|||
@RequestMapping("api/agv") |
|||
@Slf4j |
|||
@CrossOrigin |
|||
public class AgvToAcsController { |
|||
private final AgvToAcsService agvToAcsService; |
|||
|
|||
@PostMapping("/waitpointRequest") |
|||
@Log("AGV到等待点请求继续执行") |
|||
@ApiOperation("AGV到等待点请求继续执行") |
|||
@SaIgnore |
|||
public ResponseEntity<Object> createFromWms(@RequestBody JSONObject param) { |
|||
return new ResponseEntity<>(agvToAcsService.waitpointRequest(param), HttpStatus.OK); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,17 @@ |
|||
package org.nl.acs.ext.wms.service; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
import java.util.Map; |
|||
|
|||
public interface AgvToAcsService { |
|||
/** |
|||
* 创建任务 |
|||
* |
|||
* @param jsonObject 条件 |
|||
* @return |
|||
*/ |
|||
Map<String, Object> waitpointRequest(JSONObject jsonObject); |
|||
|
|||
} |
@ -0,0 +1,87 @@ |
|||
package org.nl.acs.ext.wms.service.impl; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.device_driver.RouteUtil; |
|||
import org.nl.acs.device_driver.maGang.MaGangConveyorDeviceDriver; |
|||
import org.nl.acs.ext.wms.service.AgvToAcsService; |
|||
import org.nl.acs.instruction.service.InstructionService; |
|||
import org.nl.acs.instruction.service.dto.Instruction; |
|||
import org.nl.acs.log.service.DeviceExecuteLogService; |
|||
import org.nl.acs.opc.Device; |
|||
import org.nl.acs.opc.DeviceAppService; |
|||
import org.nl.modules.common.exception.BadRequestException; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class AgvToAcsServiceImpl implements AgvToAcsService { |
|||
|
|||
private final DeviceAppService deviceAppService; |
|||
private final InstructionService instructionService; |
|||
private final DeviceExecuteLogService logService; |
|||
|
|||
@Override |
|||
public Map<String, Object> waitpointRequest(JSONObject param) { |
|||
//指令号
|
|||
String inst_code = param.getString("task_code"); |
|||
//站点
|
|||
String address = param.getString("address"); |
|||
//车号
|
|||
String vehicle_code = param.getString("device_code"); |
|||
String deviceCode = RouteUtil.getDeviceCode(address); |
|||
Instruction instructionDto = instructionService.findByCode(inst_code); |
|||
if (ObjectUtil.isEmpty(instructionDto)) { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:指令任务号不存在! 指令号:" + inst_code); |
|||
throw new BadRequestException("请求失败,指令任务号不存在!"); |
|||
} |
|||
Device device = deviceAppService.findDeviceByCode(deviceCode); |
|||
MaGangConveyorDeviceDriver maGangConveyorDeviceDriver = (MaGangConveyorDeviceDriver) device.getDeviceDriver(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("status", 200); |
|||
map.put("message", "操作成功"); |
|||
if (address.contains("INGET")) { |
|||
if (maGangConveyorDeviceDriver.getMove() == 1) { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); |
|||
return map; |
|||
} else { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:取货前-取货点无货!"); |
|||
throw new BadRequestException("请求失败,取货前-取货点无货!"); |
|||
} |
|||
} else if (address.contains("OUTGET")) { |
|||
if (maGangConveyorDeviceDriver.getMove() == 0) { |
|||
maGangConveyorDeviceDriver.writing(2); |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); |
|||
return map; |
|||
} else { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:取货完成后-取货点有货!"); |
|||
throw new BadRequestException("请求失败,取货完成后-取货点有货!"); |
|||
} |
|||
} else if (address.contains("INPUT")) { |
|||
if (maGangConveyorDeviceDriver.getMove() == 0) { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); |
|||
return map; |
|||
} else { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:放货前-放货点有货!"); |
|||
throw new BadRequestException("请求失败,放货前-放货点有货!"); |
|||
} |
|||
} else if (address.contains("OUTPUT")) { |
|||
if (maGangConveyorDeviceDriver.getMove() == 1) { |
|||
maGangConveyorDeviceDriver.writing(3); |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); |
|||
return map; |
|||
} else { |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:放货完成后-放货点无货!"); |
|||
throw new BadRequestException("请求失败,放货完成后-放货点无货!"); |
|||
} |
|||
} |
|||
logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:请求失败,地址有误! 地址:" + address); |
|||
throw new BadRequestException("请求失败,地址有误!"); |
|||
} |
|||
} |
@ -0,0 +1,502 @@ |
|||
<template> |
|||
<!--标准版-输送机-控制点--> |
|||
<div> |
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span">设备协议:</span> |
|||
</div> |
|||
|
|||
<el-row> |
|||
<el-col :span="12"> |
|||
OpcServer: |
|||
<el-select |
|||
v-model="opc_id" |
|||
placeholder="无" |
|||
clearable |
|||
@change="changeOpc" |
|||
> |
|||
<el-option |
|||
v-for="item in dataOpcservers" |
|||
:key="item.opc_id" |
|||
:label="item.opc_name" |
|||
:value="item.opc_id" |
|||
/> |
|||
</el-select> |
|||
</el-col> |
|||
<el-col :span="12"> |
|||
PLC: |
|||
<el-select |
|||
v-model="plc_id" |
|||
placeholder="无" |
|||
clearable |
|||
@change="changePlc" |
|||
> |
|||
<el-option |
|||
v-for="item in dataOpcPlcs" |
|||
:key="item.plc_id" |
|||
:label="item.plc_name" |
|||
:value="item.plc_id" |
|||
/> |
|||
</el-select> |
|||
</el-col> |
|||
</el-row> |
|||
|
|||
</el-card> |
|||
|
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span">输送系统:</span> |
|||
</div> |
|||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px"> |
|||
<el-row> |
|||
<el-col :span="8"> |
|||
<el-form-item label="电气调度号" label-width="150px"> |
|||
<el-input v-model="form.address" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
</el-form> |
|||
</el-card> |
|||
|
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span">指令相关:</span> |
|||
</div> |
|||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px"> |
|||
<el-row> |
|||
<el-col :span="8"> |
|||
<el-form-item label="检验有货"> |
|||
<el-switch v-model="form.inspect_in_stocck" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
<el-col :span="8"> |
|||
<el-form-item label="忽视取货校验" label-width="150px"> |
|||
<el-switch v-model="form.ignore_pickup_check" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
<el-col :span="8"> |
|||
<el-form-item label="忽视放货校验" label-width="150px"> |
|||
<el-switch v-model="form.ignore_release_check" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
|
|||
<el-row> |
|||
<el-col :span="8"> |
|||
<el-form-item label="呼叫"> |
|||
<el-switch v-model="form.apply_task" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
<el-col :span="8"> |
|||
<el-form-item label="响应" label-width="150px"> |
|||
<el-switch v-model="form.manual_create_task" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
|
|||
<el-row> |
|||
<el-col :span="8"> |
|||
<el-form-item label="关联设备" prop="device_code"> |
|||
<el-select |
|||
v-model="form.link_device_code" |
|||
filterable |
|||
multiple |
|||
placeholder="请选择" |
|||
> |
|||
<el-option |
|||
v-for="item in deviceList" |
|||
:key="item.device_code" |
|||
:label="item.device_name" |
|||
:value="item.device_code" |
|||
/> |
|||
</el-select> |
|||
</el-form-item> |
|||
</el-col> |
|||
<el-col :span="8"> |
|||
<el-form-item label="关联三色灯" prop="device_code" label-width="100px"> |
|||
<el-select |
|||
v-model="form.link_three_lamp" |
|||
filterable |
|||
clearable |
|||
placeholder="请选择" |
|||
> |
|||
<el-option |
|||
v-for="item in deviceList" |
|||
:key="item.device_code" |
|||
:label="item.device_name" |
|||
:value="item.device_code" |
|||
/> |
|||
</el-select> |
|||
</el-form-item> |
|||
</el-col> |
|||
<el-col :span="8"> |
|||
<el-form-item label="是否输入物料" label-width="150px"> |
|||
<el-switch v-model="form.input_material" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
</el-form> |
|||
</el-card> |
|||
|
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span">AGV相关:</span> |
|||
</div> |
|||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px"> |
|||
<el-row> |
|||
<el-col :span="8"> |
|||
<el-form-item label="取货"> |
|||
<el-switch v-model="form.is_pickup" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
<el-col :span="8"> |
|||
<el-form-item label="放货"> |
|||
<el-switch v-model="form.is_release" /> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
</el-form> |
|||
</el-card> |
|||
|
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span">PLC读取字段:</span> |
|||
</div> |
|||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px"> |
|||
<el-table |
|||
v-loading="false" |
|||
:data="data1" |
|||
:max-height="550" |
|||
size="small" |
|||
style="width: 100%;margin-bottom: 15px" |
|||
> |
|||
|
|||
<el-table-column prop="name" label="用途" /> |
|||
<el-table-column prop="code" label="别名要求" /> |
|||
<el-table-column prop="db" label="DB块"> |
|||
<template slot-scope="scope"> |
|||
<el-input |
|||
v-model="data1[scope.$index].db" |
|||
size="mini" |
|||
class="edit-input" |
|||
@input="finishReadEdit(data1[scope.$index])" |
|||
/> |
|||
</template> |
|||
</el-table-column> |
|||
<el-table-column prop="dbr_value"> |
|||
<template slot="header"> |
|||
<el-link type="primary" :underline="false" @click.native="test_read1()">测试读</el-link> |
|||
</template> |
|||
<template slot-scope="scope"> |
|||
<el-input v-model="data1[scope.$index].dbr_value" size="mini" class="edit-input" /> |
|||
</template> |
|||
</el-table-column> |
|||
</el-table> |
|||
</el-form> |
|||
</el-card> |
|||
|
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span">PLC写入字段:</span> |
|||
</div> |
|||
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="78px"> |
|||
<el-table |
|||
v-loading="false" |
|||
:data="data2" |
|||
:max-height="550" |
|||
size="small" |
|||
style="width: 100%;margin-bottom: 15px" |
|||
> |
|||
|
|||
<el-table-column prop="name" label="用途" /> |
|||
<el-table-column prop="code" label="别名要求" /> |
|||
<el-table-column prop="db" label="DB块"> |
|||
<template slot-scope="scope"> |
|||
<el-input |
|||
v-model="data2[scope.$index].db" |
|||
size="mini" |
|||
class="edit-input" |
|||
@input="finishWriteEdit(data2[scope.$index])" |
|||
/> |
|||
</template> |
|||
</el-table-column> |
|||
<el-table-column prop="dbw_value"> |
|||
<template slot="header"> |
|||
<el-link type="primary" :underline="false" @click.native="test_write1()">测试写</el-link> |
|||
</template> |
|||
<template slot-scope="scope"> |
|||
<el-input v-model="data2[scope.$index].dbw_value" size="mini" class="edit-input" /> |
|||
</template> |
|||
</el-table-column> |
|||
</el-table> |
|||
</el-form> |
|||
</el-card> |
|||
|
|||
<el-card class="box-card" shadow="never"> |
|||
<div slot="header" class="clearfix"> |
|||
<span class="role-span" /> |
|||
<el-button |
|||
:loading="false" |
|||
icon="el-icon-check" |
|||
size="mini" |
|||
style="float: right; padding: 6px 9px" |
|||
type="primary" |
|||
@click="doSubmit" |
|||
>保存 |
|||
</el-button> |
|||
</div> |
|||
</el-card> |
|||
|
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { |
|||
queryDriverConfig, |
|||
updateConfig, |
|||
testRead, |
|||
testwrite |
|||
} from '@/api/acs/device/driverConfig' |
|||
import { selectOpcList } from '@/api/acs/device/opc' |
|||
import { selectPlcList } from '@/api/acs/device/opcPlc' |
|||
import { selectListByOpcID } from '@/api/acs/device/opcPlc' |
|||
|
|||
import crud from '@/mixins/crud' |
|||
import deviceCrud from '@/api/acs/device/device' |
|||
|
|||
export default { |
|||
name: 'StandardConveyorControl', |
|||
mixins: [crud], |
|||
props: { |
|||
parentForm: { |
|||
type: Object, |
|||
require: true |
|||
} |
|||
}, |
|||
data() { |
|||
return { |
|||
device_code: '', |
|||
device_id: '', |
|||
plc_id: '', |
|||
plc_code: '', |
|||
address: '', |
|||
opc_id: '', |
|||
opc_code: '', |
|||
configLoading: false, |
|||
dataOpcservers: [], |
|||
dataOpcPlcs: [], |
|||
deviceList: [], |
|||
data1: [], |
|||
data2: [], |
|||
form: { |
|||
inspect_in_stocck: true, |
|||
ignore_pickup_check: true, |
|||
ignore_release_check: true, |
|||
apply_task: true, |
|||
link_three_lamp: '', |
|||
manual_create_task: true, |
|||
is_pickup: true, |
|||
is_release: true, |
|||
link_device_code: [] |
|||
}, |
|||
rules: {} |
|||
} |
|||
}, |
|||
created() { |
|||
this.$nextTick(() => { |
|||
// 从父表单获取设备编码 |
|||
this.device_id = this.$props.parentForm.device_id |
|||
this.device_code = this.$props.parentForm.device_code |
|||
queryDriverConfig(this.device_id, this.$props.parentForm.driver_code).then(data => { |
|||
// 给表单赋值,并且属性不能为空 |
|||
if (data.form) { |
|||
const arr = Object.keys(data.form) |
|||
// 不为空 |
|||
if (arr.length > 0) { |
|||
this.form = data.form |
|||
} |
|||
} |
|||
|
|||
// 给表单赋值,并且属性不能为空 |
|||
if (data.parentForm) { |
|||
const arr = Object.keys(data.parentForm) |
|||
// 不为空 |
|||
if (arr.length > 0) { |
|||
this.opc_code = data.parentForm.opc_code |
|||
this.plc_code = data.parentForm.plc_code |
|||
} |
|||
} |
|||
this.data1 = data.rs |
|||
this.data2 = data.ws |
|||
this.sliceItem() |
|||
}) |
|||
selectPlcList().then(data => { |
|||
this.dataOpcPlcs = data |
|||
this.plc_id = this.$props.parentForm.opc_plc_id |
|||
}) |
|||
selectOpcList().then(data => { |
|||
this.dataOpcservers = data |
|||
this.opc_id = this.$props.parentForm.opc_server_id |
|||
}) |
|||
deviceCrud.selectDeviceList().then(data => { |
|||
this.deviceList = data |
|||
}) |
|||
}) |
|||
}, |
|||
methods: { |
|||
finishReadEdit(data) { |
|||
// 编辑的是code列,并且值包含mode |
|||
if (data.code.indexOf('mode') !== -1) { |
|||
const dbValue = data.db |
|||
// .之前的字符串 |
|||
const beforeStr = dbValue.match(/(\S*)\./)[1] |
|||
// .之后的字符串 |
|||
const afterStr = dbValue.match(/\.(\S*)/)[1] |
|||
// 取最后数字 |
|||
const endNumber = afterStr.substring(1) |
|||
// 最后为非数字 |
|||
if (isNaN(parseInt(endNumber))) { |
|||
return |
|||
} |
|||
for (const val in this.data1) { |
|||
if (this.data1[val].code.indexOf('move') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 1) |
|||
} |
|||
if (this.data1[val].code.indexOf('action') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 2) |
|||
} |
|||
if (this.data1[val].code.indexOf('ioaction') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 3) |
|||
} |
|||
if (this.data1[val].code.indexOf('height') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 4) |
|||
} |
|||
if (this.data1[val].code.indexOf('error') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 5) |
|||
} |
|||
if (this.data1[val].code.indexOf('direction') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 6) |
|||
} |
|||
if (this.data1[val].code.indexOf('operation_type') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 7) |
|||
} |
|||
if (this.data1[val].code.indexOf('task') !== -1) { |
|||
this.data1[val].db = beforeStr + '.' + 'D' + (parseInt(endNumber) + 21) |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
finishWriteEdit(data) { |
|||
// 编辑的是code列,并且值包含mode |
|||
if (data.code.indexOf('to_command') !== -1) { |
|||
const dbValue = data.db |
|||
// .之前的字符串 |
|||
const beforeStr = dbValue.match(/(\S*)\./)[1] |
|||
// .之后的字符串 |
|||
const afterStr = dbValue.match(/\.(\S*)/)[1] |
|||
// 取最后数字 |
|||
const endNumber = afterStr.substring(1) |
|||
// 最后为非数字 |
|||
if (isNaN(parseInt(endNumber))) { |
|||
return |
|||
} |
|||
for (const val in this.data2) { |
|||
if (this.data2[val].code.indexOf('to_target') !== -1) { |
|||
this.data2[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 2) |
|||
} |
|||
if (this.data2[val].code.indexOf('to_task') !== -1) { |
|||
this.data2[val].db = beforeStr + '.' + 'D' + (parseInt(endNumber) + 6) |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
changeOpc(val) { |
|||
this.dataOpcservers.forEach(item => { |
|||
if (item.opc_id === val) { |
|||
this.opc_code = item.opc_code |
|||
} |
|||
}) |
|||
|
|||
selectListByOpcID(val).then(data => { |
|||
this.dataOpcPlcs = data |
|||
this.plc_id = '' |
|||
this.plc_code = '' |
|||
if (this.dataOpcPlcs && this.dataOpcPlcs.length > 0) { |
|||
this.plc_id = this.dataOpcPlcs[0].plc_id |
|||
this.plc_code = this.dataOpcPlcs[0].plc_code |
|||
} |
|||
this.sliceItem() |
|||
}) |
|||
}, |
|||
changePlc(val) { |
|||
this.dataOpcPlcs.forEach(item => { |
|||
if (item.plc_id === val) { |
|||
this.plc_code = item.plc_code |
|||
this.sliceItem() |
|||
return |
|||
} |
|||
}) |
|||
}, |
|||
test_read1() { |
|||
testRead(this.data1, this.opc_id).then(data => { |
|||
this.data1 = data |
|||
this.notify('操作成功!', 'success') |
|||
}).catch(err => { |
|||
console.log(err.response.data.message) |
|||
}) |
|||
}, |
|||
test_write1() { |
|||
testwrite(this.data2, this.opc_id).then(data => { |
|||
this.notify('操作成功!', 'success') |
|||
}).catch(err => { |
|||
console.log(err.response.data.message) |
|||
}) |
|||
}, |
|||
doSubmit() { |
|||
this.$refs['form'].validate((valid) => { |
|||
if (valid) { |
|||
this.configLoading = true |
|||
// 根据驱动类型判断是否为路由设备 |
|||
const parentForm = this.parentForm |
|||
parentForm.is_route = true |
|||
parentForm.plc_id = this.plc_id |
|||
parentForm.opc_id = this.opc_id |
|||
updateConfig(parentForm, this.form, this.data1, this.data2).then(res => { |
|||
this.notify('保存成功', 'success') |
|||
this.configLoading = false |
|||
}).catch(err => { |
|||
this.configLoading = false |
|||
console.log(err.response.data.message) |
|||
}) |
|||
} |
|||
}) |
|||
}, |
|||
sliceItem() { // 拼接DB的Item值 |
|||
this.data1.forEach(item => { |
|||
const str = item.code |
|||
// 是否包含. |
|||
if (str.search('.') !== -1) { |
|||
// 截取最后一位 |
|||
item.code = this.opc_code + '.' + this.plc_code + '.' + this.device_code + '.' + str.slice(str.lastIndexOf('.') + 1) |
|||
} else { |
|||
item.code = this.opc_code + '.' + this.plc_code + '.' + this.device_code + '.' + item.code |
|||
} |
|||
}) |
|||
this.data2.forEach(item => { |
|||
const str = item.code |
|||
// 是否包含. |
|||
if (str.search('.') !== -1) { |
|||
// 截取最后一位 |
|||
item.code = this.opc_code + '.' + this.plc_code + '.' + this.device_code + '.' + str.slice(str.lastIndexOf('.') + 1) |
|||
} else { |
|||
item.code = this.opc_code + '.' + this.plc_code + '.' + this.device_code + '.' + item.code |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
|
|||
</style> |
Loading…
Reference in new issue