add 大屏真实数据方法
This commit is contained in:
@@ -16,8 +16,6 @@ public class AbstractDeviceDriver implements DeviceDriver {
|
||||
|
||||
|
||||
public AbstractDeviceDriver() {
|
||||
// this.execute_log = new BusinessLoggerImpl(BusinessDomain.device_execute.name());
|
||||
// this.device_log = BusinessLoggerFactory.getNoRepeatBusinessLogger(BusinessDomain.device_execute.name());
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +32,7 @@ public class AbstractDeviceDriver implements DeviceDriver {
|
||||
|
||||
@Override
|
||||
public DeviceDriver setDriverDefination(DeviceDriverDefination var1) {
|
||||
this.driverDefination = driverDefination;
|
||||
this.driverDefination = var1;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.nl.acs.device_driver.driver;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.nl.acs.ext.wms.data.JsonUtl;
|
||||
import org.nl.acs.log.service.DeviceExecuteLogService;
|
||||
import org.nl.acs.opc.ItemValue;
|
||||
import org.nl.acs.opc.OpcConfig;
|
||||
@@ -14,7 +13,6 @@ import org.nl.modules.lucene.service.dto.LuceneLogDto;
|
||||
import org.nl.modules.wql.exception.WDKException;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -22,12 +20,6 @@ import java.util.Map;
|
||||
public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver {
|
||||
UnifiedDataAccessor opcUdw;
|
||||
|
||||
private Date sendTime;
|
||||
private String last_items;
|
||||
private int noLog_sendTimeOut;
|
||||
private Date noLog_sendTime;
|
||||
private String noLog_last_items;
|
||||
|
||||
public AbstractOpcDeviceDriver() {
|
||||
this.opcUdw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
}
|
||||
@@ -57,7 +49,7 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + ".";
|
||||
}
|
||||
|
||||
public boolean control(Map<String, Object> itemValues) {
|
||||
public void control(Map<String, Object> itemValues) {
|
||||
|
||||
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||
|
||||
@@ -73,61 +65,23 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
||||
i++;
|
||||
}
|
||||
|
||||
return this.control(p2);
|
||||
this.control(p2);
|
||||
}
|
||||
|
||||
public boolean control(ItemValue[] itemValues) {
|
||||
public void control(ItemValue[] itemValues) {
|
||||
if (itemValues != null && itemValues.length != 0) {
|
||||
String this_items = JsonUtl.parseWithoutException(itemValues);
|
||||
boolean need_write = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ItemValue[] var5 = itemValues;
|
||||
int var6 = itemValues.length;
|
||||
|
||||
for (int var7 = 0; var7 < var6; ++var7) {
|
||||
ItemValue itemValue = var5[var7];
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
|
||||
opcServerService.writeInteger(this.getOpcServer(), itemValues);
|
||||
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||
|
||||
for (ItemValue itemValue : itemValues) {
|
||||
String code = itemValue.getItem_code();
|
||||
Object udw_value = this.getUdwValue(code);
|
||||
Object write_value = itemValue.getItem_value();
|
||||
sb.append(code);
|
||||
sb.append(":");
|
||||
sb.append(JsonUtl.parseWithoutException(udw_value));
|
||||
sb.append(";");
|
||||
// if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) {
|
||||
// need_write = true;
|
||||
// }
|
||||
}
|
||||
need_write = true;
|
||||
|
||||
if (need_write) {
|
||||
Date date = new Date();
|
||||
/*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) {
|
||||
log.trace("发送时间因为小于{}毫秒,而被无视", WcsConfig.opc_write_repeat_check);
|
||||
return false;
|
||||
}*/
|
||||
|
||||
this.last_items = this_items;
|
||||
this.sendTime = date;
|
||||
/* this.execute_log.setResource(this.getDevice().getCode(), this.getDevice().getName());
|
||||
this.execute_log.log("原始记录{}->变更为{}", new Object[]{sb, this_items});
|
||||
OpcServerService opcServerService = OpcServerFactory.getOpcServerService();*/
|
||||
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
|
||||
opcServerService.writeInteger(this.getOpcServer(), itemValues);
|
||||
UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor();
|
||||
ItemValue[] var17 = itemValues;
|
||||
int var18 = itemValues.length;
|
||||
|
||||
for (int var19 = 0; var19 < var18; ++var19) {
|
||||
ItemValue itemValue = var17[var19];
|
||||
String code = itemValue.getItem_code();
|
||||
Object value = itemValue.getItem_value();
|
||||
opcValueAccessor.setValue(code, value);
|
||||
}
|
||||
Object value = itemValue.getItem_value();
|
||||
opcValueAccessor.setValue(code, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
throw new WDKException("下发 无内容");
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface WmsToAcsService {
|
||||
* 创建任务
|
||||
*
|
||||
* @param jsonObject 条件
|
||||
* @return
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> createFromWms(String jsonObject);
|
||||
|
||||
|
||||
@@ -8,32 +8,24 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.config.AcsConfig;
|
||||
import org.nl.acs.device.service.DeviceService;
|
||||
import org.nl.acs.device_driver.DeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_Laminating_machine.LnshLaminatingMachineDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_fold_disc_site.LnshFoldDiscSiteDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_kiln_lane.LnshKilnLaneDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_kiln_truss.LnshKilnTrussDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_labeling_machine.LnshLabelingMachineDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_mixing_mill.LnshMixingMillDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_out_kiln_truss.LnshOutKilnTrussDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_package_line.LnshPackageLineDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_package_pallet_manipulator.LnshPackagePalletManipulatorDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_package_site.LnshPackageSiteDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator.LnshPalletizingManipulatorDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator_site.LnshPalletizingManipulatorSiteDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_press.LnshPressDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_rgv.LnshRGVDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_split_manipulator.LnshSplitManipulatorDeviceDriver;
|
||||
import org.nl.acs.device_driver.lnsh.lnsh_station.LnshStationDeviceDriver;
|
||||
import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver;
|
||||
import org.nl.acs.ext.wms.service.WmsToAcsService;
|
||||
import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.instruction.service.dto.Instruction;
|
||||
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;
|
||||
import org.nl.acs.route.service.dto.RouteLineDto;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
@@ -57,15 +49,13 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
|
||||
private final InstructionService InstructionService;
|
||||
private final TaskService TaskService;
|
||||
private final DeviceService DeviceService;
|
||||
private final DeviceAppService DeviceAppService;
|
||||
private final RouteLineService RouteLineService;
|
||||
private final ProduceshiftorderService produceshiftorderService;
|
||||
|
||||
private String log_file_type = "log_file_type";
|
||||
private String log_type = "WMS下发ACS";
|
||||
private final String log_file_type = "log_file_type";
|
||||
private final String log_type = "WMS下发ACS";
|
||||
|
||||
@Override
|
||||
public Map<String, Object> createFromWms(String param) {
|
||||
@@ -82,8 +72,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
String task_code = task.getString("task_code");
|
||||
String start_point_code = task.getString("start_device_code");
|
||||
String next_point_code = task.getString("next_device_code");
|
||||
String start_device_code = "";
|
||||
String next_device_code = "";
|
||||
String start_device_code;
|
||||
String next_device_code;
|
||||
String start_parent_code = "";
|
||||
String next_parent_code = "";
|
||||
if (StrUtil.isEmpty(task_code)) {
|
||||
@@ -98,7 +88,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
|
||||
JSONObject start_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_point_code + "'").uniqueResult(0);
|
||||
if (!ObjectUtil.isEmpty(start_device_json)) {
|
||||
start_point_code = (String) start_device_json.get("parent_storage_code") == null ? start_point_code : (String) start_device_json.get("storage_code");
|
||||
start_point_code = start_device_json.get("parent_storage_code") == null ? start_point_code : (String) start_device_json.get("storage_code");
|
||||
if (start_point_code.contains(".")) {
|
||||
start_point_code = start_point_code.substring(0, start_point_code.indexOf("."));
|
||||
}
|
||||
@@ -106,7 +96,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
}
|
||||
JSONObject next_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_point_code + "'").uniqueResult(0);
|
||||
if (!ObjectUtil.isEmpty(next_device_json)) {
|
||||
next_point_code = (String) next_device_json.get("parent_storage_code") == null ? next_point_code : (String) next_device_json.get("storage_code");
|
||||
next_point_code = next_device_json.get("parent_storage_code") == null ? next_point_code : (String) next_device_json.get("storage_code");
|
||||
if (next_point_code.contains(".")) {
|
||||
next_point_code = next_point_code.substring(0, next_point_code.indexOf("."));
|
||||
}
|
||||
@@ -121,14 +111,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
String params = task.getString("params");
|
||||
|
||||
if (start_point_code.indexOf("-") > 0) {
|
||||
String str[] = start_point_code.split("-");
|
||||
String[] str = start_point_code.split("-");
|
||||
start_device_code = str[0];
|
||||
} else {
|
||||
start_device_code = start_point_code;
|
||||
}
|
||||
|
||||
if (next_point_code.indexOf("-") > 0) {
|
||||
String str[] = next_point_code.split("-");
|
||||
String[] str = next_point_code.split("-");
|
||||
next_device_code = str[0];
|
||||
} else {
|
||||
next_device_code = next_point_code;
|
||||
@@ -146,12 +136,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
if (taskDto != null) {
|
||||
throw new WDKException("不能存在相同的任务号!");
|
||||
}
|
||||
// if (!StrUtil.isEmpty(vehicle_code) && !"0000".equals(vehicle_code)) {
|
||||
// TaskDto vehicle_dto = TaskService.findByContainer(vehicle_code);
|
||||
// if (vehicle_dto != null) {
|
||||
// throw new WDKException("已存在该载具号的任务!");
|
||||
// }
|
||||
// }
|
||||
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("task_code", task_code);
|
||||
jo.put("ext_task_uuid", ext_task_uuid);
|
||||
@@ -187,7 +172,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
try {
|
||||
TaskService.create(task_dto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("createFromWms method error !", e);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("task_code", task_code);
|
||||
json.put("ext_task_uuid", ext_task_uuid);
|
||||
@@ -203,14 +188,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
resultJson.put("errArr", errArr);
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("createFromWms - 返回参数 {}", resultJson.toString());
|
||||
log.info("createFromWms - 返回参数 {}", resultJson);
|
||||
|
||||
} catch (Exception e) {
|
||||
resultJson.put("status", 400);
|
||||
resultJson.put("errArr", e.getMessage());
|
||||
resultJson.put("message", e.getMessage());
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("createFromWms - 返回参数 {}", resultJson.toString());
|
||||
log.info("createFromWms - 返回参数 {}", resultJson);
|
||||
}
|
||||
return resultJson;
|
||||
} finally {
|
||||
@@ -228,13 +213,11 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
ParamService acsConfigService = SpringContextHolder.getBean(ParamServiceImpl.class);
|
||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||
log.debug(tasks.toString());
|
||||
log.info("cancelFromWms - 请求参数 {}", tasks.toString());
|
||||
log.info("cancelFromWms - 请求参数 {}", tasks);
|
||||
for (int i = 0; i < tasks.size(); i++) {
|
||||
JSONObject task = tasks.getJSONObject(i);
|
||||
String task_uuid = task.getString("task_id");
|
||||
String task_code = task.getString("task_code");
|
||||
String vehicle_code = task.getString("vehicle_code");
|
||||
String params = task.getString("params");
|
||||
|
||||
if (StrUtil.isEmpty(task_uuid)) {
|
||||
throw new WDKException("任务标识不能为空");
|
||||
@@ -259,7 +242,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
resultJson.put("status", HttpStatus.OK);
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("cancelFromWms - 返回参数 {}", resultJson.toString());
|
||||
log.info("cancelFromWms - 返回参数 {}", resultJson);
|
||||
return resultJson;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
@@ -272,7 +255,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
log.info("createOrder - 请求参数 {}", orders.toString());
|
||||
|
||||
for (int i = 0; i < orders.size(); i++) {
|
||||
Boolean is_flag = false;
|
||||
|
||||
JSONObject json = orders.getJSONObject(i);
|
||||
String producetask_code = json.getString("workorder_code");
|
||||
@@ -315,7 +297,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
map.put("to_material_code", material_code);
|
||||
map.put("to_command", 1);
|
||||
lnshMixingMillDeviceDriver.writing(map);
|
||||
is_flag = true;
|
||||
}
|
||||
if (device.getDeviceDriver() instanceof LnshPressDeviceDriver) {
|
||||
lnshPressDeviceDriver = (LnshPressDeviceDriver) device.getDeviceDriver();
|
||||
@@ -339,7 +320,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
map.put("to_Wthickness", Wthickness);
|
||||
map.put("to_command", 1);
|
||||
lnshPressDeviceDriver.writing(map);
|
||||
is_flag = true;
|
||||
}
|
||||
if (device.getDeviceDriver() instanceof LnshPackagePalletManipulatorDeviceDriver) {
|
||||
lnshPackagePalletManipulatorDeviceDriver = (LnshPackagePalletManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
@@ -364,7 +344,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
map.put("to_vehicle_type", String.valueOf(json.getIntValue("vehicle_type") - 2));
|
||||
map.put("to_command", 1);
|
||||
lnshPackagePalletManipulatorDeviceDriver.writing(map);
|
||||
is_flag = true;
|
||||
}
|
||||
if (device.getDeviceDriver() instanceof LnshSplitManipulatorDeviceDriver) {
|
||||
lnshSplitManipulatorDeviceDriver = (LnshSplitManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
@@ -388,24 +367,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
map.put("to_Wthickness", Wthickness);
|
||||
map.put("to_command", 1);
|
||||
lnshSplitManipulatorDeviceDriver.writing(map);
|
||||
is_flag = true;
|
||||
}
|
||||
//下发成功后,写入工单信息表记录
|
||||
|
||||
// ProduceshiftorderDto dto = new ProduceshiftorderDto();
|
||||
// dto.setDevice_code(device_code);
|
||||
// dto.setOrder_code(producetask_code);
|
||||
// dto.setOrder_status("0");
|
||||
// dto.setMaterial_code(material_code);
|
||||
// dto.setMaterial_name(material_name);
|
||||
// dto.setCust_code(cust_code);
|
||||
// dto.setCust_name(cust_name);
|
||||
// dto.setModel(model);
|
||||
// dto.setMolten_pool(molten_pool);
|
||||
// dto.setWeight(weight);
|
||||
// dto.setQty(qty);
|
||||
// dto.setProduct_code(product_code);
|
||||
// produceshiftorderService.create(dto);
|
||||
|
||||
}
|
||||
|
||||
@@ -413,583 +375,34 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
resultJson.put("status", HttpStatus.OK.value());
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("createOrder - 返回参数 {}", resultJson.toString());
|
||||
log.info("createOrder - 返回参数 {}", resultJson);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> updateDeviceGoodsFromWms(String param) {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
JSONArray datas = JSONArray.parseArray(param);
|
||||
log.info("updateDeviceGoodsFromWms - 请求参数 {}", datas.toString());
|
||||
for (int i = 0; i < datas.size(); i++) {
|
||||
JSONObject data = datas.getJSONObject(i);
|
||||
String device_code = data.getString("point_code");
|
||||
String has_goods = data.getString("has_goods");
|
||||
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("device_code", device_code);
|
||||
jo.put("hasGoodStatus", has_goods);
|
||||
DeviceService.changeDeviceStatus(jo);
|
||||
|
||||
}
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("status", HttpStatus.OK);
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("updateDeviceGoodsFromWms - 返回参数 {}", resultJson.toString());
|
||||
return resultJson;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> areaControl(JSONObject form) {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
String device_code = form.getString("device_code");
|
||||
String type = form.getString("type");
|
||||
|
||||
Device device = DeviceAppService.findDeviceByCode(device_code);
|
||||
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("status", HttpStatus.OK);
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("updateDeviceGoodsFromWms - 返回参数 {}", resultJson.toString());
|
||||
return resultJson;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> putAction(String jsonObject) throws Exception {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
JSONArray datas = JSONArray.parseArray(jsonObject);
|
||||
log.info("putAction - 请求参数 {}", datas.toString());
|
||||
for (int i = 0; i < datas.size(); i++) {
|
||||
JSONObject data = datas.getJSONObject(i);
|
||||
String device_code = data.getString("device_code");
|
||||
String code = data.getString("code");
|
||||
String value = data.getString("value");
|
||||
Device device = DeviceAppService.findDeviceByCode(device_code);
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
throw new Exception("未找到对应设备:" + device_code);
|
||||
}
|
||||
LnshLaminatingMachineDeviceDriver lnshLaminatingMachineDeviceDriver;
|
||||
//晟华覆膜机
|
||||
if (device.getDeviceDriver() instanceof LnshLaminatingMachineDeviceDriver) {
|
||||
lnshLaminatingMachineDeviceDriver = (LnshLaminatingMachineDeviceDriver) device.getDeviceDriver();
|
||||
org.nl.acs.device_driver.lnsh.lnsh_Laminating_machine.ItemProtocol itemProtocol = new org.nl.acs.device_driver.lnsh.lnsh_Laminating_machine.ItemProtocol(lnshLaminatingMachineDeviceDriver);
|
||||
if (!lnshLaminatingMachineDeviceDriver.isExistFieldName(code, itemProtocol)) {
|
||||
throw new Exception("设备:" + device_code + "未找到对应信号:" + code);
|
||||
}
|
||||
lnshLaminatingMachineDeviceDriver.writing(code, value);
|
||||
}
|
||||
}
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("status", HttpStatus.OK);
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", new JSONObject());
|
||||
log.info("putAction - 返回参数 {}", resultJson.toString());
|
||||
return resultJson;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
public Map<String, Object> putAction(String jsonObject) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryDevice(String jsonObject) throws Exception {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
log.info("queryDevice - 请求参数 {}", jsonObject.toString());
|
||||
JSONArray backja = new JSONArray();
|
||||
JSONArray datas = JSONArray.parseArray(jsonObject);
|
||||
|
||||
//无光电普通站点
|
||||
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
|
||||
//自动门
|
||||
StandardAutodoorDeviceDriver standardAutodoorDeviceDriver;
|
||||
//晟华-码垛机械手
|
||||
LnshPalletizingManipulatorDeviceDriver lnshPalletizingManipulatorDeviceDriver;
|
||||
//晟华-窑车道
|
||||
LnshKilnLaneDeviceDriver lnshKilnLaneDeviceDriver;
|
||||
//晟华-包装码垛机械手
|
||||
LnshPackagePalletManipulatorDeviceDriver lnshPackagePalletManipulatorDeviceDriver;
|
||||
//晟华-贴标机
|
||||
LnshLabelingMachineDeviceDriver lnshLabelingMachineDeviceDriver;
|
||||
//晟华-拆垛机械手
|
||||
LnshSplitManipulatorDeviceDriver lnshSplitManipulatorDeviceDriver;
|
||||
//晟华-RGV
|
||||
LnshRGVDeviceDriver lnshRGVDeviceDriver;
|
||||
//晟华-工位(交互模板)
|
||||
LnshStationDeviceDriver lnshStationDeviceDriver;
|
||||
//晟华-缓存货架
|
||||
LnshLaminatingMachineDeviceDriver lnshLaminatingMachineDeviceDriver;
|
||||
//晟华-机械手工位
|
||||
LnshPalletizingManipulatorSiteDeviceDriver lnshPalletizingManipulatorSiteDeviceDriver;
|
||||
//晟华-包装线工位
|
||||
LnshPackageSiteDeviceDriver lnshPackageSiteDeviceDriver;
|
||||
|
||||
if (datas.size() == 0) {
|
||||
List<Device> list = DeviceService.findCacheDevice();
|
||||
for (int i = 0, j = list.size(); i < j; i++) {
|
||||
Device device = list.get(i);
|
||||
JSONObject obj = new JSONObject();
|
||||
String device_code = device.getDevice_code();
|
||||
JSONObject jo = new JSONObject();
|
||||
if (ObjectUtil.isNull(device)) {
|
||||
continue;
|
||||
}
|
||||
if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) {
|
||||
lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshStationDeviceDriver.getMode());
|
||||
jo.put("move", lnshStationDeviceDriver.getMove());
|
||||
jo.put("action", lnshStationDeviceDriver.getAction());
|
||||
jo.put("io_action", lnshStationDeviceDriver.getIo_action());
|
||||
jo.put("hasGoods", lnshStationDeviceDriver.getHasGoods());
|
||||
jo.put("isOnline", lnshStationDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshStationDeviceDriver.getError());
|
||||
jo.put("isError", lnshStationDeviceDriver.getIserror());
|
||||
jo.put("message", lnshStationDeviceDriver.getMessage());
|
||||
jo.put("task", lnshStationDeviceDriver.getTask());
|
||||
jo.put("weight", lnshStationDeviceDriver.getWeight());
|
||||
jo.put("material", lnshStationDeviceDriver.getMaterial());
|
||||
jo.put("barcode", lnshStationDeviceDriver.getBarcode());
|
||||
// jo.put("specifications", lnshStationDeviceDriver.getSpecifications());
|
||||
// jo.put("batch", lnshStationDeviceDriver.getBatch());
|
||||
// jo.put("pallet_type", lnshStationDeviceDriver.getContainer_type());
|
||||
|
||||
} else if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) {
|
||||
lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPalletizingManipulatorSiteDeviceDriver.getMode());
|
||||
jo.put("move", lnshPalletizingManipulatorSiteDeviceDriver.getMove());
|
||||
jo.put("action", lnshPalletizingManipulatorSiteDeviceDriver.getAction());
|
||||
jo.put("io_action", lnshPalletizingManipulatorSiteDeviceDriver.getIo_action());
|
||||
jo.put("hasGoods", lnshPalletizingManipulatorSiteDeviceDriver.getHasGoods());
|
||||
jo.put("isOnline", lnshPalletizingManipulatorSiteDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshPalletizingManipulatorSiteDeviceDriver.getError());
|
||||
jo.put("isError", lnshPalletizingManipulatorSiteDeviceDriver.getIserror());
|
||||
jo.put("message", lnshPalletizingManipulatorSiteDeviceDriver.getMessage());
|
||||
jo.put("task", lnshPalletizingManipulatorSiteDeviceDriver.getTask());
|
||||
jo.put("weight", lnshPalletizingManipulatorSiteDeviceDriver.getWeight());
|
||||
jo.put("material", lnshPalletizingManipulatorSiteDeviceDriver.getMaterial());
|
||||
jo.put("barcode", lnshPalletizingManipulatorSiteDeviceDriver.getBarcode());
|
||||
jo.put("AlongSide", lnshPalletizingManipulatorSiteDeviceDriver.getAlongSide());
|
||||
jo.put("BshortSide", lnshPalletizingManipulatorSiteDeviceDriver.getBshortSide());
|
||||
jo.put("Htrapezoidal", lnshPalletizingManipulatorSiteDeviceDriver.getHtrapezoidal());
|
||||
jo.put("Wthickness", lnshPalletizingManipulatorSiteDeviceDriver.getWthickness());
|
||||
} else if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorDeviceDriver) {
|
||||
lnshPalletizingManipulatorDeviceDriver = (LnshPalletizingManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPalletizingManipulatorDeviceDriver.getMode());
|
||||
jo.put("status", lnshPalletizingManipulatorDeviceDriver.getStatus());
|
||||
jo.put("action", lnshPalletizingManipulatorDeviceDriver.getAction());
|
||||
jo.put("isOnline", lnshPalletizingManipulatorDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshPalletizingManipulatorDeviceDriver.getError());
|
||||
// jo.put("batch", lnshPalletizingManipulatorDeviceDriver.getBatch());
|
||||
// jo.put("specifications", lnshPalletizingManipulatorDeviceDriver.getSpecifications());
|
||||
jo.put("isError", lnshPalletizingManipulatorDeviceDriver.getIserror());
|
||||
jo.put("message", lnshPalletizingManipulatorDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshKilnLaneDeviceDriver) {
|
||||
lnshKilnLaneDeviceDriver = (LnshKilnLaneDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshKilnLaneDeviceDriver.getMode());
|
||||
jo.put("status", lnshKilnLaneDeviceDriver.getStatus());
|
||||
jo.put("isOnline", lnshKilnLaneDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshKilnLaneDeviceDriver.getError());
|
||||
jo.put("isError", lnshKilnLaneDeviceDriver.getIserror());
|
||||
jo.put("open_time", lnshKilnLaneDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshKilnLaneDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshKilnLaneDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshKilnLaneDeviceDriver.getError_time());
|
||||
jo.put("car_sum", lnshKilnLaneDeviceDriver.getCar_sum());
|
||||
jo.put("nullCar_qty", lnshKilnLaneDeviceDriver.getNullCar_qty());
|
||||
jo.put("burning_car_qty", lnshKilnLaneDeviceDriver.getBurning_car_qty());
|
||||
jo.put("message", lnshKilnLaneDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshPackagePalletManipulatorDeviceDriver) {
|
||||
lnshPackagePalletManipulatorDeviceDriver = (LnshPackagePalletManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPackagePalletManipulatorDeviceDriver.getMode());
|
||||
jo.put("status", lnshPackagePalletManipulatorDeviceDriver.getStatus());
|
||||
// jo.put("onoff_status", lnshPackagePalletManipulatorDeviceDriver.getOnoff_status());
|
||||
// jo.put("specifications", lnshPackagePalletManipulatorDeviceDriver.getSpecifications());
|
||||
// jo.put("batch", lnshPackagePalletManipulatorDeviceDriver.getBatch());
|
||||
jo.put("isOnline", lnshPackagePalletManipulatorDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshPackagePalletManipulatorDeviceDriver.getError());
|
||||
jo.put("putStation", lnshPackagePalletManipulatorDeviceDriver.getPut_station());
|
||||
jo.put("barcode", lnshPackagePalletManipulatorDeviceDriver.getBarcode());
|
||||
jo.put("material", lnshPackagePalletManipulatorDeviceDriver.getMaterial());
|
||||
jo.put("qty", lnshPackagePalletManipulatorDeviceDriver.getQty());
|
||||
jo.put("open_time", lnshPackagePalletManipulatorDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshPackagePalletManipulatorDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshPackagePalletManipulatorDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshPackagePalletManipulatorDeviceDriver.getError_time());
|
||||
jo.put("order_No", lnshPackagePalletManipulatorDeviceDriver.getOrder_No());
|
||||
jo.put("isError", lnshPackagePalletManipulatorDeviceDriver.getIserror());
|
||||
jo.put("message", lnshPackagePalletManipulatorDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshLabelingMachineDeviceDriver) {
|
||||
lnshLabelingMachineDeviceDriver = (LnshLabelingMachineDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshLabelingMachineDeviceDriver.getMode());
|
||||
jo.put("status", lnshLabelingMachineDeviceDriver.getStatus());
|
||||
jo.put("isOnline", lnshLabelingMachineDeviceDriver.getIsonline());
|
||||
jo.put("open_time", lnshLabelingMachineDeviceDriver.getOpen_time());
|
||||
jo.put("close_time", lnshLabelingMachineDeviceDriver.getClose_time());
|
||||
jo.put("standby_time", lnshLabelingMachineDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshLabelingMachineDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshLabelingMachineDeviceDriver.getError_time());
|
||||
jo.put("labeling_qty", lnshLabelingMachineDeviceDriver.getLabeling_qty());
|
||||
jo.put("isError", lnshLabelingMachineDeviceDriver.getIserror());
|
||||
jo.put("message", lnshLabelingMachineDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshSplitManipulatorDeviceDriver) {
|
||||
lnshSplitManipulatorDeviceDriver = (LnshSplitManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshSplitManipulatorDeviceDriver.getMode());
|
||||
jo.put("isOnline", lnshSplitManipulatorDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshSplitManipulatorDeviceDriver.getError());
|
||||
jo.put("getStation", lnshSplitManipulatorDeviceDriver.getGetStation());
|
||||
jo.put("barcode", lnshSplitManipulatorDeviceDriver.getBarcode());
|
||||
jo.put("material", lnshSplitManipulatorDeviceDriver.getMaterial());
|
||||
// jo.put("batch", lnshSplitManipulatorDeviceDriver.getBatch());
|
||||
// jo.put("specifications", lnshSplitManipulatorDeviceDriver.getSpecifications());
|
||||
// jo.put("qty", lnshSplitManipulatorDeviceDriver.getQty());
|
||||
jo.put("total_split", lnshSplitManipulatorDeviceDriver.getTotal_split());
|
||||
jo.put("open_time", lnshSplitManipulatorDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshSplitManipulatorDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshSplitManipulatorDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshSplitManipulatorDeviceDriver.getError_time());
|
||||
jo.put("isError", lnshSplitManipulatorDeviceDriver.getIserror());
|
||||
jo.put("message", lnshSplitManipulatorDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshLaminatingMachineDeviceDriver) {
|
||||
lnshLaminatingMachineDeviceDriver = (LnshLaminatingMachineDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshLaminatingMachineDeviceDriver.getMode());
|
||||
jo.put("move", lnshLaminatingMachineDeviceDriver.getMove());
|
||||
jo.put("container_type", lnshLaminatingMachineDeviceDriver.getContainer_type() + 3);
|
||||
// jo.put("barcode", lnshLaminatingMachineDeviceDriver.getBarcode());
|
||||
jo.put("task", lnshLaminatingMachineDeviceDriver.getTask());
|
||||
jo.put("error", lnshLaminatingMachineDeviceDriver.getError());
|
||||
jo.put("isOnline", lnshLaminatingMachineDeviceDriver.getIsonline());
|
||||
jo.put("isError", lnshLaminatingMachineDeviceDriver.getIserror());
|
||||
jo.put("message", lnshLaminatingMachineDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshRGVDeviceDriver) {
|
||||
lnshRGVDeviceDriver = (LnshRGVDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshRGVDeviceDriver.getMode());
|
||||
jo.put("status", lnshRGVDeviceDriver.getStatus());
|
||||
jo.put("move1", lnshRGVDeviceDriver.getMove1());
|
||||
jo.put("move2", lnshRGVDeviceDriver.getMove2());
|
||||
jo.put("action1", lnshRGVDeviceDriver.getAction1());
|
||||
jo.put("action2", lnshRGVDeviceDriver.getAction2());
|
||||
jo.put("walk_y", lnshRGVDeviceDriver.getWalk_y());
|
||||
jo.put("error", lnshRGVDeviceDriver.getError());
|
||||
jo.put("task1", lnshRGVDeviceDriver.getTask1());
|
||||
jo.put("task2", lnshRGVDeviceDriver.getTask2());
|
||||
jo.put("isOnline", lnshRGVDeviceDriver.getIsonline());
|
||||
jo.put("isError", lnshRGVDeviceDriver.getIserror());
|
||||
jo.put("message", lnshRGVDeviceDriver.getMessage());
|
||||
jo.put("open_time", lnshRGVDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshRGVDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshRGVDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshRGVDeviceDriver.getError_time());
|
||||
// jo.put("task_qty", lnshRGVDeviceDriver.getTask_qty());
|
||||
// jo.put("finishTask_qty", lnshRGVDeviceDriver.getFinishTask_qty());
|
||||
// jo.put("batch", lnshRGVDeviceDriver.getBatch());
|
||||
// jo.put("specifications", lnshRGVDeviceDriver.getSpecifications());
|
||||
// jo.put("qty", lnshRGVDeviceDriver.getQty());
|
||||
} else if (device.getDeviceDriver() instanceof LnshPackageSiteDeviceDriver) {
|
||||
lnshPackageSiteDeviceDriver = (LnshPackageSiteDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPackageSiteDeviceDriver.getMode());
|
||||
jo.put("move", lnshPackageSiteDeviceDriver.getMove());
|
||||
jo.put("action", lnshPackageSiteDeviceDriver.getAction());
|
||||
jo.put("ioaction", lnshPackageSiteDeviceDriver.getIoaction());
|
||||
jo.put("error", lnshPackageSiteDeviceDriver.getError());
|
||||
jo.put("vehicle_code", lnshPackageSiteDeviceDriver.getVehicle_code());
|
||||
jo.put("vehicle_type", lnshPackageSiteDeviceDriver.getVehicle_type());
|
||||
} else {
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
}
|
||||
backja.add(jo);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < datas.size(); i++) {
|
||||
JSONObject jo = new JSONObject();
|
||||
JSONObject data = datas.getJSONObject(i);
|
||||
String device_code = data.getString("device_code");
|
||||
Device device = DeviceAppService.findDeviceByCode(device_code);
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
throw new Exception("未找到对应设备:" + device_code);
|
||||
}
|
||||
|
||||
if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) {
|
||||
standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", standardAutodoorDeviceDriver.getMode());
|
||||
jo.put("action", standardAutodoorDeviceDriver.getAction());
|
||||
jo.put("isOnline", true);
|
||||
jo.put("error", standardAutodoorDeviceDriver.getError());
|
||||
jo.put("isError", standardAutodoorDeviceDriver.getIserror());
|
||||
} else if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
|
||||
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("move", standardOrdinarySiteDeviceDriver.getMove());
|
||||
jo.put("container", standardOrdinarySiteDeviceDriver.getContainer());
|
||||
jo.put("hasGoods", standardOrdinarySiteDeviceDriver.getHasGoods());
|
||||
jo.put("isOnline", true);
|
||||
//点击弹出
|
||||
jo.put("is_click", true);
|
||||
jo.put("device_type", device.getDevice_type());
|
||||
jo.put("error", standardOrdinarySiteDeviceDriver.getError());
|
||||
jo.put("isError", standardOrdinarySiteDeviceDriver.getIserror());
|
||||
jo.put("container", standardOrdinarySiteDeviceDriver.getContainer());
|
||||
jo.put("message", standardOrdinarySiteDeviceDriver.getMessage());
|
||||
jo.put("material", standardOrdinarySiteDeviceDriver.getMaterial());
|
||||
jo.put("batch", standardOrdinarySiteDeviceDriver.getBatch());
|
||||
|
||||
} else if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) {
|
||||
lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshStationDeviceDriver.getMode());
|
||||
jo.put("move", lnshStationDeviceDriver.getMove());
|
||||
jo.put("action", lnshStationDeviceDriver.getAction());
|
||||
jo.put("io_action", lnshStationDeviceDriver.getIo_action());
|
||||
jo.put("hasGoods", lnshStationDeviceDriver.getHasGoods());
|
||||
jo.put("isOnline", lnshStationDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshStationDeviceDriver.getError());
|
||||
jo.put("isError", lnshStationDeviceDriver.getIserror());
|
||||
jo.put("message", lnshStationDeviceDriver.getMessage());
|
||||
jo.put("task", lnshStationDeviceDriver.getTask());
|
||||
jo.put("weight", lnshStationDeviceDriver.getWeight());
|
||||
jo.put("material", lnshStationDeviceDriver.getMaterial());
|
||||
jo.put("barcode", lnshStationDeviceDriver.getBarcode());
|
||||
// jo.put("specifications", lnshStationDeviceDriver.getSpecifications());
|
||||
// jo.put("batch", lnshStationDeviceDriver.getBatch());
|
||||
// jo.put("pallet_type", lnshStationDeviceDriver.getContainer_type());
|
||||
|
||||
} else if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) {
|
||||
lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPalletizingManipulatorSiteDeviceDriver.getMode());
|
||||
jo.put("move", lnshPalletizingManipulatorSiteDeviceDriver.getMove());
|
||||
jo.put("action", lnshPalletizingManipulatorSiteDeviceDriver.getAction());
|
||||
jo.put("io_action", lnshPalletizingManipulatorSiteDeviceDriver.getIo_action());
|
||||
jo.put("hasGoods", lnshPalletizingManipulatorSiteDeviceDriver.getHasGoods());
|
||||
jo.put("isOnline", lnshPalletizingManipulatorSiteDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshPalletizingManipulatorSiteDeviceDriver.getError());
|
||||
jo.put("isError", lnshPalletizingManipulatorSiteDeviceDriver.getIserror());
|
||||
jo.put("message", lnshPalletizingManipulatorSiteDeviceDriver.getMessage());
|
||||
jo.put("task", lnshPalletizingManipulatorSiteDeviceDriver.getTask());
|
||||
jo.put("weight", lnshPalletizingManipulatorSiteDeviceDriver.getWeight());
|
||||
jo.put("material", lnshPalletizingManipulatorSiteDeviceDriver.getMaterial());
|
||||
jo.put("barcode", lnshPalletizingManipulatorSiteDeviceDriver.getBarcode());
|
||||
jo.put("AlongSide", lnshPalletizingManipulatorSiteDeviceDriver.getAlongSide());
|
||||
jo.put("BshortSide", lnshPalletizingManipulatorSiteDeviceDriver.getBshortSide());
|
||||
jo.put("Htrapezoidal", lnshPalletizingManipulatorSiteDeviceDriver.getHtrapezoidal());
|
||||
jo.put("Wthickness", lnshPalletizingManipulatorSiteDeviceDriver.getWthickness());
|
||||
} else if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorDeviceDriver) {
|
||||
lnshPalletizingManipulatorDeviceDriver = (LnshPalletizingManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPalletizingManipulatorDeviceDriver.getMode());
|
||||
jo.put("status", lnshPalletizingManipulatorDeviceDriver.getStatus());
|
||||
jo.put("action", lnshPalletizingManipulatorDeviceDriver.getAction());
|
||||
jo.put("isOnline", lnshPalletizingManipulatorDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshPalletizingManipulatorDeviceDriver.getError());
|
||||
// jo.put("batch", lnshPalletizingManipulatorDeviceDriver.getBatch());
|
||||
// jo.put("specifications", lnshPalletizingManipulatorDeviceDriver.getSpecifications());
|
||||
jo.put("isError", lnshPalletizingManipulatorDeviceDriver.getIserror());
|
||||
jo.put("message", lnshPalletizingManipulatorDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshKilnLaneDeviceDriver) {
|
||||
lnshKilnLaneDeviceDriver = (LnshKilnLaneDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshKilnLaneDeviceDriver.getMode());
|
||||
jo.put("status", lnshKilnLaneDeviceDriver.getStatus());
|
||||
jo.put("isOnline", lnshKilnLaneDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshKilnLaneDeviceDriver.getError());
|
||||
jo.put("isError", lnshKilnLaneDeviceDriver.getIserror());
|
||||
jo.put("open_time", lnshKilnLaneDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshKilnLaneDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshKilnLaneDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshKilnLaneDeviceDriver.getError_time());
|
||||
jo.put("car_sum", lnshKilnLaneDeviceDriver.getCar_sum());
|
||||
jo.put("nullCar_qty", lnshKilnLaneDeviceDriver.getNullCar_qty());
|
||||
jo.put("burning_car_qty", lnshKilnLaneDeviceDriver.getBurning_car_qty());
|
||||
jo.put("message", lnshKilnLaneDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshPackagePalletManipulatorDeviceDriver) {
|
||||
lnshPackagePalletManipulatorDeviceDriver = (LnshPackagePalletManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPackagePalletManipulatorDeviceDriver.getMode());
|
||||
jo.put("status", lnshPackagePalletManipulatorDeviceDriver.getStatus());
|
||||
// jo.put("onoff_status", lnshPackagePalletManipulatorDeviceDriver.getOnoff_status());
|
||||
// jo.put("specifications", lnshPackagePalletManipulatorDeviceDriver.getSpecifications());
|
||||
// jo.put("batch", lnshPackagePalletManipulatorDeviceDriver.getBatch());
|
||||
jo.put("isOnline", lnshPackagePalletManipulatorDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshPackagePalletManipulatorDeviceDriver.getError());
|
||||
jo.put("putStation", lnshPackagePalletManipulatorDeviceDriver.getPut_station());
|
||||
jo.put("barcode", lnshPackagePalletManipulatorDeviceDriver.getBarcode());
|
||||
jo.put("material", lnshPackagePalletManipulatorDeviceDriver.getMaterial());
|
||||
jo.put("qty", lnshPackagePalletManipulatorDeviceDriver.getQty());
|
||||
jo.put("open_time", lnshPackagePalletManipulatorDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshPackagePalletManipulatorDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshPackagePalletManipulatorDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshPackagePalletManipulatorDeviceDriver.getError_time());
|
||||
jo.put("order_No", lnshPackagePalletManipulatorDeviceDriver.getOrder_No());
|
||||
jo.put("isError", lnshPackagePalletManipulatorDeviceDriver.getIserror());
|
||||
jo.put("message", lnshPackagePalletManipulatorDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshLabelingMachineDeviceDriver) {
|
||||
lnshLabelingMachineDeviceDriver = (LnshLabelingMachineDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshLabelingMachineDeviceDriver.getMode());
|
||||
jo.put("status", lnshLabelingMachineDeviceDriver.getStatus());
|
||||
jo.put("isOnline", lnshLabelingMachineDeviceDriver.getIsonline());
|
||||
jo.put("open_time", lnshLabelingMachineDeviceDriver.getOpen_time());
|
||||
jo.put("close_time", lnshLabelingMachineDeviceDriver.getClose_time());
|
||||
jo.put("standby_time", lnshLabelingMachineDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshLabelingMachineDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshLabelingMachineDeviceDriver.getError_time());
|
||||
jo.put("labeling_qty", lnshLabelingMachineDeviceDriver.getLabeling_qty());
|
||||
jo.put("isError", lnshLabelingMachineDeviceDriver.getIserror());
|
||||
jo.put("message", lnshLabelingMachineDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshSplitManipulatorDeviceDriver) {
|
||||
lnshSplitManipulatorDeviceDriver = (LnshSplitManipulatorDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshSplitManipulatorDeviceDriver.getMode());
|
||||
jo.put("isOnline", lnshSplitManipulatorDeviceDriver.getIsonline());
|
||||
jo.put("error", lnshSplitManipulatorDeviceDriver.getError());
|
||||
jo.put("getStation", lnshSplitManipulatorDeviceDriver.getGetStation());
|
||||
jo.put("barcode", lnshSplitManipulatorDeviceDriver.getBarcode());
|
||||
jo.put("material", lnshSplitManipulatorDeviceDriver.getMaterial());
|
||||
// jo.put("batch", lnshSplitManipulatorDeviceDriver.getBatch());
|
||||
// jo.put("specifications", lnshSplitManipulatorDeviceDriver.getSpecifications());
|
||||
// jo.put("qty", lnshSplitManipulatorDeviceDriver.getQty());
|
||||
jo.put("total_split", lnshSplitManipulatorDeviceDriver.getTotal_split());
|
||||
jo.put("open_time", lnshSplitManipulatorDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshSplitManipulatorDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshSplitManipulatorDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshSplitManipulatorDeviceDriver.getError_time());
|
||||
jo.put("isError", lnshSplitManipulatorDeviceDriver.getIserror());
|
||||
jo.put("message", lnshSplitManipulatorDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshLaminatingMachineDeviceDriver) {
|
||||
lnshLaminatingMachineDeviceDriver = (LnshLaminatingMachineDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshLaminatingMachineDeviceDriver.getMode());
|
||||
jo.put("move", lnshLaminatingMachineDeviceDriver.getMove());
|
||||
jo.put("container_type", lnshLaminatingMachineDeviceDriver.getContainer_type() + 3);
|
||||
// jo.put("barcode", lnshLaminatingMachineDeviceDriver.getBarcode());
|
||||
jo.put("task", lnshLaminatingMachineDeviceDriver.getTask());
|
||||
jo.put("error", lnshLaminatingMachineDeviceDriver.getError());
|
||||
jo.put("isOnline", lnshLaminatingMachineDeviceDriver.getIsonline());
|
||||
jo.put("isError", lnshLaminatingMachineDeviceDriver.getIserror());
|
||||
jo.put("message", lnshLaminatingMachineDeviceDriver.getMessage());
|
||||
} else if (device.getDeviceDriver() instanceof LnshRGVDeviceDriver) {
|
||||
lnshRGVDeviceDriver = (LnshRGVDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshRGVDeviceDriver.getMode());
|
||||
jo.put("status", lnshRGVDeviceDriver.getStatus());
|
||||
jo.put("move_1", lnshRGVDeviceDriver.getMove1());
|
||||
jo.put("move_2", lnshRGVDeviceDriver.getMove2());
|
||||
jo.put("action_1", lnshRGVDeviceDriver.getAction1());
|
||||
jo.put("action_2", lnshRGVDeviceDriver.getAction2());
|
||||
jo.put("walk_y", lnshRGVDeviceDriver.getWalk_y());
|
||||
jo.put("error", lnshRGVDeviceDriver.getError());
|
||||
jo.put("task1", lnshRGVDeviceDriver.getTask1());
|
||||
jo.put("task2", lnshRGVDeviceDriver.getTask2());
|
||||
jo.put("isOnline", lnshRGVDeviceDriver.getIsonline());
|
||||
jo.put("isError", lnshRGVDeviceDriver.getIserror());
|
||||
jo.put("message", lnshRGVDeviceDriver.getMessage());
|
||||
jo.put("open_time", lnshRGVDeviceDriver.getOpen_time());
|
||||
jo.put("standby_time", lnshRGVDeviceDriver.getStandby_time());
|
||||
jo.put("production_time", lnshRGVDeviceDriver.getProduction_time());
|
||||
jo.put("error_time", lnshRGVDeviceDriver.getError_time());
|
||||
// jo.put("task_qty", lnshRGVDeviceDriver.getTask_qty());
|
||||
// jo.put("finishTask_qty", lnshRGVDeviceDriver.getFinishTask_qty());
|
||||
// jo.put("batch", lnshRGVDeviceDriver.getBatch());
|
||||
// jo.put("specifications", lnshRGVDeviceDriver.getSpecifications());
|
||||
// jo.put("qty", lnshRGVDeviceDriver.getQty());
|
||||
} else if (device.getDeviceDriver() instanceof LnshPackageSiteDeviceDriver) {
|
||||
lnshPackageSiteDeviceDriver = (LnshPackageSiteDeviceDriver) device.getDeviceDriver();
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
jo.put("mode", lnshPackageSiteDeviceDriver.getMode());
|
||||
jo.put("move", lnshPackageSiteDeviceDriver.getMove());
|
||||
jo.put("action", lnshPackageSiteDeviceDriver.getAction());
|
||||
jo.put("ioaction", lnshPackageSiteDeviceDriver.getIoaction());
|
||||
jo.put("error", lnshPackageSiteDeviceDriver.getError());
|
||||
jo.put("vehicle_code", lnshPackageSiteDeviceDriver.getVehicle_code());
|
||||
jo.put("vehicle_type", lnshPackageSiteDeviceDriver.getVehicle_type());
|
||||
} else {
|
||||
jo.put("device_code", device.getDevice_code());
|
||||
}
|
||||
backja.add(jo);
|
||||
}
|
||||
}
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("status", HttpStatus.OK);
|
||||
resultJson.put("message", "操作成功");
|
||||
resultJson.put("data", backja);
|
||||
log.info("queryDevice - 返回参数 {}", resultJson.toString());
|
||||
return resultJson;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
public Map<String, Object> queryDevice(String jsonObject) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryTray(String whereJson) {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
log.info("queryTray - 请求参数 {}", whereJson);
|
||||
JSONArray datas = JSONArray.parseArray(whereJson);
|
||||
|
||||
for (int i = 0; i < datas.size(); i++) {
|
||||
String device_code = datas.getString(i);
|
||||
Device device = DeviceAppService.findDeviceByCode(device_code);
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
throw new BadRequestException("未找到设备 [" + device_code + "]");
|
||||
}
|
||||
|
||||
if (device.getDeviceDriver() instanceof LnshLaminatingMachineDeviceDriver) {
|
||||
LnshLaminatingMachineDeviceDriver driver = (LnshLaminatingMachineDeviceDriver) device.getDeviceDriver();
|
||||
if (driver.getMode() != 0
|
||||
&& driver.getError() == 0
|
||||
&& driver.getMove() != 0) {
|
||||
driver.writing(1);
|
||||
driver.writing(1);
|
||||
} else {
|
||||
String message = "";
|
||||
if (driver.getMode() != 0) {
|
||||
message += "覆膜机未联机,";
|
||||
} else {
|
||||
if (driver.getError() != 0) {
|
||||
message += "覆膜机故障,";
|
||||
}
|
||||
if (driver.getMove() == 0) {
|
||||
message += "覆膜机无木托盘,";
|
||||
}
|
||||
}
|
||||
message += "无法下木托盘!";
|
||||
throw new BadRequestException(message);
|
||||
}
|
||||
} else {
|
||||
throw new BadRequestException("[" + device_code + "] 不是覆膜机!");
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject resultJson = new JSONObject();
|
||||
resultJson.put("status", HttpStatus.OK.value());
|
||||
resultJson.put("message", "已下木托盘!");
|
||||
log.info("queryTray - 返回参数 {}", resultJson);
|
||||
return resultJson;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1157,17 +570,12 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
if (device.getDeviceDriver() instanceof LnshPackageSiteDeviceDriver) {
|
||||
LnshPackageSiteDeviceDriver driver = (LnshPackageSiteDeviceDriver) device.getDeviceDriver();
|
||||
|
||||
driver.writing("to_vehicle_type", info.getString("vehicle_type"));
|
||||
driver.writing("to_vehicle_type", info.getString("vehicle_type"));
|
||||
|
||||
driver.writing("to_vehicle_code", String.valueOf(info.getIntValue("vehicle_code")));
|
||||
driver.writing("to_vehicle_code", String.valueOf(info.getIntValue("vehicle_code")));
|
||||
|
||||
driver.writing("to_is_package", info.getString("is_package"));
|
||||
driver.writing("to_is_package", info.getString("is_package"));
|
||||
|
||||
driver.writing(5);
|
||||
driver.writing(5);
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("to_vehicle_type", info.getString("vehicle_type"));
|
||||
map.put("to_vehicle_code", String.valueOf(info.getIntValue("vehicle_code")));
|
||||
map.put("to_is_package", info.getString("is_package"));
|
||||
map.put("to_command", 5);
|
||||
driver.writing(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1175,7 +583,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", HttpStatus.OK.value());
|
||||
result.put("message", "写入成功成功!");
|
||||
result.put("message", "写入成功!");
|
||||
log.info("writeVehicle - 返回参数 {}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -17,47 +17,31 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
||||
DeviceAppService deviceAppService;
|
||||
int cache_thread = 3;
|
||||
|
||||
int corePoolSize = 50;
|
||||
int maximumPoolSize = 100;
|
||||
int queueLength = maximumPoolSize * cache_thread;
|
||||
|
||||
int multiple = cache_thread;
|
||||
|
||||
int loop_time_millions = 100;
|
||||
ExecutorService executorService;
|
||||
Map<String, BlockedRunable> runs;
|
||||
|
||||
public DeviceExecuteAutoRun() {
|
||||
// this.executorService = Executors.newCachedThreadPool();
|
||||
/* this.executorService=new ThreadPoolExecutor(
|
||||
corePoolSize,
|
||||
maximumPoolSize,
|
||||
1L,
|
||||
TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<>( queueLength),
|
||||
new TheadFactoryName()
|
||||
);*/
|
||||
this.executorService = new ThreadPoolExecutor(
|
||||
10,
|
||||
20,
|
||||
1L,
|
||||
TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<>(queueLength),
|
||||
new TheadFactoryName(), new RejectedExecutionHandler() {
|
||||
|
||||
@Override
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||
if (!executor.isShutdown()) {
|
||||
try {
|
||||
executor.getQueue().put(r);
|
||||
} catch (InterruptedException arg3) {
|
||||
log.debug("", arg3);
|
||||
new TheadFactoryName(), (r, executor) -> {
|
||||
if (!executor.isShutdown()) {
|
||||
try {
|
||||
executor.getQueue().put(r);
|
||||
} catch (InterruptedException arg3) {
|
||||
log.debug("", arg3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
this.runs = new LinkedHashMap();
|
||||
this.runs = new LinkedHashMap<>();
|
||||
this.runs = Collections.synchronizedMap(this.runs);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
static ExecutorService executorService;
|
||||
public static Map<String, OpcServerManageDto> opcServersConfig;
|
||||
public static Map<String, OpcItemDto> itemCodeOpcItemDtoMapping = new ConcurrentHashMap();
|
||||
public static Map<String, OpcItemDto> itemCodeOpcItemDtoMapping = new ConcurrentHashMap<>();
|
||||
|
||||
static boolean canRefreshOpcEntity = true;
|
||||
private long lastRefreshOpcEntityTime;
|
||||
static UnifiedDataAccessor udw;
|
||||
private static Map<String, Boolean> canReadOpcValues;
|
||||
private static final Map<String, Boolean> canReadOpcValues;
|
||||
private static volatile Map<String, OpcEntity> opcCodeOpcEntityMapping;
|
||||
|
||||
public DeviceOpcSynchronizeAutoRun() {
|
||||
@@ -60,29 +60,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
return opcServerService.getServer(opcCode);
|
||||
}
|
||||
|
||||
static void submitTimeLimitTask(Runnable runnable, String opcCode) {
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, executorService);
|
||||
|
||||
// try {
|
||||
// future.get(10L, TimeUnit.SECONDS);
|
||||
// } catch (InterruptedException var9) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// } catch (ExecutionException var10) {
|
||||
// var10.printStackTrace();
|
||||
// } catch (TimeoutException var11) {
|
||||
// itemCodeOpcItemDtoMapping.keySet().forEach((key) -> {
|
||||
// udw.setValue(key, (Object) null);
|
||||
// });
|
||||
// canReadOpcValues = new ConcurrentHashMap<>();
|
||||
// System.out.println("opc设备同步器 任务执行超时,取消任务...");
|
||||
// future.cancel(true);
|
||||
// } finally {
|
||||
// canRefreshOpcEntity = true;
|
||||
// if (opcCode != null) {
|
||||
// canReadOpcValues.put(opcCode, true);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
static void submitTimeLimitTask(Runnable runnable) {
|
||||
CompletableFuture.runAsync(runnable, executorService);
|
||||
}
|
||||
|
||||
private ExecutorService createThreadPool() {
|
||||
@@ -95,19 +74,15 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
OpcStartTag.is_run = true;
|
||||
opcServersConfig = this.opcServerManageService.queryAllServerMap();
|
||||
executorService = this.createThreadPool();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
itemCodeOpcItemDtoMapping.keySet().forEach((key) -> {
|
||||
udw.setValue(key, (Object) null);
|
||||
});
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap<>();
|
||||
itemCodeOpcItemDtoMapping.keySet().forEach((key) -> udw.setValue(key, null));
|
||||
canRefreshOpcEntity = true;
|
||||
canReadOpcValues.clear();
|
||||
|
||||
while (true) {
|
||||
this.refreshOpcEntity();
|
||||
Iterator var1 = opcServersConfig.keySet().iterator();
|
||||
|
||||
while (var1.hasNext()) {
|
||||
String opcCode = (String) var1.next();
|
||||
for (String opcCode : opcServersConfig.keySet()) {
|
||||
submitTimeLimitTask(() -> {
|
||||
boolean in = false;
|
||||
try {
|
||||
@@ -117,14 +92,14 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
this.readOpcValues(opcCode);
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
var3.printStackTrace();
|
||||
log.error("error !", var3);
|
||||
} finally {
|
||||
canRefreshOpcEntity = true;
|
||||
if (opcCode != null && in) {
|
||||
canReadOpcValues.put(opcCode, true);
|
||||
}
|
||||
}
|
||||
}, opcCode);
|
||||
});
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond);
|
||||
@@ -133,16 +108,13 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
private void readOpcValues(String opcCode) throws Exception {
|
||||
synchronized (opcCode.intern()) {
|
||||
OpcEntity opcEntity = (OpcEntity) opcCodeOpcEntityMapping.get(opcCode);
|
||||
OpcEntity opcEntity = opcCodeOpcEntityMapping.get(opcCode);
|
||||
if (opcEntity != null) {
|
||||
if (opcEntity.getItems().size() != 0) {
|
||||
if (!opcEntity.getItems().isEmpty()) {
|
||||
long begin = System.currentTimeMillis();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("opc {} 开始计时{}", opcCode, begin);
|
||||
}
|
||||
|
||||
new HashMap();
|
||||
|
||||
Map<Item, ItemState> itemStatus;
|
||||
try {
|
||||
itemStatus = opcEntity.readAll();
|
||||
@@ -160,22 +132,13 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
log.warn("opc {} 读取超时 : {}", opcCode, duration);
|
||||
}
|
||||
|
||||
// boolean allNull = itemStatus.entrySet().stream().map((map) -> {
|
||||
// return OpcUtl.getValue((Item)map.getKey(), (ItemState)map.getValue());
|
||||
// }).allMatch(Objects::isNull);
|
||||
// if (allNull) {
|
||||
// opcEntity.getItems().clear();
|
||||
// }
|
||||
|
||||
UnifiedDataAccessor udw = opcEntity.getUdw();
|
||||
|
||||
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var18 = items.iterator();
|
||||
|
||||
while (var18.hasNext()) {
|
||||
Item item = (Item) var18.next();
|
||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
||||
for (Item item : items) {
|
||||
ItemState itemState = itemStatus.get(item);
|
||||
Object nowValue = OpcUtl.getValue(item, itemState);
|
||||
String itemId = item.getId();
|
||||
Object historyValue = udw.getValue(itemId);
|
||||
@@ -183,10 +146,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
}
|
||||
if (!UnifiedDataAppService.isEquals(nowValue, historyValue)) {
|
||||
OpcItemDto itemDto = (OpcItemDto) itemCodeOpcItemDtoMapping.get(itemId);
|
||||
if (true) {
|
||||
this.logItemChanged(itemId, udw, nowValue, itemDto);
|
||||
}
|
||||
OpcItemDto itemDto = itemCodeOpcItemDtoMapping.get(itemId);
|
||||
this.logItemChanged(itemId, udw, nowValue, itemDto);
|
||||
udw.setValue(itemId, nowValue);
|
||||
}
|
||||
|
||||
@@ -206,35 +167,23 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
submitTimeLimitTask(() -> {
|
||||
try {
|
||||
Map<String, List<List<OpcItemDto>>> protocol = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
Iterator var2 = protocol.entrySet().iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
Entry<String, List<List<OpcItemDto>>> stringListEntry = (Entry) var2.next();
|
||||
String opcCode = (String) stringListEntry.getKey();
|
||||
List<List<OpcItemDto>> opcItemDtos = (List) stringListEntry.getValue();
|
||||
((OpcEntity) opcCodeOpcEntityMapping.computeIfAbsent(opcCode, OpcEntity::new)).reload(opcItemDtos);
|
||||
for (Entry<String, List<List<OpcItemDto>>> stringListEntry : protocol.entrySet()) {
|
||||
String opcCode = stringListEntry.getKey();
|
||||
List<List<OpcItemDto>> opcItemDtos = stringListEntry.getValue();
|
||||
opcCodeOpcEntityMapping.computeIfAbsent(opcCode, OpcEntity::new).reload(opcItemDtos);
|
||||
}
|
||||
} catch (Exception var6) {
|
||||
var6.printStackTrace();
|
||||
log.error("error !", var6);
|
||||
} finally {
|
||||
canRefreshOpcEntity = true;
|
||||
}
|
||||
|
||||
}, (String) null);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logMessage(String errorMessage) {
|
||||
try {
|
||||
// issueLogger.setResource(OpcConfig.resource_code, OpcConfig.resource_name).setError(StringUtl.getString(100), "设备同步通信异常").log(errorMessage, new Object[0]);
|
||||
// businessLogger.setResource(OpcConfig.resource_code, OpcConfig.resource_name).setError(StringUtl.getString(100), "设备同步通信异常").log(errorMessage, new Object[0]);
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void after() {
|
||||
OpcStartTag.is_run = false;
|
||||
opcCodeOpcEntityMapping.values().forEach((opcEntity) -> {
|
||||
@@ -242,8 +191,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
opcServerService.cleanGroups(opcEntity.getOpcCode());
|
||||
});
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
itemCodeOpcItemDtoMapping = new ConcurrentHashMap();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap<>();
|
||||
itemCodeOpcItemDtoMapping = new ConcurrentHashMap<>();
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
|
||||
@@ -252,10 +201,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
List<String> relate_items = itemDto.getRelate_items();
|
||||
if (relate_items != null && !relate_items.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Iterator var8 = relate_items.iterator();
|
||||
|
||||
while (var8.hasNext()) {
|
||||
String relate = (String) var8.next();
|
||||
for (String relate : relate_items) {
|
||||
Object obj = udw.getValue(relate);
|
||||
sb.append("key:").append(relate).append("value:").append(obj).append(";");
|
||||
}
|
||||
@@ -274,7 +221,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
static {
|
||||
udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
canReadOpcValues = new ConcurrentHashMap();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
canReadOpcValues = new ConcurrentHashMap<>();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,176 +16,171 @@ import org.springframework.stereotype.Service;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年02月01日 11:27
|
||||
* @desc desc
|
||||
*/
|
||||
@Service
|
||||
public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
|
||||
@Autowired OpcServerManageService opcServerManageService;
|
||||
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
|
||||
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
|
||||
Map<String, Group> groups = Collections.synchronizedMap(new HashMap());
|
||||
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
|
||||
@Autowired
|
||||
OpcServerManageService opcServerManageService;
|
||||
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap<>();
|
||||
Map<String, Server> servers = Collections.synchronizedMap(new HashMap<>());
|
||||
Map<String, Group> groups = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
public OpcServerServiceImpl() {}
|
||||
public OpcServerServiceImpl() {
|
||||
}
|
||||
|
||||
public void autoInitial() throws Exception {
|
||||
this.reload();
|
||||
if (OpcConfig.auto_start_opc) {
|
||||
Thread t =
|
||||
new Thread() {
|
||||
public void run() {
|
||||
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
|
||||
public void autoInitial() throws Exception {
|
||||
this.reload();
|
||||
if (OpcConfig.auto_start_opc) {
|
||||
Thread t =
|
||||
new Thread(() -> {
|
||||
|
||||
while (var1.hasNext()) {
|
||||
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
|
||||
for (OpcServerManageDto dto : OpcServerServiceImpl.this.opcServerManageDtos.values()) {
|
||||
try {
|
||||
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
||||
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
||||
} catch (Exception var4) {
|
||||
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reload() {
|
||||
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
|
||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||
}
|
||||
|
||||
public void cleanGroups(String opcCode) {
|
||||
Group group = this.groups.get(opcCode);
|
||||
if (group != null) {
|
||||
Server server = group.getServer();
|
||||
|
||||
try {
|
||||
group.remove();
|
||||
} catch (JIException var5) {
|
||||
log.error("error !", var5);
|
||||
}
|
||||
|
||||
this.groups.remove(opcCode);
|
||||
server.disconnect();
|
||||
this.servers.remove(opcCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Group getServer(String code) throws Exception {
|
||||
synchronized (this.buildLock(code)) {
|
||||
Group group;
|
||||
group = this.groups.get(code);
|
||||
if (group != null) {
|
||||
label68:
|
||||
{
|
||||
Group var10000;
|
||||
try {
|
||||
if (!group.isActive()) {
|
||||
break label68;
|
||||
}
|
||||
|
||||
var10000 = group;
|
||||
} catch (JIException var14) {
|
||||
log.error(code, var14);
|
||||
break label68;
|
||||
}
|
||||
|
||||
return var10000;
|
||||
}
|
||||
}
|
||||
|
||||
Server server = this.servers.get(code);
|
||||
boolean needcreate = false;
|
||||
if (server == null) {
|
||||
needcreate = true;
|
||||
} else {
|
||||
try {
|
||||
group = server.findGroup(code);
|
||||
} catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException |
|
||||
IllegalArgumentException var13) {
|
||||
log.error(code, var13);
|
||||
needcreate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needcreate) {
|
||||
OpcServerManageDto dto = this.opcServerManageDtos.get(code);
|
||||
if (dto == null) {
|
||||
throw new BadRequestException(code + "{} 不存在");
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
}
|
||||
|
||||
try {
|
||||
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
|
||||
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
|
||||
} catch (Exception var4) {
|
||||
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
|
||||
assert server != null;
|
||||
group = server.addGroup(code);
|
||||
} catch (Exception var12) {
|
||||
this.clearServer(code);
|
||||
ThreadUtl.sleep(5000L);
|
||||
log.warn("获取opc出错重新获取 {}", code, var12);
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
|
||||
try {
|
||||
assert server != null;
|
||||
group = server.addGroup(code);
|
||||
} catch (Exception var11) {
|
||||
log.error("error !", var11);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reload() {
|
||||
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
|
||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||
}
|
||||
|
||||
public void cleanGroups(String opcCode) {
|
||||
Group group = (Group)this.groups.get(opcCode);
|
||||
if (group != null) {
|
||||
Server server = group.getServer();
|
||||
|
||||
try {
|
||||
group.remove();
|
||||
} catch (JIException var5) {
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
this.groups.remove(opcCode);
|
||||
server.disconnect();
|
||||
this.servers.remove(opcCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Group getServer(String code) throws Exception {
|
||||
synchronized(this.buildLock(code)) {
|
||||
Group group = null;
|
||||
group = (Group)this.groups.get(code);
|
||||
if (group != null) {
|
||||
label68: {
|
||||
Group var10000;
|
||||
try {
|
||||
if (!group.isActive()) {
|
||||
break label68;
|
||||
this.servers.put(code, server);
|
||||
this.groups.put(code, group);
|
||||
}
|
||||
|
||||
var10000 = group;
|
||||
} catch (JIException var14) {
|
||||
log.error(code, var14);
|
||||
break label68;
|
||||
}
|
||||
|
||||
return var10000;
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
Server server = (Server)this.servers.get(code);
|
||||
boolean needcreate = false;
|
||||
String groupName = code;
|
||||
if (server == null) {
|
||||
needcreate = true;
|
||||
} else {
|
||||
try {
|
||||
group = server.findGroup(groupName);
|
||||
} catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException | IllegalArgumentException var13) {
|
||||
log.error(code, var13);
|
||||
needcreate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needcreate) {
|
||||
OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code);
|
||||
if (dto == null) {
|
||||
throw new BadRequestException(code + "{} 不存在");
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
}
|
||||
|
||||
try {
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var12) {
|
||||
this.clearServer(code);
|
||||
ThreadUtl.sleep(5000L);
|
||||
log.warn("获取opc出错重新获取", code, var12);
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
|
||||
try {
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var11) {
|
||||
var11.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.servers.put(code, server);
|
||||
this.groups.put(code, group);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearServer(String code) {
|
||||
synchronized(this.buildLock(code)) {
|
||||
try {
|
||||
Server server = (Server)this.servers.get(code);
|
||||
server.disconnect();
|
||||
} catch (Exception var5) {
|
||||
}
|
||||
public void clearServer(String code) {
|
||||
synchronized (this.buildLock(code)) {
|
||||
try {
|
||||
Server server = this.servers.get(code);
|
||||
server.disconnect();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
this.servers.remove(code);
|
||||
this.groups.remove(code);
|
||||
this.servers.remove(code);
|
||||
this.groups.remove(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void writeInteger(String code, ItemValue... values) {
|
||||
try {
|
||||
Group group = this.getServer(code);
|
||||
OpcUtl.writeValue(group, values);
|
||||
} catch (Exception var4) {
|
||||
this.clearServer(code);
|
||||
log.warn("写入出错opc server {} 重新加载", code, var4);
|
||||
ThreadUtl.sleep(5000L);
|
||||
public void writeInteger(String code, ItemValue... values) {
|
||||
try {
|
||||
Group group = this.getServer(code);
|
||||
OpcUtl.writeValue(group, values);
|
||||
} catch (Exception var4) {
|
||||
this.clearServer(code);
|
||||
log.warn("写入出错opc server {} 重新加载", code, var4);
|
||||
ThreadUtl.sleep(5000L);
|
||||
// throw var4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String buildLock(String key) {
|
||||
if (StrUtil.isEmpty(key)) {
|
||||
key = "";
|
||||
private String buildLock(String key) {
|
||||
if (StrUtil.isEmpty(key)) {
|
||||
key = "";
|
||||
}
|
||||
String builder = "OpcServerService." +
|
||||
key;
|
||||
return builder.intern();
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("OpcServerService.");
|
||||
builder.append(key);
|
||||
String lock = builder.toString().intern();
|
||||
return lock;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,17 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.queryparser.classic.QueryParser;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -29,7 +24,7 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class Searcher {
|
||||
|
||||
public static Map<String, Object> search(String indexDir, String ext,Map whereJson) throws Exception {
|
||||
public static Map<String, Object> search(String indexDir, String ext, Map<Object, Object> whereJson) throws Exception {
|
||||
//获取要查询的路径,也就是索引所在的位置
|
||||
Directory dir = FSDirectory.open(Paths.get(indexDir));
|
||||
IndexReader reader = DirectoryReader.open(dir);
|
||||
@@ -49,57 +44,56 @@ public class Searcher {
|
||||
int start = pageNum * pageSize;// 当前页的起始条数
|
||||
int end = start + pageSize;// 当前页的结束条数(不能包含)
|
||||
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
|
||||
Sort sort = new Sort(new SortField("logTime", SortField.Type.DOC,true));
|
||||
Sort sort = new Sort(new SortField("logTime", SortField.Type.STRING, true));
|
||||
|
||||
TopDocs docs = null;
|
||||
TopDocs docs;
|
||||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
||||
//时间范围查询
|
||||
String startDate = (String) whereJson.get("begin_time");
|
||||
String endDate = (String) whereJson.get("end_time");
|
||||
Calendar calendar=Calendar.getInstance();
|
||||
calendar.set(1970, 0, 1);
|
||||
if (startDate == null){
|
||||
startDate = DateUtil.format(calendar.getTime(),"yyyy-MM-dd HH:mm:ss.SSS");
|
||||
}else{
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(1970, Calendar.JANUARY, 1);
|
||||
if (startDate == null) {
|
||||
startDate = DateUtil.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||
} else {
|
||||
startDate = LuceneIndexWriter.getDate(startDate);
|
||||
}
|
||||
if (endDate == null){
|
||||
endDate = DateUtil.format(new DateTime(),"yyyy-MM-dd HH:mm:ss.SSS");
|
||||
if (endDate == null) {
|
||||
endDate = DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS");
|
||||
} else {
|
||||
endDate = LuceneIndexWriter.getDate(endDate);
|
||||
}
|
||||
TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true);
|
||||
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
|
||||
if (whereJson.get("device_code") != null){
|
||||
booleanQueryBuilder.add(termRangeQuery, BooleanClause.Occur.MUST);
|
||||
if (whereJson.get("device_code") != null) {
|
||||
Query termQuery = new TermQuery(new Term("device_code", (String) whereJson.get("device_code")));
|
||||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (whereJson.get("method") != null){
|
||||
if (whereJson.get("method") != null) {
|
||||
Query termQuery = new TermQuery(new Term("method", (String) whereJson.get("method")));
|
||||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (whereJson.get("status_code") != null){
|
||||
if (whereJson.get("status_code") != null) {
|
||||
Query termQuery = new TermQuery(new Term("status_code", (String) whereJson.get("status_code")));
|
||||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (whereJson.get("requestparam") != null){
|
||||
WildcardQuery query = new WildcardQuery(new Term("requestparam", "*"+(String) whereJson.get("requestparam")+"*"));
|
||||
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (whereJson.get("responseparam") != null){
|
||||
WildcardQuery query = new WildcardQuery(new Term("responseparam", "*"+(String) whereJson.get("responseparam")+"*"));
|
||||
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (whereJson.get("blurry") != null) {
|
||||
WildcardQuery query = new WildcardQuery(new Term("fieldContent", "*"+(String) whereJson.get("blurry")+"*"));
|
||||
if (whereJson.get("requestparam") != null) {
|
||||
WildcardQuery query = new WildcardQuery(new Term("requestparam", "*" + whereJson.get("requestparam") + "*"));
|
||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
||||
}
|
||||
docs = searcher.search(booleanQueryBuilder.build(), end,sort);
|
||||
if (whereJson.get("responseparam") != null) {
|
||||
WildcardQuery query = new WildcardQuery(new Term("responseparam", "*" + whereJson.get("responseparam") + "*"));
|
||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (whereJson.get("blurry") != null) {
|
||||
WildcardQuery query = new WildcardQuery(new Term("fieldContent", "*" + whereJson.get("blurry") + "*"));
|
||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
||||
}
|
||||
docs = searcher.search(booleanQueryBuilder.build(), end, sort);
|
||||
//记录索引时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("匹配{}共耗时{}毫秒",booleanQueryBuilder.build(),(endTime-startTime));
|
||||
log.info("匹配{}共耗时{}毫秒", booleanQueryBuilder.build(), (endTime - startTime));
|
||||
log.info("查询到{}条日志文件", docs.totalHits.value);
|
||||
List<String> list = new ArrayList<>();
|
||||
ScoreDoc[] scoreDocs = docs.scoreDocs;
|
||||
if (end > docs.totalHits.value) end = (int) docs.totalHits.value;
|
||||
JSONArray array = new JSONArray();
|
||||
@@ -108,18 +102,18 @@ public class Searcher {
|
||||
ScoreDoc scoreDoc = scoreDocs[i];
|
||||
Document doc = reader.document(scoreDoc.doc);
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("content",doc.get("fieldContent"));
|
||||
object.put("device_code",doc.get("device_code"));
|
||||
object.put("logTime",doc.get("logTime"));
|
||||
object.put("method",doc.get("method"));
|
||||
object.put("status_code",doc.get("status_code"));
|
||||
object.put("requestparam",doc.get("requestparam"));
|
||||
object.put("responseparam",doc.get("responseparam"));
|
||||
if(doc.get("fieldContent") != null) {
|
||||
object.put("content", doc.get("fieldContent"));
|
||||
object.put("device_code", doc.get("device_code"));
|
||||
object.put("logTime", doc.get("logTime"));
|
||||
object.put("method", doc.get("method"));
|
||||
object.put("status_code", doc.get("status_code"));
|
||||
object.put("requestparam", doc.get("requestparam"));
|
||||
object.put("responseparam", doc.get("responseparam"));
|
||||
if (doc.get("fieldContent") != null) {
|
||||
array.add(object);
|
||||
}
|
||||
}
|
||||
for(Object logDto:array){
|
||||
for (Object logDto : array) {
|
||||
log.info(logDto.toString());
|
||||
}
|
||||
reader.close();
|
||||
@@ -128,16 +122,4 @@ public class Searcher {
|
||||
jo.put("totalElements", docs.totalHits.value);
|
||||
return jo;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String indexDir = "D:\\lucene\\index";
|
||||
//查询这个字符串
|
||||
String q = "07.832";
|
||||
Map whereJson = null;
|
||||
try {
|
||||
search(indexDir, q,whereJson);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.nl.modules.lucene.common.LuceneIndexWriter;
|
||||
import org.nl.modules.lucene.enums.LogTypeEnum;
|
||||
@@ -18,12 +17,8 @@ import org.nl.modules.lucene.service.dto.LuceneLogDto;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author jlm
|
||||
* @description 服务实现
|
||||
* @date 2023-04-11
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -32,7 +27,7 @@ public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
||||
|
||||
@Override
|
||||
public void deviceItemValue(String device_code, String key, String value) {
|
||||
String now = DateUtil.now();
|
||||
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@@ -43,12 +38,12 @@ public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException {
|
||||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) {
|
||||
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
|
||||
addIndex(luceneLogDto);
|
||||
}
|
||||
|
||||
private void addIndex(LuceneLogDto luceneLogDto) throws IOException {
|
||||
private void addIndex(LuceneLogDto luceneLogDto) {
|
||||
IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter();
|
||||
//创建一个Document对象
|
||||
Document document = new Document();
|
||||
@@ -94,7 +89,7 @@ public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
||||
MDC.put(name, name);
|
||||
log.info("{}", message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("error !", e);
|
||||
} finally {
|
||||
MDC.remove(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user