Browse Source

学生成绩

dzx 4 months ago
parent
commit
002f38873b

+ 3 - 3
src/main/java/com/xjrsoft/module/base/service/impl/WhitelistManagementServiceImpl.java

@@ -125,10 +125,10 @@ public class WhitelistManagementServiceImpl extends MPJBaseServiceImpl<Whitelist
                 continue;
             }
 
-            String name = this.GetName(vo.get(0).toString());
-            String credentialNumber = this.GetCredentialNumber(vo.get(1).toString());
+            String name = vo.get(0).toString();
+            String credentialNumber = vo.get(1).toString();
             Long userId = this.getUserId(credentialNumber);
-            String phone = this.GetPhone(vo.get(2).toString());
+            String phone = vo.get(2).toString();
 
             if (!name.isEmpty() && !credentialNumber.isEmpty() && !phone.isEmpty()) {
                 WhitelistManagement whitelistManagement = new WhitelistManagement();

+ 49 - 0
src/main/java/com/xjrsoft/module/job/ExamScoreDataTask.java

@@ -0,0 +1,49 @@
+package com.xjrsoft.module.job;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.xjrsoft.module.base.service.IBaseCourseSubjectService;
+import com.xjrsoft.module.xycxedu.service.IExamSubjectScoreService;
+import com.xjrsoft.module.xycxedu.service.IXycxeduExamListService;
+import com.xjrsoft.module.xycxedu.util.DataUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author dzx
+ * @date 2024/5/8
+ */
+@Component
+@Slf4j
+public class ExamScoreDataTask {
+
+    @Autowired
+    private IXycxeduExamListService examListService;
+
+    @Autowired
+    private IExamSubjectScoreService scoreService;
+
+    @Autowired
+    private IBaseCourseSubjectService courseService;
+    @Scheduled(cron = "0 */15 * * * ?")
+    public void RefreshConnectionPool() {
+        String active = SpringUtil.getActiveProfile();
+        if(!"prod".equals(active)){
+            log.info("非正式环境,无法执行数据推送");
+            return;
+        }
+        doExecute();
+    }
+
+    void doExecute(){
+        //同步考试计划数据
+        DataUtil dataUtil = new DataUtil();
+        dataUtil.examListData(examListService);
+
+        //同步成绩
+        dataUtil.studentScoreData(examListService, scoreService, courseService);
+    }
+
+
+}

+ 97 - 0
src/main/java/com/xjrsoft/module/xycxedu/entity/ExamSubjectScore.java

@@ -0,0 +1,97 @@
+package com.xjrsoft.module.xycxedu.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+
+/**
+* @title: 考试科目成绩表
+* @Author dzx
+* @Date: 2024年7月18日
+* @Version 1.0
+*/
+@Data
+@TableName("exam_subject_score")
+@ApiModel(value = "考试科目成绩表", description = "考试科目成绩表")
+public class ExamSubjectScore implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    @ApiModelProperty("主键")
+    @TableId
+    private Long id;
+
+    @ApiModelProperty("创建人")
+    @TableField(fill = FieldFill.INSERT)
+    private Long createUserId;
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty("创建时间")
+    @TableField(fill = FieldFill.INSERT)
+    private Date createDate;
+
+    @ApiModelProperty("修改人")
+    @TableField(fill = FieldFill.UPDATE)
+    private Long modifyUserId;
+    /**
+    * 修改时间
+    */
+    @ApiModelProperty("修改时间")
+    @TableField(fill = FieldFill.UPDATE)
+    private Date modifyDate;
+
+    @ApiModelProperty("删除标记")
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer deleteMark;
+    /**
+     * 有效标志
+     */
+    @ApiModelProperty("有效标志")
+    @TableField(fill = FieldFill.INSERT)
+    private Integer enabledMark;
+
+    /**
+    * 学期id
+    */
+    @ApiModelProperty("学期id")
+    private Long semesterId;
+    /**
+    * 考试计划名称
+    */
+    @ApiModelProperty("考试计划名称")
+    private String milexamname;
+    /**
+    * 考试计划id
+    */
+    @ApiModelProperty("考试计划id")
+    private Long milexamid;
+
+    @ApiModelProperty("课程科目id(base_course_subject)")
+    private Long courseSubjectId;
+
+    @ApiModelProperty("课程名称")
+    private String coursename;
+
+    @ApiModelProperty("学生id(xjr_user)")
+    private Long userId;
+
+    @ApiModelProperty("分数")
+    private Integer score;
+
+    @ApiModelProperty("班级排名")
+    private Integer classRanking;
+
+    @ApiModelProperty("年级排名")
+    private Integer gradeRanking;
+
+}

+ 65 - 0
src/main/java/com/xjrsoft/module/xycxedu/entity/XycxeduExamList.java

