package cn.autoform.util.tool; import cn.autoform.fw.exception.FormClientException; import cn.autoform.fw.exception.RestResult; import java.util.Objects; import java.util.Optional; public class GetFormClientResult { @SuppressWarnings({ "unchecked", "rawtypes"}) public static T getRightResult(RestResult result) throws FormClientException{ if(result!=null && !"0000".equals(result.getRspCode())){ throw new FormClientException(result.getRspCode(), result.getRspDesc()==null || Objects.equals("",result.getRspDesc()) ?result.getRspMsg():result.getRspDesc()); }else{ return Optional.ofNullable(result).map(RestResult::getData).map(data->(T)data).orElse(null); } } @SuppressWarnings({ "unchecked", "rawtypes"}) public static T getRightResultGetUserCode(RestResult result) throws FormClientException{ if(result!=null && !"000000".equals(result.getRspCode())){ throw new FormClientException(result.getRspCode(), result.getRspDesc()==null || Objects.equals("",result.getRspDesc()) ?result.getRspMsg():result.getRspDesc()); }else{ return Optional.ofNullable(result).map(RestResult::getData).map(data->(T)data).orElse(null); } } }