业务背景需求:
查看某个应用的每个按钮的时间趋势。
需求分解
输入:1,start 2,end 3,app
返回:数据格式
表格内含多行曲线
List<?壹> 这是表格
?→name 问号壹是一行包括曲线和一个按钮名字login/buy
?→List<?贰>曲线中的一个点(time,int:V1,V2,V3)
需要两个数据Bean.
返回数字格式案例
[
{
“name”: “login”,
“points”: [
{
“lastweek”: 100,
“time”: “2019-09-09 12:05:08”,
“today”: 100,
“yestoday”: 200
},
{
“lastweek”: 150,
“time”: “2019-09-09 12;06;08”,
“today”: 150,
“yestoday”: 250
}
]
},
{
“name”: “login”,
“points”: [
{
“lastweek”: 100,
“time”: “2019-09-09 12:05:08”,
“today”: 100,
“yestoday”: 200
},
{
“lastweek”: 150,
“time”: “2019-09-09 12;06;08”,
“today”: 150,
“yestoday”: 250
}
]
},
{
“name”: “login”,
“points”: [
{
“lastweek”: 100,
“time”: “2019-09-09 12:05:08”,
“today”: 100,
“yestoday”: 200
},
{
“lastweek”: 150,
“time”: “2019-09-09 12;06;08”,
“today”: 150,
“yestoday”: 250
}
]
}
]
程序实现
1:数据bean 描述线上的一个点。
public class Point {
String time;
int today;
int yestoday;
int lastweek;
public String getTime() {
return time;
}
public int getToday() {
return today;
}
public int getYestoday() {
return yestoday;
}
public int getLastweek() {
return lastweek;
}
public Point(String time, int today, int yestoday, int lastweek) {
this.time = time;
this.today = today;
this.yestoday = yestoday;
this.lastweek = lastweek;
}
public static void main(String[] args) {
Point point1 = new Point(“2019-09-09 12:05:08”, 100, 200, 100);
Point point2 = new Point(“2019-09-09 12;06;08”, 150, 250, 150);
System.out.println(point1.getTime() + " 的今天的相应时间是:" + point1.getToday());
System.out.println(point2.getTime() + “的昨天的相应时间是:” + point2.getYestoday());
System.out.println(point1.getTime()+“的上周的对应时间是:”+point1.getLastweek()+"@@@@@@"+point2.getTime()+“的上周对应时间是:”+point2.getLastweek());
}
}
数据bean2 表示表格中的一行(包括名字 和 一条线)
import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.List;
public class ResTime {
String name;
List points;
public String getName() {
return name;
}
public List getPoints() {
return points;
}
//构造方法,初始化各个属性
public ResTime(String name, List points) {
this.name = name;
this.points = points;
}
public static ResTime morkOne() {
Point point1 = new Point(“2019-09-09 12:05:08”, 100, 200, 100);
Point point2 = new Point(“2019-09-09 12;06;08”, 150, 250, 150);
System.out.println(point1.getTime() + " 的今天的相应时间是:" + point1.getToday());
System.out.println(point2.getTime() + “的昨天的相应时间是:” + point2.getYestoday());
System.out.println(point1.getTime() + “的上周的对应时间是:” + point1.getLastweek() + “@@@@@@” + point2.getTime() + “的上周对应时间是:” + point2.getLastweek());
List points = new ArrayList();
points.add(point1);
points.add(point2);
ResTime resTime1 = new ResTime(“login”, points);
String info = JSON.toJSONString(resTime1.getPoints());
System.out.println(“name:” + resTime1.getName() + “, line:” + info);
return resTime1;
}
}
3:Service,用来处理业务逻辑,通常包含 if,List,for,等
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class ResTimeService {
public List doListRt(String start, String end, String app) {
List result = new ArrayList();
ResTime resTime1 =ResTime.morkOne();
ResTime resTime2 =ResTime.morkOne();
ResTime resTime3 =ResTime.morkOne();
result.add(resTime1);
result.add(resTime2);
result.add(resTime3);
return result;
}
}
3:Action层 ,用来接收浏览器请求,返回数据
import com.douyin.w3.core.vo.rt.ResTimeService;
public class LogManagerAction {
@Autowired
ResTimeService resTimeService;
public void doListResTimes(Writter ctx,
@Param(“start”) String start,
@Param(“end”) String end,
@Param(“app”) String app
) {
ctx.writerData(resTimeService.doListRt(start, end, app));
}
}