ExaminationBasicMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.keao.edu.user.dao.ExaminationBasicDao">
  8. <resultMap type="com.keao.edu.user.entity.ExaminationBasic" id="ExaminationBasic">
  9. <result column="id_" property="id" />
  10. <result column="name_" property="name" />
  11. <result column="exam_mode_" property="examMode" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler" />
  12. <result column="exam_location_id_list_" property="examLocationIdList" />
  13. <result column="exam_location_name_list_" property="examLocationNameList" />
  14. <result column="status_" property="status" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler" />
  15. <result column="enroll_start_time_" property="enrollStartTime" />
  16. <result column="enroll_end_time_" property="enrollEndTime" />
  17. <result column="expect_exam_start_time_" property="expectExamStartTime" />
  18. <result column="expect_exam_end_time_" property="expectExamEndTime" />
  19. <result column="actual_exam_start_time_" property="actualExamStartTime" />
  20. <result column="actual_exam_end_time_" property="actualExamEndTime" />
  21. <result column="poster_title_" property="posterTitle" />
  22. <result column="poster_profile_" property="posterProfile" />
  23. <result column="poster_background_img_" property="posterBackgroundImg" />
  24. <result column="custom_poster_" property="customPoster"/>
  25. <result column="create_time_" property="createTime" />
  26. <result column="update_time_" property="updateTime" />
  27. <result column="tenant_id_" property="tenantId" />
  28. <result column="memo_" property="memo" />
  29. <result column="organ_id_" property="organId"/>
  30. <result column="creator_id_" property="creatorId"/>
  31. </resultMap>
  32. <resultMap id="ExaminationBasicDto" type="com.keao.edu.user.dto.ExaminationBasicDto" extends="ExaminationBasic">
  33. </resultMap>
  34. <!-- 根据主键查询一条记录 -->
  35. <select id="get" resultMap="ExaminationBasic" >
  36. SELECT * FROM examination_basic WHERE id_ = #{id}
  37. </select>
  38. <select id="getExaminationBasic" resultMap="ExaminationBasicDto" >
  39. SELECT * FROM examination_basic WHERE id_ = #{examId}
  40. </select>
  41. <!-- 全查询 -->
  42. <select id="findAll" resultMap="ExaminationBasic">
  43. SELECT * FROM examination_basic WHERE tenant_id_=#{tenantId}
  44. </select>
  45. <!-- 向数据库增加一条记录 -->
  46. <insert id="insert" parameterType="com.keao.edu.user.entity.ExaminationBasic" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  47. INSERT INTO examination_basic (id_,name_,exam_mode_,exam_location_id_list_,exam_location_name_list_,status_,enroll_start_time_,enroll_end_time_,
  48. expect_exam_start_time_,expect_exam_end_time_,actual_exam_start_time_,actual_exam_end_time_,
  49. poster_title_,poster_profile_,poster_background_img_,custom_poster_,creator_id_,create_time_,update_time_,tenant_id_,memo_,organ_id_)
  50. VALUES(#{id},#{name},#{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examLocationIdList},#{examLocationNameList},
  51. #{status,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{enrollStartTime},#{enrollEndTime},
  52. #{expectExamStartTime},#{expectExamEndTime},#{actualExamStartTime},#{actualExamEndTime},
  53. #{posterTitle},#{posterProfile},#{posterBackgroundImg},#{customPoster},#{creatorId},NOW(),NOW(),#{tenantId},#{memo},#{organId})
  54. </insert>
  55. <update id="update" parameterType="com.keao.edu.user.entity.ExamOrganizationRelation">
  56. UPDATE examination_basic
  57. <set>
  58. <if test="name != null">
  59. name_ = #{name},
  60. </if>
  61. <if test="examMode != null">
  62. exam_mode_ = #{examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  63. </if>
  64. <if test="examLocationIdList != null">
  65. exam_location_id_list_ = #{examLocationIdList},
  66. </if>
  67. <if test="examLocationNameList != null">
  68. exam_location_name_list_ = #{examLocationNameList},
  69. </if>
  70. <if test="status != null">
  71. status_ = #{status,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  72. </if>
  73. <if test="enrollStartTime != null">
  74. enroll_start_time_ = #{enrollStartTime},
  75. </if>
  76. <if test="enrollEndTime != null">
  77. enroll_end_time_ = #{enrollEndTime},
  78. </if>
  79. <if test="expectExamStartTime != null">
  80. expect_exam_start_time_ = #{expectExamStartTime},
  81. </if>
  82. <if test="expectExamEndTime != null">
  83. expect_exam_end_time_ = #{expectExamEndTime},
  84. </if>
  85. actual_exam_start_time_ = #{actualExamStartTime},
  86. actual_exam_end_time_ = #{actualExamEndTime},
  87. <if test="posterTitle != null">
  88. poster_title_ = #{posterTitle},
  89. </if>
  90. <if test="posterProfile != null">
  91. poster_profile_ = #{posterProfile},
  92. </if>
  93. poster_background_img_ = #{posterBackgroundImg},
  94. custom_poster_ = #{customPoster},
  95. <if test="tenantId != null">
  96. tenant_id_ = #{tenantId},
  97. </if>
  98. <if test="memo!=null">
  99. memo_=#{memo},
  100. </if>
  101. <if test="creatorId!=null">
  102. creator_id_=#{creatorId},
  103. </if>
  104. update_time_ = NOW()
  105. </set> WHERE id_ = #{id}
  106. </update>
  107. <update id="batchUpdate" parameterType="com.keao.edu.user.entity.ExamOrganizationRelation">
  108. <foreach collection="exams" item="exam" separator=";">
  109. UPDATE examination_basic
  110. <set>
  111. <if test="exam.name != null">
  112. name_ = #{exam.name},
  113. </if>
  114. <if test="exam.examMode != null">
  115. exam_mode_ = #{exam.examMode,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  116. </if>
  117. <if test="exam.examLocationIdList != null">
  118. exam_location_id_list_ = #{exam.examLocationIdList},
  119. </if>
  120. <if test="exam.examLocationNameList != null">
  121. exam_location_name_list_ = #{exam.examLocationNameList},
  122. </if>
  123. <if test="exam.status != null">
  124. status_ = #{exam.status,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  125. </if>
  126. <if test="exam.enrollStartTime != null">
  127. enroll_start_time_ = #{exam.enrollStartTime},
  128. </if>
  129. <if test="exam.enrollEndTime != null">
  130. enroll_end_time_ = #{exam.enrollEndTime},
  131. </if>
  132. <if test="exam.expectExamStartTime != null">
  133. expect_exam_start_time_ = #{exam.expectExamStartTime},
  134. </if>
  135. <if test="exam.expectExamEndTime != null">
  136. expect_exam_end_time_ = #{exam.expectExamEndTime},
  137. </if>
  138. actual_exam_start_time_ = #{exam.actualExamStartTime},
  139. actual_exam_end_time_ = #{exam.actualExamEndTime},
  140. <if test="exam.posterTitle != null">
  141. poster_title_ = #{exam.posterTitle},
  142. </if>
  143. <if test="exam.posterProfile != null">
  144. poster_profile_ = #{exam.posterProfile},
  145. </if>
  146. <if test="exam.posterBackgroundImg != null">
  147. poster_background_img_ = #{exam.posterBackgroundImg},
  148. </if>
  149. <if test="exam.customPoster != null">
  150. custom_poster_ = #{exam.customPoster},
  151. </if>
  152. <if test="exam.tenantId != null">
  153. tenant_id_ = #{exam.tenantId},
  154. </if>
  155. <if test="exam.memo!=null">
  156. memo_=#{exam.memo},
  157. </if>
  158. <if test="exam.creatorId!=null">
  159. creator_id_=#{exam.creatorId},
  160. </if>
  161. update_time_ = NOW()
  162. </set> WHERE id_ = #{exam.id}
  163. </foreach>
  164. </update>
  165. <!-- 根据主键删除一条记录 -->
  166. <delete id="delete" >
  167. DELETE FROM examination_basic WHERE id_ = #{id}
  168. </delete>
  169. <sql id="queryCondition">
  170. <where>
  171. <if test="organIds!=null">
  172. AND organ_id_ IN
  173. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  174. #{organId}
  175. </foreach>
  176. </if>
  177. <if test="examStatus!=null">
  178. AND status_=#{examStatus}
  179. </if>
  180. <if test="search!=null">
  181. AND (id_=#{search} OR name_ LIKE CONCAT('%', #{search}, '%'))
  182. </if>
  183. </where>
  184. </sql>
  185. <!-- 分页查询 -->
  186. <select id="queryPage" resultMap="ExaminationBasic" parameterType="map">
  187. SELECT * FROM examination_basic
  188. <include refid="queryCondition"/>
  189. <include refid="global.limit"/>
  190. </select>
  191. <!-- 查询当前表的总记录数 -->
  192. <select id="queryCount" resultType="int">
  193. SELECT COUNT(*) FROM examination_basic
  194. <include refid="queryCondition"/>
  195. </select>
  196. <sql id="findExaminationBasicsCondition">
  197. <where>
  198. eb.status_!='DELETE'
  199. <if test="organId!=null">
  200. AND (eor.organ_id_ = #{organId}
  201. OR eb.organ_id_ IN
  202. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  203. #{organId}
  204. </foreach>
  205. )
  206. </if>
  207. <if test="examStatus!=null">
  208. AND eb.status_=#{examStatus}
  209. </if>
  210. <if test="search!=null">
  211. AND (eb.id_=#{search} OR eb.name_ LIKE CONCAT('%', #{search}, '%'))
  212. </if>
  213. </where>
  214. </sql>
  215. <select id="findExaminationBasics" resultMap="ExaminationBasicDto" parameterType="map">
  216. SELECT DISTINCT eb.*
  217. FROM
  218. exam_organization_relation eor
  219. LEFT JOIN examination_basic eb ON eor.examination_basic_id_ = eb.id_
  220. <include refid="findExaminationBasicsCondition"/>
  221. ORDER BY id_ DESC
  222. <include refid="global.limit"/>
  223. </select>
  224. <select id="countExaminationBasics" resultType="int">
  225. SELECT COUNT(DISTINCT eb.id_)
  226. FROM
  227. exam_organization_relation eor
  228. LEFT JOIN examination_basic eb ON eor.examination_basic_id_ = eb.id_
  229. <include refid="findExaminationBasicsCondition"/>
  230. </select>
  231. <select id="getNeedUpdateStatusExams" resultMap="ExaminationBasic">
  232. SELECT * FROM examination_basic WHERE status_ IN ('NOT_START', 'APPLYING', 'APPLIED', 'EXAM_ING', 'EXAM_END')
  233. </select>
  234. <select id="getExams" resultMap="ExaminationBasicDto">
  235. SELECT * FROM examination_basic
  236. WHERE id_ IN
  237. <foreach collection="examIds" item="examId" separator="," open="(" close=")">
  238. #{examId}
  239. </foreach>
  240. </select>
  241. <select id="lockExam" resultMap="ExaminationBasic">
  242. SELECT
  243. id_,
  244. name_,
  245. exam_mode_,
  246. exam_location_id_list_,
  247. status_,
  248. enroll_start_time_,
  249. enroll_end_time_,
  250. expect_exam_start_time_,
  251. expect_exam_end_time_,
  252. poster_title_,
  253. poster_profile_,
  254. poster_background_img_,
  255. memo_,
  256. create_time_,
  257. update_time_,
  258. tenant_id_,
  259. organ_id_,
  260. creator_id_,
  261. exam_location_name_list_,
  262. actual_exam_start_time_,
  263. actual_exam_end_time_
  264. FROM
  265. examination_basic
  266. WHERE
  267. id_ = #{examId} FOR UPDATE
  268. </select>
  269. <select id="getEndExamsWithDayAndStatus" resultMap="ExaminationBasic">
  270. SELECT * FROM examination_basic WHERE status_ IN ('EXAM_END') AND DATE_FORMAT(actual_exam_end_time_, '%Y-%m-%d') = #{day}
  271. </select>
  272. <select id="getUnderwayExams" resultMap="ExaminationBasicDto">
  273. SELECT DISTINCT eb.*
  274. FROM
  275. exam_organization_relation eor
  276. LEFT JOIN examination_basic eb ON eor.examination_basic_id_ = eb.id_
  277. WHERE status_ IN ( 'APPLYING', 'APPLIED' )
  278. <if test="organId!=null">
  279. AND (eor.organ_id_ = #{organId}
  280. OR eb.organ_id_ IN
  281. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  282. #{organId}
  283. </foreach>
  284. )
  285. </if>
  286. ORDER BY
  287. eb.id_
  288. LIMIT 6;
  289. </select>
  290. <select id="getTenantExamStatistics" resultType="com.keao.edu.user.dto.ExamStatisticsDto">
  291. SELECT
  292. COUNT(id_) 'totalExamNum',
  293. SUM(CASE WHEN status_!='RESULT_CONFIRM' THEN 1 ELSE 0 END) 'underWayExamNum'
  294. FROM
  295. examination_basic eb
  296. WHERE
  297. status_ NOT IN ( 'CLOSE', 'DELETE' )
  298. <if test="organIds!=null">
  299. AND EXISTS (SELECT examination_basic_id_ FROM exam_organization_relation WHERE
  300. eb.id_=examination_basic_id_ AND organ_id_ IN
  301. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  302. #{organId}
  303. </foreach>
  304. )
  305. </if>
  306. </select>
  307. </mapper>