Browse Source

acs驱动与交互

master
psh 11 months ago
parent
commit
5553983559
  1. 4
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java
  2. 9
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/RequestMethodEnum.java
  3. 64
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/fold_disc_site/FoldDiscSiteDefinition.java
  4. 247
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/fold_disc_site/FoldDiscSiteDeviceDriver.java
  5. 117
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/fold_disc_site/ItemProtocol.java
  6. 6
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/ssx_site/ItemProtocol.java
  7. 14
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/ssx_site/SsxSiteDefination.java
  8. 76
      acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/ssx_site/SsxSiteDeviceDriver.java
  9. 489
      acs/nladmin-ui/src/views/acs/device/driver/cw_site.vue
  10. 236
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/KJRKTask.java
  11. 236
      lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/SSXBKJTask.java

4
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java

@ -29,7 +29,9 @@ public enum DriverTypeEnum {
AUTODOOR(10, "standard_autodoor", "标准版-自动门", "autodoor"),
CW_SITE(11, "cw_site", "超威-检测站点", "conveyor");
SSX_SITE(11, "ssx_site", "输送线", "conveyor");
//驱动索引
private int index;

9
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/RequestMethodEnum.java

@ -12,10 +12,11 @@ import com.alibaba.fastjson.JSONObject;
public enum RequestMethodEnum {
feedback_task_status(1, "feedback_task_status", "反馈任务状态","1"),
apply_mjxl(2, "MJXLTask", "涂板线满架下料","1"),
apply_bpsl(3, "BPSLTask", "包片上料","1"),
apply_tbxbkj(4, "TBXBKJTask", "涂板线补空架","1"),
apply_kghjrk(5, "KGHJRKTask", "空固化架入库","1");
apply_point(2, "POINTTask", "点对点任务","1"),
apply_yclrk(3, "YCLRKTask", "原材料入库","1"),
apply_yclck(4, "YCLCKTask", "原材料出库","1"),
apply_ssxbkj(5, "SSXBKJTask", "输送线补空架","1"),
apply_kjrk(6, "KJRKTask", "空固化架入库","1");
//驱动索引

64
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/fold_disc_site/FoldDiscSiteDefinition.java

@ -0,0 +1,64 @@
package org.nl.acs.device_driver.basedriver.fold_disc_site;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefinition;
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 FoldDiscSiteDefinition implements OpcDeviceDriverDefinition {
@Override
public String getDriverCode() {
return "fold_disc_site";
}
@Override
public String getDriverName() {
return "叠盘机";
}
@Override
public String getDriverDescription() {
return "叠盘机";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new FoldDiscSiteDeviceDriver()).setDevice(device).setDriverDefinition(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return FoldDiscSiteDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList<>();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDTOs() {
return getReadableItemDtos2();
}
public static List<ItemDto> getReadableItemDtos2() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDTOs() {
return ItemProtocol.getWriteableItemDtos();
}
}

247
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/fold_disc_site/FoldDiscSiteDeviceDriver.java

@ -0,0 +1,247 @@
package org.nl.acs.device_driver.basedriver.fold_disc_site;
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.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RequestMethodEnum;
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.feedBackTaskStatus.FeedBackTaskStatusRequest;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
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.utils.ReadUtil;
import org.nl.config.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.http.HttpStatus;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 叠盘机
*/
@Slf4j
@Getter
@Setter
@RequiredArgsConstructor
public class FoldDiscSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
String device_code;
int mode = 0;
int error = 0;
int move = 0;
int last_mode = 0;
int last_error = 0;
int last_move = 0;
Boolean isonline = true;
int hasGoods = 0;
Boolean iserror = false;
boolean requireSucess = false;
boolean requireQtySuccess = false;
boolean errorDeviceRecord = false;
JSONObject errorDeviceRecordRequest = new JSONObject();
int heartbeat;
int last_heartbeat;
private Date checkHeartbeattime = new Date();
private Date last_checkHeartbeattime = new Date();
int branchProtocol = 0;
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private int instruction_require_time_out = 3000;
private int instruction_finished_time_out;
String message;
int number = 0;
int last_number = 0;
int task = 0;
int last_task = 0;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() {
try {
device_code = this.getDeviceCode();
mode = itemProtocol.getMode();
move = itemProtocol.getMove();
number = itemProtocol.getNumber();
error = itemProtocol.getError();
task = itemProtocol.getTask();
if (number != last_number) {
int max_emptypalletnum = Integer.parseInt(this.getDevice().getExtraValue().get("max_emptypalletnum").toString());
if (number == max_emptypalletnum) {
this.requireSucess = false;
}
}
} catch (Exception var17) {
return;
}
//急停
if (this.isStop()) {
//未在线无心跳
} else 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 = "";
switch (mode) {
case 1:
log.debug("设备运转模式:等待工作");
break;
case 2:
if (!this.requireSucess) {
this.shipDeviceUpdate();
}
}
}
last_mode = mode;
last_move = move;
last_number = number;
last_error = error;
last_task = task;
}
public void writing(String param, String value) {
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);
Map<String, Object> itemMap = new HashMap<>();
itemMap.put(to_param, value);
ReadUtil.write(itemMap, server);
server.disconnect();
logServer.deviceExecuteLog(this.device_code, "", "", param + " 写入 " + value);
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
server.disconnect();
}
public void writing(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>();
itemMap.put(to_command, command);
ReadUtil.write(itemMap, server);
ReadUtil.write(itemMap, server);
server.disconnect();
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command);
}
private void shipDeviceUpdate() {
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);
} else {
this.instruction_require_time = date;
FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest();
request.setDevice_code(this.device_code);
request.setRequest_medthod_code(RequestMethodEnum.apply_kjrk.getCode());
request.setRequest_medthod_name(RequestMethodEnum.apply_kjrk.getName());
String resp = acsToWmsService.applyTask(request);
JSONObject res_jo = JSONObject.parseObject(resp);
if (StrUtil.equals(res_jo.getString("code"), "200")) {
log.info("叠盘位堆叠数量满自动申请搬运任务成功!");
this.requireSucess = true;
}
}
}
@Override
public JSONObject getDeviceStatusName() throws Exception {
String mode;
switch (this.mode) {
case 0:
mode = "脱机";
break;
case 2:
mode = "待机";
break;
default:
mode = String.valueOf(this.mode);
}
JSONObject jo = new JSONObject();
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("error", error);
jo.put("number", number);
jo.put("isError", iserror);
jo.put("isOnline", isonline);
jo.put("message", message);
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
}

117
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/fold_disc_site/ItemProtocol.java

@ -0,0 +1,117 @@
package org.nl.acs.device_driver.basedriver.fold_disc_site;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Getter
@Setter
@SuppressWarnings("unused")
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_number = "number";
public static String item_error = "error";
public static String item_task = "task";
public static String item_to_command = "to_command";
public static String item_to_target = "to_target";
public static String item_to_task = "to_task";
Boolean isonline;
private FoldDiscSiteDeviceDriver driver;
public ItemProtocol(FoldDiscSiteDeviceDriver driver) {
this.driver = driver;
}
public int getHeartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return this.getOpcIntegerValue(item_mode);
}
public int getMove() {
return this.getOpcIntegerValue(item_move);
}
public int getNumber() {
return this.getOpcIntegerValue(item_number);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
public int getToCommand() {
return this.getOpcIntegerValue(item_to_command);
}
public int getToTarget() {
return this.getOpcIntegerValue(item_to_target);
}
public int getToTask() {
return this.getOpcIntegerValue(item_to_task);
}
//是否有货
public int hasGoods(int move) {
return move;
}
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
// log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (value != null) {
return value;
}
return "";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList<ItemDto> list = new ArrayList<>();
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1", Boolean.TRUE));
list.add(new ItemDto(item_move, "广电信号", "DB1.B2"));
list.add(new ItemDto(item_number, "数量", "DB1.B3"));
list.add(new ItemDto(item_error, "error", "DB1.B5"));
list.add(new ItemDto(item_task, "任务号", "DB1.D6"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList<ItemDto> list = new ArrayList<>();
list.add(new ItemDto(item_to_command, "下发指令", "DB2.W0", Boolean.TRUE));
list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W2"));
list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D4"));
return list;
}
}

6
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/cw_site/ItemProtocol.java → acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/ssx_site/ItemProtocol.java

@ -1,4 +1,4 @@
package org.nl.acs.device_driver.basedriver.cw_site;
package org.nl.acs.device_driver.basedriver.ssx_site;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@ -19,9 +19,9 @@ public class ItemProtocol {
public static String item_tier = "tier";
public static String item_to_command = "to_command";
private CwSiteDeviceDriver driver;
private SsxSiteDeviceDriver driver;
public ItemProtocol(CwSiteDeviceDriver driver) {
public ItemProtocol(SsxSiteDeviceDriver driver) {
this.driver = driver;
}

14
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/cw_site/CwSiteDefination.java → acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/ssx_site/SsxSiteDefination.java

@ -1,4 +1,4 @@
package org.nl.acs.device_driver.basedriver.cw_site;
package org.nl.acs.device_driver.basedriver.ssx_site;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device.domain.Device;
@ -15,31 +15,31 @@ import java.util.List;
* 说明该站点为普通带光电检测站点
*/
@Service
public class CwSiteDefination implements OpcDeviceDriverDefination {
public class SsxSiteDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "cw_site";
return "ssx_site";
}
@Override
public String getDriverName() {
return "超威-检测站点";
return "输送线-检测站点";
}
@Override
public String getDriverDescription() {
return "超威-检测站点";
return "输送线-检测站点";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new CwSiteDeviceDriver()).setDevice(device).setDriverDefination(this);
return (new SsxSiteDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return CwSiteDeviceDriver.class;
return SsxSiteDeviceDriver.class;
}
@Override

76
acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/cw_site/CwSiteDeviceDriver.java → acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/ssx_site/SsxSiteDeviceDriver.java

@ -1,7 +1,5 @@
package org.nl.acs.device_driver.basedriver.cw_site;
package org.nl.acs.device_driver.basedriver.ssx_site;
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;
@ -19,15 +17,9 @@ import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.domain.Instruction;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.WcsConfig;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.route.service.dto.RouteLineDto;
import org.nl.acs.task.domain.Task;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.acs.task.service.mapper.TaskMapper;
import org.nl.acs.utils.ConvertUtil;
import org.nl.common.utils.CodeUtil;
import org.nl.config.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
@ -42,7 +34,7 @@ import java.util.Map;
@Slf4j
@Data
@RequiredArgsConstructor
public class CwSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver , DeviceStageMonitor {
public class SsxSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver , DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@ -179,7 +171,7 @@ public class CwSiteDeviceDriver extends AbstractOpcDeviceDriver implements Devic
}
if (error != last_error) {
}
if (action != last_action) {
if (mode != last_mode) {
this.setRequireSucess(false);
}
@ -215,38 +207,21 @@ public class CwSiteDeviceDriver extends AbstractOpcDeviceDriver implements Devic
return;
case 2:
break;
}
switch (action) {
//呼叫负极板
case 1:
if (move==0 && !requireSucess) {
apply(1,"2");
}
break;
//呼叫边负极板
case 2:
if (move==0 && !requireSucess) {
apply(2,"3");
}
case 5:
log.info("呼叫空盅");
this.apply(5);
break;
//呼叫正极板
case 3:
if (move==0 && !requireSucess) {
apply(3,"1");
}
case 6:
log.info("空盅出库");
this.apply(6);
break;
//出负极空固化架
case 4:
if (move!=0 && !requireSucess) {
apply(4,"2");
}
case 7:
log.info("呼叫满料");
this.apply(7);
break;
//出正极空固化架
case 5:
if (move!=0 && !requireSucess) {
apply(5,"1");
}
case 8:
log.info("满料出库");
this.apply(8);
break;
}
@ -357,7 +332,7 @@ public class CwSiteDeviceDriver extends AbstractOpcDeviceDriver implements Devic
*
* @param
*/
public synchronized boolean apply(Integer type,String materialType) {
public synchronized boolean apply(Integer type) {
Date date = new Date();
if (date.getTime() - this.time.getTime() < (long) this.instruction_require_time_out) {
log.trace("触发时间因为小于{}毫秒,而被无视", this.time);
@ -366,22 +341,21 @@ public class CwSiteDeviceDriver extends AbstractOpcDeviceDriver implements Devic
this.time = date;
FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest();
request.setDevice_code(devicecode);
request.setMaterial_type(materialType);
if (type==1 ||type==2||type==3) {
//包片上料
request.setRequest_medthod_code(RequestMethodEnum.apply_bpsl.getCode());
request.setRequest_medthod_name(RequestMethodEnum.apply_bpsl.getName());
}else if (type==4||type==5) {
//空托盘出库,包片机和销售出库空位都可以
request.setRequest_medthod_code(RequestMethodEnum.apply_kghjrk.getCode());
request.setRequest_medthod_name(RequestMethodEnum.apply_kghjrk.getName());
if (type==5) {
//呼叫空固化架
request.setRequest_medthod_code(RequestMethodEnum.apply_ssxbkj.getCode());
request.setRequest_medthod_name(RequestMethodEnum.apply_ssxbkj.getName());
}else if (type==8) {
//原材料入库
request.setRequest_medthod_code(RequestMethodEnum.apply_yclrk.getCode());
request.setRequest_medthod_name(RequestMethodEnum.apply_yclrk.getName());
}
String resp = acsToWmsService.applyTask(request);
JSONObject res_jo = JSONObject.parseObject(resp);
if (StrUtil.equals(res_jo.getString("code"), "200")) {
this.writing(type);
this.setRequireSucess(true);
log.info("acs申请任务", this.devicecode, "满盅入库任务申请成功!");
log.info("acs申请任务", this.devicecode, "任务申请成功!");
}
return true;
}

489
acs/nladmin-ui/src/views/acs/device/driver/cw_site.vue

@ -1,489 +0,0 @@
<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
filterable
@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: 'StandardInspectSite',
mixins: [crud],
props: {
parentForm: {
type: Object,
require: true
}
},
data() {
return {
device_code: '',
device_id: '',
plc_id: '',
plc_code: '',
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: [],
address: ''
},
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) {
debugger
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('error') !== -1) {
this.data1[val].db = beforeStr + '.' + afterStr.substring(0, 1) + (parseInt(endNumber) + 5)
}
if (this.data1[val].code.indexOf('task') !== -1) {
this.data1[val].db = beforeStr + '.' + 'D' + (parseInt(endNumber) + 7)
}
}
}
},
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() { // DBItem
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>

236
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/KJRKTask.java

@ -0,0 +1,236 @@
package org.nl.wms.sch.task_manage.task.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.exception.BadRequestException;
import org.nl.wms.ext.service.AcsToWmsService;
import org.nl.wms.ext.service.dto.to.BaseResponse;
import org.nl.wms.pdm.service.IPdmBdWorkorderService;
import org.nl.wms.pdm.service.dao.PdmBdWorkorder;
import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService;
import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup;
import org.nl.wms.sch.point.service.ISchBasePointService;
import org.nl.wms.sch.point.service.dao.SchBasePoint;
import org.nl.wms.sch.task.service.ISchBaseTaskService;
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig;
import org.nl.wms.sch.task_manage.AbstractTask;
import org.nl.wms.sch.task_manage.enums.GroupBindMaterialStatusEnum;
import org.nl.wms.sch.task_manage.enums.GroupStatusEnum;
import org.nl.wms.sch.task_manage.task.TaskType;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.sch.task_manage.task.tasks.mapper.PointMapper;
import org.nl.wms.util.PointUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* @Author: psh
* @Description: 空架入库
* @Date: 2024/1/24
*/
@Slf4j
@Component
@TaskType("KJRKTask")
@Lazy
public class KJRKTask extends AbstractTask {
private static String TASK_CONFIG_CODE = "KJRKTask";
/**
* 入口
*/
private static String ENTRANCE = "1";
@Autowired
private ISchBasePointService pointService;
@Autowired
private ISchBaseTaskService taskService;
@Autowired
private ISchBaseTaskconfigService taskConfigService;
@Autowired
private IPdmBdWorkorderService workorderService;
@Autowired
private ISchBaseVehiclematerialgroupService vehiclematerialgroupService;
@Autowired
private PointMapper pointMapper;
@Autowired
private AcsToWmsService acsToWmsService;
@Override
// @Transactional(rollbackFor = Exception.class)
protected void create() throws BadRequestException {
// 获取任务
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY);
// 配置信息
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>()
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE));
for (SchBaseTask task : tasks) {
// 找终点
SchBasePoint startPoint = pointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
.eq(SchBasePoint::getPoint_code, task.getPoint_code1()));
String extGroupData = task.getExt_group_data();
JSONObject jsonObject = JSONObject.parseObject(extGroupData);
// String materialType = jsonObject.getString("material_type");
SchBasePoint point = findNextPoint();
if (ObjectUtil.isEmpty(point)) {
task.setRemark("未找到所需点位!");
taskService.update(task);
// 消息通知
log.info("原材料入库未找到当前符合条件的点位!");
continue;
}
// 设置终点并修改创建成功状态
task.setPoint_code2(point.getPoint_code());
task.setTask_status(TaskStatus.CREATED.getCode());
task.setRemark("");
taskService.update(task);
//发起任务时先把点位占用,防止发起重复任务
point.setIng_task_code(task.getTask_code());
// point.setVehicle_type(materialType);
pointService.update(point);
//下发
this.renotifyAcs(task);
}
}
/**
* 判断目标点位
*
* @return
*/
private SchBasePoint findNextPoint() {
String regionCode = "YL";
List<SchBasePoint> schBasePointList = pointMapper.findPointByRegion(regionCode, "2");
for (SchBasePoint schBasePoint : schBasePointList) {
if ("2".equals(schBasePoint.getPoint_status())
&& schBasePoint.getVehicle_qty() ==0) {
log.info("原材料入库找到当前符合条件的点位{}", schBasePoint.getPoint_code());
return schBasePoint;
}
}
return null;
}
@Override
// @Transactional(rollbackFor = Exception.class)
protected void updateStatus(String task_code, TaskStatus status) {
// 校验任务
SchBaseTask taskObj = taskService.getById(task_code);
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) {
throw new BadRequestException("该任务已完成!");
}
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) {
throw new BadRequestException("该任务已取消!");
}
// 获取参数
JSONObject extGroupData = ObjectUtil.isNotEmpty(taskObj.getExt_group_data())
? JSONObject.parseObject(taskObj.getExt_group_data())
: null;
// 载具编码:没有就创建一个
String vehicle_code = ObjectUtil.isNotEmpty(taskObj.getVehicle_code())
? taskObj.getVehicle_code()
: IdUtil.getSnowflake(1, 1).nextIdStr();
PdmBdWorkorder workorderCode = null;
if (extGroupData != null) {
workorderCode = ObjectUtil.isNotEmpty(extGroupData.getString("workorder_code"))
? workorderService.getOne(new LambdaQueryWrapper<PdmBdWorkorder>()
.eq(PdmBdWorkorder::getWorkorder_code, extGroupData.getString("workorder_code")))
: null;
}
String startPoint = taskObj.getPoint_code1(); // 获取起点
String endPoint = ObjectUtil.isNotEmpty(taskObj.getPoint_code2())?taskObj.getPoint_code2().substring(0,taskObj.getPoint_code2().length()-2):"0"; // 获取终点
SchBasePoint startPointObj = pointService.getById(startPoint);
SchBasePoint endPointObj = pointService.getById(endPoint);
// 根据传来的类型去对任务进行操作
if (status.equals(TaskStatus.EXECUTING)) { // 执行中
taskObj.setTask_status(TaskStatus.EXECUTING.getCode());
taskObj.setRemark("执行中");
}
if (status.equals(TaskStatus.FINISHED)) { // 完成
// 起点清空
if (ObjectUtil.isNotEmpty(startPointObj)) {
PointUtils.clearPoint(startPointObj);
}
// 终点解锁
endPointObj.setIng_task_code("");
endPointObj.setVehicle_code(ObjectUtil.isEmpty(endPointObj.getVehicle_code()) ? vehicle_code + "," : endPointObj.getVehicle_code() + vehicle_code + ",");
endPointObj.setVehicle_qty(1);
pointService.update(endPointObj);
// 要把数据存到组盘表 -> 改造公共方法,返回id
//todo 组盘表需要关联外部mes晶棒数据,一对多
SchBaseVehiclematerialgroup groupEntity = new SchBaseVehiclematerialgroup();
groupEntity.setGroup_id(IdUtil.getSnowflake(1, 1).nextIdStr());
groupEntity.setCreate_id("2");
groupEntity.setCreate_name("ACS");
groupEntity.setCreate_time(DateUtil.now());
groupEntity.setMaterial_id(ObjectUtil.isNotEmpty(workorderCode)
? workorderCode.getMaterial_id()
: "");
groupEntity.setStanding_time(ObjectUtil.isNotEmpty(workorderCode)
? workorderCode.getStanding_time()
: 0);
groupEntity.setMaterial_weight(ObjectUtil.isNotEmpty(extGroupData)
? extGroupData.getBigDecimal("material_qty")
: BigDecimal.valueOf(0));
groupEntity.setWorkorder_code(ObjectUtil.isNotEmpty(workorderCode)
? workorderCode.getWorkorder_code()
: "");
groupEntity.setVehicle_code(vehicle_code);
groupEntity.setVehicle_type(taskObj.getVehicle_type());
groupEntity.setPoint_code(startPoint);
groupEntity.setPoint_name(startPointObj.getPoint_name());
groupEntity.setPcsn(DateUtil.format(DateUtil.date(), "yyyyMMdd"));
groupEntity.setInstorage_time(DateUtil.now());
groupEntity.setTask_code(taskObj.getTask_code());
groupEntity.setGroup_bind_material_status(GroupBindMaterialStatusEnum.BOUND.getValue()); // 绑定
groupEntity.setGroup_status(GroupStatusEnum.IN_STORAGE.getType()); // 暂时不维护。
groupEntity.setIs_delete(false);
groupEntity.setMove_way(startPoint);
vehiclematerialgroupService.save(groupEntity);
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setGroup_id(groupEntity.getGroup_id());
taskObj.setRemark("任务完成");
try {
//todo 入库成功后上报mes
}catch (Exception e){
log.error("原材料入库上报MES失败{}",e.getMessage(),e);
}
}
if (status.equals(TaskStatus.CANCELED)) { // 取消
// 终点解锁
if (ObjectUtil.isNotEmpty(endPointObj)) {
endPointObj.setIng_task_code("");
//任务取消把原先占用的位置释放
pointService.update(endPointObj);
}
taskObj.setRemark("任务取消");
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
}
taskService.update(taskObj);
}
@Override
public void forceFinish(String task_code) {
this.updateStatus(task_code, TaskStatus.FINISHED);
}
@Override
public void cancel(String task_code) {
this.updateStatus(task_code, TaskStatus.CANCELED);
}
@Override
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) {
//该场景无需重算等待点
}
}

