1、java曲线图统计
1、按照天数的曲线
1、曲线图的实体类相关类
1、解释:如果下面的y2list 其实没有用到,因为上面只有一个曲线
public class UserAppsComplateData implements Serializable {
private List<String> xlist;
private List<Long> y1list;
private List<Long> y2list;
public List<String> getXlist()
{
return xlist;
}
public void setXlist(List<String> xlist)
{
this.xlist = xlist;
}
public List<Long> getY1list()
{
return y1list;
}
public void setY1list(List<Long> y1list)
{
this.y1list = y1list;
}
public List<Long> getY2list()
{
return y2list;
}
public void setY2list(List<Long> y2list)
{
this.y2list = y2list;
}
}
2、js调用controller
/**
* 获取商务在投产品数量列表
* @return
*/
@RequestMapping("getAppPutInList")
@ResponseBody
public ResponseBean getAppPutInList(Long adminId,String startDate, String endDate){
try {
if(adminId == null) adminId = CasConfig.RemoteUserUtil.getRemoteUserId();
return ResponseBean.buildSuccess(saleService.getAppPutInList(adminId,startDate,endDate));
} catch (AppException e)
{
return ResponseBean.buildFailure(e.getMessage());
}
}
3、服务层开始实现吧,朋友
@Override
public UserAppsComplateData getAppPutInList(Long adminId, String startDate, String endDate)
{
UserAppsComplateData complateData = new UserAppsComplateData();
List<String> xlist =
new ArrayList<>();
List<Long> y1list =
new ArrayList<>();
List<Date> lDate = findDates(DateHelper.convertString2Date(startDate,DateHelper.YYYY_MM_DD), DateHelper.convertString2Date(endDate,DateHelper.YYYY_MM_DD));
for (Date date : lDate)
{
xlist.add(DateHelper.convertDate2String(date, DateHelper.YYYY_MM_DD));
String sdate = DateHelper.convertDate2String(date, DateHelper.YYYY_MM_DD) + "
00:00:00";
String edate = DateHelper.convertDate2String(date, DateHelper.YYYY_MM_DD) + "
23:59:59";
Date stime = DateHelper.convertString2Date(sdate, DateHelper.YYYY_MM_DD_HH_MM_SS);
Date etime = DateHelper.convertString2Date(edate, DateHelper.YYYY_MM_DD_HH_MM_SS);
List<UserAppsSpreadData> spreadIdsList = userAppMapper.getSpreadIdsList(4l, stime, etime);
y1list.add(Long.valueOf(spreadIdsList.size()));
}
complateData.setXlist(xlist);
complateData.setY1list(y1list);
return complateData;
}
2、获取一段时间内的日期
/**
* 获取一段时间之内的日期
* @param dBegin
* @param dEnd
* @return
*/
private List<Date> findDates(Date dBegin, Date dEnd)
{
List lDate = new ArrayList();
lDate.add(dBegin);
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
Calendar calEnd = Calendar.getInstance();
calEnd.setTime(dEnd);
// 测试此日期是否在指定日期之后
while (dEnd.after(calBegin.getTime()))
{
// 根据日历的规则,为给定的日历字段添加或减去指定的时间量
calBegin.add(Calendar.DAY_OF_MONTH, 1);
lDate.add(calBegin.getTime());
}
return lDate;
}
2、按照月份的曲线
1、曲线图
2.、设置曲线实体类
public class UserAppsData implements Serializable {
private List<AppsAppData> appDataList;
private List<String> xlist;
private List<Integer> ylist;
private String ym; //当月月份
public List<AppsAppData> getAppDataList()
{
return appDataList;
}
public void setAppDataList(List<AppsAppData> appDataList)
{
this.appDataList = appDataList;
}
public List<String> getXlist()
{
return xlist;
}
public void setXlist(List<String> xlist)
{
this.xlist = xlist;
}
public List<Integer> getYlist()
{
return ylist;
}
public void setYlist(List<Integer> ylist)
{
this.ylist = ylist;
}
public String getYm() {
return ym;
}
public void setYm(String ym)
{
this.ym = ym;
}
}
3、controller
/**
* 获取商务新增应用列表
* @return
*/
@RequestMapping("getNewAddAppList")
@ResponseBody
public ResponseBean getNewAddAppList(Long adminId){
try {
if(adminId == null) adminId = CasConfig.RemoteUserUtil.getRemoteUserId();
return ResponseBean.buildSuccess(saleService.getNewAddAppList(adminId));
} catch (AppException e)
{
return ResponseBean.buildFailure(e.getMessage());
}
}
4、服务层真正实现
@Override
public UserAppsData getNewAddAppList(Long adminId)
{
List<String> xlist =
new ArrayList<>();
List<Integer> ylist =
new ArrayList<>();
UserAppsData appsData = new UserAppsData();
Date startDate = DateHelper.convertString2Date(getMonthFirstDay(),DateHelper.YYYY_MM_DD);
List<AppsAppData> list = userAppMapper.getUserAppAddList(adminId, startDate,new Date());
appsData.setYm(DateHelper.convertDate2String(new Date(),DateHelper.YYYY_MM));
appsData.setAppDataList(list);
for (int i = 6; i > 0 ; i--){
xlist.add(StringUtils.substringAfter(getYm(-i),"-")); 2017-08 取出08
List<AppsAppData> appAddListLast = userAppMapper.getUserAppAddList(adminId, getFirstYMDHMS(-i-1),getLastYMDHMS(-i-1));
List<AppsAppData> appAddListNew = userAppMapper.getUserAppAddList(adminId, getFirstYMDHMS(-i),getLastYMDHMS(-i));
int sum = 0;
appAddListNew.remove(appAddListLast);
ylist.add(appAddListNew.size());
}
appsData.setXlist(xlist);
appsData.setYlist(ylist);
return appsData;
}
1、getYm(-i)当前月份的接触上减去(6,5,4,3,2,1) 也就是显示8,9,10,11,12,1 月的曲线
private String getYm(int num)
{
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, num);
return DateHelper.convertDate2String(calendar.getTime(), DateHelper.YYYY_MM);
}
2、取得上个月的第一天,和上个月的最后一天(这里是28号,不过也差不多就是个这) 减去几就是上几个月的值
private Date getFirstYMDHMS(int num)
{
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,
calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
calendar.add(Calendar.MONTH, num);
String time = DateHelper.convertDate2String(calendar.getTime(), DateHelper.YYYY_MM_DD)+"
00:00:00";
return DateHelper.convertString2Date(time, DateHelper.YYYY_MM_DD_HH_MM_SS);
}
private Date getLastYMDHMS(int num)
{
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,
calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
calendar.add(Calendar.MONTH, num);
String time = DateHelper.convertDate2String(calendar.getTime(), DateHelper.YYYY_MM_DD)+"
23:59:59";
return DateHelper.convertString2Date(time, DateHelper.YYYY_MM_DD_HH_MM_SS);
}