AppUserMapper.xml 32 KB

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