FsStatisQwWatchMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fs.statis.mapper.FsStatisQwWatchMapper">
  4. <resultMap id="BaseResultMap" type="com.fs.statis.domain.FsStatisQwWatch">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="dept_id" jdbcType="BIGINT" property="deptId" />
  7. <result column="company_user_id" jdbcType="BIGINT" property="companyUserId" />
  8. <result column="qw_user_id" jdbcType="VARCHAR" property="qwUserId" />
  9. <result column="sop_task_num" jdbcType="BIGINT" property="sopTaskNum" />
  10. <result column="period_num" jdbcType="BIGINT" property="periodNum" />
  11. <result column="period_person_num" jdbcType="BIGINT" property="periodPersonNum" />
  12. <result column="completed_num" jdbcType="BIGINT" property="completedNum" />
  13. <result column="data_date" jdbcType="DATE" property="dataDate" />
  14. <result column="send_num" jdbcType="BIGINT" property="sendNum" />
  15. <result column="not_registered_num" jdbcType="BIGINT" property="notRegisteredNum" />
  16. <result column="interrupt_num" jdbcType="BIGINT" property="interruptNum" />
  17. <result column="registered_num" jdbcType="BIGINT" property="registeredNum" />
  18. <result column="qw_repeat_num" jdbcType="BIGINT" property="qwRepeatNum" />
  19. <result column="user_repeat_num" jdbcType="BIGINT" property="userRepeatNum" />
  20. <result column="black_num" jdbcType="BIGINT" property="blackNum" />
  21. <result column="deleted_num" jdbcType="BIGINT" property="deletedNum" />
  22. <result column="order_num" jdbcType="BIGINT" property="orderNum" />
  23. <result column="order_money_total" jdbcType="DECIMAL" property="orderMoneyTotal" />
  24. <result column="red_package_money_total" jdbcType="DECIMAL" property="redPackageMoneyTotal" />
  25. <result column="call_num" jdbcType="BIGINT" property="callNum" />
  26. <result column="receive_pass_num" jdbcType="BIGINT" property="receivePassNum" />
  27. <result column="receive_not_num" jdbcType="BIGINT" property="receiveNotNum" />
  28. <result column="call_time_total" jdbcType="BIGINT" property="callTimeTotal" />
  29. <result column="remind_pending_num" jdbcType="BIGINT" property="remindPendingNum" />
  30. <result column="remind_processed_num" jdbcType="BIGINT" property="remindProcessedNum" />
  31. <result column="reg_rate" jdbcType="DECIMAL" property="regRate" />
  32. <result column="finished_rate" jdbcType="DECIMAL" property="finishedRate" />
  33. </resultMap>
  34. <sql id="Base_Column_List">
  35. id, dept_id, company_user_id, qw_user_id, sop_task_num, period_num, period_person_num,
  36. completed_num, data_date, send_num, not_registered_num, interrupt_num, registered_num,
  37. qw_repeat_num, user_repeat_num, black_num, deleted_num, order_num, order_money_total,
  38. red_package_money_total, call_num, receive_pass_num, receive_not_num, call_time_total,
  39. remind_pending_num, remind_processed_num, reg_rate, finished_rate
  40. </sql>
  41. <!-- Columns that can be inserted (excludes auto-increment and generated columns) -->
  42. <sql id="Insert_Column_List">
  43. dept_id, company_user_id, qw_user_id, sop_task_num, period_num, period_person_num,
  44. completed_num, data_date, send_num, not_registered_num, interrupt_num, qw_repeat_num,
  45. user_repeat_num, black_num, deleted_num, order_num, order_money_total,
  46. red_package_money_total, call_num, receive_pass_num, receive_not_num, call_time_total,
  47. remind_pending_num, remind_processed_num
  48. </sql>
  49. <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
  50. select
  51. <include refid="Base_Column_List" />
  52. from fs_statis_qw_watch
  53. where id = #{id,jdbcType=BIGINT}
  54. </select>
  55. <select id="selectByUniqueKey" resultMap="BaseResultMap">
  56. select
  57. <include refid="Base_Column_List" />
  58. from fs_statis_qw_watch
  59. where dept_id = #{deptId,jdbcType=BIGINT}
  60. and company_user_id = #{companyUserId,jdbcType=BIGINT}
  61. and qw_user_id = #{qwUserId,jdbcType=VARCHAR}
  62. and data_date = #{dataDate,jdbcType=DATE}
  63. </select>
  64. <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
  65. delete from fs_statis_qw_watch
  66. where id = #{id,jdbcType=BIGINT}
  67. </delete>
  68. <insert id="insert" keyProperty="id" useGeneratedKeys="true" parameterType="com.fs.statis.domain.FsStatisQwWatch">
  69. insert into fs_statis_qw_watch (
  70. <include refid="Insert_Column_List" />
  71. )
  72. values (
  73. #{deptId,jdbcType=BIGINT}, #{companyUserId,jdbcType=BIGINT}, #{qwUserId,jdbcType=VARCHAR},
  74. #{sopTaskNum,jdbcType=BIGINT}, #{periodNum,jdbcType=BIGINT}, #{periodPersonNum,jdbcType=BIGINT},
  75. #{completedNum,jdbcType=BIGINT}, #{dataDate,jdbcType=DATE}, #{sendNum,jdbcType=BIGINT},
  76. #{notRegisteredNum,jdbcType=BIGINT}, #{interruptNum,jdbcType=BIGINT},
  77. #{qwRepeatNum,jdbcType=BIGINT}, #{userRepeatNum,jdbcType=BIGINT}, #{blackNum,jdbcType=BIGINT},
  78. #{deletedNum,jdbcType=BIGINT}, #{orderNum,jdbcType=BIGINT}, #{orderMoneyTotal,jdbcType=DECIMAL},
  79. #{redPackageMoneyTotal,jdbcType=DECIMAL}, #{callNum,jdbcType=BIGINT}, #{receivePassNum,jdbcType=BIGINT},
  80. #{receiveNotNum,jdbcType=BIGINT}, #{callTimeTotal,jdbcType=BIGINT}, #{remindPendingNum,jdbcType=BIGINT},
  81. #{remindProcessedNum,jdbcType=BIGINT}
  82. )
  83. </insert>
  84. <insert id="insertSelective" keyProperty="id" useGeneratedKeys="true" parameterType="com.fs.statis.domain.FsStatisQwWatch">
  85. insert into fs_statis_qw_watch
  86. <trim prefix="(" suffix=")" suffixOverrides=",">
  87. <if test="deptId != null">dept_id,</if>
  88. <if test="companyUserId != null">company_user_id,</if>
  89. <if test="qwUserId != null">qw_user_id,</if>
  90. <if test="sopTaskNum != null">sop_task_num,</if>
  91. <if test="periodNum != null">period_num,</if>
  92. <if test="periodPersonNum != null">period_person_num,</if>
  93. <if test="completedNum != null">completed_num,</if>
  94. <if test="dataDate != null">data_date,</if>
  95. <if test="sendNum != null">send_num,</if>
  96. <if test="notRegisteredNum != null">not_registered_num,</if>
  97. <if test="interruptNum != null">interrupt_num,</if>
  98. <if test="qwRepeatNum != null">qw_repeat_num,</if>
  99. <if test="userRepeatNum != null">user_repeat_num,</if>
  100. <if test="blackNum != null">black_num,</if>
  101. <if test="deletedNum != null">deleted_num,</if>
  102. <if test="orderNum != null">order_num,</if>
  103. <if test="orderMoneyTotal != null">order_money_total,</if>
  104. <if test="redPackageMoneyTotal != null">red_package_money_total,</if>
  105. <if test="callNum != null">call_num,</if>
  106. <if test="receivePassNum != null">receive_pass_num,</if>
  107. <if test="receiveNotNum != null">receive_not_num,</if>
  108. <if test="callTimeTotal != null">call_time_total,</if>
  109. <if test="remindPendingNum != null">remind_pending_num,</if>
  110. <if test="remindProcessedNum != null">remind_processed_num,</if>
  111. </trim>
  112. <trim prefix="values (" suffix=")" suffixOverrides=",">
  113. <if test="deptId != null">#{deptId,jdbcType=BIGINT},</if>
  114. <if test="companyUserId != null">#{companyUserId,jdbcType=BIGINT},</if>
  115. <if test="qwUserId != null">#{qwUserId,jdbcType=VARCHAR},</if>
  116. <if test="sopTaskNum != null">#{sopTaskNum,jdbcType=BIGINT},</if>
  117. <if test="periodNum != null">#{periodNum,jdbcType=BIGINT},</if>
  118. <if test="periodPersonNum != null">#{periodPersonNum,jdbcType=BIGINT},</if>
  119. <if test="completedNum != null">#{completedNum,jdbcType=BIGINT},</if>
  120. <if test="dataDate != null">#{dataDate,jdbcType=DATE},</if>
  121. <if test="sendNum != null">#{sendNum,jdbcType=BIGINT},</if>
  122. <if test="notRegisteredNum != null">#{notRegisteredNum,jdbcType=BIGINT},</if>
  123. <if test="interruptNum != null">#{interruptNum,jdbcType=BIGINT},</if>
  124. <if test="qwRepeatNum != null">#{qwRepeatNum,jdbcType=BIGINT},</if>
  125. <if test="userRepeatNum != null">#{userRepeatNum,jdbcType=BIGINT},</if>
  126. <if test="blackNum != null">#{blackNum,jdbcType=BIGINT},</if>
  127. <if test="deletedNum != null">#{deletedNum,jdbcType=BIGINT},</if>
  128. <if test="orderNum != null">#{orderNum,jdbcType=BIGINT},</if>
  129. <if test="orderMoneyTotal != null">#{orderMoneyTotal,jdbcType=DECIMAL},</if>
  130. <if test="redPackageMoneyTotal != null">#{redPackageMoneyTotal,jdbcType=DECIMAL},</if>
  131. <if test="callNum != null">#{callNum,jdbcType=BIGINT},</if>
  132. <if test="receivePassNum != null">#{receivePassNum,jdbcType=BIGINT},</if>
  133. <if test="receiveNotNum != null">#{receiveNotNum,jdbcType=BIGINT},</if>
  134. <if test="callTimeTotal != null">#{callTimeTotal,jdbcType=BIGINT},</if>
  135. <if test="remindPendingNum != null">#{remindPendingNum,jdbcType=BIGINT},</if>
  136. <if test="remindProcessedNum != null">#{remindProcessedNum,jdbcType=BIGINT},</if>
  137. </trim>
  138. </insert>
  139. <update id="updateByPrimaryKeySelective" parameterType="com.fs.statis.domain.FsStatisQwWatch">
  140. update fs_statis_qw_watch
  141. <set>
  142. <if test="deptId != null">dept_id = #{deptId,jdbcType=BIGINT},</if>
  143. <if test="companyUserId != null">company_user_id = #{companyUserId,jdbcType=BIGINT},</if>
  144. <if test="qwUserId != null">qw_user_id = #{qwUserId,jdbcType=VARCHAR},</if>
  145. <if test="sopTaskNum != null">sop_task_num = #{sopTaskNum,jdbcType=BIGINT},</if>
  146. <if test="periodNum != null">period_num = #{periodNum,jdbcType=BIGINT},</if>
  147. <if test="periodPersonNum != null">period_person_num = #{periodPersonNum,jdbcType=BIGINT},</if>
  148. <if test="completedNum != null">completed_num = #{completedNum,jdbcType=BIGINT},</if>
  149. <if test="dataDate != null">data_date = #{dataDate,jdbcType=DATE},</if>
  150. <if test="sendNum != null">send_num = #{sendNum,jdbcType=BIGINT},</if>
  151. <if test="notRegisteredNum != null">not_registered_num = #{notRegisteredNum,jdbcType=BIGINT},</if>
  152. <if test="interruptNum != null">interrupt_num = #{interruptNum,jdbcType=BIGINT},</if>
  153. <if test="qwRepeatNum != null">qw_repeat_num = #{qwRepeatNum,jdbcType=BIGINT},</if>
  154. <if test="userRepeatNum != null">user_repeat_num = #{userRepeatNum,jdbcType=BIGINT},</if>
  155. <if test="blackNum != null">black_num = #{blackNum,jdbcType=BIGINT},</if>
  156. <if test="deletedNum != null">deleted_num = #{deletedNum,jdbcType=BIGINT},</if>
  157. <if test="orderNum != null">order_num = #{orderNum,jdbcType=BIGINT},</if>
  158. <if test="orderMoneyTotal != null">order_money_total = #{orderMoneyTotal,jdbcType=DECIMAL},</if>
  159. <if test="redPackageMoneyTotal != null">red_package_money_total = #{redPackageMoneyTotal,jdbcType=DECIMAL},</if>
  160. <if test="callNum != null">call_num = #{callNum,jdbcType=BIGINT},</if>
  161. <if test="receivePassNum != null">receive_pass_num = #{receivePassNum,jdbcType=BIGINT},</if>
  162. <if test="receiveNotNum != null">receive_not_num = #{receiveNotNum,jdbcType=BIGINT},</if>
  163. <if test="callTimeTotal != null">call_time_total = #{callTimeTotal,jdbcType=BIGINT},</if>
  164. <if test="remindPendingNum != null">remind_pending_num = #{remindPendingNum,jdbcType=BIGINT},</if>
  165. <if test="remindProcessedNum != null">remind_processed_num = #{remindProcessedNum,jdbcType=BIGINT},</if>
  166. </set>
  167. where id = #{id,jdbcType=BIGINT}
  168. </update>
  169. <update id="updateByPrimaryKey" parameterType="com.fs.statis.domain.FsStatisQwWatch">
  170. update fs_statis_qw_watch
  171. set dept_id = #{deptId,jdbcType=BIGINT},
  172. company_user_id = #{companyUserId,jdbcType=BIGINT},
  173. qw_user_id = #{qwUserId,jdbcType=VARCHAR},
  174. sop_task_num = #{sopTaskNum,jdbcType=BIGINT},
  175. period_num = #{periodNum,jdbcType=BIGINT},
  176. period_person_num = #{periodPersonNum,jdbcType=BIGINT},
  177. completed_num = #{completedNum,jdbcType=BIGINT},
  178. data_date = #{dataDate,jdbcType=DATE},
  179. send_num = #{sendNum,jdbcType=BIGINT},
  180. not_registered_num = #{notRegisteredNum,jdbcType=BIGINT},
  181. interrupt_num = #{interruptNum,jdbcType=BIGINT},
  182. qw_repeat_num = #{qwRepeatNum,jdbcType=BIGINT},
  183. user_repeat_num = #{userRepeatNum,jdbcType=BIGINT},
  184. black_num = #{blackNum,jdbcType=BIGINT},
  185. deleted_num = #{deletedNum,jdbcType=BIGINT},
  186. order_num = #{orderNum,jdbcType=BIGINT},
  187. order_money_total = #{orderMoneyTotal,jdbcType=DECIMAL},
  188. red_package_money_total = #{redPackageMoneyTotal,jdbcType=DECIMAL},
  189. call_num = #{callNum,jdbcType=BIGINT},
  190. receive_pass_num = #{receivePassNum,jdbcType=BIGINT},
  191. receive_not_num = #{receiveNotNum,jdbcType=BIGINT},
  192. call_time_total = #{callTimeTotal,jdbcType=BIGINT},
  193. remind_pending_num = #{remindPendingNum,jdbcType=BIGINT},
  194. remind_processed_num = #{remindProcessedNum,jdbcType=BIGINT}
  195. where id = #{id,jdbcType=BIGINT}
  196. </update>
  197. <select id="selectList" parameterType="com.fs.statis.domain.FsStatisQwWatch" resultMap="BaseResultMap">
  198. select
  199. <include refid="Base_Column_List" />
  200. from fs_statis_qw_watch
  201. <where>
  202. <if test="deptId != null">and dept_id = #{deptId,jdbcType=BIGINT}</if>
  203. <if test="companyUserId != null">and company_user_id = #{companyUserId,jdbcType=BIGINT}</if>
  204. <if test="qwUserId != null and qwUserId != ''">and qw_user_id = #{qwUserId,jdbcType=VARCHAR}</if>
  205. <if test="dataDate != null">and data_date = #{dataDate,jdbcType=DATE}</if>
  206. <!-- Add other conditions as needed -->
  207. </where>
  208. <!-- Add order by or limit clauses if necessary -->
  209. </select>
  210. <select id="queryList" resultType="com.fs.statis.domain.FsStatisQwWatch">
  211. select
  212. dept_id,
  213. company_user_id,
  214. qw_user_id,
  215. ifnull(sum(sop_task_num),0) as sop_task_num,
  216. ifnull(sum(period_num),0) as period_num,
  217. ifnull(sum(period_person_num),0) as period_person_num,
  218. ifnull(sum(completed_num),0) as completed_num,
  219. ifnull(sum(send_num),0) as send_num,
  220. ifnull(sum(not_registered_num),0) as not_registered_num,
  221. ifnull(sum(interrupt_num),0) as interrupt_num,
  222. ifnull(sum(registered_num),0) as registered_num,
  223. ifnull(sum(qw_repeat_num),0) as qw_repeat_num,
  224. ifnull(sum(user_repeat_num),0) as user_repeat_num,
  225. ifnull(sum(black_num),0) as black_num,
  226. ifnull(sum(deleted_num),0) as deleted_num,
  227. ifnull(sum(order_num),0) as order_num,
  228. ifnull(sum(order_money_total),0) as order_money_total,
  229. ifnull(sum(red_package_money_total),0) as red_package_money_total,
  230. ifnull(sum(call_num),0) as call_num,
  231. ifnull(sum(receive_pass_num),0) as receive_pass_num,
  232. ifnull(sum(receive_not_num),0) as receive_not_num,
  233. ifnull(sum(call_time_total),0) as call_time_total,
  234. ifnull(sum(remind_pending_num),0) as remind_pending_num,
  235. ifnull(sum(remind_processed_num),0) as remind_processed_num,
  236. (case when sum(send_num)>=sum(registered_num) then ROUND(SUM(registered_num) * 1.0 / SUM(send_num), 4) else 0 end) as reg_rate,
  237. (case when sum(send_num)>=sum(completed_num) then ROUND(SUM(completed_num) * 1.0 / SUM(send_num), 4) else 0 end) as finished_rate,
  238. ifnull(sum(traffic_sum,0)) as traffic_sum,
  239. ifnull(sum(reg_num,0)) as reg_num
  240. from fs_statis_qw_watch
  241. <where>
  242. <if test="startDate != null and endDate != null">
  243. AND data_date between #{startDate} and #{endDate}
  244. </if>
  245. <if test="userIds != null and userIds.size() > 0">
  246. AND company_user_id in
  247. <foreach collection="userIds" item="item" open="(" close=")" separator=",">
  248. #{item}
  249. </foreach>
  250. </if>
  251. </where>
  252. group by company_user_id
  253. </select>
  254. <select id="exportList" resultType="com.fs.statis.domain.FsStatisQwWatch">
  255. select
  256. any_value(watch.dept_id),
  257. concat(dept.dept_id,'_',dept.dept_name) as dept_name,
  258. watch.company_user_id,
  259. concat(cu.user_id,'_',cu.user_name) as company_user_name,
  260. ifnull(sum(watch.sop_task_num),0) as sop_task_num,
  261. ifnull(sum(watch.period_num),0) as period_num,
  262. ifnull(sum(watch.period_person_num),0) as period_person_num,
  263. ifnull(sum(watch.completed_num),0) as completed_num,
  264. ifnull(sum(watch.send_num),0) as send_num,
  265. ifnull(sum(watch.not_registered_num),0) as not_registered_num,
  266. ifnull(sum(watch.interrupt_num),0) as interrupt_num,
  267. ifnull(sum(watch.registered_num),0) as registered_num,
  268. ifnull(sum(watch.qw_repeat_num),0) as qw_repeat_num,
  269. ifnull(sum(watch.user_repeat_num),0) as user_repeat_num,
  270. ifnull(sum(watch.black_num),0) as black_num,
  271. ifnull(sum(watch.deleted_num),0) as deleted_num,
  272. ifnull(sum(watch.order_num),0) as order_num,
  273. ifnull(sum(watch.order_money_total),0) as order_money_total,
  274. ifnull(sum(watch.red_package_money_total),0) as red_package_money_total,
  275. ifnull(sum(watch.call_num),0) as call_num,
  276. ifnull(sum(watch.receive_pass_num),0) as receive_pass_num,
  277. ifnull(sum(watch.receive_not_num),0) as receive_not_num,
  278. ifnull(sum(watch.call_time_total),0) as call_time_total,
  279. ifnull(sum(watch.remind_pending_num),0) as remind_pending_num,
  280. ifnull(sum(watch.remind_processed_num),0) as remind_processed_num,
  281. (case when sum(watch.send_num)>=sum(watch.registered_num) then ROUND(SUM(watch.registered_num) * 1.0 / SUM(watch.send_num), 4) else 0 end) as reg_rate,
  282. (case when sum(watch.send_num)>=sum(watch.completed_num) then ROUND(SUM(watch.completed_num) * 1.0 / SUM(watch.send_num), 4) else 0 end) as finished_rate,
  283. ifnull(sum(traffic_sum,0)) as traffic_sum,
  284. ifnull(sum(reg_num,0)) as reg_num
  285. from fs_statis_qw_watch watch
  286. left join company_dept dept on watch.dept_id=dept.dept_id
  287. left join company_user cu on watch.company_user_id=cu.user_id
  288. <where>
  289. <if test="startDate != null and endDate != null">
  290. AND watch.data_date between #{startDate} and #{endDate}
  291. </if>
  292. <if test="userIds != null and userIds.size() > 0">
  293. AND watch.company_user in
  294. <foreach collection="userIds" item="item" open="(" close=")" separator=",">
  295. #{item}
  296. </foreach>
  297. </if>
  298. </where>
  299. group by watch.company_user_id
  300. </select>
  301. <insert id="batchInsert" parameterType="java.util.List">
  302. replace into fs_statis_qw_watch (
  303. <include refid="Insert_Column_List" />
  304. )
  305. values
  306. <foreach collection="list" item="item" index="index" separator=",">
  307. (
  308. #{item.deptId,jdbcType=BIGINT}, #{item.companyUserId,jdbcType=BIGINT}, #{item.qwUserId,jdbcType=VARCHAR},
  309. #{item.sopTaskNum,jdbcType=BIGINT}, #{item.periodNum,jdbcType=BIGINT}, #{item.periodPersonNum,jdbcType=BIGINT},
  310. #{item.completedNum,jdbcType=BIGINT}, #{item.dataDate,jdbcType=DATE}, #{item.sendNum,jdbcType=BIGINT},
  311. #{item.notRegisteredNum,jdbcType=BIGINT}, #{item.interruptNum,jdbcType=BIGINT},
  312. #{item.qwRepeatNum,jdbcType=BIGINT}, #{item.userRepeatNum,jdbcType=BIGINT}, #{item.blackNum,jdbcType=BIGINT},
  313. #{item.deletedNum,jdbcType=BIGINT}, #{item.orderNum,jdbcType=BIGINT}, #{item.orderMoneyTotal,jdbcType=DECIMAL},
  314. #{item.redPackageMoneyTotal,jdbcType=DECIMAL}, #{item.callNum,jdbcType=BIGINT}, #{item.receivePassNum,jdbcType=BIGINT},
  315. #{item.receiveNotNum,jdbcType=BIGINT}, #{item.callTimeTotal,jdbcType=BIGINT}, #{item.remindPendingNum,jdbcType=BIGINT},
  316. #{item.remindProcessedNum,jdbcType=BIGINT},#{item.trafficSum,jdbcType=BIGINT},#{item.regNum,jdbcType=BIGINT}
  317. )
  318. </foreach>
  319. </insert>
  320. <insert id="generateData">
  321. <![CDATA[
  322. REPLACE INTO fs_statis_qw_watch(
  323. company_user_id,
  324. data_date,
  325. qw_user_id,
  326. send_num,
  327. period_num,
  328. period_person_num,
  329. not_registered_num,
  330. completed_num,
  331. interrupt_num,
  332. dept_id,
  333. black_num,
  334. deleted_num,
  335. order_num,
  336. order_money_total,
  337. red_package_money_total,
  338. receive_pass_num,
  339. receive_not_num,
  340. call_time_total,
  341. remind_pending_num,
  342. remind_processed_num,
  343. qw_repeat_num,
  344. user_repeat_num,
  345. traffic_sum,
  346. reg_num
  347. )
  348. WITH extended_temp AS (
  349. -- 原始temp表数据
  350. SELECT company_user_id, qw_user_id, this_date, dept_id
  351. FROM fs_statis_qw_temp_param
  352. WHERE this_date IS NOT NULL
  353. UNION
  354. -- 添加订单统计维度的记录
  355. SELECT DISTINCT
  356. o.company_user_id,
  357. '-1' as qw_user_id,
  358. #{date} as this_date,
  359. cu.dept_id as dept_id
  360. FROM fs_store_order o
  361. left join company_user cu
  362. on o.company_user_id=cu.user_id
  363. WHERE o.status in (4,5)
  364. AND o.company_user_id IS NOT NULL
  365. AND o.create_time >= #{startTime}
  366. AND o.create_time < #{endTime}
  367. UNION
  368. -- 添加红包统计维度的记录
  369. SELECT DISTINCT
  370. log.company_user_id,
  371. '-1' as qw_user_id,
  372. #{date} as this_date,
  373. cu.dept_id as dept_id
  374. FROM fs_course_red_packet_log log
  375. left join company_user cu
  376. on log.company_user_id=cu.user_id
  377. WHERE log.status = 1
  378. AND log.create_time >= #{startTime}
  379. AND log.create_time < #{endTime}
  380. )
  381. SELECT
  382. temp.company_user_id as company_user_id,
  383. temp.this_date as data_date,
  384. temp.qw_user_id as qw_user_id,
  385. IFNULL(log_stats.send_count, 0) as send_num,
  386. IFNULL(log_stats.period_count, 0) as period_num,
  387. IFNULL(log_stats.period_person_count, 0) as period_person_num,
  388. IFNULL(log_stats.not_register_count, 0) as not_registered_num,
  389. IFNULL(log_stats.completed_count, 0) as completed_num,
  390. IFNULL(log_stats.interrupt_count, 0) as interrupt_num,
  391. temp.dept_id as dept_id,
  392. IFNULL(contact.black_num, 0) as black_num,
  393. IFNULL(contact.deleted_num, 0) as deleted_num,
  394. IFNULL(stats_order.order_num, 0) as order_num,
  395. IFNULL(stats_order.order_money_total, 0) as order_money_total,
  396. IFNULL(redp.red_package_money_total, 0) as red_package_money_total,
  397. IFNULL(voice.receive_pass_num, 0) as receive_pass_num,
  398. IFNULL(voice.receive_not_num, 0) as receive_not_num,
  399. IFNULL(voice.call_time_total, 0) as call_time_total,
  400. IFNULL(qw_work.remind_pending_num, 0) as remind_pending_num,
  401. IFNULL(qw_work.remind_processed_num, 0) as remind_processed_num,
  402. IFNULL(contact.qw_repeat_num,0) as qw_repeat_num,
  403. IFNULL(contact.user_repeat_num,0) as user_repeat_num,
  404. IFNULL(traffic.traffic_sum,0) as traffic_sum,
  405. IFNULL(fs_user.reg_num,0) as reg_num
  406. FROM extended_temp temp
  407. LEFT JOIN (
  408. SELECT
  409. company_user_id,
  410. qw_user_id,
  411. COUNT(DISTINCT log_id) as send_count,
  412. COUNT(DISTINCT sop_id) as period_count,
  413. COUNT(DISTINCT CASE WHEN sop_id is not null then qw_external_contact_id END) as period_person_count,
  414. COUNT(DISTINCT CASE WHEN log_type = 3 THEN log_id END) as not_register_count,
  415. COUNT(DISTINCT CASE WHEN log_type = 2 THEN log_id END) as completed_count,
  416. COUNT(DISTINCT CASE WHEN (log_type = 4 OR log_type = 1) THEN log_id END) as interrupt_count
  417. FROM fs_course_watch_log
  418. WHERE ((update_time >= #{startTime} and update_time < #{endTime}) OR (create_time >= #{startTime} and create_time < #{endTime}))
  419. GROUP BY company_user_id, qw_user_id
  420. ) log_stats ON temp.company_user_id = log_stats.company_user_id
  421. AND temp.qw_user_id = log_stats.qw_user_id
  422. -- 拉黑数和删除数
  423. LEFT JOIN (
  424. SELECT
  425. contact.company_user_id,
  426. contact.qw_user_id,
  427. COUNT(CASE WHEN contact.status = 4 THEN 1 END) as black_num,
  428. COUNT(CASE WHEN contact.status = 5 OR contact.status = 7 THEN 1 END) as deleted_num,
  429. COUNT(contact.is_repeat) as qw_repeat_num,
  430. COUNT(contact.user_repeat) as user_repeat_num
  431. FROM qw_external_contact contact
  432. WHERE contact.qw_user_id IS NOT NULL
  433. AND contact.company_user_id IS NOT NULL
  434. AND contact.status IN (4, 5, 7)
  435. AND contact.update_time >= #{startTime}
  436. AND contact.update_time < #{endTime}
  437. GROUP BY company_user_id,qw_user_id
  438. ) contact ON contact.qw_user_id = temp.qw_user_id
  439. AND contact.company_user_id = temp.company_user_id
  440. -- 订单数、订单总金额
  441. LEFT JOIN (
  442. SELECT
  443. COUNT(DISTINCT order_id) as order_num,
  444. SUM(pay_money) as order_money_total,
  445. company_user_id,
  446. '-1' as qw_user_id
  447. FROM fs_store_order
  448. WHERE status = 5
  449. AND company_user_id IS NOT NULL
  450. AND create_time >= #{startTime}
  451. AND create_time < #{endTime}
  452. GROUP BY company_user_id,qw_user_id
  453. ) stats_order ON temp.company_user_id = stats_order.company_user_id
  454. AND temp.qw_user_id = '-1'
  455. -- 红包数
  456. LEFT JOIN (
  457. SELECT
  458. company_user_id,
  459. sum(amount) as red_package_money_total,
  460. '-1' as qw_user_id
  461. FROM fs_course_red_packet_log
  462. WHERE status = 1
  463. AND create_time >= #{startTime}
  464. AND create_time < #{endTime}
  465. GROUP BY company_user_id,qw_user_id
  466. ) redp ON temp.company_user_id = redp.company_user_id
  467. AND temp.qw_user_id = '-1'
  468. -- 通话统计(总拨打数(可以后面两项相加)、接通数、未接通数、通话时长)
  469. LEFT JOIN (
  470. SELECT
  471. company_user_id,
  472. qw_user_id,
  473. COUNT(CASE WHEN status = 1 THEN 1 END) as receive_pass_num,
  474. COUNT(CASE WHEN status = 2 THEN 1 END) as receive_not_num,
  475. SUM(CASE WHEN status = 1 THEN duration END) as call_time_total
  476. FROM qw_user_voice_log
  477. WHERE create_time >= #{startTime}
  478. AND create_time < #{endTime}
  479. GROUP BY company_user_id, qw_user_id
  480. ) voice ON temp.company_user_id = voice.company_user_id
  481. AND temp.qw_user_id = voice.qw_user_id
  482. -- 催课看板(催课未处理数、催课已处理数、未处理已完课数、已处理已完课数)
  483. LEFT JOIN (
  484. SELECT
  485. company_user_id,
  486. qw_user_id,
  487. COUNT(CASE WHEN status = 0 THEN 1 END) as remind_pending_num,
  488. COUNT(CASE WHEN status = 1 THEN 1 END) as remind_processed_num
  489. FROM qw_work_task
  490. WHERE create_time >= #{startTime}
  491. AND create_time < #{endTime}
  492. GROUP BY company_user_id, qw_user_id
  493. ) qw_work ON temp.company_user_id = qw_work.company_user_id
  494. AND temp.qw_user_id = qw_work.qw_user_id
  495. -- 流量统计
  496. LEFT JOIN (
  497. select
  498. company_user_id,
  499. qw_user_id,
  500. SUM(internet_traffic) as traffic_sum
  501. from fs_course_traffic_log
  502. where create_time >= #{startTime}
  503. AND create_time < #{endTime}
  504. GROUP BY company_user_id, qw_user_id
  505. )traffic ON temp.company_user_id = traffic.company_user_id
  506. AND temp.qw_user_id = traffic.qw_user_id
  507. -- 注册人数
  508. LEFT JOIN (
  509. select company_user_id,
  510. qw_user_id,
  511. count(user_id) as reg_num
  512. from fs_user
  513. WHERE create_time >= #{startTime}
  514. AND create_time < #{endTime}
  515. GROUP BY company_user_id, qw_user_id
  516. ) fs_user ON temp.company_user_id = fs_user.company_user_id
  517. AND temp.qw_user_id = fs_user.qw_user_id
  518. ]]>
  519. </insert>
  520. </mapper>