Commit 23c485dd by s_guodong

返回值的层级结构增加root

parent 090d76dc
......@@ -2,6 +2,7 @@ package com.ceb.gjjs.mda.resource.base;
import com.brilliance.mda.runtime.mda.driver.MdaEnv;
import com.brilliance.mda.runtime.request.BaseVO;
import com.brilliance.mda.runtime.response.RespondRoot;
import com.brilliance.mda.runtime.response.ResponseSet;
import com.brilliance.mda.support.service.ICommonService;
import com.brilliance.mda.support.td.BDAuthInfo;
......@@ -36,116 +37,116 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
@Path("/init")
@POST
public ResponseSet<V> init(@RequestBody V req) {
public RespondRoot<V> init(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().init(req);
return new RespondRoot<>(getCommonService().init(req));
}
@Path("/checkAll")
@POST
public ResponseSet checkAll(@RequestBody V req) {
public RespondRoot checkAll(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().checkAll(req);
return new RespondRoot(getCommonService().checkAll(req));
}
@Path("/saveData")
@POST
public ResponseSet<V> saveData(@RequestBody V req) {
public RespondRoot<V> saveData(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().saveData(req);
return new RespondRoot<>(getCommonService().saveData(req));
}
@Path("/confirmData")
@POST
public ResponseSet<V> confirmData(@RequestBody V req) {
public RespondRoot<V> confirmData(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().confirmData(req);
return new RespondRoot<>(getCommonService().confirmData(req));
}
@Path("/pending")
@POST
public ResponseSet<V> pending(@RequestBody V req) {
public RespondRoot<V> pending(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().pending(req);
return new RespondRoot<>(getCommonService().pending(req));
}
@Path("/executeCheck/{rule}")
@POST
public ResponseSet<V> executeCheck(@PathParam("rule") String rule, @RequestBody V req) {
public RespondRoot<V> executeCheck(@PathParam("rule") String rule, @RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
String[] ruleArr = rule.split(",");
return getCommonService().executeCheck(req, ruleArr);
return new RespondRoot<>(getCommonService().executeCheck(req, ruleArr));
}
@Path("/executeRule/{rule}")
@POST
public ResponseSet<V> executeRule(@PathParam("rule") String rule, @RequestBody V req) {
public RespondRoot<V> executeRule(@PathParam("rule") String rule, @RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
String[] ruleArr = rule.split(",");
return getCommonService().executeRule(req, ruleArr);
return new RespondRoot<>(getCommonService().executeRule(req, ruleArr));
}
@Path("/executeDefault/{rule}")
@POST
public ResponseSet<V> executeDefault(@PathParam("rule") String rule, @RequestBody V req) {
public RespondRoot<V> executeDefault(@PathParam("rule") String rule, @RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
String[] ruleArr = rule.split(",");
return getCommonService().executeDefault(req, ruleArr);
return new RespondRoot<>(getCommonService().executeDefault(req, ruleArr));
}
@Path("/executeNotify")
@POST
public ResponseSet<V> executeNotify(@RequestBody V req) {
public RespondRoot<V> executeNotify(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().executeNotify(req);
return new RespondRoot<>(getCommonService().executeNotify(req));
}
@Path("/executeDocpan")
@POST
public ResponseSet<V> executeDocpan(@RequestBody V req) {
public RespondRoot<V> executeDocpan(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().executeDocpan(req);
return new RespondRoot<>(getCommonService().executeDocpan(req));
}
@Path("/executeDocpanDetail")
@POST
public ResponseSet<V> executeDocpanDetail(@RequestBody V req) {
public RespondRoot<V> executeDocpanDetail(@RequestBody V req) {
String checkResult = resetAndcheckParam(req);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, req));
}
return getCommonService().executeDocpanDetail(req);
return new RespondRoot<>(getCommonService().executeDocpanDetail(req));
}
......@@ -160,7 +161,7 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
}
protected <T> ResponseSet<T> executeRule(RequestCommonVo requestCommonVo, Class<T> respondVoClass, String rule) {
protected <T> RespondRoot<T> executeRule(RequestCommonVo requestCommonVo, Class<T> respondVoClass, String rule) {
V baseVO = getVo();
RequestBaseVo requestBaseVo = requestCommonVo.getRoot();
T t = null;
......@@ -170,22 +171,22 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
}
String s = resetAndcheckBaseParam(requestBaseVo, baseVO);
if (!StringUtils.isBlank(s)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, s, t);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, s, t));
}
String checkResult = resetAndcheckParam(requestBaseVo, baseVO);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, t);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, t));
}
String[] ruleArr = new String[]{rule};
ResponseSet responseSet = getCommonService().executeRule(baseVO, ruleArr);
Object data = responseSet.getData();
ReflectUtil.setValue2RespondVo(t, respondVoClass, data, baseVO.getClass());
responseSet.setData(t);
return responseSet;
return new RespondRoot<>(responseSet);
}
protected <T> ResponseSet<T> executeCheck(RequestCommonVo<RequestBaseVo> requestCommonVo, Class<T> respondVoClass, String rule) {
protected <T> RespondRoot<T> executeCheck(RequestCommonVo<RequestBaseVo> requestCommonVo, Class<T> respondVoClass, String rule) {
V baseVO = getVo();
RequestBaseVo requestBaseVo = requestCommonVo.getRoot();
T t = null;
......@@ -195,18 +196,18 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
}
String s = resetAndcheckBaseParam(requestBaseVo, baseVO);
if (!StringUtils.isBlank(s)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, s, t);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, s, t));
}
String checkResult = resetAndcheckParam(requestBaseVo, baseVO);
if (StringUtils.isNotBlank(checkResult)) {
return new ResponseSet<>(ResponseSet.CODE_FAILURE, checkResult, t);
return new RespondRoot<>(new ResponseSet<>(ResponseSet.CODE_FAILURE, s, t));
}
String[] ruleArr = new String[]{rule};
ResponseSet responseSet = getCommonService().executeCheck(baseVO, ruleArr);
Object data = responseSet.getData();
ReflectUtil.setValue2RespondVo(t, respondVoClass, data, baseVO.getClass());
responseSet.setData(t);
return responseSet;
return new RespondRoot<>(responseSet);
}
......
package com.brilliance.mda.runtime.response;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.io.Serializable;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/18
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class RespondRoot<T> implements Serializable {
private ResponseSet<T> root;
public RespondRoot(ResponseSet<T> root) {
this.root = root;
}
}
......@@ -21,18 +21,14 @@ public class ResponseSet<T> {
public static final String CODE_FAILURE = "BBBBBB";
public static final String MSG_SUCESS = "操作成功!";
private String respCode;
private String respMsg;
private Map<String, String> fieldErrors;
private Map<String, List<String>> codeSet;
private String retcod;
private String retmsg;
private Object data;
public ResponseSet(IContext ctx, Object t) {
this.respCode = CODE_SUCCESS;
this.respMsg = MSG_SUCESS;
this.retcod = CODE_SUCCESS;
this.retmsg = MSG_SUCESS;
this.data = t;
fieldErrors = cloneFieldErrorsFromContext(ctx);
this.codeSet = getValuesSet(ctx);
ctx.visitValues();
MdaDriver.setValueToVO(ctx, this.data);
}
......@@ -47,42 +43,24 @@ public class ResponseSet<T> {
return valuesSet;
}
private Map<String, String> cloneFieldErrorsFromContext(IContext ctx) {
if (ctx == null) {
return null;
}
Map<String, String> fieldErrors = ctx.getFieldErrors();
Map<String, String> fieldErrorsClone = new LinkedHashMap<>();
fieldErrorsClone.putAll(fieldErrors);
fieldErrors.clear();
return fieldErrorsClone;
}
public ResponseSet(Object t) {
this.respCode = CODE_SUCCESS;
this.respMsg = MSG_SUCESS;
this.retcod = CODE_SUCCESS;
this.retmsg = MSG_SUCESS;
if (MdaEnv.getContext() != null) {
fieldErrors = cloneFieldErrorsFromContext(MdaEnv.getContext());
this.codeSet = getValuesSet(MdaEnv.getContext());
MdaEnv.getContext().visitValues();
}
this.data = t;
}
public ResponseSet(String errCode, String errMsg) {
this.respCode = errCode;
this.respMsg = errMsg;
this.retcod = errCode;
this.retmsg = errMsg;
if (MdaEnv.getContext() != null) {
fieldErrors = cloneFieldErrorsFromContext(MdaEnv.getContext());
this.codeSet = getValuesSet(MdaEnv.getContext());
MdaEnv.getContext().visitValues();
}
}
// public ResponseSet(String errCode,String errMsg,Map<String,String> fieldErrors){
// this(errCode,errMsg);
// this.fieldErrors = fieldErrors;
// }
public ResponseSet(String errCode, String errMsg, T t) {
this(errCode, errMsg);
this.data = t;
......@@ -99,36 +77,20 @@ public class ResponseSet<T> {
this.data = data;
}
public String getRespCode() {
return respCode;
}
public void setRespCode(String respCode) {
this.respCode = respCode;
}
public String getRespMsg() {
return respMsg;
}
public void setRespMsg(String respMsg) {
this.respMsg = respMsg;
}
public Map<String, String> getFieldErrors() {
return fieldErrors;
public String getRetcod() {
return retcod;
}
public void setFieldErrors(Map<String, String> fieldErrors) {
this.fieldErrors = fieldErrors;
public void setRetcod(String retcod) {
this.retcod = retcod;
}
public Map<String, List<String>> getCodeSet() {
return codeSet;
public String getRetmsg() {
return retmsg;
}
public void setCodeSet(Map<String, List<String>> codeSet) {
this.codeSet = codeSet;
public void setRetmsg(String retmsg) {
this.retmsg = retmsg;
}
static class BooleanResult {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment