SysPcAddressHistoryMapper.xml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.SysPcAddressHistoryMapper">
  6. <resultMap id="BaseResultMap" type="com.ydtech.modules.admin.model.po.SysPcAddressHistory">
  7. <id property="id" column="id" jdbcType="BIGINT"/>
  8. <id property="userId" column="user_id" jdbcType="VARCHAR"/>
  9. <result property="userName" column="user_name" jdbcType="VARCHAR"/>
  10. <result property="ip" column="ip" jdbcType="VARCHAR"/>
  11. <result property="longitude" column="longitude" jdbcType="VARCHAR"/>
  12. <result property="latitude" column="latitude" jdbcType="VARCHAR"/>
  13. <result property="address" column="address" jdbcType="VARCHAR"/>
  14. <result property="operationTime" column="operation_time" jdbcType="TIMESTAMP"/>
  15. <result property="province" column="prov" jdbcType="VARCHAR"/>
  16. <result property="city" column="city" jdbcType="VARCHAR"/>
  17. <result property="district" column="district" jdbcType="VARCHAR"/>
  18. <result property="source" column="source" jdbcType="VARCHAR"/>
  19. </resultMap>
  20. <select id="getPcAddress" resultType="com.ydtech.modules.admin.model.vo.PcAddressHistoryTimeVo">
  21. select spa.time, COUNT(spa.user_id) as countNum
  22. from(
  23. SELECT
  24. DISTINCT s.user_id,DATE_FORMAT(s.operation_time, '%Y-%m-%d %H' ) as time
  25. FROM
  26. sys_pc_address_history s
  27. <where>
  28. <if test="source != null">
  29. s.source = #{source}
  30. </if>
  31. <if test="source == null">
  32. s.source in (1,2)
  33. </if>
  34. <if test="collect !=null and collect.size()>0">
  35. AND s.user_id in
  36. <foreach collection="collect" item="item" open="(" close=")" separator=",">
  37. #{item}
  38. </foreach>
  39. </if>
  40. <if test="dates != null and dates != ''">
  41. and DATE_FORMAT(s.operation_time, '%Y-%m-%d' ) = DATE_FORMAT( #{dates}, '%Y-%m-%d' )
  42. </if>
  43. </where>
  44. ) as spa
  45. GROUP BY
  46. spa.time
  47. ORDER BY
  48. spa.time ASC
  49. </select>
  50. <select id="getPcAddressSection" resultType="com.ydtech.modules.admin.model.vo.PcAddressHistoryTimeVo">
  51. select spa.time, COUNT(spa.user_id) as countNum
  52. from(
  53. SELECT
  54. DISTINCT s.user_id,DATE_FORMAT(s.operation_time, '%Y-%m-%d' ) as time
  55. FROM
  56. sys_pc_address_history s
  57. <where>
  58. <if test="source != null ">
  59. s.source = #{source}
  60. </if>
  61. <if test="source == null ">
  62. s.source in (1,2)
  63. </if>
  64. <if test="collect !=null and collect.size()>0">
  65. AND s.user_id in
  66. <foreach collection="collect" item="item" open="(" close=")" separator=",">
  67. #{item}
  68. </foreach>
  69. </if>
  70. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  71. and (DATE_FORMAT(s.operation_time, '%Y-%m-%d') between DATE_FORMAT( #{startTime}, '%Y-%m-%d') and DATE_FORMAT( #{endTime}, '%Y-%m-%d'))
  72. </if>
  73. </where>
  74. ) as spa
  75. GROUP BY
  76. spa.time
  77. ORDER BY
  78. spa.time ASC
  79. </select>
  80. <select id="getPcAddressHistory" resultType="com.ydtech.modules.admin.model.po.SysPcAddressHistory">
  81. SELECT t1.*
  82. FROM sys_pc_address_history t1
  83. INNER JOIN (
  84. SELECT s.user_id, MAX(s.id) AS max_id
  85. FROM sys_pc_address_history s
  86. <where>
  87. <if test="source != null ">
  88. s.source = #{source}
  89. </if>
  90. <if test="source == null">
  91. s.source in (1,2)
  92. </if>
  93. <if test="collect !=null and collect.size()>0">
  94. AND s.user_id in
  95. <foreach collection="collect" item="item" open="(" close=")" separator=",">
  96. #{item}
  97. </foreach>
  98. </if>
  99. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  100. and (DATE_FORMAT(s.operation_time, '%Y-%m-%d' ) between DATE_FORMAT( #{startTime}, '%Y-%m-%d' ) and DATE_FORMAT( #{endTime}, '%Y-%m-%d' ))
  101. </if>
  102. </where>
  103. GROUP BY s.user_id
  104. ) t2 ON t1.id = t2.max_id
  105. ORDER BY t1.id DESC
  106. </select>
  107. <select id="getPcAddressInfo" resultType="com.ydtech.modules.admin.model.po.SysPcAddressHistory">
  108. SELECT t1.*
  109. FROM sys_pc_address_history t1
  110. INNER JOIN (
  111. SELECT s.user_id, MAX(s.id) AS max_id
  112. FROM sys_pc_address_history s
  113. <where>
  114. <if test="source == null">
  115. s.source in (1,2)
  116. </if>
  117. <if test="source != null">
  118. s.source = #{source}
  119. </if>
  120. <if test="collect !=null and collect.size()>0">
  121. AND s.user_id in
  122. <foreach collection="collect" item="item" open="(" close=")" separator=",">
  123. #{item}
  124. </foreach>
  125. </if>
  126. <if test="dates != null and dates != ''">
  127. and DATE_FORMAT(s.operation_time, '%Y-%m-%d' ) = DATE_FORMAT( #{dates}, '%Y-%m-%d' )
  128. </if>
  129. </where>
  130. GROUP BY s.user_id
  131. ) t2 ON t1.id = t2.max_id
  132. ORDER BY t1.id DESC
  133. </select>
  134. <select id="queryAddressHistory" resultType="com.ydtech.modules.admin.model.po.SysPcAddressHistory">
  135. SELECT t1.*
  136. FROM sys_pc_address_history t1
  137. INNER JOIN (
  138. SELECT user_id, MAX(id) AS max_id
  139. FROM sys_pc_address_history
  140. <where>
  141. <if test="dto.lng != null and dto.lng != ''">
  142. and longitude=#{dto.lng}
  143. </if>
  144. <if test="dto.lat != null and dto.lat != ''">
  145. and latitude=#{dto.lat}
  146. </if>
  147. <if test="dto.source != null">
  148. and source=#{dto.source}
  149. </if>
  150. <if test="dto.source == null">
  151. and source in (1,2)
  152. </if>
  153. <if test="dto.collectIds !=null and dto.collectIds.size()>0">
  154. and user_id in
  155. <foreach collection="dto.collectIds" item="item" open="(" close=")" separator=",">
  156. #{item}
  157. </foreach>
  158. </if>
  159. <if test="dto.collect !=null and dto.collect.size()>0">
  160. and user_id in
  161. <foreach collection="dto.collect" item="item" open="(" close=")" separator=",">
  162. #{item}
  163. </foreach>
  164. </if>
  165. <if test="dto.queryId != null and dto.queryId != ''">
  166. and user_id like concat(#{dto.queryId},'%')
  167. </if>
  168. <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''and dto.startTime != dto.endTime">
  169. and (DATE_FORMAT(operation_time, '%Y-%m-%d' ) between DATE_FORMAT( #{dto.startTime}, '%Y-%m-%d' ) and DATE_FORMAT( #{dto.endTime}, '%Y-%m-%d' ))
  170. </if>
  171. <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''and dto.startTime == dto.endTime">
  172. and (DATE_FORMAT(operation_time, '%Y-%m-%d' ) like CONCAT( DATE_FORMAT( #{dto.startTime}, '%Y-%m-%d' ), '%' ))
  173. </if>
  174. </where>
  175. GROUP BY user_id) t2 ON t1.id = t2.max_id
  176. ORDER BY t1.id DESC
  177. </select>
  178. </mapper>