| package com.matrix.system.shopXcx.dto; | 
|   | 
|   | 
| import java.util.*; | 
|   | 
| public class YYmonth { | 
|   | 
|     private Integer year; | 
|     private Integer month; | 
|     private List<YYDay> dates = new ArrayList<>(); | 
|   | 
|     public static List<YYmonth> buildMonth(int monthSpan) { | 
|         List<YYmonth> months = new ArrayList<>(); | 
|         for (int i = 0; i < monthSpan; i++) { | 
|             Calendar today = Calendar.getInstance(); | 
|             YYmonth yYmonth = new YYmonth(); | 
|             yYmonth.year = today.get(Calendar.YEAR); | 
|   | 
|   | 
|             yYmonth.month = today.get(Calendar.MONTH)+1+i; | 
|             //跨年 | 
|             if (yYmonth.month > 12) { | 
|                 yYmonth.month = yYmonth.month - 12; | 
|                 yYmonth.year = yYmonth.year + 1; | 
|             } | 
|             //修改年月 | 
|             today.set(Calendar.YEAR, yYmonth.year); | 
|             today.set(Calendar.MONTH, yYmonth.month-1); | 
|   | 
|             int dayOfMonth = today.getActualMaximum(Calendar.DAY_OF_MONTH); | 
|   | 
|   | 
|             for (int j = 1; j < dayOfMonth+1; j++) { | 
|   | 
|                 Calendar day = Calendar.getInstance(); | 
|                 day.set(Calendar.YEAR, yYmonth.year); | 
|                 day.set(Calendar.MONTH, yYmonth.month-1); | 
|                 day.set(Calendar.DAY_OF_MONTH, j); | 
|                 int dayOfWeek = day.get(Calendar.DAY_OF_WEEK); | 
|                 if (j == 1) { | 
|                     //判断当月第一天是周几,计算需要几个占位符 | 
|                     for (int k = 1; k < dayOfWeek; k++) { | 
|                         YYDay dayItem = new YYDay(); | 
|                         dayItem.setStatus(0); | 
|                         yYmonth.dates.add(dayItem); | 
|                     } | 
|                 } | 
|                 YYDay dayItem = new YYDay(day.getTime(),j); | 
|                 //时间是否小于当前时间 | 
|                 if(i==0&& today.get(Calendar.DAY_OF_MONTH)>j){ | 
|                     dayItem.setStatus(2); | 
|                 }else{ | 
|                     if(i==0 && today.get(Calendar.DAY_OF_MONTH)==j){ | 
|                         dayItem.setStatus(3); | 
|                     }else if(i==monthSpan-1 && j>dayOfMonth-4){ | 
|                         //最后一个月的后四天不能选 | 
|                         dayItem.setStatus(2); | 
|                     }else{ | 
|                         dayItem.setStatus(1); | 
|                     } | 
|                 } | 
|                 yYmonth.dates.add(dayItem); | 
|             } | 
|             months.add(yYmonth); | 
|         } | 
|         return months; | 
|     } | 
|   | 
|   | 
|     public Integer getYear() { | 
|         return year; | 
|     } | 
|   | 
|     public void setYear(Integer year) { | 
|         this.year = year; | 
|     } | 
|   | 
|     public Integer getMonth() { | 
|         return month; | 
|     } | 
|   | 
|     public void setMonth(Integer month) { | 
|         this.month = month; | 
|     } | 
|   | 
|     public List<YYDay> getDates() { | 
|         return dates; | 
|     } | 
|   | 
|     public void setDates(List<YYDay> dates) { | 
|         this.dates = dates; | 
|     } | 
|   | 
|     public static void main(String[] args) { | 
|         List<YYmonth> m= buildMonth(3); | 
|         System.out.println(m.size()); | 
|     } | 
| } |