一、Server端
1、加入Maven依赖
<!-- jsonrpc4j -->
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
<artifactId>jsonrpc4j</artifactId>
<version>1.5.3</version>
</dependency>
2、创建服务
IAttendService.java
@JsonRpcService("attendService")
public interface IAttendService {
//设备接入网络
public int access(String brcode, String dname, String uuid);
//录入考勤信息
public int attend(String pversion,String uuid,String brcode,String vg,String time);
//同步时间
public String syntime();
//设备同步分组
int syngroups(String uuid, String brcode);
}
AttendService.java
@Service
@AutoJsonRpcServiceImpl
public class AttendService implements IAttendService{
@Resource
private ITestService testService;
@Override
public int syngroups(String uuid,String brcode){
int dgroups = 0;
return dgroups;
}
@Override
public String syntime(){
return TimeUtil.createTime(new Date());
}
/**
* @param brcode
* @param dname
* @param uuid
* @return
*/
@Override
public int access(String brcode, String dname, String uuid){
int flag = 0;
System.out.println("接入网络信息" + brcode + dname + uuid);
return flag;
}
/**
* @param pversion
* @param uuid
* @return
*/
@Override
public int attend(String pversion,String uuid,String brcode,String vg,String time) {
int flag = 0;
long ltime = Long.valueOf(time);
System.out.println(pversion + uuid + brcode + vg + time);
return flag;
}
}
3、整合Spring
<!-- jsonrpc4j -->
<bean id="attendService" class="com.vguang.service.AttendService"></bean>
<bean id="jackson" class="com.fasterxml.jackson.databind.ObjectMapper" />
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<bean id="streamingCompositeService" class="com.googlecode.jsonrpc4j.spring.CompositeJsonStreamServiceExporter">
<!-- 生产环境 -->
<property name="hostName" value="10.141.43.122"/>
<property name="port" value="8399"/>
<property name="services">
<list>
<ref bean="attendService"/>
</list>
</property>
</bean>