您的位置:首页 > 其它

响应时间实战记录2(调用外部接口获取真实数据)

2019-02-06 22:56 337 查看

package com.douyin.w3.core.vo.rt;

import com.douyin.w3.core.service.RtService;
import com.douyin.w3.module.view.module.seri.vo.VisualizationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ResTimeService {
@Autowired
RtService rtService;

public List doListRt(String start, String end, String app) {

//1:处理入参
List result = new ArrayList();
long startTime = Long.parseLong(start);
long endTime = Long.parseLong(end);

//2:根据参数,调用远程接口,获取数据结果
Map<String, List> data = rtService.getRtLines(app, startTime, endTime);

//3:通过for循环,将远程结果,转化成自己的 POJO数据对象
for (String name : data.keySet()) {
List vos = data.get(name);
ResTime resTime1 = transform(name, vos);
result.add(resTime1);
}

return result;
}

private ResTime transform(String name, List vos) {
List points = transform(vos);
ResTime resTime1 = new ResTime(name, points);
return resTime1;
}

private List transform(List vos) {
List points = new ArrayList();
for (VisualizationVo vo : vos) {

Point point1 = new Point(vo.getDate() ,
double2Int(vo.getValue()),
double2Int(vo.getLastDayValue()),
double2Int(vo.getLastWeekValue())
);
points.add(point1);

}

return points;
}

private int double2Int(double value) {
return new Double(value).intValue();
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: