kongzy
2024-06-24 4910e41f81a85c03a9dfc83f8ec9c1e71c123d49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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.gkhy.exam.system.mapper.ExQuestionBankMapper">
    <resultMap type="com.gkhy.exam.system.domain.ExQuestionBank" id="ExQuestionBankResult">
        <result property="id"       column="id"       />
        <result property="name"    column="name"    />
        <result property="categoryId"     column="category_id"     />
        <result property="status"         column="status"          />
        <result property="delFlag"         column="del_flag"          />
        <result property="companyId"         column="company_id"          />
        <result property="privatize"         column="privatize"          />
        <result property="version"         column="version"          />
        <result property="createBy"       column="create_by"       />
        <result property="createTime"     column="create_time"     />
        <result property="updateBy"       column="update_by"       />
        <result property="updateTime"     column="update_time"     />
        <result property="remark"         column="remark"          />
        <result property="totalCount"         column="total_count"          />
        <result property="exerciseCount"         column="exercise_count"          />
    </resultMap>
 
    <sql id="selectQuestionBankVo">
        select id, name, category_id, status, del_flag,company_id,privatize,version, create_by, create_time, update_by, update_time, remark,
               (select count(1) from ex_question where bank_id=a.id) as total_count
        from ex_question_bank
    </sql>
 
    <update id="deleteByBankId">
        update ex_question_bank set del_flag=1 where id=#{bankId}
    </update>
 
    <select id="checkNameUniqueForAdmin" resultType="com.gkhy.exam.system.domain.ExQuestionBank">
        select id,name from ex_question_bank where name=#{name} and privatize=1 and del_flag=0 limit 1
    </select>
 
    <select id="checkNameUnique" resultType="com.gkhy.exam.system.domain.ExQuestionBank">
        select id,name from ex_question_bank where name=#{name} and company_id=#{companyId} and del_flag=0 limit 1
    </select>
 
    <select id="selectQuestionBankList" resultMap="ExQuestionBankResult">
        <include refid="selectQuestionBankVo"/>
        <where>
            and del_flag=0
            <if test="name != null and name != ''">
                AND name like concat('%', #{name}, '%')
            </if>
            <if test="categoryId != null ">
                AND categoryId =#{categoryId}
            </if>
            <if test="status != null ">
                AND status =#{status}
            </if>
            <if test="companyId != null ">
                AND (company_id =#{companyId} or privatize=1)
            </if>
        </where>
        order by id desc
    </select>
 
    <select id="selectQuestionBankListForStudent" resultType="com.gkhy.exam.system.domain.ExQuestionBank">
        select a.*,
        (select count(1) from ex_question where bank_id=a.id) as total_count,
        b.exe_count as exercise_count
        from ex_question_bank a
        left join (select bank_id,count(*) as exe_count from ex_exercise_answer where student_id=#{studentId} group by bank_id) b on b.bank_id=a.id
        <where>
            and (a.company_id=#{companyId} or a.privatize=1) and a.del_flag=0
            <if test="name!=null and name!=''">
                a.name like concat('%',#{name},'%')
            </if>
        </where>
        order by a.id desc
    </select>
 
    <select id="selectQuestionBankByIdForStudent" resultType="com.gkhy.exam.system.domain.ExQuestionBank">
        select a.*,
               (select count(1) from ex_question where bank_id=a.id) as total_count,
               (select count(1)  from ex_exercise_answer where bank_id=#{bankId} and student_id=#{studentId}) as exercise_count
        from ex_question_bank a
        where a.bank_id=#{bankId}
    </select>
</mapper>