CmBehaviorRecordMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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.caimei365.tools.mapper.CmBehaviorRecordMapper">
  4. <insert id="insertRecord" parameterType="com.caimei365.tools.model.po.CmBehaviorRecordPo" useGeneratedKeys="true" keyProperty="recordID">
  5. INSERT INTO cm_behavior_record (IP, userID, pagePath, pageType, pageLabel, behaviorType, productID, accessTime, accessDuration, accessDate,referer,accessSource,accessClient,isReckon,region,userAgent,delFlag)
  6. VALUES(#{IP},#{userId},#{pagePath},#{pageType},#{pageLabel},#{behaviorType},#{productId},#{accessTime},#{accessDuration},#{accessDate},#{referer},#{accessSource},#{accessClient},#{isReckon},#{region},#{userAgent},#{delFlag})
  7. </insert>
  8. <select id="toDateRecode" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  9. SELECT IP, userID FROM cm_behavior_record WHERE accessDate = #{accessDate} GROUP BY IP, userID
  10. </select>
  11. <select id="toDateIPTimeRecode" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  12. SELECT recordID, IP, userID, accessTime FROM cm_behavior_record WHERE IP = #{IP} AND userID = #{userId} AND isReckon = 0
  13. AND accessTime BETWEEN #{startTime} and #{endTime}
  14. union
  15. SELECT recordID, IP, userID, accessTime FROM cm_behavior_record WHERE IP = #{IP} AND isReckon = 0 AND accessDate = #{accessDate} AND userID = #{userId}
  16. ORDER BY accessTime ASC
  17. </select>
  18. <update id="updateDuration">
  19. UPDATE cm_behavior_record
  20. SET accessDuration = #{accessDuration},
  21. isReckon = #{isReckon}
  22. WHERE recordID = #{recordID}
  23. </update>
  24. <select id="findList" resultType="com.caimei365.tools.model.po.CmUserPo">
  25. SELECT userID, registerIP FROM USER where userID between #{startId} and #{endId}
  26. </select>
  27. <update id="updateOldData">
  28. UPDATE USER
  29. SET ipAddress = #{ipAddress}
  30. WHERE userID = #{userID}
  31. </update>
  32. <select id="selSvipCoupon" resultType="com.caimei365.tools.model.po.CmVipCouponPo">
  33. SELECT id,
  34. useTime,
  35. updateTime,
  36. status,
  37. delFlag
  38. FROM cm_svip_coupon_month WHERE delFlag != 0 AND useTime BETWEEN #{startTime} AND #{endTime}
  39. </select>
  40. <update id="updateSvipCoupon">
  41. UPDATE cm_svip_coupon_month
  42. SET delFlag = 0
  43. WHERE id = #{id}
  44. </update>
  45. <insert id="insertVipCouponMonth">
  46. INSERT INTO cm_svip_coupon_month (useTime, updateTime, status,delFlag)
  47. VALUES (#{useTime}, #{updateTime}, #{status}, #{delFlag})
  48. </insert>
  49. <select id="selCoupon" resultType="com.caimei365.tools.model.po.CmCouponPo">
  50. SELECT
  51. id,
  52. name,
  53. couponAmount,
  54. touchPrice,
  55. startDate,
  56. endDate,
  57. receivePeriod,
  58. useTimeFlag,
  59. receiveFlag,
  60. usePeriod,
  61. status,
  62. couponType,
  63. vipFlag,
  64. userId,
  65. shopId,
  66. productType,
  67. pcBanner,
  68. appletsBanner,
  69. categoryType,
  70. couponsMode,
  71. moneyCouponPrice,
  72. moneyCouponFlag,
  73. couponPayWay,
  74. moneyCouponType,
  75. createDate,
  76. delFlag
  77. FROM cm_coupon WHERE delFlag = 0 AND configure = 1
  78. </select>
  79. <update id="updateCoupon">
  80. UPDATE cm_coupon
  81. SET configure = #{configure}
  82. WHERE id = #{id}
  83. </update>
  84. <insert id="insertCoupon" parameterType="com.caimei365.tools.model.po.CmCouponPo" keyProperty="id" useGeneratedKeys="true">
  85. INSERT INTO cm_coupon(
  86. name,
  87. couponPayWay,
  88. couponAmount,
  89. touchPrice,
  90. startDate,
  91. endDate,
  92. receivePeriod,
  93. receiveFlag,
  94. useTimeFlag,
  95. usePeriod,
  96. status,
  97. couponType,
  98. vipFlag,
  99. userId,
  100. shopId,
  101. productType,
  102. pcBanner,
  103. appletsBanner,
  104. categoryType,
  105. couponsMode,
  106. createDate,
  107. moneyCouponPrice,
  108. moneyCouponFlag,
  109. moneyCouponType,
  110. delFlag,
  111. configure
  112. ) VALUES (
  113. #{name},
  114. #{couponPayWay},
  115. #{couponAmount},
  116. #{touchPrice},
  117. #{startDate},
  118. #{endDate},
  119. #{receivePeriod},
  120. #{receiveFlag},
  121. #{useTimeFlag},
  122. #{usePeriod},
  123. #{status},
  124. #{couponType},
  125. #{vipFlag},
  126. #{userId},
  127. #{shopId},
  128. #{productType},
  129. #{pcBanner},
  130. #{appletsBanner},
  131. #{categoryType},
  132. #{couponsMode},
  133. #{createDate},
  134. #{moneyCouponPrice},
  135. #{moneyCouponFlag},
  136. #{moneyCouponType},
  137. #{delFlag},
  138. #{configure}
  139. )
  140. </insert>
  141. <select id="selCouponPro" resultType="com.caimei365.tools.model.po.CmCouponAssociatePo">
  142. select * from cm_coupon_product where couponId = #{couponId}
  143. </select>
  144. <insert id="insertCouponAssociate">
  145. INSERT INTO `cm_coupon_product` (
  146. `couponId`, `productId`, `pcStatus`,
  147. `appletsStatus`,
  148. `sort`, `addTime`, `delFlag`
  149. )
  150. VALUES
  151. (
  152. #{couponId}, #{productId}, #{pcStatus},
  153. #{appletsStatus},
  154. #{sort}, #{addTime}, #{delFlag}
  155. )
  156. </insert>
  157. <select id="selSvipCouponById" resultType="integer">
  158. SELECT max(id) as id FROM cm_svip_coupon_month
  159. </select>
  160. <insert id="insertRelation">
  161. INSERT INTO cm_svip_coupon(couponId, montId, updateTime,delFlag)
  162. VALUES(#{couponId}, #{montId}, #{updateTime},#{delFlag})
  163. </insert>
  164. <select id="countNum" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  165. SELECT IP as IP, COUNT(DISTINCT userID) as count FROM cm_behavior_record
  166. where accessDate = #{accessDate}
  167. GROUP BY IP, accessDate ORDER BY accessDate DESC
  168. </select>
  169. <select id="userIdAcc" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  170. SELECT IP as IP, userID as userId FROM cm_behavior_record WHERE IP = #{IP} AND accessDate = #{accessDate} GROUP BY IP ,userID ORDER BY userID DESC LIMIT 1
  171. </select>
  172. <select id="selBehaviorList" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  173. SELECT recordID as recordID, IP as IP, userID as userId FROM cm_behavior_record WHERE IP = #{IP} AND userID = 0 AND accessDate = #{accessDate}
  174. </select>
  175. <update id="updateBehavior">
  176. UPDATE cm_behavior_record
  177. SET IP = #{IP},
  178. userID = #{userId}
  179. WHERE recordID = #{recordID}
  180. </update>
  181. <select id="selYesterdayList" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  182. SELECT
  183. b.IP,
  184. b.userID,
  185. c.clubID,
  186. MAX(b.accessTime) AS lastAccessTime,
  187. (
  188. CASE WHEN u.userIdentity = 2 THEN 2
  189. WHEN u.userIdentity = 4 THEN 2
  190. WHEN u.userIdentity = 3 THEN 3
  191. WHEN b.userID = 0 THEN 1
  192. END)AS companyType,
  193. (
  194. CASE WHEN b.userID = 0 THEN ''
  195. WHEN u.userIdentity = 2 THEN c.name
  196. when u.userIdentity = 3 then s.name
  197. WHEN u.userIdentity = 4 THEN IF(c.name != u.userName,c.name,'')
  198. END)AS corporateName,
  199. (
  200. CASE WHEN b.userID = 0 THEN ''
  201. WHEN u.userIdentity = 2 THEN c.linkMan
  202. WHEN u.userIdentity = 3 THEN s.linkMan
  203. WHEN u.userIdentity = 4 THEN c.linkMan
  204. END)AS contacts,
  205. (CASE WHEN u.userIdentity = 2 THEN c.contractMobile
  206. WHEN u.userIdentity = 4 THEN c.contractMobile
  207. WHEN u.userIdentity = 3 THEN s.contractMobile
  208. END)AS phoneNumber,
  209. (SELECT CASE STATUS WHEN 91 THEN '采美默认协销经理(官方账号)' ELSE linkMan END FROM serviceprovider WHERE serviceProviderID = c.spID) AS spName,
  210. COUNT(b.IP) AS number,
  211. (SELECT consultName
  212. FROM cm_roos_information
  213. WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultName,
  214. (SELECT consultMobile
  215. FROM cm_roos_information
  216. WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultMobile,
  217. b.behaviorType,
  218. b.productID,
  219. b.accessTime,
  220. SUM(b.accessDuration) AS accessDuration,
  221. b.accessDate,
  222. b.accessClient,
  223. b.region AS region,
  224. u.registerTime AS addTime,
  225. b.delFlag
  226. FROM cm_behavior_record b
  227. LEFT JOIN USER u ON b.userID = u.userID
  228. LEFT JOIN club c ON b.userID = c.userID
  229. LEFT JOIN shop s ON b.userID = s.userID
  230. WHERE b.IP != '106.55.202.118' AND b.delFlag = 0 AND b.accessDate = #{accessDate}
  231. AND b.region NOT LIKE '%美国Microsoft公司%' AND b.region NOT LIKE '%亚马逊(Amazon)公司%'
  232. GROUP BY b.IP, b.accessDate,b.userID ORDER BY b.accessTime DESC
  233. </select>
  234. <select id="insertYesterdayList">
  235. INSERT INTO cm_behavior_record_index (
  236. IP,
  237. userID,
  238. clubID,
  239. lastAccessTime,
  240. companyType,
  241. corporateName,
  242. contacts,
  243. phoneNumber,
  244. spName,
  245. number,
  246. consultName,
  247. consultMobile,
  248. accessTime,
  249. accessDuration,
  250. accessDate,
  251. accessClient,
  252. region,
  253. relevanceShop,
  254. label,
  255. addTime,
  256. delFlag
  257. ) values (
  258. #{IP},
  259. #{userId},
  260. #{clubId},
  261. #{lastAccessTime},
  262. #{companyType},
  263. #{corporateName},
  264. #{contacts},
  265. #{phoneNumber},
  266. #{spName},
  267. #{number},
  268. #{consultName},
  269. #{consultMobile},
  270. #{accessTime},
  271. #{accessDuration},
  272. #{accessDate},
  273. #{accessClient},
  274. #{region},
  275. #{relevanceShop},
  276. #{label},
  277. #{addTime},
  278. '0'
  279. )
  280. </select>
  281. <select id="selTodayData" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  282. SELECT
  283. b.IP,
  284. b.userID,
  285. c.clubID,
  286. MAX(b.accessTime) AS lastAccessTime,
  287. (
  288. CASE WHEN u.userIdentity = 2 THEN 2
  289. WHEN u.userIdentity = 4 THEN 2
  290. WHEN u.userIdentity = 3 THEN 3
  291. WHEN b.userID = 0 THEN 1
  292. END)AS companyType,
  293. (
  294. CASE WHEN b.userID = 0 THEN ''
  295. WHEN u.userIdentity = 2 THEN c.name
  296. WHEN u.userIdentity = 3 THEN s.name
  297. WHEN u.userIdentity = 4 THEN c.name -- IF(c.name != u.userName,c.name,'')
  298. END)AS corporateName,
  299. (
  300. CASE WHEN b.userID = 0 THEN ''
  301. WHEN u.userIdentity = 2 THEN c.linkMan
  302. WHEN u.userIdentity = 3 THEN s.linkMan
  303. WHEN u.userIdentity = 4 THEN c.linkMan
  304. END)AS contacts,
  305. (
  306. CASE WHEN u.userIdentity = 2 THEN c.contractMobile
  307. WHEN u.userIdentity = 4 THEN c.contractMobile
  308. WHEN u.userIdentity = 3 THEN s.contractMobile
  309. END)AS phoneNumber,
  310. (SELECT CASE STATUS WHEN 91 THEN '采美默认协销经理(官方账号)' ELSE linkMan END FROM serviceprovider WHERE serviceProviderID = c.spID) AS spName,
  311. COUNT(b.IP) AS number,
  312. (SELECT consultName
  313. FROM cm_roos_information
  314. WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultName,
  315. (SELECT consultMobile
  316. FROM cm_roos_information
  317. WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultMobile,
  318. b.accessTime,
  319. SUM(b.accessDuration) AS accessDuration,
  320. b.accessDate,
  321. b.accessClient,
  322. b.region AS region,
  323. u.registerTime AS addTime
  324. FROM cm_behavior_record b
  325. LEFT JOIN USER u ON b.userID = u.userID
  326. LEFT JOIN club c ON b.userID = c.userID
  327. LEFT JOIN shop s ON b.userID = s.userID
  328. WHERE b.IP != '106.55.202.118' AND b.delFlag = 0 AND b.accessDate = #{accessDate}
  329. AND b.region NOT LIKE '%美国Microsoft公司%' AND b.region NOT LIKE '%亚马逊(Amazon)公司%'
  330. GROUP BY b.IP, b.accessDate,b.userID ORDER BY b.accessTime DESC
  331. </select>
  332. <select id="selDataList" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  333. SELECT s.name AS relevanceShop, cbs.userID, cbs.IP, cbs.pageLabel
  334. FROM cm_behavior_record cbs
  335. LEFT JOIN cm_behavior_shopid cbr ON cbs.recordID = cbr.recordID
  336. LEFT JOIN shop s ON s.shopID = cbr.shopID
  337. where cbs.accessDate = #{accessDate}
  338. order by cbs.accessTime
  339. </select>
  340. <insert id="inBehaviorToday">
  341. INSERT INTO cm_behavior_record_today (
  342. id,
  343. IP,
  344. userId,
  345. clubId,
  346. lastAccessTime,
  347. companyType,
  348. corporateName,
  349. contacts,
  350. phoneNumber,
  351. spName,
  352. number,
  353. consultName,
  354. consultMobile,
  355. accessTime,
  356. accessDuration,
  357. accessDate,
  358. accessClient,
  359. region,
  360. relevanceShop,
  361. label,
  362. addTime
  363. ) values (
  364. #{recordID},
  365. #{IP},
  366. #{userId},
  367. #{clubId},
  368. #{lastAccessTime},
  369. #{companyType},
  370. #{corporateName},
  371. #{contacts},
  372. #{phoneNumber},
  373. #{spName},
  374. #{number},
  375. #{consultName},
  376. #{consultMobile},
  377. #{accessTime},
  378. #{accessDuration},
  379. #{accessDate},
  380. #{accessClient},
  381. #{region},
  382. #{relevanceShop},
  383. #{label},
  384. #{addTime}
  385. )
  386. </insert>
  387. <delete id="delTodayData">
  388. TRUNCATE TABLE cm_behavior_record_today
  389. </delete>
  390. <select id="shopIds" resultType="java.lang.Integer">
  391. SELECT DISTINCT csr.shopID FROM cm_shop_relevance csr
  392. LEFT JOIN cm_shop_label csl ON csr.id = csl.relevanceId
  393. LEFT JOIN cm_user_search_frequency cusf ON csl.keywordId = cusf.id
  394. <where>
  395. csr.delFlag = 0 and
  396. csl.delFlag = 0 and
  397. <if test="strList != null and strList.size > 0">
  398. <foreach collection="strList" item="keyword" open="(" close=")" separator="or">
  399. cusf.keyword = #{keyword}
  400. </foreach>
  401. </if>
  402. </where>
  403. </select>
  404. <select id="selShopId" resultType="java.lang.Integer">
  405. select id from cm_shop_relevance where delFlag = 0 and shopID = #{shopId}
  406. </select>
  407. <insert id="insertShopId">
  408. insert into cm_behavior_shopId (recordID, shopID) values (#{recordId}, #{shopId})
  409. </insert>
  410. <select id="selRegisterIP" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
  411. SELECT u.userID as userId, u.registerIP as registerIp, c.clubID as clubId, c.provinceID as provinceId , c.cityID as cityId
  412. FROM USER u
  413. LEFT JOIN club c ON c.userID = u.userID
  414. WHERE u.userIdentity = 4 and c.clubID between #{startId} and #{endId}
  415. </select>
  416. <select id="selProvince" resultType="java.lang.Integer">
  417. SELECT provinceID as provinceId FROM province WHERE NAME LIKE concat('%', #{regionPro} ,'%') limit 1
  418. </select>
  419. <select id="selCity" resultType="com.caimei365.tools.model.po.AddressPo">
  420. SELECT cityID as cityId, provinceID as provinceId FROM city WHERE NAME LIKE concat('%', #{regionCity} ,'%') AND validFlag = 1 limit 1
  421. </select>
  422. <update id="upClubAddress">
  423. update club
  424. <set>
  425. <if test="provinceId != null and provinceId != ''">
  426. provinceID = #{provinceId},
  427. </if>
  428. <if test="cityId != null and cityId != ''">
  429. cityID = #{cityId}
  430. </if>
  431. </set>
  432. where clubID = #{clubId}
  433. </update>
  434. </mapper>