WeCustomerMapper.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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.linkwechat.mapper.WeCustomerMapper">
  6. <update id="updateDelByUpdate">
  7. update we_customer wcr
  8. set wcr.del_flag=1
  9. where date_format(wcr.update_time,'%Y-%m-%d') != date_format(#{date},'%Y-%m-%d')
  10. and wcr.del_flag=0
  11. </update>
  12. <select id="findWeCustomerListIds" resultType="java.lang.String">
  13. SELECT wcr.id FROM we_customer wcr
  14. <where>
  15. <if test="weCustomerList.gender !=null">
  16. AND wcr.gender=#{weCustomerList.gender}
  17. </if>
  18. <if test="weCustomerList.source !=null">
  19. AND wcr.source=#{weCustomerList.source}
  20. </if>
  21. <if test="weCustomerList.trackState !=null">
  22. AND wcr.track_state=#{weCustomerList.trackState}
  23. </if>
  24. <if test="weCustomerList.addMethod !=null">
  25. AND wcr.add_method=#{weCustomerList.addMethod}
  26. </if>
  27. <if test="weCustomerList.customerType !=null">
  28. AND wcr.customer_type=#{weCustomerList.customerType}
  29. </if>
  30. <if test="weCustomerList.externalUserid !=null">
  31. AND wcr.external_userid=#{weCustomerList.externalUserid}
  32. </if>
  33. <if test="weCustomerList.firstUserId !=null">
  34. AND wcr.add_user_id=#{weCustomerList.firstUserId}
  35. </if>
  36. <if test="weCustomerList.delFlag != null">
  37. AND wcr.del_flag = #{weCustomerList.delFlag}
  38. </if>
  39. <if test="weCustomerList.name != null and weCustomerList.name !=''">
  40. AND CONCAT( IFNULL(wcr.customer_name,''))
  41. LIKE CONCAT('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
  42. </if>
  43. <if test="weCustomerList.userIds !=null and weCustomerList.userIds !=''">
  44. AND wcr.add_user_id in
  45. <foreach collection="weCustomerList.userIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
  46. #{item}
  47. </foreach>
  48. </if>
  49. <if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
  50. <foreach item="tagId" index="index" collection="weCustomerList.tagIds.split(',')">
  51. AND FIND_IN_SET(#{tagId},wcr.tag_ids)
  52. </foreach>
  53. </if>
  54. <if test="weCustomerList.noTagCheck">
  55. AND ISNULL(wcr.tag_ids) or LENGTH(TRIM(wcr.tag_ids)) =0
  56. </if>
  57. <if test="weCustomerList.excludeTagIds !=null and weCustomerList.excludeTagIds !=''">
  58. <foreach item="excludeTagId" index="index" collection="weCustomerList.excludeTagIds.split(',')">
  59. AND !FIND_IN_SET(#{excludeTagId},wcr.tag_ids)
  60. </foreach>
  61. </if>
  62. <if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
  63. AND date_format(wcr.add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
  64. </if>
  65. </where>
  66. ORDER BY wcr.add_time desc
  67. <if test="pageDomain !=null">
  68. <if test="pageDomain.pageNum !=null and pageDomain.pageSize !=null">
  69. limit ${pageDomain.pageSize * (pageDomain.pageNum-1)}, #{pageDomain.pageSize}
  70. </if>
  71. </if>
  72. </select>
  73. <select id="findWeUserIds" resultType="java.lang.String">
  74. select we_user_id from sys_user
  75. </select>
  76. <select id="findWeCustomerListIdsByApp" resultType="java.lang.String">
  77. SELECT wcr.id FROM we_customer wcr
  78. LEFT JOIN sys_user su on su.we_user_id=wcr.add_user_id
  79. <where>
  80. <if test="weCustomerList.name != null and weCustomerList.name !=''">
  81. AND CONCAT( IFNULL(wcr.customer_name,''),IFNULL(su.user_name,''))
  82. LIKE CONCAT('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
  83. </if>
  84. <if test="weCustomerList.customerType !=null">
  85. AND wcr.customer_type=#{weCustomerList.customerType}
  86. </if>
  87. <if test="weCustomerList.trackState !=null">
  88. AND wcr.track_state=#{weCustomerList.trackState}
  89. </if>
  90. <if test="weCustomerList.addMethod !=null">
  91. AND wcr.add_method=#{weCustomerList.addMethod}
  92. </if>
  93. <if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
  94. <foreach item="tagId" index="index" collection="weCustomerList.tagIds.split(',')">
  95. AND FIND_IN_SET(#{tagId},wcr.tag_ids)
  96. </foreach>
  97. </if>
  98. <if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
  99. AND date_format(wcr.add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
  100. </if>
  101. <if test="weCustomerList.firstUserId !=null">
  102. AND wcr.add_user_id=#{weCustomerList.firstUserId}
  103. </if>
  104. <if test="weCustomerList.delFlag != null">
  105. AND wcr.del_flag = #{weCustomerList.delFlag}
  106. </if>
  107. </where>
  108. ORDER BY wcr.add_time desc
  109. <if test="pageDomain !=null">
  110. <if test="pageDomain.pageNum !=null and pageDomain.pageSize !=null">
  111. limit ${pageDomain.pageSize * (pageDomain.pageNum-1)}, #{pageDomain.pageSize}
  112. </if>
  113. </if>
  114. </select>
  115. <select id="countWeCustomerListByApp" resultType="long">
  116. SELECT count(wcr.id) FROM we_customer wcr
  117. LEFT JOIN sys_user su on su.we_user_id=wcr.add_user_id
  118. <where>
  119. <if test="weCustomerList.name != null and weCustomerList.name !=''">
  120. AND CONCAT( IFNULL(wcr.customer_name,''),IFNULL(su.user_name,''))
  121. LIKE CONCAT('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
  122. </if>
  123. <if test="weCustomerList.customerType !=null">
  124. AND wcr.customer_type=#{weCustomerList.customerType}
  125. </if>
  126. <if test="weCustomerList.trackState !=null">
  127. AND wcr.track_state=#{weCustomerList.trackState}
  128. </if>
  129. <if test="weCustomerList.addMethod !=null">
  130. AND wcr.add_method=#{weCustomerList.addMethod}
  131. </if>
  132. <if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
  133. <foreach item="tagId" index="index" collection="weCustomerList.tagIds.split(',')">
  134. AND FIND_IN_SET(#{tagId},wcr.tag_ids)
  135. </foreach>
  136. </if>
  137. <if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
  138. AND date_format(wcr.add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
  139. </if>
  140. <if test="weCustomerList.firstUserId !=null">
  141. AND wcr.add_user_id=#{weCustomerList.firstUserId}
  142. </if>
  143. <if test="weCustomerList.delFlag != null">
  144. AND wcr.del_flag = #{weCustomerList.delFlag}
  145. </if>
  146. </where>
  147. </select>
  148. <select id="findWeCustomerList" resultType="com.linkwechat.domain.customer.vo.WeCustomersVo">
  149. SELECT
  150. wc.id,
  151. wc.unionid,
  152. wc.avatar,
  153. wc.customer_name,
  154. wc.customer_full_name,
  155. wc.customer_type as customerType,
  156. wc.external_userid,
  157. wc.add_user_id as firstUserId,
  158. wc.track_state,
  159. wc.add_method,
  160. wc.add_time as firstAddTime,
  161. wc.birthday,
  162. wc.gender,
  163. MOBILE_MASK(wc.phone) phone,
  164. wc.email,
  165. wc.address,
  166. wc.qq,
  167. wc.source,
  168. wc.position,
  169. wc.corp_name as corpName,
  170. wc.other_descr as otherDescr,
  171. timestampdiff(day,wc.add_time,NOW()) as retentionDays,
  172. (SELECT GROUP_CONCAT(DISTINCT wu.user_name) FROM sys_user wu WHERE wu.we_user_id=wc.add_user_id) as userName,
  173. (SELECT GROUP_CONCAT(wt.tag_id) FROM we_flower_customer_tag_rel wfctr
  174. LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
  175. WHERE wfctr.external_userid=wc.external_userid AND wc.add_user_id=wfctr.user_id AND wt.tag_type=3 and wfctr.del_flag=0) as personTagIds,
  176. (SELECT GROUP_CONCAT(wt.name) FROM we_flower_customer_tag_rel wfctr
  177. LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
  178. WHERE wfctr.external_userid=wc.external_userid AND wc.add_user_id=wfctr.user_id AND wt.tag_type=3 and wfctr.del_flag=0) as personTagNames,
  179. (SELECT GROUP_CONCAT(wt.name) FROM we_flower_customer_tag_rel wfctr
  180. LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
  181. WHERE wfctr.external_userid=wc.external_userid AND wc.add_user_id=wfctr.user_id AND wt.tag_type=1 and wfctr.del_flag=0) as tagNames,
  182. (SELECT GROUP_CONCAT(wt.tag_id) FROM we_flower_customer_tag_rel wfctr
  183. LEFT JOIN we_tag wt ON wt.tag_id= wfctr.tag_id
  184. WHERE wfctr.external_userid=wc.external_userid AND wc.add_user_id=wfctr.user_id AND wt.tag_type=1 and wfctr.del_flag=0) as tagIds,
  185. wc.update_time as updateTime,
  186. IF(wc.del_flag = 0,'有效','无效') as delFlagName,
  187. IF(wc.del_flag = 1, (case when wc.del_flag_ba = 1 and wc.del_flag_bei = 0 then '客户删除员工'
  188. when wc.del_flag_ba = 0 and wc.del_flag_bei = 1 then '员工删除客户'
  189. when wc.del_flag_ba = 1 and wc.del_flag_bei = 1 then '双向删除'
  190. else '未知'
  191. end), '正常') as delFlagStatus
  192. FROM
  193. we_customer wc
  194. WHERE
  195. wc.id in
  196. <foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
  197. #{id}
  198. </foreach>
  199. ORDER BY wc.add_time desc
  200. </select>
  201. <select id="countWeCustomerList" resultType="long">
  202. SELECT count(0) FROM we_customer wcr
  203. <where>
  204. <if test="weCustomerList.gender !=null">
  205. AND wcr.gender=#{weCustomerList.gender}
  206. </if>
  207. <if test="weCustomerList.source !=null">
  208. AND wcr.source=#{weCustomerList.source}
  209. </if>
  210. <if test="weCustomerList.trackState !=null">
  211. AND wcr.track_state=#{weCustomerList.trackState}
  212. </if>
  213. <if test="weCustomerList.addMethod !=null">
  214. AND wcr.add_method=#{weCustomerList.addMethod}
  215. </if>
  216. <if test="weCustomerList.customerType !=null">
  217. AND wcr.customer_type=#{weCustomerList.customerType}
  218. </if>
  219. <if test="weCustomerList.externalUserid !=null">
  220. AND wcr.external_userid=#{weCustomerList.externalUserid}
  221. </if>
  222. <if test="weCustomerList.firstUserId !=null">
  223. AND wcr.add_user_id=#{weCustomerList.firstUserId}
  224. </if>
  225. <if test="weCustomerList.delFlag != null">
  226. AND wcr.del_flag = #{weCustomerList.delFlag}
  227. </if>
  228. <if test="weCustomerList.name != null and weCustomerList.name !=''">
  229. AND CONCAT( IFNULL(wcr.customer_name,''))
  230. LIKE CONCAT('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
  231. </if>
  232. <if test="weCustomerList.userIds !=null and weCustomerList.userIds !=''">
  233. AND wcr.add_user_id in
  234. <foreach collection="weCustomerList.userIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
  235. #{item}
  236. </foreach>
  237. </if>
  238. <if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
  239. <foreach item="tagId" index="index" collection="weCustomerList.tagIds.split(',')">
  240. AND FIND_IN_SET(#{tagId},wcr.tag_ids)
  241. </foreach>
  242. </if>
  243. <if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
  244. AND date_format(wcr.add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
  245. </if>
  246. </where>
  247. </select>
  248. <select id="noRepeatCountCustomer" resultType="long">
  249. SELECT
  250. COUNT(DISTINCT wc.external_userid)
  251. FROM
  252. we_customer wc
  253. <where>
  254. <if test="weCustomerList.gender !=null">
  255. AND wc.gender=#{weCustomerList.gender}
  256. </if>
  257. <if test="weCustomerList.trackState !=null">
  258. AND wc.track_state=#{weCustomerList.trackState}
  259. </if>
  260. <if test="weCustomerList.addMethod !=null">
  261. AND wc.add_method=#{weCustomerList.addMethod}
  262. </if>
  263. <if test="weCustomerList.customerType !=null">
  264. AND wc.customer_type=#{weCustomerList.customerType}
  265. </if>
  266. <if test="weCustomerList.externalUserid !=null">
  267. AND wc.external_userid=#{weCustomerList.externalUserid}
  268. </if>
  269. <if test="weCustomerList.firstUserId !=null">
  270. AND wc.add_user_id=#{weCustomerList.firstUserId}
  271. </if>
  272. <if test="weCustomerList.delFlag != null">
  273. AND wc.del_flag = #{weCustomerList.delFlag}
  274. </if>
  275. <if test="weCustomerList.name != null and weCustomerList.name !=''">
  276. AND wc.customer_name like concat('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
  277. </if>
  278. <if test="weCustomerList.userIds !=null and weCustomerList.userIds !=''">
  279. AND wc.add_user_id in
  280. <foreach collection="weCustomerList.userIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
  281. #{item}
  282. </foreach>
  283. </if>
  284. <if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
  285. <foreach item="tagId" index="index" collection="weCustomerList.tagIds.split(',')">
  286. AND FIND_IN_SET(#{tagId},tag_ids)
  287. </foreach>
  288. </if>
  289. <if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
  290. AND date_format(wc.add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
  291. </if>
  292. </where>
  293. </select>
  294. <select id="findWecustomerGroups" resultType="com.linkwechat.domain.customer.vo.WeCustomerDetailInfoVo$Groups">
  295. SELECT
  296. wg.chat_id,
  297. wg.group_name,
  298. wgm.join_time,
  299. wgm.join_scene,
  300. (SELECT distinct wu.user_name FROM sys_user wu WHERE wu.we_user_id=wg.owner) as leaderName
  301. FROM
  302. we_group_member wgm
  303. LEFT JOIN we_group wg ON wg.chat_id = wgm.chat_id
  304. WHERE wgm.del_flag=0 and wg.del_flag=0 AND wgm.user_id=#{userId}
  305. ORDER BY wgm.join_time
  306. </select>
  307. <select id="findUserNameByUserId" resultType="String">
  308. SELECT DISTINCT user_name FROM sys_user WHERE we_user_id=#{weUserId} and del_flag = 0
  309. </select>
  310. <select id="findCustomerByOperUseridAndCustomerId" resultType="com.linkwechat.domain.customer.vo.WeCustomerPortraitVo">
  311. SELECT
  312. wc.id as customerId,
  313. wc.customer_name as name,
  314. wc.other_descr as remark,
  315. wc.phone as remarkMobiles,
  316. wc.birthday,
  317. wc.email,
  318. wc.address,
  319. wc.qq,
  320. wc.position,
  321. wc.corp_name as remarkCorpName,
  322. wc.other_descr as description,
  323. wc.add_user_id as user_id,
  324. wc.avatar,
  325. wc.external_userid,
  326. wc.gender,
  327. wc.track_state,
  328. wc.customer_type,
  329. GROUP_CONCAT(if(wt.tag_type=1,wt.`tag_id`,null )) as tagIds,
  330. GROUP_CONCAT(if(wt.tag_type=1,wt.`name`,null )) as tagNames,
  331. GROUP_CONCAT(if(wt.tag_type=3,wt.`tag_id`,null )) as personTagIds,
  332. GROUP_CONCAT(if(wt.tag_type=3,wt.`name`,null )) as personTagNames,
  333. wc.track_content as content,
  334. wc.province_id,
  335. wc.city_id,
  336. wc.area_id,
  337. wc.area,
  338. wc.customer_full_name as customerFullName
  339. FROM
  340. we_customer wc
  341. LEFT JOIN we_flower_customer_tag_rel wfcrf ON wfcrf.user_id = wc.add_user_id AND wfcrf.external_userid=wc.external_userid AND wfcrf.del_flag=0
  342. LEFT JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id
  343. WHERE wc.external_userid=#{externalUserid} and wc.add_user_id=#{userid}
  344. </select>
  345. <select id="countSocialConn" resultType="com.linkwechat.domain.customer.vo.WeCustomerSocialConnVo">
  346. SELECT
  347. (
  348. SELECT
  349. count(DISTINCT wfcr.add_user_id)
  350. FROM
  351. we_customer wfcr WHERE wfcr.external_userid=wc.external_userid
  352. ) AS addEmployeNum,
  353. (
  354. SELECT
  355. COUNT(*)
  356. FROM
  357. we_group_member wgm where wgm.union_id=wc.external_userid
  358. ) AS addGroupNum,
  359. (
  360. SELECT
  361. COUNT(*)
  362. FROM we_group_member where chat_id in (
  363. SELECT
  364. chat_id
  365. FROM
  366. `we_group_member` where union_id=wc.external_userid
  367. ) and user_id=#{userid}
  368. ) AS commonGroupNum
  369. FROM we_customer wc WHERE wc.external_userid=#{externalUserid} and wc.add_user_id=#{userid}
  370. </select>
  371. <select id="findWeUserByCutomerId" resultType="com.linkwechat.domain.customer.vo.WeCustomerAddUserVo">
  372. SELECT
  373. wu.user_name,
  374. wc.add_user_id as userId,
  375. wu.avatar as headImageUrl,
  376. wc.add_time as createTime
  377. FROM
  378. we_customer wc
  379. INNER JOIN sys_user wu ON wc.add_user_id = wu.we_user_id
  380. WHERE wc.external_userid=#{externalUserid} and wu.del_flag=0
  381. </select>
  382. <insert id="batchAddOrUpdate">
  383. INSERT INTO we_customer(
  384. id,
  385. external_userid,
  386. customer_name,
  387. customer_full_name,
  388. avatar,
  389. customer_type,
  390. gender,
  391. unionid,
  392. birthday,
  393. corp_name,
  394. `position`,
  395. is_open_chat,
  396. create_time,
  397. create_by,
  398. add_user_id,
  399. add_time,
  400. qq,
  401. email,
  402. address,
  403. phone,
  404. add_method,
  405. del_flag,
  406. `state`,
  407. update_by,
  408. update_time,
  409. other_descr,
  410. remark_name,
  411. create_by_id,
  412. update_by_id,
  413. tag_ids
  414. ) values
  415. <foreach collection="weCustomers" item="item" index="index" separator=",">
  416. (#{item.id},#{item.externalUserid},#{item.customerName},#{item.customerFullName},#{item.avatar},#{item.customerType},#{item.gender}, #{item.unionid},#{item.birthday},
  417. #{item.corpName},#{item.position},#{item.isOpenChat}, #{item.createTime},
  418. #{item.createBy},#{item.addUserId},#{item.addTime},#{item.qq},#{item.email},#{item.address},#{item.phone},#{item.addMethod},#{item.delFlag},
  419. #{item.state},#{item.updateBy},#{item.updateTime},#{item.otherDescr},#{item.remarkName},#{item.createById},#{item.updateById},
  420. #{item.tagIds}
  421. )
  422. </foreach>
  423. ON DUPLICATE KEY UPDATE
  424. customer_name=IFNULL(VALUES(customer_name),we_customer.customer_name),
  425. customer_full_name=IFNULL(VALUES(customer_full_name),we_customer.customer_full_name),
  426. avatar=IFNULL(VALUES(avatar), we_customer.avatar),
  427. customer_type=IFNULL(VALUES(customer_type),we_customer.customer_type),
  428. gender=IFNULL(VALUES(gender), we_customer.gender),
  429. unionid=IFNULL(VALUES(unionid), we_customer.unionid),
  430. birthday=IFNULL(VALUES(birthday), we_customer.birthday),
  431. corp_name=IFNULL(VALUES(corp_name), we_customer.corp_name),
  432. `position`=IFNULL(VALUES(`position`), we_customer.position),
  433. is_open_chat=IFNULL(VALUES(is_open_chat), we_customer.is_open_chat),
  434. add_user_id=IFNULL(VALUES(add_user_id), we_customer.add_user_id),
  435. add_time=IFNULL(VALUES(add_time),we_customer.add_time),
  436. qq=IFNULL(VALUES(qq), we_customer.qq),
  437. email=IFNULL(VALUES(email), we_customer.email),
  438. address=IFNULL(VALUES(address), we_customer.address),
  439. phone=IFNULL(VALUES(phone), we_customer.phone),
  440. add_method=IFNULL(VALUES(add_method), we_customer.add_method),
  441. del_flag=IFNULL(VALUES(del_flag),we_customer.del_flag),
  442. `state`=IFNULL(VALUES(`state`),we_customer.state),
  443. create_by=IFNULL(VALUES(create_by),we_customer.create_by),
  444. create_by_id=IFNULL(VALUES(create_by_id),we_customer.create_by_id),
  445. update_by=IFNULL(VALUES(update_by),we_customer.update_by),
  446. update_by_id=IFNULL(VALUES(update_by_id),we_customer.update_by_id),
  447. update_time=IFNULL(VALUES(update_time),we_customer.update_time),
  448. other_descr=IFNULL(VALUES(other_descr),we_customer.other_descr),
  449. tag_ids=IFNULL(VALUES(tag_ids),we_customer.tag_ids),
  450. loss_time=IFNULL(VALUES(loss_time),we_customer.loss_time),
  451. del_flag_bei=IFNULL(VALUES(del_flag_bei),we_customer.del_flag_bei),
  452. del_flag_ba=IFNULL(VALUES(del_flag_ba),we_customer.del_flag_ba),
  453. remark_name=IFNULL(VALUES(remark_name),we_customer.remark_name);
  454. </insert>
  455. <select id="findCurrentTenantSysUser" resultType="com.linkwechat.common.core.domain.entity.SysUser">
  456. SELECT * FROM sys_user
  457. </select>
  458. <select id="findCurrentSysUserInfo" resultType="com.linkwechat.common.core.domain.entity.SysUser">
  459. SELECT * FROM sys_user where user_id=#{userId}
  460. </select>
  461. <select id="findSysUserInfoByWeUserId" resultType="com.linkwechat.common.core.domain.entity.SysUser">
  462. SELECT * FROM sys_user where we_user_id= #{weUserId}
  463. </select>
  464. <select id="getCustomerListByCondition" resultType="com.linkwechat.domain.WeCustomer">
  465. select distinct wc.external_userid,
  466. wc.add_user_id
  467. from we_customer wc
  468. left join sys_user su on wc.add_user_id = su.we_user_id and su.del_flag = 0
  469. left join sys_user_dept sud
  470. on sud.we_user_id = su.we_user_id and sud.del_flag = 0
  471. left join we_flower_customer_tag_rel wfctr
  472. on wfctr.external_userid = wc.external_userid and wfctr.del_flag = 0
  473. <where>
  474. <if test="userIds != null and userIds != ''">
  475. and su.we_user_id in
  476. <foreach collection="userIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
  477. #{item}
  478. </foreach>
  479. </if>
  480. <if test="deptIds != null and deptIds != ''">
  481. and sud.dept_id in
  482. <foreach collection="deptIds.split(',')" item="item" index="index" open="(" close=")" separator=",">
  483. #{item}
  484. </foreach>
  485. </if>
  486. <if test="tagIds != null and tagIds != ''">
  487. <foreach item="tagId" index="index" collection="tagIds.split(',')">
  488. AND FIND_IN_SET(#{tagId},wfctr.tag_id)
  489. </foreach>
  490. </if>
  491. <if test="beginTime !=null and beginTime != ''">
  492. and date_format(wc.add_time,'%Y-%m-%d') &gt;= #{beginTime}
  493. </if>
  494. <if test="endTime != null and endTime != ''">
  495. and date_format(wc.add_time,'%Y-%m-%d') &lt;= #{endTime}
  496. </if>
  497. <if test="stateList != null and stateList.size() > 0">
  498. and wc.state in
  499. <foreach item="state" collection="states" index="index" open="(" separator="," close=")">
  500. #{state}
  501. </foreach>
  502. </if>
  503. </where>
  504. and wc.del_flag = 0
  505. </select>
  506. <select id="findAllSysUser" resultType="com.linkwechat.common.core.domain.entity.SysUser">
  507. SELECT * FROM sys_user where del_flag=0
  508. </select>
  509. <delete id="deleteWeCustomer">
  510. DELETE from we_customer where external_userid=#{externalUserId} and add_user_id=#{userId}
  511. </delete>
  512. <delete id="removeById">
  513. DELETE from we_customer where id=#{userId}
  514. </delete>
  515. <select id="findWeCustomerListEuIds" resultType="java.lang.String">
  516. SELECT wcr.external_userid FROM we_customer wcr
  517. LEFT JOIN sys_user su on su.we_user_id=wcr.add_user_id
  518. <where>
  519. <if test="weCustomerList.name != null and weCustomerList.name !=''">
  520. AND CONCAT( IFNULL(wcr.customer_name,''),IFNULL(su.user_name,''))
  521. LIKE CONCAT('%',#{weCustomerList.name,jdbcType=VARCHAR},'%')
  522. </if>
  523. <if test="weCustomerList.customerType !=null">
  524. AND wcr.customer_type=#{weCustomerList.customerType}
  525. </if>
  526. <if test="weCustomerList.trackState !=null">
  527. AND wcr.track_state=#{weCustomerList.trackState}
  528. </if>
  529. <if test="weCustomerList.isFilterLossCustomer">
  530. AND wcr.track_state != 5
  531. </if>
  532. <if test="weCustomerList.addMethod !=null">
  533. AND wcr.add_method=#{weCustomerList.addMethod}
  534. </if>
  535. <if test="weCustomerList.tagIds !=null and weCustomerList.tagIds !=''">
  536. <foreach item="tagId" index="index" collection="weCustomerList.tagIds.split(',')">
  537. AND FIND_IN_SET(#{tagId},wcr.tag_ids)
  538. </foreach>
  539. </if>
  540. <if test="weCustomerList.beginTime !=null and weCustomerList.beginTime != '' and weCustomerList.endTime !='' and weCustomerList.endTime != null">
  541. AND date_format(wcr.add_time,'%Y-%m-%d') BETWEEN #{weCustomerList.beginTime} AND #{weCustomerList.endTime}
  542. </if>
  543. <if test="weCustomerList.firstUserId !=null">
  544. AND wcr.add_user_id in
  545. <foreach collection="weCustomerList.firstUserId.split(',')" item="item" index="index" open="(" close=")" separator=",">
  546. #{item}
  547. </foreach>
  548. </if>
  549. <if test="weCustomerList.delFlag != null">
  550. AND wcr.del_flag = #{weCustomerList.delFlag}
  551. </if>
  552. </where>
  553. ORDER BY wcr.add_time desc
  554. </select>
  555. <select id="selectList1" resultType="com.linkwechat.domain.WeCustomer">
  556. SELECT * FROM we_customer
  557. where add_user_id = #{addUserId}
  558. and external_userid=#{externalUserid}
  559. </select>
  560. <select id="selectWeQrAdd" resultType="java.lang.String">
  561. SELECT we_user_id FROM we_qr_add a where a.del_flag=0
  562. </select>
  563. </mapper>