xiangpei
2024-05-27 b0b59f3d9ee0340268e74e1e7a810e9087372160
课目关联部门
6个文件已修改
4个文件已添加
217 ■■■■■ 已修改文件
src/main/java/com/mindskip/xzs/controller/admin/EducationController.java 41 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/SubjectDept.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/domain/vo/SubjectDeptVO.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/DeptQuestionMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/repository/SubjectDeptMapper.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/viewmodel/admin/education/SubjectEditRequestVM.java 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/viewmodel/admin/education/SubjectResponseVM.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DeptQuestionMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/SubjectDeptMapper.xml 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mindskip/xzs/controller/admin/EducationController.java
@@ -5,36 +5,37 @@
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.ExamPaperSubject;
import com.mindskip.xzs.domain.Subject;
import com.mindskip.xzs.domain.SubjectDept;
import com.mindskip.xzs.domain.vo.SubjectDeptVO;
import com.mindskip.xzs.repository.SubjectDeptMapper;
import com.mindskip.xzs.service.*;
import com.mindskip.xzs.utility.PageInfoHelper;
import com.mindskip.xzs.viewmodel.admin.education.SubjectEditRequestVM;
import com.mindskip.xzs.viewmodel.admin.education.SubjectPageRequestVM;
import com.mindskip.xzs.viewmodel.admin.education.SubjectResponseVM;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
@RestController("AdminEducationController")
@RequestMapping(value = "/api/admin/education")
@RequiredArgsConstructor
public class EducationController extends BaseApiController {
    private final SubjectService subjectService;
    private final SubjectDeptMapper subjectDeptMapper;
    private final QuestionSubjectService questionSubjectService;
    private final ExamPaperSubjectService examPaperSubjectService;
    private final ExamPaperDepartmentService examPaperDepartmentService;
    private final ExamPaperService examPaperService;
    @Autowired
    public EducationController(SubjectService subjectService, QuestionSubjectService questionSubjectService, ExamPaperSubjectService examPaperSubjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperService examPaperService) {
        this.subjectService = subjectService;
        this.questionSubjectService = questionSubjectService;
        this.examPaperSubjectService = examPaperSubjectService;
        this.examPaperDepartmentService = examPaperDepartmentService;
        this.examPaperService = examPaperService;
    }
    @RequestMapping(value = "/subject/list", method = RequestMethod.POST)
    public RestResponse<List<Subject>> list() {
@@ -45,10 +46,20 @@
    @RequestMapping(value = "/subject/page", method = RequestMethod.POST)
    public RestResponse<PageInfo<SubjectResponseVM>> pageList(@RequestBody SubjectPageRequestVM model) {
        PageInfo<Subject> pageInfo = subjectService.page(model);
        PageInfo<SubjectResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> modelMapper.map(e, SubjectResponseVM.class));
        PageInfo<SubjectResponseVM> page = PageInfoHelper.copyMap(pageInfo, item -> {
            SubjectResponseVM vo = new SubjectResponseVM();
            BeanUtils.copyProperties(item, vo);
            List<SubjectDeptVO> subjectDeptVOS = subjectDeptMapper.deptBySubjectId(item.getId());
            List<Integer> deptIds = subjectDeptVOS.stream().map(SubjectDeptVO::getDeptId).collect(Collectors.toList());
            String deptNames = subjectDeptVOS.stream().map(SubjectDeptVO::getDeptName).collect(Collectors.joining("、"));
            vo.setDeptIds(deptIds);
            vo.setDeptNames(deptNames);
            return vo;
        });
        return RestResponse.ok(page);
    }
    @Transactional(rollbackFor = Exception.class)
    @RequestMapping(value = "/subject/edit", method = RequestMethod.POST)
    public RestResponse edit(@RequestBody @Valid SubjectEditRequestVM model) {
        Subject subject = modelMapper.map(model, Subject.class);
@@ -58,6 +69,15 @@
        } else {
            subjectService.updateByIdFilter(subject);
        }
        // 处理部门
        subjectDeptMapper.removeBySubjectId(subject.getId());
        List<SubjectDept> subjectDeptList = model.getDeptIds().stream().map(deptId -> {
            SubjectDept subjectDept = new SubjectDept();
            subjectDept.setSubjectId(subject.getId());
            subjectDept.setDeptId(deptId);
            return subjectDept;
        }).collect(Collectors.toList());
        subjectDeptMapper.add(subjectDeptList);
        return RestResponse.ok();
    }
@@ -65,6 +85,9 @@
    public RestResponse<SubjectEditRequestVM> select(@PathVariable Integer id) {
        Subject subject = subjectService.selectById(id);
        SubjectEditRequestVM vm = modelMapper.map(subject, SubjectEditRequestVM.class);
        List<SubjectDeptVO> subjectDeptVOS = subjectDeptMapper.deptBySubjectId(id);
        List<Integer> deptIds = subjectDeptVOS.stream().map(SubjectDeptVO::getDeptId).collect(Collectors.toList());
        vm.setDeptIds(deptIds);
        return RestResponse.ok(vm);
    }
src/main/java/com/mindskip/xzs/domain/SubjectDept.java
New file
@@ -0,0 +1,19 @@
package com.mindskip.xzs.domain;
import lombok.Data;
/**
 * @author:xp
 * @date:2024/5/27 14:28
 */
