|
|
@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
package com.dsideal.resource.Util;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class RetKit {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 按VUE的要求返回List<Record>数据格式
|
|
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* data: Map<String,Object>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(List<com.jfinal.plugin.activerecord.Record> list) {
|
|
|
|
|
|
|
|
return renderSuccess(null, list, null, 0, 0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(String msg, List<com.jfinal.plugin.activerecord.Record> list) {
|
|
|
|
|
|
|
|
return renderSuccess(msg, list, null, 0, 0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(String msg, Page<com.jfinal.plugin.activerecord.Record> page, String dataName) {
|
|
|
|
|
|
|
|
return renderSuccess(msg, page.getList(), dataName, page.getPageNumber(), page.getPageSize(), page.getTotalRow());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(String msg, Map<String, Object> map) {
|
|
|
|
|
|
|
|
Map<String, Object> rMap = new HashMap<>();
|
|
|
|
|
|
|
|
rMap.put("code", 200);
|
|
|
|
|
|
|
|
if (!StrKit.isBlank(msg)) {
|
|
|
|
|
|
|
|
rMap.put("msg", msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rMap.put("data", map);
|
|
|
|
|
|
|
|
return rMap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(cn.hutool.json.JSONArray jsonArray) {
|
|
|
|
|
|
|
|
return renderSuccess(null, jsonArray);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(String msg, cn.hutool.json.JSONArray jsonArray) {
|
|
|
|
|
|
|
|
Map<String, Object> rMap = new HashMap<>();
|
|
|
|
|
|
|
|
rMap.put("code", 200);
|
|
|
|
|
|
|
|
if (!StrKit.isBlank(msg)) {
|
|
|
|
|
|
|
|
rMap.put("msg", msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rMap.put("data", jsonArray);
|
|
|
|
|
|
|
|
return rMap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderSuccess(String msg, List<Record> list, String dataName, int pageNum, int pageSize, int total) {
|
|
|
|
|
|
|
|
Map<String, Object> rMap = new HashMap<>();
|
|
|
|
|
|
|
|
rMap.put("code", 200);
|
|
|
|
|
|
|
|
if (!StrKit.isBlank(msg)) {
|
|
|
|
|
|
|
|
rMap.put("msg", msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StrKit.isBlank(dataName)) {
|
|
|
|
|
|
|
|
//没有List的名称,直接把list放到data中,[]数组形式
|
|
|
|
|
|
|
|
rMap.put("data", list);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//有List的名称,则把list放到data中,也需要把list的 size()做为一个属性,放到data上的count属性中
|
|
|
|
|
|
|
|
Map<String, Object> _map = new HashMap<>();
|
|
|
|
|
|
|
|
_map.put(dataName, list);
|
|
|
|
|
|
|
|
_map.put("total", list.size());
|
|
|
|
|
|
|
|
if (pageNum > 0) {
|
|
|
|
|
|
|
|
_map.put("pageNum", pageNum);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pageSize > 0) {
|
|
|
|
|
|
|
|
_map.put("pageSize", pageSize);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total > 0) {
|
|
|
|
|
|
|
|
_map.put("total", total);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rMap.put("data", _map);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rMap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderFail(String msg) {
|
|
|
|
|
|
|
|
return renderFail(msg, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, Object> renderFail(String msg, Map<String, Object> map) {
|
|
|
|
|
|
|
|
Map<String, Object> rMap = new HashMap<>();
|
|
|
|
|
|
|
|
rMap.put("code", 500);
|
|
|
|
|
|
|
|
if (!StrKit.isBlank(msg)) {
|
|
|
|
|
|
|
|
rMap.put("msg", msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
|
|
|
rMap.put("data", map);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rMap;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|