package com.zy.asrs.entity;
|
|
|
import com.core.common.Cools;
|
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.HashMap;
|
|
public class Re extends HashMap<String, Object> {
|
private static final long serialVersionUID = 1L;
|
private static final String CODE = "code";
|
private static final String MSG = "msg";
|
private static final String DATA = "data";
|
|
public Re(Integer code, String msg) {
|
super.put("returnStatus", code);
|
super.put("returnInfo", msg);
|
Date date=new Date();
|
DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String dateStr=df.format(date);
|
super.put ("msgTime", dateStr);
|
}
|
|
public static Re ok() {
|
return parse("0-操作成功");
|
}
|
|
public static Re ok(String msg) {
|
Re r = ok();
|
r.put("msg", msg);
|
return r;
|
}
|
|
public static Re ok(Object obj) {
|
return parse("0-操作成功").add(obj);
|
}
|
|
public static Re error() {
|
return parse("1-服务器错误");
|
}
|
|
public static Re error(String msg) {
|
Re r = error();
|
r.put("msg", msg);
|
return r;
|
}
|
|
public Re add(Object obj) {
|
this.put("data", obj);
|
return this;
|
}
|
|
public static Re parse(String message) {
|
if (Cools.isEmpty(message)) {
|
return parse("1-服务器错误");
|
} else {
|
String[] msg = message.split("-");
|
return msg.length == 2 ? new Re(Integer.parseInt(msg[0]), msg[1]) : parse("1-".concat(message));
|
}
|
}
|
}
|