纸管库和套管工位驱动编写

This commit is contained in:
yanps
2023-11-07 10:47:16 +08:00
parent 82c46653e6
commit 2e634be0ce
12 changed files with 620 additions and 73 deletions

View File

@@ -59,7 +59,9 @@ public enum DriverTypeEnum {
PACKAGE_MANIPULATOR(24,"package_manipulator","内包间行架机械手","station"),
PAPER_TUBE_DEVICE2(22, "paper_tube_conveyor2", "纸管库设备2", "conveyor");
PAPER_TUBE_DEVICE2(25, "paper_tube_conveyor2", "纸管库设备2", "conveyor"),
CASING_STATION(26, "casing_station", "套管工位", "conveyor");
//驱动索引
private int index;

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.basedriver.paper_tube_device2.PaperTubeConveyor2DeviceDriver;
import java.util.ArrayList;
import java.util.List;

View File

@@ -123,7 +123,7 @@ public class PaperTubeConveyorDeviceDriver extends AbstractOpcDeviceDriver imple
}
if (out_finish != last_out_finish) {
if(out_finish == 1){
this.writing(0);
//this.writing(0);
this.writing("to_target","0");
this.writing("to_out_qty","0");
@@ -197,7 +197,7 @@ public class PaperTubeConveyorDeviceDriver extends AbstractOpcDeviceDriver imple
itemMap.put(to_param, Integer.parseInt(param));
// itemMap.put(to_param, Integer.parseInt(value));
this.control(itemMap);
//this.control(itemMap);
logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + param);
}

View File

@@ -1,8 +1,12 @@
package org.nl.acs.device_driver.basedriver.paper_tube_device2;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
@@ -82,7 +86,7 @@ public class ItemProtocol {
public static String item_to_command = "to_command";
//下发目标站
public static String item_to_target = "to_target";
//下发任务号
public static String item_to_task = "to_task";
public static String item_to_material1 = "to_material1";
public static String item_to_out_qty1 = "to_out_qty1";
@@ -114,10 +118,40 @@ public class ItemProtocol {
return this.getOpcIntegerValue(item_mode);
}
public int getMove() {
return this.getOpcIntegerValue(item_move);
}
public int getCarrier_direction() {
return this.getOpcIntegerValue(item_carrier_direction);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
public int getTo_task() {
return this.getOpcIntegerValue(item_to_task);
}
public String getItem_out_seq_arr() {
return this.getOpcStringValue(item_out_seq_arr);
}
public List getItem_out_seq_arr1() {
return this.getOpcArrayValue1(item_out_seq_arr);
}
public int[] getItem_out_qty_arr() {
return this.getOpcArrayValue(item_out_qty_arr);
}
public String getMaterial1() {
return this.getOpcStringValue(item_material1);
}
@@ -200,12 +234,61 @@ public class ItemProtocol {
return "0";
}
public int[] getOpcArrayValue(String protocol) {
int[] arrayValue = this.driver.getIntegeregerArrayValue(protocol);
if (ObjectUtil.isNull(arrayValue)) {
} else {
return arrayValue;
}
return new int[3];
}
public List getOpcArrayValue1(String protocol) {
List arrayValue = this.driver.getArrayValue(protocol);
if (ObjectUtil.isNull(arrayValue)) {
} else {
return arrayValue;
}
return new ArrayList();
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB101.W0"));
list.add(new ItemDto(item_mode, "模式", "DB101.W2"));
list.add(new ItemDto(item_error, "error", "DB101.W58"));
list.add(new ItemDto(item_mode, "工作模式", "DB101.W2"));
list.add(new ItemDto(item_move, "光电信号", "DB101.W3"));
list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB101.W4"));
list.add(new ItemDto(item_error, "报警", "DB101.W58"));
list.add(new ItemDto(item_task, "任务号", "DB101.W68"));
list.add(new ItemDto(item_out_seq_arr, "出库顺序数组", "DB101.W5"));
list.add(new ItemDto(item_out_qty_arr, "出库数量数组", "DB101.W6"));
list.add(new ItemDto(item_material1, "物料1", "DB101.W7"));
list.add(new ItemDto(item_qty1, "数量1", "DB101.W19"));
list.add(new ItemDto(item_material2, "物料2", "DB101.W8"));
list.add(new ItemDto(item_qty2, "数量2", "DB101.W20"));
list.add(new ItemDto(item_material3, "物料3", "DB101.W9"));
list.add(new ItemDto(item_qty3, "数量3", "DB101.W21"));
list.add(new ItemDto(item_material4, "物料4", "DB101.W10"));
list.add(new ItemDto(item_qty4, "数量4", "DB101.W22"));
list.add(new ItemDto(item_material5, "物料5", "DB101.W11"));
list.add(new ItemDto(item_qty5, "数量5", "DB101.W23"));
list.add(new ItemDto(item_material6, "物料6", "DB101.W12"));
list.add(new ItemDto(item_qty6, "数量6", "DB101.W24"));
list.add(new ItemDto(item_material7, "物料7", "DB101.W13"));
list.add(new ItemDto(item_qty7, "数量7", "DB101.W25"));
list.add(new ItemDto(item_material8, "物料8", "DB101.W14"));
list.add(new ItemDto(item_qty8, "数量8", "DB101.W26"));
list.add(new ItemDto(item_material9, "物料9", "DB101.W15"));
list.add(new ItemDto(item_qty9, "数量9", "DB101.W27"));
list.add(new ItemDto(item_material10, "物料10", "DB101.W16"));
list.add(new ItemDto(item_qty10, "数量10", "DB101.W28"));
list.add(new ItemDto(item_material11, "物料11", "DB101.W17"));
list.add(new ItemDto(item_qty11, "数量11", "DB101.W29"));
list.add(new ItemDto(item_material12, "物料12", "DB101.W18"));
list.add(new ItemDto(item_qty12, "数量12", "DB101.W30"));
return list;
}
@@ -213,7 +296,19 @@ public class ItemProtocol {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_target , "下发仓位号", "DB102.W2"));
list.add(new ItemDto(item_to_command, "下发命令", "DB102.W4"));
list.add(new ItemDto(item_to_task, "下发任务号", "DB102.W1"));
list.add(new ItemDto(item_to_material1, "下发物料1", "DB102.W3"));
list.add(new ItemDto(item_to_out_qty1, "下发物料1数量", "DB102.W7"));
list.add(new ItemDto(item_to_seq1, "出库顺序1", "DB102.W10"));
list.add(new ItemDto(item_to_position1, "仓位1", "DB102.W13"));
list.add(new ItemDto(item_to_material2, "下发物料2", "DB102.W5"));
list.add(new ItemDto(item_to_out_qty2, "下发物料2数量", "DB102.W8"));
list.add(new ItemDto(item_to_seq2, "出库顺序2", "DB102.W11"));
list.add(new ItemDto(item_to_position2, "仓位2", "DB102.W14"));
list.add(new ItemDto(item_to_material3, "下发物料3", "DB102.W6"));
list.add(new ItemDto(item_to_out_qty3, "下发物料3数量", "DB102.W9"));
list.add(new ItemDto(item_to_seq3, "出库顺序3", "DB102.W12"));
list.add(new ItemDto(item_to_position3, "仓位3", "DB102.W15"));
return list;
}

View File

@@ -1,6 +1,12 @@
package org.nl.acs.device_driver.basedriver.paper_tube_device2;
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 cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
@@ -11,24 +17,29 @@ 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.data.ApplyPaperActionRequest;
import org.nl.acs.ext.wms.data.ApplyPaperActionResponse;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.history.ErrorUtil;
import org.nl.acs.history.service.DeviceErrorLogService;
import org.nl.acs.history.service.dto.DeviceErrorLogDto;
import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl;
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.route.service.dto.RouteLineDto;
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.wql.util.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 纸管库
@@ -56,19 +67,57 @@ public class PaperTubeConveyor2DeviceDriver extends AbstractOpcDeviceDriver impl
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
@Autowired
AgvService agvService = SpringContextHolder.getBean(AgvService.class);
@Autowired
DeviceErrorLogService deviceErrorLogService = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class);
private Date instruction_update_time = new Date();
private Date require_apply_strangulation_time = new Date();
private int instruction_update_time_out = 500;
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 last_heartbeat = 0;
//工作模式
int mode = 0;
int inventory_qty =0;
int out_finish =0;
int error =0;
int to_command =0;
int to_target =0;
int last_mode = 0;
//光电信号
int move = 0;
int last_move = 0;
//托盘方向
int carrier_direction = 0;
int last_carrier_direction = 0;
//报警
int error = 0;
int last_error = 0;
//任务号
int task = 0;
int last_task = 0;
int inventory_qty = 0;
int out_finish = 0;
//下发命令
int to_command = 0;
int last_to_command = 0;
//下发目标站
int to_target = 0;
int last_to_target = 0;
//下发任务号
int to_task = 0;
int last_to_task = 0;
String item_out_seq_arr = null;
List item_out_seq_arr1 = null;
String last_item_out_seq_arr = null;
int[] item_out_qty_arr = null;
int[] last_item_out_qty_arr = null;
//当前指令
Instruction inst = null;
String material = null;
Boolean isonline = true;
@@ -78,13 +127,16 @@ public class PaperTubeConveyor2DeviceDriver extends AbstractOpcDeviceDriver impl
//1-执行任务2-取货完成3-放货完成;
int flag;
int last_mode = 0;
int last_inventory_qty =0;
int last_out_finish =0;
int last_error = 0;
String last_material = null;
int last_inventory_qty = 0;
int last_out_finish = 0;
String last_material = null;
String message = null;
String device_code;
String task_code = null;
String vehicle_code;
String inst_message;
@Override
public Device getDevice() {
@@ -96,57 +148,125 @@ public class PaperTubeConveyor2DeviceDriver extends AbstractOpcDeviceDriver impl
@Override
public void execute() {
String message = null;
try {
String message = null;
device_code = this.getDeviceCode();
heartbeat = this.itemProtocol.getHeartbeat();
mode = this.itemProtocol.getMode();
move = this.itemProtocol.getMove();
carrier_direction = this.itemProtocol.getCarrier_direction();
error = this.itemProtocol.getError();
task = this.itemProtocol.getTask();
to_command = this.itemProtocol.getTo_command();
to_target = this.itemProtocol.getTotarget();
to_task = this.itemProtocol.getTo_task();
//item_out_seq_arr1 = this.itemProtocol.getItem_out_seq_arr1();
item_out_seq_arr = this.itemProtocol.getItem_out_seq_arr();
item_out_qty_arr = this.itemProtocol.getItem_out_qty_arr();
device_code = this.getDeviceCode();
heartbeat = this.itemProtocol.getHeartbeat();
mode = this.itemProtocol.getMode();
error = this.itemProtocol.getError();
to_command = this.itemProtocol.getTo_command();
to_target = this.itemProtocol.getTotarget();
if (mode != last_mode) {
this.setRequireSucess(false);
if (mode == 0) {
this.setIsonline(false);
message = "未联机";
} else {
this.setIsonline(true);
if (to_command != last_to_command) {
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command" + last_to_command + "->" + to_command);
}
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
if (inventory_qty != last_inventory_qty) {
logServer.deviceExecuteLog(this.device_code, "", "", "信号inventory_qty" + last_inventory_qty + "->" + inventory_qty);
}
if (out_finish != last_out_finish) {
if(out_finish == 1){
this.writing(0);
this.writing("to_target","0");
this.writing("to_out_qty","0");
if (to_target != last_to_target) {
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target" + last_to_target + "->" + to_target);
}
logServer.deviceExecuteLog(this.device_code, "", "", "信号out_finish" + last_out_finish + "->" + out_finish);
}
if (!StrUtil.equals(material,last_material)) {
logServer.deviceExecuteLog(this.device_code, "", "", "信号material" + last_material + "->" + material);
}
if (error != last_error) {
if(error > 0){
this.setIserror(true);
} else {
if(error > 0){
this.setIserror(false);
if (to_task != last_to_task) {
logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task" + last_to_task + "->" + to_task);
}
if (mode != last_mode) {
JSONObject param = new JSONObject();
param.put("device_code", this.device_code);
param.put("mode", Math.min(mode, 3));
param.put("device_name", this.getDevice().getDevice_name());
param.put("device_type", "1");
param.put("product_area", paramService.findByCode("productArea").getValue());
acsToWmsService.sendDeviceStatus(param);
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode + "复位请求标记:" + requireSucess);
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 (carrier_direction != last_carrier_direction) {
logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction));
logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction" + last_carrier_direction + "->" + carrier_direction);
}
if (error != last_error) {
if (error != 0) {
DeviceErrorLogDto dto = new DeviceErrorLogDto();
dto.setDevice_code(device_code);
dto.setError_code(String.valueOf(error));
String errorInfo = ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(error));
dto.setError_info(errorInfo);
deviceErrorLogService.create(dto);
}
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号error" + last_error + "->" + error);
}
logServer.deviceExecuteLog(this.device_code, "", "", "信号out_finish" + last_out_finish + "->" + out_finish);
if (task != last_task) {
logServer.deviceItemValue(this.device_code, "task", String.valueOf(task));
logServer.deviceExecuteLog(this.device_code, "", "", "信号task" + last_task + "->" + task);
}
if (move != 0 && task > 0) {
update_instruction_status();
}
} catch (Exception var17) {
var17.printStackTrace();
logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol));
}
if (mode == 0) {
this.setIsonline(false);
message = "未联机";
} else if (error != 0) {
this.setIserror(true);
message = "有报警";
} else {
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
//纸管库申请任务
switch (mode) {
case 1:
log.debug("弃用(留作兼容)");
break;
case 2:
//申请任务
if (move > 0 && !requireSucess) {
instruction_require();
}
break;
case 3:
log.info("运行中");
break;
case 4:
//申请出货
if (move == 1 && !requireSucess) {
request_for_shipment(String.valueOf(mode), item_out_seq_arr, item_out_qty_arr);
}
break;
}
}
last_heartbeat = heartbeat;
last_mode = mode;
last_inventory_qty = inventory_qty;
last_out_finish = out_finish;
last_error = error;
last_material = material;
last_carrier_direction = carrier_direction;
last_task = task;
last_to_command = to_command;
last_to_target = to_target;
last_to_task = to_task;
last_item_out_seq_arr = item_out_seq_arr;
last_item_out_qty_arr = item_out_qty_arr;
}
@@ -160,7 +280,6 @@ public class PaperTubeConveyor2DeviceDriver extends AbstractOpcDeviceDriver impl
public void writing(List list) {
Map<String, Object> itemMap = new HashMap<String, Object>();
for (int i = 0; i < list.size(); i++) {
Object ob = list.get(i);
@@ -176,28 +295,240 @@ public class PaperTubeConveyor2DeviceDriver extends AbstractOpcDeviceDriver impl
this.checkcontrol(itemMap);
} catch (Exception e) {
e.printStackTrace();
try{
try {
this.checkcontrol(itemMap);
} catch (Exception e1){
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
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)) {
this.control(itemMap);
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap);
}
}
public synchronized void request_for_shipment(String mode, String item_out_seq_arr, int[] item_out_qty_arr) {
Date date = new Date();
if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) {
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out);
} else {
this.require_apply_strangulation_time = date;
ApplyPaperActionRequest applyPaperActionRequest = new ApplyPaperActionRequest();
applyPaperActionRequest.setDevice_code(this.device_code);
applyPaperActionRequest.setType("1");
applyPaperActionRequest.setTask_code(String.valueOf(task));
//获取出库顺序
boolean contains = item_out_seq_arr.contains(",");
//String s = item_out_seq_arr.replaceAll("[\\[\\]]", "");
if (contains) {
String[] split = item_out_seq_arr.split(",");
applyPaperActionRequest.setMaterial1(split[0]);
applyPaperActionRequest.setMaterial2(split[1]);
} else {
applyPaperActionRequest.setMaterial1(item_out_seq_arr);
}
/*if (item_out_qty_arr.length == 2) {
// 去除方括号
applyPaperActionRequest.setMaterial1(String.valueOf(item_out_qty_arr[0]));
applyPaperActionRequest.setMaterial2(String.valueOf(item_out_qty_arr[1]));
} else if (item_out_qty_arr.length == 1) {
applyPaperActionRequest.setMaterial1(String.valueOf(item_out_qty_arr[0]));
}*/
if (item_out_qty_arr.length >= 1 && item_out_qty_arr.length < 4) {
applyPaperActionRequest.setQty1(String.valueOf(item_out_qty_arr[0]));
applyPaperActionRequest.setQty2(String.valueOf(item_out_qty_arr[1]));
}
ApplyPaperActionResponse applyPaperActionResponse = acsToWmsService.applyPaperActionRequest(applyPaperActionRequest);
Map map3 = new HashMap();
if (applyPaperActionResponse.getstatus() == 200) {
map3.put("to_command", "4");
this.writing(map3);
requireSucess = true;
logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse);
message = "申请出货成功";
} else {
message = applyPaperActionResponse.getMessage();
map3.put("to_command", "5");
this.writing(map3);
requireSucess = false;
message = "出库顺序错误";
logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse);
}
}
}
/**
* 申请任务
*/
public synchronized Boolean instruction_require() {
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;
//查找有没有对应的指令
//找指令类型是10的
Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code);
if (ObjectUtil.isNull(inst)) {
return false;
}
if (ObjectUtil.isNotNull(inst) && "10".equals(inst.getInstruction_code())) {
Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code());
String next_addr = nextdevice.getExtraValue().get("address").toString();
TaskDto taskDto = taskserver.findByCodeFromCache(inst.getTask_code());
List<Paper> paperArray = getPaperArray(taskDto.getPaper_array());
if (ObjectUtil.isEmpty(inst)) {
return false;
}
Map map = new HashMap();
if (paperArray.size() == 1) {
writeStatus(paperArray, map, 1);
} else if (paperArray.size() == 2) {
writeStatus(paperArray, map, 1);
writeStatus(paperArray, map, 2);
} else if (paperArray.size() == 3) {
writeStatus(paperArray, map, 1);
writeStatus(paperArray, map, 2);
writeStatus(paperArray, map, 3);
}
writeData(next_addr, inst, map);
this.writing(map);
requireSucess = true;
return true;
} else {
//判断是否有相同起点的,任务状态就绪的任务
//任务类型是10
TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code);
if (ObjectUtil.isNull(taskdto)) {
return false;
}
List<Paper> paperArray = getPaperArray(taskdto.getPaper_array());
if (ObjectUtil.isNotNull(taskdto) && "10".equals(taskdto.getTask_type())) {
//判断指令的起点和当前的设备号相同
if (!taskdto.getStart_device_code().equals(device_code)) {
return false;
}
//判断当前任务号是否存在指令
Instruction inst1 = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code());
Device nextdevice = deviceAppservice.findDeviceByCode(inst1.getNext_device_code());
String next_addr = nextdevice.getExtraValue().get("address").toString();
Device pointdevice = deviceAppservice.findDeviceByCode(inst1.getNext_point_code());
String point_addr = pointdevice.getExtraValue().get("address").toString();
//没有就创建指令
String taskid = taskdto.getTask_id();
String taskcode = taskdto.getTask_code();
String priority = taskdto.getPriority();
String start_point_code = taskdto.getStart_point_code();
String start_device_code = taskdto.getStart_device_code();
String route_plan_code = taskdto.getRoute_plan_code();
Instruction instdto = new Instruction();
instdto.setInstruction_id(IdUtil.simpleUUID());
instdto.setRoute_plan_code(route_plan_code);
instdto.setRemark(taskdto.getRemark());
instdto.setMaterial(taskdto.getMaterial());
instdto.setQuantity(taskdto.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_addr);
instdto.setStart_point_code(start_point_code);
instdto.setNext_point_code(point_addr);
instdto.setPriority(priority);
instdto.setInstruction_status("0");
instdto.setExecute_device_code(start_point_code);
try {
instructionService.create(instdto);
} catch (Exception e) {
e.printStackTrace();
log.error("指令创建失败!", e.getMessage());
return false;
}
taskdto.setTask_status("1");
taskserver.update(taskdto);
requireSucess = true;
Map map = new HashMap();
if (paperArray.size() == 1) {
writeStatus(paperArray, map, 1);
} else if (paperArray.size() == 2) {
writeStatus(paperArray, map, 1);
writeStatus(paperArray, map, 2);
} else if (paperArray.size() == 3) {
writeStatus(paperArray, map, 1);
writeStatus(paperArray, map, 2);
writeStatus(paperArray, map, 3);
}
writeData(next_addr, instdto, map);
this.writing(map);
requireSucess = true;
return true;
}
//并且指令的起点和当前的设备号相同
//找到就要下发数据
//查找就绪状态的任务
//并且任务的起点和当前的设备号相同
//找到创建指令
//入库顺序
}
return false;
}
}
public void writeData(String next_addr, Instruction instdto, Map map) {
map.put("to_target", next_addr);
map.put("to_task", instdto.getInstruction_code());
map.put("to_command", "1");
}
public String getToParam() {
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
}
public void writeStatus(List<Paper> paperArray, Map map, Integer status) {
Paper paper = paperArray.get(status);
map.put("to_material" + status, paper.getMeterial_code());
map.put("to_out_qty" + status, paper.getQty());
map.put("to_seq" + status, "1");
map.put("to_position" + status, paper.getDevice_code());
}
public void writing(String key, String param) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
//String opcservcerid = this.getDevice().getOpc_server_id();
//Server server = ReadUtil.getServer(opcservcerid);
//Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_param, Integer.parseInt(param));
// itemMap.put(to_param, Integer.parseInt(value));
//itemMap.put(to_param, Integer.parseInt(value));
this.control(itemMap);
logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + param);
}
public synchronized boolean finish_instruction() throws Exception {
instructionService.finish(inst);
return true;
}
@Override
public JSONObject getDeviceStatusName() {
JSONObject jo = new JSONObject();
@@ -225,6 +556,65 @@ public class PaperTubeConveyor2DeviceDriver extends AbstractOpcDeviceDriver impl
return jo;
}
/**
* 解析出库的顺序
*/
public List<Paper> getPaperArray(String paper_array) {
JSONArray jsonArray = JSONUtil.parseArray(paper_array);
List<Paper> papers = jsonArray.toList(Paper.class);
return papers;
}
/**
* 更新指令状态
*/
public synchronized void update_instruction_status() throws Exception {
Date date = new Date();
if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) {
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out);
} else {
this.instruction_update_time = date;
inst = checkInst();
if (inst != null) {
//a点到b点,给状态说允许取货
if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) {
inst.setInstruction_status("1");
inst.setExecute_device_code(this.device_code);
instructionService.update(inst);
logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task);
}
//当货物到达b点,实现完成指令
if (StrUtil.equals(inst.getInstruction_status(), "1") || StrUtil.equals(inst.getInstruction_status(), "0")) {
if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) {
inst.setExecute_device_code(this.device_code);
finish_instruction();
logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task);
}
}
}
}
}
public Instruction checkInst() {
if (ObjectUtil.isNotEmpty(this.inst)) {
if (this.task > 0) {
if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) {
return this.inst;
} else {
inst = instructionService.findByCodeFromCache(String.valueOf(task));
return inst;
}
}
} else {
inst = instructionService.findByCodeFromCache(String.valueOf(task));
return inst;
}
return null;
}
@Override
public void setDeviceStatus(JSONObject data) {

View File

@@ -81,6 +81,11 @@ public interface OpcDeviceDriver extends DeviceDriver {
return (String) this.getOpcValueAccessor().getValue(this.getItem(protocol));
}
default List getArrayValue(String protocol) {
return (List) this.getOpcValueAccessor().getValue(this.getItem(protocol));
}
default Object getValue(String protocol) {
return this.getOpcValueAccessor().getValue(this.getItem(protocol));
}

View File

@@ -98,6 +98,13 @@ public interface AcsToWmsService {
*/
ApplyLabelingAndBindingResponse applyLabelingAndBindingRequest(ApplyLabelingAndBindingRequest param);
/**
* 申请出纸管,套纸管
* @param param
* @return
*/
ApplyPaperActionResponse applyPaperActionRequest(ApplyPaperActionRequest param);
LiKuApplyTakResponse liKuApplyTaskRequest(LiKuApplyTaskRequest liKuApplyTaskRequest);
UpdateLKTaskResponse updateLKTaskRequest(UpdateLKTaskRequest updateLKTaskRequest);

View File

@@ -444,10 +444,42 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
} finally {
MDC.remove(log_file_type);
}
}
@Override
public ApplyPaperActionResponse applyPaperActionRequest(ApplyPaperActionRequest param) {
try {
MDC.put(log_file_type, log_type);
ApplyPaperActionResponse applyPaperActionResponse = new ApplyPaperActionResponse();
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) {
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue();
AddressDto addressDto = addressService.findByCode("applyPaperAction");
String methods_url = addressDto.getMethods_url();
String url = wmsUrl + methods_url;
log.info("ApplyPaperActionRequest----请求参数{}", param);
try {
// String result = "";
String result = HttpRequest.post(url)
.body(JSON.toJSONString(param))
.execute().body();
JSONObject jsonObject = JSONObject.parseObject(result);
log.info("ApplyPaperActionResponse----返回参数{}", result);
applyPaperActionResponse = JSONObject.toJavaObject(jsonObject, ApplyPaperActionResponse.class);
} catch (Exception e) {
JSONObject map = new JSONObject();
map.put("status", 400);
map.put("message", e.getMessage());
return JSONObject.toJavaObject(map, ApplyPaperActionResponse.class);
}
}
return applyPaperActionResponse;
} finally {
MDC.remove(log_file_type);
}
}
@Override
public LiKuApplyTakResponse liKuApplyTaskRequest(LiKuApplyTaskRequest param) {
try {

View File

@@ -1186,6 +1186,11 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return null;
}
/**
* 根据任务号查询任务
* @param task_code
* @return
*/
public TaskDto findByCodeFromCache(String task_code) {
Iterator var3 = tasks.iterator();

View File

@@ -1,5 +1,5 @@
server:
port: 8010
port: 8011
tomcat:
accept-count: 1000
max-connections: 10000