@@ -0,0 +1,65 @@
+package com.xjrsoft.module.xycxedu.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+import java.util.Date;
+
+
+/**
+* @title: 晓羊策学考试计划表
+* @Author dzx
+* @Date: 2024年7月18日
+* @Version 1.0
+*/
+@Data
+@TableName("xycxedu_exam_list")
+@ApiModel(value = "晓羊策学考试计划表", description = "晓羊策学考试计划表")
+public class XycxeduExamList implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+    @ApiModelProperty("主键")
+    @TableId
+    private Long id;
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty("首次推送时间")
+    @TableField(fill = FieldFill.INSERT)
+    private Date createDate;
+    /**
+    * 修改时间
+    */
+    @ApiModelProperty("修改时间")
+    @TableField(fill = FieldFill.UPDATE)
+    private Date modifyDate;
+    /**
+    * 表名
+    */
+    @ApiModelProperty("考试计划id")
+    private Long milexamid;
+    /**
+    * 英文姓名
+    */
+    @ApiModelProperty("考试计划名称")
+    private String milexamname;
+    /**
+    * 姓名拼音
+    */
+    @ApiModelProperty("学年")
+    private Integer regyear;
+
+    @ApiModelProperty("年级名称")
+    private String grade;
+
+    @ApiModelProperty("考试时间")
+    private LocalDate sdate;
+
+}

+ 18 - 0
src/main/java/com/xjrsoft/module/xycxedu/mapper/ExamSubjectScoreMappper.java

@@ -0,0 +1,18 @@
+package com.xjrsoft.module.xycxedu.mapper;
+
+import com.github.yulichang.base.MPJBaseMapper;
+import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+* @title: 晓羊策学考试计划表
+* @Author dzx
+* @Date: 2024年7月18日
+* @Version 1.0
+*/
+@Mapper
+public interface ExamSubjectScoreMappper extends MPJBaseMapper<ExamSubjectScore> {
+
+    Long getUserIdByIdNumber(@Param("idNumber") String idNumber);
+}

+ 16 - 0
src/main/java/com/xjrsoft/module/xycxedu/mapper/XycxeduExamListMappper.java

@@ -0,0 +1,16 @@
+package com.xjrsoft.module.xycxedu.mapper;
+
+import com.github.yulichang.base.MPJBaseMapper;
+import com.xjrsoft.module.xycxedu.entity.XycxeduExamList;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @title: 晓羊策学考试计划表
+* @Author dzx
+* @Date: 2024年7月18日
+* @Version 1.0
+*/
+@Mapper
+public interface XycxeduExamListMappper extends MPJBaseMapper<XycxeduExamList> {
+
+}

+ 16 - 0
src/main/java/com/xjrsoft/module/xycxedu/service/IExamSubjectScoreService.java

@@ -0,0 +1,16 @@
+package com.xjrsoft.module.xycxedu.service;
+
+import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
+
+/**
+ * @title: 晓羊策学考试计划表
+ * @Author dzx
+ * @Date: 2024年7月18日
+ * @Version 1.0
+*/
+
+public interface IExamSubjectScoreService extends MPJBaseService<ExamSubjectScore> {
+
+    Long getUserIdByIdNumber(String idNumber);
+}

+ 15 - 0
src/main/java/com/xjrsoft/module/xycxedu/service/IXycxeduExamListService.java

@@ -0,0 +1,15 @@
+package com.xjrsoft.module.xycxedu.service;
+
+import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.xycxedu.entity.XycxeduExamList;
+
+/**
+ * @title: 晓羊策学考试计划表
+ * @Author dzx
+ * @Date: 2024年7月18日
+ * @Version 1.0
+*/
+
+public interface IXycxeduExamListService extends MPJBaseService<XycxeduExamList> {
+
+}

+ 23 - 0
src/main/java/com/xjrsoft/module/xycxedu/service/impl/ExamSubjectScoreServiceImpl.java

@@ -0,0 +1,23 @@
+package com.xjrsoft.module.xycxedu.service.impl;
+
+import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
+import com.xjrsoft.module.xycxedu.mapper.ExamSubjectScoreMappper;
+import com.xjrsoft.module.xycxedu.service.IExamSubjectScoreService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * @title: 晓羊策学考试计划表
+ * @Author dzx
+ * @Date: 2024年7月18日
+ * @Version 1.0
+*/
+@Service
+@AllArgsConstructor
+public class ExamSubjectScoreServiceImpl extends MPJBaseServiceImpl<ExamSubjectScoreMappper, ExamSubjectScore> implements IExamSubjectScoreService {
+    @Override
+    public Long getUserIdByIdNumber(String idNumber) {
+        return this.getUserIdByIdNumber(idNumber);
+    }
+}

+ 19 - 0
src/main/java/com/xjrsoft/module/xycxedu/service/impl/XycxeduExamListServiceImpl.java

@@ -0,0 +1,19 @@
+package com.xjrsoft.module.xycxedu.service.impl;
+
+import com.github.yulichang.base.MPJBaseServiceImpl;
+import com.xjrsoft.module.xycxedu.entity.XycxeduExamList;
+import com.xjrsoft.module.xycxedu.mapper.XycxeduExamListMappper;
+import com.xjrsoft.module.xycxedu.service.IXycxeduExamListService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * @title: 晓羊策学考试计划表
+ * @Author dzx
+ * @Date: 2024年7月18日
+ * @Version 1.0
+*/
+@Service
+@AllArgsConstructor
+public class XycxeduExamListServiceImpl extends MPJBaseServiceImpl<XycxeduExamListMappper, XycxeduExamList> implements IXycxeduExamListService {
+}

+ 57 - 0
src/main/java/com/xjrsoft/module/xycxedu/util/ApiUtil.java

@@ -0,0 +1,57 @@
+package com.xjrsoft.module.xycxedu.util;
+
+import cn.hutool.http.HttpUtil;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author dzx
+ * @date 2024/7/17
+ */
+@Slf4j
+public class ApiUtil {
+
+    private final static int schoolid = 189;
+    private final static String sign = "888";
+    private final static String accessid = "86a5d02ae9f78470";
+
+    private final static String host = "https://openapi.xycxedu.com";
+
+
+    public static JsonArray getExamList() {
+        String url = host + "/exam/list?schoolid=" + schoolid + "&accessid=" + accessid + "&sign=" + sign;
+        String result = HttpUtil.get(url);
+        JsonParser parser = new JsonParser();
+        JsonObject asJsonObject = parser.parse(result).getAsJsonObject();
+        JsonArray jsonArray = asJsonObject.get("data").getAsJsonArray();
+        return jsonArray;
+    }
+
+    public static JsonArray getStudentScoreByCourse(Integer examid) {
+        long timeMillis = System.currentTimeMillis();
+        String url = host + "/exam/totalscore?schoolid=" + schoolid + "&accessid=" + accessid + "&sign=" + sign + "&examid=" + examid + "&timestamp=" + timeMillis;
+        String result = HttpUtil.get(url);
+        JsonParser parser = new JsonParser();
+        JsonObject asJsonObject = parser.parse(result).getAsJsonObject();
+        JsonArray jsonArray = asJsonObject.get("data").getAsJsonArray();
+        return jsonArray;
+    }
+
+    /**
+     * 根据考试id获取考试下的科目信息
+     * @param milexamid
+     * @return
+     */
+    public static JsonArray getCourseByExam(Long milexamid) {
+        long timeMillis = System.currentTimeMillis();
+        String url = host + "/exam/course?schoolid=" + schoolid + "&accessid=" + accessid + "&sign=" + sign + "&milexamid=" + milexamid + "&timestamp=" + timeMillis;
+        String result = HttpUtil.get(url);
+        JsonParser parser = new JsonParser();
+        JsonObject asJsonObject = parser.parse(result).getAsJsonObject();
+        JsonArray jsonArray = asJsonObject.get("data").getAsJsonArray();
+        return jsonArray;
+    }
+
+}

+ 116 - 0
src/main/java/com/xjrsoft/module/xycxedu/util/DataUtil.java

