RouterController.java 2 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
package com.lyms.hospital.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lyms.sync.ParamsAdpter;
import com.lyms.sync.SyncHandler;
import com.lyms.sync.SyncUtils;
import com.lyms.sync.channel.ChannelData;
import com.lyms.web.controller.BaseController;

/**
* <li>@ClassName: RouterController
* <li>@Description: 远程接口调用数据处理分发
* <li>@author maliang
* <li>@date 2017年3月14日
* <li>
*/
@RestController
@RequestMapping("/remote")
public class RouterController extends BaseController {
private static final Logger log = LoggerFactory.getLogger(RouterController.class);

@RequestMapping(value = "/pull", produces = { MediaType.APPLICATION_JSON_VALUE })
public Object pull(HttpServletRequest request) throws Exception {
ChannelData data = SyncUtils.conver(request);
log.debug("节点数据被中心拉取:" + ToStringBuilder.reflectionToString(data));
Object handResult = SyncHandler.handler(data);
if (data.getLoop()) {
data = (ChannelData) handResult;
} else {
data.setData(ParamsAdpter.builder().push(handResult).toJsonString());
}
data.setAck(true);
return data;
}
@RequestMapping(value = "/push", produces = { MediaType.APPLICATION_JSON_VALUE })
public Object push(HttpServletRequest request) throws Exception {
ChannelData data = SyncUtils.conver(request);
log.debug("中心推送数据到节点:" + ToStringBuilder.reflectionToString(data));
Object handResult = SyncHandler.handler(data);
if (data.getLoop()) {
data = (ChannelData) handResult;
} else {
data.setData(ParamsAdpter.builder().push(handResult).toJsonString());
}
return data;
}


}