53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
|
|
package com.engine.salary.util;
|
||
|
|
|
||
|
|
|
||
|
|
import com.alibaba.fastjson.JSONObject;
|
||
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
||
|
|
import weaver.general.BaseBean;
|
||
|
|
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.Map;
|
||
|
|
import java.util.function.Function;
|
||
|
|
|
||
|
|
|
||
|
|
public class ResponseResult extends HashMap<String, Object> {
|
||
|
|
|
||
|
|
private static final long serialVersionUID = 1L;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 统一返回方法
|
||
|
|
*/
|
||
|
|
public static String run(Function<Map<String, Object>,Map<String, Object>> f,Map<String, Object> m) {
|
||
|
|
try {
|
||
|
|
return Ok(f.apply(m));
|
||
|
|
} catch (SalaryRunTimeException e) {
|
||
|
|
return Error(e.getMessage());
|
||
|
|
} catch (Exception e) {
|
||
|
|
BaseBean b = new BaseBean();
|
||
|
|
b.writeLog(e);
|
||
|
|
return Error(e.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 成功返回
|
||
|
|
*/
|
||
|
|
private static String Ok(Map<String, Object> map) {
|
||
|
|
Map<String, Object> apidatas = new HashMap<>();
|
||
|
|
apidatas.put("status", true);
|
||
|
|
apidatas.put("data",map);
|
||
|
|
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 失败返回
|
||
|
|
*/
|
||
|
|
private static String Error(String message) {
|
||
|
|
Map<String, Object> apidatas = new HashMap<>();
|
||
|
|
apidatas.put("status", false);
|
||
|
|
apidatas.put("errormsg", message);
|
||
|
|
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
|
||
|
|
}
|
||
|
|
}
|