世界微速讯:时间曲线统计图数据结构,时间工具

2022-09-29 15:13:12来源:互联网  


(相关资料图)

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

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);}}

相关阅读

精彩推荐

相关词

推荐阅读