时间曲线统计图数据结构,时间工具

图表数据结构生成工具类: 

public class GraphicUtils {

	public  static List<GraphicDTO>  getDayHures(List<GraphicDTO> list){
		List<GraphicDTO> newList= new ArrayList<>();
		for (int i=0;i<=23;i++){
			newList.add(getGraphicDTO(i+""));
		}
		return getGraphicDTOS(list, newList);
	}
    /**
	 *  曲线图数据拷贝赋值
	 * @param list SQL统计数据集合
	 * @param newList 工具生成数据集合
	 * @return list
	 */
	private static List<GraphicDTO> getGraphicDTOS(List<GraphicDTO> list, List<GraphicDTO> newList) {
		if(list==null||list.size()==0)return newList;
		newList=newList.stream().map(m -> {
			list.stream().filter(m2-> Objects.equals(m.getCreateTime(),m2.getCreateTime())).forEach(m2-> {
				m.setAmount(m2.getAmount());
				m.setOrderNum(m2.getOrderNum());
				m.setUserCount(m2.getUserCount());
			});
			return m;
		}).collect(Collectors.toList());
		return newList;
	}

	public static  GraphicDTO getGraphicDTO(String count){
		return new GraphicDTO(count);
	}
	public  static List<GraphicDTO>  getDay(List<GraphicDTO> list, String startDate, String endDate){
		List<GraphicDTO> newList;
		newList=GraphicUtils.getGraphicDTODate(startDate,endDate);
		return getGraphicDTOS(list, newList);
	}

	/**
	 *  获取两个时间段之间的所有日期 (年月日)
	 *  
	 * @param startTime 开始时间
	 * @param endTime 结束时间
	 * @return list
	 */
	public static List<GraphicDTO> getGraphicDTODate(String startTime, String endTime){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		// 声明保存日期集合
		List<GraphicDTO> list = new ArrayList<GraphicDTO>();
		try {
			// 转化成日期类型
			Date startDate = sdf.parse(startTime);
			Date endDate = sdf.parse(endTime);

			//用Calendar 进行日期比较判断
			Calendar calendar = Calendar.getInstance();
			while (startDate.getTime()<=endDate.getTime()){
				// 把日期添加到集合
				list.add(new GraphicDTO(sdf.format(startDate)));
				// 设置日期
				calendar.setTime(startDate);
				//把日期增加一天
				calendar.add(Calendar.DATE, 1);
				// 获取增加后的日期
				startDate=calendar.getTime();
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return list;
	}


	public static List<UserMemberRightDTO> initiUserMemberRightDTOList(){
		List<UserMemberRightDTO> newList = new ArrayList<>();
		newList.add(new UserMemberRightDTO("企业版","enterprise",0));
		newList.add(new UserMemberRightDTO("旗舰版","personal",0));
		newList.add(new UserMemberRightDTO("个人版","regular",0));
		newList.add(new UserMemberRightDTO("团队版","team",0));
		return newList;
	}
    /**
	 *  饼图数据拷贝赋值,算出总数
	 * @param dataList SQL统计数据集合
	 * @return Map
	 */
	public static Map<String,Object> setUserMemberRightDTOListData(List<UserMemberRightDTO> dataList){
		List<UserMemberRightDTO> newList = initiUserMemberRightDTOList();
		AtomicInteger total = new AtomicInteger();
		Map<String,Object> objectMap = new HashMap<>();
		if(dataList.size()>0) {
			newList = newList.stream().map(m -> {
				dataList.stream().filter(m2 -> Objects.equals(m.getMemberCode(), m2.getMemberCode())).forEach(m2 -> {
					m.setMemberNum(m2.getMemberNum());
					total.addAndGet(m2.getMemberNum());
				});
				return m;
			}).collect(Collectors.toList());
		}
		objectMap.put("total",total);
		objectMap.put("records",newList);
		return objectMap;
	}
}

曲线图实体类:

public class GraphicDTO {
	public GraphicDTO() {
	}

	public GraphicDTO(String createTime) {
		this.createTime = createTime;
	}

	public GraphicDTO(String createTime, Integer orderNum) {
		this.createTime = createTime;
		this.orderNum = orderNum;
	}

	public GraphicDTO(String createTime, BigDecimal amount, int orderNum, int userCount) {
		this.createTime = createTime;
		this.amount = amount;
		this.orderNum = orderNum;
		this.userCount = userCount;
	}

	@ApiModelProperty("图表横向数据")
	private String createTime;

	@ApiModelProperty("充值金额")
	private BigDecimal amount = BigDecimal.valueOf(0);

	@ApiModelProperty("充值笔数")
	private int orderNum = 0;

	@ApiModelProperty("充值商家数")
	private int userCount = 0;
}

饼图实体类:

public class UserMemberRightDTO {

	@ApiModelProperty(value = "套餐名称")
	public String memberName;

	@ApiModelProperty(value = "套餐编码")
	private String memberCode;

	@ApiModelProperty(value = "会员数量")
	private Integer memberNum;

	public UserMemberRightDTO() {
	}

	public UserMemberRightDTO(String memberName, String memberCode, Integer memberNum) {
		this.memberName = memberName;
		this.memberCode = memberCode;
		this.memberNum = memberNum;
	}
}

时间转换工具类:

public class DateUtils {

	/**
	 * 得到X天后的时间(时间格式)
	 * @param date
	 * @param day
	 * @return
	 */
	public static Date getXDateAfterDate(Date date, int day) {
		Calendar now = Calendar.getInstance();
		now.setTime(date);
		now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
		return now.getTime();
	}

	/**
	 * 获取指定日期后N天
	 *
	 * @param specifiedDay 日期
	 * @param n            后几天
	 * @return
	 */
	public static LocalDateTime getSpecifiedDayAfter(String specifiedDay, int n) {
		Calendar c = Calendar.getInstance();
		Date date = null;
		try {
			date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(specifiedDay);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		c.setTime(date);
		int day = c.get(Calendar.DATE);
		c.set(Calendar.DATE, day + n);
		String dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
		DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return LocalDateTime.parse(dayAfter, df);
	}
	/**
		获取当前时间转字符串
	 */
	public static String getCurDateStr() {
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		LocalDateTime now = LocalDateTime.now();
		return now.format(dateTimeFormatter);
	}

	/**
	 * 获取本月第一天
	 * @return STR
	 */
	public static String getMonthFirstDay(){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH,1);
		calendar.add(Calendar.MONTH,0);
		return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime())+" 00:00:00";
	}
	/**
	 * 获取本月最后一天
	 * @return STR
	 */
	public static String getMonthLastDay(){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime())+" 23:59:59";
	}

