AppUserMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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.ytpm.picking.dao.AppUserMapper">
  4. <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
  5. insert into yt_dyz_user
  6. (
  7. user_id,
  8. nick_name,
  9. head_img,
  10. registry_time,
  11. last_login_time,
  12. last_login_ip,
  13. login_days,
  14. total_video,
  15. total_income,
  16. nearly_income,
  17. red_packet_balance,
  18. red_packet_amount,
  19. points_balance,
  20. points_total,
  21. withdraw_total,
  22. sign_days,
  23. user_status,
  24. risk_reason,
  25. wx_open_id,
  26. ditch_id,
  27. platform_id,
  28. app_id,
  29. power,
  30. phone,
  31. phone_json,
  32. device_id
  33. )
  34. values
  35. (
  36. #{userId},
  37. #{nickName},
  38. #{headImg},
  39. #{registryTime},
  40. #{lastLoginTime},
  41. #{lastLoginIp},
  42. #{loginDays},
  43. #{totalVideo},
  44. #{totalIncome},
  45. #{nearlyIncome},
  46. #{redPacketBalance},
  47. #{redPacketAmount},
  48. #{pointsBalance},
  49. #{pointsTotal},
  50. #{withdrawTotal},
  51. #{signDays},
  52. #{userStatus},
  53. #{riskReason},
  54. #{wxOpenId},
  55. #{ditchId},
  56. #{platformId},
  57. #{appId},
  58. #{power},
  59. #{phone},
  60. #{phoneJson},
  61. #{deviceId}
  62. )
  63. </insert>
  64. <insert id="addPowerRecord">
  65. insert into yt_dyz_power_record
  66. (
  67. record_id, user_id, type, remark, add_time
  68. )
  69. values
  70. (
  71. #{recordId},#{userId},#{type},#{remark},#{addTime}
  72. )
  73. </insert>
  74. <insert id="saveAppConfig">
  75. insert into yt_app_default_config
  76. (
  77. config_name,
  78. open_id,
  79. secret,
  80. app_id,
  81. app_key,
  82. app_type,
  83. ditch_id
  84. )
  85. values
  86. (
  87. #{configName},
  88. #{openId},
  89. #{secret},
  90. #{appId},
  91. #{appKey},
  92. #{appType},
  93. #{ditchId}
  94. )
  95. </insert>
  96. <update id="updateAppConfig">
  97. update yt_app_default_config
  98. <set>
  99. <if test="canSimulator != null">
  100. can_simulator = #{canSimulator},
  101. </if>
  102. <if test="configName != null">
  103. config_name = #{configName},
  104. </if>
  105. <if test="openId != null">
  106. open_id = #{openId},
  107. </if>
  108. <if test="secret != null">
  109. secret = #{secret},
  110. </if>
  111. <if test="appKey != null">
  112. app_key = #{appKey},
  113. </if>
  114. <if test="appType != null">
  115. app_type = #{appType},
  116. </if>
  117. <if test="takuAppId != null">
  118. taku_app_id = #{takuAppId},
  119. </if>
  120. <if test="takuKey != null">
  121. taku_key = #{takuKey},
  122. </if>
  123. <if test="takuBannerPid != null">
  124. taku_banner_pid = #{takuBannerPid},
  125. </if>
  126. <if test="takuNativePid != null">
  127. taku_native_pid = #{takuNativePid},
  128. </if>
  129. <if test="takuRewardPid != null">
  130. taku_reward_pid = #{takuRewardPid},
  131. </if>
  132. <if test="takuInterstitialPid != null">
  133. taku_interstitial_pid = #{takuInterstitialPid},
  134. </if>
  135. <if test="canUseRoot != null">
  136. can_use_root = #{canUseRoot},
  137. </if>
  138. <if test="canUseAdb != null">
  139. can_use_adb = #{canUseAdb},
  140. </if>
  141. <if test="canUseFloat != null">
  142. can_use_float = #{canUseFloat},
  143. </if>
  144. <if test="canAccumulation != null">
  145. can_accumulation = #{canAccumulation},
  146. </if>
  147. <if test="ditchId != null">
  148. ditch_id = #{ditchId},
  149. </if>
  150. <if test="powerWaitTime != null">
  151. power_wait_time = #{powerWaitTime},
  152. </if>
  153. <if test="interstitialIntervalTime != null">
  154. interstitial_interval_time = #{interstitialIntervalTime},
  155. </if>
  156. <if test="flowIntervalTime != null">
  157. flow_interval_time = #{flowIntervalTime},
  158. </if>
  159. <if test="taskLimitTip != null">
  160. task_limit_tip = #{taskLimitTip},
  161. </if>
  162. <if test="lowValueTip != null">
  163. low_value_tip = #{lowValueTip},
  164. </if>
  165. <if test="brushTip != null">
  166. brush_tip = #{brushTip},
  167. </if>
  168. <if test="startWaitTime != null">
  169. start_wait_time = #{startWaitTime},
  170. </if>
  171. <if test="canCacheVideo != null">
  172. can_cache_video = #{canCacheVideo}
  173. </if>
  174. </set>
  175. where app_id = #{appId}
  176. </update>
  177. <update id="addOnePower">
  178. update yt_dyz_user set power = power+1 where user_id = #{userId}
  179. </update>
  180. <update id="subOnePower">
  181. update yt_dyz_user set power = power-1 where user_id = #{userId}
  182. </update>
  183. <update id="updateUser" parameterType="com.ytpm.app.model.YtDyzUser">
  184. update yt_dyz_user
  185. <set>
  186. <if test="nickName != null">
  187. nick_name = #{nickName},
  188. </if>
  189. <if test="phone != null">
  190. phone = #{phone},
  191. </if>
  192. <if test="deviceId != null">
  193. device_id = #{deviceId},
  194. </if>
  195. <if test="headImg != null">
  196. head_img = #{headImg},
  197. </if>
  198. <if test="power != null">
  199. power = #{power},
  200. </if>
  201. <if test="lastLoginTime != null">
  202. last_login_time = #{lastLoginTime},
  203. </if>
  204. <if test="lastLoginIp != null">
  205. last_login_ip = #{lastLoginIp},
  206. </if>
  207. <if test="loginDays != null">
  208. login_days = #{loginDays},
  209. </if>
  210. <if test="totalVideo != null">
  211. total_video = #{totalVideo},
  212. </if>
  213. <if test="totalIncome != null">
  214. total_income = #{totalIncome},
  215. </if>
  216. <if test="nearlyIncome != null">
  217. nearly_income = #{nearlyIncome},
  218. </if>
  219. <if test="redPacketBalance != null">
  220. red_packet_balance = #{redPacketBalance},
  221. </if>
  222. <if test="redPacketAmount != null">
  223. red_packet_amount = #{redPacketAmount},
  224. </if>
  225. <if test="pointsBalance != null">
  226. points_balance = #{pointsBalance},
  227. </if>
  228. <if test="pointsTotal != null">
  229. points_total = #{pointsTotal},
  230. </if>
  231. <if test="withdrawTotal != null">
  232. withdraw_total = #{withdrawTotal},
  233. </if>
  234. <if test="signDays != null">
  235. sign_days = #{signDays},
  236. </if>
  237. <if test="userStatus != null">
  238. user_status = #{userStatus},
  239. </if>
  240. <if test="riskReason != null">
  241. risk_reason = #{riskReason},
  242. </if>
  243. <if test="wxOpenId != null">
  244. wx_open_id = #{wxOpenId},
  245. </if>
  246. <if test="phoneJson != null">
  247. phone_json = #{phoneJson},
  248. </if>
  249. <if test="platformId != null">
  250. platform_id = #{platformId}
  251. </if>
  252. </set>
  253. where user_id = #{userId}
  254. </update>
  255. <delete id="delByAppId">
  256. delete from yt_app_default_config where app_id = #{appId}
  257. </delete>
  258. <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
  259. select
  260. user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power,
  261. registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, nearly_income,
  262. red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total,
  263. sign_days, user_status, risk_reason, wx_open_id, platform_id
  264. from yt_dyz_user
  265. where wx_open_id = #{openid}
  266. and ditch_id = #{ditchId}
  267. </select>
  268. <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
  269. select
  270. user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power,
  271. registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, nearly_income,
  272. red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total,
  273. sign_days, user_status, risk_reason, wx_open_id, platform_id
  274. from yt_dyz_user
  275. where 1 = 1
  276. <if test="userId != null and userId !=''">
  277. and user_id = #{userId}
  278. </if>
  279. <if test="nickName != null and nickName !=''">
  280. and nick_name like concat('%',#{nickName},'%')
  281. </if>
  282. <if test="ditchId != null">
  283. and ditch_id = #{ditchId}
  284. </if>
  285. <if test="userStatus != null">
  286. and user_status = #{userStatus}
  287. </if>
  288. <if test="registryTimeBegin != null">
  289. and DATE_FORMAT(registry_time, '%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{registryTimeBegin}, '%Y-%m-%d')
  290. </if>
  291. <if test="registryTimeEnd != null">
  292. and DATE_FORMAT(registry_time, '%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{registryTimeEnd}, '%Y-%m-%d')
  293. </if>
  294. <if test="lastLoginTimeBegin != null">
  295. and DATE_FORMAT(last_login_time, '%Y-%m-%d') <![CDATA[>=]]> DATE_FORMAT(#{lastLoginTimeBegin}, '%Y-%m-%d')
  296. </if>
  297. <if test="lastLoginTimeEnd != null">
  298. and DATE_FORMAT(last_login_time, '%Y-%m-%d') <![CDATA[<=]]> DATE_FORMAT(#{lastLoginTimeEnd}, '%Y-%m-%d')
  299. </if>
  300. <if test="appIds != null and appIds != ''">
  301. and app_id in
  302. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  303. #{item}
  304. </foreach>
  305. </if>
  306. order by user_id desc
  307. </select>
  308. <select id="selectPrimaryKey" resultType="com.ytpm.app.model.YtDyzUser">
  309. select
  310. user_id,app_id,phone,device_id, ditch_id, head_img, nick_name, registry_time, last_login_time, last_login_ip,
  311. login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  312. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id, power, nearly_income
  313. from yt_dyz_user
  314. where user_id = #{userId}
  315. </select>
  316. <resultMap id="UserMap" type="com.ytpm.app.model.YtDyzUser">
  317. <id column="user_id" property="userId" />
  318. <result column="head_img" property="headImg" />
  319. <result column="nick_name" property="nickName" />
  320. <result column="phone" property="phone" />
  321. <result column="device_id" property="deviceId" />
  322. <result column="registry_time" property="registryTime" />
  323. <result column="last_login_time" property="lastLoginTime" />
  324. <result column="last_login_ip" property="lastLoginIp" />
  325. <result column="login_days" property="loginDays" />
  326. <result column="total_video" property="totalVideo" />
  327. <result column="total_income" property="totalIncome" />
  328. <result column="nearly_income" property="nearlyIncome" />
  329. <result column="red_packet_balance" property="redPacketBalance" />
  330. <result column="red_packet_amount" property="redPacketAmount" />
  331. <result column="points_balance" property="pointsBalance" />
  332. <result column="points_total" property="pointsTotal" />
  333. <result column="withdraw_total" property="withdrawTotal" />
  334. <result column="sign_days" property="signDays" />
  335. <result column="user_status" property="userStatus" />
  336. <result column="risk_reason" property="riskReason" />
  337. <result column="wx_open_id" property="wxOpenId" />
  338. <result column="ditch_id" property="ditchId" />
  339. <result column="app_id" property="appId" />
  340. <result column="platform_id" property="platformId" />
  341. <result column="power" property="power" />
  342. <collection property="loginRecordList" ofType="com.ytpm.app.model.YtDyzLoginRecord">
  343. <result column="record_id" property="recordId" />
  344. <result column="user_id" property="userId" />
  345. <result column="login_time" property="loginTime" />
  346. <result column="device_brand" property="deviceBrand" />
  347. <result column="device_model" property="deviceModel" />
  348. <result column="login_ip" property="loginIp" />
  349. <result column="operator" property="operator" />
  350. <result column="ip_addr" property="ipAddr" />
  351. </collection>
  352. </resultMap>
  353. <select id="getUserList" resultMap="UserMap">
  354. select
  355. du.user_id,
  356. du.head_img,
  357. du.nick_name,
  358. du.phone,
  359. du.device_id,
  360. du.registry_time,
  361. du.last_login_time,
  362. du.last_login_ip,
  363. du.login_days,
  364. du.total_video,
  365. du.total_income,
  366. du.nearly_income,
  367. du.red_packet_balance,
  368. du.red_packet_amount,
  369. du.points_balance,
  370. du.points_total,
  371. du.withdraw_total,
  372. du.sign_days,
  373. du.user_status,
  374. du.risk_reason,
  375. du.wx_open_id,
  376. du.ditch_id,
  377. du.app_id,
  378. du.platform_id,
  379. du.power,
  380. lr.record_id,
  381. lr.login_time,
  382. lr.device_brand,
  383. lr. device_model,
  384. lr.login_ip,
  385. lr.operator,
  386. lr.ip_addr
  387. from yt_dyz_user du
  388. left join yt_dyz_login_record lr on du.user_id = lr.user_id
  389. <where>
  390. <if test="userIds != null and userIds != ''">
  391. and du.user_id in
  392. <foreach collection="userIds.split(',')" item="item" separator="," open="(" close=")">
  393. #{item}
  394. </foreach>
  395. </if>
  396. <if test="loginTimeBegin != null">
  397. and du.last_login_time <![CDATA[>=]]> #{loginTimeBegin}
  398. </if>
  399. <if test="loginTimeEnd != null">
  400. and du.last_login_time <![CDATA[<=]]> #{loginTimeEnd}
  401. </if>
  402. </where>
  403. group by du.user_id
  404. </select>
  405. <select id="queryAllByTime" resultType="com.ytpm.app.model.YtDyzUser">
  406. SELECT
  407. user_id,app_id,phone,device_id, nick_name, head_img, power,
  408. registry_time,last_login_time, last_login_ip, login_days, total_video, total_income, nearly_income,
  409. red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total,
  410. sign_days, user_status, risk_reason, wx_open_id, platform_id
  411. FROM yt_dyz_user
  412. <where>
  413. <if test="startTime != null">
  414. AND registry_time >= #{startTime}
  415. </if>
  416. <if test="endTime != null">
  417. AND registry_time &lt;= #{endTime}
  418. </if>
  419. <choose>
  420. <when test="appIdList == null or appIdList.isEmpty()">
  421. AND 1 = 0
  422. </when>
  423. <otherwise>
  424. AND app_id IN
  425. <foreach collection="appIdList" item="item"
  426. open="(" close=")" separator=",">
  427. #{item}
  428. </foreach>
  429. </otherwise>
  430. </choose>
  431. </where>
  432. ORDER BY registry_time DESC
  433. </select>
  434. <select id="countUsersByHour" resultType="com.ytpm.app.view.HourCountView">
  435. SELECT HOUR(registry_time) AS hour, COUNT(*) AS count
  436. FROM yt_dyz_user
  437. WHERE registry_time BETWEEN #{startTime} AND #{endTime}
  438. <choose>
  439. <when test="appIdList == null or appIdList.isEmpty()">
  440. AND 1 = 0
  441. </when>
  442. <otherwise>
  443. AND app_id IN
  444. <foreach collection="appIdList" item="item"
  445. open="(" close=")" separator=",">
  446. #{item}
  447. </foreach>
  448. </otherwise>
  449. </choose>
  450. GROUP BY HOUR(registry_time)
  451. </select>
  452. <select id="queryTodayBanned" resultType="com.ytpm.app.model.YtDyzUser">
  453. select user_id from yt_dyz_user
  454. where registry_time BETWEEN #{startTime} AND #{endTime}
  455. and user_id in
  456. <foreach collection="userIdList" item="item"
  457. open="(" close=")" separator=",">
  458. #{item}
  459. </foreach>
  460. </select>
  461. <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
  462. select
  463. config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
  464. app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
  465. taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
  466. can_use_root, can_use_adb, can_use_float, can_accumulation,
  467. ditch_id, power_wait_time, interstitial_interval_time,
  468. low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
  469. from yt_app_default_config
  470. where app_type = #{appType}
  471. </select>
  472. <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
  473. select
  474. config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
  475. answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
  476. taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
  477. ditch_id, power_wait_time, interstitial_interval_time,
  478. low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
  479. from yt_app_default_config
  480. where app_id = #{appId}
  481. </select>
  482. <select id="getSecretByAppId" resultType="java.lang.String">
  483. select
  484. config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
  485. answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
  486. taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
  487. ditch_id, power_wait_time, interstitial_interval_time,
  488. low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
  489. from yt_app_default_config
  490. where app_id = #{appId}
  491. </select>
  492. <select id="queryByOpenid" resultType="com.ytpm.app.model.YtDyzUser">
  493. select
  494. user_id,phone,device_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  495. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  496. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power
  497. from yt_dyz_user
  498. where wx_open_id = #{openid}
  499. </select>
  500. <select id="getByDeviceId" resultType="java.lang.String">
  501. select platform_id
  502. from yt_dyz_user
  503. where device_id = #{deviceId} and wx_open_id = #{openid}
  504. limit 1
  505. </select>
  506. <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
  507. select
  508. config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
  509. answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
  510. taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
  511. ditch_id, power_wait_time, interstitial_interval_time,
  512. low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
  513. from yt_app_default_config
  514. where app_id in
  515. <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
  516. #{item}
  517. </foreach>
  518. </select>
  519. <select id="getAdCount" resultType="java.lang.Integer">
  520. select sum(total_video)
  521. from yt_dyz_user
  522. where app_id in
  523. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  524. #{item}
  525. </foreach>
  526. </select>
  527. <select id="getRevenueCount" resultType="java.math.BigDecimal">
  528. select sum(total_income)
  529. from yt_dyz_user
  530. where app_id in
  531. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  532. #{item}
  533. </foreach>
  534. </select>
  535. <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
  536. SELECT
  537. u.app_id,
  538. sum( ar.revenue ) totalRevenue
  539. FROM
  540. yt_dyz_ad_record ar
  541. JOIN yt_dyz_user u ON ar.user_id = u.user_id
  542. <where>
  543. <if test="sortBy != null">
  544. <choose>
  545. <when test="sortBy == 1">
  546. DATE_FORMAT( ar.finish_time, '%Y-%m-%d' ) = CURRENT_DATE()
  547. </when>
  548. <when test=" sortBy == 2">
  549. YEARWEEK( ar.finish_time, 1 ) = YEARWEEK(now(),1)
  550. </when>
  551. <otherwise>
  552. DATE_FORMAT( ar.finish_time, '%Y-%m' ) = DATE_FORMAT(NOW(), '%Y-%m')
  553. </otherwise>
  554. </choose>
  555. </if>
  556. </where>
  557. GROUP BY
  558. u.app_id
  559. ORDER BY
  560. sum( ar.revenue ) DESC
  561. LIMIT #{limit}
  562. </select>
  563. <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
  564. SELECT
  565. u.user_id,
  566. u.nick_name,
  567. u.head_img,
  568. u.total_video,
  569. sum( ar.revenue ) totalIncome
  570. FROM
  571. yt_dyz_ad_record ar
  572. JOIN yt_dyz_user u ON ar.user_id = u.user_id
  573. <where>
  574. <if test="sortBy != null">
  575. <choose>
  576. <when test="sortBy == 1">
  577. DATE_FORMAT( ar.finish_time, '%Y-%m-%d' ) = CURRENT_DATE()
  578. </when>
  579. <when test=" sortBy == 2">
  580. YEARWEEK( ar.finish_time, 1 ) = YEARWEEK(now(),1)
  581. </when>
  582. <otherwise>
  583. DATE_FORMAT( ar.finish_time, '%Y-%m' ) = DATE_FORMAT(NOW(), '%Y-%m')
  584. </otherwise>
  585. </choose>
  586. </if>
  587. </where>
  588. GROUP BY ar.user_id
  589. ORDER BY
  590. sum( ar.revenue ) DESC
  591. limit #{limit}
  592. </select>
  593. <select id="countUserByAppIds" resultType="java.lang.Integer">
  594. select
  595. count(user_id)
  596. from yt_dyz_user
  597. where app_id in
  598. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  599. #{item}
  600. </foreach>
  601. </select>
  602. <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
  603. select
  604. sum(total_income)
  605. from yt_dyz_user
  606. where app_id in
  607. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  608. #{item}
  609. </foreach>
  610. </select>
  611. <select id="countBannedByAppIds" resultType="java.lang.Integer">
  612. select
  613. count(user_id)
  614. from yt_dyz_user
  615. where user_status > 1 and app_id in
  616. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  617. #{item}
  618. </foreach>
  619. </select>
  620. <select id="countRegistryUser" resultType="java.lang.Integer">
  621. select
  622. count(user_id)
  623. from yt_dyz_user
  624. where app_id = #{appId}
  625. <if test="type != null and type ==1">
  626. and DATE(registry_time) = DATE(now())
  627. </if>
  628. <if test="type != null and type ==2">
  629. and DATE(registry_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  630. </if>
  631. <if test="type != null and type ==3">
  632. and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  633. </if>
  634. </select>
  635. <select id="countLoginUser" resultType="java.lang.Integer">
  636. select
  637. count(user_id)
  638. from yt_dyz_user
  639. where app_id = #{appId}
  640. <if test="type != null and type ==1">
  641. and DATE(last_login_time) = DATE(now())
  642. </if>
  643. <if test="type != null and type ==2">
  644. and DATE(last_login_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  645. </if>
  646. <if test="type != null and type ==3">
  647. and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  648. </if>
  649. </select>
  650. <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
  651. select
  652. DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
  653. count(user_id) `count`
  654. from yt_dyz_user
  655. where app_id = #{appId}
  656. <if test="type != null and type ==1">
  657. and DATE(registry_time) = DATE(now())
  658. </if>
  659. <if test="type != null and type ==2">
  660. and DATE(registry_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  661. </if>
  662. <if test="type != null and type ==3">
  663. and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  664. </if>
  665. group by `time`
  666. </select>
  667. <select id="countLoginHour" resultType="com.ytpm.middle.view.AppUserHourVO">
  668. select
  669. DATE_FORMAT(last_login_time,'%Y-%m-%d %H:00:00') as `time`,
  670. count(user_id) `count`
  671. from yt_dyz_user
  672. where app_id = #{appId}
  673. <if test="type != null and type ==1">
  674. and DATE(last_login_time) = DATE(now())
  675. </if>
  676. <if test="type != null and type ==2">
  677. and DATE(last_login_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  678. </if>
  679. <if test="type != null and type ==3">
  680. and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  681. </if>
  682. group by `time`
  683. </select>
  684. <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
  685. select
  686. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
  687. from yt_dyz_user
  688. where user_id in
  689. <foreach collection="userIds.split(',')" separator="," item="item" open="(" close=")">
  690. #{item}
  691. </foreach>
  692. </select>
  693. <resultMap id="UserAdMap" type="com.ytpm.agent.view.AgentAuditCheckVO">
  694. <id column="user_id" property="userId" />
  695. <result column="app_id" property="appId" />
  696. <result column="nick_name" property="nickName" />
  697. <collection property="adRecordList" ofType="com.ytpm.app.model.YtDyzAdRecord">
  698. <result column="record_id" property="recordId" />
  699. <result column="placement_id" property="placementId" />
  700. <result column="ad_source_id" property="adSourceId" />
  701. <result column="ad_source_type" property="adSourceType" />
  702. <result column="ad_source_index" property="adSourceIndex" />
  703. <result column="revenue" property="revenue" />
  704. <result column="ecpm" property="ecpm" />
  705. <result column="network_form_id" property="networkFormId" />
  706. <result column="network_name" property="networkName" />
  707. <result column="network_placement_id" property="networkPlacementId" />
  708. <result column="finish_time" property="finishTime" />
  709. <result column="begin_time" property="beginTime" />
  710. </collection>
  711. </resultMap>
  712. <select id="queryTodayUserAd" resultMap="UserAdMap">
  713. select
  714. u.user_id,
  715. u.app_id,
  716. u.nick_name,
  717. ar.record_id,
  718. ar.placement_id,
  719. ar.ad_source_id,
  720. ar.ad_source_type,
  721. ar.ad_source_index,
  722. ar.revenue,
  723. ar.ecpm,
  724. ar.network_form_id,
  725. ar.network_name,
  726. ar.network_placement_id,
  727. ar.finish_time,
  728. ar.begin_time
  729. from yt_dyz_ad_record ar
  730. join yt_dyz_user u on ar.user_id = u.user_id
  731. where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in
  732. <foreach collection="userIds.split(',')" separator="," item="item" open="(" close=")">
  733. #{item}
  734. </foreach>
  735. and DATE_FORMAT(ar.finish_time, '%Y-%m-%d') = current_date()
  736. </select>
  737. <select id="getMonthRegistryUser" resultType="com.ytpm.app.model.YtDyzUser">
  738. select
  739. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  740. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  741. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id,
  742. power, phone, device_id
  743. from yt_dyz_user
  744. where app_id in
  745. <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
  746. #{item}
  747. </foreach>
  748. <if test="type != null and type == 1">
  749. and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(now(),'%Y-%m')
  750. </if>
  751. <if test="type != null and type == 2">
  752. and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(now(),'%Y-%m')
  753. </if>
  754. </select>
  755. <select id="countDitch" resultType="java.lang.Integer">
  756. select
  757. count( distinct ditch_id)
  758. from yt_dyz_user
  759. where device_id = #{deviceId}
  760. and registry_time > (NOW() - INTERVAL #{hours} HOUR )
  761. </select>
  762. <select id="countLoginDitch" resultType="java.lang.Integer">
  763. select
  764. count( distinct ditch_id)
  765. from yt_dyz_user
  766. where device_id = #{deviceId}
  767. and last_login_time > (NOW() - INTERVAL #{hours} HOUR )
  768. </select>
  769. <select id="getLastRegistryUser" resultType="com.ytpm.app.model.YtDyzUser">
  770. select
  771. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  772. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  773. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id,
  774. power, phone, device_id, phone_json
  775. from yt_dyz_user
  776. where device_id = #{deviceId}
  777. </select>
  778. <select id="getByDeviceAndDitch" resultType="com.ytpm.app.model.YtDyzUser">
  779. select
  780. user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
  781. total_video, total_income, nearly_income, red_packet_balance, red_packet_amount, points_balance, points_total,
  782. withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id,
  783. power, phone, device_id, phone_json
  784. from yt_dyz_user
  785. where device_id = #{deviceId} and ditch_id = #{ditchId} limit 1
  786. </select>
  787. <select id="getPlatformByDeviceId" resultType="java.lang.String">
  788. select platform_id
  789. from yt_dyz_user
  790. where device_id = #{deviceId}
  791. limit 1
  792. </select>
  793. <update id="unlockUser">
  794. update yt_dyz_user
  795. set user_status = 1
  796. where user_status > 1
  797. and user_id in
  798. <foreach collection="userIds.split(',')" item="item" separator="," open="(" close=")">
  799. #{item}
  800. </foreach>
  801. </update>
  802. <update id="updateTotal">
  803. UPDATE yt_dyz_user
  804. SET nearly_income = 0, nearly_begin_time = NOW()
  805. WHERE user_id = #{userId}
  806. AND last_login_time <![CDATA[ < ]]> DATE_SUB(NOW(), INTERVAL 3 DAY)
  807. AND IFNULL(nearly_begin_time, NOW()) <![CDATA[ < ]]> DATE_SUB(NOW(), INTERVAL 3 DAY);
  808. UPDATE yt_dyz_user SET nearly_begin_time = NOW() WHERE user_id = #{userId} AND nearly_begin_time IS NULL;
  809. UPDATE yt_dyz_user
  810. SET total_video = COALESCE(total_video, 0) + #{videoCount},
  811. total_income = COALESCE(total_income, 0) + #{revenue},
  812. nearly_income = COALESCE(nearly_income, 0) + #{revenue}
  813. WHERE user_id = #{userId};
  814. </update>
  815. </mapper>