更新
This commit is contained in:
@@ -17,6 +17,7 @@ import org.nl.acs.instruction.service.impl.InstructionServiceImpl;
|
||||
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.nl.modules.system.service.ParamService;
|
||||
import org.nl.modules.system.service.impl.ParamServiceImpl;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
@@ -286,6 +287,9 @@ public class TwoNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
try {
|
||||
log.info("下发agv数据:" + Bytes2HexString(b));
|
||||
System.out.println("下发agv数据:" + Bytes2HexString(b));
|
||||
if(ObjectUtil.isEmpty(dos)){
|
||||
throw new BadRequestException("2楼NDC链接异常!");
|
||||
}
|
||||
dos.write(b);
|
||||
dos.flush();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -514,7 +514,11 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
|
||||
}
|
||||
}
|
||||
logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap);
|
||||
this.control(itemMap);
|
||||
try{
|
||||
this.checkcontrol(itemMap);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
package org.nl.acs.device_driver.driver;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.nl.acs.ext.wms.data.JsonUtl;
|
||||
import org.nl.acs.opc.OpcConfig;
|
||||
import org.nl.acs.opc.OpcServerService;
|
||||
import org.nl.acs.opc.OpcServerServiceImpl;
|
||||
import org.nl.acs.opc.WcsConfig;
|
||||
import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.opc.*;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.nl.modules.wql.exception.WDKException;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.AddFailedException;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver {
|
||||
|
||||
@Autowired
|
||||
private OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class);
|
||||
|
||||
UnifiedDataAccessor opcUdw;
|
||||
|
||||
private Date sendTime;
|
||||
@@ -34,6 +38,65 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
return this.opcUdw;
|
||||
}
|
||||
|
||||
|
||||
public void checkcontrol(Map<String, Object> itemValues) throws JIException, AddFailedException {
|
||||
Group group = opcServerService.getServer(this.getOpcServer());
|
||||
Map<String, Object> write = new HashMap();
|
||||
Map<String, Item> readitems = new LinkedHashMap();
|
||||
List<String> itemsString = new ArrayList();
|
||||
itemsString = new ArrayList<> (itemValues.keySet());
|
||||
Iterator is = itemsString.iterator();
|
||||
|
||||
while (is.hasNext()) {
|
||||
String string = (String) is.next();
|
||||
try {
|
||||
readitems.put(string, group.addItem(string));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
while(true) {
|
||||
//下发信号
|
||||
control( itemValues);
|
||||
Map<String, Object> read = new HashMap();
|
||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[])readitems.values().toArray(new Item[0]));
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var15 = items.iterator();
|
||||
|
||||
while(var15.hasNext()) {
|
||||
Item item = (Item)var15.next();
|
||||
ItemState itemState = (ItemState)itemStatus.get(item);
|
||||
Object value = OpcUtl.getValue(item, itemState);
|
||||
read.put(item.getId(), value);
|
||||
}
|
||||
|
||||
boolean check = true;
|
||||
Iterator var24 = itemsString.iterator();
|
||||
|
||||
while(var24.hasNext()) {
|
||||
String itemString = (String)var24.next();
|
||||
if (!ObjectUtl.isEquals(itemValues.get(itemString), JsonUtl.parse(read.get(itemString)))) {
|
||||
check = false;
|
||||
}
|
||||
}
|
||||
if (check) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
ThreadUtl.sleep(300L);
|
||||
}
|
||||
|
||||
if (i > 3) {
|
||||
throw new WDKException("写入次数超过3次而失败");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean control(Map<String, Object> itemValues) {
|
||||
|
||||
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||
|
||||
@@ -722,7 +722,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
//创建任务和指令
|
||||
taskService.create(task_dto);
|
||||
inst.setSend_status("1");
|
||||
taskService.createInst(inst);
|
||||
taskService.extCreateInst(inst);
|
||||
|
||||
} else {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
@@ -106,6 +106,9 @@ public interface InstructionService {
|
||||
void create(Instruction dto) throws Exception;
|
||||
|
||||
void create2(Instruction dto) throws Exception;
|
||||
|
||||
void create3(Instruction dto) throws Exception;
|
||||
|
||||
/**
|
||||
* 再次创建
|
||||
*
|
||||
|
||||
@@ -407,6 +407,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
}
|
||||
} catch (Exception e) {
|
||||
dto.setSend_status("2");
|
||||
dto.setRemark(e.getMessage());
|
||||
e.printStackTrace();
|
||||
log.warn("创建指令异常:"+e.getMessage());
|
||||
}
|
||||
@@ -532,6 +533,122 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
instructions.add(dto);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create3(Instruction dto) throws Exception {
|
||||
dto = foramte(dto);
|
||||
String task_code = dto.getTask_code();
|
||||
TaskDto task = taskService.findByCodeFromCache(task_code);
|
||||
|
||||
WQLObject instwo = WQLObject.getWQLObject("acs_instruction");
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String now = DateUtil.now();
|
||||
if (StrUtil.isEmpty(dto.getRoute_plan_code())) {
|
||||
dto.setRoute_plan_code(task.getRoute_plan_code());
|
||||
}
|
||||
if (StrUtil.isEmpty(dto.getPriority())) {
|
||||
dto.setPriority(task.getPriority());
|
||||
}
|
||||
if (StrUtil.isEmpty(dto.getInstruction_code())) {
|
||||
dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO"));
|
||||
}
|
||||
if (StrUtil.isEmpty(dto.getInstruction_id())) {
|
||||
dto.setInstruction_id(IdUtil.simpleUUID());
|
||||
}
|
||||
if (StrUtil.isEmpty(dto.getIs_send())) {
|
||||
dto.setIs_send(task.getIs_send());
|
||||
}
|
||||
if (StrUtil.isEmpty(dto.getLink_num())) {
|
||||
dto.setIs_send(task.getLink_num());
|
||||
}
|
||||
if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) {
|
||||
dto.setInstruction_type(task.getTask_type());
|
||||
} else if (false) {
|
||||
|
||||
} else {
|
||||
dto.setInstruction_type("3");
|
||||
}
|
||||
|
||||
// 起点设备与终点设备相同则为初始指令
|
||||
if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) {
|
||||
if (!StrUtil.equals(dto.getCompound_inst(), "0")
|
||||
&& StrUtil.equals(task.getCompound_task(), "1")) {
|
||||
dto.setCompound_inst("1");
|
||||
dto.setCompound_inst_data(task.getCompound_task_data());
|
||||
}
|
||||
}
|
||||
|
||||
dto.setCreate_by(currentUsername);
|
||||
dto.setUpdate_by(currentUsername);
|
||||
dto.setUpdate_time(now);
|
||||
dto.setCreate_time(now);
|
||||
dto.setStart_parent_code(task.getStart_parent_code());
|
||||
dto.setNext_parent_code(task.getNext_parent_code());
|
||||
|
||||
if (ObjectUtil.isNotEmpty(task.getTask_type())) {
|
||||
dto.setInstruction_type(task.getTask_type());
|
||||
}
|
||||
|
||||
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
|
||||
Device startdevice = appService.findDeviceByCode(dto.getStart_device_code());
|
||||
Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code());
|
||||
|
||||
HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver;
|
||||
StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver;
|
||||
|
||||
if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver();
|
||||
hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code()));
|
||||
}
|
||||
|
||||
try {
|
||||
String start_device_code = dto.getStart_device_code();
|
||||
String next_device_code = dto.getNext_device_code();
|
||||
String route_plan_code = task.getRoute_plan_code();
|
||||
List<RouteLineDto> shortPathsList =
|
||||
routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code);
|
||||
RouteLineDto route = null;
|
||||
for (int i = 0; i < shortPathsList.size(); i++) {
|
||||
RouteLineDto routeLineDto = shortPathsList.get(i);
|
||||
String route_device = routeLineDto.getDevice_code();
|
||||
String route_next_device = routeLineDto.getNext_device_code();
|
||||
if (route_device.equals(dto.getStart_device_code())
|
||||
&& route_next_device.equals(dto.getNext_device_code())) {
|
||||
route = routeLineDto;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(route)) {
|
||||
throw new BadRequestException("未查询到相关路由!");
|
||||
}
|
||||
if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) {
|
||||
// 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统
|
||||
if (!StrUtil.equals(task.getAgv_system_type(), "0")
|
||||
&& ObjectUtil.isNotEmpty(task.getAgv_system_type())) {
|
||||
NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class);
|
||||
ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto);
|
||||
} else {
|
||||
// Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(), dto);
|
||||
// if (StrUtil.equals(resp.result, "true")) {
|
||||
// dto.setSend_status("1");
|
||||
// } else {
|
||||
// dto.setSend_status("2");
|
||||
// }
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
dto.setSend_status("2");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
|
||||
|
||||
wo.insert(json);
|
||||
instructions.add(dto);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createAgain(Instruction dto) throws Exception {
|
||||
String task_code = dto.getTask_code();
|
||||
|
||||
@@ -205,6 +205,7 @@ public interface TaskService {
|
||||
|
||||
Instruction createInst(Instruction inst) throws Exception;
|
||||
|
||||
Instruction extCreateInst(Instruction inst) throws Exception;
|
||||
|
||||
Instruction createTemporaryInst(TaskDto dto);
|
||||
|
||||
|
||||
@@ -510,12 +510,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
|
||||
wo.insert(json);
|
||||
synchronized(TaskServiceImpl.class){
|
||||
System.out.println("-------------------"+dto.getTask_code());
|
||||
System.out.println("-------------1"+tasks.size());
|
||||
|
||||
tasks.add(dto);
|
||||
System.out.println("-------------2"+tasks.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1195,6 +1190,17 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
return instdto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction extCreateInst(Instruction inst) throws Exception {
|
||||
|
||||
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
|
||||
InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl");
|
||||
|
||||
instructionservice.create3(inst);
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Instruction createInst(Instruction inst) throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user