	/**
	 * 获取本周的第一天
	 * @return String
	 * **/
	public static String getWeekStart(){
		Calendar cal=Calendar.getInstance();
		cal.add(Calendar.WEEK_OF_MONTH, 0);
		cal.set(Calendar.DAY_OF_WEEK, 2);
		Date time=cal.getTime();
		return new SimpleDateFormat("yyyy-MM-dd").format(time)+" 00:00:00";
	}

	/**
	 * 获取本周的最后一天
	 * @return String
	 * **/
	public static String getWeekEnd(){
		Calendar cal=Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
		cal.add(Calendar.DAY_OF_WEEK, 1);
		Date time=cal.getTime();
		return new SimpleDateFormat("yyyy-MM-dd").format(time)+" 23:59:59";
	}

	/**
	 * 获取两个时间之间的天数
	 * @param s1 s1
	 * @param s2 s2
	 * @return int
	 */
	public static  int fun(String s1,String s2){
		//ctrl+alt+/提示方法参数
		//指定日期格式
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		//按照指定格式转化为LocalDate对象
		LocalDate time1 = LocalDate.parse(s1,dateTimeFormatter);
		LocalDate time2 = LocalDate.parse(s2,dateTimeFormatter);
		//调方法计算两个LocalDate的天数差
		long between = ChronoUnit.DAYS.between(time1, time2);
		return (int)between;
	}

	/**
	 *
	 * @param s1 yyyy-MM-dd HH:mm:ss
	 * @return yyyy-MM-dd
	 */
	public static  String dateStr(String s1){
		//ctrl+alt+/提示方法参数
		//指定日期格式
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
		//按照指定格式转化为LocalDate对象
		LocalDate time1 = LocalDate.parse(s1,dateTimeFormatter);
		return dateTimeFormatter1.format(time1);
	}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值