统一接口
package com.fanhuaholdings.cbs.common;
import com.fanhuaholdings.cbs.common.view.BaseVO;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@RequestMapping("/warningCallBack")
public interface WarningCallBackActionService<T extends BaseVO> {
@RequestMapping(value = "/warningCallBackForOrder", method = RequestMethod.POST)
void warningCallBackForOrder(@RequestBody T t);
@RequestMapping(value = "/warningCallBackForConfig", method = RequestMethod.POST)
void warningCallBackForConfig(@RequestBody T t);
}
实现
主要对统一接口返回的数据,根据不同的后续处理方式,将json对象序列化为对应的处理类的参数对象
/**
* @desc < 将其他模块返回的JSON串,反序列化为指定处理类的对象 >
* @author fengyc
*/
protected T serializer(String json) {
T t;
Type type = this.getClass().getGenericSuperclass();
ParameterizedType p = (ParameterizedType) type;
Class<T> cls = (Class<T>) p.getActualTypeArguments()[0];
try {
t = JSONUtils.jsonToObject(json, cls);
return t;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
处理类
protected T serializer(String json)该方法返回对象,根据调用对象不同,将json转换为RnContinueResultVO、FsBatchInterestVO、FaAgentWagePreVO等
public class CollectDataHandlerForContinue extends AbstractCollectDataHandler<RnContinueResultVO>;
public class CollectDataHandleForSettle extends AbstractCollectDataHandler<FsBatchInterestVO>;
public class CollectDataHandleForBlWage extends AbstractCollectDataHandler<FaAgentWagePreVO>;