ResultVo.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. package com.java110.vo;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.alibaba.fastjson.serializer.SerializerFeature;
  4. import org.springframework.http.HttpHeaders;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.http.ResponseEntity;
  7. import java.io.Serializable;
  8. /**
  9. * @ClassName ResultVo
  10. * @Description TODO
  11. * @Author wuxw
  12. * @Date 2020/5/28 18:41
  13. * @Version 1.0
  14. * add by wuxw 2020/5/28
  15. **/
  16. public class ResultVo implements Serializable {
  17. public static final int CODE_ERROR = 404;// 未知异常
  18. public static final int CODE_OK = 0; // 成功
  19. public static final int CODE_MACHINE_OK = 0; // 成功
  20. public static final int CODE_MACHINE_ERROR = -1; // 未知异常
  21. public static final int CODE_UNAUTHORIZED = 401; //认证失败
  22. public static final int CODE_WECHAT_UNAUTHORIZED = 1401; //认证失败
  23. public static final int CODE_BUSINESS_VERIFICATION = 5010; //业务校验未通过
  24. public static final int ORDER_ERROR = 500; //订单调度异常
  25. public static final String MSG_ERROR = "未知异常";// 未知异常
  26. public static final String MSG_OK = "成功"; // 成功
  27. public static final String MSG_UNAUTHORIZED = "认证失败"; //认证失败
  28. public static final int DEFAULT_RECORD = 1;
  29. public static final int DEFAULT_TOTAL = 1;
  30. public static final int CODE_WAIT_PAY = 41;// 支付未完成
  31. // 分页页数
  32. private int page;
  33. // 行数
  34. private int rows;
  35. //页数
  36. private int records;
  37. // 总记录数
  38. private long total;
  39. //状态
  40. private int code;
  41. //错误提示
  42. private String msg;
  43. //数据对象
  44. private Object data;
  45. //用来存放大计、小计金额
  46. private Object sumTotal;
  47. //所需数据
  48. private Object rep;
  49. public ResultVo() {
  50. }
  51. public ResultVo(int code, String msg) {
  52. this.code = code;
  53. this.msg = msg;
  54. }
  55. public ResultVo(Object data) {
  56. this.code = CODE_OK;
  57. this.msg = MSG_OK;
  58. this.data = data;
  59. }
  60. public ResultVo(int records, int total, Object data) {
  61. this.code = CODE_OK;
  62. this.msg = MSG_OK;
  63. this.records = records;
  64. this.total = total;
  65. this.data = data;
  66. }
  67. public ResultVo(int records, long total, Object data) {
  68. this.code = CODE_OK;
  69. this.msg = MSG_OK;
  70. this.records = records;
  71. this.total = total;
  72. this.data = data;
  73. }
  74. public ResultVo(int records, int total, Object data, Object sumTotal) {
  75. this.code = CODE_OK;
  76. this.msg = MSG_OK;
  77. this.records = records;
  78. this.total = total;
  79. this.data = data;
  80. this.sumTotal = sumTotal;
  81. }
  82. public ResultVo(int records, int total, Object data, Object sumTotal, Object rep) {
  83. this.code = CODE_OK;
  84. this.msg = MSG_OK;
  85. this.records = records;
  86. this.total = total;
  87. this.data = data;
  88. this.sumTotal = sumTotal;
  89. this.rep = rep;
  90. }
  91. public ResultVo(int code, String msg, Object data) {
  92. this.code = code;
  93. this.msg = msg;
  94. this.data = data;
  95. }
  96. public ResultVo(int records, int total, int code, String msg, Object data) {
  97. this.records = records;
  98. this.total = total;
  99. this.code = code;
  100. this.msg = msg;
  101. this.data = data;
  102. }
  103. public int getPage() {
  104. return page;
  105. }
  106. public void setPage(int page) {
  107. this.page = page;
  108. }
  109. public int getRows() {
  110. return rows;
  111. }
  112. public void setRows(int rows) {
  113. this.rows = rows;
  114. }
  115. public int getRecords() {
  116. return records;
  117. }
  118. public void setRecords(int records) {
  119. this.records = records;
  120. }
  121. public long getTotal() {
  122. return total;
  123. }
  124. public void setTotal(int total) {
  125. this.total = total;
  126. }
  127. public int getCode() {
  128. return code;
  129. }
  130. public void setCode(int code) {
  131. this.code = code;
  132. }
  133. public String getMsg() {
  134. return msg;
  135. }
  136. public void setMsg(String msg) {
  137. this.msg = msg;
  138. }
  139. public Object getData() {
  140. return data;
  141. }
  142. public void setData(Object data) {
  143. this.data = data;
  144. }
  145. public Object getSumTotal() {
  146. return sumTotal;
  147. }
  148. public void setSumTotal(Object sumTotal) {
  149. this.sumTotal = sumTotal;
  150. }
  151. public Object getRep() {
  152. return rep;
  153. }
  154. public void setRep(Object rep) {
  155. this.rep = rep;
  156. }
  157. @Override
  158. public String toString() {
  159. return JSONObject.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
  160. }
  161. /**
  162. * 创建ResponseEntity对象
  163. *
  164. * @param data 数据对象
  165. * @return
  166. */
  167. public static ResponseEntity<String> createResponseEntity(Object data) {
  168. ResultVo resultVo = new ResultVo(DEFAULT_RECORD, DEFAULT_TOTAL, data);
  169. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  170. return responseEntity;
  171. }
  172. /**
  173. * 创建ResponseEntity对象
  174. *
  175. * @param resultVo 数据对象
  176. * @return
  177. */
  178. public static ResponseEntity<String> createResponseEntity(ResultVo resultVo) {
  179. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  180. return responseEntity;
  181. }
  182. /**
  183. * 成功通用回复
  184. *
  185. * @return
  186. */
  187. public static ResponseEntity<String> success() {
  188. ResultVo resultVo = new ResultVo(CODE_OK, MSG_OK);
  189. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  190. return responseEntity;
  191. }
  192. /**
  193. * 成功通用回复
  194. *
  195. * @return
  196. */
  197. public static ResponseEntity<String> error(String msg,HttpStatus status) {
  198. ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
  199. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), status);
  200. return responseEntity;
  201. }
  202. /**
  203. * 成功通用回复
  204. *
  205. * @return
  206. */
  207. public static ResponseEntity<String> error(String msg) {
  208. ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
  209. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  210. return responseEntity;
  211. }
  212. /**
  213. * 成功通用回复
  214. *
  215. * @return
  216. */
  217. public static ResponseEntity<String> error(String msg,Object data) {
  218. ResultVo resultVo = new ResultVo(CODE_ERROR, msg,data);
  219. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  220. return responseEntity;
  221. }
  222. /**
  223. * 创建ResponseEntity对象
  224. *
  225. * @param records 页数
  226. * @param total 总记录数
  227. * @param data 数据对象
  228. * @return
  229. */
  230. public static ResponseEntity<String> createResponseEntity(int records, int total, Object data) {
  231. ResultVo resultVo = new ResultVo(records, total, data);
  232. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  233. return responseEntity;
  234. }
  235. /**
  236. * 创建ResponseEntity对象
  237. *
  238. * @param records
  239. * @param total
  240. * @param data
  241. * @param sumTotal
  242. * @return
  243. */
  244. public static ResponseEntity<String> createResponseEntity(int records, int total, Object data, Object sumTotal) {
  245. ResultVo resultVo = new ResultVo(records, total, data, sumTotal);
  246. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  247. return responseEntity;
  248. }
  249. /**
  250. * 页面跳转
  251. *
  252. * @param url
  253. * @return
  254. */
  255. public static ResponseEntity<String> redirectPage(String url) {
  256. HttpHeaders headers = new HttpHeaders();
  257. headers.add(HttpHeaders.LOCATION, url);
  258. ResponseEntity<String> responseEntity = new ResponseEntity<String>("", headers, HttpStatus.FOUND);
  259. return responseEntity;
  260. }
  261. /**
  262. * 创建ResponseEntity对象
  263. *
  264. * @param code 状态嘛
  265. * @param msg 返回信息
  266. * @param data 数据对象
  267. * @return
  268. */
  269. public static ResponseEntity<String> createResponseEntity(int code, String msg, Object data) {
  270. ResultVo resultVo = new ResultVo(code, msg, data);
  271. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  272. return responseEntity;
  273. }
  274. /**
  275. * 创建ResponseEntity对象
  276. *
  277. * @param code 状态嘛
  278. * @param msg 返回信息
  279. * @return
  280. */
  281. public static ResponseEntity<String> createResponseEntity(int code, String msg) {
  282. ResultVo resultVo = new ResultVo(code, msg);
  283. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  284. return responseEntity;
  285. }
  286. /**
  287. * 创建ResponseEntity对象
  288. *
  289. * @param records 页数
  290. * @param total 总记录数
  291. * @param code 状态嘛
  292. * @param msg 返回信息
  293. * @param data 数据对象
  294. * @return
  295. */
  296. public static ResponseEntity<String> createResponseEntity(int records, int total, int code, String msg, Object data) {
  297. ResultVo resultVo = new ResultVo(records, total, code, msg, data);
  298. ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
  299. return responseEntity;
  300. }
  301. }