kangwei:
1 设备运行时,补全日期、月份数据
正在显示
6 个修改的文件
包含
125 行增加
和
6 行删除
1 | package com.skua.modules.common.service; | ||
2 | |||
3 | import java.util.List; | ||
4 | import java.util.Map; | ||
5 | |||
6 | /** | ||
7 | * @auther kangwei | ||
8 | * @create 2024-11-19-12:09 | ||
9 | */ | ||
10 | public interface IPgCommonService { | ||
11 | List<Map<String, Object>> queryForList(String sql); | ||
12 | Map<String, Object> queryForMap(String sql); | ||
13 | } |
sk-base-common/src/main/java/com/skua/modules/common/service/impl/PgCommonServiceImpl.java
0 → 100644
1 | package com.skua.modules.common.service.impl; | ||
2 | |||
3 | import com.baomidou.dynamic.datasource.annotation.DS; | ||
4 | import com.skua.modules.common.service.IPgCommonService; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | ||
6 | import org.springframework.jdbc.core.JdbcTemplate; | ||
7 | import org.springframework.stereotype.Service; | ||
8 | |||
9 | import java.util.List; | ||
10 | import java.util.Map; | ||
11 | |||
12 | /** | ||
13 | * @auther kangwei | ||
14 | * @create 2024-11-19-12:10 | ||
15 | */ | ||
16 | @Service | ||
17 | @DS("pg-db") | ||
18 | public class PgCommonServiceImpl implements IPgCommonService { | ||
19 | @Autowired | ||
20 | private JdbcTemplate jdbcTemplate; | ||
21 | @Override | ||
22 | public List<Map<String, Object>> queryForList(String sql) { | ||
23 | return jdbcTemplate.queryForList(sql); | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public Map<String, Object> queryForMap(String sql) { | ||
28 | return jdbcTemplate.queryForMap(sql); | ||
29 | } | ||
30 | |||
31 | |||
32 | } |
此文件的差异被折叠,
点击展开。
... | @@ -2,11 +2,9 @@ package com.skua.modules.guest.util; | ... | @@ -2,11 +2,9 @@ package com.skua.modules.guest.util; |
2 | 2 | ||
3 | import java.text.ParseException; | 3 | import java.text.ParseException; |
4 | import java.text.SimpleDateFormat; | 4 | import java.text.SimpleDateFormat; |
5 | import java.time.LocalDate; | 5 | import java.time.*; |
6 | import java.time.LocalDateTime; | ||
7 | import java.time.Period; | ||
8 | import java.time.ZoneId; | ||
9 | import java.time.format.DateTimeFormatter; | 6 | import java.time.format.DateTimeFormatter; |
7 | import java.time.temporal.ChronoUnit; | ||
10 | import java.util.*; | 8 | import java.util.*; |
11 | import java.util.stream.Stream; | 9 | import java.util.stream.Stream; |
12 | 10 | ||
... | @@ -97,6 +95,62 @@ public class DateUtil { | ... | @@ -97,6 +95,62 @@ public class DateUtil { |
97 | } | 95 | } |
98 | 96 | ||
99 | 97 | ||
98 | /*** | ||
99 | * 获取两个时间的日期 | ||
100 | * @param start | ||
101 | * @param end | ||
102 | * @return | ||
103 | */ | ||
104 | public static List<String> getDaysBetween(String start, String end,String format) { | ||
105 | List<String> days = new ArrayList<>(); | ||
106 | if(format == null ){ | ||
107 | format = "yyyy-MM-dd"; | ||
108 | } | ||
109 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); | ||
110 | // 解析日期 | ||
111 | LocalDate startDate = LocalDate.parse(start, formatter); | ||
112 | LocalDate endDate = LocalDate.parse(end, formatter); | ||
113 | LocalDate currentDate = LocalDate.now();//创建一个LocalData对象获取当前日期 | ||
114 | if(endDate.isAfter( currentDate)){ | ||
115 | endDate = currentDate; | ||
116 | } | ||
117 | long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate); | ||
118 | for (int i = 0; i <= numOfDaysBetween; i++) { | ||
119 | LocalDate date = startDate.plusDays(i); | ||
120 | days.add(date.toString()); // 格式化为 yyyy-MM | ||
121 | } | ||
122 | return days; | ||
123 | } | ||
124 | /*** | ||
125 | * 获取两个时间的月份 | ||
126 | * @param start | ||
127 | * @param end | ||
128 | * @return | ||
129 | */ | ||
130 | public static List<String> getMonthsBetween(String start, String end,String format) { | ||
131 | if(format == null ){ | ||
132 | format = "yyyy-MM-dd"; | ||
133 | } | ||
134 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); | ||
135 | // 解析日期 | ||
136 | LocalDate startDate = LocalDate.parse(start, formatter); | ||
137 | LocalDate endDate = LocalDate.parse(end, formatter); | ||
138 | LocalDate currentDate = LocalDate.now();//创建一个LocalData对象获取当前日期 | ||
139 | if(endDate.isAfter( currentDate)){ | ||
140 | endDate = currentDate; | ||
141 | } | ||
142 | List<String> months = new ArrayList<>(); | ||
143 | // 获取起始和结束月份 | ||
144 | YearMonth startMonth = YearMonth.from(startDate); | ||
145 | YearMonth endMonth = YearMonth.from(endDate); | ||
146 | // 遍历月份并添加到列表 | ||
147 | YearMonth currentMonth = startMonth; | ||
148 | while (!currentMonth.isAfter(endMonth)) { | ||
149 | months.add(currentMonth.toString()); // 格式化为 yyyy-MM | ||
150 | currentMonth = currentMonth.plusMonths(1); | ||
151 | } | ||
152 | return months; | ||
153 | } | ||
100 | 154 | ||
101 | /** | 155 | /** |
102 | * 获取两个日期之间的所有日期 (年月日) | 156 | * 获取两个日期之间的所有日期 (年月日) |
... | @@ -123,10 +177,9 @@ public class DateUtil { | ... | @@ -123,10 +177,9 @@ public class DateUtil { |
123 | if(currentDate.getTime() < endDate.getTime() ){ | 177 | if(currentDate.getTime() < endDate.getTime() ){ |
124 | endDate = currentDate; | 178 | endDate = currentDate; |
125 | } | 179 | } |
126 | |||
127 | //用Calendar 进行日期比较判断 | 180 | //用Calendar 进行日期比较判断 |
128 | Calendar calendar = Calendar.getInstance(); | 181 | Calendar calendar = Calendar.getInstance(); |
129 | while (startDate.getTime() < endDate.getTime()){ | 182 | while (startDate.getTime() <= endDate.getTime()){ |
130 | // 把日期添加到集合 | 183 | // 把日期添加到集合 |
131 | list.add(formatSDF.format(startDate)); | 184 | list.add(formatSDF.format(startDate)); |
132 | // 设置日期 | 185 | // 设置日期 | ... | ... |
... | @@ -121,4 +121,15 @@ public class MaterialInfo { | ... | @@ -121,4 +121,15 @@ public class MaterialInfo { |
121 | @Excel(name = "修订过程", width = 15) | 121 | @Excel(name = "修订过程", width = 15) |
122 | @ApiModelProperty(value = "修订过程") | 122 | @ApiModelProperty(value = "修订过程") |
123 | private String updateHistory; | 123 | private String updateHistory; |
124 | |||
125 | @ApiModelProperty(value = "文件号") | ||
126 | private String fileCode; | ||
127 | |||
128 | @ApiModelProperty(value = "使用范围") | ||
129 | private String useScope; | ||
130 | |||
131 | @ApiModelProperty(value = "审核状态:0 未发布 1 已发布(待审核)2 审核驳回 3 审核通过") | ||
132 | @Dict(dicCode = "purchase_plan_status") | ||
133 | private String status; | ||
134 | |||
124 | } | 135 | } | ... | ... |
... | @@ -322,4 +322,14 @@ public class ScreenDataServiceImpl implements IScreenDataService { | ... | @@ -322,4 +322,14 @@ public class ScreenDataServiceImpl implements IScreenDataService { |
322 | return months; | 322 | return months; |
323 | } | 323 | } |
324 | 324 | ||
325 | public static void main(String[] args) { | ||
326 | String startTime = "2024-01-01";// | ||
327 | String endTime = "2024-12-31"; | ||
328 | String format ="yyyy-MM-dd"; | ||
329 | List<String> dateList = getMonthsBetween(startTime, endTime); | ||
330 | for(String date : dateList){ | ||
331 | System.out.println("date:"+date); | ||
332 | } | ||
333 | } | ||
334 | |||
325 | } | 335 | } | ... | ... |
-
请 注册 或 登录 后发表评论