@Data
public class SubjectDept {
    private Integer id;
    /** 课目ID */
    private Integer subjectId;
    private Integer deptId;
}
src/main/java/com/mindskip/xzs/domain/vo/SubjectDeptVO.java
New file
@@ -0,0 +1,22 @@
package com.mindskip.xzs.domain.vo;
import lombok.Data;
/**
 * @author:xp
 * @date:2024/5/27 14:41
 */
@Data
public class SubjectDeptVO {
    private Integer id;
    private Integer deptId;
    private String deptName;
    private Integer subjectId;
    private String subjectName;
}
src/main/java/com/mindskip/xzs/repository/DeptQuestionMapper.java
@@ -16,7 +16,7 @@
    void add(@Param("deptQuestions") List<DeptQuestion> deptQuestions);
    void remove(@Param("questionId") Integer questionId, @Param("deptIds") List<Integer> deptIds);
    void remove(@Param("questionId") Integer questionId);
    /** 查询部门信息 */
    List<DeptQuestionVO> deptByQuestionId(@Param("questionId") Integer questionId);
src/main/java/com/mindskip/xzs/repository/SubjectDeptMapper.java
New file
@@ -0,0 +1,22 @@
package com.mindskip.xzs.repository;
import com.mindskip.xzs.domain.SubjectDept;
import com.mindskip.xzs.domain.vo.SubjectDeptVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
 * @author:xp
 * @date:2024/5/27 14:29
 */
@Mapper
public interface SubjectDeptMapper {
    void add(@Param("subjectDeptList") List<SubjectDept> subjectDeptList);
    void removeBySubjectId(@Param("subjectId") Integer subjectId);
    List<SubjectDeptVO> deptBySubjectId(@Param("subjectId") Integer subjectId);
}
src/main/java/com/mindskip/xzs/service/impl/QuestionServiceImpl.java
@@ -139,7 +139,7 @@
        questionMapper.updateByPrimaryKeySelective(question);
        // 处理题目所属部门
        deptQuestionMapper.remove(question.getId(), model.getDeptIds());
        deptQuestionMapper.remove(question.getId());
        List<DeptQuestion> deptQuestions = model.getDeptIds().stream().map(deptId -> {
            DeptQuestion deptQuestion = new DeptQuestion();
            deptQuestion.setQuestionId(question.getId());
src/main/java/com/mindskip/xzs/viewmodel/admin/education/SubjectEditRequestVM.java
@@ -1,12 +1,14 @@
package com.mindskip.xzs.viewmodel.admin.education;
import com.mindskip.xzs.viewmodel.BaseVM;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
public class SubjectEditRequestVM extends BaseVM {
    private Integer id;
@@ -14,41 +16,10 @@
    @NotBlank
    private String name;
//    @NotNull
    private List<Integer> deptIds;
    private Integer level;
//    @NotBlank
    private String levelName;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getLevel() {
        return level;
    }
    public void setLevel(Integer level) {
        this.level = level;
    }
    public String getLevelName() {
        return levelName;
    }
    public void setLevelName(String levelName) {
        this.levelName = levelName;
    }
}
src/main/java/com/mindskip/xzs/viewmodel/admin/education/SubjectResponseVM.java
@@ -1,10 +1,13 @@
package com.mindskip.xzs.viewmodel.admin.education;
import com.mindskip.xzs.viewmodel.BaseVM;
import lombok.Data;
import java.util.List;
@Data
public class SubjectResponseVM extends BaseVM {
    private Integer id;
    private String name;
@@ -13,35 +16,8 @@
    private String levelName;
    public Integer getId() {
        return id;
    }
    private List<Integer> deptIds;
    public void setId(Integer id) {
        this.id = id;
    }
    private String deptNames;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getLevel() {
        return level;
    }
    public void setLevel(Integer level) {
        this.level = level;
    }
    public String getLevelName() {
        return levelName;
    }
    public void setLevelName(String levelName) {
        this.levelName = levelName;
    }
}
src/main/resources/mapper/DeptQuestionMapper.xml
@@ -16,12 +16,6 @@
        DELETE
        FROM t_dept_question
        WHERE question_id = #{questionId}
        <if test="deptIds != null and deptIds.size > 0">
            AND dept_id IN
            <foreach collection="deptIds" open="(" separator="," close=")" item="deptId">
                #{deptId}
            </foreach>
        </if>
    </delete>
    <select id="deptByQuestionId" resultType="com.mindskip.xzs.domain.vo.DeptQuestionVO">
src/main/resources/mapper/SubjectDeptMapper.xml
New file
@@ -0,0 +1,28 @@
<?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.mindskip.xzs.repository.SubjectDeptMapper">
    <insert id="add" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO t_subject_dept(subject_id, dept_id) VALUES
        <foreach collection="subjectDeptList" item="item" separator=",">
            (#{item.subjectId}, #{item.deptId})
        </foreach>
    </insert>
    <delete id="removeBySubjectId">
        DELETE
        FROM t_subject_dept
        WHERE subject_id = #{subjectId}
    </delete>
    <select id="deptBySubjectId" resultType="com.mindskip.xzs.domain.vo.SubjectDeptVO">
        SELECT tdq.dept_id, td.name as deptName
        FROM t_subject_dept tdq
                 INNER JOIN t_department td ON td.id = tdq.dept_id
        WHERE tdq.subject_id = #{subjectId}
    </select>
</mapper>