UserCourseAnswerMapper.xml 6.2 KB

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