TaPersonMapper.xml 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. temp_date.date as date,
  159. temp_date.type_name as activity,
  160. temp.activityCount as activityCount
  161. FROM
  162. (
  163. SELECT
  164. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date, b.type_id, b.type_name
  165. from sequence a, td_biz_event_type b
  166. where
  167. <if test="startDate == null or endDate == null">
  168. a.rownum <![CDATA[ <= ]]> 7
  169. </if>
  170. <if test="startDate != null or endDate != null">
  171. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  172. </if>
  173. ) AS temp_date
  174. LEFT JOIN (
  175. SELECT
  176. COUNT(1) as activityCount,
  177. tpvr.event_type,
  178. DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' ) as date
  179. FROM
  180. ta_person tp
  181. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  182. where ifnull(tp.person_type, '') != #{personType}
  183. <if test="buildingId != null and buildingId != ''">
  184. and tpvr.building_id = #{buildingId}
  185. </if>
  186. GROUP BY tpvr.event_type, DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' )
  187. ) AS temp ON temp_date.date = temp.date and temp_date.type_id = temp.event_type
  188. </select>
  189. <select id="selectActiveUserCount" resultType="map">
  190. SELECT
  191. *
  192. FROM
  193. (
  194. SELECT
  195. <if test="dateType == 'day'.toString()">
  196. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  197. </if>
  198. <if test="dateType == 'week'.toString()">
  199. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum WEEK ), '%Y-%m-%d' ) AS date
  200. </if>
  201. <if test="dateType == 'month'.toString()">
  202. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum MONTH ), '%Y-%m-%d' ) AS date
  203. </if>
  204. FROM
  205. sequence a
  206. WHERE
  207. <if test="startDate == null or endDate == null">
  208. a.rownum <![CDATA[ <= ]]> 7
  209. </if>
  210. <if test="startDate != null or endDate != null">
  211. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  212. </if>
  213. ) AS temp_date
  214. LEFT JOIN (
  215. SELECT
  216. COUNT(1) as activity_count,
  217. tpvr.visit_time AS visit_time
  218. FROM
  219. ta_person tp
  220. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  221. where ifnull(tp.person_type, '') != #{personType}
  222. ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
  223. </select>
  224. <select id="selectNewsUserCount" resultType="map">
  225. SELECT
  226. authorization_count_table.date as date,
  227. ifnull(authorization_count_table.authorization_count, 0) as authorization_count,
  228. ifnull(user_count_table.user_count, 0) as user_count
  229. FROM
  230. (
  231. SELECT
  232. *
  233. FROM
  234. (
  235. SELECT
  236. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  237. FROM
  238. sequence a
  239. WHERE
  240. <if test="startDate == null or endDate == null">
  241. a.rownum <![CDATA[ <= ]]> 7
  242. </if>
  243. <if test="startDate != null or endDate != null">
  244. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  245. </if>
  246. ) AS temp_date
  247. LEFT JOIN (
  248. SELECT
  249. COUNT(1) as authorization_count,
  250. tp.create_date AS create_date
  251. FROM
  252. ta_person tp
  253. where ifnull(tp.person_type, '') != #{personType}
  254. and tp.phone is NOT NULL
  255. GROUP BY tp.create_date
  256. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
  257. ) as authorization_count_table
  258. ,
  259. (
  260. SELECT
  261. *
  262. FROM
  263. (
  264. SELECT
  265. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  266. FROM
  267. sequence a
  268. WHERE
  269. <if test="startDate == null or endDate == null">
  270. a.rownum <![CDATA[ <= ]]> 7
  271. </if>
  272. <if test="startDate != null or endDate != null">
  273. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  274. </if>
  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. user_count.create_date as create_date
  344. FROM
  345. (
  346. SELECT
  347. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date,
  348. tempf.from_name as from_name,
  349. tempf.from_code as from_code
  350. FROM
  351. sequence a
  352. ,
  353. td_person_from tempf
  354. WHERE
  355. <if test="startDate == null or endDate == null">
  356. a.rownum <![CDATA[ <= ]]> 7
  357. </if>
  358. <if test="startDate != null or endDate != null">
  359. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  360. </if>
  361. ) AS temp_date
  362. LEFT JOIN
  363. (
  364. SELECT
  365. ifnull(COUNT(1), 0) as count,
  366. tps.create_date as create_date,
  367. tpfs.from_code as from_code,
  368. tpfs.from_name as from_name
  369. FROM ta_person tps
  370. LEFT JOIN td_person_from tpfs
  371. ON tps.from_code = tpfs.from_code
  372. WHERE tpfs.from_code = tps.from_code
  373. and ifnull(tps.person_type, '') != #{personType}
  374. <if test="registeredType == 'registered' and registeredType != ''">
  375. and tps.phone is not null
  376. </if>
  377. GROUP BY tpfs.from_code
  378. ) as user_count
  379. ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = user_count.from_code
  380. order by temp_date.date DESC
  381. </select>
  382. </mapper>