指令任务迭代器更新

This commit is contained in:
ludj
2023-02-03 22:57:19 +08:00
parent 00027e655d
commit 2db47e8cbc
7 changed files with 1518 additions and 1672 deletions

View File

@@ -21,93 +21,10 @@ import org.openscada.opc.lib.list.ServerList;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class ReadUtil {
public static void main(String[] args) throws AlreadyConnectedException, JIException, UnknownHostException, NotConnectedException, DuplicateGroupException, AddFailedException, InterruptedException {
// 启动服务
/* ItemProtocol ipl = new ItemProtocol();
List<ItemDto> list = ipl.getReadableItemDtos();
List<String> ls = new ArrayList<>();
for (ItemDto dto : list) {
//ls.add("RD3.RD3.2265."+ dto.getCode());
}
ls.add("DDJ1.DDJ1.DDJ1.heartbeat");
ls.add("DDJ1.DDJ1.DDJ1.action");
final Server server = getServer();
Map<String, Object> map = read(ls, server);
*//*Map<String, Object> params=new HashMap<>();
params.put("RD3.RD3.2265."+"mode","0");
write(params, server);*//*
System.out.println(111);*/
/* try {
test();
} catch (InterruptedException e) {
e.printStackTrace();
}*/
//List<Map<String, String>> maps = showAllOpcServer("192.168.81.207", "administrator", "123", "");
Server server = getServer();
List<String> itemString = new ArrayList<String>();
itemString.add("RD1.RD1.1005.test");
Map map = read(itemString, server);
System.out.println(map.get("RD1.RD1.1005.test"));
// int[] a = (int[]) map.get("RD1.RD1.1005.test");
// for(int i=0; i<a.length; i++){
// System.out.println(a[i]);
// }
// Server server = ReadUtil.getServer();
// Map<String, Object> itemMap = new HashMap<String, Object>();
// itemMap.put("RD1.RD1.1005.test", "1.2");
}
/**
* 发布订阅测试
*/
private static final int PERIOD = 100;
private static final int SLEEP = 2000;
public static void test() throws AlreadyConnectedException, JIException, UnknownHostException, AddFailedException, NotConnectedException, DuplicateGroupException, InterruptedException {
/*ConnectionInformation ci = new ConnectionInformation();
ci.setHost("10.1.5.123");
ci.setDomain("");
ci.setUser("freud");
ci.setPassword("password");
ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305");
Server server = new Server(ci,
Executors.newSingleThreadScheduledExecutor());*/
Server server = getServer();
// server.connect();
AccessBase access = new Async20Access(server, PERIOD, false);
access.addItem("RD1.RD1.B21.mode", new DataCallback() {
private int count;
@SneakyThrows
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++count) + "],ItemName:["
+ item.getId() + "],value:" + itemstate.getValue());
System.out.println(itemstate.getValue().isArray());
List<String> listB = Arrays.asList(itemstate.getValue().toString());
System.out.println(listB.get(0));
}
});
access.bind();
Thread.sleep(SLEEP);
access.unbind();
server.dispose();
}
public static Server getServer(String opc_id) {
//OPC表【acs_opc】
@@ -134,28 +51,6 @@ public class ReadUtil {
return server;
}
public static Server getServer() {
//RD1.RD1.1028
// 连接信息
ConnectionInformation ci = new ConnectionInformation();
ci.setHost("192.168.81.251");
ci.setDomain("");
ci.setUser("administrator");
ci.setPassword("Huawei@123");
ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729");
final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
try {
server.connect();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (JIException e) {
e.printStackTrace();
} catch (AlreadyConnectedException e) {
e.printStackTrace();
}
return server;
}
public static void write(Map<String, Object> strings, Server server) {
try {
//Group group = this.opcServerService.getServer(opcServiceCode);
@@ -198,7 +93,6 @@ public class ReadUtil {
public static Map<String, Object> read(List<String> itemString, Server server) {
HashMap map = new HashMap();
try {
//Group group = this.opcServerService.getServer(opcServiceCode);
Group group = server.addGroup();
Map<String, Item> items = new LinkedHashMap();
Iterator is = itemString.iterator();
@@ -226,6 +120,7 @@ public class ReadUtil {
} catch (Exception e) {
e.printStackTrace();
}
return map;
}

View File

@@ -1,58 +0,0 @@
package org.nl.acs.device.service.impl;
import lombok.Data;
import lombok.SneakyThrows;
import org.nl.acs.instruction.service.dto.InstructionDto;
import org.nl.acs.opc.OpcUtl;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.acs.task.service.impl.TaskServiceImpl;
@Data
public class ConveyorDevice {
String id;
int jobNo = -1;
int lastjobNo = -1;
String palletNo;
InstructionDto inst;
RecvThread rt;
public ConveyorDevice(String id) {
if (id == null) {
throw new NullPointerException("ID is null");
} else {
this.id = id;
}
System.out.println("id:" + id);
rt = new RecvThread();
rt.run();
}
public void adviseData() {
System.out.println("test");
}
private class RecvThread implements Runnable {
@SneakyThrows
@Override
public void run() {
System.out.println("test");
String MODE = "RD1.RD1." + id + ".mode";
String code = OpcUtl.read(MODE);
if ("2".equals(code)) {
TaskService taskserver = new TaskServiceImpl();
TaskDto dto = new TaskDto();
dto.setStart_point_code(id);
dto.setNext_point_code("1002");
taskserver.create(dto);
}
}
}
}

View File

@@ -1,18 +0,0 @@
package org.nl.acs.device.service.impl;
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
String device = "1001,1002";
List list = new ArrayList<>();
list.add("1001");
list.add("1002");
for (int i = 0; i < list.size(); i++) {
ConveyorDevice condev = new ConveyorDevice(list.get(i).toString());
}
}
}

View File

@@ -1089,12 +1089,14 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public Instruction findByLinkNumSend(String code) {
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) {
return inst;
}
}
return null;
}
@@ -1102,8 +1104,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public List<Instruction> findByLinkNum(String code) {
List<Instruction> list = new ArrayList<>();
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) {
list.add(inst);
}
@@ -1113,19 +1116,22 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public Instruction findByLinkNumNoSend(String code) {
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) {
return inst;
}
}
return null;
}
@Override
public Instruction findByCodeFromCache(String code) {
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(code, inst.getInstruction_code())) {
return inst;
}
@@ -1136,8 +1142,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public Instruction findByBarcodeFromCache(String barcode) {
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(barcode, inst.getVehicle_code())) {
return inst;
}
@@ -1147,9 +1154,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public Instruction findByIdFromCache(String id) {
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(id, inst.getInstruction_id())) {
return inst;
}
@@ -1244,8 +1251,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public Integer querySameDestinationInst(String devicecode) {
int num = 0;
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
//处理空盘位站点
String next_code = inst.getNext_point_code();
if (next_code.indexOf(".") != -1) {
@@ -1255,14 +1263,16 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
num = num + 1;
}
}
return num;
}
@Override
public Integer querySameInstType(String inst_type) {
int num = 0;
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
if (StrUtil.equals(inst.getInstruction_type(), inst_type)) {
num = num + 1;
}
@@ -1273,8 +1283,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
@Override
public Integer querySameOriginInst(String devicecode) {
int num = 0;
for (int i = 0; i < this.instructions.size(); i++) {
Instruction inst = instructions.get(i);
Iterator<Instruction> it = instructions.iterator();
while (it.hasNext()){
Instruction inst = it.next();
//处理空盘位站点
String start_code = inst.getStart_point_code();
if (start_code.indexOf(".") != -1) {

View File

@@ -21,6 +21,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
String message;
private Server server;
Group group;
public DeviceOpcProtocolRunable() {
this.error_num = 0;
this.message = null;
@@ -62,13 +64,15 @@ public class DeviceOpcProtocolRunable implements Runnable {
public void run() {
while (true) {
try {
server = OpcServerUtl.getServerWithOutException(
server =
OpcServerUtl.getServerWithOutException(
this.OpcServer.getOpc_host(),
this.OpcServer.getCls_id(),
this.OpcServer.getUser(),
this.OpcServer.getPassword(),
this.OpcServer.getDomain());
Group group = server.addGroup();
group = server.addGroup();
List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator();
@@ -117,10 +121,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
label97:
while (true) {
// System.out.println("label97");
// System.out.println("label97");
long begin = System.currentTimeMillis();
Map<Item, ItemState> itemStatus =
group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
//TODO 读完释放server可行否?
long end = System.currentTimeMillis();
log.trace("{} 开始记时{}", tag, DateUtil.now());
long duration = end - begin;
@@ -135,12 +141,13 @@ public class DeviceOpcProtocolRunable implements Runnable {
time_out = false;
}
// A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表
Set<Item> items = itemStatus.keySet();
Iterator var18 = items.iterator();
while (true) {
// System.out.println("label98");
Item item;
// A1_HK_04.A1_HK_04.A1_HK_04_3.door
// 当前值
Object value;
// 旧的值
@@ -155,6 +162,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.error_num = 0;
this.message = null;
}
// 所有信号读完并且没有变化的值
continue label97;
}
@@ -183,7 +191,6 @@ public class DeviceOpcProtocolRunable implements Runnable {
log.info("信号{}变更从{}->{};信号快照:{}", new Object[] {item.getId(), his, value, sb});
}
System.out.println("设置值:【"+item.getId()+"】-->"+value);
// 设置值
accessor_value.setValue(item.getId(), value);
}
@@ -197,6 +204,15 @@ public class DeviceOpcProtocolRunable implements Runnable {
this.server = null;
}
if (group != null) {
try {
group.clear();
group.remove();
} catch (Exception var6) {
}
this.group = null;
}
String error_message = "设备信息同步异常";
if (!StrUtil.equals(this.message, error_message)) {
log.warn("", var30);
@@ -215,5 +231,4 @@ public class DeviceOpcProtocolRunable implements Runnable {
}
}
}
}

View File

@@ -268,31 +268,6 @@ public class OpcUtl {
return value;
}
public static String read(String item) throws Exception {
System.out.println(item);
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", "");
// String byteItemString = "RD1.RD1.1001.mode";
Group group = server.addGroup();
Item byteItem = group.addItem(item);
ItemState itemState = null;
JIVariant value = null;
itemState = byteItem.read(true);
value = itemState.getValue();
String data = OpcUtl.getValue(byteItem, itemState) + "";
return data;
}
public static void main(String[] args) throws Exception {
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", "");
String byteItemString = "RD1.RD1.1001.mode";
Group group = server.addGroup();
Item byteItem = group.addItem(byteItemString);
ItemState itemState = null;
JIVariant value = null;
System.out.println(byteItem.getId());
itemState = byteItem.read(true);
System.out.println(itemState.getQuality());
System.out.println(getValue(byteItem, itemState));
}
}

View File

@@ -1,7 +1,5 @@
package org.nl.acs.task.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
@@ -61,33 +59,23 @@ import java.util.stream.Collectors;
* @author ldjun
* @description 服务实现
* @date 2021-03-18
**/
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
List<TaskDto> tasks = new ArrayList();
@Autowired
DeviceAppService deviceAppService;
@Autowired
RouteLineService routelineserver;
@Autowired
AcsToWmsService acstowmsService;
@Autowired
TaskFeedbackService taskFeedbackService;
@Autowired
ParamService paramService;
@Autowired
XianGongAgvService agvService;
@Autowired
RouteLineService routeLineService;
@Autowired
DeviceAssignedService deviceAssignedService;
@Autowired
InstructionService instructionService;
@Autowired
StorageCellService storageCellService;
@Autowired DeviceAppService deviceAppService;
@Autowired RouteLineService routelineserver;
@Autowired AcsToWmsService acstowmsService;
@Autowired TaskFeedbackService taskFeedbackService;
@Autowired ParamService paramService;
@Autowired XianGongAgvService agvService;
@Autowired RouteLineService routeLineService;
@Autowired DeviceAssignedService deviceAssignedService;
@Autowired InstructionService instructionService;
@Autowired StorageCellService storageCellService;
@Override
public void autoInitial() throws Exception {
@@ -109,8 +97,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
//WQLObject wo = WQLObject.getWQLObject("acs_task");
//ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc");
// WQLObject wo = WQLObject.getWQLObject("acs_task");
// ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time
// desc");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
String task_code = (String) whereJson.get("task_code");
@@ -137,7 +126,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (!StrUtil.isEmpty(is_over)) {
map.put("is_over", is_over);
}
final JSONObject jo = WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "");
final JSONObject jo =
WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "");
return jo;
}
@@ -152,8 +142,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
String is_over = (String) whereJson.get("is_over");
String task_type = (String) whereJson.get("task_type");
List<TaskDto> taskList = new ArrayList();
for (int i = 0; i < tasks.size(); i++) {
TaskDto task = tasks.get(i);
Iterator<TaskDto> it = tasks.iterator();
while (it.hasNext()) {
TaskDto task = it.next();
if ("1".equals(is_over) && Integer.valueOf(task.getTask_status()) < 2) {
continue;
}
@@ -172,7 +164,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (!ObjectUtil.isEmpty(material_type) && !task.getMaterial().equals(material_type)) {
continue;
}
if (!ObjectUtil.isEmpty(point_code) && !(task.getStart_point_code().contains(point_code) || task.getNext_point_code().contains(point_code))) {
if (!ObjectUtil.isEmpty(point_code)
&& !(task.getStart_point_code().contains(point_code)
|| task.getNext_point_code().contains(point_code))) {
continue;
}
if (!ObjectUtil.isEmpty(task_type) && !task.getTask_type().equals(task_type)) {
@@ -182,14 +176,22 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
// 按照创建时间排序
taskList = taskList
.stream()
.sorted((task1, task2) -> DateUtil.compare(DateUtil.parseDate(task1.getCreate_time()), DateUtil.parse(task2.getCreate_time())))
taskList =
taskList.stream()
.sorted(
(task1, task2) ->
DateUtil.compare(
DateUtil.parseDate(task1.getCreate_time()),
DateUtil.parse(task2.getCreate_time())))
.collect(Collectors.toList());
Integer currentPageNumber = page.getPageNumber() + 1;
Integer pageMaxSize = page.getPageSize();
List<TaskDto> taskDtoList = taskList.stream().skip((currentPageNumber - 1) * pageMaxSize).limit(pageMaxSize).collect(Collectors.toList());
List<TaskDto> taskDtoList =
taskList.stream()
.skip((currentPageNumber - 1) * pageMaxSize)
.limit(pageMaxSize)
.collect(Collectors.toList());
JSONObject jo = new JSONObject();
jo.put("content", taskDtoList);
jo.put("totalElements", taskList.size());
@@ -198,8 +200,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
@Override
public Map<String, Object> getAll(Map whereJson, Pageable page) {
//WQLObject wo = WQLObject.getWQLObject("acs_task");
//ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc");
// WQLObject wo = WQLObject.getWQLObject("acs_task");
// ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time
// desc");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "2");
String task_code = (String) whereJson.get("task_code");
@@ -228,7 +231,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
map.put("create_time", create_time);
map.put("end_time", end_time);
}
JSONObject jsonObject1 = WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc");
JSONObject jsonObject1 =
WQL.getWO("QTASK_QUERY")
.addParamMap(map)
.pageQuery(WqlUtil.getHttpContext(page), "create_time desc");
JSONArray array = jsonObject1.getJSONArray("content");
int totalElements = (Integer) jsonObject1.get("totalElements");
JSONArray arr = new JSONArray();
@@ -281,7 +287,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
Iterator<TaskDto> iterator = tasks.iterator();
while (iterator.hasNext()) {
TaskDto task = iterator.next();
if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "0")) {
if (task.getStart_device_code().equals(device_code)
&& StrUtil.equals(task.getTask_status(), "0")) {
list.add(task);
}
}
@@ -297,7 +304,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (!StrUtil.equals(task.getTask_type(), "6")) {
continue;
}
if ((task.getStart_device_code().equals(start_device_code) || task.getStart_device_code2().equals(start_device_code)) && StrUtil.equals(task.getTask_status(), "0")) {
if ((task.getStart_device_code().equals(start_device_code)
|| task.getStart_device_code2().equals(start_device_code))
&& StrUtil.equals(task.getTask_status(), "0")) {
list.add(task);
}
}
@@ -313,7 +322,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (!StrUtil.equals(task.getTask_type(), "6")) {
continue;
}
if (task.getStart_device_code().equals(back_start_device_code) && StrUtil.equals(task.getTask_status(), "0")) {
if (task.getStart_device_code().equals(back_start_device_code)
&& StrUtil.equals(task.getTask_status(), "0")) {
list.add(task);
}
}
@@ -326,7 +336,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
Iterator<TaskDto> iterator = tasks.iterator();
while (iterator.hasNext()) {
TaskDto task = iterator.next();
if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "1")) {
if (task.getStart_device_code().equals(device_code)
&& StrUtil.equals(task.getTask_status(), "1")) {
Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code());
if (ObjectUtil.isNotEmpty(instruction)) {
list.add(task);
@@ -336,7 +347,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return list;
}
public List<TaskDto> queryTaskByStartAndIntStatus(String head_start_device_code) {
List<TaskDto> list = new ArrayList<>();
Iterator<TaskDto> iterator = tasks.iterator();
@@ -345,7 +355,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (!StrUtil.equals(task.getTask_type(), "6")) {
continue;
}
if ((task.getStart_device_code().equals(head_start_device_code) || task.getStart_device_code2().equals(head_start_device_code)) && StrUtil.equals(task.getTask_status(), "1")) {
if ((task.getStart_device_code().equals(head_start_device_code)
|| task.getStart_device_code2().equals(head_start_device_code))
&& StrUtil.equals(task.getTask_status(), "1")) {
Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code());
if (ObjectUtil.isNotEmpty(instruction)) {
list.add(task);
@@ -363,7 +375,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (!StrUtil.equals(task.getTask_type(), "6")) {
continue;
}
if ((task.getStart_device_code().equals(back_start_device_code)) && StrUtil.equals(task.getTask_status(), "1")) {
if ((task.getStart_device_code().equals(back_start_device_code))
&& StrUtil.equals(task.getTask_status(), "1")) {
Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code());
if (ObjectUtil.isNotEmpty(instruction)) {
list.add(task);
@@ -426,10 +439,13 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
dto.setPriority("1");
}
String plan_code = dto.getRoute_plan_code();
//判断起点终点设备类型
// 判断起点终点设备类型
String startDeviceType = deviceAppService.findDeviceTypeByCode(dto.getStart_device_code());
String nextDeviceType = deviceAppService.findDeviceTypeByCode(dto.getNext_device_code());
if (routelineserver.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code).size() == 0) {
if (routelineserver
.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code)
.size()
== 0) {
throw new Exception(dto.getStart_point_code() + "->" + dto.getNext_point_code() + "路由不通!");
}
String createTaskCheck = paramService.findByCode(AcsConfig.CREATETASKCHECK).getValue();
@@ -439,25 +455,23 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
Device startdevice = appService.findDeviceByCode(start_device_code);
dto.setMaterial(startdevice.getMaterial_type());
if (StrUtil.equals(createTaskCheck, "1")) {
//判断起点为输送设备
if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {
// 判断起点为输送设备
if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {}
}
if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) {
}
if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) {}
} else {
//判断起点为输送设备
if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {
}
// 判断起点为输送设备
if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {}
if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) {
// if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver();
// if (nextdevice.getHas_goods() != 0) {
// throw new Exception("任务终点需满足无货!");
// }
// }
// if (nextdevice.getDeviceDriver() instanceof
// StandardOrdinarySiteDeviceDriver) {
// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver)
// nextdevice.getDeviceDriver();
// if (nextdevice.getHas_goods() != 0) {
// throw new Exception("任务终点需满足无货!");
// }
// }
JSONObject jo = new JSONObject();
JSONObject jo2 = new JSONObject();
@@ -519,11 +533,15 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
TaskDto dto = new TaskDto();
Map whereJson = (Map) array.get(i);
//String device_code = (String) whereJson.get("device_code");
// String device_code = (String) whereJson.get("device_code");
String device_code = MapUtil.getStr(whereJson, "device_code");
dto.setRoute_plan_code("one");
String next_device_code = "";
String plan_uuid = WQLObject.getWQLObject("acs_route_plan").query("plan_code= '" + dto.getRoute_plan_code() + "'").uniqueResult(0).getString("plan_uuid");
String plan_uuid =
WQLObject.getWQLObject("acs_route_plan")
.query("plan_code= '" + dto.getRoute_plan_code() + "'")
.uniqueResult(0)
.getString("plan_uuid");
JSONArray ja = routelineserver.queryNextLine(device_code, plan_uuid);
for (int j = 0; j < ja.size(); j++) {
JSONObject jo = (JSONObject) ja.get(j);
@@ -639,7 +657,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) {
tasks.add(dto);
}
//判断是否为WMS下发的任务如果是反馈任务状态给WMS
// 判断是否为WMS下发的任务如果是反馈任务状态给WMS
String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue();
if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) {
TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code());
@@ -726,7 +744,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
taskFeedbackService.update(feefbackdto);
}
}
}
}
@@ -755,7 +772,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
JSONObject json = (JSONObject) JSONObject.toJSON(entity);
wo.update(json);
removeByCodeFromCache(entity.getTask_code());
//判断是否为WMS下发的任务如果是反馈任务状态给WMS
// 判断是否为WMS下发的任务如果是反馈任务状态给WMS
String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue();
if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) {
TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code());
@@ -844,9 +861,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
taskFeedbackService.update(feefbackdto);
}
}
}
//如果属于先知AGV关闭运单序列
// 如果属于先知AGV关闭运单序列
if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) {
try {
agvService.markComplete(entity.getTask_code());
@@ -876,14 +892,16 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
WQLObject wo = WQLObject.getWQLObject("acs_task");
JSONObject json = (JSONObject) JSONObject.toJSON(entity);
wo.update(json);
//清理缓存
for (int i = 0; i < tasks.size(); i++) {
TaskDto taskDto = tasks.get(i);
Iterator<TaskDto> it = tasks.iterator();
// 清理缓存
while (it.hasNext()){
TaskDto taskDto = it.next();
if (taskDto.getTask_id().equals(id)) {
tasks.remove(i);
tasks.remove(taskDto);
}
}
//判断是否为WMS下发的任务如果是反馈任务状态给WMS
// 判断是否为WMS下发的任务如果是反馈任务状态给WMS
String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue();
if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) {
JSONObject feed_jo = new JSONObject();
@@ -894,7 +912,11 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
ja.add(feed_jo);
acstowmsService.feedbackTaskStatusToWms(ja);
}
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(entity.getStart_device_code(), entity.getNext_device_code(), entity.getRoute_plan_code());
List<RouteLineDto> shortPathsList =
routeLineService.getShortPathLines(
entity.getStart_device_code(),
entity.getNext_device_code(),
entity.getRoute_plan_code());
String type = shortPathsList.get(0).getType();
// != 0 为agv任务
if (!StrUtil.equals(type, "0")) {
@@ -905,7 +927,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
@Override
public Instruction createTemporaryInst(TaskDto acsTask){
public Instruction createTemporaryInst(TaskDto acsTask) {
if (acsTask == null) {
throw new BadRequestException("被删除或无权限,操作失败!");
}
@@ -913,10 +935,11 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
ParamService paramService = SpringContextHolder.getBean(ParamService.class);
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl");
// InstructionDto inst = instructionservice.findByTaskid(acsTask, "instruction_status < 2 ");
// if (inst != null) {
// throw new BadRequestException("有指令未完成!");
// }
// InstructionDto inst = instructionservice.findByTaskid(acsTask, "instruction_status < 2
// ");
// if (inst != null) {
// throw new BadRequestException("有指令未完成!");
// }
String taskid = acsTask.getTask_id();
String taskcode = acsTask.getTask_code();
@@ -926,7 +949,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
String start_device_code = acsTask.getStart_device_code();
String route_plan_code = acsTask.getRoute_plan_code();
String vehicleType = acsTask.getVehicle_type();
//是否复合任务 =0非复合任务
// 是否复合任务 =0非复合任务
String compound_task = acsTask.getCompound_task();
String next_point_code = acsTask.getNext_point_code();
String next_device_code = acsTask.getNext_device_code();
@@ -941,13 +964,13 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
String to_y = acsTask.getTo_y();
String to_z = acsTask.getTo_z();
/**
* 开始平均分解校验
*/
String this_device_code = this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code());
/** 开始平均分解校验 */
String this_device_code =
this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code());
if (StrUtil.isEmpty(this_device_code)) {
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code);
List<RouteLineDto> shortPathsList =
routeLineService.getShortPathLines(
start_device_code, acsTask.getNext_device_code(), route_plan_code);
RouteLineDto routeLineDto = shortPathsList.get(0);
String path = routeLineDto.getPath();
String type = routeLineDto.getType();
@@ -1007,19 +1030,19 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
instdto.setTo_y(to_y);
instdto.setTo_z(to_z);
//判断agv系统
//1、1楼叉车系统
//2、2楼1区域AGV系统
//3、2楼2区域AGV系统
// 判断agv系统
// 1、1楼叉车系统
// 2、2楼1区域AGV系统
// 3、2楼2区域AGV系统
if (!StrUtil.equals(agv_system_type, "1")) {
// task_type
//1、生箔 Itype=1:取空,取满,放空,放满;
//2、分切 Itype=3取满、取空、放满、放空
//3、普通任务 Itype=2:取货、放货;
//4、叉车任务
//5、输送任务
//6、行架
//7、立库
// 1、生箔 Itype=1:取空,取满,放空,放满;
// 2、分切 Itype=3取满、取空、放满、放空
// 3、普通任务 Itype=2:取货、放货;
// 4、叉车任务
// 5、输送任务
// 6、行架
// 7、立库
if (StrUtil.equals(task_type, "1")) {
instdto.setAgv_inst_type("1");
} else if (StrUtil.equals(task_type, "3")) {
@@ -1033,8 +1056,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return instdto;
}
@Override
public Instruction createInst(String ids) throws Exception {
TaskDto acsTask = this.findById(ids);
@@ -1057,7 +1078,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
String start_device_code = acsTask.getStart_device_code();
String route_plan_code = acsTask.getRoute_plan_code();
String vehicleType = acsTask.getVehicle_type();
//是否复合任务 =0非复合任务
// 是否复合任务 =0非复合任务
String compound_task = acsTask.getCompound_task();
String next_point_code = acsTask.getNext_point_code();
String next_device_code = acsTask.getNext_device_code();
@@ -1065,12 +1086,13 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
String next_point_code2 = acsTask.getNext_point_code2();
String agv_system_type = acsTask.getAgv_system_type();
String task_type = acsTask.getTask_type();
/**
* 开始平均分解校验
*/
String this_device_code = this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code());
/** 开始平均分解校验 */
String this_device_code =
this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code());
if (StrUtil.isEmpty(this_device_code)) {
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code);
List<RouteLineDto> shortPathsList =
routeLineService.getShortPathLines(
start_device_code, acsTask.getNext_device_code(), route_plan_code);
RouteLineDto routeLineDto = shortPathsList.get(0);
String path = routeLineDto.getPath();
String type = routeLineDto.getType();
@@ -1120,19 +1142,19 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
instdto.setNext_device_code2(next_point_code2);
instdto.setNext_point_code2(next_point_code2);
instdto.setAgv_system_type(agv_system_type);
//判断agv系统
//1、1楼叉车系统
//2、2楼1区域AGV系统
//3、2楼2区域AGV系统
// 判断agv系统
// 1、1楼叉车系统
// 2、2楼1区域AGV系统
// 3、2楼2区域AGV系统
if (!StrUtil.equals(agv_system_type, "1")) {
// task_type
//1、生箔 Itype=1:取空,取满,放空,放满;
//2、分切 Itype=3取满、取空、放满、放空
//3、普通任务 Itype=2:取货、放货;
//4、叉车任务
//5、输送任务
//6、行架
//7、立库
// 1、生箔 Itype=1:取空,取满,放空,放满;
// 2、分切 Itype=3取满、取空、放满、放空
// 3、普通任务 Itype=2:取货、放货;
// 4、叉车任务
// 5、输送任务
// 6、行架
// 7、立库
if (StrUtil.equals(task_type, "1")) {
instdto.setAgv_inst_type("1");
} else if (StrUtil.equals(task_type, "3")) {
@@ -1145,8 +1167,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
instructionservice.create2(instdto);
// acsTask.setTask_status("1");
// this.update(acsTask);
// acsTask.setTask_status("1");
// this.update(acsTask);
return instdto;
}
@@ -1160,7 +1182,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return inst;
}
@Override
public void download(List<TaskDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
@@ -1202,9 +1223,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
}
@Override
public void createTaskByClick(JSONObject json) {
}
public void createTaskByClick(JSONObject json) {}
@Override
public int checkAllowCreate(String devicecode) {
@@ -1239,7 +1258,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return tasks;
}
public TaskDto findByContainer(String container_code) {
Iterator var3 = tasks.iterator();
@@ -1288,17 +1306,17 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return null;
}
@Override
public TaskDto findByStartCodeAndReady(String device_code) {
Iterator var3 = tasks.iterator();
while (var3.hasNext()) {
TaskDto task = (TaskDto) var3.next();
// if (!StrUtil.equals(task.getTask_type(), "5")) {
// continue;
// }
if (StrUtil.equals(task.getStart_device_code(), device_code) && StrUtil.equals(task.getTask_status(), "0")) {
// if (!StrUtil.equals(task.getTask_type(), "5")) {
// continue;
// }
if (StrUtil.equals(task.getStart_device_code(), device_code)
&& StrUtil.equals(task.getTask_status(), "0")) {
return task;
}
}
@@ -1340,7 +1358,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (Integer.parseInt(start_point[2]) < 10 && start_point[2].length() == 1) {
from_z = "0" + start_point[2];
task.setFrom_z(from_z);
} else if (start_point[2].length() == 2 ){
} else if (start_point[2].length() == 2) {
from_z = start_point[2];
task.setFrom_z(start_point[2]);
} else {
@@ -1350,8 +1368,14 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
task.setStart_device_code(task.getStart_device_code());
} else {
String start_device = deviceAppService.findDeviceByCode(start_point_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name();
//如果point_device为货架则不包含列层信息需要重新拼接
String start_device =
deviceAppService
.findDeviceByCode(start_point_code)
.getDeviceDriverDefination()
.getFitDeviceTypes()
.get(0)
.name();
// 如果point_device为货架则不包含列层信息需要重新拼接
if (StrUtil.equals("storage", start_device)) {
if (StrUtil.isEmpty(task.getFrom_x())) {
throw new BadRequestException("货位信息起点需要包含列信息");
@@ -1368,7 +1392,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (Integer.parseInt(task.getFrom_z()) < 10 && task.getFrom_z().length() == 1) {
from_z = "0" + task.getFrom_z();
task.setFrom_z(from_z);
} else if (task.getFrom_z().length() == 2 ) {
} else if (task.getFrom_z().length() == 2) {
from_z = task.getFrom_z();
task.setFrom_z(from_z);
} else {
@@ -1397,7 +1421,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (Integer.parseInt(next_point[2]) < 10 && next_point[2].length() == 1) {
to_z = "0" + next_point[2];
task.setTo_z(to_z);
} else if ( next_point[2].length() == 2){
} else if (next_point[2].length() == 2) {
to_z = next_point[2];
task.setTo_z(to_z);
} else {
@@ -1408,7 +1432,13 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
task.setNext_device_code(task.getNext_device_code());
} else {
String next_device = deviceAppService.findDeviceByCode(next_point_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name();
String next_device =
deviceAppService
.findDeviceByCode(next_point_code)
.getDeviceDriverDefination()
.getFitDeviceTypes()
.get(0)
.name();
if (StrUtil.equals("storage", next_device)) {
if (StrUtil.isEmpty(task.getTo_x())) {
throw new BadRequestException("货位信息终点需要包含列信息");
@@ -1425,7 +1455,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
if (Integer.parseInt(task.getTo_z()) < 10 && task.getTo_z().length() == 1) {
to_z = "0" + task.getTo_z();
task.setTo_z(to_z);
} else if (task.getTo_z().length() == 2){
} else if (task.getTo_z().length() == 2) {
to_z = task.getTo_z();
task.setTo_z(to_z);
} else {
@@ -1438,7 +1468,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
} else {
task.setNext_device_code(next_point_code);
task.setNext_device_code(next_point_code);
}
}
return task;
@@ -1458,7 +1487,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
@Override
public String queryAssignedByDevice(String device_code, String task_nextdeice_code) {
List<DeviceAssignedDto> list = deviceAssignedService.queryAssignedBydevice(device_code, task_nextdeice_code);
List<DeviceAssignedDto> list =
deviceAssignedService.queryAssignedBydevice(device_code, task_nextdeice_code);
int flag1 = 0;
String flag2 = null;
for (int i = 0; i < list.size(); i++) {
@@ -1489,7 +1519,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
flag2 = this_device_code;
}
}
}
if (!StrUtil.isEmpty(flag2)) {
return flag2;
@@ -1497,15 +1526,15 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return null;
}
@Override
public Integer querySameDeviceReadyTask(String start_device,String next_device,String status ) {
public Integer querySameDeviceReadyTask(String start_device, String next_device, String status) {
int num = 0;
Iterator<TaskDto> iterator = tasks.iterator();
while (iterator.hasNext()) {
TaskDto task = iterator.next();
if (StrUtil.equals(task.getStart_device_code(),start_device) && StrUtil.equals(task.getNext_device_code(),next_device)
&& StrUtil.equals(task.getTask_status(),status)) {
if (StrUtil.equals(task.getStart_device_code(), start_device)
&& StrUtil.equals(task.getNext_device_code(), next_device)
&& StrUtil.equals(task.getTask_status(), status)) {
num++;
}
}
@@ -1513,7 +1542,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
return num;
}
@Override
public Integer querySameTaskByType(String taskType) {
int num = 0;
@@ -1537,6 +1565,4 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
public Integer querySameDestinationTask(String code) {
return null;
}
}