UserCourseAnswerMapper.xml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.zhongzheng.modules.user.mapper.UserCourseAnswerMapper">
  6. <resultMap type="com.zhongzheng.modules.user.domain.UserCourseAnswer" id="UserCourseAnswerResult">
  7. <result property="answerId" column="answer_id"/>
  8. <result property="userId" column="user_id"/>
  9. <result property="assignUserId" column="assign_user_id"/>
  10. <result property="answerText" column="answer_text"/>
  11. <result property="courseId" column="course_id"/>
  12. <result property="sectionId" column="section_id"/>
  13. <result property="moduleId" column="module_id"/>
  14. <result property="chapterId" column="chapter_id"/>
  15. <result property="createTime" column="create_time"/>
  16. <result property="updateTime" column="update_time"/>
  17. <result property="goodsId" column="goods_id"/>
  18. <result property="assignAnswerId" column="assign_answer_id"/>
  19. </resultMap>
  20. <resultMap type="com.zhongzheng.modules.user.vo.UserCourseAnswerVo" id="UserCourseAnswerVo">
  21. <result property="answerId" column="answer_id"/>
  22. <result property="userId" column="user_id"/>
  23. <result property="assignUserId" column="assign_user_id"/>
  24. <result property="answerText" column="answer_text"/>
  25. <result property="courseId" column="course_id"/>
  26. <result property="sectionId" column="section_id"/>
  27. <result property="moduleId" column="module_id"/>
  28. <result property="chapterId" column="chapter_id"/>
  29. <result property="realname" column="realname"/>
  30. <result property="avatar" column="avatar"/>
  31. <result property="assignRealname" column="assign_realname"/>
  32. <result property="assignAvatar" column="assign_avatar"/>
  33. <result property="createTime" column="create_time"/>
  34. <result property="goodsId" column="goods_id"/>
  35. <result property="educationName" column="education_name"/>
  36. <result property="projectName" column="project_name"/>
  37. <result property="businessName" column="business_name"/>
  38. <result property="goodsName" column="goods_name"/>
  39. <result property="courseName" column="course_name"/>
  40. <result property="assignAnswerId" column="assign_answer_id"/>
  41. <result property="assignAnswerText" column="assign_answer_text"/>
  42. <result property="subjectNames" column="subject_names"/>
  43. </resultMap>
  44. <select id="selectAnswer" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" resultMap="UserCourseAnswerVo">
  45. SELECT
  46. uca.*,
  47. u.realname,
  48. u.avatar,
  49. u2.realname assign_realname,
  50. u2.avatar assign_avatar
  51. <if test="msgType == 2">
  52. ,uca1.answer_text as assign_answer_text
  53. </if>
  54. <if test="msgType != null">
  55. ,g.goods_name,
  56. c.course_name,
  57. cet.education_name,
  58. cpt.project_name,
  59. cb.business_name,
  60. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names
  61. </if>
  62. FROM
  63. user_course_answer uca
  64. <if test="msgType == 2">
  65. LEFT JOIN user_course_answer uca1 ON uca.assign_answer_id = uca1.answer_id
  66. </if>
  67. LEFT JOIN `user` u ON uca.user_id = u.user_id
  68. LEFT JOIN `user` u2 ON uca.assign_user_id = u2.user_id
  69. <if test="msgType != null">
  70. LEFT JOIN goods g on uca.goods_id = g.goods_id
  71. LEFT JOIN course c on c.course_id = uca.course_id
  72. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  73. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  74. LEFT JOIN course_business cb ON g.business_id = cb.id
  75. </if>
  76. WHERE
  77. 1 = 1
  78. AND uca.STATUS =1
  79. <if test="courseId != null and courseId != ''">
  80. AND uca.course_id = #{courseId}
  81. </if>
  82. <if test="moduleId != null and moduleId != ''">
  83. AND uca.module_id = #{moduleId}
  84. </if>
  85. <if test="chapterId != null and chapterId != ''">
  86. AND uca.chapter_id = #{chapterId}
  87. </if>
  88. <if test="sectionId != null and sectionId != ''">
  89. AND uca.section_id = #{sectionId}
  90. </if>
  91. <if test="goodsId != null and goodsId != ''">
  92. AND uca.goods_id = #{goodsId}
  93. </if>
  94. <if test="msgType != null and msgType == 1">
  95. AND ISNULL(uca.assign_user_id )
  96. </if>
  97. <if test="msgType != null and msgType == 2">
  98. AND uca.assign_user_id>0 AND uca.assign_answer_id is not null
  99. </if>
  100. <if test="searchKey != null and searchKey != '' ">
  101. and (g.goods_name like concat('%', #{searchKey}, '%') or uca.answer_text like concat('%', #{searchKey}, '%'))
  102. </if>
  103. <if test="msgType != null">
  104. <if test="educationTypeId != null and educationTypeId != ''">
  105. AND g.education_type_id = #{educationTypeId}
  106. </if>
  107. <if test="businessIds != null and businessIds.size()!=0 ">
  108. AND g.business_id in
  109. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  110. #{item}
  111. </foreach>
  112. </if>
  113. <if test="businessId != null and businessId != ''">
  114. AND g.business_id = #{businessId}
  115. </if>
  116. </if>
  117. <if test="sort != null and sort == 0">
  118. order by uca.create_time desc
  119. </if>
  120. <if test="sort == null and sort == ''">
  121. order by uca.create_time
  122. </if>
  123. </select>
  124. <update id="delChildAnswer" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" >
  125. UPDATE user_course_answer
  126. SET `status` = - 1
  127. WHERE
  128. FIND_IN_SET(
  129. answer_id,(
  130. SELECT
  131. ischild
  132. FROM
  133. (
  134. SELECT
  135. t1.answer_id,
  136. t1.assign_answer_id,
  137. t1.create_time,
  138. t2.*,
  139. IF
  140. ( find_in_set( assign_answer_id, @pids ) > 0, @pids := concat( @pids, ',', answer_id ), 0 ) AS ischild
  141. FROM
  142. ( SELECT answer_id, assign_answer_id, create_time FROM user_course_answer t WHERE t.assign_answer_id > 0 and tenant_id = #{tenantId} ORDER BY t.create_time ) t1,
  143. ( SELECT @pids := #{answerId} ) t2
  144. ) t4
  145. WHERE
  146. t4.ischild > 0
  147. ORDER BY
  148. create_time DESC
  149. LIMIT 1
  150. ))
  151. </update>
  152. <update id="delChildAnswer2" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" >
  153. UPDATE user_course_answer
  154. set `status` = - 1
  155. WHERE
  156. FIND_IN_SET(
  157. answer_id,(
  158. SELECT
  159. ischild
  160. FROM
  161. (
  162. SELECT
  163. t1.answer_id,
  164. t1.assign_answer_id,
  165. t1.create_time,
  166. t2.*,
  167. IF
  168. ( find_in_set( assign_answer_id, @pids ) > 0, @pids := concat( @pids, ',', answer_id ), 0 ) AS ischild
  169. FROM
  170. ( SELECT answer_id, assign_answer_id, create_time FROM user_course_answer t WHERE t.assign_answer_id > 0 ORDER BY t.create_time ) t1,
  171. ( SELECT @pids := #{answerId} ) t2
  172. ) t4
  173. WHERE
  174. t4.ischild > 0
  175. ORDER BY
  176. create_time DESC
  177. LIMIT 1
  178. ))
  179. </update>
  180. </mapper>