FsCourseRedPacketLogMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.fs.course.mapper.FsCourseRedPacketLogMapper">
  6. <resultMap type="FsCourseRedPacketLog" id="FsCourseRedPacketLogResult">
  7. <result property="logId" column="log_id" />
  8. <result property="courseId" column="course_id" />
  9. <result property="userId" column="user_id" />
  10. <result property="videoId" column="video_id" />
  11. <result property="companyUserId" column="company_user_id" />
  12. <result property="companyId" column="company_id" />
  13. <result property="amount" column="amount" />
  14. <result property="createTime" column="create_time" />
  15. <result property="qwUserId" column="qw_user_id" />
  16. <result property="outBatchNo" column="out_batch_no" />
  17. <result property="status" column="status" />
  18. <result property="updateTime" column="update_time" />
  19. <result property="watchLogId" column="watch_log_id" />
  20. <result property="remark" column="remark" />
  21. <result property="result" column="result" />
  22. <result property="periodId" column="period_id" />
  23. <result property="batchId" column="batch_id" />
  24. <result property="appId" column="app_id" />
  25. </resultMap>
  26. <sql id="selectFsCourseRedPacketLogVo">
  27. select log_id,watch_log_id, remark,out_batch_no,status,update_time,course_id, user_id, video_id, company_user_id, company_id, amount, create_time, qw_user_id,period_id,result,app_id,batch_id from fs_course_red_packet_log
  28. </sql>
  29. <select id="selectFsCourseRedPacketLogList" parameterType="FsCourseRedPacketLog" resultMap="FsCourseRedPacketLogResult">
  30. <include refid="selectFsCourseRedPacketLogVo"/>
  31. <where>
  32. <if test="courseId != null "> and course_id = #{courseId}</if>
  33. <if test="userId != null "> and user_id = #{userId}</if>
  34. <if test="videoId != null "> and video_id = #{videoId}</if>
  35. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  36. <if test="companyId != null "> and company_id = #{companyId}</if>
  37. <if test="amount != null "> and amount = #{amount}</if>
  38. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  39. </where>
  40. </select>
  41. <select id="selectFsCourseRedPacketLogByLogId" parameterType="Long" resultMap="FsCourseRedPacketLogResult">
  42. <include refid="selectFsCourseRedPacketLogVo"/>
  43. where log_id = #{logId}
  44. </select>
  45. <select id="selectFsCourseRedPacketLogListVONew" resultType="com.fs.course.vo.FsCourseRedPacketLogListPVO">
  46. select
  47. watch.log_id,
  48. watch.user_id,
  49. uc.course_name,
  50. v.title as video_name,
  51. watch.log_type,
  52. watch.qw_external_contact_id,
  53. watch.qw_user_id,
  54. watch.course_id,
  55. watch.send_type,
  56. watch.video_id,
  57. l.create_time,
  58. SEC_TO_TIME(watch.duration) duration,
  59. l.amount,
  60. l.status,
  61. l.out_batch_no,
  62. v.title,u.nick_name as fsNickName,u.avatar as fsAvatar,u.phone,cu.nick_name company_user_name,c.company_name,qu.qw_user_name
  63. from fs_course_watch_log watch
  64. left join fs_course_red_packet_log l on watch.user_id = l.user_id and watch.video_id = l.video_id
  65. left join fs_user_course_video v on v.video_id = watch.video_id
  66. left join fs_user_course uc on uc.course_id = l.course_id
  67. left join fs_user u on u.user_id = watch.user_id
  68. left join company_user cu on cu.user_id=watch.company_user_id
  69. left join company c on c.company_id=watch.company_id
  70. LEFT JOIN qw_user qu on qu.id= watch.qw_user_id
  71. <where>
  72. <if test = ' userId !=null '> and watch.user_id = #{userId} </if>
  73. <if test = ' companyId !=null '> and watch.company_id = #{companyId} </if>
  74. <if test = ' companyUserName !=null '> and cu.nick_name like concat('%', #{companyUserName}, '%') </if>
  75. <if test = ' nickName !=null '> and u.nick_name like concat('%', #{nickName}, '%') </if>
  76. <if test = ' courseId !=null '> and watch.course_id = #{courseId} </if>
  77. <if test = ' videoId !=null '> and watch.video_id = #{videoId} </if>
  78. <if test = ' status !=null '> and l.status = #{status} </if>
  79. <if test = ' logType !=null '> and watch.log_type = #{logType} </if>
  80. <if test = ' phone !=null '> and u.phone = #{phone} </if>
  81. <if test = ' qwUserId !=null '> and watch.qw_user_id = #{qwUserId} </if>
  82. <if test="sTime != null"> and DATE(watch.create_time) &gt;= DATE(#{sTime})</if>
  83. <if test="eTime != null"> and DATE(watch.create_time) &lt;= DATE(#{eTime})</if>
  84. </where>
  85. order by watch.log_id desc
  86. </select>
  87. <insert id="insertFsCourseRedPacketLog" parameterType="FsCourseRedPacketLog" useGeneratedKeys="true" keyProperty="logId">
  88. insert into fs_course_red_packet_log
  89. <trim prefix="(" suffix=")" suffixOverrides=",">
  90. <if test="courseId != null">course_id,</if>
  91. <if test="userId != null">user_id,</if>
  92. <if test="videoId != null">video_id,</if>
  93. <if test="companyUserId != null">company_user_id,</if>
  94. <if test="companyId != null">company_id,</if>
  95. <if test="amount != null">amount,</if>
  96. <if test="createTime != null">create_time,</if>
  97. <if test="qwUserId != null">qw_user_id,</if>
  98. <if test="outBatchNo != null">out_batch_no,</if>
  99. <if test="status != null">status,</if>
  100. <if test="updateTime != null">update_time,</if>
  101. <if test="watchLogId != null">watch_log_id,</if>
  102. <if test="remark != null">remark,</if>
  103. <if test="periodId != null">period_id,</if>
  104. <if test="result != null">result,</if>
  105. <if test="batchId != null">batch_id,</if>
  106. <if test="appId != null">app_id,</if>
  107. </trim>
  108. <trim prefix="values (" suffix=")" suffixOverrides=",">
  109. <if test="courseId != null">#{courseId},</if>
  110. <if test="userId != null">#{userId},</if>
  111. <if test="videoId != null">#{videoId},</if>
  112. <if test="companyUserId != null">#{companyUserId},</if>
  113. <if test="companyId != null">#{companyId},</if>
  114. <if test="amount != null">#{amount},</if>
  115. <if test="createTime != null">#{createTime},</if>
  116. <if test="qwUserId != null">#{qwUserId},</if>
  117. <if test="outBatchNo != null">#{outBatchNo},</if>
  118. <if test="status != null">#{status},</if>
  119. <if test="updateTime != null">#{updateTime},</if>
  120. <if test="watchLogId != null">#{watchLogId},</if>
  121. <if test="remark != null">#{remark},</if>
  122. <if test="periodId != null">#{periodId},</if>
  123. <if test="result != null">#{result},</if>
  124. <if test="batchId != null">#{batchId},</if>
  125. <if test="appId != null">#{appId},</if>
  126. </trim>
  127. </insert>
  128. <update id="updateFsCourseRedPacketLog" parameterType="FsCourseRedPacketLog">
  129. update fs_course_red_packet_log
  130. <trim prefix="SET" suffixOverrides=",">
  131. <if test="courseId != null">course_id = #{courseId},</if>
  132. <if test="userId != null">user_id = #{userId},</if>
  133. <if test="videoId != null">video_id = #{videoId},</if>
  134. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  135. <if test="companyId != null">company_id = #{companyId},</if>
  136. <if test="amount != null">amount = #{amount},</if>
  137. <if test="createTime != null">create_time = #{createTime},</if>
  138. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  139. <if test="outBatchNo != null">out_batch_no = #{outBatchNo},</if>
  140. <if test="status != null">status = #{status},</if>
  141. <if test="updateTime != null">update_time = #{updateTime},</if>
  142. <if test="watchLogId != null">watch_log_id = #{watchLogId},</if>
  143. <if test="periodId != null">period_id = #{periodId},</if>
  144. <if test="remark != null">remark = #{remark},</if>
  145. <if test="batchId != null">batch_id = #{batchId},</if>
  146. <if test="appId != null">app_id = #{appId},</if>
  147. </trim>
  148. where log_id = #{logId}
  149. </update>
  150. <delete id="deleteFsCourseRedPacketLogByLogId" parameterType="Long">
  151. delete from fs_course_red_packet_log where log_id = #{logId}
  152. </delete>
  153. <delete id="deleteFsCourseRedPacketLogByLogIds" parameterType="String">
  154. delete from fs_course_red_packet_log where log_id in
  155. <foreach item="logId" collection="array" open="(" separator="," close=")">
  156. #{logId}
  157. </foreach>
  158. </delete>
  159. <!-- 查询新用户红包金额总和 -->
  160. <select id="getNewVipRedPackAmountByCompanyUserIdId" resultType="java.math.BigDecimal">
  161. select
  162. ifnull(sum(fcrpl.amount), 0)
  163. from fs_course_red_packet_log fcrpl
  164. inner join fs_user fu on fu.user_id = fcrpl.user_id and date(fu.create_time) = CURDATE()
  165. where fcrpl.company_user_id = #{companyUserId}
  166. </select>
  167. </mapper>