完成责任量化功能
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.njcn.advance.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.advance.enums.AdvanceResponseEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.EnumUtils;
|
||||
import com.njcn.device.biz.enums.DeviceResponseEnum;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年12月20日 10:03
|
||||
*/
|
||||
public class AdvanceEnumUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 获取UserResponseEnum实例
|
||||
*/
|
||||
public static AdvanceResponseEnum getDeviceEnumResponseEnumByMessage(@NotNull Object value) {
|
||||
AdvanceResponseEnum advanceResponseEnum;
|
||||
try {
|
||||
String message = value.toString();
|
||||
if(message.indexOf(StrUtil.C_COMMA)>0){
|
||||
value = message.substring(message.indexOf(StrUtil.C_COMMA)+1);
|
||||
}
|
||||
advanceResponseEnum = EnumUtils.valueOf(AdvanceResponseEnum.class, value, AdvanceResponseEnum.class.getMethod(BusinessException.GET_MESSAGE_METHOD));
|
||||
return Objects.isNull(advanceResponseEnum) ? AdvanceResponseEnum.INTERNAL_ERROR : advanceResponseEnum;
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new BusinessException(CommonResponseEnum.INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public static Enum<?> getExceptionEnum(HttpResult<Object> result){
|
||||
//如果返回错误,且为内部错误,则直接抛出异常
|
||||
CommonResponseEnum commonResponseEnum = EnumUtils.getCommonResponseEnumByCode(result.getCode());
|
||||
if (commonResponseEnum == CommonResponseEnum.ADVANCE_RESPONSE_ENUM) {
|
||||
return getDeviceEnumResponseEnumByMessage(result.getMessage());
|
||||
}
|
||||
return commonResponseEnum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn.advance.utils;
|
||||
|
||||
import com.njcn.advance.pojo.bo.responsibility.QvvrStruct;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月24日 14:12
|
||||
*/
|
||||
public class ResponsibilityCallDllOrSo extends JnaCallDllOrSo {
|
||||
|
||||
public static String strpath;
|
||||
|
||||
public ResponsibilityCallDllOrSo(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPath() {
|
||||
ResponsibilityCallDllOrSo.strpath = super.getStrpath();
|
||||
}
|
||||
|
||||
public interface ResponsibilityLibrary extends Library {
|
||||
// 加载Lib库
|
||||
ResponsibilityCallDllOrSo.ResponsibilityLibrary INSTANTCE = (ResponsibilityCallDllOrSo.ResponsibilityLibrary) Native.loadLibrary(ResponsibilityCallDllOrSo.strpath, ResponsibilityCallDllOrSo.ResponsibilityLibrary.class);
|
||||
// 定义方法--->与C方法相对应
|
||||
void harm_response(QvvrStruct outData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user