ActivityUserMapperMapper.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.ActivityUserMapperDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.ActivityUserMapper" id="ActivityUserMapper">
  9. <result column="id_" property="id" />
  10. <result column="category_id_" property="categoryId" />
  11. <result column="give_category_id_" property="giveCategoryId" />
  12. <result column="single_course_time_" property="singleCourseTime" />
  13. <result column="give_single_course_time_" property="giveSingleCourseTime" />
  14. <result column="activity_id_" property="activityId" />
  15. <result column="user_id_" property="userId" />
  16. <result column="teacher_id_" property="teacherId" />
  17. <result column="vip_flag_" property="vipFlag" />
  18. <result column="give_vip_flag_" property="giveVipFlag" />
  19. <result column="practice_flag_" property="practiceFlag" />
  20. <result column="give_practice_flag_" property="givePracticeFlag" />
  21. <result column="member_flag_" property="memberFlag" />
  22. <result column="give_member_flag_" property="giveMemberFlag" />
  23. <result column="payment_order_id_" property="paymentOrderId" />
  24. <result column="vip_group_id_" property="vipGroupId" />
  25. <result column="total_course_num_" property="totalCourseNum" />
  26. <result column="total_give_course_num_" property="totalGiveCourseNum" />
  27. <result column="sub_course_num_" property="subCourseNum" />
  28. <result column="sub_give_course_num_" property="subGiveCourseNum" />
  29. <result column="give_vip_group_id_" property="giveVipGroupId" />
  30. <result column="member_order_id_" property="memberOrderId" />
  31. <result column="give_member_order_id_" property="giveMemberOrderId" />
  32. <result column="practice_group_id_" property="practiceGroupId" />
  33. <result column="give_practice_group_id_" property="givePracticeGroupId" />
  34. <result column="return_fee_" property="returnFee" />
  35. <result column="sub_no_course_price_" property="subNoCoursePrice" />
  36. <result column="actual_price_" property="actualPrice" />
  37. <result column="add_memo_" property="addMemo" />
  38. <result column="cut_memo_" property="cutMemo" />
  39. <result column="give_coupon_id_" property="giveCouponId" />
  40. <result column="create_time_" property="createTime" />
  41. <result column="calender_id_" property="calenderId" />
  42. <result column="update_time_" property="updateTime" />
  43. <result column="tenant_id_" property="tenantId" />
  44. </resultMap>
  45. <!-- 根据主键查询一条记录 -->
  46. <select id="get" resultMap="ActivityUserMapper" >
  47. SELECT * FROM activity_user_mapper WHERE id_ = #{id}
  48. </select>
  49. <!-- 全查询 -->
  50. <select id="findAll" resultMap="ActivityUserMapper">
  51. SELECT * FROM activity_user_mapper where tenant_id_ = #{tenantId} ORDER BY id_
  52. </select>
  53. <!-- 向数据库增加一条记录 -->
  54. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ActivityUserMapper" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  55. INSERT INTO activity_user_mapper (activity_id_,user_id_,vip_flag_,give_vip_flag_,
  56. practice_flag_,give_practice_flag_,member_flag_,give_member_flag_,create_time_,update_time_,payment_order_id_,
  57. vip_group_id_,give_vip_group_id_,practice_group_id_,give_practice_group_id_,return_fee_,
  58. member_order_id_,give_member_order_id_,teacher_id_,actual_price_,add_memo_,cut_memo_,tenant_id_,give_coupon_id_,
  59. total_course_num_,total_give_course_num_,sub_course_num_,sub_give_course_num_,sub_no_course_price_,single_course_time_,
  60. give_single_course_time_,category_id_,give_category_id_,calender_id_)
  61. VALUES(#{activityId},#{userId},#{vipFlag},#{giveVipFlag},#{practiceFlag},
  62. #{givePracticeFlag},#{memberFlag},#{giveMemberFlag},NOW(),NOW(),#{paymentOrderId},#{vipGroupId},
  63. #{giveVipGroupId},#{practiceGroupId},#{givePracticeGroupId},#{returnFee},
  64. #{memberOrderId},#{giveMemberOrderId},#{teacherId},#{actualPrice},#{addMemo},#{cutMemo},#{tenantId},#{giveCouponId},
  65. #{totalCourseNum},#{totalGiveCourseNum},#{subCourseNum},#{subGiveCourseNum},#{subNoCoursePrice},
  66. #{singleCourseTime},#{giveSingleCourseTime},#{categoryId},#{giveCategoryId},#{calenderId})
  67. </insert>
  68. <insert id="batchInsert">
  69. INSERT INTO activity_user_mapper (activity_id_,user_id_,vip_flag_,give_vip_flag_,
  70. practice_flag_,give_practice_flag_,member_flag_,give_member_flag_,create_time_,update_time_,payment_order_id_,
  71. vip_group_id_,give_vip_group_id_,practice_group_id_,give_practice_group_id_,return_fee_,member_order_id_,
  72. give_member_order_id_,teacher_id_,actual_price_,add_memo_,cut_memo_,tenant_id_,give_coupon_id_,
  73. total_course_num_,total_give_course_num_,sub_course_num_,sub_give_course_num_,sub_no_course_price_,single_course_time_,
  74. give_single_course_time_,category_id_,give_category_id_,calender_id_)
  75. VALUES
  76. <foreach collection="activityUserMappers" item="item" separator=",">
  77. (#{item.activityId},#{item.userId},#{item.vipFlag},#{item.giveVipFlag},#{item.practiceFlag},
  78. #{item.givePracticeFlag},#{item.memberFlag},#{item.giveMemberFlag},NOW(),NOW(),#{item.paymentOrderId},#{item.vipGroupId},
  79. #{item.giveVipGroupId},#{item.practiceGroupId},#{item.givePracticeGroupId},#{item.returnFee},
  80. #{item.memberOrderId},#{item.giveMemberOrderId},#{item.teacherId},#{item.actualPrice},#{item.addMemo},#{item.cutMemo},
  81. #{item.tenantId},#{item.giveCouponId},#{item.totalCourseNum},#{item.totalGiveCourseNum},#{item.subCourseNum},
  82. #{item.subGiveCourseNum},#{item.subNoCoursePrice},#{item.singleCourseTime},#{item.giveSingleCourseTime},
  83. #{item.categoryId},#{item.giveCategoryId},#{item.calenderId})
  84. </foreach>
  85. </insert>
  86. <!-- 根据主键查询一条记录 -->
  87. <update id="update" parameterType="com.ym.mec.biz.dal.entity.ActivityUserMapper">
  88. UPDATE activity_user_mapper
  89. <set>
  90. <if test="calenderId != null">
  91. calender_id_ = #{calenderId},
  92. </if>
  93. <if test="singleCourseTime != null">
  94. single_course_time_ = #{singleCourseTime},
  95. </if>
  96. <if test="giveSingleCourseTime != null">
  97. give_single_course_time_ = #{giveSingleCourseTime},
  98. </if>
  99. <if test="totalCourseNum != null">
  100. total_course_num_ = #{totalCourseNum},
  101. </if>
  102. <if test="subNoCoursePrice != null">
  103. sub_no_course_price_ = #{subNoCoursePrice},
  104. </if>
  105. <if test="totalGiveCourseNum != null">
  106. total_give_course_num_ = #{totalGiveCourseNum},
  107. </if>
  108. <if test="subCourseNum != null">
  109. sub_course_num_ = #{subCourseNum},
  110. </if>
  111. <if test="subGiveCourseNum != null">
  112. sub_give_course_num_ = #{subGiveCourseNum},
  113. </if>
  114. <if test="giveCouponId != null">
  115. give_coupon_id_ = #{giveCouponId},
  116. </if>
  117. <if test="cutMemo != null">
  118. cut_memo_ = #{cutMemo},
  119. </if>
  120. <if test="addMemo != null">
  121. add_memo_ = #{addMemo},
  122. </if>
  123. <if test="actualPrice != null">
  124. actual_price_ = #{actualPrice},
  125. </if>
  126. <if test="teacherId != null">
  127. teacher_id_ = #{teacherId},
  128. </if>
  129. <if test="memberOrderId != null">
  130. member_order_id_ = #{memberOrderId},
  131. </if>
  132. <if test="giveMemberOrderId != null">
  133. give_member_order_id_ = #{giveMemberOrderId},
  134. </if>
  135. <if test="returnFee != null">
  136. return_fee_ = #{returnFee},
  137. </if>
  138. <if test="vipGroupId != null">
  139. vip_group_id_ = #{vipGroupId},
  140. </if>
  141. <if test="giveVipGroupId != null">
  142. give_vip_group_id_ = #{giveVipGroupId},
  143. </if>
  144. <if test="practiceGroupId != null">
  145. practice_group_id_ = #{practiceGroupId},
  146. </if>
  147. <if test="givePracticeGroupId != null">
  148. give_practice_group_id_ = #{givePracticeGroupId},
  149. </if>
  150. <if test="paymentOrderId != null">
  151. payment_order_id_ = #{paymentOrderId},
  152. </if>
  153. <if test="userId != null">
  154. user_id_ = #{userId},
  155. </if>
  156. <if test="givePracticeFlag != null">
  157. give_practice_flag_ = #{givePracticeFlag},
  158. </if>
  159. <if test="giveVipFlag != null">
  160. give_vip_flag_ = #{giveVipFlag},
  161. </if>
  162. <if test="vipFlag != null">
  163. vip_flag_ = #{vipFlag},
  164. </if>
  165. <if test="activityId != null">
  166. activity_id_ = #{activityId},
  167. </if>
  168. <if test="practiceFlag != null">
  169. practice_flag_ = #{practiceFlag},
  170. </if>
  171. <if test="memberFlag != null">
  172. member_flag_ = #{memberFlag},
  173. </if>
  174. <if test="giveMemberFlag != null">
  175. give_member_flag_ = #{giveMemberFlag},
  176. </if>
  177. update_time_ = NOW()
  178. </set>WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  179. </update>
  180. <update id="use">
  181. UPDATE activity_user_mapper SET
  182. <if test="type == 'VIP'">
  183. vip_flag_ = 2,vip_group_id_ = #{groupId},update_time_ = NOW()
  184. WHERE vip_flag_ = 1
  185. </if>
  186. <if test="type == 'GIVE_VIP'">
  187. give_vip_flag_ = 2,give_vip_group_id_ = #{groupId},update_time_ = NOW()
  188. WHERE give_vip_flag_ = 1
  189. </if>
  190. <if test="type == 'PRACTICE'">
  191. practice_flag_ = 2,practice_group_id_ = #{groupId},update_time_ = NOW()
  192. WHERE practice_flag_ = 1
  193. </if>
  194. <if test="type == 'GIVE_PRACTICE'">
  195. give_practice_flag_ = 2,give_practice_group_id_ = #{groupId},update_time_ = NOW()
  196. WHERE give_practice_flag_ = 1
  197. </if>
  198. AND FIND_IN_SET(id_,#{activityUserMapperIds}) AND FIND_IN_SET(user_id_,#{studentIds}) AND return_fee_ = 0
  199. </update>
  200. <update id="updateTeacherId">
  201. UPDATE activity_user_mapper SET teacher_id_ = #{teacherId} WHERE user_id_ = #{userId}
  202. </update>
  203. <update id="batchUpdate">
  204. <foreach collection="useActivityUserMappers" item="entity" separator=";">
  205. UPDATE activity_user_mapper
  206. <set>
  207. <if test="entity.subNoCoursePrice != null">
  208. sub_no_course_price_ = #{entity.subNoCoursePrice},
  209. </if>
  210. <if test="entity.subCourseNum != null">
  211. sub_course_num_ = #{entity.subCourseNum},
  212. </if>
  213. <if test="entity.subGiveCourseNum != null">
  214. sub_give_course_num_ = #{entity.subGiveCourseNum},
  215. </if>
  216. <if test="entity.vipGroupId != null">
  217. vip_group_id_ = #{entity.vipGroupId},
  218. </if>
  219. <if test="entity.giveVipGroupId != null">
  220. give_vip_group_id_ = #{entity.giveVipGroupId},
  221. </if>
  222. <if test="entity.practiceGroupId != null">
  223. practice_group_id_ = #{entity.practiceGroupId},
  224. </if>
  225. <if test="entity.givePracticeGroupId != null">
  226. give_practice_group_id_ = #{entity.givePracticeGroupId},
  227. </if>
  228. <if test="entity.givePracticeFlag != null">
  229. give_practice_flag_ = #{entity.givePracticeFlag},
  230. </if>
  231. <if test="entity.giveVipFlag != null">
  232. give_vip_flag_ = #{entity.giveVipFlag},
  233. </if>
  234. <if test="entity.vipFlag != null">
  235. vip_flag_ = #{entity.vipFlag},
  236. </if>
  237. <if test="entity.practiceFlag != null">
  238. practice_flag_ = #{entity.practiceFlag},
  239. </if>
  240. update_time_ = NOW()
  241. </set>WHERE id_ = #{entity.id}
  242. </foreach>
  243. </update>
  244. <update id="batchUpdateFree">
  245. <foreach collection="useActivityUserMappers" item="entity" separator=";">
  246. UPDATE activity_user_mapper
  247. <set>
  248. <if test="entity.subGiveCourseNum != null">
  249. sub_give_course_num_ = #{entity.subGiveCourseNum},
  250. </if>
  251. <if test="entity.giveVipGroupId != null">
  252. give_vip_group_id_ = #{entity.giveVipGroupId},
  253. </if>
  254. <if test="entity.givePracticeGroupId != null">
  255. give_practice_group_id_ = #{entity.givePracticeGroupId},
  256. </if>
  257. <if test="entity.givePracticeFlag != null">
  258. give_practice_flag_ = #{entity.givePracticeFlag},
  259. </if>
  260. <if test="entity.giveVipFlag != null">
  261. give_vip_flag_ = #{entity.giveVipFlag},
  262. </if>
  263. update_time_ = NOW()
  264. </set>WHERE id_ = #{entity.id}
  265. </foreach>
  266. </update>
  267. <!-- 根据主键删除一条记录 -->
  268. <delete id="delete" >
  269. DELETE FROM activity_user_mapper WHERE id_ = #{id}
  270. </delete>
  271. <!-- 分页查询 -->
  272. <select id="queryPage" resultMap="ActivityUserMapper" parameterType="map">
  273. SELECT * FROM activity_user_mapper where tenant_id_ = #{tenantId}
  274. <if test="userId != null">
  275. AND user_id_ = #{userId}
  276. </if>
  277. <if test="activityId != null">
  278. AND activity_id_ = #{activityId}
  279. </if>
  280. ORDER BY id_ DESC
  281. <include refid="global.limit"/>
  282. </select>
  283. <!-- 查询当前表的总记录数 -->
  284. <select id="queryCount" resultType="int">
  285. SELECT COUNT(*) FROM activity_user_mapper where tenant_id_ = #{tenantId}
  286. <if test="userId != null">
  287. AND user_id_ = #{userId}
  288. </if>
  289. <if test="activityId != null">
  290. AND activity_id_ = #{activityId}
  291. </if>
  292. </select>
  293. <select id="findByStudentIdList" resultMap="ActivityUserMapper">
  294. SELECT * FROM activity_user_mapper
  295. WHERE return_fee_ = 0 AND FIND_IN_SET(user_id_,#{studentIds})
  296. <if test="activityId != null">
  297. AND activity_id_ = #{activityId}
  298. </if>
  299. <if test="type == 'GIVE_VIP'">
  300. AND give_vip_flag_ = 1
  301. </if>
  302. <if test="type == 'GIVE_PRACTICE'">
  303. AND give_practice_flag_ = 1
  304. </if>
  305. <if test="type == 'VIP'">
  306. AND vip_flag_ = 1
  307. </if>
  308. <if test="type == 'PRACTICE'">
  309. AND practice_flag_ = 1
  310. </if>
  311. GROUP BY user_id_
  312. </select>
  313. <select id="countActivityBuyNum" resultType="java.lang.Integer">
  314. SELECT count(id_) FROM activity_user_mapper
  315. WHERE activity_id_ = #{activityId} AND user_id_ = #{userId}
  316. </select>
  317. <select id="findVipUserMapper" resultMap="ActivityUserMapper">
  318. SELECT * FROM activity_user_mapper
  319. WHERE 1 = 1
  320. <if test="groupType == 'VIP'">
  321. AND (vip_group_id_ = #{groupId} OR give_vip_group_id_ = #{groupId})
  322. </if>
  323. <if test="groupType == 'PRACTICE'">
  324. AND (practice_group_id_ = #{groupId} OR give_practice_group_id_ = #{groupId})
  325. </if>
  326. <if test="studentId != null">
  327. AND user_id_ = #{studentId}
  328. </if>
  329. LIMIT 1
  330. </select>
  331. <select id="countActivityUserMapper" resultType="java.lang.Integer">
  332. SELECT COUNT(DISTINCT aum.user_id_)
  333. FROM activity_user_mapper aum
  334. LEFT JOIN sys_user su ON su.id_ = aum.user_id_
  335. LEFT JOIN organization o ON o.id_ = su.organ_id_
  336. WHERE aum.return_fee_ = 0 AND aum.activity_id_ = #{activityId}
  337. <if test="search != null and search != ''">
  338. AND (aum.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  339. </if>
  340. <if test="organId != null and organId != ''">
  341. AND FIND_IN_SET(su.organ_id_,#{organId})
  342. </if>
  343. </select>
  344. <resultMap id="ActivityStudentDto" type="com.ym.mec.biz.dal.dto.ActivityStudentDto">
  345. <result property="userId" column="user_id_"/>
  346. <result property="username" column="username_"/>
  347. <result property="organName" column="name_"/>
  348. <result property="phone" column="phone_"/>
  349. <result property="totalCourseNum" column="total_course_num_"/>
  350. <result property="subCourseNum" column="sub_course_num_"/>
  351. <result property="totalGiveCourseNum" column="total_give_course_num_"/>
  352. <result property="subGiveCourseNum" column="sub_give_course_num_"/>
  353. </resultMap>
  354. <select id="queryActivityUserMapper" resultMap="ActivityStudentDto">
  355. SELECT o.name_,aum.user_id_,su.username_,su.phone_,
  356. SUM(aum.total_course_num_) total_course_num_,
  357. SUM(aum.sub_course_num_) sub_course_num_,
  358. SUM(aum.total_give_course_num_) total_give_course_num_,
  359. SUM(aum.sub_give_course_num_) sub_give_course_num_
  360. FROM activity_user_mapper aum
  361. LEFT JOIN sys_user su ON su.id_ = aum.user_id_
  362. LEFT JOIN organization o ON o.id_ = su.organ_id_
  363. WHERE aum.return_fee_ = 0 AND aum.activity_id_ = #{activityId}
  364. <if test="search != null and search != ''">
  365. AND (aum.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
  366. </if>
  367. <if test="organId != null and organId != ''">
  368. AND FIND_IN_SET(su.organ_id_,#{organId})
  369. </if>
  370. GROUP BY aum.user_id_
  371. <include refid="global.limit"/>
  372. </select>
  373. <select id="getStudentNoMapperInfo" resultType="Integer">
  374. SELECT CASE WHEN aum.give_practice_flag_ = 1 THEN vga.give_course_num_ ELSE 0 END total_num_
  375. FROM activity_user_mapper aum
  376. LEFT JOIN vip_group_activity vga ON vga.id_ = aum.activity_id_
  377. WHERE aum.return_fee_ = 0 AND aum.user_id_ = #{userId} AND aum.activity_id_ = #{activityId}
  378. GROUP BY aum.user_id_
  379. </select>
  380. <select id="exportStudentSubCourse" resultType="com.ym.mec.biz.dal.dto.ExportStudentSubCourse">
  381. select
  382. t.user_id_ as userId,
  383. su.username_ as username,
  384. t.activity_id_ as activityId,
  385. o.name_ as organizationName,
  386. vga.name_ as activityName,
  387. sum(if(t.vip_flag_ = 1 || t.practice_flag_ = 1 ,1,0)) as subCourseNum,
  388. sum(if(t.give_vip_flag_ = 1 || t.give_practice_flag_ = 1,1,0)) as subGiveCourseNum
  389. from activity_user_mapper t
  390. left join vip_group_activity vga on t.activity_id_ = vga.id_
  391. left join sys_user su on t.user_id_ = su.id_
  392. left join organization o on su.organ_id_ = o.id_
  393. where t.tenant_id_ = #{tenantId} and t.return_fee_ = 0
  394. and (t.vip_flag_ = 1 or t.give_vip_flag_ = 1 or t.practice_flag_ = 1 or t.give_practice_flag_ = 1)
  395. <if test="organId != null">
  396. AND FIND_IN_SET(su.organ_id_,#{organId})
  397. </if>
  398. group by t.user_id_ , t.activity_id_
  399. </select>
  400. <resultMap id="CourseFormDto" type="com.ym.mec.biz.dal.dto.CourseFormDto">
  401. <result property="id" column="id_"/>
  402. <result property="name" column="name_"/>
  403. <result property="num" column="num_"/>
  404. <result property="studentNum" column="student_num_"/>
  405. </resultMap>
  406. <select id="queryWaitCourseCategory" resultMap="CourseFormDto">
  407. SELECT CASE WHEN vgc.id_ IS NULL THEN '网管课' ELSE vgc.name_ END name_,
  408. CASE WHEN vgc.id_ IS NULL THEN 0 ELSE vgc.id_ END id_,COUNT(DISTINCT aum.user_id_) num_,
  409. CASE WHEN vgc.id_ IS NULL THEN 1 ELSE vgc.student_num_ END student_num_
  410. FROM (select category_id_,user_id_,teacher_id_ from activity_user_mapper aum WHERE aum.sub_course_num_ > 0 AND aum.return_fee_ = 0
  411. UNION ALL
  412. select give_category_id_ category_id_,user_id_,teacher_id_ from activity_user_mapper aum
  413. WHERE aum.sub_give_course_num_ > 0 AND aum.return_fee_ = 0) aum
  414. LEFT JOIN vip_group_category vgc ON aum.category_id_ = vgc.id_
  415. <if test="organIds != null and organIds != ''">
  416. LEFT JOIN sys_user su ON su.id_ = aum.user_id_
  417. </if>
  418. <where>
  419. <if test="userId != null">
  420. AND aum.teacher_id_ = #{userId}
  421. </if>
  422. <if test="organIds != null and organIds != ''">
  423. AND FIND_IN_SET(su.organ_id_,#{organIds})
  424. </if>
  425. </where>
  426. GROUP BY vgc.id_
  427. </select>
  428. <resultMap id="ActivityUserDto" type="com.ym.mec.biz.dal.dto.ActivityUserDto">
  429. <result property="userId" column="user_id_"/>
  430. <result property="username" column="username_"/>
  431. <result property="phone" column="phone_"/>
  432. <result property="subjectName" column="subject_name_"/>
  433. <result property="subjectId" column="subject_id_"/>
  434. <result property="subCourseNum" column="sub_course_num_"/>
  435. </resultMap>
  436. <select id="queryActivityStudentList" resultMap="ActivityUserDto">
  437. SELECT aum.user_id_,su.avatar_,sj.id_ subject_id_,su.username_,su.phone_,sj.name_ subject_name_,SUM(aum.sub_course_num_) sub_course_num_
  438. FROM (SELECT aum.id_,aum.user_id_,aum.sub_course_num_,
  439. aum.single_course_time_,aum.teacher_id_ from activity_user_mapper aum
  440. WHERE aum.sub_course_num_ > 0 AND aum.return_fee_ = 0
  441. <if test="queryInfo.categoryId != null">
  442. AND aum.category_id_ = #{queryInfo.categoryId}
  443. </if>
  444. <if test="queryInfo.categoryId == null">
  445. AND aum.category_id_ IS NULL
  446. </if>
  447. UNION ALL
  448. SELECT aum.id_,aum.user_id_,aum.sub_give_course_num_ sub_course_num_,
  449. aum.give_single_course_time_ single_course_time_,aum.teacher_id_ from activity_user_mapper aum
  450. WHERE aum.sub_give_course_num_ > 0 AND aum.return_fee_ = 0
  451. <if test="queryInfo.categoryId != null">
  452. AND aum.give_category_id_ = #{queryInfo.categoryId}
  453. </if>
  454. <if test="queryInfo.categoryId == null">
  455. AND aum.give_category_id_ IS NULL
  456. </if>
  457. ) aum
  458. LEFT JOIN sys_user su ON su.id_ = aum.user_id_
  459. LEFT JOIN student s ON s.user_id_ = aum.user_id_
  460. LEFT JOIN subject sj ON sj.id_ = s.subject_id_list_
  461. <where>
  462. <if test="queryInfo.search != null and queryInfo.search != ''">
  463. AND (su.id_ = #{queryInfo.search}
  464. OR su.username_ LIKE CONCAT('%',#{queryInfo.search},'%')
  465. OR su.phone_ LIKE CONCAT('%',#{queryInfo.search},'%'))
  466. </if>
  467. <if test="queryInfo.singleCourseTime != null">
  468. AND aum.single_course_time_ = #{queryInfo.singleCourseTime}
  469. </if>
  470. <if test="queryInfo.organIds != null and queryInfo.organIds != ''">
  471. AND FIND_IN_SET(su.organ_id_,#{queryInfo.organIds})
  472. </if>
  473. <if test="queryInfo.subjectIds != null and queryInfo.subjectIds != ''">
  474. AND FIND_IN_SET(sj.id_,#{queryInfo.subjectIds})
  475. </if>
  476. <if test="queryInfo.teacherId != null">
  477. AND aum.teacher_id_ = #{queryInfo.teacherId}
  478. </if>
  479. <if test="queryInfo.studentIds != null and queryInfo.studentIds.size > 0">
  480. AND aum.user_id_ IN
  481. <foreach collection="queryInfo.studentIds" item="studentId" open="(" separator="," close=")">
  482. #{studentId}
  483. </foreach>
  484. </if>
  485. </where>
  486. GROUP BY aum.user_id_
  487. ORDER BY sj.id_ DESC,sub_course_num_ DESC
  488. </select>
  489. <select id="queryActivityCourseTimeList" resultType="java.lang.Integer">
  490. select distinct aum.single_course_time_ from activity_user_mapper aum
  491. left join sys_user su on su.id_ = aum.user_id_
  492. where aum.return_fee_ = 0 and aum.total_course_num_ > 0
  493. <if test="queryInfo.categoryId != null">
  494. AND aum.category_id_ = #{queryInfo.categoryId}
  495. </if>
  496. <if test="queryInfo.categoryId == null">
  497. AND aum.category_id_ IS NULL
  498. </if>
  499. <if test="queryInfo.teacherId != null">
  500. AND aum.teacher_id_ = #{queryInfo.teacherId}
  501. </if>
  502. <if test="queryInfo.organIds != null and queryInfo.organIds != ''">
  503. AND FIND_IN_SET(su.organ_id_,#{queryInfo.organIds})
  504. </if>
  505. union
  506. select distinct aum.give_single_course_time_ from activity_user_mapper aum
  507. left join sys_user su on su.id_ = aum.user_id_
  508. where aum.return_fee_ = 0 and aum.sub_give_course_num_ > 0
  509. <if test="queryInfo.categoryId != null">
  510. AND aum.give_category_id_ = #{queryInfo.categoryId}
  511. </if>
  512. <if test="queryInfo.categoryId == null">
  513. AND aum.give_category_id_ IS NULL
  514. </if>
  515. <if test="queryInfo.teacherId != null">
  516. AND aum.teacher_id_ = #{queryInfo.teacherId}
  517. </if>
  518. <if test="queryInfo.organIds != null and queryInfo.organIds != ''">
  519. AND FIND_IN_SET(su.organ_id_,#{queryInfo.organIds})
  520. </if>
  521. </select>
  522. <select id="findTotalByStudents" resultMap="ActivityUserMapper">
  523. select aum.id_, category_id_,user_id_,sub_course_num_,vip_group_id_, give_vip_group_id_, practice_group_id_,
  524. give_practice_group_id_,actual_price_,sub_no_course_price_
  525. from activity_user_mapper aum
  526. WHERE aum.user_id_ IN
  527. <foreach collection="dto.studentIdList" item="userId" open="(" separator="," close=")">
  528. #{userId}
  529. </foreach>
  530. and aum.single_course_time_ = #{dto.classMinutes} and return_fee_ = 0 and aum.sub_course_num_ > 0
  531. <if test="dto.categoryId != null">
  532. AND aum.category_id_ = #{dto.categoryId}
  533. </if>
  534. <if test="dto.categoryId == null">
  535. AND aum.category_id_ IS NULL
  536. </if>
  537. UNION ALL
  538. select aum.id_,give_category_id_ category_id_, user_id_,sub_give_course_num_ sub_course_num_,vip_group_id_, give_vip_group_id_, practice_group_id_, give_practice_group_id_,0 actual_price_,0 sub_no_course_price_
  539. from activity_user_mapper aum
  540. WHERE aum.user_id_ IN
  541. <foreach collection="dto.studentIdList" item="userId" open="(" separator="," close=")">
  542. #{userId}
  543. </foreach>
  544. and aum.give_single_course_time_ = #{dto.classMinutes} and return_fee_ = 0 and aum.sub_give_course_num_ > 0
  545. <if test="dto.categoryId != null">
  546. AND aum.give_category_id_ = #{dto.categoryId}
  547. </if>
  548. <if test="dto.categoryId == null">
  549. AND aum.give_category_id_ IS NULL
  550. </if>
  551. </select>
  552. <select id="findByStudents" resultMap="ActivityUserMapper">
  553. select * from activity_user_mapper aum
  554. WHERE aum.user_id_ IN
  555. <foreach collection="studentIdList" item="userId" open="(" separator="," close=")">
  556. #{userId}
  557. </foreach>
  558. and aum.single_course_time_ = #{classMinutes} and return_fee_ = 0 and aum.sub_course_num_ > 0
  559. <if test="categoryId != null">
  560. AND aum.category_id_ = #{categoryId}
  561. </if>
  562. <if test="categoryId == null">
  563. AND aum.category_id_ IS NULL
  564. </if>
  565. </select>
  566. <select id="findByStudents1" resultMap="ActivityUserMapper">
  567. select * from activity_user_mapper aum
  568. WHERE aum.user_id_ IN
  569. <foreach collection="studentIdList" item="userId" open="(" separator="," close=")">
  570. #{userId}
  571. </foreach>
  572. and aum.give_single_course_time_ = #{classMinutes} and return_fee_ = 0 and aum.sub_give_course_num_ > 0
  573. <if test="categoryId != null">
  574. AND aum.give_category_id_ = #{categoryId}
  575. </if>
  576. <if test="categoryId == null">
  577. AND aum.give_category_id_ IS NULL
  578. </if>
  579. </select>
  580. <select id="findByIds" resultMap="ActivityUserMapper">
  581. SELECT * FROM activity_user_mapper aum WHERE FIND_IN_SET(aum.id_,#{activityUserMapperIds})
  582. </select>
  583. <resultMap id="ActivityUserMapperDetailDto" type="com.ym.mec.biz.dal.dto.ActivityUserMapperDetailDto" extends="ActivityUserMapper">
  584. <result property="organId" column="organ_id_"/>
  585. </resultMap>
  586. <select id="queryDetailPage" resultMap="ActivityUserMapperDetailDto">
  587. select aum.*,su.organ_id_ from activity_user_mapper aum
  588. left join sys_user su ON su.id_ = aum.user_id_
  589. <include refid="queryDetailPageSql"/>
  590. ORDER BY aum.id_ DESC
  591. <include refid="global.limit"/>
  592. </select>
  593. <sql id="queryDetailPageSql">
  594. <where>
  595. <if test="search != null and search != ''">
  596. AND (aum.activity_id_ = #{search} OR aum.add_memo_ LIKE CONCAT('%',#{search},'%'))
  597. </if>
  598. <if test="organId != null and organId != ''">
  599. AND FIND_IN_SET(su.organ_id_,#{organId})
  600. </if>
  601. <if test="returnFee != null">
  602. AND aum.return_fee_ = #{returnFee}
  603. </if>
  604. <if test="returnFee != null">
  605. AND aum.return_fee_ = #{returnFee}
  606. </if>
  607. <if test="hasSubCourse != null and hasSubCourse == true">
  608. and (aum.sub_course_num_ > 0 or aum.sub_give_course_num_ > 0)
  609. </if>
  610. <if test="hasSubCourse != null and hasSubCourse == false">
  611. and aum.sub_course_num_ &lt;= 0 and aum.sub_give_course_num_ &lt;= 0
  612. </if>
  613. </where>
  614. </sql>
  615. <select id="countDetailPage" resultType="java.lang.Integer">
  616. select COUNT(aum.id_) from activity_user_mapper aum
  617. left join sys_user su ON su.id_ = aum.user_id_
  618. <include refid="queryDetailPageSql"/>
  619. </select>
  620. </mapper>