首页>代码>java web网页版redis客户端工具>/redis-admin/src/main/java/cn/workcenter/common/response/WorkcenterResponseBodyJson.java
package cn.workcenter.common.response;

import cn.workcenter.common.WorkcenterResult;
import cn.workcenter.common.constant.WebConstant;

import com.alibaba.fastjson.JSON;


/**
 * 
 * 响应信息 
 * 
 * @author luoy
 *
 */
public class WorkcenterResponseBodyJson implements ResponseBody , WebConstant{
	
	public final String returncode; // 状态码
	public final String returnmsg;  // 返回的信息
	public final String returnmemo; // 返回的文本信息 {SUCCESS/FAILURE}:{errorcode}:{errormsg}
	public final Object data;       // 返回的响应数据
	public final String operator;   // 操作标示
	
	private WorkcenterResponseBodyJson() {
		returncode = "";
		returnmsg = "";
		returnmemo = "";
		operator = "";
		data = null;
	}
	
	private WorkcenterResponseBodyJson(String returncode, String returnmsg, String returnmemo, Object data, String operator) {
		this.returncode = returncode;
		this.returnmsg = returnmsg;
		this.returnmemo = returnmemo;
		this.operator = operator;
		this.data = data;
	}
	
	public static WorkcenterResponseBodyJson.Builder custom() {
		return new Builder();
	}
	
	public static class Builder {
		private String returncode;
		private String returnmsg;
		private String returnmemo;
		private String operator;
		private Object data;
		
		Builder() {
			super();
			this.returncode = "200";
			this.returnmsg = "request success";
			this.returnmemo = "SUCCESS:200000:request success";
			this.operator = "nothing";
			this.data = "attachment";
		}
		
		public WorkcenterResponseBodyJson.Builder setReturncode(String returncode) {
			this.returncode = returncode;
			return this;
		}

		public WorkcenterResponseBodyJson.Builder setReturnmsg(String returnmsg) {
			this.returnmsg = returnmsg;
			return this;
		}

		public WorkcenterResponseBodyJson.Builder setReturnmemo(String returnmemo) {
			this.returnmemo = returnmemo;
			return this;
		}
		
		public WorkcenterResponseBodyJson.Builder setOperator(String operator) {
			this.operator = operator;
			return this;
		}
		
		public Builder setAll(RuntimeException e) {
			this.returncode = "500";
			this.returnmsg = "server error";
			this.returnmemo = "FAILURE:10010000:RuntimeExceptionException" + COLON + e.getMessage();
			this.operator = null;
			this.data = null;
			return this;
		}
		
		public Builder setAll(Exception e) {
			this.returncode = "500";
			this.returnmsg = "server error";
			this.returnmemo = "FAILURE:10010000:Exception" + COLON + e.getMessage();
			this.operator = null;
			this.data = null;
			return this;
		}
		
		public Builder setAll(Throwable t) {
			this.returncode = "500";
			this.returnmsg = "server error";
			this.returnmemo = "FAILURE:10010000:Throwable" + COLON + t.getMessage();
			this.operator = null;
			this.data = null;
			return this;
		}
		
		public WorkcenterResponseBodyJson.Builder setAll(RuntimeException e, String operator) {
			this.returncode = "500";
			this.returnmsg = "server error";
			this.returnmemo = "FAILURE:10010000:RuntimeException" + COLON + e.getMessage();
			this.operator = operator;
			this.data = null;
			return this;
		}
		
		public WorkcenterResponseBodyJson.Builder setAll(WorkcenterResult result, String operator) {
			this.returncode = result.getResultCode();
			this.returnmsg = result.getResultMsg();
			this.returnmemo = result.getCodeEnum().getStatus() + COLON+result.getCodeEnum().getCode() + COLON+result.getCodeEnum().getMsg();
			this.operator = operator;
			this.data = result.getData();
			return this;
		}
		
		public WorkcenterResponseBodyJson.Builder setAll(WorkcenterResult result,  String operator, Object data) {
			this.returncode = result.getResultCode();
			this.returnmsg = result.getResultMsg();
			this.returnmemo = result.getCodeEnum().getStatus() + COLON+result.getCodeEnum().getCode() + COLON+result.getCodeEnum().getMsg();
			this.operator = operator;
			this.data = data;
			return this;
		}
		
		public WorkcenterResponseBodyJson.Builder setAll(String returncode, String returnmsg, String returnmemo, String operator , Object data){
			this.returncode = returncode;
			this.returnmsg = returnmsg;
			this.returnmemo = returnmemo;
			this.operator = operator;
			this.data = data;
			return this;
		}

		public WorkcenterResponseBodyJson build() {
			return new WorkcenterResponseBodyJson(returncode, returnmsg, returnmemo, data, operator);
		}

	}

	public String getReturncode() {
		return returncode;
	}

	public String getReturnmsg() {
		return returnmsg;
	}

	public String getReturnmemo() {
		return returnmemo;
	}
	
	public String getOperator() {
		return operator;
	}
	
	public Object getData() {
		return data;
	}
	
	@Override
	public String toString() {
		String json = JSON.toJSONString(this);
		return json;
	}
	
}
最近下载更多
凡人  LV2 2021年6月23日
sunnvig  LV2 2020年7月13日
q1147070520  LV1 2020年4月27日
qq420100523  LV1 2020年3月29日
Kevin_ZC  LV4 2020年3月28日
skipple3  LV39 2020年2月26日
111222333444555  LV2 2019年9月3日
Justice_Eternal  LV14 2019年8月31日
青春撕扯流年  LV8 2019年8月26日
forest9426  LV2 2019年7月26日
最近浏览更多
asddwh  LV12 2023年12月29日
yyh1252  LV8 2023年11月16日
liuyong_tom 2023年6月8日
暂无贡献等级
微信网友_6502065173204992  LV1 2023年6月2日
996171721  LV7 2023年5月29日
yangxb2  LV10 2022年10月27日
qq1176648922  LV6 2022年10月24日
youwuzuichen  LV10 2022年9月9日
小橘子1640  LV3 2022年5月31日
mwh1001  LV15 2022年5月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友