明天生产

This commit is contained in:
张江玮
2023-02-17 16:07:54 +08:00
parent c8b54b5fb4
commit c83be923c3
23 changed files with 522 additions and 205 deletions

View File

@@ -0,0 +1,36 @@
package org.nl.acs.device_driver.driver;
/**
* @author ldjun
* @version 1.0
* @date 2023年02月01日 11:21
* @desc desc
*/
public class ItemValue {
private String item_code;
private Object item_value;
public ItemValue() {
}
public ItemValue(String item_code, Object item_value) {
this.item_code = item_code;
this.item_value = item_value;
}
public String getItem_code() {
return this.item_code;
}
public void setItem_code(String item_code) {
this.item_code = item_code;
}
public Object getItem_value() {
return this.item_value;
}
public void setItem_value(Object item_value) {
this.item_value = item_value;
}
}

View File

@@ -20,6 +20,7 @@ import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.order.service.ProduceshiftorderService;
import org.nl.acs.order.service.dto.ProduceshiftorderDto;
import org.nl.acs.route.service.RouteLineService;
@@ -55,6 +56,8 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
@Autowired
ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean("produceshiftorderServiceImpl");
@Autowired
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
String device_code;
@@ -488,6 +491,10 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_call_material_time);
return false;
} else {
int status = ((HfStationDeviceDriver) deviceAppService.findDeviceByCode("GT03").getDeviceDriver()).getStatus();
if (status != 2) {
return false;
}
logServer.deviceInfo("acs申请任务", this.getDevice_code(), "开始申请压机叫料任务!");
this.instruction_call_material_time = date;
JSONObject json = new JSONObject();
@@ -522,6 +529,7 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De
json.put("device_code", device_code);
json.put("create_mode", "2");
json.put("is_auto_issue", "0");
json.put("to_gt01", status == 4);
json.put("type", "4");
JSONObject resp = acsToWmsService.apply(json);
if (StrUtil.equals(resp.getString("status"), "200")) {

View File

@@ -3,7 +3,6 @@ package org.nl.acs.ext.wms.rest;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -69,12 +68,20 @@ public class WmsToAcsController {
return new ResponseEntity<>(wmstoacsService.forceFinishFromWms(whereJson), HttpStatus.OK);
}
@PostMapping("/queryGT04Status")
@Log("查询GT04状态")
@ApiOperation("查询GT04状态")
@PostMapping("/queryGT01Status")
@Log("查询GT01状态")
@ApiOperation("查询GT01状态")
@SaIgnore
public ResponseEntity<Object> queryGT04Status() throws Exception {
return new ResponseEntity<>(wmstoacsService.queryGT04Status(), HttpStatus.OK);
public ResponseEntity<Object> queryGT01Status() throws Exception {
return new ResponseEntity<>(wmstoacsService.queryGT01Status(), HttpStatus.OK);
}
@PostMapping("/queryGT03Status")
@Log("查询输送线状态")
@ApiOperation("查询输送线状态")
@SaIgnore
public ResponseEntity<Object> queryGT03Status() {
return new ResponseEntity<>(wmstoacsService.queryGT03Status(), HttpStatus.OK);
}

View File

@@ -2,8 +2,6 @@ package org.nl.acs.ext.wms.service;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
public interface WmsToAcsService {
@@ -41,5 +39,7 @@ public interface WmsToAcsService {
Map<String, Object> forceFinishFromWms(String jsonObject) throws Exception;
Map<String, Object> queryGT04Status();
Map<String, Object> queryGT01Status();
Map<String, Object> queryGT03Status();
}

View File

@@ -364,10 +364,18 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
}
@Override
public Map<String, Object> queryGT04Status() {
HfStationDeviceDriver gt04 = (HfStationDeviceDriver) deviceAppService.findDeviceByCode("GT04").getDeviceDriver();
public Map<String, Object> queryGT01Status() {
HfStationDeviceDriver gt01 = (HfStationDeviceDriver) deviceAppService.findDeviceByCode("GT01").getDeviceDriver();
JSONObject result = new JSONObject();
result.put("GT04", gt04.getMode() != 0 && gt04.getMove() == 0);
result.put("GT01", gt01.getMode() != 0 && gt01.getMove() == 0);
return result;
}
@Override
public Map<String, Object> queryGT03Status() {
HfStationDeviceDriver gt03 = (HfStationDeviceDriver) deviceAppService.findDeviceByCode("GT03").getDeviceDriver();
JSONObject result = new JSONObject();
result.put("GT03", gt03.getMode() != 0 && gt03.getStatus() == 2);
return result;
}
}

View File

@@ -4,19 +4,28 @@ import cn.hutool.core.util.NumberUtil;
import lombok.extern.slf4j.Slf4j;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.*;
import org.nl.acs.device_driver.driver.ItemValue;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.wql.exception.WDKException;
import org.openscada.opc.lib.common.ConnectionInformation;
import org.openscada.opc.lib.da.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
@Slf4j
public class OpcUtl {
private static int timeout = 180000;
private static int timeout = 1*60*1000;
private static String key = "rpc.socketTimeout";
public static int successNum=0;
public static int errNum=0;
static {
checkTimeout();
}
public static void checkTimeout() {
if (Integer.getInteger(key, 0).intValue() != timeout) {
@@ -26,9 +35,20 @@ public class OpcUtl {
}
public static void writeValue(Group group, WriteRequest... requests) {
public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
try {
Map e = group.write(requests);
Map<Item, Integer> e=null;
try{
e=group.write(requests);
group.write(requests);
}catch (Exception e1){
try{
e= group.write(requests);
}catch (Exception e2){
e= group.write(requests);
}
}
boolean is_success = true;
StringBuilder message = new StringBuilder();
Iterator arg4 = e.keySet().iterator();
@@ -50,9 +70,60 @@ public class OpcUtl {
if (!is_success) {
// throw new BusinessException(message.toString());
System.out.println("下发信号失败:"+message.toString());
System.out.println("下发信号失败原因:"+message.toString());
log.info("下发信号失败:"+message.toString());
throw new WDKException(message.toString());
}
} catch (JIException arg7) {
// throw new BusinessException(arg7);
log.info("下发信号失败:"+arg7.getMessage());
System.out.println("下发信号失败原因:"+arg7.getMessage());
throw new WDKException(arg7);
}
}
public static void writeValue(Group group, ItemValue... values) throws WDKException {
try {
if (values != null && values.length > 0) {
List<WriteRequest> ws = new ArrayList();
ItemValue[] var3 = values;
int var4 = values.length;
for(int var5 = 0; var5 < var4; ++var5) {
ItemValue value = var3[var5];
Item item = group.addItem(value.getItem_code());
ws.add(new WriteRequest(item, getVariant(value.getItem_value())));
}
writeValue(group, (WriteRequest[])ws.toArray(new WriteRequest[0]));
}
} catch (AddFailedException | JIException var8) {
throw new WDKException(var8);
}
}
public static JIVariant getVariant(Object object) {
if (object instanceof Integer) {
return getIntegerVariant((Integer)object);
} else if (object instanceof String) {
return getStringVariant((String)object);
} else if (object instanceof byte[]) {
return getByteArrayVariant((byte[])((byte[])object));
} else if (object instanceof Byte[]) {
return getByteArrayVariant((Byte[])((Byte[])object));
} else if (object instanceof Boolean) {
return new JIVariant((Boolean)object);
} else if (object instanceof int[]) {
return getByteArrayVariantxx((int[])((int[])object));
} else if (object instanceof Integer[]) {
JIArray array = new JIArray((Integer)object, false);
JIVariant value = new JIVariant(array);
return value;
} else if (object instanceof JIVariant) {
return (JIVariant)object;
} else {
throw new WDKException("未实现目前支持是int,string,byte[]");
}
}
@@ -60,6 +131,7 @@ public class OpcUtl {
if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) {
if (item != null) {
log.debug("value is not good {} : {}", item.getId(), itemState.getQuality());
// throw new WDKException("值不健康进行重连!");
} else {
log.debug("value is not good {}", itemState.getQuality());
}
@@ -150,12 +222,27 @@ public class OpcUtl {
server = new Server(getConnection(host, clsid, user, password, domain),
Executors.newSingleThreadScheduledExecutor());
server.connect();
successNum++;
return server;
} catch (Exception e) {
throw new WDKException(e);
errNum++;
throw new WDKException(e.getMessage());
}finally{
System.out.println("successNum:"+successNum);
System.out.println("errNum:"+errNum);
System.out.println(11);
}
}
public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws WDKException {
checkTimeout();
Server server = null;
server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor());
AutoReconnectController autoReconnectController = new AutoReconnectController(server);
autoReconnectController.connect();
return server;
}
public static ConnectionInformation getConnection(String host, String clsid, String user, String password,
String domain) {
ConnectionInformation connection = new ConnectionInformation();
@@ -167,6 +254,44 @@ public class OpcUtl {
return connection;
}
public static JIVariant getByteArrayVariantxx(int[] bytes) {
Integer[] byte_Data = new Integer[bytes.length];
for(int i = 0; i < bytes.length; ++i) {
byte_Data[i] = bytes[i];
}
JIArray array = new JIArray(byte_Data, false);
JIVariant value = new JIVariant(array);
return value;
}
public static JIVariant getIntegerVariant(Integer integer) {
return new JIVariant(integer);
}
public static JIVariant getStringVariant(String string) {
return new JIVariant(string);
}
public static JIVariant getByteArrayVariant(byte[] bytes) {
Byte[] byte_Data = new Byte[bytes.length];
for(int i = 0; i < bytes.length; ++i) {
byte_Data[i] = bytes[i];
}
JIArray array = new JIArray(byte_Data, false);
JIVariant value = new JIVariant(array);
return value;
}
public static JIVariant getByteArrayVariant(Byte[] bytes) {
JIArray array = new JIArray(bytes, false);
JIVariant value = new JIVariant(array);
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", "");
@@ -180,18 +305,5 @@ public class OpcUtl {
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

@@ -112,10 +112,10 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
if (ObjectUtil.isEmpty(device)) {
throw new BadRequestException("未找到对应设备:" + dto.getDevice_code());
}
JSONArray resultJSONArray = wo.query("is_deleted = '0' and order_status in ('0', '1') and device_code = '" + dto.getDevice_code() + "'").getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(resultJSONArray)) {
throw new BadRequestException("该设备已存在未完成工单,不能下发");
}
// JSONArray resultJSONArray = wo.query("is_deleted = '0' and order_status in ('0', '1') and device_code = '" + dto.getDevice_code() + "'").getResultJSONArray(0);
// if (ObjectUtil.isNotEmpty(resultJSONArray)) {
// throw new BadRequestException("该设备已存在未完成工单,不能下发");
// }
String currentUsername = SecurityUtils.getCurrentUsername();
String now = DateUtil.now();
dto.setOrder_id(IdUtil.simpleUUID());
@@ -137,9 +137,19 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
if (device.getDeviceDriver() instanceof HfStationDeviceDriver) {
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
if (StrUtil.isNotBlank(hfStationDeviceDriver.getOrder())) {
throw new BadRequestException("设备正在生产");
}
if (hfStationDeviceDriver.getStatus() != 2) {
throw new BadRequestException("设备状态不为自动");
}
hfStationDeviceDriver.writing("to_order", dto.getOrder_code());
hfStationDeviceDriver.writing("to_order_num", String.valueOf(dto.getQty()));
hfStationDeviceDriver.writing("to_product_number", dto.getMaterial_code());
hfStationDeviceDriver.writing("to_order", dto.getOrder_code());
hfStationDeviceDriver.writing("to_order_num", String.valueOf(dto.getQty()));
hfStationDeviceDriver.writing("to_product_number", dto.getMaterial_code());
hfStationDeviceDriver.writing("to_command", "3");
hfStationDeviceDriver.writing("to_command", "3");
}
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
@@ -259,13 +269,13 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
map1.put("update_time", now);
WQLObject wo1 = WQLObject.getWQLObject("acs_produceshiftorder");
wo1.update(map1);
String device_code = param.getString("device_code");
HfStationDeviceDriver hfStationDeviceDriver;
Device device = deviceAppService.findDeviceByCode(device_code);
if (device.getDeviceDriver() instanceof HfStationDeviceDriver) {
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
hfStationDeviceDriver.writing("to_command", "5");
}
// String device_code = param.getString("device_code");
// HfStationDeviceDriver hfStationDeviceDriver;
// Device device = deviceAppService.findDeviceByCode(device_code);
// if (device.getDeviceDriver() instanceof HfStationDeviceDriver) {
// hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
// hfStationDeviceDriver.writing("to_command", "5");
// }
Iterator<ProduceshiftorderDto> iterator = order.iterator();
while (iterator.hasNext()) {
ProduceshiftorderDto instruction = iterator.next();
@@ -287,13 +297,20 @@ public class ProduceshiftorderServiceImpl implements ProduceshiftorderService, A
if (device.getDeviceDriver() instanceof HfStationDeviceDriver) {
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
String order = hfStationDeviceDriver.getOrder();
if (StrUtil.isNotEmpty(order)){
throw new BadRequestException("设备已下发工单信息!");
if (StrUtil.isNotBlank(order)){
throw new BadRequestException("设备正在生产");
}
hfStationDeviceDriver = (HfStationDeviceDriver) device.getDeviceDriver();
if (hfStationDeviceDriver.getStatus() != 2) {
throw new BadRequestException("设备状态不为自动");
}
hfStationDeviceDriver.writing("to_order", produceshiftorderDto.getOrder_code());
hfStationDeviceDriver.writing("to_order_num", String.valueOf(produceshiftorderDto.getQty()));
hfStationDeviceDriver.writing("to_product_number", produceshiftorderDto.getMaterial_code());
hfStationDeviceDriver.writing("to_order", produceshiftorderDto.getOrder_code());
hfStationDeviceDriver.writing("to_order_num", String.valueOf(produceshiftorderDto.getQty()));
hfStationDeviceDriver.writing("to_product_number", produceshiftorderDto.getMaterial_code());
hfStationDeviceDriver.writing("to_command", "3");
hfStationDeviceDriver.writing("to_command", "3");
}
}