AdProfitDetailMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.his.mapper.AdProfitDetailMapper">
  4. <resultMap type="AdProfitDetail" id="AdProfitDetailResult">
  5. <result property="id" column="id" />
  6. <result property="adTransId" column="ad_trans_id" />
  7. <result property="adTaskId" column="ad_task_id" />
  8. <result property="sumMoney" column="sum_money" />
  9. <result property="userId" column="user_id" />
  10. <result property="userMoney" column="user_money" />
  11. <result property="companyId" column="company_id" />
  12. <result property="companyMoney" column="company_money" />
  13. <result property="huyiMoney" column="huyi_money" />
  14. <result property="yunlianMoney" column="yunlian_money" />
  15. <result property="createTime" column="create_time" />
  16. </resultMap>
  17. <sql id="selectAdProfitDetailVo">
  18. select id, ad_trans_id, ad_task_id, sum_money, user_id, user_money, company_id, company_money, huyi_money, yunlian_money, create_time from ad_profit_detail
  19. </sql>
  20. <select id="selectAdProfitDetailById" parameterType="Long" resultMap="AdProfitDetailResult">
  21. <include refid="selectAdProfitDetailVo"/>
  22. where id = #{id}
  23. </select>
  24. <insert id="insertAdProfitDetail" parameterType="AdProfitDetail" useGeneratedKeys="true" keyProperty="id">
  25. insert into ad_profit_detail
  26. <trim prefix="(" suffix=")" suffixOverrides=",">
  27. <if test="adTransId != null and adTransId != ''">ad_trans_id,</if>
  28. <if test="adTaskId != null">ad_task_id,</if>
  29. <if test="sumMoney != null">sum_money,</if>
  30. <if test="userId != null">user_id,</if>
  31. <if test="userMoney != null">user_money,</if>
  32. <if test="companyId != null">company_id,</if>
  33. <if test="companyMoney != null">company_money,</if>
  34. <if test="huyiMoney != null">huyi_money,</if>
  35. <if test="yunlianMoney != null">yunlian_money,</if>
  36. <if test="createTime != null">create_time,</if>
  37. </trim>
  38. <trim prefix="values (" suffix=")" suffixOverrides=",">
  39. <if test="adTransId != null and adTransId != ''">#{adTransId},</if>
  40. <if test="adTaskId != null">#{adTaskId},</if>
  41. <if test="sumMoney != null">#{sumMoney},</if>
  42. <if test="userId != null">#{userId},</if>
  43. <if test="userMoney != null">#{userMoney},</if>
  44. <if test="companyId != null">#{companyId},</if>
  45. <if test="companyMoney != null">#{companyMoney},</if>
  46. <if test="huyiMoney != null">#{huyiMoney},</if>
  47. <if test="yunlianMoney != null">#{yunlianMoney},</if>
  48. <if test="createTime != null">#{createTime},</if>
  49. </trim>
  50. </insert>
  51. <update id="updateAdProfitDetail" parameterType="AdProfitDetail">
  52. update ad_profit_detail
  53. <trim prefix="SET" suffixOverrides=",">
  54. <if test="adTransId != null and adTransId != ''">ad_trans_id = #{adTransId},</if>
  55. <if test="adTaskId != null">ad_task_id = #{adTaskId},</if>
  56. <if test="sumMoney != null">sum_money = #{sumMoney},</if>
  57. <if test="userId != null">user_id = #{userId},</if>
  58. <if test="userMoney != null">user_money = #{userMoney},</if>
  59. <if test="companyId != null">company_id = #{companyId},</if>
  60. <if test="companyMoney != null">company_money = #{companyMoney},</if>
  61. <if test="huyiMoney != null">huyi_money = #{huyiMoney},</if>
  62. <if test="yunlianMoney != null">yunlian_money = #{yunlianMoney},</if>
  63. <if test="createTime != null">create_time = #{createTime},</if>
  64. </trim>
  65. where id = #{id}
  66. </update>
  67. <delete id="deleteAdProfitDetailById" parameterType="Long">
  68. delete from ad_profit_detail where id = #{id}
  69. </delete>
  70. <delete id="deleteAdProfitDetailByIds" parameterType="String">
  71. delete from ad_profit_detail where id in
  72. <foreach item="id" collection="array" open="(" separator="," close=")">
  73. #{id}
  74. </foreach>
  75. </delete>
  76. <select id="getCompanyByUserId" resultType="java.lang.String">
  77. SELECT
  78. company_id
  79. FROM
  80. `qw_external_contact`
  81. WHERE
  82. fs_user_id = #{userId}
  83. ORDER BY
  84. create_time ASC LIMIT 1
  85. </select>
  86. <select id="selectAdProfitDetailList" resultType="com.fs.his.dto.AdProfitDetailDto">
  87. SELECT
  88. a.*,
  89. b.company_name,
  90. c.nick_name
  91. FROM
  92. `ad_profit_detail` a
  93. LEFT JOIN company b ON a.company_id = b.company_id
  94. LEFT JOIN fs_user c ON a.user_id = c.user_id
  95. <where>
  96. <if test="adTransId != null and adTransId != ''"> and a.ad_trans_id = #{adTransId}</if>
  97. <if test="adTaskId != null and adTaskId != ''"> and a.ad_task_id = #{adTaskId}</if>
  98. <if test="sumMoney != null "> and a.sum_money = #{sumMoney}</if>
  99. <if test="userId != null "> and a.user_id = #{userId}</if>
  100. <if test="userMoney != null "> and a.user_money = #{userMoney}</if>
  101. <if test="companyId != null "> and a.company_id = #{companyId}</if>
  102. <if test="companyMoney != null "> and a.company_money = #{companyMoney}</if>
  103. <if test="huyiMoney != null "> and a.huyi_money = #{huyiMoney}</if>
  104. <if test="yunlianMoney != null "> and a.yunlian_money = #{yunlianMoney}</if>
  105. <if test="companyName != null"> and b.company_name = #{companyName}</if>
  106. <if test="sTime != null"> and Date(a.create_time) &gt;= Date(#{sTime})</if>
  107. <if test="eTime != null"> and Date(a.create_time) &lt;= Date(#{eTime})</if>
  108. <if test="nickName != null"> and c.nick_name like concat('%',#{nickName},'%')</if>
  109. </where>
  110. order by a.create_time desc
  111. </select>
  112. <select id="getWithFinishAndMayWithdraw" resultType="java.util.Map">
  113. SELECT
  114. SUM(may_withdraw) AS totalMayWithdraw,
  115. SUM(withdraw_finish) AS totalWithdrawFinish
  116. FROM
  117. fs_user
  118. WHERE
  119. may_withdraw > 0.00
  120. OR withdraw_finish > 0.00
  121. </select>
  122. <select id="statisticsList" resultType="com.fs.his.vo.AdProfitDetailStatisticsVo">
  123. <!-- 1. 用户分润 -->
  124. SELECT
  125. '用户分润' AS `name`,
  126. IFNULL(ROUND(SUM(a.user_money) / 100, 2), 0) AS amountYuan,
  127. 'summary' AS type,
  128. 1 AS sortOrder
  129. FROM ad_profit_detail a
  130. WHERE <include refid="timeCondition"/>
  131. UNION ALL
  132. <!-- 2. 互医分润 -->
  133. SELECT
  134. '互医分润' AS `name`,
  135. IFNULL(ROUND(SUM(a.huyi_money) / 100, 2), 0) AS amountYuan,
  136. 'summary' AS type,
  137. 2 AS sortOrder
  138. FROM ad_profit_detail a
  139. WHERE <include refid="timeCondition"/>
  140. UNION ALL
  141. <!-- 3. 云联分润 -->
  142. SELECT
  143. '云联分润' AS `name`,
  144. IFNULL(ROUND(SUM(a.yunlian_money) / 100, 2), 0) AS amountYuan,
  145. 'summary' AS type,
  146. 3 AS sortOrder
  147. FROM ad_profit_detail a
  148. WHERE <include refid="timeCondition"/>
  149. UNION ALL
  150. <!-- 4. 各公司分润 -->
  151. SELECT
  152. c.company_name AS `name`,
  153. IFNULL(ROUND(SUM(a.company_money) / 100, 2), 0) AS amountYuan,
  154. 'company' AS type,
  155. a.company_id + 100 AS sortOrder
  156. FROM ad_profit_detail a
  157. LEFT JOIN company c ON a.company_id = c.company_id
  158. WHERE a.company_id IS NOT NULL
  159. AND <include refid="timeCondition"/>
  160. GROUP BY a.company_id, c.company_name
  161. ORDER BY sortOrder, `name`
  162. </select>
  163. <sql id="timeCondition">
  164. <choose>
  165. <!-- type为null时,使用startTime和endTime -->
  166. <when test="param.type == null">
  167. a.create_time >= #{param.startTime}
  168. AND a.create_time &lt; DATE_ADD(#{param.endTime}, INTERVAL 1 DAY)
  169. </when>
  170. <!-- 1. 今天 -->
  171. <when test="param.type == 1">
  172. a.create_time >= CURDATE()
  173. AND a.create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  174. </when>
  175. <!-- 2. 昨天 -->
  176. <when test="param.type == 2">
  177. a.create_time >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  178. AND a.create_time &lt; CURDATE()
  179. </when>
  180. <!-- 3. 本周 -->
  181. <when test="param.type == 3">
  182. a.create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  183. AND a.create_time &lt; DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
  184. </when>
  185. <!-- 4. 上周 -->
  186. <when test="param.type == 4">
  187. a.create_time >= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
  188. AND a.create_time &lt; DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  189. </when>
  190. <!-- 5. 本月 -->
  191. <when test="param.type == 5">
  192. a.create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
  193. AND a.create_time &lt; DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
  194. </when>
  195. <!-- 6. 上月 -->
  196. <when test="param.type == 6">
  197. a.create_time >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
  198. AND a.create_time &lt; DATE_FORMAT(CURDATE(), '%Y-%m-01')
  199. </when>
  200. <!-- 7. 本季度 -->
  201. <when test="param.type == 7">
  202. a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
  203. AND a.create_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
  204. </when>
  205. <!-- 8. 上季度 -->
  206. <when test="param.type == 8">
  207. a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
  208. AND a.create_time &lt; STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
  209. </when>
  210. <!-- 9. 本年 -->
  211. <when test="param.type == 9">
  212. a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
  213. AND a.create_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
  214. </when>
  215. <!-- 10. 去年 -->
  216. <when test="param.type == 10">
  217. a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
  218. AND a.create_time &lt; STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
  219. </when>
  220. </choose>
  221. </sql>
  222. </mapper>