SysUserAccountHistoryMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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.ydtech.modules.admin.dao.SysUserAccountHistoryMapper">
  6. <resultMap id="BaseResultMap" type="com.ydtech.modules.admin.model.po.SysUserAccountHistory">
  7. <id property="id" column="id" jdbcType="BIGINT"/>
  8. <result property="amount" column="amount" jdbcType="DECIMAL"/>
  9. <result property="surplusAmount" column="surplus_amount" jdbcType="DECIMAL"/>
  10. <result property="documentary" column="documentary" jdbcType="TINYINT"/>
  11. <result property="property" column="property" jdbcType="TINYINT"/>
  12. <result property="suborder" column="suborder" jdbcType="VARCHAR"/>
  13. <result property="fromBankCard" column="from_bank_card" jdbcType="VARCHAR"/>
  14. <result property="toBankCard" column="to_bank_card" jdbcType="VARCHAR"/>
  15. <result property="userId" column="user_id" jdbcType="VARCHAR"/>
  16. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  17. <result property="businessSegmentsType" column="business_eegments_type" jdbcType="VARCHAR"/>
  18. </resultMap>
  19. <sql id="Base_Column_List">
  20. id,amount,surplus_amount,
  21. documentary,property,suborder,
  22. from_bank_card,to_bank_card,user_id,
  23. create_time,business_eegments_type
  24. </sql>
  25. <select id="revenueReportYear" resultType="com.ydtech.modules.admin.model.dto.RevenueReportDto">
  26. SELECT
  27. a.reportDate AS reportDate,
  28. MAX( CASE WHEN a.property = 1 THEN a.amount ELSE 0 END ) AS haldingAmount,
  29. MAX( CASE WHEN a.property = 2 THEN a.amount ELSE 0 END ) AS documentaryAmount,
  30. MAX( CASE WHEN a.property = 3 THEN a.amount ELSE 0 END ) AS promotionAmount
  31. FROM
  32. (
  33. SELECT
  34. CONCAT(YEAR(create_time),'-',LPAD(MONTH(create_time), 2, '0')) reportDate,
  35. property as property,
  36. sum(amount) as amount
  37. FROM
  38. sys_user_account_history
  39. WHERE
  40. documentary=2
  41. and create_time &gt;= #{beginTime} and create_time &lt;= #{endTime}
  42. and user_id=#{userId}
  43. GROUP BY
  44. CONCAT(YEAR(create_time),'-',LPAD(MONTH(create_time), 2, '0')),
  45. property
  46. ) a
  47. GROUP BY
  48. a.reportDate
  49. </select>
  50. <select id="revenueReportMonth" resultType="com.ydtech.modules.admin.model.dto.RevenueReportDto">
  51. SELECT
  52. a.reportDate AS reportDate,
  53. MAX( CASE WHEN a.property = 1 THEN a.amount ELSE 0 END ) AS haldingAmount,
  54. MAX( CASE WHEN a.property = 2 THEN a.amount ELSE 0 END ) AS documentaryAmount,
  55. MAX( CASE WHEN a.property = 3 THEN a.amount ELSE 0 END ) AS promotionAmount
  56. FROM
  57. (
  58. SELECT
  59. CONCAT(YEAR(create_time),'-',LPAD(MONTH(create_time), 2, '0'),'-',LPAD(Day(create_time), 2, '0')) reportDate,
  60. property as property,
  61. sum(amount) as amount
  62. FROM
  63. sys_user_account_history
  64. WHERE
  65. documentary=2
  66. and create_time &gt;= #{beginTime} and create_time &lt;= #{endTime}
  67. and user_id=#{userId}
  68. GROUP BY
  69. CONCAT(YEAR(create_time),'-',LPAD(MONTH(create_time), 2, '0'),'-',LPAD(Day(create_time), 2, '0')),
  70. property
  71. ) a
  72. GROUP BY
  73. a.reportDate
  74. </select>
  75. <select id="revenueReportDay" resultType="com.ydtech.modules.admin.model.dto.RevenueReportDto">
  76. SELECT
  77. a.reportDate AS reportDate,
  78. MAX( CASE WHEN a.property = 1 THEN a.amount ELSE 0 END ) AS haldingAmount,
  79. MAX( CASE WHEN a.property = 2 THEN a.amount ELSE 0 END ) AS documentaryAmount,
  80. MAX( CASE WHEN a.property = 3 THEN a.amount ELSE 0 END ) AS promotionAmount
  81. FROM
  82. (
  83. SELECT
  84. CONCAT(YEAR ( create_time ),'-',LPAD( MONTH ( create_time ), 2, '0' ),'-',LPAD( DAY ( create_time ), 2, '0' ),' ',LPAD( HOUR ( create_time ), 2, '0' )) reportDate,
  85. property as property,
  86. sum( amount ) as amount
  87. FROM
  88. sys_user_account_history
  89. WHERE
  90. documentary=2
  91. and create_time &gt;= #{beginTime} and create_time &lt;= #{endTime}
  92. and user_id=#{userId}
  93. GROUP BY
  94. CONCAT(YEAR ( create_time ),'-',LPAD( MONTH ( create_time ), 2, '0' ),'-',LPAD( DAY ( create_time ), 2, '0' ),' ',LPAD( HOUR ( create_time ), 2, '0' )),
  95. property
  96. ) a
  97. GROUP BY
  98. a.reportDate
  99. </select>
  100. <select id="findMyIncomeAndExpensesAmountByUserId"
  101. resultType="com.ydtech.modules.admin.model.dto.MyCollectInAdvanceDto">
  102. SELECT
  103. his.id as id,
  104. ins.id as "subOrderNo",
  105. ins.signing_time as "signingTime",
  106. o.licenseno as "licenseno",
  107. his.amount as "amount",
  108. his.business_eegments_type as "businessSegmentsType",
  109. his.documentary as "incomeAndExpensesType",
  110. his.property as "transactionType",
  111. his.create_time as "createTime",
  112. his.auditiing_id as "auditiingId",
  113. CASE saa.auditing_status
  114. WHEN '2' THEN '提现中'
  115. WHEN '3' THEN '已提现'
  116. WHEN '4' THEN '驳回'
  117. ELSE ''
  118. END AS "auditingStatus",
  119. CASE ifa.audituser WHEN '自动审核' THEN '1'
  120. ELSE '2' END as "checkStatus"
  121. FROM
  122. sys_user_account_history his
  123. LEFT JOIN ins_area_company ins ON his.suborder = ins.id
  124. LEFT JOIN ins_orders o ON o.orderno = ins.orderno
  125. left join sys_amount_auditing saa on saa.id =his.auditiing_id
  126. left join ins_fee_audit ifa on ifa.ins_order_no = ins.id
  127. WHERE
  128. his.property !=1 and his.property !=2
  129. <if test="myIncomeAndExpensesQueryDto.incomeAndExpensesType !=null and myIncomeAndExpensesQueryDto.incomeAndExpensesType != '' and myIncomeAndExpensesQueryDto.incomeAndExpensesType != '0' ">
  130. AND his.documentary=#{ myIncomeAndExpensesQueryDto.incomeAndExpensesType}
  131. </if>
  132. and his.user_id = #{myIncomeAndExpensesQueryDto.userId}
  133. <if test="myIncomeAndExpensesQueryDto.startDate !=null and myIncomeAndExpensesQueryDto.startDate != '' and myIncomeAndExpensesQueryDto.endDate !=null and myIncomeAndExpensesQueryDto.endDate != '' ">
  134. AND his.create_time BETWEEN #{myIncomeAndExpensesQueryDto.startDate} AND #{myIncomeAndExpensesQueryDto.endDate}
  135. </if>
  136. <if test="myIncomeAndExpensesQueryDto.transactionType !=null and myIncomeAndExpensesQueryDto.transactionType != '' and myIncomeAndExpensesQueryDto.transactionType != '0'">
  137. and his.property = #{myIncomeAndExpensesQueryDto.transactionType}
  138. </if>
  139. <if test="myIncomeAndExpensesQueryDto.businessSegmentsType !=null and myIncomeAndExpensesQueryDto.businessSegmentsType != '' and myIncomeAndExpensesQueryDto.businessSegmentsType != '0'">
  140. and his.business_eegments_type =#{myIncomeAndExpensesQueryDto.businessSegmentsType}
  141. </if>
  142. order by his.create_time desc
  143. </select>
  144. <select id="findMyIncomeAndExpensesAmountByUserIdCount" resultType="java.lang.Long">
  145. SELECT
  146. count(0)
  147. FROM
  148. sys_user_account_history his
  149. WHERE
  150. his.property !=1 and his.property !=2
  151. <if test="myIncomeAndExpensesQueryDto.incomeAndExpensesType !=null and myIncomeAndExpensesQueryDto.incomeAndExpensesType != '' and myIncomeAndExpensesQueryDto.incomeAndExpensesType != '0'">
  152. AND his.documentary=#{ myIncomeAndExpensesQueryDto.incomeAndExpensesType}
  153. </if>
  154. and his.user_id = #{myIncomeAndExpensesQueryDto.userId}
  155. <if test="myIncomeAndExpensesQueryDto.startDate !=null and myIncomeAndExpensesQueryDto.startDate != '' and myIncomeAndExpensesQueryDto.endDate !=null and myIncomeAndExpensesQueryDto.endDate != '' ">
  156. AND his.create_time BETWEEN #{myIncomeAndExpensesQueryDto.startDate} AND #{myIncomeAndExpensesQueryDto.endDate}
  157. </if>
  158. <if test="myIncomeAndExpensesQueryDto.transactionType !=null and myIncomeAndExpensesQueryDto.transactionType != '' and myIncomeAndExpensesQueryDto.transactionType != '0'">
  159. and his.property = #{myIncomeAndExpensesQueryDto.transactionType}
  160. </if>
  161. <if test="myIncomeAndExpensesQueryDto.businessSegmentsType !=null and myIncomeAndExpensesQueryDto.businessSegmentsType != '' and myIncomeAndExpensesQueryDto.businessSegmentsType != '0' ">
  162. and his.business_eegments_type =#{myIncomeAndExpensesQueryDto.businessSegmentsType}
  163. </if>
  164. </select>
  165. <select id="findSumAmount" resultType="java.math.BigDecimal">
  166. SELECT
  167. sum(his.amount) as "sumAmount"
  168. FROM
  169. sys_user_account_history his
  170. WHERE
  171. his.property !=1 and his.property !=2
  172. <if test="myIncomeAndExpensesQueryDto.incomeAndExpensesType !=null and myIncomeAndExpensesQueryDto.incomeAndExpensesType != '' and myIncomeAndExpensesQueryDto.incomeAndExpensesType != '0' ">
  173. AND his.documentary=#{ myIncomeAndExpensesQueryDto.incomeAndExpensesType}
  174. </if>
  175. and his.user_id = #{myIncomeAndExpensesQueryDto.userId}
  176. <if test="myIncomeAndExpensesQueryDto.startDate !=null and myIncomeAndExpensesQueryDto.startDate != '' and myIncomeAndExpensesQueryDto.endDate !=null and myIncomeAndExpensesQueryDto.endDate != '' ">
  177. AND his.create_time BETWEEN #{myIncomeAndExpensesQueryDto.startDate} AND #{myIncomeAndExpensesQueryDto.endDate}
  178. </if>
  179. <if test="myIncomeAndExpensesQueryDto.transactionType !=null and myIncomeAndExpensesQueryDto.transactionType != '' and myIncomeAndExpensesQueryDto.transactionType != '0'">
  180. and his.property = #{myIncomeAndExpensesQueryDto.transactionType}
  181. </if>
  182. <if test="myIncomeAndExpensesQueryDto.businessSegmentsType !=null and myIncomeAndExpensesQueryDto.businessSegmentsType != '' and myIncomeAndExpensesQueryDto.businessSegmentsType != '0' ">
  183. and his.business_eegments_type =#{myIncomeAndExpensesQueryDto.businessSegmentsType}
  184. </if>
  185. </select>
  186. <select id="findSumAmountByUserId" resultType="java.math.BigDecimal">
  187. SELECT
  188. sum(his.amount) as "sumAmount"
  189. FROM
  190. sys_user_account_history his
  191. WHERE
  192. his.documentary =#{types}
  193. and his.property !=1 and his.property !=2
  194. and his.user_id = #{userId}
  195. </select>
  196. <select id="findMyIncomeAndExpensesAmountNewByUserId"
  197. resultType="com.ydtech.modules.admin.model.dto.ExportExpenditureTypeDetalsSZDto">
  198. <include refid="common_List_sql"/>
  199. </select>
  200. <select id="exportMyIncomeAndExpensesAmountNewByUserId"
  201. resultType="com.ydtech.modules.admin.model.dto.ExportExpenditureTypeDetalsSZDto">
  202. <include refid="common_List_sql"/>
  203. </select>
  204. <sql id="common_List_sql">
  205. SELECT
  206. his.id as id,
  207. ins.id as "subOrderNo",
  208. ins.signing_time as "signingTime",
  209. o.licenseno as "licenseno",
  210. his.amount as "amount",
  211. his.business_eegments_type as "businessSegmentsType",
  212. his.documentary as "incomeAndExpensesType",
  213. his.property as "transactionType",
  214. his.create_time as "createTime",
  215. his.auditiing_id as "auditiingId",
  216. CASE saa.auditing_status
  217. WHEN '2' THEN '提现中'
  218. WHEN '3' THEN '已提现'
  219. WHEN '4' THEN '已驳回'
  220. ELSE ''
  221. END AS "auditingStatus"
  222. FROM
  223. sys_user_account_history his
  224. LEFT JOIN ins_area_company ins ON his.suborder = ins.id
  225. LEFT JOIN ins_orders o ON o.orderno = ins.orderno
  226. left join sys_amount_auditing saa on saa.id =his.auditiing_id
  227. WHERE
  228. his.property !=1 and his.property !=2
  229. <if test="vo.incomeAndExpensesType !=null and vo.incomeAndExpensesType != '' and vo.incomeAndExpensesType != '0' ">
  230. AND his.documentary=#{ vo.incomeAndExpensesType}
  231. </if>
  232. and his.user_id = #{vo.userId}
  233. <if test="vo.startDate !=null and vo.startDate != '' and vo.endDate !=null and vo.endDate != '' ">
  234. AND his.create_time BETWEEN #{vo.startDate} AND #{vo.endDate}
  235. </if>
  236. <if test="vo.transactionType !=null and vo.transactionType != '' and vo.transactionType != '0'">
  237. and his.property = #{vo.transactionType}
  238. </if>
  239. <if test="vo.businessSegmentsType !=null and vo.businessSegmentsType != '' and vo.businessSegmentsType != '0'">
  240. and his.business_eegments_type =#{vo.businessSegmentsType}
  241. </if>
  242. <if test="vo.licenseNo !=null and vo.licenseNo != ''">
  243. and o.licenseno =#{vo.licenseNo}
  244. </if>
  245. order by his.create_time desc
  246. </sql>
  247. <select id="queryRevenueAndExpenditureDataPage"
  248. resultType="com.ydtech.modules.admin.model.report.financeData.RevenueAndExpenditureDataDto">
  249. SELECT
  250. his.id as id,
  251. his.amount as "amount",
  252. DATE_FORMAT(his.create_time, '%Y-%m-%d %H:%i:%s') as "createTime",
  253. his.auditiing_id as "auditiingId",
  254. CASE saa.auditing_status
  255. WHEN '2' THEN '提现中'
  256. WHEN '3' THEN '已提现'
  257. WHEN '4' THEN '已驳回'
  258. ELSE ''
  259. END AS "auditingStatus",
  260. su.id as userId,
  261. su.name as userName,
  262. DATE_FORMAT(saa.auditing_time, '%Y-%m-%d %H:%i:%s') as auditingTime,
  263. CASE
  264. dept.management_source
  265. WHEN '1' THEN
  266. '渠道'
  267. WHEN '2' THEN
  268. '代理人' ELSE ''
  269. END deptType
  270. FROM
  271. sys_user_account_history his
  272. LEFT JOIN ins_area_company ins ON his.suborder = ins.id
  273. LEFT JOIN sys_user su ON su.id = his.user_id
  274. LEFT JOIN sys_amount_auditing saa ON saa.id = his.auditiing_id
  275. LEFT JOIN sys_dept dept ON dept.id = su.dept_id
  276. WHERE
  277. his.property !=1 and his.property !=2
  278. AND (
  279. dept.management_source = 1
  280. OR dept.management_source = 2)
  281. and his.documentary =1
  282. <if test="vo.userId !=null and vo.userId != '' ">
  283. and his.user_id = #{vo.userId}
  284. </if>
  285. <if test="vo.startDate !=null and vo.startDate != '' and vo.endDate !=null and vo.endDate != '' ">
  286. AND his.create_time BETWEEN #{vo.startDate} AND #{vo.endDate}
  287. </if>
  288. <if test="vo.auditstatus !=null and vo.auditstatus != '' ">
  289. AND saa.auditing_status = #{auditstatus}
  290. </if>
  291. order by his.create_time desc
  292. </select>
  293. </mapper>