com.jladder.data.RequestResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jladder Show documentation
Show all versions of jladder Show documentation
with java,a low code SDK,通用低代码开发包
package com.jladder.data;
import com.jladder.Ladder;
import com.jladder.lang.Json;
import com.jladder.lang.Regex;
import com.jladder.lang.Times;
import java.util.*;
/***
* 请求返回结果类
*/
public class RequestResult{
/***
* 初始化开始时间
*/
private transient long _dtstart = 0;
/***
* 是否处理成功
*/
public boolean Success;
/***
* 状态码
*/
public int Code;
/***
* 消息正文
*/
public String Message;
///
/// 资源索引
///
public String Rel;
///
/// 返回结果
///
public Object Result;
///
/// 返回时间
///
public long ReTime = Times.getTS();
///
/// 处理时长
///
public String duration = "0ms";
///
/// 节点标识
///
public String watchPoint = Ladder.Settings().getSite();
///
/// 未定义
///
public String datatype = "undefined";
private Map config = null;
///
/// 基本构造
///
public RequestResult()
{
_dtstart = Times.getTS();
Code = 200;
Message = AjaxResultCode.getMessage(200);
}
///
/// 基本构造
///
/// 返回情况
public RequestResult(Object result){
_dtstart =Times.getTS();;
if (result == null){
this.Code = 400;
Message = AjaxResultCode.Undfind.name();
return;
}
else if (result instanceof Integer){
this.Code = (int)result;
if (Code != 200) Message = AjaxResultCode.getMessage(Code);
else this.Message = "";
return;
}
else if (result instanceof String){
if (Regex.isMatch(result.toString(), "^\\d+$")){
this.Code = Integer.valueOf(result.toString());
return;
}
}
else if (result instanceof AjaxResult){
AjaxResult ret = (AjaxResult)result;
Code = ret.getStatusCode();
Message = ret.getMessage();
Result = ret.getData();
Rel = ret.getRel();
duration = ret.getDuration();
datatype = ret.getDatatype();
return;
}
else if (result instanceof Boolean){
boolean re = (Boolean)result;
if (re){
Code = 200;
}
else{
Code = 500;
Message = AjaxResultCode.getMessage(500);
}
return;
}
Code = 200;
Message = "操作成功";
Result = result;
}
///
/// 基本构造
///
/// 状态码
/// 消息文本
public RequestResult(int code, String message)
{
_dtstart = Times.getTS();
Message = message;
Code = code;
}
///
/// 设置
///
/// 状态码
/// 消息文本
///
public RequestResult set(int code, String msg)
{
_dtstart = Times.getTS();
Code = code;
Message = msg;
return this;
}
/***
* 设置消息文本
* @param message 消息文本
* @return
*/
public RequestResult setMessage(String message)
{
_dtstart = Times.getTS();
Message = message;
return this;
}
///
/// 设置处理时长
///
/// 开始时间
///
public RequestResult SetDuration(Date startTime)
{
long time = new Date().getTime() - startTime.getTime();
duration = time+"ms";
return this;
}
///
/// 设置处理时长
///
/// 开始时间
///
public RequestResult setDuration(String duration)
{
_dtstart = Times.getTS();
duration = duration;
return this;
}
///
/// 设置返回数据
///
/// 数据
///
public RequestResult setData(Object data)
{
_dtstart = Times.getTS();
Result = data;
return this;
}
///
/// 推入数据
///
/// 数据
///
public RequestResult pushData(Object data)
{
_dtstart = Times.getTS();
if (Result == null)
{
Result = new ArrayList