From db6c7d402f5253cda22ff4f4a13f1f75fd4a7a98 Mon Sep 17 00:00:00 2001 From: "zhouj1203@hotmail.com" Date: Thu, 8 Aug 2024 15:13:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=82=E6=95=B0=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E6=96=B9=E5=BC=8F=EF=BC=8C=E8=B0=83=E6=95=B4=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=A7=A3=E6=9E=90=E5=86=85=E5=AE=B9=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6Dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminDutyController.java | 4 ++-- .../admin/service/AdminIndexDutyService.java | 2 +- .../impl/AdminIndexDutyServiceImpl.java | 14 +++++++----- .../model/dto/weekDuty/LessonRecordDto.java | 22 ++++++++++++++----- .../java/cn/teammodel/utils/JsonUtil.java | 22 +++++++++++++++++++ 5 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 src/main/java/cn/teammodel/utils/JsonUtil.java diff --git a/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java b/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java index 7a1ce27..b240877 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java @@ -73,8 +73,8 @@ public class AdminDutyController { } @PostMapping("getLessonRecord") @ApiOperation("获取课堂记录") - public R > appraiseNodeRank(@Valid @RequestBody Map map , HttpServletRequest request) { - Map res = adminIndexDutyService.getLessonRecord(map,request); + public R > appraiseNodeRank(@Valid @RequestBody LessonRecordDto lessonRecordDto , HttpServletRequest request) { + Map res = adminIndexDutyService.getLessonRecord(lessonRecordDto,request); return R.success(res); } } diff --git a/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java b/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java index f5721bc..05959b8 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java @@ -24,6 +24,6 @@ public interface AdminIndexDutyService { List appraiseNodeRank(TimeRangeDto timeRangeDto); - Map getLessonRecord (Map map, HttpServletRequest request); + Map getLessonRecord (LessonRecordDto lessonRecordDto, HttpServletRequest request); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java index 29e98af..715acba 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java @@ -21,6 +21,7 @@ import cn.teammodel.repository.DutyRecordRepository; import cn.teammodel.repository.SchoolRepository; import cn.teammodel.repository.TeacherRepository; import cn.teammodel.security.utils.SecurityUtil; +import cn.teammodel.utils.JsonUtil; import cn.teammodel.utils.SchoolDateUtil; import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; import com.fasterxml.jackson.databind.ObjectMapper; @@ -73,13 +74,13 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService { private ClassRepository classRepository; @Resource private DutyRecordRepository dutyRecordRepository; - - private final Environment env; - @Autowired + private Environment env; + + /* @Autowired public AdminIndexDutyServiceImpl(Environment env) { this.env = env; - } + }*/ @Override public DutyIndexData getIndexData(String periodId) { @@ -224,7 +225,7 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService { } @Override - public Map getLessonRecord(Map map, HttpServletRequest request) { + public Map getLessonRecord(LessonRecordDto lessonRecordDto, HttpServletRequest request) { Map mapper = new HashMap<>(); String apiUrl = env.getProperty("ies.server-url"); @@ -240,8 +241,9 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService { httpPost.setHeader("Content-Type", "application/json; charset=utf-8"); // 设置请求体 + JsonUtil.convertToJson(lessonRecordDto); //String requestBody = String.format("{\"school\":\"%s\"}","{\"name\":\"%s\"}","{\"periodId\":\"%s\"}", code,name,periodId); - httpPost.setEntity(new StringEntity(new Gson().toJson(map))); + httpPost.setEntity(new StringEntity(JsonUtil.convertToJson(lessonRecordDto))); // 发送请求 try (CloseableHttpResponse response = httpClient.execute(httpPost)) { diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/LessonRecordDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/LessonRecordDto.java index fd7e336..1e4140e 100644 --- a/src/main/java/cn/teammodel/model/dto/weekDuty/LessonRecordDto.java +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/LessonRecordDto.java @@ -2,14 +2,26 @@ package cn.teammodel.model.dto.weekDuty; import lombok.Data; +import java.util.ArrayList; + @Data public class LessonRecordDto { - private String code; + private String tmdid; + private String scope; + private String school; private String name; private String periodId; - private Long startTime; - private Long endTime; - private String Authorization; - private String AuthToken; + private Long stime; + private Long etime; + private ArrayList category; + private ArrayList subjectId; + private ArrayList grade; + private boolean doubleGreen = false; + private boolean singleGreen = false; + private boolean isOk = false; + private boolean quality = false; + private String DESC = "startTime"; + private int pageCount; private String continuationToken; + private boolean managePage = true; } diff --git a/src/main/java/cn/teammodel/utils/JsonUtil.java b/src/main/java/cn/teammodel/utils/JsonUtil.java new file mode 100644 index 0000000..ba0a3df --- /dev/null +++ b/src/main/java/cn/teammodel/utils/JsonUtil.java @@ -0,0 +1,22 @@ +package cn.teammodel.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonUtil { + private static final ObjectMapper objectMapper = new ObjectMapper(); + + /** + * Converts an object to a JSON string. + * + * @param obj The object to be converted. + * @return The JSON string representation of the object. + */ + public static String convertToJson(Object obj) { + try { + return objectMapper.writeValueAsString(obj); + } catch (JsonProcessingException e) { + throw new RuntimeException("Failed to convert object to JSON", e); + } + } +}