UserMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. </resultMap>
  54. <resultMap type="com.zhongzheng.modules.user.vo.RanKingUser" id="RanKingUserResult">
  55. <result property="hourse" column="sum_study"/>
  56. <result property="avatar" column="avatar"/>
  57. <result property="nickname" column="nickname"/>
  58. <result property="rank" column="pm"/>
  59. </resultMap>
  60. <resultMap type="com.zhongzheng.modules.user.vo.UserStudyRecordVo" id="StudyRecordResult">
  61. <result property="telphone" column="telphone"/>
  62. <result property="realname" column="realname"/>
  63. <result property="endTime" column="end_time"/>
  64. <result property="startTime" column="start_time"/>
  65. <result property="title" column="title"/>
  66. <result property="courseName" column="course_name"/>
  67. <result property="studyDuration" column="study_duration"/>
  68. </resultMap>
  69. <select id="selectByRank" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  70. SELECT sum(s.study_duration) AS sum_study,u.nickname,u.avatar FROM `user` u
  71. LEFT JOIN user_study_record s ON u.user_id=s.user_id where 1=1
  72. <if test="userId != null and userId != ''">
  73. AND u.user_id = #{userId}
  74. </if>
  75. <if test="startTime != null and startTime != ''">
  76. AND s.create_time BETWEEN #{startTime} and #{endTime}
  77. </if>
  78. GROUP BY u.user_id
  79. </select>
  80. <select id="selectByRanks" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  81. SELECT A.*
  82. FROM
  83. (
  84. SELECT sum(s.study_duration) AS sum_study,u.nickname,u.avatar FROM `user` u
  85. LEFT JOIN user_study_record s ON u.user_id=s.user_id where 1=1
  86. <if test="startTime != null and startTime != ''">
  87. AND s.create_time BETWEEN #{startTime} and #{endTime}
  88. </if>
  89. GROUP BY u.user_id ORDER BY sum_study desc LIMIT 20
  90. ) A where
  91. A.sum_study >0
  92. </select>
  93. <select id="selectByRankOne" parameterType="integer" resultType="int">
  94. SELECT
  95. COUNT(s.sum_study)
  96. FROM
  97. (SELECT sum( s.study_duration ) AS sum_study FROM user_study_record s WHERE 1 = 1 GROUP BY s.user_id) s
  98. WHERE s.sum_study >= #{hourse}
  99. </select>
  100. <select id="selectByRankOneByTime" parameterType="map" resultType="int">
  101. SELECT
  102. COUNT(s.sum_study)
  103. FROM
  104. (SELECT sum( s.study_duration ) AS sum_study FROM user_study_record s WHERE 1 = 1
  105. <if test="startTime != null and startTime != ''">
  106. and s.create_time BETWEEN #{startTime} and #{endTime}
  107. </if>
  108. GROUP BY s.user_id) s
  109. WHERE s.sum_study >= #{hourse}
  110. </select>
  111. <select id="selectByOneRank" parameterType="com.zhongzheng.modules.user.bo.RanKingUserQuery" resultMap="RanKingUserResult">
  112. SELECT u.nickname,u.avatar FROM `user` u
  113. where 1=1
  114. <if test="userId != null and userId != ''">
  115. AND u.user_id = #{userId}
  116. </if>
  117. GROUP BY u.user_id
  118. </select>
  119. <select id="selectUserNum" parameterType="integer" resultType="int">
  120. SELECT
  121. COUNT(user_id)
  122. FROM
  123. `user`
  124. WHERE 1=1 and user_level = #{grade}
  125. </select>
  126. <select id="selectList" parameterType="com.zhongzheng.modules.user.bo.UserQueryBo" resultMap="UserResult">
  127. SELECT DISTINCT
  128. u.*
  129. <if test="getOrderNum != null and getOrderNum == 1" >
  130. ,ou.goods_course_num,ou.goods_bank_num,ou.goods_live_num
  131. </if>
  132. FROM
  133. `user` u
  134. <if test="getOrderNum != null and getOrderNum == 1" >
  135. LEFT JOIN (
  136. SELECT
  137. sum( CASE WHEN g.goods_type = 1 THEN 1 ELSE 0 END ) AS goods_course_num,
  138. sum( CASE WHEN g.goods_type = 2 THEN 1 ELSE 0 END ) AS goods_bank_num,
  139. sum( CASE WHEN g.goods_type = 6 THEN 1 ELSE 0 END ) AS goods_live_num,
  140. o.user_id
  141. FROM
  142. `order` o
  143. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  144. LEFT JOIN goods g ON og.goods_id = g.goods_id
  145. WHERE o.`status` = 1
  146. AND og.refund_status in (0,1,3)
  147. AND og.pay_status in (2,3,4)
  148. GROUP BY
  149. o.user_id
  150. ) ou ON u.user_id = ou.user_id
  151. </if>
  152. <if test="businessId != null and businessId != ''">
  153. LEFT JOIN `order` o ON u.user_id = o.user_id and o.`status` = 1
  154. LEFT JOIN order_goods og ON o.order_sn = og.order_sn and og.`status` = 1
  155. LEFT JOIN goods g ON og.goods_id = g.goods_id
  156. </if>
  157. WHERE
  158. 1 = 1
  159. <if test="status != null and status.size()!=0 ">
  160. AND u.status in
  161. <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
  162. #{item}
  163. </foreach>
  164. </if>
  165. <if test="businessId != null and businessId != ''">
  166. and og.`status` = 1
  167. and og.refund_status in (0,1,3)
  168. and og.pay_status in (2,3,4)
  169. AND g.business_id = #{businessId}
  170. </if>
  171. <if test="startTime != null and startTime != ''">
  172. AND u.create_time &gt; #{startTime}
  173. </if>
  174. <if test="endTime != null and endTime != ''">
  175. AND u.create_time &lt; #{endTime}
  176. </if>
  177. <if test="nickname != null and nickname != ''" >
  178. AND u.nickname like concat('%', #{nickname}, '%')
  179. </if>
  180. <if test="telphone != null and telphone != ''" >
  181. AND u.telphone = #{telphone}
  182. </if>
  183. <if test="idCard != null and idCard != ''" >
  184. AND u.id_card = #{idCard}
  185. </if>
  186. <if test="realname != null and realname != ''" >
  187. AND u.realname like concat('%', #{realname}, '%')
  188. </if>
  189. <if test="companyName != null and companyName != ''" >
  190. AND u.company_name like concat('%', #{companyName}, '%')
  191. </if>
  192. <if test="userId != null and userId != ''" >
  193. AND u.user_id = #{userId}
  194. </if>
  195. <if test="empty != null and empty != ''" >
  196. and u.realname is NOT NULL
  197. </if>
  198. <if test="goodsSearchKey != null and goodsSearchKey != ''" >
  199. and ( SELECT
  200. count(og.*)
  201. FROM
  202. `order` o
  203. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  204. where 1=1
  205. and og.`status` = 1
  206. and og.refund_status in (0,1,3)
  207. and og.pay_status in (2,3,4))
  208. and (g.goods_name like concat('%', #{goodsSearchKey}, '%') or g.code like concat('%', #{goodsSearchKey}, '%'))
  209. and o.user_id = u.user_id)>0
  210. </if>
  211. <if test="goodsSearchKey != null and goodsSearchKey != ''" >
  212. and ( SELECT
  213. count(og.*)
  214. FROM
  215. `order` o
  216. LEFT JOIN order_goods og on o.order_sn = og.order_sn
  217. where 1=1
  218. and og.`status` = 1
  219. and og.refund_status in (0,1,3)
  220. and og.pay_status in (2,3,4))
  221. and (g.goods_name like concat('%', #{goodsSearchKey}, '%') or g.code like concat('%', #{goodsSearchKey}, '%'))
  222. and o.user_id = u.user_id)>0
  223. </if>
  224. <if test="gradePoint != null and gradePoint == 1" >
  225. 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
  226. </if>
  227. <if test="gradePoint != null and gradePoint == 2" >
  228. 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
  229. </if>
  230. <if test="searchKey != null and searchKey != '' and searchType == 0 ">
  231. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%'))
  232. </if>
  233. <if test="idCards != null and idCards.size()!=0 and searchType == 0" >
  234. AND u.id_card in
  235. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  236. #{item}
  237. </foreach>
  238. </if>
  239. <if test="searchType == 1" >
  240. and (u.realname like concat('%', #{searchKey}, '%') or u.id_card like concat('%', #{searchKey}, '%') or
  241. u.id_card in
  242. <foreach collection="idCards" item="item" index="index" open="(" close=")" separator=",">
  243. #{item}
  244. </foreach>)
  245. </if>
  246. </select>
  247. <select id="selectStudyRecordList" resultMap="StudyRecordResult">
  248. SELECT
  249. usr.study_duration,
  250. c.course_name,
  251. pv.title,
  252. usr.start_time,
  253. usr.end_time,
  254. u.realname,
  255. u.telphone
  256. FROM
  257. user_study_record usr
  258. LEFT JOIN course c ON usr.course_id = c.course_id
  259. LEFT JOIN course_section cs ON usr.section_id = cs.section_id
  260. LEFT JOIN polyv_video pv ON cs.polyv_id = pv.polyv_id
  261. LEFT JOIN `user` u ON usr.user_id = u.user_id
  262. WHERE 1=1
  263. <if test="userId != null and userId != ''" >
  264. AND usr.user_id = #{userId}
  265. </if>
  266. <if test="courseName != null and courseName != ''" >
  267. AND c.course_name like concat('%', #{courseName}, '%')
  268. </if>
  269. <if test="title != null and title != ''" >
  270. AND pv.title like concat('%', #{title}, '%')
  271. </if>
  272. <if test="startTime1 != null and startTime1 != ''" >
  273. AND usr.start_time > #{startTime1}
  274. </if>
  275. <if test="startTime2 != null and startTime2 != ''" >
  276. AND #{startTime2} > usr.start_time
  277. </if>
  278. <if test="endTime1 != null and endTime1 != ''" >
  279. AND usr.end_time > #{endTime1}
  280. </if>
  281. <if test="endTime2 != null and endTime2 != ''" >
  282. AND #{endTime2} > usr.end_time
  283. </if>
  284. ORDER BY
  285. usr.record_id DESC
  286. </select>
  287. <select id="selectLookNum" parameterType="Long" resultType="integer">
  288. SELECT
  289. COUNT( user_id )
  290. FROM
  291. recruit_interview_message
  292. WHERE
  293. 1 = 1
  294. AND user_id = #{userId}
  295. AND look_status = 0
  296. </select>
  297. <select id="periodSum" parameterType="Long" resultType="Long">
  298. SELECT
  299. COUNT(1)
  300. FROM
  301. user_period up
  302. LEFT JOIN user_period_status ups ON ups.period_id = up.id
  303. LEFT JOIN class_grade_user cgu on up.grade_id = cgu.grade_id and up.user_id = cgu.user_id
  304. WHERE
  305. up.user_id = #{userId}
  306. and ups.period_status =1
  307. and cgu.change_grade = 0
  308. and ups.`status` in (0,3)
  309. </select>
  310. <select id="subscribeSum" parameterType="Long" resultType="Long">
  311. SELECT
  312. COUNT(1)
  313. FROM
  314. user_subscribe us
  315. WHERE
  316. us.user_id = #{userId}
  317. AND us.subscribe_status = 1
  318. and (us.exam_expend is null or us.exam_expend = 0)
  319. </select>
  320. <select id="informSum" parameterType="Long" resultType="Long">
  321. SELECT
  322. COUNT(1)
  323. FROM
  324. inform_user iu
  325. WHERE
  326. iu.user_id = #{userId}
  327. and iu.receipt_status = 0
  328. and iu.system_status in (1,2)
  329. </select>
  330. <select id="orderSum" parameterType="Long" resultType="Long">
  331. SELECT
  332. COUNT( 1 )
  333. FROM
  334. `order`
  335. WHERE
  336. user_id = #{userId}
  337. AND order_status =0
  338. </select>
  339. </mapper>