From 6587bcca676860d2f364bc0481b224a3b8e3fae8 Mon Sep 17 00:00:00 2001 From: "zhouj1203@hotmail.com" Date: Wed, 14 Aug 2024 19:14:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=89=BA=E6=9C=AF=E8=AF=84?= =?UTF-8?q?=E6=B5=8B=E7=9B=B8=E5=85=B3=E5=86=85=E5=AE=B9=20=E5=90=8D?= =?UTF-8?q?=E5=8D=95=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/ArtController.java | 4 +- .../controller/admin/service/ArtService.java | 3 +- .../admin/service/impl/ArtServiceImpl.java | 56 +++++++++----- .../model/dto/admin/common/GroupDto.java | 11 +++ .../model/dto/admin/common/RGroupList.java | 73 +++++++++++++++++++ .../model/dto/admin/common/RMember.java | 73 +++++++++++++++++++ .../java/cn/teammodel/utils/GroupUtil.java | 72 ++++++++++++++++++ src/main/resources/application.yml | 3 +- 8 files changed, 274 insertions(+), 21 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/dto/admin/common/GroupDto.java create mode 100644 src/main/java/cn/teammodel/model/dto/admin/common/RGroupList.java create mode 100644 src/main/java/cn/teammodel/model/dto/admin/common/RMember.java create mode 100644 src/main/java/cn/teammodel/utils/GroupUtil.java diff --git a/src/main/java/cn/teammodel/controller/admin/controller/ArtController.java b/src/main/java/cn/teammodel/controller/admin/controller/ArtController.java index 7d588f0..40078f3 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/ArtController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/ArtController.java @@ -33,8 +33,8 @@ public class ArtController { @PostMapping("getArtList") @ApiOperation("获取当前学校艺术评测列表") - public R> findRecords(@Valid @RequestBody ArtFindDto artFindDto) { - List res = ArtService.getArtList(artFindDto); + public R> findRecords(@Valid @RequestBody ArtFindDto artFindDto,HttpServletRequest request) { + List res = ArtService.getArtList(artFindDto,request); return R.success(res); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/ArtService.java b/src/main/java/cn/teammodel/controller/admin/service/ArtService.java index 9301dae..a57726c 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/ArtService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/ArtService.java @@ -3,9 +3,10 @@ package cn.teammodel.controller.admin.service; import cn.teammodel.model.dto.admin.art.ArtFindDto; import cn.teammodel.model.vo.admin.ArtElementsVo; +import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Map; public interface ArtService { - List getArtList(ArtFindDto artFindDto); + List getArtList(ArtFindDto artFindDto, HttpServletRequest request); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/ArtServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/ArtServiceImpl.java index 8856827..140609f 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/ArtServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/ArtServiceImpl.java @@ -3,20 +3,25 @@ package cn.teammodel.controller.admin.service.impl; import cn.teammodel.common.PK; import cn.teammodel.controller.admin.service.ArtService; import cn.teammodel.model.dto.admin.art.ArtFindDto; +import cn.teammodel.model.dto.admin.common.GroupDto; +import cn.teammodel.model.dto.admin.common.RGroupList; +import cn.teammodel.model.dto.admin.common.RMember; import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.vo.admin.ArtElementsVo; import cn.teammodel.repository.ArtRepository; import cn.teammodel.repository.ClassRepository; import cn.teammodel.repository.StudentRepository; +import cn.teammodel.utils.GroupUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import javax.servlet.http.HttpServletRequest; +import java.util.*; import java.util.stream.Collectors; - +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; @Service public class ArtServiceImpl implements ArtService { @Resource @@ -25,31 +30,48 @@ public class ArtServiceImpl implements ArtService { private ClassRepository classRepository; @Resource private StudentRepository studentRepository; + @Autowired + private Environment env; @Override - public List getArtList(ArtFindDto artFindDto) { + public List getArtList(ArtFindDto artFindDto, HttpServletRequest request) { List artElementsVos = artRepository.findPeriodById(artFindDto.getPeriodId(),"Art-"+ artFindDto.getCode()); List classIds = artElementsVos.stream() .map(ArtElementsVo::getClasses) // 正确的方法引用 .flatMap(List::stream) // 将内部列表扁平化 .collect(Collectors.toList()); - - List classes = classRepository.findAllByCodeAndIdIn("Class-"+artFindDto.getCode(),classIds); + GroupDto groupDto = new GroupDto(); + groupDto.setIds(classIds); + groupDto.setSchoolId(artFindDto.getCode()); + //List classes = classRepository.findAllByCodeAndIdIn("Class-"+artFindDto.getCode(),classIds); + Map groupId = GroupUtil.getGroupId(groupDto,new GroupUtil(env), request); + List rGroupList = new ArrayList<>(); + List rMembers = new ArrayList<>(); + for (Map.Entry entry : groupId.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + if (key.equals("groups")) { + String jsonGroups = JSON.toJSONString(value); + rGroupList = JSON.parseObject(jsonGroups, new TypeReference>() {}); + } + if (key.equals("members")) { + String jsonGroups = JSON.toJSONString(value); + rMembers = JSON.parseObject(jsonGroups, new TypeReference>() {}); + } + } try { for (ArtElementsVo artElementsVo : artElementsVos) { List classes1 = artElementsVo.getClasses(); - int stuInClassCount = 0; + //int stuInClassCount = 0; for(String classId : classes1) { - stuInClassCount += studentRepository.countByClassIdAndCode(classId, String.format(PK.STUDENT, artFindDto.getCode())); + //stuInClassCount += studentRepository.countByClassIdAndCode(classId, String.format(PK.STUDENT, artFindDto.getCode())); ArtElementsVo.ClassInfos classInfos = new ArtElementsVo.ClassInfos(); - Optional className = classes.stream() - .filter(classInfo -> classInfo.getId().equals(classId)) - .map(ClassInfo::getName) - .findFirst(); - classInfos.setId(classId); - classInfos.setName(className.orElse("No Class Name")); + rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().ifPresent(rGroupList1 -> { + classInfos.setId(rGroupList1.getId()); + classInfos.setName(rGroupList1.getName()); + }); artElementsVo.addClassesInfos(classInfos); } - artElementsVo.setCount(stuInClassCount); + artElementsVo.setCount(rMembers.size()); } } catch (Exception e) { diff --git a/src/main/java/cn/teammodel/model/dto/admin/common/GroupDto.java b/src/main/java/cn/teammodel/model/dto/admin/common/GroupDto.java new file mode 100644 index 0000000..ac703fd --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/admin/common/GroupDto.java @@ -0,0 +1,11 @@ +package cn.teammodel.model.dto.admin.common; + +import lombok.Data; + +import java.util.List; + +@Data +public class GroupDto { + public List ids; + public String schoolId; +} diff --git a/src/main/java/cn/teammodel/model/dto/admin/common/RGroupList.java b/src/main/java/cn/teammodel/model/dto/admin/common/RGroupList.java new file mode 100644 index 0000000..608c22c --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/admin/common/RGroupList.java @@ -0,0 +1,73 @@ +package cn.teammodel.model.dto.admin.common; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +@Data +public class RGroupList { + public String id ; + public String code ; + public String pk ; + public String name ; + //标记该名单唯一code + public String no ; + public String periodId ; + //课程id,需要标记则标记 + //public String courseId ; + public String scope ; + public String school ; + public String creatorId ; + /// + ///研修培训名单,yxtrain 教学班teach ,行政班(学生搜寻classId动态返回)class ,教研组research,学科组(学科搜寻动态返回)subject,好友friend,管理manage,群组group等,"activity", + ///TeacherAll 全体教师,StudentAll全体学生 TchStuAll,全体师生 动态返回 + /// + public String type ; + public int year ; + /// + /// 名单过期时间。 + /// + public long expire ; + /// + /// 醍摩豆id成员数量 + /// + public int tcount ; + /// + /// 校内账号成员数量 + /// + public int scount ; + public List members = new ArrayList<>(); + public String leader ; + public int froms ; + /// + /// 个人名单是否开放 加入。0 不允许,1 允许。 + /// + public int joinLock ; + /// + ///补充毕业0在校,1毕业 + /// + public int graduate ; + /// + /// 是否开启审核,0未开启,1开启。 + /// + public int review ; + /// + /// 加入人数200人,学生加入已满200 自动关闭加入。可手动解除限制,开启审核时,关闭人数上限设置机制 + /// + public int limitCount ; + /// + /// 自选座号 0 不允许,1 运行 + /// + public int optNo ; + /// + /// 二维码过期时间 + /// + public long qrcodeExpire ; + /// + /// 二维码 天数 + /// + public int qrcodeDays ; + public HashSet grades = new HashSet(); + +} diff --git a/src/main/java/cn/teammodel/model/dto/admin/common/RMember.java b/src/main/java/cn/teammodel/model/dto/admin/common/RMember.java new file mode 100644 index 0000000..1046532 --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/admin/common/RMember.java @@ -0,0 +1,73 @@ +package cn.teammodel.model.dto.admin.common; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; +@Data +public class RMember { + + /// + /// 账号id + /// + public String id ; + //学生所在的学校 + public String code ; + //兼容HiTeach 需要的字段 + public String schoolId ; + + //学生所在的学校 + public String schoolName ; + /// + /// 名称 + /// + public String name ; + /// + ///类型 1 tmdid,2 student + /// + public int type ; + /// + /// 头像 + /// + public String picture ; + + /// + /// 性别 M( male,男) F (female 女) N(secret 保密) + /// + public String gender ; + /// + ///座号 + /// + public String no ; + /// + /// IRS WebIRS编号。 + /// + public String irs ; + public String tag ; + /// + /// 行政班 + /// + public String classId ; + /// + /// 名单分组id + /// + public String groupId ; + /// + /// 名单分组名称 + /// + public String groupName ; + public String nickname ; + //补充毕业 + //0在校,1毕业 + public int graduate ; + //所在名单集合 + public List groupListIds = new ArrayList(); + public int year ; + public String periodId ; + /// + /// 0 自动的座号和irs,1 手动的irs + /// + public int manual ; + + +} diff --git a/src/main/java/cn/teammodel/utils/GroupUtil.java b/src/main/java/cn/teammodel/utils/GroupUtil.java new file mode 100644 index 0000000..a4d8c6f --- /dev/null +++ b/src/main/java/cn/teammodel/utils/GroupUtil.java @@ -0,0 +1,72 @@ +package cn.teammodel.utils; + +import cn.teammodel.model.dto.admin.common.GroupDto; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.core.env.Environment; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class GroupUtil { + + private final Environment env; + + public GroupUtil(Environment env) { + this.env = env; + } + public static Map getGroupId(GroupDto dto, GroupUtil groupUtil, HttpServletRequest request) { + Map mapper = new HashMap<>(); + String apiUrl = groupUtil.env.getProperty("ies.server-url-group"); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + // 创建HttpPost对象 + HttpPost httpPost = new HttpPost(apiUrl); + + //添加请求头 + httpPost.setHeader("Authorization", request.getHeader("Authorization")); + httpPost.setHeader("X-Auth-Authtoken", request.getHeader("X-Auth-Authtoken")); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-Type", "application/json; charset=utf-8"); + + // 设置请求体 + //JsonUtil.convertToJson(dto); + //String requestBody = String.format("{\"school\":\"%s\"}","{\"name\":\"%s\"}","{\"periodId\":\"%s\"}", code,name,periodId); + httpPost.setEntity(new StringEntity(JsonUtil.convertToJson(dto))); + + // 发送请求 + try (CloseableHttpResponse response = httpClient.execute(httpPost)) { + // 获取响应实体 + HttpEntity entity = response.getEntity(); + + if (entity != null) { + // 解析响应内容 + String jsonString = EntityUtils.toString(entity); + ObjectMapper objectMapper = new ObjectMapper(); + mapper = objectMapper.readValue(jsonString, TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class)); + } + + // 检查响应状态码 + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) throw new RuntimeException("Failed : HTTP error code : " + statusCode); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } + return mapper; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 038d823..0123999 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -61,4 +61,5 @@ ding: server-url: https://oapi.dingtalk.com/robot/send?access_token=32d9b24f69c2c4fd7c2dab43268b6258a7214d2620e0805d7b6d1429003b64b6 #IES 课堂记录 ies: - server-url: https://www.teammodel.cn/common/lesson-record/get-lesson-record \ No newline at end of file + server-url: https://www.teammodel.cn/common/lesson-record/get-lesson-record + server-url-group: https://www.teammodel.cn/grouplist/get-members-listids \ No newline at end of file