UserMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  13. <result property="telphone" column="telphone" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  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. <result property="job" column="job"/>
  60. <result property="shareCode" column="share_code"/>
  61. </resultMap>
  62. <resultMap type="com.zhongzheng.modules.user.vo.RanKingUser" id="RanKingUserResult">
  63. <result property="hourse" column="sum_study"/>
  64. <result property="avatar" column="avatar"/>
  65. <result property="nickname" column="nickname"/>
  66. <result property="rank" column="pm"/>
  67. </resultMap>
  68. <resultMap type="com.zhongzheng.modules.user.vo.UserStudyRecordVo" id="StudyRecordResult">
  69. <result property="telphone" column="telphone" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  70. <result property="realname" column="realname"/>
  71. <result property="endTime" column="end_time"/>
  72. <result property="startTime" column="start_time"/>
  73. <result property="title" column="title"/>
  74. <result property="courseName" column="course_name"/>
  75. <result property="studyDuration" column="study_duration"/>
  76. </resultMap>
  77. <select id="selectByRank" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  78. SELECT sum(s.study_duration) AS sum_study,u.nickname,u.avatar FROM `user` u
  79. LEFT JOIN user_study_record s ON u.user_id=s.user_id where 1=1
  80. <if test="userId != null and userId != ''">
  81. AND u.user_id = #{userId}
  82. </if>
  83. <if test="startTime != null and startTime != ''">
  84. AND s.create_time BETWEEN #{startTime} and #{endTime}
  85. </if>
  86. GROUP BY u.user_id
  87. </select>
  88. <select id="selectByRanks" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  89. SELECT A.*
  90. FROM
  91. (
  92. SELECT sum(s.study_duration) AS sum_study,u.nickname,u.avatar FROM `user` u
  93. LEFT JOIN user_study_record s ON u.user_id=s.user_id where 1=1
  94. <if test="startTime != null and startTime != ''">
  95. AND s.create_time BETWEEN #{startTime} and #{endTime}
  96. </if>
  97. GROUP BY u.user_id ORDER BY sum_study desc LIMIT 20
  98. ) A where
  99. A.sum_study >0
  100. </select>
  101. <select id="selectByRankOne" parameterType="integer" resultType="int">
  102. SELECT
  103. COUNT(s.sum_study)
  104. FROM
  105. (SELECT sum( s.study_duration ) AS sum_study FROM user_study_record s WHERE 1 = 1 GROUP BY s.user_id) s
  106. WHERE s.sum_study >= #{hourse}
  107. </select>
  108. <select id="selectByRankOneByTime" parameterType="map" resultType="int">
  109. SELECT
  110. COUNT(s.sum_study)
  111. FROM
  112. (SELECT sum( s.study_duration ) AS sum_study FROM user_study_record s WHERE 1 = 1
  113. <if test="startTime != null and startTime != ''">
  114. and s.create_time BETWEEN #{startTime} and #{endTime}
  115. </if>
  116. GROUP BY s.user_id) s
  117. WHERE s.sum_study >= #{hourse}
  118. </select>
  119. <select id="selectByOneRank" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  120. SELECT u.nickname,u.avatar FROM `user` u
  121. where 1=1
  122. <if test="userId != null and userId != ''">
  123. AND u.user_id = #{userId}
  124. </if>
  125. GROUP BY u.user_id
  126. </select>
  127. <select id="selectUserNum" parameterType="integer" resultType="int">
  128. SELECT
  129. COUNT(user_id)
  130. FROM
  131. `user`
  132. WHERE 1=1 and user_level = #{grade}
  133. </select>
  134. <select id="selectList" parameterType="com.zhongzheng.modules.user.bo.UserQueryBo" resultMap="UserResult">
  135. SELECT DISTINCT
  136. u.*,
  137. (case WHEN u.union_id is null then 0 ELSE 1 end) as user_bind_wx,
  138. (case WHEN uwf.gzh_open_id is null then 0 ELSE 1 end) as user_follow_wx
  139. <if test="getOrderNum != null and getOrderNum == 1" >
  140. ,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
  141. </if>
  142. FROM
  143. `user` u
  144. LEFT JOIN user_wx_follow uwf ON u.union_id = uwf.union_id
  145. <if test="getOrderNum != null and getOrderNum == 1" >
  146. LEFT JOIN (
  147. SELECT
  148. sum( CASE WHEN g.goods_type = 1 THEN 1 ELSE 0 END ) AS goods_course_num,
  149. sum( CASE WHEN g.goods_type = 2 THEN 1 ELSE 0 END ) AS goods_bank_num,
  150. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num,
  151. o.user_id
  152. FROM
  153. `order` o
  154. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  155. LEFT JOIN goods g ON og.goods_id = g.goods_id
  156. WHERE o.`status` = 1
  157. AND og.refund_status in (0,1,3)
  158. AND og.pay_status in (2,3,4)
  159. GROUP BY
  160. o.user_id
  161. ) ou ON u.user_id = ou.user_id
  162. LEFT JOIN (SELECT user_id,from_plat as visit_from_plat,create_time as last_visit_time from user_visit_log where id in(SELECT MAX(id) from user_visit_log GROUP BY user_id))uvl on u.user_id = uvl.user_id
  163. LEFT JOIN (SELECT user_id,from_plat as study_from_plat,create_time as last_study_time from user_study_log where id in(SELECT MAX(id) from user_study_log GROUP BY user_id))usl on u.user_id = usl.user_id
  164. </if>
  165. <if test="businessId != null and businessId != ''">
  166. LEFT JOIN `order` o ON u.user_id = o.user_id and o.`status` = 1
  167. LEFT JOIN order_goods og ON o.order_sn = og.order_sn and og.`status` = 1
  168. LEFT JOIN goods g ON og.goods_id = g.goods_id
  169. </if>
  170. WHERE
  171. 1 = 1
  172. <if test="status != null and status.size()!=0 ">
  173. AND u.status in
  174. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  175. #{item}
  176. </foreach>
  177. </if>
  178. <if test="businessId != null and businessId != ''">
  179. and og.`status` = 1
  180. and og.refund_status in (0,1,3)
  181. and og.pay_status in (2,3,4)
  182. AND g.business_id = #{businessId}
  183. </if>
  184. <if test="startTime != null and startTime != ''">
  185. AND u.create_time &gt; #{startTime}
  186. </if>
  187. <if test="endTime != null and endTime != ''">
  188. AND u.create_time &lt; #{endTime}
  189. </if>
  190. <if test="userKerWord != null and userKerWord != ''" >
  191. AND (u.realname like concat('%', #{userKerWord}, '%') OR u.telphone like concat('%', #{userKerWord,typeHandler=com.zhongzheng.common.type.EncryptHandler}, '%') OR u.id_card like concat('%', #{userKerWord,typeHandler=com.zhongzheng.common.type.EncryptHandler}, '%'))
  192. </if>
  193. <if test="nickname != null and nickname != ''" >
  194. AND u.nickname like concat('%', #{nickname}, '%')
  195. </if>
  196. <if test="telphone != null and telphone != ''" >
  197. AND u.telphone like concat('%', #{telphone,typeHandler=com.zhongzheng.common.type.EncryptHandler}, '%')
  198. </if>
  199. <if test="idCard != null and idCard != ''" >
  200. AND u.id_card like concat('%', #{idCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}, '%')
  201. </if>
  202. <if test="realname != null and realname != ''" >
  203. AND u.realname like concat('%', #{realname}, '%')
  204. </if>
  205. <if test="companyName != null and companyName != ''" >
  206. AND u.company_name like concat('%', #{companyName}, '%')
  207. </if>
  208. <if test="userId != null and userId != ''" >
  209. AND u.user_id = #{userId}
  210. </if>
  211. <if test="empty != null and empty != ''" >
  212. and u.realname is NOT NULL
  213. </if>
  214. <if test="goodsSearchKey != null and goodsSearchKey != ''" >
  215. and ( SELECT
  216. count(og.*)
  217. FROM
  218. `order` o
  219. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  220. where 1=1
  221. and og.`status` = 1
  222. and og.refund_status in (0,1,3)
  223. and og.pay_status in (2,3,4))
  224. and (g.goods_name like concat('%', #{goodsSearchKey}, '%') or g.code like concat('%', #{goodsSearchKey}, '%'))
  225. and o.user_id = u.user_id)>0
  226. </if>
  227. <if test="goodsSearchKey != null and goodsSearchKey != ''" >
  228. and ( SELECT
  229. count(*)
  230. FROM
  231. `order` o
  232. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  233. LEFT JOIN goods g on og.goods_id = g.goods_id
  234. where 1=1
  235. and og.`status` = 1
  236. and og.refund_status in (0,1,3)
  237. and og.pay_status in (2,3,4)
  238. and (g.goods_name like concat('%', #{goodsSearchKey}, '%') or g.code like concat('%', #{goodsSearchKey}, '%'))
  239. and o.user_id = u.user_id)>0
  240. </if>
  241. <if test="gradePoint != null and gradePoint == 1" >
  242. 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
  243. </if>
  244. <if test="gradePoint != null and gradePoint == 2" >
  245. 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
  246. </if>
  247. <if test="searchKey != null and searchKey != '' and searchType == 0 ">
  248. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey,typeHandler=com.zhongzheng.common.type.EncryptHandler}, '%'))
  249. </if>
  250. <if test="idCards != null and idCards.size()!=0 and searchType == 0" >
  251. AND u.id_card in
  252. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  253. #{item,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  254. </foreach>
  255. </if>
  256. <if test="searchType == 1" >
  257. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey,typeHandler=com.zhongzheng.common.type.EncryptHandler}, '%') or
  258. u.id_card in
  259. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  260. #{item,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  261. </foreach>)
  262. </if>
  263. <if test="hasBindWx != null and hasBindWx == 1 ">
  264. AND u.union_id is not null
  265. </if>
  266. <if test="hasBindWx != null and hasBindWx == 0 ">
  267. AND u.union_id is null
  268. </if>
  269. <if test="hasFollowWx != null and hasFollowWx == 1 ">
  270. AND uwf.gzh_open_id is not null
  271. </if>
  272. <if test="hasFollowWx != null and hasFollowWx == 0 ">
  273. AND uwf.gzh_open_id is null
  274. </if>
  275. <if test="lastVisitPlat != null ">
  276. AND uvl.visit_from_plat = #{lastVisitPlat}
  277. </if>
  278. <if test="lastStudyPlat != null ">
  279. AND usl.study_from_plat = #{lastStudyPlat}
  280. </if>
  281. <if test="visitStartTime != null and visitStartTime !=''">
  282. and (SELECT
  283. count(*)
  284. FROM user_visit_log where user_id = u.user_id and create_time>= #{visitStartTime} and #{visitEndTime} >= create_time)>0
  285. </if>
  286. <if test="studyStartTime != null and studyStartTime !=''">
  287. and (SELECT
  288. count(*)
  289. FROM user_study_log where user_id = u.user_id and create_time>= #{studyStartTime} and #{studyEndTime} >= create_time)>0
  290. </if>
  291. <if test="gradeName != null and gradeName != ''">
  292. and ( SELECT
  293. count(*)
  294. FROM
  295. `order` o
  296. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  297. LEFT JOIN class_grade cg on cg.grade_id = og.grade_id
  298. where 1=1
  299. and og.`status` = 1
  300. and og.refund_status in (0,1,3)
  301. and og.pay_status in (2,3,4)
  302. and (cg.class_name like concat('%', #{gradeName}, '%'))
  303. and o.user_id = u.user_id)>0
  304. </if>
  305. ORDER BY u.user_id DESC
  306. </select>
  307. <select id="selectStudyRecordList" resultMap="StudyRecordResult">
  308. SELECT
  309. usr.study_duration,
  310. c.course_name,
  311. pv.title,
  312. usr.start_time,
  313. usr.end_time,
  314. u.realname,
  315. u.telphone
  316. FROM
  317. user_study_record usr
  318. LEFT JOIN course c ON usr.course_id = c.course_id
  319. LEFT JOIN course_section cs ON usr.section_id = cs.section_id
  320. LEFT JOIN polyv_video pv ON cs.polyv_id = pv.polyv_id
  321. LEFT JOIN `user` u ON usr.user_id = u.user_id
  322. WHERE 1=1
  323. <if test="userId != null and userId != ''" >
  324. AND usr.user_id = #{userId}
  325. </if>
  326. <if test="courseName != null and courseName != ''" >
  327. AND c.course_name like concat('%', #{courseName}, '%')
  328. </if>
  329. <if test="title != null and title != ''" >
  330. AND pv.title like concat('%', #{title}, '%')
  331. </if>
  332. <if test="startTime1 != null and startTime1 != ''" >
  333. AND usr.start_time > #{startTime1}
  334. </if>
  335. <if test="startTime2 != null and startTime2 != ''" >
  336. AND #{startTime2} > usr.start_time
  337. </if>
  338. <if test="endTime1 != null and endTime1 != ''" >
  339. AND usr.end_time > #{endTime1}
  340. </if>
  341. <if test="endTime2 != null and endTime2 != ''" >
  342. AND #{endTime2} > usr.end_time
  343. </if>
  344. ORDER BY
  345. usr.record_id DESC
  346. </select>
  347. <select id="selectLookNum" parameterType="Long" resultType="integer">
  348. SELECT
  349. COUNT( user_id )
  350. FROM
  351. recruit_interview_message
  352. WHERE
  353. 1 = 1
  354. AND user_id = #{userId}
  355. AND look_status = 0
  356. </select>
  357. <select id="periodSum" parameterType="Long" resultType="Long">
  358. SELECT
  359. COUNT(1)
  360. FROM
  361. user_period up
  362. LEFT JOIN user_period_status ups ON ups.period_id = up.id
  363. LEFT JOIN class_grade_user cgu on up.grade_id = cgu.grade_id and up.user_id = cgu.user_id
  364. WHERE
  365. up.user_id = #{userId}
  366. and ups.period_status =1
  367. and cgu.change_grade = 0
  368. and ups.`status` in (0,3)
  369. </select>
  370. <select id="subscribeSum" parameterType="Long" resultType="Long">
  371. SELECT
  372. COUNT(1)
  373. FROM
  374. user_subscribe us
  375. WHERE
  376. us.user_id = #{userId}
  377. AND us.subscribe_status = 1
  378. and (us.exam_expend is null or us.exam_expend = 0)
  379. </select>
  380. <select id="informSum" parameterType="Long" resultType="Long">
  381. SELECT
  382. COUNT(1)
  383. FROM
  384. inform_user iu
  385. WHERE
  386. iu.user_id = #{userId}
  387. and iu.receipt_status = 0
  388. and iu.system_status in (1,2)
  389. </select>
  390. <select id="orderSum" parameterType="Long" resultType="Long">
  391. SELECT
  392. COUNT( 1 )
  393. FROM
  394. `order`
  395. WHERE
  396. user_id = #{userId}
  397. AND order_status =0
  398. </select>
  399. <select id="queryUserByTelphoneTenant" parameterType="map" resultMap="UserResult">
  400. SELECT
  401. *
  402. FROM
  403. `user`
  404. WHERE
  405. telphone = #{telphone,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  406. AND status = 1 AND tenant_id = #{tenantId}
  407. </select>
  408. <select id="getUserByTelNotTenant" parameterType="java.lang.String" resultType="com.zhongzheng.modules.user.domain.User">
  409. SELECT
  410. *
  411. FROM
  412. `user`
  413. WHERE
  414. telphone = #{telphone,typeHandler=com.zhongzheng.common.type.EncryptHandler} AND status = 1
  415. </select>
  416. <select id="getUserByIdNumNotTenant" parameterType="java.lang.String" resultType="com.zhongzheng.modules.user.domain.User">
  417. SELECT
  418. *
  419. FROM
  420. `user`
  421. WHERE
  422. id_card = #{idNum,typeHandler=com.zhongzheng.common.type.EncryptHandler} AND status = 1
  423. </select>
  424. <select id="queryUserByIdNumTenant" parameterType="map" resultMap="UserResult">
  425. SELECT
  426. *
  427. FROM
  428. `user`
  429. WHERE
  430. id_card = #{idNum,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  431. AND status = 1 AND tenant_id = #{tenantId}
  432. </select>
  433. <select id="selectAllUserList" parameterType="com.zhongzheng.modules.user.bo.UserQueryBo" resultMap="UserResult">
  434. SELECT
  435. *
  436. FROM
  437. `user`
  438. </select>
  439. <select id="editUserInfo" parameterType="com.zhongzheng.modules.user.bo.UserQueryBo">
  440. UPDATE `user`
  441. <trim prefix="set" suffixOverrides=",">
  442. <if test="telphone != null">
  443. telphone = #{telphone},
  444. </if>
  445. <if test="idCard != null">
  446. id_card = #{idCard},
  447. </if>
  448. </trim>
  449. WHERE
  450. user_id = #{userId}
  451. </select>
  452. </mapper>