TaPersonMapper.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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.huiju.estateagents.mapper.TaPersonMapper">
  4. <select id="selectCardList" resultType="java.util.HashMap">
  5. SELECT
  6. t.person_id AS id,
  7. t.name,
  8. t.company,
  9. t.department,
  10. t.post,
  11. t.tel AS phone,
  12. t.avatarurl AS avatar,
  13. t.photo
  14. FROM
  15. ta_person t
  16. WHERE
  17. t.person_type = #{personType}
  18. AND t.status = #{status}
  19. ORDER BY
  20. t.create_date DESC
  21. </select>
  22. <select id="selectBuildingConsultants" resultType="java.util.HashMap">
  23. SELECT
  24. t.person_id AS id,
  25. t.name,
  26. t.company,
  27. t.department,
  28. t.post,
  29. t.tel AS phone,
  30. t.avatarurl AS avatar,
  31. t.photo
  32. FROM
  33. ta_person t
  34. JOIN ta_person_building s USING (person_id)
  35. WHERE
  36. s.building_id = #{buildingId}
  37. AND t.person_type = #{personType}
  38. AND t. STATUS = #{status}
  39. ORDER BY
  40. t.create_date DESC
  41. </select>
  42. <select id="getSalesExecutive" resultType="com.huiju.estateagents.entity.TaPerson">
  43. SELECT
  44. *
  45. FROM
  46. ta_person t
  47. WHERE
  48. t.person_type = 'Sales Executive'
  49. AND t.status = 1
  50. LIMIT 1
  51. </select>
  52. <select id="getPersonByOpenId" resultType="com.huiju.estateagents.entity.TaPerson">
  53. SELECT
  54. *
  55. FROM
  56. ta_person t
  57. WHERE
  58. t.mini_openid = #{openId}
  59. AND IFNULL(t.status, 0) &gt; -1
  60. </select>
  61. <update id="setFieldIncrement">
  62. UPDATE ta_person
  63. SET ${field} = IFNULL(${field}, 0) + #{increment}
  64. WHERE person_id = #{personId}
  65. </update>
  66. <select id="selectCustomer" resultType="com.huiju.estateagents.entity.TaPerson">
  67. SELECT
  68. a.*,
  69. b.event as event,
  70. b.activity as activity,
  71. b.data as data,
  72. (select b.visit_time FROM ta_person_visit_record b where a.person_id = b.person_id ORDER BY b.visit_time desc LIMIT 1) as visitTime
  73. FROM
  74. ta_person a
  75. LEFT JOIN ta_person_visit_record b ON a.person_id = b.person_id
  76. WHERE
  77. a.person_type IS NULL
  78. ORDER BY create_date desc
  79. </select>
  80. <select id="getById" resultType="com.huiju.estateagents.entity.TaPerson">
  81. SELECT
  82. a.*
  83. FROM
  84. ta_person a
  85. WHERE
  86. a.person_id = #{personId}
  87. </select>
  88. <select id="getUserProjects" resultType="java.lang.String">
  89. SELECT
  90. b.building_name
  91. FROM
  92. ta_person_building a
  93. LEFT JOIN ta_building b ON a.building_id = b.building_id
  94. WHERE a.person_id = #{personId}
  95. </select>
  96. <select id="selectByIdPerson" resultType="com.huiju.estateagents.entity.TaPerson">
  97. select * from ta_person where mini_openid = #{openid};
  98. </select>
  99. <select id="getConsultantByName" resultType="java.lang.String">
  100. select person_id from ta_person where name like CONCAT('%',#{name}, '%')
  101. </select>
  102. <select id="getConsultantByTel" resultType="java.lang.String">
  103. select person_id from ta_person where tel = #{tel}
  104. </select>
  105. <select id="selectCardListofMine" resultType="java.util.HashMap">
  106. SELECT
  107. t.person_id AS id,
  108. t.name,
  109. t.company,
  110. t.department,
  111. t.post,
  112. t.tel AS phone,
  113. t.avatarurl AS avatar,
  114. t.photo
  115. FROM
  116. ta_person t
  117. WHERE
  118. t.person_type = #{personType}
  119. AND t.status = #{status}
  120. <if test="personIds != null">
  121. and t.person_id in
  122. <foreach collection="personIds" item="personIds" index="index" open="(" close=")" separator=",">
  123. #{ordersId}
  124. </foreach>
  125. </if>
  126. ORDER BY
  127. t.create_date DESC
  128. </select>
  129. <select id="selectRecentlyCount" resultType="integer" >
  130. SELECT
  131. SUM(activity_count) as activity_count
  132. FROM
  133. (
  134. SELECT
  135. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  136. FROM
  137. sequence a
  138. WHERE
  139. <if test="startDate == null or endDate == null">
  140. a.rownum <![CDATA[ <= ]]> 7
  141. </if>
  142. <if test="startDate != null or endDate != null">
  143. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  144. </if>
  145. ) AS temp_date
  146. LEFT JOIN (
  147. SELECT
  148. COUNT(1) as activity_count,
  149. tpvr.visit_time AS visit_time
  150. FROM
  151. ta_person tp
  152. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  153. where ifnull(tp.person_type, '') != #{personType}
  154. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  155. </select>
  156. <select id="selectUserBehavior" resultType="com.huiju.estateagents.po.PersonPO">
  157. SELECT
  158. *
  159. FROM
  160. (
  161. SELECT
  162. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  163. FROM
  164. sequence a
  165. WHERE
  166. <if test="startDate == null or endDate == null">
  167. a.rownum <![CDATA[ <= ]]> 7
  168. </if>
  169. <if test="startDate != null or endDate != null">
  170. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  171. </if>
  172. ) AS temp_date
  173. LEFT JOIN (
  174. SELECT
  175. COUNT(1) as activityCount,
  176. tpvr.visit_time AS visitTime,
  177. tbet.type_name as activity
  178. FROM
  179. ta_person tp
  180. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  181. INNER JOIN td_biz_event_type tbet ON tpvr.event_type = tbet.type_id
  182. where ifnull(tp.person_type, '') != #{personType}
  183. GROUP BY tpvr.activity
  184. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visitTime , '%Y-%m-%d' )
  185. </select>
  186. <select id="selectActiveUserCount" resultType="map">
  187. SELECT
  188. *
  189. FROM
  190. (
  191. SELECT
  192. <if test="dateType == 'day'.toString()">
  193. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  194. </if>
  195. <if test="dateType == 'week'.toString()">
  196. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum WEEK ), '%Y-%m-%d' ) AS date
  197. </if>
  198. <if test="dateType == 'month'.toString()">
  199. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum MONTH ), '%Y-%m-%d' ) AS date
  200. </if>
  201. FROM
  202. sequence a
  203. WHERE
  204. <if test="startDate == null or endDate == null">
  205. a.rownum <![CDATA[ <= ]]> 7
  206. </if>
  207. <if test="startDate != null or endDate != null">
  208. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  209. </if>
  210. ) AS temp_date
  211. LEFT JOIN (
  212. SELECT
  213. COUNT(1) as activity_count,
  214. tpvr.visit_time AS visit_time
  215. FROM
  216. ta_person tp
  217. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  218. where ifnull(tp.person_type, '') != #{personType}
  219. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  220. </select>
  221. <select id="selectNewsUserCount" resultType="map">
  222. SELECT
  223. authorization_count_table.date as date,
  224. authorization_count_table.authorization_count as authorization_count,
  225. user_count_table.user_count as user_count
  226. FROM
  227. (
  228. SELECT
  229. *
  230. FROM
  231. (
  232. SELECT
  233. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  234. FROM
  235. sequence a
  236. WHERE
  237. <if test="startDate == null or endDate == null">
  238. a.rownum <![CDATA[ <= ]]> 7
  239. </if>
  240. <if test="startDate != null or endDate != null">
  241. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  242. </if>
  243. ) AS temp_date
  244. LEFT JOIN (
  245. SELECT
  246. COUNT(1) as authorization_count,
  247. tpvr.visit_time AS visit_time
  248. FROM
  249. ta_person tp
  250. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  251. where ifnull(tp.person_type, '') != #{personType}
  252. and tp.phone is NOT NULL
  253. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  254. ) as authorization_count_table
  255. ,
  256. (SELECT
  257. *
  258. FROM
  259. (
  260. SELECT
  261. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  262. FROM
  263. sequence a
  264. WHERE
  265. <if test="startDate == null or endDate == null">
  266. a.rownum <![CDATA[ <= ]]> 7
  267. </if>
  268. <if test="startDate != null or endDate != null">
  269. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  270. </if>
  271. ) AS temp_date
  272. LEFT JOIN (
  273. SELECT
  274. COUNT(1) as user_count,
  275. tpvr.visit_time AS visit_time
  276. FROM
  277. ta_person tp
  278. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  279. where ifnull(tp.person_type, '') != #{personType}
  280. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  281. ) as user_count_table
  282. GROUP BY date
  283. </select>
  284. <select id="selectUserSourcePie" resultType="integer">
  285. select count(1)
  286. FROM ta_person
  287. WHERE ifnull(person_type, '') != #{personType}
  288. <if test="recommendPersonType != null and recommendPersonType != ''">
  289. and recommend_person_type = #{recommendPersonType}
  290. </if>
  291. </select>
  292. <select id="selectUserSourceColumnar" resultType="map">
  293. SELECT
  294. tpf.from_name as from_name,
  295. (
  296. SELECT
  297. COUNT(1)
  298. FROM ta_person tps
  299. LEFT JOIN td_person_from tpfs
  300. ON tps.from_code = tpfs.from_code
  301. WHERE tpfs.from_code = tpf.from_code and tps.phone is NOT NULL
  302. and ifnull(tps.person_type, '') != #{personType}
  303. <if test="startDate != null or endDate != null">
  304. and tps.create_date BETWEEN #{startDate} and #{endDate}
  305. </if>
  306. <if test="startDate == null or endDate == null">
  307. and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
  308. </if>
  309. ) as registered,
  310. (
  311. SELECT
  312. COUNT(1)
  313. FROM ta_person tps
  314. LEFT JOIN td_person_from tpfs
  315. ON tps.from_code = tpfs.from_code
  316. WHERE tpfs.from_code = tpf.from_code
  317. and ifnull(tps.person_type, '') != #{personType}
  318. <if test="startDate != null or endDate != null">
  319. and tps.create_date BETWEEN #{startDate} and #{endDate}
  320. </if>
  321. <if test="startDate == null or endDate == null">
  322. and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
  323. </if>
  324. ) as user_count
  325. FROM td_person_from tpf
  326. LEFT JOIN ta_person tp
  327. ON tp.from_code = tpf.from_code
  328. where ifnull(tp.person_type, '') != #{personType}
  329. GROUP BY tpf.from_code
  330. </select>
  331. <select id="selectUserSourceData" resultType="map">
  332. select
  333. *
  334. FROM
  335. (
  336. SELECT
  337. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  338. FROM
  339. sequence a
  340. WHERE
  341. <if test="startDate == null or endDate == null">
  342. a.rownum <![CDATA[ <= ]]> 7
  343. </if>
  344. <if test="startDate != null or endDate != null">
  345. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  346. </if>
  347. ) AS temp_date
  348. LEFT JOIN
  349. (
  350. SELECT
  351. COUNT(1) as count,
  352. tps.create_date as create_date,
  353. tpfs.from_code as from_code,
  354. tpfs.from_name as from_name
  355. FROM ta_person tps
  356. LEFT JOIN td_person_from tpfs
  357. ON tps.from_code = tpfs.from_code
  358. WHERE tpfs.from_code = tps.from_code
  359. and ifnull(tps.person_type, '') != #{personType}
  360. GROUP BY tpfs.from_code
  361. ) as user_count
  362. ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date
  363. </select>
  364. </mapper>