|
@@ -0,0 +1,57 @@
|
|
|
+package com.example.nngkxxdp.controller;
|
|
|
+
|
|
|
+import com.example.nngkxxdp.util.BaseResult;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.time.DayOfWeek;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/qjt")
|
|
|
+public class QjingtController {
|
|
|
+
|
|
|
+ @GetMapping
|
|
|
+ public BaseResult isWeekend() {
|
|
|
+ ArrayList<Object> num = new ArrayList<>();
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalTime now = LocalTime.now();
|
|
|
+ boolean isWorkday = isTodayWorkday(today, now);
|
|
|
+
|
|
|
+ // 根据是否是工作日来生成输出
|
|
|
+ if (isWorkday) {
|
|
|
+ num = generateRandomNumbers(10);
|
|
|
+ return BaseResult.ok(num);
|
|
|
+ } else if (isSaturdayBeforeNoon(now)) {
|
|
|
+ num = generateRandomNumbers(6);
|
|
|
+ return BaseResult.ok(num);
|
|
|
+ } else {
|
|
|
+ num.add(0);
|
|
|
+ num.add(0);
|
|
|
+ return BaseResult.ok(num);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isTodayWorkday(LocalDate date, LocalTime time) {
|
|
|
+ DayOfWeek dayOfWeek = date.getDayOfWeek();
|
|
|
+ return !(dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isSaturdayBeforeNoon(LocalTime time) {
|
|
|
+ return time.isBefore(LocalTime.of(12, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<Object> generateRandomNumbers(int upperBound) {
|
|
|
+ ArrayList<Object> num = new ArrayList<>();
|
|
|
+ Random random = new Random();
|
|
|
+ int num1 = random.nextInt(upperBound); // 生成0到upperBound-1之间的随机数
|
|
|
+ int num2 = random.nextInt(upperBound); // 再次生成0到upperBound-1之间的随机数
|
|
|
+ num.add(num1);
|
|
|
+ num.add(num2);
|
|
|
+ return num;
|
|
|
+ }
|
|
|
+}
|