From a4855dabaa525b8a780dbeaaff5a0c7ac91b0863 Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期二, 18 六月 2024 15:18:23 +0800
Subject: [PATCH] 教学资源,随序试卷生成简化
---
src/main/resources/mapper/EducationResourceMapper.xml | 87 ++++++++++
src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java | 98 ++++++++++++
src/main/java/com/ycl/jxkg/mapper/EducationResourceMapper.java | 27 +++
src/main/java/com/ycl/jxkg/service/EducationResourceService.java | 40 +++++
src/main/java/com/ycl/jxkg/controller/admin/EducationResourceController.java | 44 +++++
src/main/java/com/ycl/jxkg/domain/entity/EducationResource.java | 38 ++++
src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java | 64 ++++++++
src/main/java/com/ycl/jxkg/domain/vo/student/education/StudentOnlineVO.java | 22 ++
src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java | 18 --
9 files changed, 422 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/controller/admin/EducationResourceController.java b/src/main/java/com/ycl/jxkg/controller/admin/EducationResourceController.java
new file mode 100644
index 0000000..249eba6
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/controller/admin/EducationResourceController.java
@@ -0,0 +1,44 @@
+package com.ycl.jxkg.controller.admin;
+
+import com.ycl.jxkg.base.Result;
+import com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO;
+import com.ycl.jxkg.service.EducationResourceService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+
+/**
+ * @author锛歺p
+ * @date锛�2024/5/16 10:58
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping(value = "/api/admin/education/resource")
+public class EducationResourceController {
+
+ private final EducationResourceService service;
+
+ @PostMapping
+ public Result add(@RequestBody @Validated EducationResourceVO form) {
+ return service.add(form);
+ }
+
+ @PostMapping("/edit")
+ public Result edit(@RequestBody @Validated EducationResourceVO form) {
+ return service.update(form);
+ }
+
+ @PostMapping("/remove")
+ public Result remove(@RequestBody @NotEmpty(message = "璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁") List<Integer> ids) {
+ return service.remove(ids);
+ }
+
+ @GetMapping("/page")
+ public Result page(EducationResourceVO query) {
+ return service.page(query);
+ }
+
+}
diff --git a/src/main/java/com/ycl/jxkg/domain/entity/EducationResource.java b/src/main/java/com/ycl/jxkg/domain/entity/EducationResource.java
new file mode 100644
index 0000000..ea6b7dc
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/domain/entity/EducationResource.java
@@ -0,0 +1,38 @@
+package com.ycl.jxkg.domain.entity;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 鏁欒偛璧勬簮
+ * @author锛歠lq
+ * @date锛�2024/6/18 10:53
+ */
+@Data
+public class EducationResource {
+
+ private Integer id;
+
+ /** 鏂囦欢绫诲瀷 */
+ private String contentType;
+
+ /** 鏂囦欢鍦板潃 */
+ private String contentUrl;
+
+ /** 鎵�灞炲垎绫� */
+ private Integer belongType;
+
+ /** 涓婚绠�浠� */
+ private String introduction;
+
+ /** 闄勪欢 */
+ private String attachment;
+
+ private Date createTime;
+
+ private Date updateTime;
+
+ private Integer deleted;
+
+}
diff --git a/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java b/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java
new file mode 100644
index 0000000..6f6333e
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/domain/vo/admin/education/EducationResourceVO.java
@@ -0,0 +1,64 @@
+package com.ycl.jxkg.domain.vo.admin.education;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author锛歠lq
+ * @date锛�2024/6/18 10:53
+ */
+@Data
+public class EducationResourceVO {
+
+ private Integer pageSize = 10;
+
+ private Integer pageNum = 1;
+
+ private Integer id;
+
+ /** 鏂囦欢绫诲瀷 */
+ @NotBlank(message = "璇烽�夋嫨鏂囦欢绫诲瀷")
+ private String contentType;
+
+ /** 鏂囦欢鍦板潃 */
+ @NotNull(message = "璇蜂笂浼犳枃浠�")
+ private UploadFile contentUrl;
+ private String contentUrlString;
+
+ /** 鎵�灞炲垎绫� */
+ @NotNull(message = "璇烽�夋嫨鍒嗙被")
+ private Integer belongType;
+
+ private String typeName;
+
+ /** 涓婚 */
+ @NotBlank(message = "璇疯緭鍏ヤ富棰樼畝浠�")
+ private String introduction;
+
+ /** 闄勪欢 */
+ private List<UploadFile> attachment;
+ private String attachmentString;
+
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date createTime;
+
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date updateTime;
+
+ @Data
+ public static class UploadFile {
+
+ /** 鍦板潃 */
+ private String url;
+
+
+ /** 鏂囦欢鍘熷鍚� */
+ private String name;
+
+ }
+}
diff --git a/src/main/java/com/ycl/jxkg/domain/vo/student/education/StudentOnlineVO.java b/src/main/java/com/ycl/jxkg/domain/vo/student/education/StudentOnlineVO.java
new file mode 100644
index 0000000..ddb0663
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/domain/vo/student/education/StudentOnlineVO.java
@@ -0,0 +1,22 @@
+package com.ycl.jxkg.domain.vo.student.education;
+
+import lombok.Data;
+
+/**
+ * @author锛歺p
+ * @date锛�2024/5/16 17:54
+ */
+@Data
+public class StudentOnlineVO {
+
+ /** 绫诲埆 */
+ private Integer belongType;
+
+ /** 涓婚 */
+ private String subject;
+
+ private Integer pageNum = 1;
+
+ private Integer pageSize = 10;
+
+}
diff --git a/src/main/java/com/ycl/jxkg/mapper/EducationResourceMapper.java b/src/main/java/com/ycl/jxkg/mapper/EducationResourceMapper.java
new file mode 100644
index 0000000..9882ec6
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/mapper/EducationResourceMapper.java
@@ -0,0 +1,27 @@
+package com.ycl.jxkg.mapper;
+
+import com.ycl.jxkg.domain.entity.EducationResource;
+import com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO;
+import com.ycl.jxkg.domain.vo.student.education.StudentOnlineVO;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author锛歠lq
+ * @date锛�2024/6/18 10:53
+ */
+@Mapper
+public interface EducationResourceMapper {
+
+ void add(@Param("form") EducationResource form);
+
+ void update(@Param("form") EducationResource form);
+
+ void remove(@Param("ids") List<Integer> ids);
+
+ List<EducationResourceVO> page(@Param("query") EducationResourceVO query);
+
+ List<EducationResourceVO> byType(@Param("query") StudentOnlineVO query);
+}
diff --git a/src/main/java/com/ycl/jxkg/service/EducationResourceService.java b/src/main/java/com/ycl/jxkg/service/EducationResourceService.java
new file mode 100644
index 0000000..749d0ac
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/service/EducationResourceService.java
@@ -0,0 +1,40 @@
+package com.ycl.jxkg.service;
+
+import com.ycl.jxkg.base.Result;
+import com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO;
+import com.ycl.jxkg.domain.vo.student.education.StudentOnlineVO;
+
+import java.util.List;
+
+/**
+ * @author锛歠lq
+ * @date锛�2024/6/18 10:53
+ */
+public interface EducationResourceService {
+
+ Result add(EducationResourceVO form);
+
+
+ Result update(EducationResourceVO form);
+
+
+ Result remove(List<Integer> ids);
+
+
+ Result page(EducationResourceVO query);
+
+ /**
+ * 瀛︾敓绔垎椤垫煡璇�
+ *
+ * @param query
+ * @return
+ */
+ Result byType(StudentOnlineVO query);
+
+ /**
+ * 瀛︿範绫诲瀷list
+ *
+ * @return
+ */
+ Result typeList();
+}
diff --git a/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java
new file mode 100644
index 0000000..97380a9
--- /dev/null
+++ b/src/main/java/com/ycl/jxkg/service/impl/EducationResourceServiceImpl.java
@@ -0,0 +1,98 @@
+package com.ycl.jxkg.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.ycl.jxkg.base.Result;
+import com.ycl.jxkg.domain.entity.EducationResource;
+import com.ycl.jxkg.domain.entity.Subject;
+import com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO;
+import com.ycl.jxkg.domain.vo.student.education.StudentOnlineVO;
+import com.ycl.jxkg.mapper.EducationResourceMapper;
+import com.ycl.jxkg.mapper.SubjectMapper;
+import com.ycl.jxkg.service.EducationResourceService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author锛歠lq
+ * @date锛�2024/6/18 10:53
+ */
+@Service
+@RequiredArgsConstructor
+public class EducationResourceServiceImpl implements EducationResourceService {
+
+ private final EducationResourceMapper mapper;
+ private final SubjectMapper subjectMapper;
+
+ @Override
+ public Result add(EducationResourceVO form) {
+ EducationResource educationResource = new EducationResource();
+ BeanUtils.copyProperties(form, educationResource);
+ educationResource.setContentUrl(JSON.toJSONString(form.getContentUrl()));
+ if (!CollectionUtils.isEmpty(form.getAttachment())) {
+ educationResource.setAttachment(JSON.toJSONString(form.getAttachment()));
+ }
+ educationResource.setCreateTime(new Date());
+ educationResource.setUpdateTime(new Date());
+ mapper.add(educationResource);
+ return Result.ok("娣诲姞鎴愬姛");
+ }
+
+ @Override
+ public Result update(EducationResourceVO form) {
+ if (Objects.isNull(form.getId())) {
+ throw new RuntimeException("璇烽�夋嫨瑕佷慨鏀圭殑鏁版嵁");
+ }
+ EducationResource educationResource = new EducationResource();
+ BeanUtils.copyProperties(form, educationResource);
+ educationResource.setContentUrl(JSON.toJSONString(form.getContentUrl()));
+ if (!CollectionUtils.isEmpty(form.getAttachment())) {
+ educationResource.setAttachment(JSON.toJSONString(form.getAttachment()));
+ } else {
+ educationResource.setAttachment("");
+ }
+ mapper.update(educationResource);
+ return Result.ok("淇敼鎴愬姛");
+ }
+
+ @Override
+ public Result remove(List<Integer> ids) {
+ mapper.remove(ids);
+ return Result.ok("鍒犻櫎鎴愬姛");
+ }
+
+ @Override
+ public Result page(EducationResourceVO query) {
+ PageInfo<EducationResourceVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() ->
+ mapper.page(query));
+ page.getList().stream().forEach(item -> {
+ item.setContentUrl(JSON.parseObject(item.getContentUrlString(), EducationResourceVO.UploadFile.class));
+ item.setAttachment(JSON.parseArray(item.getAttachmentString(), EducationResourceVO.UploadFile.class));
+ });
+ return Result.ok(page.getList()).put("total", page.getTotal());
+ }
+
+ @Override
+ public Result byType(StudentOnlineVO query) {
+ PageInfo<EducationResourceVO> page = PageHelper.startPage(query.getPageNum(), query.getPageSize()).doSelectPageInfo(() ->
+ mapper.byType(query));
+ page.getList().stream().forEach(item -> {
+ item.setContentUrl(JSON.parseObject(item.getContentUrlString(), EducationResourceVO.UploadFile.class));
+ item.setAttachment(JSON.parseArray(item.getAttachmentString(), EducationResourceVO.UploadFile.class));
+ });
+ return Result.ok(page.getList()).put("total", page.getTotal());
+ }
+
+ @Override
+ public Result typeList() {
+ List<Subject> subjects = subjectMapper.allSubject();
+ return Result.ok(subjects);
+ }
+}
diff --git a/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java b/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java
index 7768c0a..928969f 100644
--- a/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java
+++ b/src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java
@@ -109,22 +109,8 @@
for (Integer questionType : map.keySet()) {
//鏁版嵁搴撻噷鐨勮繖涓被鍨嬬殑棰樼洰
List<Integer> questionIdList = map.get(questionType);
- Result InnerError1 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.SingleChoice.getCode());
- if (InnerError1 != null) return InnerError1;
- Result InnerError2 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.MultipleChoice.getCode());
- if (InnerError2 != null) return InnerError2;
- Result InnerError3 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.TrueFalse.getCode());
- if (InnerError3 != null) return InnerError3;
- Result InnerError4 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.GapFilling.getCode());
- if (InnerError4 != null) return InnerError4;
- Result InnerError5 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.ShortAnswer.getCode());
- if (InnerError5 != null) return InnerError5;
- Result InnerError6 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.Audio.getCode());
- if (InnerError6 != null) return InnerError6;
- Result InnerError7 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.Calculate.getCode());
- if (InnerError7 != null) return InnerError7;
- Result InnerError8 = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.Analysis.getCode());
- if (InnerError8 != null) return InnerError8;
+ Result result = createQuestion(questionSetting, questionTitleList, questionType, questionIdList,QuestionTypeEnum.fromCode(questionType).getCode());
+ if (result != null) return result;
}
examPaper.setContent(JSON.toJSONString(questionTitleList));
baseMapper.insert(examPaper);
diff --git a/src/main/resources/mapper/EducationResourceMapper.xml b/src/main/resources/mapper/EducationResourceMapper.xml
new file mode 100644
index 0000000..86c3488
--- /dev/null
+++ b/src/main/resources/mapper/EducationResourceMapper.xml
@@ -0,0 +1,87 @@
+<?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.ycl.jxkg.mapper.EducationResourceMapper">
+
+ <select id="page" resultType="com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO">
+ SELECT
+ ter.id,
+ ter.content_type,
+ ter.content_url as contentUrlString,
+ ter.belong_type,
+ ter.introduction,
+ ter.create_time,
+ ter.update_time,
+ ter.attachment as attachmentString,
+ ts.name as typeName
+ FROM
+ t_education_resource ter
+ INNER JOIN t_subject ts ON ts.id = ter.belong_type
+ <where>
+ AND ter.deleted = 0
+ <if test="query.introduction != null and query.introduction != ''">
+ AND ter.introduction like concat('%', #{query.subject}, '%')
+ </if>
+ <if test="query.belongType != null">
+ AND ts.id = #{query.belongType}
+ </if>
+ </where>
+ ORDER BY
+ ter.create_time DESC
+ </select>
+
+ <select id="byType" resultType="com.ycl.jxkg.domain.vo.admin.education.EducationResourceVO">
+ SELECT
+ ter.id,
+ ter.content_type,
+ ter.content_url as contentUrlString,
+ ter.belong_type,
+ ter.introduction,
+ ter.create_time,
+ ter.update_time,
+ ter.attachment as attachmentString
+ FROM
+ t_education_resource ter
+ INNER JOIN t_subject ts ON ts.id = tos.belong_type
+ <where>
+ AND ter.deleted = 0
+ <if test="query.introduction != null and query.introduction != ''">
+ AND ter.introduction like concat('%', #{query.subject}, '%')
+ </if>
+ <if test="query.belongType != null">
+ AND ts.id = #{query.belongType}
+ </if>
+ </where>
+ ORDER BY
+ ter.create_time DESC
+ </select>
+
+ <insert id="add" keyColumn="id" useGeneratedKeys="true">
+ INSERT INTO t_education_resource(content_type, content_url, belong_type, introduction, create_time, update_time,
+ attachment)
+ value (#{form.contentType}, #{form.contentUrl}, #{form.belongType}, #{form.introduction}, #{form.createTime}, #{form.updateTime}, #{form.attachment})
+ </insert>
+
+ <update id="update">
+ UPDATE
+ t_education_resource
+ <set>
+ <if test="form.contentType != null and form.contentType != ''">content_type = #{form.contentType},</if>
+ <if test="form.contentUrl != null and form.contentUrl != ''">content_url = #{form.contentUrl},</if>
+ <if test="form.belongType != null">belong_type = #{form.belongType},</if>
+ <if test="form.introduction != null and form.introduction != ''">introduction = #{form.introduction},</if>
+ <if test="form.updateTime != null">update_time = #{form.updateTime},</if>
+ attachment = #{form.attachment}
+ </set>
+ WHERE
+ id = #{form.id}
+ </update>
+
+ <update id="remove">
+ UPDATE t_education_resource SET deleted = 1 WHERE id IN
+ <foreach collection="ids" open="(" separator="," close=")" item="id">#{id}</foreach>
+ </update>
+
+
+</mapper>
--
Gitblit v1.8.0