package thyyxxk.webserver.entity.api.forpowersi.drgdip;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.List;

public class DrgDipResponseFactory {
    public static <T> JSONObject success(List<T> data) {
        ReturnEntity entity = new ReturnEntity();
        entity.setReturnCode(1);
        entity.setReturnMessage("成功。");
        entity.setReturnData(JSON.parseArray(JSON.toJSONStringWithDateFormat(data, "yyyy-MM-dd HH:mm:ss",
                SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty)));
        return JSON.parseObject(JSON.toJSONString(entity));
    }

    public static JSONObject noCorrespondingDataFound() {
        ReturnEntity entity = new ReturnEntity();
        entity.setReturnCode(2);
        entity.setReturnMessage("未查询到对应数据。");
        entity.setReturnData(new JSONArray());
        return JSON.parseObject(JSON.toJSONString(entity));
    }

    public static JSONObject wrongParameters(String message) {
        ReturnEntity entity = new ReturnEntity();
        entity.setReturnCode(3);
        entity.setReturnMessage("参数错误：" + message);
        return JSON.parseObject(JSON.toJSONString(entity));
    }

    public static JSONObject serviceExecutionException(String message) {
        ReturnEntity entity = new ReturnEntity();
        entity.setReturnCode(9);
        entity.setReturnMessage("服务执行发生异常：" + message);
        return JSON.parseObject(JSON.toJSONString(entity));
    }
}
