DzClassesMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.dz.mapper.DzClassesMapper">
  6. <resultMap type="DzClasses" id="DzClassesResult">
  7. <result property="classId" column="class_id" />
  8. <result property="deptId" column="dept_id" />
  9. <result property="schoolId" column="school_id" />
  10. <result property="year" column="year" />
  11. <result property="name" column="name" />
  12. <result property="online" column="online" />
  13. <result property="status" column="status" />
  14. <result property="stats" column="stats" />
  15. <result property="createTime" column="create_time" />
  16. <result property="updateTime" column="update_time" />
  17. <result property="isDefault" column="is_default" />
  18. <association property="school" javaType="DzSchool" resultMap="DzSchoolResult" />
  19. </resultMap>
  20. <resultMap type="DzSchool" id="DzSchoolResult">
  21. <result property="id" column="id" />
  22. <result property="name" column="school_name" />
  23. <result property="deptId" column="dept_id" />
  24. <result property="location" column="location" />
  25. <result property="pro" column="pro" />
  26. <result property="city" column="city" />
  27. <result property="area" column="area" />
  28. </resultMap>
  29. <select id="selectClassesDirectedBuildStats" resultType="com.alibaba.fastjson2.JSONObject">
  30. SELECT c.`class_id` classId, c.`name` className, lt.`batch_id` batchId, lt.`name` batchName, count(*) `total`, SUM(if(ls.`major_plan_id` IS NULL, 1, 0)) unexact,
  31. SUM(IF(ls.`major_plan_id` IS not NULL and ts.`student_id` IS NULL, 1, 0)) unsend,
  32. SUM(IF(ls.`major_plan_id` IS not NULL and ts.`student_id` IS NOT NULL and ts.`status` != 4 , 1, 0)) unfinish,
  33. sum(if(ls.`major_plan_id` IS NOT NULL and ts.`student_id` is not null AND ts.`status` = 4 , 1, 0)) send
  34. FROM `dz_teacher_class` tc
  35. join `learn_student` ls on tc.`class_id` = ls.`class_id`
  36. join `dz_classes` c on ls.`class_id` = c.`class_id`
  37. JOIN `sys_user` u ON ls.`student_id` = u.`user_id`
  38. join `learn_test` lt on lt.`year` = #{year} <if test="batchId != null"> and lt.`batch_id` = #{batchId} </if>
  39. LEFT JOIN `learn_test_student` ts ON ts.`student_id` = ls.`student_id`
  40. <if test="batchId != null"> and ts.`batch_id` = #{batchId} </if>
  41. <if test="buildType != null"> AND ts.`build_type` = #{buildType} </if>
  42. <if test="subjectId != null"> and ts.`subject_id` = #{subjectId} </if>
  43. <where>tc.`teacher_id` = #{teacherId}
  44. <if test="classId != null"> AND ls.`class_id` = #{classId}</if>
  45. <if test="buildType != null and buildType == 'ExactIntelligent'"> AND ls.`university_id` is not null</if>
  46. <if test="universityId != null"> AND ls.`university_id` = #{universityId}</if>
  47. <if test="majorGroup != null"> AND ls.`major_group` = #{majorGroup}</if>
  48. <if test="majorPlanId != null"> AND ls.`major_plan_id` = #{majorPlanId}</if>
  49. <if test="examType != null and examType != ''"> AND u.`exam_type` = #{examType}</if>
  50. </where>
  51. group by c.`class_id`, c.`name`, lt.`batch_id`, lt.`name`
  52. order by c.`class_id`, c.`name`, lt.`batch_id`, lt.`name`
  53. </select>
  54. <select id="selectClassesBuildStats" resultType="com.alibaba.fastjson2.JSONObject">
  55. SELECT c.`class_id` classId, c.`name` className, lt.`batch_id` batchId, lt.`name` batchName, count(*) `total`,
  56. SUM(IF(ts.`student_id` IS NULL, 1, 0)) unsend,
  57. SUM(IF(ts.`student_id` IS NOT NULL and ts.`status` != 4 , 1, 0)) unfinish,
  58. sum(if(ts.`student_id` is not null AND ts.`status` = 4 , 1, 0)) send
  59. FROM `dz_teacher_class` tc
  60. join `learn_student` ls on tc.`class_id` = ls.`class_id`
  61. JOIN sys_user u ON ls.`student_id` = u.`user_id`
  62. join `dz_classes` c on ls.`class_id` = c.`class_id`
  63. join `learn_test` lt on lt.`year` = #{year} <if test="batchId != null"> and lt.`batch_id` = #{batchId} </if>
  64. LEFT JOIN `learn_test_student` ts ON ts.`student_id` = ls.`student_id`
  65. <if test="batchId != null"> and ts.`batch_id` = #{batchId} </if>
  66. <if test="buildType != null"> AND ts.`build_type` = #{buildType} </if>
  67. <if test="subjectId != null"> and ts.`subject_id` = #{subjectId} </if>
  68. <where>tc.`teacher_id` = #{teacherId}
  69. <if test="classId != null"> AND ls.`class_id` = #{classId}</if>
  70. <if test="universityId != null"> AND ls.`university_id` = #{universityId}</if>
  71. <if test="majorGroup != null"> AND ls.`major_group` = #{majorGroup}</if>
  72. <if test="majorPlanId != null"> AND ls.`major_plan_id` = #{majorPlanId}</if>
  73. <if test="examType != null and examType != ''"> AND u.`exam_type` = #{examType}</if>
  74. </where>
  75. group by c.`class_id`, c.`name`, lt.`batch_id`, lt.`name`
  76. order by c.`class_id`, c.`name`, lt.`batch_id`, lt.`name`
  77. </select>
  78. <select id="getPaperStudentRecords" resultType="com.alibaba.fastjson2.JSONObject">
  79. SELECT ts.examinee_id examineeId, ls.`student_id` studentId, u.`nick_name` studentName, dc.`name` className, u.`phonenumber` mobile, ts.`batch_id` batchId, ts.`subject_id` subjectId, ts.`paper_id` paperId, lp.`paperName`, lp.`fenshu` total, le.`score`, le.`score_rate` rate,
  80. lt.`name` batchName, ds.`subject_name` subjectName,
  81. CASE WHEN ls.`major_plan_id` IS NULL AND #{buildType} IN ('ExactHand', 'ExactIntelligent') THEN '10' WHEN ts.`student_id` IS NULL THEN '20' WHEN ts.`status` != 4 THEN '30' ELSE '40' END state
  82. FROM `learn_student` ls
  83. JOIN `sys_user` u ON ls.`student_id` = u.`user_id`
  84. JOIN `learn_test_student` ts ON ts.`student_id` = ls.`student_id`
  85. JOIN `dz_classes` dc on dc.`class_id` = ls.`class_id`
  86. JOIN `dz_subject` ds on ds.`subject_id` = ts.`subject_id`
  87. join `learn_test` lt on lt.`batch_id` = ts.`batch_id`
  88. <if test="batchId != null"> and ts.`batch_id` = #{batchId} </if>
  89. <if test="buildType != null"> AND ts.`build_type` = #{buildType} </if>
  90. <if test="subjectId != null"> and ts.`subject_id` = #{subjectId} </if>
  91. LEFT JOIN `learn_examinee` le ON le.examinee_id = ts.examinee_id
  92. LEFT JOIN `learn_paper` lp ON ts.`paper_id` = lp.`id`
  93. <where> ls.`class_id` = #{classId}
  94. <if test="universityId != null"> AND ls.`university_id` = #{universityId}</if>
  95. <if test="majorGroup != null"> AND ls.`major_group` = #{majorGroup}</if>
  96. <if test="majorPlanId != null"> AND ls.`major_plan_id` = #{majorPlanId}</if>
  97. <if test="examType != null and examType != ''"> AND u.`exam_type` = #{examType}</if>
  98. </where>
  99. </select>
  100. <sql id="selectDzClassesVo">
  101. select t1.class_id, t1.dept_id, t1.school_id, t1.year, t1.name, t1.online, t1.status, t1.stats, t1.create_time, t1.update_time,t1.is_default,
  102. t2.id, t2.name school_name, t2.dept_id, t2.pro, t2.city, t2.area
  103. from dz_classes t1
  104. left join dz_school t2 on t1.school_id=t2.id
  105. </sql>
  106. <select id="selectDzClassesList" parameterType="DzClasses" resultMap="DzClassesResult">
  107. <include refid="selectDzClassesVo"/>
  108. <where>
  109. <if test="schoolId != null "> and t1.school_id = #{schoolId}</if>
  110. <if test="deptId != null and deptId > 0 "> and t1.dept_id = #{deptId}</if>
  111. <if test="deptId == 0 "> and t1.dept_id is null </if>
  112. <if test="year != null "> and t1.year = #{year}</if>
  113. <if test="name != null and name != ''"> and t1.name like concat('%', #{name}, '%')</if>
  114. <if test="online != null "> and t1.online = #{online}</if>
  115. <if test="status != null "> and t1.status = #{status}</if>
  116. <if test="isDefault != null "> and t1.is_default = #{isDefault}</if>
  117. <if test="stats != null and stats != ''"> and t1.stats = #{stats}</if>
  118. </where>
  119. </select>
  120. <select id="selectClassesForTeacher" parameterType="Long" resultMap="DzClassesResult">
  121. SELECT c.* FROM `dz_teacher_class` tc
  122. JOIN `dz_classes` c ON tc.`class_id` = c.`class_id`
  123. WHERE tc.`teacher_id` = #{teacherId} AND NOW() &lt; tc.`out_date`
  124. </select>
  125. <select id="selectClassesByIds" resultMap="DzClassesResult">
  126. <include refid="selectDzClassesVo"/>
  127. where t1.class_id in <foreach collection="ids" item="id" open="(" separator="," close=")">#{id}</foreach>
  128. </select>
  129. <select id="selectDzClassesListBySchoolId" resultMap="DzClassesResult">
  130. select * from dz_classes t1
  131. where t1.school_id = #{schoolId}
  132. </select>
  133. <select id="selectDzClassesBySchoolIds" resultMap="DzClassesResult">
  134. <include refid="selectDzClassesVo"/>
  135. where t1.school_id in
  136. <foreach collection="schoolIds" item="schoolId" open="(" separator="," close=")">
  137. #{schoolId}
  138. </foreach>
  139. </select>
  140. <select id="selectDzClassesByClassId" parameterType="Long" resultMap="DzClassesResult">
  141. <include refid="selectDzClassesVo"/>
  142. where t1.class_id = #{classId}
  143. </select>
  144. <insert id="insertDzClasses" parameterType="DzClasses" useGeneratedKeys="true" keyProperty="classId">
  145. insert into dz_classes
  146. <trim prefix="(" suffix=")" suffixOverrides=",">
  147. <if test="deptId != null">dept_id,</if>
  148. <if test="schoolId != null">school_id,</if>
  149. <if test="year != null">year,</if>
  150. <if test="name != null and name != ''">name,</if>
  151. <if test="online != null">online,</if>
  152. <if test="status != null">status,</if>
  153. <if test="stats != null">stats,</if>
  154. <if test="createTime != null">create_time,</if>
  155. <if test="updateTime != null">update_time,</if>
  156. <if test="isDefault != null">is_default,</if>
  157. </trim>
  158. <trim prefix="values (" suffix=")" suffixOverrides=",">
  159. <if test="deptId != null">#{deptId},</if>
  160. <if test="schoolId != null">#{schoolId},</if>
  161. <if test="year != null">#{year},</if>
  162. <if test="name != null and name != ''">#{name},</if>
  163. <if test="online != null">#{online},</if>
  164. <if test="status != null">#{status},</if>
  165. <if test="stats != null">#{stats},</if>
  166. <if test="createTime != null">#{createTime},</if>
  167. <if test="updateTime != null">#{updateTime},</if>
  168. <if test="isDefault != null">#{isDefault},</if>
  169. </trim>
  170. </insert>
  171. <update id="updateDzClasses" parameterType="DzClasses">
  172. update dz_classes
  173. <trim prefix="SET" suffixOverrides=",">
  174. <if test="deptId != null">dept_id = #{deptId},</if>
  175. <if test="schoolId != null">school_id = #{schoolId},</if>
  176. <if test="year != null">year = #{year},</if>
  177. <if test="name != null and name != ''">name = #{name},</if>
  178. <if test="online != null">online = #{online},</if>
  179. <if test="status != null">status = #{status},</if>
  180. <if test="stats != null">stats = #{stats},</if>
  181. <if test="createTime != null">create_time = #{createTime},</if>
  182. <if test="updateTime != null">update_time = #{updateTime},</if>
  183. <if test="isDefault != null">is_default = #{isDefault},</if>
  184. </trim>
  185. where class_id = #{classId}
  186. </update>
  187. <delete id="deleteDzClassesByClassId" parameterType="Long">
  188. delete from dz_classes where class_id = #{classId}
  189. </delete>
  190. <delete id="deleteDzClassesByClassIds" parameterType="String">
  191. delete from dz_classes where class_id in
  192. <foreach item="classId" collection="array" open="(" separator="," close=")">
  193. #{classId}
  194. </foreach>
  195. </delete>
  196. </mapper>