FsCourseRedPacketLogMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. <result property="mchId" column="mch_id" />
  26. </resultMap>
  27. <sql id="selectFsCourseRedPacketLogVo">
  28. select log_id,watch_log_id,mch_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
  29. </sql>
  30. <select id="selectFsCourseRedPacketLogList" parameterType="FsCourseRedPacketLog" resultMap="FsCourseRedPacketLogResult">
  31. <include refid="selectFsCourseRedPacketLogVo"/>
  32. <where>
  33. <if test="courseId != null "> and course_id = #{courseId}</if>
  34. <if test="userId != null "> and user_id = #{userId}</if>
  35. <if test="videoId != null "> and video_id = #{videoId}</if>
  36. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  37. <if test="companyId != null "> and company_id = #{companyId}</if>
  38. <if test="amount != null "> and amount = #{amount}</if>
  39. <if test="status != null "> and `status` = #{status}</if>
  40. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  41. <if test="beginTime != null "> and create_time &gt;= #{beginTime}</if>
  42. <if test="endTime != null "> and create_time &lt;= #{endTime}</if>
  43. </where>
  44. </select>
  45. <select id="selectFsCourseRedPacketLogByLogId" parameterType="Long" resultMap="FsCourseRedPacketLogResult">
  46. <include refid="selectFsCourseRedPacketLogVo"/>
  47. where log_id = #{logId}
  48. </select>
  49. <select id="selectFsCourseRedPacketLogListVONew" resultType="com.fs.course.vo.FsCourseRedPacketLogListPVO">
  50. select
  51. watch.log_id,
  52. watch.user_id,
  53. uc.course_name,
  54. v.title as video_name,
  55. watch.log_type,
  56. watch.qw_external_contact_id,
  57. watch.qw_user_id,
  58. watch.course_id,
  59. watch.send_type,
  60. watch.video_id,
  61. l.create_time,
  62. SEC_TO_TIME(watch.duration) duration,
  63. l.amount,
  64. l.status,
  65. l.out_batch_no,
  66. 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
  67. from fs_course_watch_log watch
  68. left join fs_course_red_packet_log l on watch.user_id = l.user_id and watch.video_id = l.video_id
  69. left join fs_user_course_video v on v.video_id = watch.video_id
  70. left join fs_user_course uc on uc.course_id = l.course_id
  71. left join fs_user u on u.user_id = watch.user_id
  72. left join company_user cu on cu.user_id=watch.company_user_id
  73. left join company c on c.company_id=watch.company_id
  74. LEFT JOIN qw_user qu on qu.id= watch.qw_user_id
  75. <where>
  76. <if test = ' userId !=null '> and watch.user_id = #{userId} </if>
  77. <if test = ' companyId !=null '> and watch.company_id = #{companyId} </if>
  78. <if test = ' companyUserName !=null '> and cu.nick_name like concat('%', #{companyUserName}, '%') </if>
  79. <if test = ' nickName !=null '> and u.nick_name like concat('%', #{nickName}, '%') </if>
  80. <if test = ' courseId !=null '> and watch.course_id = #{courseId} </if>
  81. <if test = ' videoId !=null '> and watch.video_id = #{videoId} </if>
  82. <if test = ' status !=null '> and l.status = #{status} </if>
  83. <if test = ' logType !=null '> and watch.log_type = #{logType} </if>
  84. <if test = ' phone !=null '> and u.phone = #{phone} </if>
  85. <if test = ' qwUserId !=null '> and watch.qw_user_id = #{qwUserId} </if>
  86. <if test="sTime != null"> and DATE(watch.create_time) &gt;= DATE(#{sTime})</if>
  87. <if test="eTime != null"> and DATE(watch.create_time) &lt;= DATE(#{eTime})</if>
  88. </where>
  89. order by watch.log_id desc
  90. </select>
  91. <insert id="insertFsCourseRedPacketLog" parameterType="FsCourseRedPacketLog" useGeneratedKeys="true" keyProperty="logId">
  92. insert into fs_course_red_packet_log
  93. <trim prefix="(" suffix=")" suffixOverrides=",">
  94. <if test="courseId != null">course_id,</if>
  95. <if test="userId != null">user_id,</if>
  96. <if test="videoId != null">video_id,</if>
  97. <if test="companyUserId != null">company_user_id,</if>
  98. <if test="companyId != null">company_id,</if>
  99. <if test="amount != null">amount,</if>
  100. <if test="createTime != null">create_time,</if>
  101. <if test="qwUserId != null">qw_user_id,</if>
  102. <if test="outBatchNo != null">out_batch_no,</if>
  103. <if test="status != null">status,</if>
  104. <if test="updateTime != null">update_time,</if>
  105. <if test="watchLogId != null">watch_log_id,</if>
  106. <if test="remark != null">remark,</if>
  107. <if test="periodId != null">period_id,</if>
  108. <if test="result != null">result,</if>
  109. <if test="batchId != null">batch_id,</if>
  110. <if test="appId != null">app_id,</if>
  111. <if test="accBalanceBefore != null">acc_balance_before,</if>
  112. <if test="accBalanceAfter != null">acc_balance_after,</if>
  113. <if test="mchId != null">mch_id,</if>
  114. <if test="watchType != null">watch_type,</if>
  115. </trim>
  116. <trim prefix="values (" suffix=")" suffixOverrides=",">
  117. <if test="courseId != null">#{courseId},</if>
  118. <if test="userId != null">#{userId},</if>
  119. <if test="videoId != null">#{videoId},</if>
  120. <if test="companyUserId != null">#{companyUserId},</if>
  121. <if test="companyId != null">#{companyId},</if>
  122. <if test="amount != null">#{amount},</if>
  123. <if test="createTime != null">#{createTime},</if>
  124. <if test="qwUserId != null">#{qwUserId},</if>
  125. <if test="outBatchNo != null">#{outBatchNo},</if>
  126. <if test="status != null">#{status},</if>
  127. <if test="updateTime != null">#{updateTime},</if>
  128. <if test="watchLogId != null">#{watchLogId},</if>
  129. <if test="remark != null">#{remark},</if>
  130. <if test="periodId != null">#{periodId},</if>
  131. <if test="result != null">#{result},</if>
  132. <if test="batchId != null">#{batchId},</if>
  133. <if test="appId != null">#{appId},</if>
  134. <if test="accBalanceBefore != null">#{accBalanceBefore},</if>
  135. <if test="accBalanceAfter != null">#{accBalanceAfter},</if>
  136. <if test="mchId != null">#{mchId},</if>
  137. <if test="watchType != null">#{watchType},</if>
  138. </trim>
  139. </insert>
  140. <update id="updateFsCourseRedPacketLog" parameterType="FsCourseRedPacketLog">
  141. update fs_course_red_packet_log
  142. <trim prefix="SET" suffixOverrides=",">
  143. <if test="courseId != null">course_id = #{courseId},</if>
  144. <if test="userId != null">user_id = #{userId},</if>
  145. <if test="videoId != null">video_id = #{videoId},</if>
  146. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  147. <if test="companyId != null">company_id = #{companyId},</if>
  148. <if test="amount != null">amount = #{amount},</if>
  149. <if test="createTime != null">create_time = #{createTime},</if>
  150. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  151. <if test="outBatchNo != null">out_batch_no = #{outBatchNo},</if>
  152. <if test="status != null">status = #{status},</if>
  153. <if test="updateTime != null">update_time = #{updateTime},</if>
  154. <if test="watchLogId != null">watch_log_id = #{watchLogId},</if>
  155. <if test="periodId != null">period_id = #{periodId},</if>
  156. <if test="remark != null">remark = #{remark},</if>
  157. <if test="batchId != null">batch_id = #{batchId},</if>
  158. <if test="appId != null">app_id = #{appId},</if>
  159. <if test="mchId != null">mch_id = #{mchId},</if>
  160. </trim>
  161. where log_id = #{logId}
  162. </update>
  163. <delete id="deleteFsCourseRedPacketLogByLogId" parameterType="Long">
  164. delete from fs_course_red_packet_log where log_id = #{logId}
  165. </delete>
  166. <delete id="deleteFsCourseRedPacketLogByLogIds" parameterType="String">
  167. delete from fs_course_red_packet_log where log_id in
  168. <foreach item="logId" collection="array" open="(" separator="," close=")">
  169. #{logId}
  170. </foreach>
  171. </delete>
  172. <!-- 查询新用户红包金额总和 -->
  173. <select id="getNewVipRedPackAmountByCompanyUserIdId" resultType="java.math.BigDecimal">
  174. select
  175. ifnull(sum(fcrpl.amount), 0)
  176. from fs_course_red_packet_log fcrpl
  177. inner join fs_user fu on fu.user_id = fcrpl.user_id and date(fu.create_time) = CURDATE()
  178. where fcrpl.company_user_id = #{companyUserId}
  179. </select>
  180. <select id="selectFsCourseRedPacketLogHourseByCompany" resultType="com.fs.company.vo.RedPacketMoneyVO">
  181. SELECT a.company_id, SUM(amount) as money FROM fs_course_red_packet_log a WHERE a.create_time &gt;= #{startTime} AND a.create_time &lt;= #{endTime} GROUP BY a.company_id
  182. </select>
  183. <!-- 看客红包统计 -->
  184. <select id="statistics" resultType="com.fs.course.dto.CourseRedPacketStatisticsDTO">
  185. select c.company_name,cu.nick_name,pl.company_user_id,cu.company_id,sum(pl.amount) as redPacketTotalMoney,count(pl.log_id) as redPacketNum from fs_course_red_packet_log pl
  186. left join company_user cu on pl.company_user_id = cu.user_id
  187. left join company c on cu.company_id=c.company_id
  188. <where>
  189. <if test="companyId != null">
  190. and cu.company_id = #{companyId}
  191. </if>
  192. <if test="companyUserId != null">
  193. and pl.company_user_id = #{companyUserId}
  194. </if>
  195. <if test="status != null">
  196. and pl.status = #{status}
  197. </if>
  198. <if test="startTime != null">
  199. and date_format(pl.create_time,'%Y-%m-%d') &gt;= date_format(#{startTime},'%Y-%m-%d')
  200. </if>
  201. <if test="endTime != null">
  202. and date_format(pl.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  203. </if>
  204. </where>
  205. group by pl.company_user_id order by c.company_name
  206. </select>
  207. <!-- 获取当前时间前十分钟到前二十分钟红包记录状态为发送中的记录 -->
  208. <select id="selectFsCourseRedPacketLogListBySending"
  209. resultType="com.fs.course.domain.FsCourseRedPacketLog">
  210. <include refid="selectFsCourseRedPacketLogVo"/> where status != 1 and create_time &gt;= #{maps.startTime} and create_time &lt;= #{maps.endTime}
  211. </select>
  212. <select id="selectFsCourseRedPacketLogListCountVO"
  213. resultType="com.fs.course.vo.FsCourseRedPacketLogListVO">
  214. SELECT
  215. <if test="maps.changeType == 2">
  216. l.company_user_id,
  217. cu.nick_name,
  218. cu.dept_id,
  219. cd.dept_name,
  220. </if>
  221. c.company_name,
  222. l.company_id,
  223. sum(l.amount) AS amount,
  224. l.create_time AS createTime
  225. FROM
  226. fs_course_red_packet_log l
  227. INNER JOIN company c ON c.company_id = l.company_id
  228. LEFT JOIN company_user cu on l.company_user_id=cu.user_id
  229. LEFT JOIN company_dept cd on cu.dept_id=cd.dept_id
  230. WHERE 1=1
  231. and l.create_time &gt;= #{maps.sTime}
  232. AND l.create_time &lt;#{maps.eTime}
  233. AND l.STATUS = 1
  234. <if test="maps.companyIds != null and maps.companyIds.size() > 0 and maps.changeType == 1 ">
  235. AND l.company_id IN
  236. <foreach collection="maps.companyIds" open="(" close=")" separator="," item="item">
  237. ${item}
  238. </foreach>
  239. </if>
  240. <if test="maps.courseId != null ">
  241. AND l.course_id = #{maps.courseId}
  242. </if>
  243. <if test="maps.courseId != null ">
  244. AND l.videoId = #{maps.videoId}
  245. </if>
  246. <if test="maps.status != null">
  247. and l.status = #{maps.status}
  248. </if>
  249. <if test="maps.userIds != null and maps.userIds.size() > 0 and maps.changeType == 2 ">
  250. AND l.company_user_id IN
  251. <foreach collection="maps.userIds" open="(" close=")" separator="," item="item">
  252. ${item}
  253. </foreach>
  254. </if>
  255. GROUP BY
  256. <choose>
  257. <when test="maps.companyIds != null and maps.changeType == 1 ">
  258. l.company_id
  259. </when>
  260. <when test="maps.userIds != null and maps.userIds.size() > 0 and maps.changeType == 2 ">
  261. l.company_id, l.company_user_id
  262. </when>
  263. <otherwise>
  264. l.company_id, l.company_user_id <!-- 默认分组方式 -->
  265. </otherwise>
  266. </choose>
  267. </select>
  268. <select id="getTodaySumAmountByCompanyUserId" resultType="java.math.BigDecimal">
  269. select
  270. ifnull(sum(amount), 0)
  271. from fs_course_red_packet_log
  272. where company_user_id = #{companyUserId}
  273. and create_time &gt;= CONCAT(CURDATE(), ' 00:00:00')
  274. and create_time &lt;= CONCAT(CURDATE(), ' 23:59:59')
  275. </select>
  276. <select id="selectAppSalesRedPacketStatisticsVO" resultType="com.fs.his.vo.AppSalesCourseStatisticsVO">
  277. select rpl.company_user_id,rpl.course_id,rpl.video_id,
  278. sum(rpl.log_id) as redPacketCount,
  279. sum(rpl.amount) as redPacketAmount
  280. from fs_course_red_packet_log rpl
  281. where rpl.watch_type = 1
  282. <if test="companyId != null ">
  283. and rpl.company_id = #{companyId}
  284. </if>
  285. <if test="companyUserId != null ">
  286. and rpl.company_user_id = #{companyUserId}
  287. </if>
  288. <if test="courseId != null ">
  289. and rpl.course_id = #{courseId}
  290. </if>
  291. <if test="videoId != null ">
  292. and rpl.video_id = #{videoId}
  293. </if>
  294. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  295. and rpl.create_time &gt;= #{startDate} and rpl.create_time &lt;= #{endDate}
  296. </if>
  297. group by rpl.company_user_id,rpl.course_id,rpl.video_id
  298. </select>
  299. <insert id="batchInsert" parameterType="java.util.List">
  300. insert into fs_course_red_packet_log_1
  301. (
  302. log_id,
  303. course_id,
  304. user_id,
  305. video_id,
  306. company_user_id,
  307. company_id,
  308. amount,
  309. create_time,
  310. qw_user_id,
  311. out_batch_no,
  312. status,
  313. update_time,
  314. watch_log_id,
  315. remark,
  316. period_id,
  317. result,
  318. batch_id,
  319. app_id,
  320. acc_balance_before,
  321. acc_balance_after,
  322. mch_id
  323. )
  324. VALUES
  325. <foreach collection="list" item="log" separator=",">
  326. (
  327. #{log.logId},
  328. #{log.courseId},
  329. #{log.userId},
  330. #{log.videoId},
  331. #{log.companyUserId},
  332. #{log.companyId},
  333. #{log.amount},
  334. #{log.createTime},
  335. #{log.qwUserId},
  336. #{log.outBatchNo},
  337. #{log.status},
  338. #{log.updateTime},
  339. #{log.watchLogId},
  340. #{log.remark},
  341. #{log.periodId},
  342. #{log.result},
  343. #{log.batchId},
  344. #{log.appId},
  345. #{log.accBalanceBefore},
  346. #{log.accBalanceAfter},
  347. #{log.mchId}
  348. )
  349. </foreach>
  350. </insert>
  351. <delete id="batchDeleteByIds" parameterType="java.util.List">
  352. DELETE FROM fs_course_red_packet_log
  353. WHERE log_id IN
  354. <foreach collection="ids" item="id" open="(" separator="," close=")">
  355. #{id}
  356. </foreach>
  357. </delete>
  358. </mapper>