17 changed files with 185 additions and 131 deletions
			
			
		@ -1,31 +1,41 @@
					 | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.constants; | 
				
			||||
 | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.handler.result.data.BooleanParser; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.handler.result.data.IntegerParser; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.handler.result.data.ResultDataParser; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.handler.result.data.StringParser; | 
				
			||||
import lombok.Getter; | 
				
			||||
import lombok.extern.slf4j.Slf4j; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @Author: ypj | 
				
			||||
 * @Date: 2024/8/14 8:28 | 
				
			||||
 */ | 
				
			||||
@Getter | 
				
			||||
@Slf4j | 
				
			||||
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"); | 
				
			||||
    STRING("String", "String类型", StringParser.class), | 
				
			||||
    BOOLEAN("Boolean", "Boolean类型", BooleanParser.class), | 
				
			||||
    INTEGER("Integer", "Integer类型", IntegerParser.class); | 
				
			||||
 | 
				
			||||
    private final String code; | 
				
			||||
 | 
				
			||||
    private final String msg; | 
				
			||||
 | 
				
			||||
    private final String className; | 
				
			||||
    private final Class<? extends ResultDataParser> parser; | 
				
			||||
 | 
				
			||||
    private final String method; | 
				
			||||
 | 
				
			||||
    ResultDataType(String code, String msg, String className, String method) { | 
				
			||||
    ResultDataType(String code, String msg, Class<? extends ResultDataParser> parser) { | 
				
			||||
        this.code = code; | 
				
			||||
        this.msg = msg; | 
				
			||||
        this.className = className; | 
				
			||||
        this.method = method; | 
				
			||||
        this.parser = parser; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    public ResultDataParser getParser() { | 
				
			||||
        try { | 
				
			||||
            return parser.newInstance(); | 
				
			||||
        } catch (Exception e) { | 
				
			||||
            log.error("get result data parse fail", e); | 
				
			||||
        } | 
				
			||||
        return null; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					 | 
				
			||||
@ -1,10 +1,11 @@
					 | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.handler; | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.handler.result; | 
				
			||||
 | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.constants.BaseEnum; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ComparisonType; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ErrorCode; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.constants.ResultStrategyType; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; | 
				
			||||
import com.hnac.hzims.bigmodel.zhipuai.handler.result.ResultStrategy; | 
				
			||||
import org.springframework.util.Assert; | 
				
			||||
 | 
				
			||||
import java.util.Objects; | 
				
			||||
@ -0,0 +1,12 @@
					 | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.handler.result.data; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @Author: ypj | 
				
			||||
 * @Date: 2024/8/28 16:12 | 
				
			||||
 */ | 
				
			||||
public class BooleanParser implements ResultDataParser<Boolean> { | 
				
			||||
    @Override | 
				
			||||
    public Boolean parse(String originalData) { | 
				
			||||
        return Boolean.parseBoolean(originalData); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,12 @@
					 | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.handler.result.data; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @Author: ypj | 
				
			||||
 * @Date: 2024/8/28 16:46 | 
				
			||||
 */ | 
				
			||||
public class IntegerParser implements ResultDataParser<Integer> { | 
				
			||||
    @Override | 
				
			||||
    public Integer parse(String originalData) { | 
				
			||||
        return Integer.parseInt(originalData); | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
@ -0,0 +1,9 @@
					 | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.handler.result.data; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @Author: ypj | 
				
			||||
 * @Date: 2024/8/28 16:04 | 
				
			||||
 */ | 
				
			||||
public interface ResultDataParser<T> { | 
				
			||||
    T parse(String originalData); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,12 @@
					 | 
				
			||||
package com.hnac.hzims.bigmodel.zhipuai.handler.result.data; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * @Author: ypj | 
				
			||||
 * @Date: 2024/8/28 16:11 | 
				
			||||
 */ | 
				
			||||
public class StringParser implements ResultDataParser<String> { | 
				
			||||
    @Override | 
				
			||||
    public String parse(String originalData) { | 
				
			||||
        return originalData; | 
				
			||||
    } | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue