UserCourseAnswerMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 AND uca.assign_answer_id is not null
  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. <if test="sort != null and sort == 0">
  116. order by uca.create_time desc
  117. </if>
  118. <if test="sort == null and sort == ''">
  119. order by uca.create_time
  120. </if>
  121. </select>
  122. <update id="delChildAnswer" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" >
  123. UPDATE user_course_answer
  124. SET `status` = - 1
  125. WHERE
  126. FIND_IN_SET(
  127. answer_id,(
  128. SELECT
  129. ischild
  130. FROM
  131. (
  132. SELECT
  133. t1.answer_id,
  134. t1.assign_answer_id,
  135. t1.create_time,
  136. t2.*,
  137. IF
  138. ( find_in_set( assign_answer_id, @pids ) > 0, @pids := concat( @pids, ',', answer_id ), 0 ) AS ischild
  139. FROM
  140. ( 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,
  141. ( SELECT @pids := #{answerId} ) t2
  142. ) t4
  143. WHERE
  144. t4.ischild > 0
  145. ORDER BY
  146. create_time DESC
  147. LIMIT 1
  148. ))
  149. </update>
  150. <update id="delChildAnswer2" parameterType="com.zhongzheng.modules.user.bo.UserCourseAnswerQueryBo" >
  151. UPDATE user_course_answer
  152. set `status` = - 1
  153. WHERE
  154. FIND_IN_SET(
  155. answer_id,(
  156. SELECT
  157. ischild
  158. FROM
  159. (
  160. SELECT
  161. t1.answer_id,
  162. t1.assign_answer_id,
  163. t1.create_time,
  164. t2.*,
  165. IF
  166. ( find_in_set( assign_answer_id, @pids ) > 0, @pids := concat( @pids, ',', answer_id ), 0 ) AS ischild
  167. FROM
  168. ( 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,
  169. ( SELECT @pids := #{answerId} ) t2
  170. ) t4
  171. WHERE
  172. t4.ischild > 0
  173. ORDER BY
  174. create_time DESC
  175. LIMIT 1
  176. ))
  177. </update>
  178. </mapper>