UserMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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.zhongzheng.modules.user.mapper.UserMapper">
  6. <resultMap type="com.zhongzheng.modules.user.domain.User" id="UserResult">
  7. <result property="userId" column="user_id"/>
  8. <result property="userAccount" column="user_account"/>
  9. <result property="nickname" column="nickname"/>
  10. <result property="realname" column="realname"/>
  11. <result property="sex" column="sex"/>
  12. <result property="idCard" column="id_card"/>
  13. <result property="telphone" column="telphone"/>
  14. <result property="userLevel" column="user_level"/>
  15. <result property="userBirth" column="user_birth"/>
  16. <result property="eduLevel" column="edu_level"/>
  17. <result property="schoolId" column="school_id"/>
  18. <result property="major" column="major"/>
  19. <result property="entranceTime" column="entrance_time"/>
  20. <result property="openId" column="open_id"/>
  21. <result property="idCardImg1" column="id_card_img1"/>
  22. <result property="idCardImg2" column="id_card_img2"/>
  23. <result property="country" column="country"/>
  24. <result property="province" column="province"/>
  25. <result property="city" column="city"/>
  26. <result property="integral" column="integral"/>
  27. <result property="createTime" column="create_time"/>
  28. <result property="updateTime" column="update_time"/>
  29. <result property="status" column="status"/>
  30. <result property="unionId" column="union_id"/>
  31. <result property="registerPlat" column="register_plat"/>
  32. <result property="lastLoginIp" column="last_login_ip"/>
  33. <result property="lastLoginTime" column="last_login_time"/>
  34. <result property="certified" column="certified"/>
  35. <result property="certifiedTime" column="certified_time"/>
  36. <result property="district" column="district"/>
  37. <result property="marry" column="marry"/>
  38. <result property="houseProvince" column="house_province"/>
  39. <result property="houseCity" column="house_city"/>
  40. <result property="houseDistrict" column="house_district"/>
  41. <result property="oneInchPhotos" column="one_inch_photos"/>
  42. <result property="politic" column="politic"/>
  43. <result property="email" column="email"/>
  44. <result property="avatar" column="avatar"/>
  45. <result property="inviteUserAccount" column="invite_user_account"/>
  46. <result property="courseNum" column="course_num"/>
  47. <result property="studyTime" column="study_time"/>
  48. <result property="password" column="password"/>
  49. <result property="goodsCourseNum" column="goods_course_num"/>
  50. <result property="goodsBankNum" column="goods_bank_num"/>
  51. <result property="importNo" column="import_no"/>
  52. <result property="goodsLiveNum" column="goods_live_num"/>
  53. <result property="userBindWx" column="user_bind_wx"/>
  54. <result property="userFollowWx" column="user_follow_wx"/>
  55. <result property="lastVisitTime" column="last_visit_time"/>
  56. <result property="visitFromPlat" column="visit_from_plat"/>
  57. <result property="studyFromPlat" column="study_from_plat"/>
  58. <result property="lastStudyTime" column="last_study_time"/>
  59. </resultMap>
  60. <resultMap type="com.zhongzheng.modules.user.vo.RanKingUser" id="RanKingUserResult">
  61. <result property="hourse" column="sum_study"/>
  62. <result property="avatar" column="avatar"/>
  63. <result property="nickname" column="nickname"/>
  64. <result property="rank" column="pm"/>
  65. </resultMap>
  66. <resultMap type="com.zhongzheng.modules.user.vo.UserStudyRecordVo" id="StudyRecordResult">
  67. <result property="telphone" column="telphone"/>
  68. <result property="realname" column="realname"/>
  69. <result property="endTime" column="end_time"/>
  70. <result property="startTime" column="start_time"/>
  71. <result property="title" column="title"/>
  72. <result property="courseName" column="course_name"/>
  73. <result property="studyDuration" column="study_duration"/>
  74. </resultMap>
  75. <select id="selectByRank" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  76. SELECT sum(s.study_duration) AS sum_study,u.nickname,u.avatar FROM `user` u
  77. LEFT JOIN user_study_record s ON u.user_id=s.user_id where 1=1
  78. <if test="userId != null and userId != ''">
  79. AND u.user_id = #{userId}
  80. </if>
  81. <if test="startTime != null and startTime != ''">
  82. AND s.create_time BETWEEN #{startTime} and #{endTime}
  83. </if>
  84. GROUP BY u.user_id
  85. </select>
  86. <select id="selectByRanks" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  87. SELECT A.*
  88. FROM
  89. (
  90. SELECT sum(s.study_duration) AS sum_study,u.nickname,u.avatar FROM `user` u
  91. LEFT JOIN user_study_record s ON u.user_id=s.user_id where 1=1
  92. <if test="startTime != null and startTime != ''">
  93. AND s.create_time BETWEEN #{startTime} and #{endTime}
  94. </if>
  95. GROUP BY u.user_id ORDER BY sum_study desc LIMIT 20
  96. ) A where
  97. A.sum_study >0
  98. </select>
  99. <select id="selectByRankOne" parameterType="integer" resultType="int">
  100. SELECT
  101. COUNT(s.sum_study)
  102. FROM
  103. (SELECT sum( s.study_duration ) AS sum_study FROM user_study_record s WHERE 1 = 1 GROUP BY s.user_id) s
  104. WHERE s.sum_study >= #{hourse}
  105. </select>
  106. <select id="selectByRankOneByTime" parameterType="map" resultType="int">
  107. SELECT
  108. COUNT(s.sum_study)
  109. FROM
  110. (SELECT sum( s.study_duration ) AS sum_study FROM user_study_record s WHERE 1 = 1
  111. <if test="startTime != null and startTime != ''">
  112. and s.create_time BETWEEN #{startTime} and #{endTime}
  113. </if>
  114. GROUP BY s.user_id) s
  115. WHERE s.sum_study >= #{hourse}
  116. </select>
  117. <select id="selectByOneRank" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  118. SELECT u.nickname,u.avatar FROM `user` u
  119. where 1=1
  120. <if test="userId != null and userId != ''">
  121. AND u.user_id = #{userId}
  122. </if>
  123. GROUP BY u.user_id
  124. </select>
  125. <select id="selectUserNum" parameterType="integer" resultType="int">
  126. SELECT
  127. COUNT(user_id)
  128. FROM
  129. `user`
  130. WHERE 1=1 and user_level = #{grade}
  131. </select>
  132. <select id="selectList" parameterType="com.zhongzheng.modules.user.bo.UserQueryBo" resultMap="UserResult">
  133. SELECT DISTINCT
  134. u.*,
  135. (case WHEN u.union_id is null then 0 ELSE 1 end) as user_bind_wx,
  136. (case WHEN uwf.gzh_open_id is null then 0 ELSE 1 end) as user_follow_wx
  137. <if test="getOrderNum != null and getOrderNum == 1" >
  138. ,ou.goods_course_num,ou.goods_bank_num,ou.goods_live_num,uvl.last_visit_time,uvl.visit_from_plat,usl.study_from_plat,usl.last_study_time
  139. </if>
  140. FROM
  141. `user` u
  142. LEFT JOIN user_wx_follow uwf ON u.union_id = uwf.union_id
  143. <if test="getOrderNum != null and getOrderNum == 1" >
  144. LEFT JOIN (
  145. SELECT
  146. sum( CASE WHEN g.goods_type = 1 THEN 1 ELSE 0 END ) AS goods_course_num,
  147. sum( CASE WHEN g.goods_type = 2 THEN 1 ELSE 0 END ) AS goods_bank_num,
  148. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num,
  149. o.user_id
  150. FROM
  151. `order` o
  152. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  153. LEFT JOIN goods g ON og.goods_id = g.goods_id
  154. WHERE o.`status` = 1
  155. AND og.refund_status in (0,1,3)
  156. AND og.pay_status in (2,3,4)
  157. GROUP BY
  158. o.user_id
  159. ) ou ON u.user_id = ou.user_id
  160. LEFT JOIN (SELECT user_id,any_value(from_plat) visit_from_plat,any_value(create_time) last_visit_time from user_visit_log GROUP BY user_id)uvl on u.user_id = uvl.user_id
  161. LEFT JOIN (SELECT user_id,any_value(from_plat) study_from_plat,any_value(create_time) last_study_time from user_study_log GROUP BY user_id)usl on u.user_id = usl.user_id
  162. </if>
  163. <if test="businessId != null and businessId != ''">
  164. LEFT JOIN `order` o ON u.user_id = o.user_id and o.`status` = 1
  165. LEFT JOIN order_goods og ON o.order_sn = og.order_sn and og.`status` = 1
  166. LEFT JOIN goods g ON og.goods_id = g.goods_id
  167. </if>
  168. WHERE
  169. 1 = 1
  170. <if test="status != null and status.size()!=0 ">
  171. AND u.status in
  172. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  173. #{item}
  174. </foreach>
  175. </if>
  176. <if test="businessId != null and businessId != ''">
  177. and og.`status` = 1
  178. and og.refund_status in (0,1,3)
  179. and og.pay_status in (2,3,4)
  180. AND g.business_id = #{businessId}
  181. </if>
  182. <if test="startTime != null and startTime != ''">
  183. AND u.create_time &gt; #{startTime}
  184. </if>
  185. <if test="endTime != null and endTime != ''">
  186. AND u.create_time &lt; #{endTime}
  187. </if>
  188. <if test="nickname != null and nickname != ''" >
  189. AND u.nickname like concat('%', #{nickname}, '%')
  190. </if>
  191. <if test="telphone != null and telphone != ''" >
  192. AND u.telphone = #{telphone}
  193. </if>
  194. <if test="idCard != null and idCard != ''" >
  195. AND u.id_card = #{idCard}
  196. </if>
  197. <if test="realname != null and realname != ''" >
  198. AND u.realname like concat('%', #{realname}, '%')
  199. </if>
  200. <if test="companyName != null and companyName != ''" >
  201. AND u.company_name like concat('%', #{companyName}, '%')
  202. </if>
  203. <if test="userId != null and userId != ''" >
  204. AND u.user_id = #{userId}
  205. </if>
  206. <if test="empty != null and empty != ''" >
  207. and u.realname is NOT NULL
  208. </if>
  209. <if test="goodsSearchKey != null and goodsSearchKey != ''" >
  210. and ( SELECT
  211. count(og.*)
  212. FROM
  213. `order` o
  214. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  215. where 1=1
  216. and og.`status` = 1
  217. and og.refund_status in (0,1,3)
  218. and og.pay_status in (2,3,4))
  219. and (g.goods_name like concat('%', #{goodsSearchKey}, '%') or g.code like concat('%', #{goodsSearchKey}, '%'))
  220. and o.user_id = u.user_id)>0
  221. </if>
  222. <if test="goodsSearchKey != null and goodsSearchKey != ''" >
  223. and ( SELECT
  224. count(og.*)
  225. FROM
  226. `order` o
  227. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  228. LEFT JOIN goods g on og.goods_id = g.goods_id
  229. where 1=1
  230. and og.`status` = 1
  231. and og.refund_status in (0,1,3)
  232. and og.pay_status in (2,3,4))
  233. and (g.goods_name like concat('%', #{goodsSearchKey}, '%') or g.code like concat('%', #{goodsSearchKey}, '%'))
  234. and o.user_id = u.user_id)>0
  235. </if>
  236. <if test="gradePoint != null and gradePoint == 1" >
  237. AND (SELECT COUNT(u.user_id) FROM class_grade_user cgu where 1=1 AND u.status in (1) and cgu.user_id= u.user_id) > 0
  238. </if>
  239. <if test="gradePoint != null and gradePoint == 2" >
  240. AND (SELECT COUNT(u.user_id) FROM class_grade_user cgu where 1=1 AND u.status in (1) and cgu.user_id= u.user_id) = 0
  241. </if>
  242. <if test="searchKey != null and searchKey != '' and searchType == 0 ">
  243. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%'))
  244. </if>
  245. <if test="idCards != null and idCards.size()!=0 and searchType == 0" >
  246. AND u.id_card in
  247. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  248. #{item}
  249. </foreach>
  250. </if>
  251. <if test="searchType == 1" >
  252. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%') or
  253. u.id_card in
  254. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  255. #{item}
  256. </foreach>)
  257. </if>
  258. <if test="hasBindWx != null and hasBindWx == 1 ">
  259. AND u.union_id is not null
  260. </if>
  261. <if test="hasBindWx != null and hasBindWx == 0 ">
  262. AND u.union_id is null
  263. </if>
  264. <if test="hasFollowWx != null and hasFollowWx == 1 ">
  265. AND uwf.gzh_open_id is not null
  266. </if>
  267. <if test="hasFollowWx != null and hasFollowWx == 0 ">
  268. AND uwf.gzh_open_id is null
  269. </if>
  270. <if test="lastVisitPlat != null ">
  271. AND uvl.visit_from_plat = #{lastVisitPlat}
  272. </if>
  273. <if test="lastStudyPlat != null ">
  274. AND usl.study_from_plat = #{lastStudyPlat}
  275. </if>
  276. <if test="visitStartTime != null and visitStartTime !=''">
  277. and uvl.last_visit_time >= #{visitStartTime}
  278. </if>
  279. <if test="visitEndTime != null and visitEndTime !=''">
  280. and #{visitEndTime} >= uvl.last_visit_time
  281. </if>
  282. <if test="studyStartTime != null and studyStartTime !=''">
  283. and usl.last_study_time >= #{studyStartTime}
  284. </if>
  285. <if test="studyEndTime != null and studyEndTime !=''">
  286. and #{studyEndTime} >= usl.last_study_time
  287. </if>
  288. <if test="gradeName != null and gradeName != ''">
  289. and ( SELECT
  290. count(og.*)
  291. FROM
  292. `order` o
  293. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  294. LEFT JOIN class_grade cg on cg.grade_id = og.grade_id
  295. where 1=1
  296. and og.`status` = 1
  297. and og.refund_status in (0,1,3)
  298. and og.pay_status in (2,3,4))
  299. and (cg.class_name like concat('%', #{gradeName}, '%'))
  300. and o.user_id = u.user_id)>0
  301. </if>
  302. </select>
  303. <select id="selectStudyRecordList" resultMap="StudyRecordResult">
  304. SELECT
  305. usr.study_duration,
  306. c.course_name,
  307. pv.title,
  308. usr.start_time,
  309. usr.end_time,
  310. u.realname,
  311. u.telphone
  312. FROM
  313. user_study_record usr
  314. LEFT JOIN course c ON usr.course_id = c.course_id
  315. LEFT JOIN course_section cs ON usr.section_id = cs.section_id
  316. LEFT JOIN polyv_video pv ON cs.polyv_id = pv.polyv_id
  317. LEFT JOIN `user` u ON usr.user_id = u.user_id
  318. WHERE 1=1
  319. <if test="userId != null and userId != ''" >
  320. AND usr.user_id = #{userId}
  321. </if>
  322. <if test="courseName != null and courseName != ''" >
  323. AND c.course_name like concat('%', #{courseName}, '%')
  324. </if>
  325. <if test="title != null and title != ''" >
  326. AND pv.title like concat('%', #{title}, '%')
  327. </if>
  328. <if test="startTime1 != null and startTime1 != ''" >
  329. AND usr.start_time > #{startTime1}
  330. </if>
  331. <if test="startTime2 != null and startTime2 != ''" >
  332. AND #{startTime2} > usr.start_time
  333. </if>
  334. <if test="endTime1 != null and endTime1 != ''" >
  335. AND usr.end_time > #{endTime1}
  336. </if>
  337. <if test="endTime2 != null and endTime2 != ''" >
  338. AND #{endTime2} > usr.end_time
  339. </if>
  340. ORDER BY
  341. usr.record_id DESC
  342. </select>
  343. <select id="selectLookNum" parameterType="Long" resultType="integer">
  344. SELECT
  345. COUNT( user_id )
  346. FROM
  347. recruit_interview_message
  348. WHERE
  349. 1 = 1
  350. AND user_id = #{userId}
  351. AND look_status = 0
  352. </select>
  353. <select id="periodSum" parameterType="Long" resultType="Long">
  354. SELECT
  355. COUNT(1)
  356. FROM
  357. user_period up
  358. LEFT JOIN user_period_status ups ON ups.period_id = up.id
  359. LEFT JOIN class_grade_user cgu on up.grade_id = cgu.grade_id and up.user_id = cgu.user_id
  360. WHERE
  361. up.user_id = #{userId}
  362. and ups.period_status =1
  363. and cgu.change_grade = 0
  364. and ups.`status` in (0,3)
  365. </select>
  366. <select id="subscribeSum" parameterType="Long" resultType="Long">
  367. SELECT
  368. COUNT(1)
  369. FROM
  370. user_subscribe us
  371. WHERE
  372. us.user_id = #{userId}
  373. AND us.subscribe_status = 1
  374. and (us.exam_expend is null or us.exam_expend = 0)
  375. </select>
  376. <select id="informSum" parameterType="Long" resultType="Long">
  377. SELECT
  378. COUNT(1)
  379. FROM
  380. inform_user iu
  381. WHERE
  382. iu.user_id = #{userId}
  383. and iu.receipt_status = 0
  384. and iu.system_status in (1,2)
  385. </select>
  386. <select id="orderSum" parameterType="Long" resultType="Long">
  387. SELECT
  388. COUNT( 1 )
  389. FROM
  390. `order`
  391. WHERE
  392. user_id = #{userId}
  393. AND order_status =0
  394. </select>
  395. </mapper>