yang_shj
3 months ago
16 changed files with 269 additions and 57 deletions
@ -1,32 +0,0 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.constants; |
||||
|
||||
import lombok.Getter; |
||||
import org.apache.poi.ss.formula.functions.T; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/8 15:27 |
||||
*/ |
||||
@Getter |
||||
public enum AnalysisResultType implements BaseEnum { |
||||
BOOLEAN("BOOLEAN", "是非判断", "是", Boolean.class), |
||||
NUMBER("NUMBER", "确定数量", null, Integer.class), |
||||
DECIMAL("DECIMAL", "获取数值", null, BigDecimal.class); |
||||
|
||||
private final String code; |
||||
|
||||
private final String msg; |
||||
|
||||
private final String condition; |
||||
|
||||
private final Class<T> clazz; |
||||
|
||||
AnalysisResultType(String code, String msg, String condition, Class clazz) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
this.condition = condition; |
||||
this.clazz = clazz; |
||||
} |
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.constants; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/14 9:23 |
||||
*/ |
||||
@Getter |
||||
public enum ComparisonType implements BaseEnum { |
||||
EQUAL("equal", "相等"), |
||||
GREATER("greater","大于"), |
||||
LESS("less","小于"); |
||||
private final String code; |
||||
|
||||
private final String msg; |
||||
|
||||
ComparisonType(String code, String msg) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
} |
||||
} |
@ -0,0 +1,31 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.constants; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/14 8:28 |
||||
*/ |
||||
@Getter |
||||
public enum ResultDataType implements BaseEnum { |
||||
OBJECT("Object", "Object类型", Object.class.getName(), null), |
||||
STRING("String", "String类型", String.class.getName(), null), |
||||
BOOLEAN("Boolean","Boolean类型",Boolean.class.getName(),"parseBoolean"), |
||||
INTEGER("Integer","Integer类型",Integer.class.getName(),"parseInt"); |
||||
|
||||
private final String code; |
||||
|
||||
private final String msg; |
||||
|
||||
private final String className; |
||||
|
||||
private final String method; |
||||
|
||||
ResultDataType(String code, String msg, String className, String method) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
this.className = className; |
||||
this.method = method; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.constants; |
||||
|
||||
import com.hnac.hzims.bigmodel.zhipuai.handler.ResultBooleanStrategy; |
||||
import com.hnac.hzims.bigmodel.zhipuai.handler.ResultCommonStrategy; |
||||
import com.hnac.hzims.bigmodel.zhipuai.handler.ResultStrategy; |
||||
import lombok.Getter; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/8 15:27 |
||||
*/ |
||||
@Getter |
||||
@Slf4j |
||||
public enum ResultStrategyType implements BaseEnum { |
||||
COMMON("ResultCommonStrategy", "普通值", ResultCommonStrategy.class), |
||||
BOOLEAN("ResultBooleanStrategy", "是非判断", ResultBooleanStrategy.class); |
||||
|
||||
private final String code; |
||||
|
||||
private final String msg; |
||||
|
||||
private final Class<? extends ResultStrategy> strategyClass; |
||||
|
||||
ResultStrategyType(String code, String msg, Class<? extends ResultStrategy> strategy) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
this.strategyClass = strategy; |
||||
} |
||||
|
||||
public ResultStrategy getStrategy() { |
||||
try { |
||||
return strategyClass.newInstance(); |
||||
} catch (Exception e) { |
||||
log.error("get result strategy fail", e); |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.handler; |
||||
|
||||
import com.hnac.hzims.bigmodel.zhipuai.constants.BaseEnum; |
||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ComparisonType; |
||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ResultStrategyType; |
||||
import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/14 7:41 |
||||
*/ |
||||
public class ResultBooleanStrategy implements ResultStrategy<Boolean> { |
||||
@Override |
||||
public String getCode() { |
||||
return ResultStrategyType.BOOLEAN.getCode(); |
||||
} |
||||
|
||||
@Override |
||||
public Boolean getResult(ZhipuAnalysisInfoEntity info, Object resultData) { |
||||
Object comparator = convertOriginalData(info.getResultCondition(), info.getResultType()); |
||||
ComparisonType comparisonType = BaseEnum.getInstance(info.getResultJudgeModel(), ComparisonType.class); |
||||
switch (comparisonType) { |
||||
case EQUAL: |
||||
return comparator.equals(resultData); |
||||
case GREATER: |
||||
return ((Comparable) comparator).compareTo(resultData) < 0; |
||||
case LESS: |
||||
return ((Comparable) comparator).compareTo(resultData) > 0; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,22 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.handler; |
||||
|
||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ResultStrategyType; |
||||
import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/13 10:33 |
||||
*/ |
||||
public class ResultCommonStrategy implements ResultStrategy<Object> { |
||||
@Override |
||||
public String getCode() { |
||||
return ResultStrategyType.COMMON.getCode(); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Object getResult(ZhipuAnalysisInfoEntity info, Object data) { |
||||
return data; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.handler; |
||||
|
||||
import com.hnac.hzims.bigmodel.zhipuai.constants.BaseEnum; |
||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ResultDataType; |
||||
import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springblade.core.tool.utils.StringUtil; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/13 10:00 |
||||
*/ |
||||
public interface ResultStrategy<T> { |
||||
|
||||
String getCode(); |
||||
|
||||
default boolean isSupport(String strategyCode) { |
||||
return getCode().equals(strategyCode); |
||||
} |
||||
|
||||
default Object convertOriginalData(String originalData, String className) { |
||||
ResultDataType type = BaseEnum.getInstance(className, ResultDataType.class); |
||||
if (null != type && StringUtil.isNotBlank(type.getMethod())) { |
||||
try { |
||||
Class<?> clazz = Class.forName(type.getClassName()); |
||||
Method method = clazz.getMethod(type.getMethod(), String.class); |
||||
return method.invoke(null, originalData); |
||||
} catch (Exception ignore) { |
||||
Logger logger = LoggerFactory.getLogger(ResultStrategy.class); |
||||
logger.info("parse data error", ignore); |
||||
} |
||||
} |
||||
return originalData; |
||||
} |
||||
|
||||
default T getResult(ZhipuAnalysisInfoEntity info, String originalData) { |
||||
return getResult(info, convertOriginalData(originalData, info.getResultType())); |
||||
} |
||||
|
||||
T getResult(ZhipuAnalysisInfoEntity info, Object resultData); |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.vo; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/13 16:18 |
||||
*/ |
||||
@Data |
||||
@ApiModel(description = "分析返回信息") |
||||
public class ZhipuAnalysisResult<T> implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "是否成功", required = true) |
||||
private boolean success; |
||||
|
||||
@ApiModelProperty(value = "承载数据") |
||||
private T result; |
||||
|
||||
@ApiModelProperty(value = "结果描述") |
||||
private String resultStr; |
||||
|
||||
} |
Loading…
Reference in new issue