12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package com.persagy.proxy.adm.request;
- import com.alibaba.fastjson.JSONArray;
- import com.persagy.proxy.adm.utils.AdmEntityTransferUtil;
- import com.persagy.proxy.common.entity.DmpResult;
- import lombok.AllArgsConstructor;
- import lombok.Data;
- import lombok.NoArgsConstructor;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * ADM 通用创建返回结果
- * @author Charlie Yu
- * @date 2021-08-16
- */
- @Data
- @NoArgsConstructor
- @AllArgsConstructor
- public class AdmCreateResponse {
- private final static String SUCCESS = "success";
- private final static String FAILURE = "failure";
- /** 结果 */
- private String result;
- /** 消息 */
- private String message;
- /** 错误数据主从对象 1 主对象 2 从对象 */
- private String errorType;
- /** 查询到的数据列表 */
- private List<?> entityList;
- public static AdmCreateResponse success() {
- return new AdmCreateResponse(SUCCESS, null, null, null);
- }
- public static AdmCreateResponse success(String message) {
- return new AdmCreateResponse(SUCCESS, message, null, null);
- }
- public static AdmCreateResponse failure(String message) {
- return new AdmCreateResponse(FAILURE, message, null, new ArrayList<>());
- }
- public static AdmCreateResponse failure(String message,String errorType) {
- return new AdmCreateResponse(FAILURE, message, errorType, new ArrayList<>());
- }
- public static AdmCreateResponse success(List<?> content) {
- return new AdmCreateResponse(SUCCESS, null, null, content);
- }
- /**
- * 从数据中台结果转换
- * @param admRequest
- * @param dmpResult
- * @param clazz
- * @param <T>
- * @return
- */
- public static <T> AdmCreateResponse fromDmp(AdmQueryCriteria admRequest, DmpResult<JSONArray> dmpResult, Class<T> clazz) {
- if(!DmpResult.SUCCESS.equals(dmpResult.getResult())) {
- return failure("调用中台查询接口出错:" + dmpResult.getMessage());
- }
- // 转换为结果
- List<T> admVOs = AdmEntityTransferUtil.toAdmMultiEntity(dmpResult.getData(), admRequest.getProjection(), clazz);
- Long total = dmpResult.getCount() == null ? null : dmpResult.getCount().longValue();
- return new AdmCreateResponse(SUCCESS, null, null, admVOs);
- }
- }
|