UserCourseAnswerMapper.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. </resultMap>
  43. <select id="selectAnswer" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" resultMap="UserCourseAnswerVo">
  44. SELECT
  45. uca.*,
  46. u.realname,
  47. u.avatar,
  48. u2.realname assign_realname,
  49. u2.avatar assign_avatar
  50. <if test="msgType == 2">
  51. ,uca1.answer_text as assign_answer_text
  52. </if>
  53. <if test="msgType != null">
  54. ,g.goods_name,
  55. c.course_name,
  56. cet.education_name,
  57. cpt.project_name,
  58. cb.business_name
  59. </if>
  60. FROM
  61. user_course_answer uca
  62. <if test="msgType == 2">
  63. LEFT JOIN user_course_answer uca1 ON uca.assign_answer_id = uca1.answer_id
  64. </if>
  65. LEFT JOIN `user` u ON uca.user_id = u.user_id
  66. LEFT JOIN `user` u2 ON uca.assign_user_id = u2.user_id
  67. <if test="msgType != null">
  68. LEFT JOIN goods g on uca.goods_id = g.goods_id
  69. LEFT JOIN course c on c.course_id = uca.course_id
  70. LEFT JOIN course_education_type cet ON g.education_type_id = cet.id
  71. LEFT JOIN course_project_type cpt ON g.project_id = cpt.id
  72. LEFT JOIN course_business cb ON g.business_id = cb.id
  73. </if>
  74. WHERE
  75. 1 = 1
  76. AND uca.STATUS =1
  77. <if test="courseId != null and courseId != ''">
  78. AND uca.course_id = #{courseId}
  79. </if>
  80. <if test="moduleId != null and moduleId != ''">
  81. AND uca.module_id = #{moduleId}
  82. </if>
  83. <if test="chapterId != null and chapterId != ''">
  84. AND uca.chapter_id = #{chapterId}
  85. </if>
  86. <if test="sectionId != null and sectionId != ''">
  87. AND uca.section_id = #{sectionId}
  88. </if>
  89. <if test="goodsId != null and goodsId != ''">
  90. AND uca.goods_id = #{goodsId}
  91. </if>
  92. <if test="msgType != null and msgType == 1">
  93. AND ISNULL(uca.assign_user_id )
  94. </if>
  95. <if test="msgType != null and msgType == 2">
  96. AND uca.assign_user_id>0
  97. </if>
  98. <if test="searchKey != null and searchKey != '' ">
  99. and (g.goods_name like concat('%', #{searchKey}, '%') or uca.answer_text like concat('%', #{searchKey}, '%'))
  100. </if>
  101. <if test="msgType != null">
  102. <if test="educationTypeId != null and educationTypeId != ''">
  103. AND g.education_type_id = #{educationTypeId}
  104. </if>
  105. <if test="businessIds != null and businessIds.size()!=0 ">
  106. AND g.business_id in
  107. <foreach collection="businessIds" item="item" index="index" open="(" close=")" separator=",">
  108. #{item}
  109. </foreach>
  110. </if>
  111. <if test="businessId != null and businessId != ''">
  112. AND g.business_id = #{businessId}
  113. </if>
  114. </if>
  115. order by uca.update_time
  116. </select>
  117. <update id="delChildAnswer" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" >
  118. UPDATE user_course_answer
  119. SET `status` = - 1
  120. WHERE
  121. FIND_IN_SET(
  122. answer_id,(
  123. SELECT
  124. ischild
  125. FROM
  126. (
  127. SELECT
  128. t1.answer_id,
  129. t1.assign_answer_id,
  130. t1.create_time,
  131. t2.*,
  132. IF
  133. ( find_in_set( assign_answer_id, @pids ) > 0, @pids := concat( @pids, ',', answer_id ), 0 ) AS ischild
  134. FROM
  135. ( 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,
  136. ( SELECT @pids := #{answerId} ) t2
  137. ) t4
  138. WHERE
  139. t4.ischild > 0
  140. ORDER BY
  141. create_time DESC
  142. LIMIT 1
  143. ))
  144. </update>
  145. <update id="delChildAnswer2" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" >
  146. UPDATE user_course_answer
  147. set `status` = - 1
  148. WHERE
  149. FIND_IN_SET(
  150. answer_id,(
  151. SELECT
  152. ischild
  153. FROM
  154. (
  155. SELECT
  156. t1.answer_id,
  157. t1.assign_answer_id,
  158. t1.create_time,
  159. t2.*,
  160. IF
  161. ( find_in_set( assign_answer_id, @pids ) > 0, @pids := concat( @pids, ',', answer_id ), 0 ) AS ischild
  162. FROM
  163. ( 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,
  164. ( SELECT @pids := #{answerId} ) t2
  165. ) t4
  166. WHERE
  167. t4.ischild > 0
  168. ORDER BY
  169. create_time DESC
  170. LIMIT 1
  171. ))
  172. </update>
  173. </mapper>