All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edi.rule.model.JSResult Maven / Gradle / Ivy

The newest version!
package edi.rule.model;

import java.util.LinkedHashMap;

import edi.rule.extend.interfaces.IJSRuleHttpResponse;
import edi.rule.extend.interfaces.IJSRuleModel;
import edi.rule.util.ZSRule;
import edi.rule.work.interfaces.IJSRuleCustom;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.experimental.Accessors;

/**
 * 

默认情况下返回类型,可通过继承此对象来自定义返回结果,子类可通过重写此类字段属性结合使用jackson注解@JsonProperty来更改属性名字,使用@JsonIgnore注解来删除属性 *

继承该类的子类尽量避免boolean类型的变量以is开头命名,以免出现一些不容易排查的问题 */ @Data @Accessors(chain=true) public class JSResult implements IJSRuleCustom,IJSRuleModel,IJSRuleHttpResponse { /** *

状态码 * */ public Integer code; /** *

系统消息 * */ public String message; /** *

系统返回的结果,此处不做泛型处理,意在只能是有序的集合类型,因为这将关乎到插件{@link JSRuleShunt}的使用 * */ public LinkedHashMap result = new LinkedHashMap<>(); /** *

系统返回的日志 * */ public String log; public static R instance(){ return ZSRule.createModel(ExtendType.result); } public static R instance(LinkedHashMap data,Integer code,String message){ R result = instance(); result.setCode(code); result.setMessage(message); result.setResult(data); return result; } public static R success(){ R result = instance(); result.setCode(HttpStatusEnum.SUCCESS.getCode()); result.setMessage(HttpStatusEnum.SUCCESS.getMessage()); return result; } public static R success(LinkedHashMap data){ R result = success(); result.setResult(data); return result; } public static R fail(Integer code,String message){ return instance(null,code,message); } public static R fail(String message){ return fail(HttpStatusEnum.FAIL.getCode(),message); } public static R fail(){ R result = instance(); result.setCode(HttpStatusEnum.FAIL.getCode()); result.setMessage(HttpStatusEnum.FAIL.getMessage()); return result; } @Getter @AllArgsConstructor protected enum HttpStatusEnum implements IJSRuleHttpResponse { SUCCESS(200, "operation successfully"), FAIL(500,"operation failure"); private final Integer code; private final String message; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy