Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张雷
/
skboot-zhongye
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
构建
提交
问题看板
文件
提交
网络
比较
分支
标签
ccb8baf8
由
sonin
编写于
2025-04-30 16:24:05 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
运营周报 根据指定周获取时间
1 个父辈
b8c39a0a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
42 行增加
和
16 行删除
sk-module-datafill/src/main/java/com/skua/modules/custom/service/impl/FCustomReportDatasetServiceImpl.java
sk-module-datafill/src/main/java/com/skua/modules/custom/service/impl/FCustomReportDatasetServiceImpl.java
查看文件 @
ccb8baf
...
...
@@ -15,7 +15,9 @@ import com.skua.modules.custom.vo.DepartEquipRemarkVO;
import
com.skua.modules.custom.vo.DepartWeekReportVO
;
import
com.skua.modules.custom.vo.FCustomReportDatasetVO
;
import
java.text.DecimalFormat
;
import
java.time.DayOfWeek
;
import
java.time.LocalDate
;
import
java.time.YearMonth
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.TemporalAdjusters
;
import
java.time.temporal.WeekFields
;
...
...
@@ -226,23 +228,47 @@ public class FCustomReportDatasetServiceImpl extends ServiceImpl<FCustomReportDa
*/
public
static
Map
<
String
,
String
>
getWeekDate
(
String
yearMonth
,
String
week
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
int
weekOfMonth
=
Integer
.
valueOf
(
week
);
// 输入的第几周
try
{
// 解析年月并构造本月的第一天日期
LocalDate
firstOfMonth
=
LocalDate
.
parse
(
yearMonth
+
"-01"
,
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
));
// 获取本月的第一个星期一
WeekFields
weekFields
=
WeekFields
.
of
(
Locale
.
getDefault
());
LocalDate
firstMondayOfMonth
=
firstOfMonth
.
with
(
TemporalAdjusters
.
firstInMonth
(
weekFields
.
getFirstDayOfWeek
()));
// 计算目标周的开始和结束日期
LocalDate
startOfWeek
=
firstMondayOfMonth
.
plusWeeks
(
weekOfMonth
-
1
).
plusDays
(
1
);
LocalDate
endOfWeek
=
startOfWeek
.
plusDays
(
6
);
DateTimeFormatter
dateFormatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
map
.
put
(
"start"
,
startOfWeek
.
format
(
dateFormatter
));
map
.
put
(
"end"
,
endOfWeek
.
format
(
dateFormatter
));
}
catch
(
Exception
e
)
{
map
.
put
(
"start"
,
""
);
map
.
put
(
"end"
,
""
);
// int weekOfMonth = Integer.valueOf(week); // 输入的第几周
// try {
// // 解析年月并构造本月的第一天日期
// LocalDate firstOfMonth = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
// // 获取本月的第一个星期一
// WeekFields weekFields = WeekFields.of(Locale.getDefault());
// LocalDate firstMondayOfMonth = firstOfMonth.with(TemporalAdjusters.firstInMonth(weekFields.getFirstDayOfWeek()));
// // 计算目标周的开始和结束日期
// LocalDate startOfWeek = firstMondayOfMonth.plusWeeks(weekOfMonth - 1).plusDays(1);
// LocalDate endOfWeek = startOfWeek.plusDays(6);
// DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// map.put("start", startOfWeek.format(dateFormatter));
// map.put("end", endOfWeek.format(dateFormatter));
// } catch (Exception e) {
// map.put("start", "");
// map.put("end", "");
// }
int
year
=
Integer
.
parseInt
(
yearMonth
.
split
(
"-"
)[
0
]);
int
month
=
Integer
.
parseInt
(
yearMonth
.
split
(
"-"
)[
1
]);
int
weekNumber
=
Integer
.
parseInt
(
week
);
YearMonth
yearMonth0
=
YearMonth
.
of
(
year
,
month
);
LocalDate
firstDayOfMonth
=
yearMonth0
.
atDay
(
1
);
// 计算该月第一周的开始日期
LocalDate
firstWeekStart
=
firstDayOfMonth
.
with
(
TemporalAdjusters
.
previousOrSame
(
DayOfWeek
.
MONDAY
));
// 计算指定周次的开始日期
LocalDate
startDate
=
firstWeekStart
.
plusWeeks
(
weekNumber
-
1
);
// 如果开始日期超出了该月范围,说明该月没有指定的周次
// if (startDate.getMonthValue() != month) {
// throw new IllegalArgumentException("该月没有第 " + weekNumber + " 周");
// }
// 计算结束日期
LocalDate
endDate
=
startDate
.
plusDays
(
6
);
if
(
endDate
.
getMonthValue
()
!=
month
)
{
endDate
=
yearMonth0
.
atEndOfMonth
();
}
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
String
startDateStr
=
startDate
.
format
(
formatter
);
String
endDateStr
=
endDate
.
format
(
formatter
);
map
.
put
(
"start"
,
startDateStr
);
map
.
put
(
"end"
,
endDateStr
);
return
map
;
}
//节能环保报表数据
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论