Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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());
    }
}