236
lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/SSXBKJTask.java

@ -0,0 +1,236 @@
package org.nl.wms.sch.task_manage.task.tasks;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.exception.BadRequestException;
import org.nl.wms.ext.service.AcsToWmsService;
import org.nl.wms.ext.service.dto.to.BaseResponse;
import org.nl.wms.pdm.service.IPdmBdWorkorderService;
import org.nl.wms.pdm.service.dao.PdmBdWorkorder;
import org.nl.wms.sch.group.service.ISchBaseVehiclematerialgroupService;
import org.nl.wms.sch.group.service.dao.SchBaseVehiclematerialgroup;
import org.nl.wms.sch.point.service.ISchBasePointService;
import org.nl.wms.sch.point.service.dao.SchBasePoint;
import org.nl.wms.sch.task.service.ISchBaseTaskService;
import org.nl.wms.sch.task.service.ISchBaseTaskconfigService;
import org.nl.wms.sch.task.service.dao.SchBaseTask;
import org.nl.wms.sch.task.service.dao.SchBaseTaskconfig;
import org.nl.wms.sch.task_manage.AbstractTask;
import org.nl.wms.sch.task_manage.enums.GroupBindMaterialStatusEnum;
import org.nl.wms.sch.task_manage.enums.GroupStatusEnum;
import org.nl.wms.sch.task_manage.task.TaskType;
import org.nl.wms.sch.task_manage.task.core.TaskStatus;
import org.nl.wms.sch.task_manage.task.tasks.mapper.PointMapper;
import org.nl.wms.util.PointUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
/**
* @Author: psh
* @Description: 输送线补空架
* @Date: 2024/1/24
*/
@Slf4j
@Component
@TaskType("SSXBKJTask")
@Lazy
public class SSXBKJTask extends AbstractTask {
private static String TASK_CONFIG_CODE = "SSXBKJTask";
/**
* 入口
*/
private static String ENTRANCE = "1";
@Autowired
private ISchBasePointService pointService;
@Autowired
private ISchBaseTaskService taskService;
@Autowired
private ISchBaseTaskconfigService taskConfigService;
@Autowired
private IPdmBdWorkorderService workorderService;
@Autowired
private ISchBaseVehiclematerialgroupService vehiclematerialgroupService;
@Autowired
private PointMapper pointMapper;
@Autowired
private AcsToWmsService acsToWmsService;
@Override
// @Transactional(rollbackFor = Exception.class)
protected void create() throws BadRequestException {
// 获取任务
List<SchBaseTask> tasks = taskService.findTasksByTaskStatus(TASK_CONFIG_CODE, TaskStatus.APPLY);
// 配置信息
SchBaseTaskconfig taskConfig = taskConfigService.getOne(new LambdaQueryWrapper<SchBaseTaskconfig>()
.eq(SchBaseTaskconfig::getConfig_code, TASK_CONFIG_CODE));
for (SchBaseTask task : tasks) {
// 找终点
SchBasePoint startPoint = pointService.getOne(new LambdaQueryWrapper<SchBasePoint>()
.eq(SchBasePoint::getPoint_code, task.getPoint_code1()));
String extGroupData = task.getExt_group_data();
JSONObject jsonObject = JSONObject.parseObject(extGroupData);
// String materialType = jsonObject.getString("material_type");
SchBasePoint point = findNextPoint();
if (ObjectUtil.isEmpty(point)) {
task.setRemark("未找到所需点位!");
taskService.update(task);
// 消息通知
log.info("原材料入库未找到当前符合条件的点位!");
continue;
}
// 设置终点并修改创建成功状态
task.setPoint_code2(point.getPoint_code());
task.setTask_status(TaskStatus.CREATED.getCode());
task.setRemark("");
taskService.update(task);
//发起任务时先把点位占用,防止发起重复任务
point.setIng_task_code(task.getTask_code());
// point.setVehicle_type(materialType);
pointService.update(point);
//下发
this.renotifyAcs(task);
}
}
/**
* 判断目标点位
*
* @return
*/
private SchBasePoint findNextPoint() {
String regionCode = "YL";
List<SchBasePoint> schBasePointList = pointMapper.findPointByRegion(regionCode, "2");
for (SchBasePoint schBasePoint : schBasePointList) {
if ("2".equals(schBasePoint.getPoint_status())
&& schBasePoint.getVehicle_qty() ==0) {
log.info("原材料入库找到当前符合条件的点位{}", schBasePoint.getPoint_code());
return schBasePoint;
}
}
return null;
}
@Override
// @Transactional(rollbackFor = Exception.class)
protected void updateStatus(String task_code, TaskStatus status) {
// 校验任务
SchBaseTask taskObj = taskService.getById(task_code);
if (taskObj.getTask_status().equals(TaskStatus.FINISHED.getCode())) {
throw new BadRequestException("该任务已完成!");
}
if (taskObj.getTask_status().equals(TaskStatus.CANCELED.getCode())) {
throw new BadRequestException("该任务已取消!");
}
// 获取参数
JSONObject extGroupData = ObjectUtil.isNotEmpty(taskObj.getExt_group_data())
? JSONObject.parseObject(taskObj.getExt_group_data())
: null;
// 载具编码:没有就创建一个
String vehicle_code = ObjectUtil.isNotEmpty(taskObj.getVehicle_code())
? taskObj.getVehicle_code()
: IdUtil.getSnowflake(1, 1).nextIdStr();
PdmBdWorkorder workorderCode = null;
if (extGroupData != null) {
workorderCode = ObjectUtil.isNotEmpty(extGroupData.getString("workorder_code"))
? workorderService.getOne(new LambdaQueryWrapper<PdmBdWorkorder>()
.eq(PdmBdWorkorder::getWorkorder_code, extGroupData.getString("workorder_code")))
: null;
}
String startPoint = taskObj.getPoint_code1(); // 获取起点
String endPoint = ObjectUtil.isNotEmpty(taskObj.getPoint_code2())?taskObj.getPoint_code2().substring(0,taskObj.getPoint_code2().length()-2):"0"; // 获取终点
SchBasePoint startPointObj = pointService.getById(startPoint);
SchBasePoint endPointObj = pointService.getById(endPoint);
// 根据传来的类型去对任务进行操作
if (status.equals(TaskStatus.EXECUTING)) { // 执行中
taskObj.setTask_status(TaskStatus.EXECUTING.getCode());
taskObj.setRemark("执行中");
}
if (status.equals(TaskStatus.FINISHED)) { // 完成
// 起点清空
if (ObjectUtil.isNotEmpty(startPointObj)) {
PointUtils.clearPoint(startPointObj);
}
// 终点解锁
endPointObj.setIng_task_code("");
endPointObj.setVehicle_code(ObjectUtil.isEmpty(endPointObj.getVehicle_code()) ? vehicle_code + "," : endPointObj.getVehicle_code() + vehicle_code + ",");
endPointObj.setVehicle_qty(1);
pointService.update(endPointObj);
// 要把数据存到组盘表 -> 改造公共方法,返回id
//todo 组盘表需要关联外部mes晶棒数据,一对多
SchBaseVehiclematerialgroup groupEntity = new SchBaseVehiclematerialgroup();
groupEntity.setGroup_id(IdUtil.getSnowflake(1, 1).nextIdStr());
groupEntity.setCreate_id("2");
groupEntity.setCreate_name("ACS");
groupEntity.setCreate_time(DateUtil.now());
groupEntity.setMaterial_id(ObjectUtil.isNotEmpty(workorderCode)
? workorderCode.getMaterial_id()
: "");
groupEntity.setStanding_time(ObjectUtil.isNotEmpty(workorderCode)
? workorderCode.getStanding_time()
: 0);
groupEntity.setMaterial_weight(ObjectUtil.isNotEmpty(extGroupData)
? extGroupData.getBigDecimal("material_qty")
: BigDecimal.valueOf(0));
groupEntity.setWorkorder_code(ObjectUtil.isNotEmpty(workorderCode)
? workorderCode.getWorkorder_code()
: "");
groupEntity.setVehicle_code(vehicle_code);
groupEntity.setVehicle_type(taskObj.getVehicle_type());
groupEntity.setPoint_code(startPoint);
groupEntity.setPoint_name(startPointObj.getPoint_name());
groupEntity.setPcsn(DateUtil.format(DateUtil.date(), "yyyyMMdd"));
groupEntity.setInstorage_time(DateUtil.now());
groupEntity.setTask_code(taskObj.getTask_code());
groupEntity.setGroup_bind_material_status(GroupBindMaterialStatusEnum.BOUND.getValue()); // 绑定
groupEntity.setGroup_status(GroupStatusEnum.IN_STORAGE.getType()); // 暂时不维护。
groupEntity.setIs_delete(false);
groupEntity.setMove_way(startPoint);
vehiclematerialgroupService.save(groupEntity);
// 任务完成
taskObj.setTask_status(TaskStatus.FINISHED.getCode());
taskObj.setGroup_id(groupEntity.getGroup_id());
taskObj.setRemark("任务完成");
try {
//todo 入库成功后上报mes
}catch (Exception e){
log.error("原材料入库上报MES失败{}",e.getMessage(),e);
}
}
if (status.equals(TaskStatus.CANCELED)) { // 取消
// 终点解锁
if (ObjectUtil.isNotEmpty(endPointObj)) {
endPointObj.setIng_task_code("");
//任务取消把原先占用的位置释放
pointService.update(endPointObj);
}
taskObj.setRemark("任务取消");
taskObj.setTask_status(TaskStatus.CANCELED.getCode());
}
taskService.update(taskObj);
}
@Override
public void forceFinish(String task_code) {
this.updateStatus(task_code, TaskStatus.FINISHED);
}
@Override
public void cancel(String task_code) {
this.updateStatus(task_code, TaskStatus.CANCELED);
}
@Override
protected void feedbackTaskState(JSONObject param, SchBaseTask schBaseTask, BaseResponse result) {
//该场景无需重算等待点
}
}
Loading…
Cancel
Save