TaPersonMapper.xml 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. <trim prefix="where">
  139. <if test="startDate != null or endDate != null">
  140. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  141. </if>
  142. </trim>
  143. ) AS temp_date
  144. LEFT JOIN (
  145. SELECT
  146. COUNT(1) as activity_count,
  147. tpvr.visit_time AS visit_time
  148. FROM
  149. ta_person tp
  150. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  151. where ifnull(tp.person_type, '') != #{personType}
  152. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  153. </select>
  154. <select id="selectUserBehavior" resultType="com.huiju.estateagents.po.PersonPO">
  155. SELECT
  156. temp_date.date as date,
  157. temp_date.type_name as activity,
  158. temp.activityCount as activityCount
  159. FROM
  160. (
  161. SELECT
  162. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date, b.type_id, b.type_name
  163. from sequence a, td_biz_event_type b
  164. <trim prefix="where">
  165. <if test="startDate != null or endDate != null">
  166. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  167. </if>
  168. </trim>
  169. ) AS temp_date
  170. LEFT JOIN (
  171. SELECT
  172. COUNT(1) as activityCount,
  173. tpvr.event_type,
  174. DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' ) as date
  175. FROM
  176. ta_person tp
  177. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  178. where ifnull(tp.person_type, '') != #{personType}
  179. <if test="buildingId != null and buildingId != ''">
  180. and tpvr.building_id = #{buildingId}
  181. </if>
  182. <if test="eventType != null and eventType != ''">
  183. and tpvr.event_type = #{eventType}
  184. </if>
  185. <if test="event != null and event != ''">
  186. and tpvr.event = #{event}
  187. </if>
  188. <if test="activity != null and activity != ''">
  189. and tpvr.activity = #{activity}
  190. </if>
  191. GROUP BY tpvr.event_type, DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' )
  192. ) AS temp ON temp_date.date = temp.date and temp_date.type_id = temp.event_type
  193. order by temp_date.date asc
  194. </select>
  195. <select id="selectActiveUserCount" resultType="map">
  196. SELECT
  197. *
  198. FROM
  199. (
  200. SELECT
  201. <if test="dateType == 'day'.toString()">
  202. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  203. </if>
  204. <if test="dateType == 'week'.toString()">
  205. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum WEEK ), '%Y-%m-%d' ) AS date
  206. </if>
  207. <if test="dateType == 'month'.toString()">
  208. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum MONTH ), '%Y-%m-%d' ) AS date
  209. </if>
  210. FROM
  211. sequence a
  212. <trim prefix="where">
  213. <if test="startDate != null or endDate != null">
  214. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  215. </if>
  216. </trim>
  217. ) AS temp_date
  218. LEFT JOIN (
  219. SELECT
  220. COUNT(1) as activity_count,
  221. tpvr.visit_time AS visit_time
  222. FROM
  223. ta_person tp
  224. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  225. where ifnull(tp.person_type, '') != #{personType}
  226. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  227. </select>
  228. <select id="selectNewsUserCount" resultType="map">
  229. SELECT
  230. authorization_count_table.date as date,
  231. ifnull(authorization_count_table.authorization_count, 0) as authorization_count,
  232. ifnull(user_count_table.user_count, 0) as user_count
  233. FROM
  234. (
  235. SELECT
  236. *
  237. FROM
  238. (
  239. SELECT
  240. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  241. FROM
  242. sequence a
  243. <trim prefix="where">
  244. <if test="startDate != null or endDate != null">
  245. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  246. </if>
  247. </trim>
  248. ) AS temp_date
  249. LEFT JOIN (
  250. SELECT
  251. COUNT(1) as authorization_count,
  252. tp.create_date AS create_date
  253. FROM
  254. ta_person tp
  255. where ifnull(tp.person_type, '') != #{personType}
  256. and tp.phone is NOT NULL
  257. GROUP BY tp.create_date
  258. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
  259. ) as authorization_count_table
  260. ,
  261. (
  262. SELECT
  263. *
  264. FROM
  265. (
  266. SELECT
  267. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  268. FROM
  269. sequence a
  270. <trim prefix="where">
  271. <if test="startDate != null or endDate != null">
  272. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  273. </if>
  274. </trim>
  275. ) AS temp_date
  276. LEFT JOIN (
  277. SELECT
  278. COUNT(1) as user_count,
  279. tp.create_date AS create_date
  280. FROM
  281. ta_person tp
  282. where ifnull(tp.person_type, '') != #{personType}
  283. GROUP BY tp.create_date
  284. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
  285. ) as user_count_table
  286. where
  287. user_count_table.date = authorization_count_table.date
  288. GROUP BY date
  289. </select>
  290. <select id="selectUserSourcePie" resultType="integer">
  291. select count(1)
  292. FROM ta_person
  293. WHERE ifnull(person_type, '') != #{personType}
  294. <if test="recommendPersonType != null and recommendPersonType != ''">
  295. and recommend_person_type = #{recommendPersonType}
  296. </if>
  297. </select>
  298. <select id="selectUserSourceColumnar" resultType="map">
  299. SELECT
  300. tpf.from_name as from_name,
  301. (
  302. SELECT
  303. COUNT(1)
  304. FROM ta_person tps
  305. LEFT JOIN td_person_from tpfs
  306. ON tps.from_code = tpfs.from_code
  307. WHERE tpfs.from_code = tpf.from_code and tps.phone is NOT NULL
  308. and ifnull(tps.person_type, '') != #{personType}
  309. <if test="startDate != null or endDate != null">
  310. and tps.create_date BETWEEN #{startDate} and #{endDate}
  311. </if>
  312. <if test="startDate == null or endDate == null">
  313. and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
  314. </if>
  315. ) as registered,
  316. (
  317. SELECT
  318. COUNT(1)
  319. FROM ta_person tps
  320. LEFT JOIN td_person_from tpfs
  321. ON tps.from_code = tpfs.from_code
  322. WHERE tpfs.from_code = tpf.from_code
  323. and ifnull(tps.person_type, '') != #{personType}
  324. <if test="startDate != null or endDate != null">
  325. and tps.create_date BETWEEN #{startDate} and #{endDate}
  326. </if>
  327. <if test="startDate == null or endDate == null">
  328. and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
  329. </if>
  330. ) as user_count
  331. FROM td_person_from tpf
  332. LEFT JOIN ta_person tp
  333. ON tp.from_code = tpf.from_code
  334. where ifnull(tp.person_type, '') != #{personType}
  335. GROUP BY tpf.from_code
  336. </select>
  337. <select id="selectUserSourceData" resultType="map">
  338. select
  339. temp_date.date AS date,
  340. temp_date.from_name as from_name,
  341. temp_date.from_code as from_code,
  342. IFNULL(user_count.count, 0) as count,
  343. IFNULL(registered_count.count,0) as registered,
  344. user_count.create_date as create_date
  345. FROM
  346. (
  347. SELECT
  348. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date,
  349. tempf.from_name as from_name,
  350. tempf.from_code as from_code
  351. FROM
  352. sequence a
  353. ,
  354. td_person_from tempf
  355. <trim prefix="where">
  356. <if test="startDate != null or endDate != null">
  357. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  358. </if>
  359. </trim>
  360. ) AS temp_date
  361. LEFT JOIN
  362. (
  363. SELECT
  364. ifnull(COUNT(1), 0) as count,
  365. tps.create_date as create_date,
  366. tpfs.from_code as from_code,
  367. tpfs.from_name as from_name
  368. FROM ta_person tps
  369. LEFT JOIN td_person_from tpfs
  370. ON tps.from_code = tpfs.from_code
  371. WHERE tpfs.from_code = tps.from_code
  372. and ifnull(tps.person_type, '') != 'Realty Consultant'
  373. GROUP BY tpfs.from_code
  374. ) as user_count
  375. ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = user_count.from_code
  376. LEFT JOIN
  377. (
  378. SELECT
  379. ifnull(COUNT(1), 0) as count,
  380. tps.create_date as create_date,
  381. tpfs.from_code as from_code,
  382. tpfs.from_name as from_name
  383. FROM ta_person tps
  384. LEFT JOIN td_person_from tpfs
  385. ON tps.from_code = tpfs.from_code
  386. WHERE tpfs.from_code = tps.from_code
  387. and ifnull(tps.person_type, '') != 'Realty Consultant'
  388. and tps.phone is not null
  389. GROUP BY tpfs.from_code
  390. ) as registered_count
  391. ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = registered_count.from_code
  392. order by temp_date.date DESC
  393. </select>
  394. </mapper>