CrmCustomerMapper.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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.fs.crm.mapper.CrmCustomerMapper">
  6. <resultMap type="CrmCustomer" id="CrmCustomerResult">
  7. <result property="customerId" column="customer_id" />
  8. <result property="customerCode" column="customer_code" />
  9. <result property="customerName" column="customer_name" />
  10. <result property="mobile" column="mobile" />
  11. <result property="sex" column="sex" />
  12. <result property="weixin" column="weixin" />
  13. <result property="remark" column="remark" />
  14. <result property="userId" column="user_id" />
  15. <result property="createUserId" column="create_user_id" />
  16. <result property="receiveUserId" column="receive_user_id" />
  17. <result property="customerUserId" column="customer_user_id" />
  18. <result property="address" column="address" />
  19. <result property="cityIds" column="city_ids" />
  20. <result property="location" column="location" />
  21. <result property="detailAddress" column="detail_address" />
  22. <result property="lng" column="lng" />
  23. <result property="lat" column="lat" />
  24. <result property="createTime" column="create_time" />
  25. <result property="updateTime" column="update_time" />
  26. <result property="status" column="status" />
  27. <result property="isReceive" column="is_receive" />
  28. <result property="deptId" column="dept_id" />
  29. <result property="isDel" column="is_del" />
  30. <result property="customerType" column="customer_type" />
  31. <result property="receiveTime" column="receive_time" />
  32. <result property="poolTime" column="pool_time" />
  33. <result property="companyId" column="company_id" />
  34. <result property="isLine" column="is_line" />
  35. <result property="source" column="source" />
  36. <result property="tags" column="tags" />
  37. <result property="extJson" column="ext_json" />
  38. <result property="visitStatus" column="visit_status" />
  39. <result property="registerDate" column="register_date" />
  40. <result property="registerLinkUrl" column="register_link_url" />
  41. <result property="registerDesc" column="register_desc" />
  42. <result property="registerSubmitTime" column="register_submit_time" />
  43. <result property="isPool" column="is_pool" />
  44. <result property="registerType" column="register_type" />
  45. <result property="payMoney" column="pay_money" />
  46. <result property="buyCount" column="buy_count" />
  47. <result property="sourceCode" column="source_code" />
  48. <result property="pushTime" column="push_time" />
  49. <result property="pushCode" column="push_code" />
  50. <result property="visitTime" column="visit_time" />
  51. <result property="trafficSource" column="traffic_source" />
  52. <result property="importType" column="import_type" />
  53. <result property="thirdAccount" column="third_account" />
  54. <result property="clueId" column="clue_id" />
  55. <result property="qwName" column="qw_name" />
  56. <result property="platformName" column="platform_name" />
  57. <result property="goodsName" column="goods_name" />
  58. <result property="goodsSpecification" column="goods_specification" />
  59. <result property="shopName" column="shop_name" />
  60. </resultMap>
  61. <sql id="selectCrmCustomerVo">
  62. select * from ylrz_his_scrm.crm_customer
  63. </sql>
  64. <select id="selectCrmCustomerList" parameterType="CrmCustomer" resultMap="CrmCustomerResult">
  65. <include refid="selectCrmCustomerVo"/>
  66. <where>
  67. <if test="customerCode != null and customerCode != ''"> and customer_code = #{customerCode}</if>
  68. <if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
  69. <if test="mobile != null and mobile != ''"> and mobile = #{mobile}</if>
  70. <if test="sex != null "> and sex = #{sex}</if>
  71. <if test="weixin != null and weixin != ''"> and weixin = #{weixin}</if>
  72. <if test="userId != null "> and user_id = #{userId}</if>
  73. <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
  74. <if test="receiveUserId != null "> and receive_user_id = #{receiveUserId}</if>
  75. <if test="customerUserId != null "> and customer_user_id = #{customerUserId}</if>
  76. <if test="address != null and address != ''"> and address = #{address}</if>
  77. <if test="location != null and location != ''"> and location = #{location}</if>
  78. <if test="detailAddress != null and detailAddress != ''"> and detail_address = #{detailAddress}</if>
  79. <if test="lng != null and lng != ''"> and lng = #{lng}</if>
  80. <if test="lat != null and lat != ''"> and lat = #{lat}</if>
  81. <if test="status != null "> and status = #{status}</if>
  82. <if test="isReceive != null "> and is_receive = #{isReceive}</if>
  83. <if test="deptId != null "> and dept_id = #{deptId}</if>
  84. <if test="isDel != null "> and is_del = #{isDel}</if>
  85. <if test="customerType != null "> and customer_type = #{customerType}</if>
  86. <if test="receiveTime != null "> and receive_time = #{receiveTime}</if>
  87. <if test="poolTime != null "> and pool_time = #{poolTime}</if>
  88. <if test="companyId != null "> and company_id = #{companyId}</if>
  89. <if test="isLine != null "> and is_line = #{isLine}</if>
  90. <if test="source != null "> and source = #{source}</if>
  91. <if test="tags != null and tags != ''"> and tags = #{tags}</if>
  92. <if test="isPool != null "> and is_pool = #{isPool}</if>
  93. <if test="trafficSource != null "> and traffic_source = #{trafficSource}</if>
  94. <if test="importType != null "> and import_type = #{importType}</if>
  95. <if test="thirdAccount != null "> and third_account = #{thirdAccount}</if>
  96. <if test="clueId != null "> and clue_id = #{clueId}</if>
  97. <if test="qwName != null "> and qw_name = #{qwName}</if>
  98. <if test="platformName != null "> and platform_name = #{platformName}</if>
  99. <if test="goodsName != null "> and goods_name = #{goodsName}</if>
  100. <if test="goodsSpecification != null "> and goods_specification = #{goodsSpecification}</if>
  101. <if test="shopName != null "> and shop_name = #{shopName}</if>
  102. </where>
  103. order by customer_id desc
  104. </select>
  105. <select id="selectCrmCustomerById" parameterType="Long" resultMap="CrmCustomerResult">
  106. <include refid="selectCrmCustomerVo"/>
  107. where customer_id = #{customerId}
  108. </select>
  109. <select id="selectCrmCustomerByMobile" parameterType="CrmCustomer" resultMap="CrmCustomerResult">
  110. <include refid="selectCrmCustomerVo"/>
  111. where is_line = 1 and mobile = #{mobile} and customer_id != #{customerId} and company_id = #{companyId}
  112. </select>
  113. <insert id="insertCrmCustomer" parameterType="CrmCustomer" useGeneratedKeys="true" keyProperty="customerId">
  114. insert into crm_customer
  115. <trim prefix="(" suffix=")" suffixOverrides=",">
  116. <if test="customerCode != null">customer_code,</if>
  117. <if test="customerName != null">customer_name,</if>
  118. <if test="mobile != null">mobile,</if>
  119. <if test="sex != null">sex,</if>
  120. <if test="weixin != null">weixin,</if>
  121. <if test="remark != null">remark,</if>
  122. <if test="userId != null">user_id,</if>
  123. <if test="createUserId != null">create_user_id,</if>
  124. <if test="receiveUserId != null">receive_user_id,</if>
  125. <if test="customerUserId != null">customer_user_id,</if>
  126. <if test="address != null">address,</if>
  127. <if test="cityIds != null">city_ids,</if>
  128. <if test="location != null">location,</if>
  129. <if test="detailAddress != null">detail_address,</if>
  130. <if test="lng != null">lng,</if>
  131. <if test="lat != null">lat,</if>
  132. <if test="createTime != null">create_time,</if>
  133. <if test="updateTime != null">update_time,</if>
  134. <if test="status != null">status,</if>
  135. <if test="isReceive != null">is_receive,</if>
  136. <if test="deptId != null">dept_id,</if>
  137. <if test="isDel != null">is_del,</if>
  138. <if test="customerType != null">customer_type,</if>
  139. <if test="receiveTime != null">receive_time,</if>
  140. <if test="poolTime != null">pool_time,</if>
  141. <if test="companyId != null">company_id,</if>
  142. <if test="isLine != null">is_line,</if>
  143. <if test="source != null">source,</if>
  144. <if test="tags != null">tags,</if>
  145. <if test="extJson != null">ext_json,</if>
  146. <if test="visitStatus != null">visit_status,</if>
  147. <if test="registerDate != null">register_date,</if>
  148. <if test="registerLinkUrl != null">register_link_url,</if>
  149. <if test="registerDesc != null">register_desc,</if>
  150. <if test="registerSubmitTime != null">register_submit_time,</if>
  151. <if test="isPool != null">is_pool,</if>
  152. <if test="registerType != null">register_type,</if>
  153. <if test="payMoney != null">pay_money,</if>
  154. <if test="buyCount != null">buy_count,</if>
  155. <if test="sourceCode != null">source_code,</if>
  156. <if test="pushTime != null">push_time,</if>
  157. <if test="pushCode != null">push_code,</if>
  158. <if test="visitTime != null">visit_time,</if>
  159. <if test="trafficSource != null">traffic_source,</if>
  160. <if test="importType != null">import_type,</if>
  161. <if test="thirdAccount != null">third_account,</if>
  162. <if test="clueId != null">clue_id,</if>
  163. <if test="qwName != null">qw_name,</if>
  164. <if test="platformName != null">platform_name,</if>
  165. <if test="goodsName != null">goods_name,</if>
  166. <if test="goodsSpecification != null">goods_specification,</if>
  167. <if test="shopName != null">shop_name,</if>
  168. <if test="traceId != null">trace_id,</if>
  169. </trim>
  170. <trim prefix="values (" suffix=")" suffixOverrides=",">
  171. <if test="customerCode != null">#{customerCode},</if>
  172. <if test="customerName != null">#{customerName},</if>
  173. <if test="mobile != null">#{mobile},</if>
  174. <if test="sex != null">#{sex},</if>
  175. <if test="weixin != null">#{weixin},</if>
  176. <if test="remark != null">#{remark},</if>
  177. <if test="userId != null">#{userId},</if>
  178. <if test="createUserId != null">#{createUserId},</if>
  179. <if test="receiveUserId != null">#{receiveUserId},</if>
  180. <if test="customerUserId != null">#{customerUserId},</if>
  181. <if test="address != null">#{address},</if>
  182. <if test="cityIds != null">#{cityIds},</if>
  183. <if test="location != null">#{location},</if>
  184. <if test="detailAddress != null">#{detailAddress},</if>
  185. <if test="lng != null">#{lng},</if>
  186. <if test="lat != null">#{lat},</if>
  187. <if test="createTime != null">#{createTime},</if>
  188. <if test="updateTime != null">#{updateTime},</if>
  189. <if test="status != null">#{status},</if>
  190. <if test="isReceive != null">#{isReceive},</if>
  191. <if test="deptId != null">#{deptId},</if>
  192. <if test="isDel != null">#{isDel},</if>
  193. <if test="customerType != null">#{customerType},</if>
  194. <if test="receiveTime != null">#{receiveTime},</if>
  195. <if test="poolTime != null">#{poolTime},</if>
  196. <if test="companyId != null">#{companyId},</if>
  197. <if test="isLine != null">#{isLine},</if>
  198. <if test="source != null">#{source},</if>
  199. <if test="tags != null">#{tags},</if>
  200. <if test="extJson != null">#{extJson},</if>
  201. <if test="visitStatus != null">#{visitStatus},</if>
  202. <if test="registerDate != null">#{registerDate},</if>
  203. <if test="registerLinkUrl != null">#{registerLinkUrl},</if>
  204. <if test="registerDesc != null">#{registerDesc},</if>
  205. <if test="registerSubmitTime != null">#{registerSubmitTime},</if>
  206. <if test="isPool != null">#{isPool},</if>
  207. <if test="registerType != null">#{registerType},</if>
  208. <if test="payMoney != null">#{payMoney},</if>
  209. <if test="buyCount != null">#{buyCount},</if>
  210. <if test="sourceCode != null">#{sourceCode},</if>
  211. <if test="pushTime != null">#{pushTime},</if>
  212. <if test="pushCode != null">#{pushCode},</if>
  213. <if test="visitTime != null">#{visitTime},</if>
  214. <if test="trafficSource != null">#{trafficSource},</if>
  215. <if test="importType != null">#{importType},</if>
  216. <if test="thirdAccount != null">#{thirdAccount},</if>
  217. <if test="clueId != null">#{clueId},</if>
  218. <if test="qwName != null">#{qwName},</if>
  219. <if test="platformName != null">#{platformName},</if>
  220. <if test="goodsName != null">#{goodsName},</if>
  221. <if test="goodsSpecification != null">#{goodsSpecification},</if>
  222. <if test="shopName != null">#{shopName},</if>
  223. <if test="traceId != null">#{traceId},</if>
  224. </trim>
  225. </insert>
  226. <insert id="insertCrmCustomerInfo">
  227. INSERT INTO crm_customer_info
  228. <trim prefix="(" suffix=")" suffixOverrides=",">
  229. <if test="customerId != null">customer_id,</if>
  230. <if test="name != null">name,</if>
  231. <if test="sex != null">sex,</if>
  232. <if test="age != null">age,</if>
  233. <if test="address != null">address,</if>
  234. <if test="habits != null">habits,</if>
  235. <if test="illnessTime != null">illness_time,</if>
  236. <if test="body != null">body,</if>
  237. <if test="study != null">study,</if>
  238. <if test="courseStatus != null">course_status,</if>
  239. <if test="course != null">course,</if>
  240. <if test="family != null">family,</if>
  241. <if test="familyDisease != null">family_disease,</if>
  242. <if test="disease != null">disease,</if>
  243. <if test="isLine != null">is_line,</if>
  244. <if test="talk != null">talk,</if>
  245. <if test="userType != null">user_type,</if>
  246. <if test="isSelf != null">is_self,</if>
  247. <if test="intensify != null">intensify,</if>
  248. <if test="isCold != null">is_cold,</if>
  249. <if test="coldBody != null">cold_body,</if>
  250. <if test="sweat != null">sweat,</if>
  251. <if test="other != null">other,</if>
  252. <if test="toilet != null">toilet,</if>
  253. <if test="eat != null">eat,</if>
  254. <if test="menses != null">menses,</if>
  255. <if test="medicine != null">medicine,</if>
  256. <if test="constitution != null">constitution,</if>
  257. <if test="recommendMedicine != null">recommend_medicine,</if>
  258. <if test="consultProduct != null">consult_product,</if>
  259. <if test="isBuy != null">is_buy,</if>
  260. <if test="buyProduct != null">buy_product,</if>
  261. <if test="createTime != null">create_time,</if>
  262. <if test="updateTime != null">update_time,</if>
  263. <if test="replyTime != null">reply_time,</if>
  264. <if test="productTalk != null">product_talk,</if>
  265. <if test="diseaseTalk != null">disease_talk,</if>
  266. <if test="channelType != null">channel_type,</if>
  267. </trim>
  268. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  269. <if test="customerId != null">#{customerId},</if>
  270. <if test="name != null">#{name},</if>
  271. <if test="sex != null">#{sex},</if>
  272. <if test="age != null">#{age},</if>
  273. <if test="address != null">#{address},</if>
  274. <if test="habits != null">#{habits},</if>
  275. <if test="illnessTime != null">#{illnessTime},</if>
  276. <if test="body != null">#{body},</if>
  277. <if test="study != null">#{study},</if>
  278. <if test="courseStatus != null">#{courseStatus},</if>
  279. <if test="course != null">#{course},</if>
  280. <if test="family != null">#{family},</if>
  281. <if test="familyDisease != null">#{familyDisease},</if>
  282. <if test="disease != null">#{disease},</if>
  283. <if test="isLine != null">#{isLine},</if>
  284. <if test="talk != null">#{talk},</if>
  285. <if test="userType != null">#{userType},</if>
  286. <if test="isSelf != null">#{isSelf},</if>
  287. <if test="intensify != null">#{intensify},</if>
  288. <if test="isCold != null">#{isCold},</if>
  289. <if test="coldBody != null">#{coldBody},</if>
  290. <if test="sweat != null">#{sweat},</if>
  291. <if test="other != null">#{other},</if>
  292. <if test="toilet != null">#{toilet},</if>
  293. <if test="eat != null">#{eat},</if>
  294. <if test="menses != null">#{menses},</if>
  295. <if test="medicine != null">#{medicine},</if>
  296. <if test="constitution != null">#{constitution},</if>
  297. <if test="recommendMedicine != null">#{recommendMedicine},</if>
  298. <if test="consultProduct != null">#{consultProduct},</if>
  299. <if test="isBuy != null">#{isBuy},</if>
  300. <if test="buyProduct != null">#{buyProduct},</if>
  301. <if test="createTime != null">#{createTime},</if>
  302. <if test="updateTime != null">#{updateTime},</if>
  303. <if test="replyTime != null">#{replyTime},</if>
  304. <if test="productTalk != null">#{productTalk},</if>
  305. <if test="diseaseTalk != null">#{diseaseTalk},</if>
  306. <if test="channelType != null">#{channelType},</if>
  307. </trim>
  308. </insert>
  309. <update id="updateCrmCustomer" parameterType="CrmCustomer">
  310. update crm_customer
  311. <trim prefix="SET" suffixOverrides=",">
  312. <if test="customerCode != null">customer_code = #{customerCode},</if>
  313. <if test="customerName != null">customer_name = #{customerName},</if>
  314. <if test="mobile != null">mobile = #{mobile},</if>
  315. <if test="sex != null">sex = #{sex},</if>
  316. <if test="weixin != null">weixin = #{weixin},</if>
  317. <if test="remark != null">remark = #{remark},</if>
  318. <if test="userId != null">user_id = #{userId},</if>
  319. <if test="createUserId != null">create_user_id = #{createUserId},</if>
  320. <if test="receiveUserId != null">receive_user_id = #{receiveUserId},</if>
  321. <if test="customerUserId != null">customer_user_id = #{customerUserId},</if>
  322. <if test="address != null">address = #{address},</if>
  323. <if test="cityIds != null">city_ids = #{cityIds},</if>
  324. <if test="location != null">location = #{location},</if>
  325. <if test="detailAddress != null">detail_address = #{detailAddress},</if>
  326. <if test="lng != null">lng = #{lng},</if>
  327. <if test="lat != null">lat = #{lat},</if>
  328. <if test="createTime != null">create_time = #{createTime},</if>
  329. <if test="updateTime != null">update_time = #{updateTime},</if>
  330. <if test="status != null">status = #{status},</if>
  331. <if test="isReceive != null">is_receive = #{isReceive},</if>
  332. <if test="deptId != null">dept_id = #{deptId},</if>
  333. <if test="isDel != null">is_del = #{isDel},</if>
  334. <if test="customerType != null">customer_type = #{customerType},</if>
  335. <if test="receiveTime != null">receive_time = #{receiveTime},</if>
  336. <if test="poolTime != null">pool_time = #{poolTime},</if>
  337. <if test="companyId != null">company_id = #{companyId},</if>
  338. <if test="isLine != null">is_line = #{isLine},</if>
  339. <if test="source != null">source = #{source},</if>
  340. <if test="tags != null">tags = #{tags},</if>
  341. <if test="extJson != null">ext_json = #{extJson},</if>
  342. <if test="visitStatus != null">visit_status = #{visitStatus},</if>
  343. <if test="registerDate != null">register_date = #{registerDate},</if>
  344. <if test="registerLinkUrl != null">register_link_url = #{registerLinkUrl},</if>
  345. <if test="registerDesc != null">register_desc = #{registerDesc},</if>
  346. <if test="registerSubmitTime != null">register_submit_time = #{registerSubmitTime},</if>
  347. <if test="isPool != null">is_pool = #{isPool},</if>
  348. <if test="registerType != null">register_type = #{registerType},</if>
  349. <if test="payMoney != null">pay_money = #{payMoney},</if>
  350. <if test="buyCount != null">buy_count = #{buyCount},</if>
  351. <if test="sourceCode != null">source_code = #{sourceCode},</if>
  352. <if test="pushTime != null">push_time = #{pushTime},</if>
  353. <if test="pushCode != null">push_code = #{pushCode},</if>
  354. <if test="visitTime != null">visit_time = #{visitTime},</if>
  355. <if test="trafficSource != null">traffic_source = #{trafficSource},</if>
  356. <if test="importType != null">import_type = #{importType},</if>
  357. <if test="thirdAccount != null">third_account = #{thirdAccount},</if>
  358. <if test="clueId != null">clue_id = #{clueId},</if>
  359. <if test="qwName != null">qw_name = #{qwName},</if>
  360. <if test="platformName != null">platform_name = #{platformName},</if>
  361. <if test="goodsName != null">goods_name = #{goodsName},</if>
  362. <if test="goodsSpecification != null">goods_specification = #{goodsSpecification},</if>
  363. <if test="shopName != null">shop_name = #{shopName},</if>
  364. </trim>
  365. where customer_id = #{customerId}
  366. </update>
  367. <update id="updateCrmCustomerInfo">
  368. update crm_customer_info
  369. <trim prefix="SET" suffixOverrides=",">
  370. <if test="aiChatRecord != null">ai_chat_record = #{aiChatRecord},</if>
  371. </trim>
  372. where customer_id = #{customerId}
  373. </update>
  374. <delete id="deleteCrmCustomerById" parameterType="Long">
  375. delete from crm_customer where customer_id = #{customerId}
  376. </delete>
  377. <delete id="deleteCrmCustomerByIds" parameterType="String">
  378. delete from crm_customer where customer_id in
  379. <foreach item="customerId" collection="array" open="(" separator="," close=")">
  380. #{customerId}
  381. </foreach>
  382. </delete>
  383. <select id="selectCrmCustomerCounts" resultType="com.alibaba.fastjson.JSONObject">
  384. SELECT count( IF ( t.is_pool =0, 1, NULL )) AS receiveCount, t.type, count( IF ( t.is_pool = 1, 1, NULL )) AS poolCount
  385. FROM
  386. (
  387. SELECT DATE_FORMAT( cu.create_time, #{sqlDateFormat} ) AS type, cu.is_pool
  388. FROM
  389. crm_customer_user AS cu
  390. WHERE
  391. (DATE_FORMAT(cu.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
  392. AND cu.company_user_id IN
  393. <foreach item="item" collection="userIds" open="(" separator="," close=")">
  394. #{item}
  395. </foreach>
  396. ) t
  397. GROUP BY t.type
  398. </select>
  399. <select id="selectCustomerFullCounts" resultType="com.alibaba.fastjson.JSONObject">
  400. SELECT count( IF ( t.is_pool =0, 1, NULL )) AS receiveCount, t.type, count(1) AS poolCount
  401. FROM
  402. (
  403. SELECT DATE_FORMAT( cu.create_time, #{sqlDateFormat} ) AS type, cu.is_pool
  404. FROM
  405. crm_customer_user AS cu
  406. WHERE
  407. (DATE_FORMAT(cu.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
  408. AND cu.company_user_id IN
  409. <foreach item="item" collection="userIds" open="(" separator="," close=")">
  410. #{item}
  411. </foreach>
  412. ) t
  413. GROUP BY t.type
  414. </select>
  415. <select id="selectCrmCustomerNumCounts" resultType="com.alibaba.fastjson.JSONObject">
  416. SELECT count( IF ( t.visit_status =4, 1, NULL )) AS customerOkNum, t.type, count(*) AS customerNum
  417. FROM
  418. (
  419. SELECT DATE_FORMAT( cu.create_time, #{sqlDateFormat} ) AS type, cu.visit_status
  420. FROM
  421. crm_customer AS cu
  422. WHERE
  423. (DATE_FORMAT(cu.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
  424. AND cu.create_user_id IN
  425. <foreach item="item" collection="userIds" open="(" separator="," close=")">
  426. #{item}
  427. </foreach>
  428. ) t
  429. GROUP BY t.type
  430. </select>
  431. <select id="selectCrmCustomerRateCounts" resultType="com.alibaba.fastjson.JSONObject">
  432. SELECT count( IF ( t.visit_status =4, 1, NULL )) AS customerOkNum, t.type, count(*) AS customerNum ,(count( IF ( t.visit_status =4, 1, NULL ))/count(*) ) * 100 as customerRate
  433. FROM
  434. (
  435. SELECT DATE_FORMAT( cu.create_time, #{sqlDateFormat} ) AS type, cu.visit_status
  436. FROM
  437. crm_customer AS cu
  438. WHERE
  439. (DATE_FORMAT(cu.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
  440. AND cu.create_user_id IN
  441. <foreach item="item" collection="userIds" open="(" separator="," close=")">
  442. #{item}
  443. </foreach>
  444. ) t
  445. GROUP BY t.type
  446. </select>
  447. <select id="selectCrmCustomerCycleCounts" resultType="com.alibaba.fastjson.JSONObject">
  448. SELECT ROUND(AVG(DATEDIFF(t.oc, cu.t.cc))) AS customerCycle,count(1) customerOkNum, t.type
  449. FROM
  450. (
  451. SELECT DATE_FORMAT( cu.create_time, #{sqlDateFormat} ) AS type, o.create_time oc,cu.create_time cc
  452. FROM
  453. fs_store_order o left join crm_customer cu ON o.customer_id = cu.customer_id WHERE is_first=1
  454. and
  455. (DATE_FORMAT(cu.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
  456. AND cu.create_user_id IN
  457. <foreach item="item" collection="userIds" open="(" separator="," close=")">
  458. #{item}
  459. </foreach>
  460. ) t
  461. GROUP BY t.type
  462. </select>
  463. <select id="selectCustomerIdByCompanyUserId" resultType="java.lang.Long">
  464. SELECT customer_id FROM crm_customer_assist where company_user_id = #{companyUserId}
  465. </select>
  466. <select id="selectCrmMyAssistListQuery" resultType="com.fs.crm.vo.CrmMyCustomerListQueryVO">
  467. select cu.*,c.create_time as customer_create_time,c.visit_status,c.remark,c.register_desc,c.register_submit_time,
  468. c.customer_code,c.customer_name,c.mobile,c.sex,c.weixin,c.address,c.is_receive,c.customer_type,c.source,
  469. c.tags,c.receive_time, c.customer_level
  470. from crm_customer_assist ca
  471. LEFT JOIN crm_customer c on c.customer_id=ca.customer_id
  472. LEFT JOIN crm_customer_user cu on c.customer_user_id=cu.customer_user_id
  473. where c.is_pool=0 and c.is_del = 0
  474. <if test="maps.companyId != null">
  475. and ca.company_id =#{maps.companyId}
  476. </if>
  477. <if test="maps.companyUserId != null">
  478. and ca.company_user_id =#{maps.companyUserId}
  479. </if>
  480. <if test="maps.customerLevel != null">
  481. and c.customer_level =#{maps.customerLevel}
  482. </if>
  483. <if test="maps.address != null and maps.address != ''">
  484. and c.address like CONCAT('%',#{maps.address},'%')
  485. </if>
  486. <if test="maps.customerCode != null and maps.customerCode != ''">
  487. and c.customer_code like CONCAT('%',#{maps.customerCode},'%')
  488. </if>
  489. <if test="maps.customerName != null and maps.customerName != ''">
  490. and c.customer_name like CONCAT('%',#{maps.customerName},'%')
  491. </if>
  492. <if test="maps.mobile != null and maps.mobile != ''">
  493. and c.mobile like CONCAT('%',#{maps.mobile},'%')
  494. </if>
  495. <if test="maps.status != null and maps.status != ''">
  496. and c.visit_status IN
  497. <foreach collection="maps.status.split(',')" item="item" index="index" open="(" close=")" separator=",">
  498. #{item}
  499. </foreach>
  500. </if>
  501. <if test="maps.isHisOrder != null and maps.isHisOrder == 1">
  502. and (select ifnull(count(1),0) from crm_customer_his_order h where h.customer_id=c.customer_id ) &gt; 0
  503. </if>
  504. <if test="maps.isHisOrder != null and maps.isHisOrder == 0">
  505. and (select ifnull(count(1),0) from crm_customer_his_order h where h.customer_id=c.customer_id ) = 0
  506. </if>
  507. <if test="maps.customerType != null">
  508. and c.customer_type IN
  509. <foreach collection="maps.customerType.split(',')" item="item" index="index" open="(" separator="," close=")">
  510. #{item}
  511. </foreach>
  512. </if>
  513. <if test="maps.source != null and maps.source != ''">
  514. and c.source IN
  515. <foreach collection="maps.source.split(',')" item="item" index="index" open="(" separator="," close=")">
  516. #{item}
  517. </foreach>
  518. </if>
  519. <if test="maps.tags != null and maps.tags != ''">
  520. and
  521. <foreach collection="maps.tags.split(',')" item="tag" open="(" separator="OR" close=")">
  522. find_in_set(#{tag},c.tags)
  523. </foreach>
  524. </if>
  525. <if test="maps.customerCreateTime != null">
  526. AND date_format(c.create_time,'%y%m%d') &gt;= date_format(#{maps.customerCreateTime[0]},'%y%m%d')
  527. AND date_format(c.create_time,'%y%m%d') &lt;= date_format(#{maps.customerCreateTime[1]},'%y%m%d')
  528. </if>
  529. <if test="maps.beginTime != null and maps.beginTime != ''">
  530. and date_format(c.receive_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d')
  531. </if>
  532. <if test="maps.endTime != null and maps.endTime != ''">
  533. and date_format(c.receive_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')
  534. </if>
  535. order by cu.customer_user_id desc
  536. </select>
  537. <select id="selectCrmCustomerInfoById" resultType="com.fs.crm.domain.CrmCustomerInfo">
  538. SELECT
  539. id,customer_id,name,sex,age,address,habits,illness_time,body,study,course_status,course,family,family_disease,disease,is_line,
  540. talk,user_type,is_self,intensify,is_cold,cold_body,sweat,other,toilet,eat,menses,medicine,constitution,recommend_medicine,
  541. consult_product,is_buy,buy_product,create_time,update_time,reply_time,product_talk,disease_talk,channel_type
  542. FROM crm_customer_info
  543. where
  544. customer_id = #{customerId};
  545. </select>
  546. </mapper>