@@ -0,0 +1,116 @@
+package com.xjrsoft.module.xycxedu.util;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.xjrsoft.module.base.entity.BaseCourseSubject;
+import com.xjrsoft.module.base.service.IBaseCourseSubjectService;
+import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
+import com.xjrsoft.module.xycxedu.entity.XycxeduExamList;
+import com.xjrsoft.module.xycxedu.service.IExamSubjectScoreService;
+import com.xjrsoft.module.xycxedu.service.IXycxeduExamListService;
+import com.yomahub.liteflow.util.JsonUtil;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author dzx
+ * @date 2024/7/17
+ */
+public class DataUtil {
+
+    /**
+     * 同步考试计划信息
+     * @param examListService
+     */
+    public void examListData(IXycxeduExamListService examListService){
+        JsonArray examList = ApiUtil.getExamList();
+        List<XycxeduExamList> updateList = new ArrayList<>();
+        List<XycxeduExamList> insertList = new ArrayList<>();
+        Date date = new Date();
+        for (JsonElement jsonElement : examList) {
+            XycxeduExamList parseObject = JsonUtil.parseObject(jsonElement.toString(), XycxeduExamList.class);
+            XycxeduExamList oldData = examListService.getOne(
+                    new QueryWrapper<XycxeduExamList>().lambda()
+                            .eq(XycxeduExamList::getMilexamid, parseObject.getMilexamid())
+            );
+            if(oldData != null){
+                BeanUtil.copyProperties(parseObject, oldData);
+                oldData.setModifyDate(date);
+                updateList.add(oldData);
+                continue;
+            }
+
+            parseObject.setCreateDate(date);
+            insertList.add(parseObject);
+        }
+        if(!updateList.isEmpty()){
+            examListService.updateBatchById(updateList);
+        }
+        if(!insertList.isEmpty()){
+            examListService.saveBatch(insertList);
+        }
+    }
+
+    public void studentScoreData(IXycxeduExamListService examListService, IExamSubjectScoreService scoreService, IBaseCourseSubjectService courseService){
+        //  查询出所有的考试计划
+        List<XycxeduExamList> list = examListService.list(
+                new QueryWrapper<XycxeduExamList>().lambda()
+        );
+        Map<Integer, Integer> examidXMilexamidMap = new HashMap<>();//存考试下的科目id和考试id关系
+        Map<Integer, String> examidXCoursenameMap = new HashMap<>();
+        for (XycxeduExamList el : list) {
+            // 根据考试计划,查询出所有科目信息
+            JsonArray courseByExam = ApiUtil.getCourseByExam(el.getMilexamid());
+            for (JsonElement jsonElement : courseByExam) {
+                JsonObject courseObj = jsonElement.getAsJsonObject();
+                examidXMilexamidMap.put(courseObj.get("examid").getAsInt(), courseObj.get("milexamid").getAsInt());
+                examidXCoursenameMap.put(courseObj.get("examid").getAsInt(), courseObj.get("coursename").getAsString());
+            }
+        }
+        Map<String, Long> courseMap = courseService.list().stream().collect(
+                Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId)
+        );
+
+        List<ExamSubjectScore> insertList = new ArrayList<>();
+        Date date = new Date();
+        // 查询每次考试每个科目的学生的成绩
+        for (Integer examid : examidXMilexamidMap.keySet()) {
+            JsonArray jsonArray = ApiUtil.getStudentScoreByCourse(examid);
+            for (JsonElement jsonElement : jsonArray) {
+                JsonObject scoreObj = jsonElement.getAsJsonObject();
+                Long userId = scoreService.getUserIdByIdNumber(scoreObj.get("stunum").getAsString());
+
+                long count = scoreService.count(
+                        new QueryWrapper<ExamSubjectScore>().lambda()
+                                .eq(ExamSubjectScore::getUserId, userId)
+                                .eq(ExamSubjectScore::getCourseSubjectId, courseMap.get(examidXCoursenameMap.get(examid)))
+                                .eq(ExamSubjectScore::getMilexamid, examidXMilexamidMap.get(examid).longValue())
+                );
+                if(count > 0){
+                    continue;
+                }
+                ExamSubjectScore score = new ExamSubjectScore() {{
+                    setUserId(userId);
+                    setScore(scoreObj.get("score").getAsInt());
+                    setMilexamid(examidXMilexamidMap.get(examid).longValue());
+                    setGradeRanking(scoreObj.get("gradeorder").getAsInt());
+                    setCoursename(examidXCoursenameMap.get(examid));
+                    setCourseSubjectId(courseMap.get(examidXCoursenameMap.get(examid)));
+                    setCreateDate(date);
+                }};
+                insertList.add(score);
+            }
+        }
+        if(!insertList.isEmpty()){
+            scoreService.saveBatch(insertList);
+        }
+    }
+}

+ 9 - 0
src/main/resources/mapper/xycxedu/ExamSubjectScoreMappper.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.xjrsoft.module.xycxedu.mapper.ExamSubjectScoreMappper">
+    <select id="getUserIdByIdNumber" resultType="java.lang.Long">
+        SELECT id FROM xjr_user WHERE credential_number = #{idNumber}
+    </select>
+</mapper>

+ 41 - 0
src/test/java/com/xjrsoft/module/xycxedu/util/ApiUtilTest.java

@@ -0,0 +1,41 @@
+package com.xjrsoft.module.xycxedu.util;
+
+import cn.hutool.http.HttpUtil;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author dzx
+ * @date 2024/7/18
+ */
+class ApiUtilTest {
+    private final static int schoolid = 189;
+    private final static String sign = "888";
+    private final static String accessid = "86a5d02ae9f78470";
+
+    private final static String host = "https://openapi.xycxedu.com";
+    @Test
+    void test() throws IOException {
+        String url = host + "/exam/list?schoolid=" + schoolid + "&accessid=" + accessid + "&sign=" + sign;
+        String s = HttpUtil.get(url);
+        Document doc = Jsoup.connect(url).get();
+        Elements titles = doc.select("pre");
+        Element firstTitle = titles.first();
+        System.out.println(firstTitle.toString());
+    }
+
+    @Test
+    void test1() throws IOException {
+        String url = host + "/exam/list?schoolid=" + schoolid + "&accessid=" + accessid + "&sign=" + sign;
+        String s = HttpUtil.get(url);
+
+        System.out.println(s);
+    }
+}