AlgScheduleFetchResponseDTO.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.usky.ai.dto;
  2. import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  3. import com.fasterxml.jackson.annotation.JsonProperty;
  4. import lombok.Data;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. @Data
  8. @JsonIgnoreProperties(ignoreUnknown = true)
  9. public class AlgScheduleFetchResponseDTO {
  10. @JsonProperty("BoardIp")
  11. private String boardIp;
  12. @JsonProperty("BoardId")
  13. private String boardId;
  14. @JsonProperty("Event")
  15. private String event = "/alg_schedule_fetch";
  16. @JsonProperty("Result")
  17. private Result result;
  18. @JsonProperty("Content")
  19. private List<Schedule> content;
  20. public boolean isSuccess() {
  21. return result != null && result.getCode() == 0;
  22. }
  23. private long time = System.currentTimeMillis();
  24. @Data
  25. @JsonIgnoreProperties(ignoreUnknown = true)
  26. public static class Result {
  27. @JsonProperty("Code") //0成功/其他失败
  28. private int code;
  29. @JsonProperty("Content")
  30. private List<Schedule> content; // Content 属性在 Result 中
  31. @JsonProperty("Desc")
  32. private String desc;
  33. }
  34. @Data
  35. @JsonIgnoreProperties(ignoreUnknown = true)
  36. public static class Schedule {
  37. @JsonProperty("Id")
  38. private int id;
  39. @JsonProperty("Name")
  40. private String name;
  41. @JsonProperty("Summary")
  42. private String summary;
  43. @JsonProperty("Value")
  44. private String value;
  45. public List<String> getReadableTimePeriods() {
  46. List<String> timePeriods = new ArrayList<>();
  47. char[] binaryValue = value.toCharArray();
  48. String[] days = {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日",};
  49. // 检查 Value 字段的长度是否正确
  50. if (binaryValue.length != 336) {
  51. //System.err.println("Value 字段长度不正确,预期长度为 336,实际长度为 " + binaryValue.length);
  52. return timePeriods; // 如果长度不足,返回空列表
  53. }
  54. for (int day = 0; day < 7; day++) {
  55. StringBuilder dayPeriods = new StringBuilder();
  56. boolean inPeriod = false;
  57. int startHour = -1;
  58. int startMinute = -1;
  59. for (int halfHour = 0; halfHour < 48; halfHour++) {
  60. int hour = halfHour / 2;
  61. int minute = (halfHour % 2) * 30;
  62. int index = day * 48 + halfHour;
  63. if (index < binaryValue.length && binaryValue[index] == '1') {
  64. if (!inPeriod) {
  65. inPeriod = true;
  66. startHour = hour;
  67. startMinute = minute;
  68. }
  69. } else {
  70. if (inPeriod) {
  71. inPeriod = false;
  72. dayPeriods.append(String.format("%02d:%02d~%02d:%02d", startHour, startMinute, hour, minute)).append(", ");
  73. }
  74. }
  75. }
  76. if (inPeriod) {
  77. int hour = 23;
  78. int minute = 30;
  79. dayPeriods.append(String.format("%02d:%02d~%02d:%02d", startHour, startMinute, hour, minute)).append(", ");
  80. }
  81. if (dayPeriods.length() > 0) {
  82. timePeriods.add(days[day] + " " + dayPeriods.toString().trim().replaceAll(", $", ""));
  83. }
  84. }
  85. System.out.println("Readable time periods: " + timePeriods);
  86. return timePeriods;
  87. }
  88. }
  89. }