17 changed files with 1017 additions and 414 deletions
@ -0,0 +1,124 @@ |
|||
package org.nl.acs.device_driver.basedriver.agv.utils; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import org.nl.modules.system.domain.Dict; |
|||
import org.nl.modules.system.service.DictDetailService; |
|||
import org.nl.modules.system.service.DictService; |
|||
import org.nl.modules.system.service.dto.DictDetailDto; |
|||
import org.nl.modules.system.service.impl.DictDetailServiceImpl; |
|||
import org.nl.modules.system.service.impl.DictServiceImpl; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.function.Function; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* @author: tu qiang |
|||
* @createDate: 2024/1/12 |
|||
*/ |
|||
public class ErrorUtil { |
|||
|
|||
public static ConcurrentHashMap<String, List<DictDetailDto>> dictMap = new ConcurrentHashMap<>(); |
|||
|
|||
|
|||
public static String getDictDetail(String type, String error_code) { |
|||
getDict(); |
|||
List<DictDetailDto> dictDetailDtos = dictMap.get(type); |
|||
String detail = null; |
|||
if (ObjectUtil.isNotEmpty(dictDetailDtos)) { |
|||
for (int i = 0; i < dictDetailDtos.size(); i++) { |
|||
DictDetailDto dictDetailDto = dictDetailDtos.get(i); |
|||
String value = dictDetailDto.getValue(); |
|||
String label = dictDetailDto.getLabel(); |
|||
if (StrUtil.equals(value, error_code)) { |
|||
detail = label; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
return detail == null ? "字典表未配置对应的报警信息" : detail; |
|||
} |
|||
|
|||
public static Map<Integer, String> getDictDetailByName(String type) { |
|||
getDict(); |
|||
List<DictDetailDto> dictDetailDtos = dictMap.get(type); |
|||
Map<Integer, String> map = new HashMap<>(); |
|||
if (ObjectUtil.isNotEmpty(dictDetailDtos)) { |
|||
List<DictDetailDto> dtos = dictDetailDtos |
|||
.stream() |
|||
.filter(dictDetailDto -> !dictDetailDto.getValue().equals("0")) |
|||
.filter(dictDetailDto -> !dictDetailDto.getValue().equals("-1")) |
|||
.collect(Collectors.toList()); |
|||
dtos.forEach(dictDetailDto -> map.put(Integer.parseInt(dictDetailDto.getValue()), dictDetailDto.getLabel())); |
|||
} |
|||
return map; |
|||
} |
|||
|
|||
|
|||
public static void getDict() { |
|||
if (ObjectUtil.isEmpty(dictMap)) { |
|||
DictDetailService dictDetailService = SpringContextHolder.getBean(DictDetailServiceImpl.class); |
|||
DictService dictService = SpringContextHolder.getBean(DictServiceImpl.class); |
|||
List<Dict> dictDtos = dictService.queryAll(); |
|||
for (int i = 0; i < dictDtos.size(); i++) { |
|||
Dict dictDto = dictDtos.get(i); |
|||
dictMap.put(dictDto.getName(), getDict(dictDto.getName(), t -> { |
|||
return dictDetailService.getDictByName(t); |
|||
})); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static List<DictDetailDto> getDict(String name, Function<String, List<DictDetailDto>> f) { |
|||
return f.apply(name); |
|||
} |
|||
|
|||
public static Map<String, String> getAgvErrorMsg(Integer ageErrorNum) { |
|||
Map<Integer, String> agvMap = getDictDetailByName("agv_error_type"); |
|||
Integer[] keys = agvMap.keySet().toArray(new Integer[0]); |
|||
String message = ""; |
|||
String code = ""; |
|||
out: |
|||
for (int i = 1; i < 1 << keys.length; i++) { |
|||
int sum = 0; |
|||
StringBuffer sb = new StringBuffer(); |
|||
StringBuffer sbCode = new StringBuffer(); |
|||
inner: |
|||
for (int j = 0; j < keys.length; j++) { |
|||
if ((i & 1 << j) != 0) { |
|||
sum += keys[j]; |
|||
sb.append(agvMap.get(keys[j])).append(","); |
|||
sbCode.append(keys[j]).append(","); |
|||
} |
|||
} |
|||
if (sum == ageErrorNum) { |
|||
code = sbCode.toString(); |
|||
message = sb.toString(); |
|||
break out; |
|||
} |
|||
} |
|||
Map<String, String> map = new HashMap<>(); |
|||
String info = replace(message); |
|||
code = replace(code); |
|||
map.put("code", StrUtil.isEmpty(code) ? "-1" : code); |
|||
map.put("info", StrUtil.isEmpty(info) ? "AGV上报报警代码有误" : info); |
|||
return map; |
|||
} |
|||
|
|||
public static String replace(String message) { |
|||
if (StrUtil.isEmpty(message)) { |
|||
return null; |
|||
} |
|||
if (message.endsWith(",")) { |
|||
return message.substring(0, message.length() - 1); |
|||
} |
|||
return message; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,79 @@ |
|||
|
|||
package org.nl.acs.opc; |
|||
|
|||
|
|||
import org.nl.modules.wql.exception.WDKException; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.ObjectInputStream; |
|||
import java.io.ObjectOutputStream; |
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.lang.reflect.Method; |
|||
import java.util.Arrays; |
|||
import java.util.Objects; |
|||
|
|||
public class ObjectUtl { |
|||
private ObjectUtl() { |
|||
} |
|||
|
|||
public static boolean isEquals(Object a, Object b) { |
|||
if (a == null && b == null) { |
|||
return true; |
|||
} else if (a != null && b != null) { |
|||
if (a.getClass().isArray()) { |
|||
if (a instanceof boolean[]) { |
|||
return Arrays.equals((boolean[]) ((boolean[]) a), (boolean[]) ((boolean[]) b)); |
|||
} else if (a instanceof byte[]) { |
|||
return Arrays.equals((byte[]) ((byte[]) a), (byte[]) ((byte[]) b)); |
|||
} else if (a instanceof int[]) { |
|||
return Arrays.equals((int[]) ((int[]) a), (int[]) ((int[]) b)); |
|||
} else if (a instanceof long[]) { |
|||
return Arrays.equals((long[]) ((long[]) a), (long[]) ((long[]) b)); |
|||
} else if (a instanceof double[]) { |
|||
return Arrays.equals((double[]) ((double[]) a), (double[]) ((double[]) b)); |
|||
} else if (a instanceof short[]) { |
|||
return Arrays.equals((short[]) ((short[]) a), (short[]) ((short[]) b)); |
|||
} else if (a instanceof char[]) { |
|||
return Arrays.equals((char[]) ((char[]) a), (char[]) ((char[]) b)); |
|||
} else if (a instanceof float[]) { |
|||
return Arrays.equals((float[]) ((float[]) a), (float[]) ((float[]) b)); |
|||
} else if (a instanceof Object[]) { |
|||
return Arrays.equals((Object[]) ((Object[]) a), (Object[]) ((Object[]) b)); |
|||
} else { |
|||
throw new WDKException("未实现"); |
|||
} |
|||
} else { |
|||
return Objects.equals(a, b); |
|||
} |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
public static boolean isTrue(Boolean boolean_) { |
|||
return boolean_ != null && isEquals(boolean_, true); |
|||
} |
|||
|
|||
public static boolean isTrue(Boolean targetBoolean, boolean defaultBoolean) { |
|||
return targetBoolean == null ? defaultBoolean : targetBoolean; |
|||
} |
|||
|
|||
public static boolean isFalse(Boolean boolean_) { |
|||
return boolean_ != null && isEquals(boolean_, false); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
public static boolean isObject(Class<?> clazz) { |
|||
if (clazz == null) { |
|||
return false; |
|||
} else if (clazz.getClass().isArray()) { |
|||
return false; |
|||
} else { |
|||
return Object.class.isAssignableFrom(clazz); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue