CloudTeacherOrderMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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.ym.mec.biz.dal.dao.CloudTeacherOrderDao">
  4. <resultMap id="CloudTeacherOrder" type="com.ym.mec.biz.dal.entity.CloudTeacherOrder">
  5. <!--@mbg.generated-->
  6. <!--@Table cloud_teacher_order-->
  7. <id column="id_" property="id"/>
  8. <result column="organ_id_" property="organId"/>
  9. <result column="student_id_" property="studentId"/>
  10. <result column="type_" property="type"/>
  11. <result column="level_" property="level"/>
  12. <result column="time_" property="time"/>
  13. <result column="amount_" property="amount"/>
  14. <result column="refund_amount_" property="refundAmount"/>
  15. <result column="status_" property="status"/>
  16. <result column="start_time_" property="startTime"/>
  17. <result column="end_time_" property="endTime"/>
  18. <result column="order_id_" property="orderId"/>
  19. <result column="remark_" property="remark"/>
  20. <result column="active_remark_" property="activeRemark"/>
  21. <result column="version_" property="version"/>
  22. <result column="create_time_" property="createTime"/>
  23. <result column="update_time_" property="updateTime"/>
  24. <result column="music_group_id_" property="musicGroupId"/>
  25. <result column="tenant_id_" property="tenantId" />
  26. </resultMap>
  27. <resultMap type="com.ym.mec.biz.dal.dto.CloudTeacherOrderDto" id="CloudTeacherOrderDto">
  28. <id column="id_" property="cloudTeacherOrder.id"/>
  29. <result column="organ_id_" property="cloudTeacherOrder.organId"/>
  30. <result column="student_id_" property="cloudTeacherOrder.studentId"/>
  31. <result column="type_" property="cloudTeacherOrder.type"/>
  32. <result column="level_" property="cloudTeacherOrder.level"/>
  33. <result column="time_" property="cloudTeacherOrder.time"/>
  34. <result column="amount_" property="cloudTeacherOrder.amount"/>
  35. <result column="refund_amount_" property="cloudTeacherOrder.refundAmount"/>
  36. <result column="status_" property="cloudTeacherOrder.status"/>
  37. <result column="start_time_" property="cloudTeacherOrder.startTime"/>
  38. <result column="end_time_" property="cloudTeacherOrder.endTime"/>
  39. <result column="order_id_" property="cloudTeacherOrder.orderId"/>
  40. <result column="trans_status_" property="studentPaymentOrder.status"/>
  41. <result column="expect_amount_" property="studentPaymentOrder.expectAmount"/>
  42. <result column="pay_time_" property="studentPaymentOrder.payTime"/>
  43. <result column="order_create_time_" property="studentPaymentOrder.createTime"/>
  44. <result column="name_" property="memberRankSetting.name"/>
  45. <result column="icon_" property="memberRankSetting.icon"/>
  46. <result column="music_group_id_" property="studentPaymentOrder.musicGroupId"/>
  47. </resultMap>
  48. <select id="get" resultMap="CloudTeacherOrder">
  49. <!--@mbg.generated-->
  50. select * from cloud_teacher_order where id_ = #{id}
  51. </select>
  52. <delete id="delete">
  53. <!--@mbg.generated-->
  54. delete from cloud_teacher_order
  55. where id_ = #{id}
  56. </delete>
  57. <insert id="insert" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.biz.dal.entity.CloudTeacherOrder"
  58. useGeneratedKeys="true">
  59. <!--@mbg.generated-->
  60. insert into cloud_teacher_order (organ_id_,student_id_, type_, level_, time_, amount_, refund_amount_, status_,
  61. order_id_,start_time_,end_time_,remark_, create_time_, update_time_,music_group_id_,active_remark_,tenant_id_)
  62. values (#{organId},#{studentId}, #{type},#{level}, #{time}, #{amount}, #{refundAmount},
  63. #{status},#{orderId},#{startTime},#{endTime}, #{remark}, NOW(), NOW(),#{musicGroupId},#{activeRemark},#{tenantId})
  64. </insert>
  65. <update id="update" parameterType="com.ym.mec.biz.dal.entity.CloudTeacherOrder">
  66. <!--@mbg.generated-->
  67. update cloud_teacher_order
  68. <set>
  69. <if test="activeRemark != null">
  70. active_remark_ = #{activeRemark},
  71. </if>
  72. <if test="musicGroupId != null">
  73. music_group_id_ = #{musicGroupId},
  74. </if>
  75. <if test="organId != null">
  76. organ_id_ = #{organId},
  77. </if>
  78. <if test="studentId != null">
  79. student_id_ = #{studentId},
  80. </if>
  81. <if test="type != null">
  82. type_ = #{type},
  83. </if>
  84. <if test="level != null">
  85. level_ = #{level},
  86. </if>
  87. <if test="time != null">
  88. time_ = #{time},
  89. </if>
  90. <if test="amount != null">
  91. amount_ = #{amount},
  92. </if>
  93. <if test="refundAmount != null">
  94. refund_amount_ = #{refundAmount},
  95. </if>
  96. <if test="status != null">
  97. status_ = #{status},
  98. </if>
  99. <if test="startTime != null">
  100. start_time_ = #{startTime},
  101. </if>
  102. <if test="endTime != null">
  103. end_time_ = #{endTime},
  104. </if>
  105. <if test="orderId != null">
  106. order_id_ = #{orderId},
  107. </if>
  108. <if test="remark != null">
  109. remark_ = #{remark},
  110. </if>
  111. version_ = version_+1,
  112. update_time_ = NOW(),
  113. </set>
  114. where id_ = #{id} AND version_ = #{version} and tenant_id_ = #{tenantId}
  115. </update>
  116. <update id="updateOrderStatusOK">
  117. update cloud_teacher_order set status_ = 2 where order_id_ = (#{orderId})
  118. </update>
  119. <update id="updateOrderId">
  120. update cloud_teacher_order
  121. set order_id_ = #{orderId} , pay_amount_ = #{amount}
  122. where id_ = #{cloudTeacherOrderId}
  123. </update>
  124. <!-- 全查询 -->
  125. <select id="findAll" resultMap="CloudTeacherOrder">
  126. SELECT *
  127. FROM cloud_teacher_order where tenant_id_ = #{tenantId}
  128. </select>
  129. <!-- 分页查询 -->
  130. <select id="queryPage" resultMap="CloudTeacherOrderDto" parameterType="map">
  131. SELECT cto.*,spo.status_ trans_status_,spo.expect_amount_,spo.pay_time_,spo.create_time_ order_create_time_,mrs.name_,mrs.icon_ FROM cloud_teacher_order cto
  132. left join student_payment_order spo on cto.order_id_ = spo.id_
  133. left join member_rank_setting mrs on mrs.id_ = cto.level_
  134. where spo.type_ = 'MEMBER'
  135. <if test="status != null">
  136. and cto.status_ = #{status}
  137. </if>
  138. <if test="studentId != null">
  139. and cto.student_id_ = #{studentId}
  140. </if>
  141. <if test="tenantId != null">
  142. and cto.tenant_id_ = #{tenantId}
  143. </if>
  144. order by spo.pay_time_ desc,spo.id_ desc
  145. <include refid="global.limit"/>
  146. </select>
  147. <!-- 查询当前表的总记录数 -->
  148. <select id="queryCount" resultType="int">
  149. SELECT COUNT(cto.id_)
  150. FROM cloud_teacher_order cto LEFT JOIN student_payment_order spo on cto.order_id_ = spo.id_
  151. where spo.type_ = 'MEMBER'
  152. <if test="status != null">
  153. and cto.status_ = #{status}
  154. </if>
  155. <if test="studentId != null">
  156. and cto.student_id_ = #{studentId}
  157. </if>
  158. <if test="tenantId != null">
  159. and cto.tenant_id_ = #{tenantId}
  160. </if>
  161. order by cto.create_time_ desc
  162. </select>
  163. <select id="getNoStartCloudTeacherOrder" resultMap="CloudTeacherOrder">
  164. SELECT cto.*
  165. FROM cloud_teacher_order cto
  166. WHERE cto.status_ = 1 and cto.tenant_id_ = #{tenantId}
  167. </select>
  168. <select id="getStudentCloudTeacherOrders" resultMap="CloudTeacherOrder">
  169. SELECT *
  170. FROM cloud_teacher_order
  171. WHERE order_id_ IN (
  172. SELECT id_
  173. FROM student_payment_order
  174. WHERE status_ = 'SUCCESS'
  175. AND user_id_ IN
  176. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  177. #{studentId}
  178. </foreach>
  179. GROUP BY user_id_
  180. )
  181. AND student_id_ IN
  182. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  183. #{studentId}
  184. </foreach>
  185. AND status_ IN (1,2)
  186. </select>
  187. <select id="getStudentCloudTeacherOrder" resultMap="CloudTeacherOrder">
  188. SELECT *
  189. FROM cloud_teacher_order
  190. WHERE student_id_ = #{studentId}
  191. <if test="musicGroupId != null and musicGroupId != ''">
  192. AND music_group_id_ = #{musicGroupId}
  193. </if>
  194. AND status_ IN (1, 2)
  195. </select>
  196. <select id="queryByOrderId" resultMap="CloudTeacherOrder">
  197. SELECT cto.* FROM cloud_teacher_order cto
  198. WHERE order_id_ = #{orderId}
  199. </select>
  200. <select id="queryOrderInfoByOrderId" resultMap="CloudTeacherOrderDto">
  201. SELECT cto.*,spo.status_ trans_status_,spo.expect_amount_,mrs.name_,mrs.icon_ FROM cloud_teacher_order cto
  202. left join student_payment_order spo on cto.order_id_ = spo.id_
  203. left join member_rank_setting mrs on mrs.id_ = cto.level_
  204. where spo.type_ = 'MEMBER' and order_id_ = #{orderId}
  205. </select>
  206. <select id="queryNoStartByUserIds" resultType="java.util.Map">
  207. SELECT student_id_ 'key',create_time_ 'value' FROM cloud_teacher_order
  208. WHERE status_ = 1
  209. <if test="userIds != null and userIds.size > 0">
  210. AND student_id_ IN
  211. <foreach collection="userIds" separator="," item="userId" open="(" close=")">
  212. #{userId}
  213. </foreach>
  214. </if>
  215. <if test="isMusicMember = 'true'">
  216. AND music_group_id_ IS NOT NULL
  217. </if>
  218. GROUP BY student_id_
  219. </select>
  220. <resultMap id="CloudTeacherActiveTargetDetailDto" type="com.ym.mec.biz.dal.dto.CloudTeacherActiveTargetDetailDto">
  221. <result property="userId" column="student_id_"/>
  222. <result property="username" column="username_"/>
  223. <result property="amount" column="amount_"/>
  224. <result property="remark" column="remark_"/>
  225. <result property="cooperationName" column="cooperation_name_"/>
  226. <result property="musicGroupName" column="music_group_name_"/>
  227. <result property="chargeType" column="charge_type_name_"/>
  228. <result property="subjectName" column="subject_name_"/>
  229. <result property="currentGradeNum" column="current_grade_num_"/>
  230. <result property="teacherName" column="teacher_name_"/>
  231. <result property="createTime" column="create_time_"/>
  232. </resultMap>
  233. <select id="queryCloudTeacherActiveDetail" resultMap="CloudTeacherActiveTargetDetailDto">
  234. SELECT su.username_,cto.remark_,cto.amount_,cto.student_id_,GROUP_CONCAT(DISTINCT co.name_) cooperation_name_,
  235. GROUP_CONCAT(DISTINCT mg.name_) music_group_name_,GROUP_CONCAT(DISTINCT ct.name_) charge_type_name_,
  236. sj.name_ subject_name_,st.current_grade_num_,sus.real_name_ teacher_name_,cto.create_time_
  237. FROM cloud_teacher_order cto
  238. LEFT JOIN sys_user su ON su.id_ = cto.student_id_
  239. LEFT JOIN student_registration sr ON sr.user_id_ = cto.student_id_ AND sr.music_group_status_ = 'NORMAL'
  240. LEFT JOIN music_group mg ON mg.id_ = sr.music_group_id_ AND mg.status_ = 'PROGRESS'
  241. LEFT JOIN cooperation_organ co ON co.id_ = mg.cooperation_organ_id_
  242. LEFT JOIN charge_type ct ON ct.id_ = mg.charge_type_id_
  243. LEFT JOIN student st ON st.user_id_ = cto.student_id_
  244. LEFT JOIN sys_user sus ON sus.id_ = st.teacher_id_
  245. LEFT JOIN `subject` sj ON sj.id_ = st.subject_id_list_
  246. <include refid="queryCloudTeacherActiveDetailSql"/>
  247. GROUP BY cto.id_
  248. ORDER BY cto.id_ DESC
  249. <include refid="global.limit"/>
  250. </select>
  251. <select id="countCloudTeacherActiveDetail" resultType="int">
  252. SELECT COUNT(DISTINCT cto.id_)
  253. FROM cloud_teacher_order cto
  254. LEFT JOIN sys_user su ON su.id_ = cto.student_id_
  255. LEFT JOIN student st ON st.user_id_ = cto.student_id_
  256. LEFT JOIN student_registration sr ON sr.user_id_ = cto.student_id_ AND sr.music_group_status_ = 'NORMAL'
  257. LEFT JOIN music_group mg ON mg.id_ = sr.music_group_id_ AND mg.status_ = 'PROGRESS'
  258. <include refid="queryCloudTeacherActiveDetailSql"/>
  259. </select>
  260. <select id="queryActiveOrderPage" resultType="string">
  261. SELECT GROUP_CONCAT(DISTINCT cto.remark_) FROM cloud_teacher_order cto
  262. LEFT JOIN student_payment_order spo ON spo.id_ = cto.order_id_
  263. WHERE spo.status_ = 'SUCCESS' AND cto.active_remark_ = #{activeRemark}
  264. AND cto.student_id_ = #{userId} AND cto.remark_ != '单月'
  265. <if test="remark != null and remark != ''">
  266. AND cto.remark_ = #{remark}
  267. </if>
  268. </select>
  269. <select id="getStudentIds" resultType="java.lang.Integer">
  270. SELECT DISTINCT student_id_ FROM cloud_teacher_order WHERE active_remark_ IS NULL AND status_ != 0 and tenant_id_ = #{tenantId}
  271. </select>
  272. <select id="queryActiveAmountMap" resultType="java.util.Map">
  273. SELECT student_id_ 'key',SUM(amount_) 'value' FROM cloud_teacher_order
  274. WHERE status_ != 0 AND active_remark_ = '202109'
  275. <if test="studentIds != null and studentIds.size > 0">
  276. AND student_id_ IN
  277. <foreach collection="studentIds" separator="," item="userId" open="(" close=")">
  278. #{userId}
  279. </foreach>
  280. </if>
  281. GROUP BY student_id_
  282. </select>
  283. <select id="queryInactive" resultType="com.ym.mec.biz.dal.entity.CloudTeacherStudent">
  284. select
  285. cto.id_ as cloudTeacherOrderId,
  286. cto.student_id_ as studentId,
  287. cto.type_ as type,
  288. case cto.type_
  289. when 1 then '天'
  290. when 2 then '月'
  291. when 3 then '季'
  292. when 4 then '半年'
  293. when 5 then '年'
  294. else ''
  295. end as typeName,
  296. cto.time_ as time,
  297. sj.id_ as subject,
  298. sj.name_ as subjectLabel,
  299. u.tenant_id_ as tenantId,
  300. u.username_ as name,
  301. u.phone_ as phone,
  302. org.name_ as organName,
  303. mg.id_ as musicGroupId,
  304. mg.name_ as musicGroupName,
  305. coo.name_ as cooperationOrganName
  306. from cloud_teacher_order cto
  307. left join student s on cto.student_id_ = s.user_id_
  308. left join sys_user u on cto.student_id_ = u.id_
  309. left join subject sj on s.subject_id_list_ = sj.id_
  310. left join student_registration sr on cto.student_id_ = sr.user_id_
  311. left join music_group mg on sr.music_group_id_ = mg.id_
  312. left join cooperation_organ coo on mg.cooperation_organ_id_ = coo.id_
  313. left join organization org on mg.organ_id_ = org.id_
  314. <where>
  315. cto.status_ = #{status} AND sr.music_group_status_ = 'NORMAL' AND mg.status_ = 'PROGRESS'
  316. <if test="queryCondition != nul and queryCondition != ''">
  317. AND (u.username_ LIKE CONCAT('%', #{queryCondition}, '%') or u.phone_ = #{queryCondition} or u.id_ = #{queryCondition})
  318. </if>
  319. <if test="subjectId">
  320. AND (s.subject_id_list_ = #{subjectId})
  321. </if>
  322. </where>
  323. <include refid="global.limit"/>
  324. </select>
  325. <select id="findInactiveCount" resultType="java.lang.Integer">
  326. select count(1) from cloud_teacher_order cto
  327. left join student s on cto.student_id_ = s.user_id_
  328. left join sys_user u on cto.student_id_ = u.id_
  329. left join subject sj on s.subject_id_list_ = sj.id_
  330. left join student_registration sr on s.user_id_ = sr.user_id_
  331. left join music_group mg on sr.music_group_id_ = mg.id_
  332. left join cooperation_organ coo on mg.cooperation_organ_id_ = coo.id_
  333. left join organization org on mg.organ_id_ = org.id_
  334. <where>
  335. cto.status_ = #{status} AND sr.music_group_status_ = 'NORMAL' AND mg.status_ = 'PROGRESS'
  336. <if test="queryCondition != nul and queryCondition != ''">
  337. AND (u.username_ LIKE CONCAT('%', #{queryCondition}, '%') or u.phone_ = #{queryCondition} or u.id_ = #{queryCondition})
  338. </if>
  339. <if test="subjectId">
  340. AND (s.subject_id_list_ = #{subjectId})
  341. </if>
  342. </where>
  343. </select>
  344. <select id="findRecordCount" resultType="java.lang.Integer">
  345. SELECT count(1) FROM cloud_teacher_order cto
  346. LEFT JOIN tenant_order_record tor ON tor.id_ = cto.order_id_
  347. LEFT JOIN student s ON cto.student_id_ = s.user_id_
  348. LEFT JOIN sys_user u ON cto.student_id_ = u.id_
  349. LEFT JOIN SUBJECT sj ON s.subject_id_list_ = sj.id_
  350. LEFT JOIN student_registration sr ON cto.student_id_ = sr.user_id_
  351. LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
  352. <where>
  353. cto.status_ = 2 AND sr.music_group_status_ = 'NORMAL' AND mg.status_ = 'PROGRESS' and tor.order_no_ is not null
  354. AND cto.type_ > 1
  355. </where>
  356. </select>
  357. <select id="queryRecord" resultType="com.ym.mec.biz.dal.entity.CloudTeacherStudent">
  358. SELECT
  359. tor.order_no_ as orderNo,
  360. cto.id_ AS cloudTeacherOrderId,
  361. cto.student_id_ AS studentId,
  362. cto.type_ AS type,
  363. CASE cto.type_ WHEN 1 THEN '天'
  364. WHEN 2 THEN '月'
  365. WHEN 3 THEN '季'
  366. WHEN 4 THEN '半年'
  367. WHEN 5 THEN '年' ELSE ''
  368. END AS typeName,
  369. cto.time_ AS time,
  370. sj.id_ AS SUBJECT,
  371. sj.name_ AS subjectName,
  372. u.tenant_id_ AS tenantId,
  373. u.username_ AS NAME,
  374. u.phone_ AS phone
  375. FROM
  376. cloud_teacher_order cto
  377. LEFT JOIN tenant_order_record tor ON tor.id_ = cto.order_id_
  378. LEFT JOIN student s ON cto.student_id_ = s.user_id_
  379. LEFT JOIN sys_user u ON cto.student_id_ = u.id_
  380. LEFT JOIN SUBJECT sj ON s.subject_id_list_ = sj.id_
  381. LEFT JOIN student_registration sr ON cto.student_id_ = sr.user_id_
  382. LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
  383. <where>
  384. cto.status_ = 2 AND sr.music_group_status_ = 'NORMAL' AND mg.status_ = 'PROGRESS' and tor.order_no_ is not null
  385. AND cto.type_ > 1
  386. </where>
  387. <include refid="global.limit"/>
  388. </select>
  389. <sql id="queryCloudTeacherActiveDetailSql">
  390. <where>
  391. cto.status_ != 0 AND cto.active_remark_ = '202109'
  392. <if test="organIds != null and organIds != ''">
  393. AND FIND_IN_SET(su.organ_id_,#{organIds})
  394. </if>
  395. <if test="search != null and search != ''">
  396. AND (su.id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR mg.id_ LIKE CONCAT('%',#{search},'%'))
  397. </if>
  398. <if test="chargeType != null">
  399. AND mg.charge_type_id_ = #{chargeType}
  400. </if>
  401. <if test="subjectId != null">
  402. AND st.subject_id_list_ = #{subjectId}
  403. </if>
  404. <if test="teacherId != null">
  405. AND st.teacher_id_ = #{teacherId}
  406. </if>
  407. <if test="tenantId != null">
  408. AND cto.tenant_id_ = #{tenantId}
  409. </if>
  410. <if test="remarkType != null and remarkType != ''">
  411. AND cto.remark_ = #{remarkType}
  412. </if>
  413. </where>
  414. </sql>
  415. </mapper>