StudentStatisticsMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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.StudentStatisticsDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.StudentStatistics" id="StudentStatistics">
  9. <result column="id_" property="id" />
  10. <result column="user_id_" property="userId" />
  11. <result column="teacher_id_" property="teacherId" />
  12. <result column="teacher_name_" property="teacherName" />
  13. <result column="music_director_id_" property="musicDirectorId" />
  14. <result column="music_director_name_" property="musicDirectorName" />
  15. <result column="total_course_num_" property="totalCourseNum" />
  16. <result column="over_course_num_" property="overCourseNum" />
  17. <result column="sub_course_num_" property="subCourseNum" />
  18. <result column="no_schedule_num_" property="noScheduleNum" />
  19. <result column="first_course_time_" property="firstCourseTime" />
  20. <result column="last_course_time_" property="lastCourseTime" />
  21. <result column="lately_course_consumer_" property="latelyCourseConsumer" />
  22. <result column="lately_year_course_consumer_" property="latelyYearCourseConsumer" />
  23. <result column="visit_num_" property="visitNum" />
  24. <result column="last_visit_status_" property="lastVisitStatus" />
  25. <result column="visit_reason_" property="visitReason" />
  26. <result column="last_visit_time_" property="lastVisitTime" />
  27. <result column="not_start_course_fee_" property="notStartCourseFee" />
  28. <result column="no_course_fee_" property="noCourseFee" />
  29. <result column="preCourseFee" property="preCourseFee" />
  30. <result column="first_order_time_" property="firstOrderTime" />
  31. <result column="last_order_time_" property="lastOrderTime" />
  32. <result column="order_num_" property="orderNum" />
  33. <result column="group_type_" property="groupType" />
  34. </resultMap>
  35. <!-- 根据主键查询一条记录 -->
  36. <select id="get" resultMap="StudentStatistics" >
  37. SELECT * FROM student_statistics WHERE id_ = #{id}
  38. </select>
  39. <!-- 全查询 -->
  40. <select id="findAll" resultMap="StudentStatistics">
  41. SELECT * FROM student_statistics ORDER BY id_
  42. </select>
  43. <!-- 向数据库增加一条记录 -->
  44. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentStatistics" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  45. INSERT INTO student_statistics (id_,user_id_,teacher_id_,teacher_name_,music_director_id_,
  46. music_director_name_,total_course_num_,over_course_num_,sub_course_num_,
  47. no_schedule_num_,first_course_time_,last_course_time_,lately_course_consumer_,
  48. visit_num_,last_visit_status_,visit_reason_,last_visit_time_,not_start_course_fee_,no_course_fee_,first_order_time_,
  49. last_order_time_,order_num_,group_type_)
  50. VALUES(#{id},#{userId},#{teacherId},#{teacherName},#{musicDirectorId},#{musicDirectorName},
  51. #{totalCourseNum},#{overCourseNum},#{subCourseNum},#{noScheduleNum},#{firstCourseTime},#{lastCourseTime},
  52. #{latelyCourseConsumer},#{visitNum},#{lastVisitStatus},#{visitReason},#{lastVisitTime},#{notStartCourseFee},#{noCourseFee},#{firstOrderTime},
  53. #{lastOrderTime},#{orderNum},#{groupType})
  54. </insert>
  55. <!-- 根据主键查询一条记录 -->
  56. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentStatistics">
  57. UPDATE student_statistics <set>
  58. <if test="overCourseNum != null">
  59. over_course_num_ = #{overCourseNum},
  60. </if>
  61. <if test="latelyCourseConsumer != null">
  62. lately_course_consumer_ = #{latelyCourseConsumer},
  63. </if>
  64. <if test="lastCourseTime != null">
  65. last_course_time_ = #{lastCourseTime},
  66. </if>
  67. <if test="totalCourseNum != null">
  68. total_course_num_ = #{totalCourseNum},
  69. </if>
  70. <if test="musicDirectorName != null">
  71. music_director_name_ = #{musicDirectorName},
  72. </if>
  73. <if test="visitNum != null">
  74. visit_num_ = #{visitNum},
  75. </if>
  76. <if test="teacherName != null">
  77. teacher_name_ = #{teacherName},
  78. </if>
  79. <if test="subCourseNum != null">
  80. sub_course_num_ = #{subCourseNum},
  81. </if>
  82. <if test="lastVisitStatus != null">
  83. last_visit_status_ = #{lastVisitStatus},
  84. </if>
  85. <if test="lastVisitTime != null">
  86. last_visit_time_ = #{lastVisitTime},
  87. </if>
  88. <if test="teacherId != null">
  89. teacher_id_ = #{teacherId},
  90. </if>
  91. <if test="musicDirectorId != null">
  92. music_director_id_ = #{musicDirectorId},
  93. </if>
  94. <if test="lastOrderTime != null">
  95. last_order_time_ = #{lastOrderTime},
  96. </if>
  97. <if test="firstOrderTime != null">
  98. first_order_time_ = #{firstOrderTime},
  99. </if>
  100. <if test="orderNum != null">
  101. order_num_ = #{orderNum},
  102. </if>
  103. <if test="groupType != null">
  104. group_type_ = #{groupType},
  105. </if>
  106. <if test="visitReason != null">
  107. visit_reason_ = #{visitReason},
  108. </if>
  109. <if test="notStartCourseFee != null">
  110. not_start_course_fee_ = #{notStartCourseFee},
  111. </if>
  112. <if test="noCourseFee != null">
  113. no_course_fee_ = #{noCourseFee},
  114. </if>
  115. <if test="noScheduleNum != null">
  116. no_schedule_num_ = #{noScheduleNum},
  117. </if>
  118. <if test="firstCourseTime != null">
  119. first_course_time_ = #{firstCourseTime},
  120. </if>
  121. </set> WHERE id_ = #{id}
  122. </update>
  123. <update id="updateTeacherAndEdu">
  124. SELECT updateTeacherAndEdu()
  125. </update>
  126. <update id="updateCourseNum">
  127. SELECT updateCourseNum()
  128. </update>
  129. <update id="updateNoCourseNum">
  130. SELECT updateNoCourseNum()
  131. </update>
  132. <update id="updateNotStartCourseFee">
  133. SELECT updateNotStartCourseFee()
  134. </update>
  135. <update id="updateNoCourseFee">
  136. SELECT updateNoCourseFee()
  137. </update>
  138. <update id="updateFirstAndLastCourseTime">
  139. SELECT updateFirstAndLastCourseTime()
  140. </update>
  141. <update id="updateNormalGroupNum">
  142. SELECT updateNormalGroupNum()
  143. </update>
  144. <!-- 根据主键删除一条记录 -->
  145. <delete id="delete" >
  146. DELETE FROM student_statistics WHERE id_ = #{id}
  147. </delete>
  148. <!-- 分页查询 -->
  149. <select id="queryPage" resultMap="StudentStatistics" parameterType="map">
  150. SELECT * FROM student_statistics ORDER BY id_ <include refid="global.limit"/>
  151. </select>
  152. <!-- 查询当前表的总记录数 -->
  153. <select id="queryCount" resultType="int">
  154. SELECT COUNT(*) FROM student_statistics
  155. </select>
  156. <resultMap id="StudentStatisticsDto" type="com.ym.mec.biz.dal.dto.StudentStatisticsDto" extends="StudentStatistics">
  157. <association property="studentBasicInfo" javaType="com.ym.mec.biz.dal.entity.StudentBasicInfo">
  158. <result column="user_id_" property="userId" />
  159. <result column="user_name_" property="userName" />
  160. <result column="phone_" property="phone" />
  161. <result column="subject_id_" property="subjectId" />
  162. <result column="subject_name_" property="subjectName" />
  163. <result column="grade_" property="grade" />
  164. <result column="organ_id_" property="organId" />
  165. <result column="organ_name_" property="organName" />
  166. <result column="cooperation_organ_id_" property="cooperationOrganId" />
  167. <result column="cooperation_organ_name_" property="cooperationOrganName" />
  168. <result column="subject_teacher_id_" property="subjectTeacherId" />
  169. <result column="subject_teacher_name_" property="subjectTeacherName" />
  170. </association>
  171. </resultMap>
  172. <sql id="queryStatisticsSql">
  173. <where>
  174. <if test="search != null and search != ''">
  175. AND (sbi.user_id_ = #{search} OR sbi.user_name_ LIKE CONCAT('%',#{search},'%'))
  176. </if>
  177. <if test="subjectId != null">
  178. AND sbi.subject_id_ = #{subjectId}
  179. </if>
  180. <if test="studentStatus != null and studentStatus != ''">
  181. <if test="studentStatus == 'NORMAL'">
  182. AND (ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0)
  183. </if>
  184. <if test="studentStatus == 'SLEEPY'">
  185. AND ss.over_course_num_ > 0 AND ss.sub_course_num_ > 0 AND ss.lately_year_course_consumer_ &lt;= 0
  186. </if>
  187. </if>
  188. <if test="feedbackType != null and feedbackType != ''">
  189. AND ss.last_visit_status_ = #{feedbackType}
  190. </if>
  191. <if test="latelyCourseConsumer != null">
  192. AND ss.lately_course_consumer_ = #{latelyCourseConsumer}
  193. </if>
  194. <if test="latelyYearCourseConsumer != null">
  195. AND ss.lately_year_course_consumer_ = #{latelyYearCourseConsumer}
  196. </if>
  197. <if test="visitNum != null">
  198. AND ss.visit_num_ = #{visitNum}
  199. </if>
  200. <if test="teacherId != null">
  201. AND ss.teacher_id_ = #{teacherId}
  202. </if>
  203. <if test="subjectTeacherId != null">
  204. AND sbi.subject_teacher_id_ = #{subjectTeacherId}
  205. </if>
  206. <if test="musicDirectorId != null">
  207. AND ss.music_director_id_ = #{musicDirectorId}
  208. </if>
  209. <if test="courseConsumerError != null and courseConsumerError == 'true'">
  210. AND ss.lately_course_consumer_ &lt; 4
  211. </if>
  212. <if test="firstCourseStartTime != null">
  213. AND ss.first_course_time_ >= #{firstCourseStartTime}
  214. </if>
  215. <if test="firstCourseEndTime != null">
  216. AND ss.first_course_time_ &lt;= #{firstCourseEndTime}
  217. </if>
  218. <if test="groupType != null and groupType != ''">
  219. AND ss.group_type_ = #{groupType}
  220. </if>
  221. <if test="organId != null and organId != ''">
  222. AND FIND_IN_SET(sbi.organ_id_,#{organId})
  223. </if>
  224. </where>
  225. </sql>
  226. <select id="countStatistics" resultType="java.lang.Integer">
  227. SELECT COUNT(sbi.id_) FROM student_basic_info sbi
  228. LEFT JOIN student_statistics ss ON ss.user_id_ = sbi.user_id_
  229. <include refid="queryStatisticsSql"/>
  230. </select>
  231. <select id="queryStatistics" resultMap="StudentStatisticsDto">
  232. SELECT *,ss.not_start_course_fee_ + ss.no_course_fee_ preCourseFee FROM student_basic_info sbi
  233. LEFT JOIN student_statistics ss ON ss.user_id_ = sbi.user_id_
  234. <include refid="queryStatisticsSql"/>
  235. <include refid="global.limit"/>
  236. </select>
  237. <resultMap id="StudentStatisticsSumDto" type="com.ym.mec.biz.dal.dto.StudentStatisticsSumDto">
  238. <result property="sleepStudentNum" column="sleepStudentNum"/>
  239. <result property="sleepStudentHasNotSchedule" column="sleepStudentHasNotSchedule"/>
  240. <result property="sleepStudentNoNotSchedule" column="sleepStudentNoNotSchedule"/>
  241. <result property="normalStudentNum" column="normalStudentNum"/>
  242. <result property="normalStudentHasNormalGroupNum" column="normalStudentHasNormalGroupNum"/>
  243. <result property="hasCourseBalanceAndNotSubCourseNum" column="hasCourseBalanceAndNotSubCourseNum"/>
  244. <result property="normalStudentHasNoScheduleNum" column="normalStudentHasNoScheduleNum"/>
  245. <result property="waitRenewNum" column="waitRenewNum"/>
  246. <result property="subCourseNum" column="subCourseNum"/>
  247. <result property="noScheduleNum" column="noScheduleNum"/>
  248. </resultMap>
  249. <select id="studentSmallClassStatisticsSum" resultMap="StudentStatisticsSumDto">
  250. SELECT
  251. COUNT(CASE WHEN ss.over_course_num_ > 0 AND ss.sub_course_num_ > 0 AND ss.lately_year_course_consumer_ &lt;= 0 THEN 1 ELSE NULL END) 'sleepStudentNum',
  252. COUNT(CASE WHEN ss.over_course_num_ > 0 AND ss.sub_course_num_ > 0 AND ss.lately_year_course_consumer_ &lt;= 0 AND ss.no_schedule_num_ > 0 THEN 1 ELSE NULL END) 'sleepStudentHasNotSchedule',
  253. COUNT(CASE WHEN ss.over_course_num_ > 0 AND ss.sub_course_num_ > 0 AND ss.lately_year_course_consumer_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0 THEN 1 ELSE NULL END) 'sleepStudentNoNotSchedule',
  254. COUNT(CASE WHEN (ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0) THEN 1 ELSE NULL END) 'normalStudentNum',
  255. COUNT(CASE WHEN ((ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0)) AND ss.normal_group_num_ > 0 THEN 1 ELSE NULL END) 'normalStudentHasNormalGroupNum',
  256. COUNT(CASE WHEN suca.course_balance_ > 0 AND ss.sub_course_num_ &lt;= 0 THEN 1 ELSE NULL END) 'hasCourseBalanceAndNotSubCourseNum',
  257. COUNT(CASE WHEN ((ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0)) AND ss.no_schedule_num_ > 0 THEN 1 ELSE NULL END) 'normalStudentHasNoScheduleNum',
  258. COUNT(CASE WHEN (ss.no_schedule_num_ + ss.no_schedule_num_) &lt; 4 THEN 1 ELSE NULL END) 'waitRenewNum',
  259. SUM(ss.sub_course_num_) 'subCourseNum',
  260. SUM(ss.no_schedule_num_) 'noScheduleNum'
  261. FROM student_statistics ss
  262. LEFT JOIN sys_user_cash_account suca ON ss.user_id_ = suca.user_id_
  263. WHERE ss.group_type_ = #{groupType}
  264. </select>
  265. <select id="countAddStudentNum" resultType="java.lang.Integer">
  266. SELECT COUNT(extend_info_) FROM (
  267. SELECT extend_info_ FROM index_base_month_data
  268. WHERE data_type_ =
  269. <if test="groupType == 'VIP'">
  270. 'STUDENT_VIP_ORDER_NUM'
  271. </if>
  272. <if test="groupType == 'THEORY'">
  273. 'STUDENT_THEORY_ORDER_NUM'
  274. </if>
  275. <if test="groupType == 'PRACTICE'">
  276. 'STUDENT_PRACTICE_ORDER_NUM'
  277. </if>
  278. AND extend_info_ IS NOT NULL
  279. GROUP BY extend_info_
  280. <if test="startDate != null and startDate != '' and endDate != null and endDate != ''">
  281. HAVING COUNT(CASE WHEN month_ &lt; #{startDate} THEN 1 ELSE NULL END) &lt; 1
  282. AND COUNT(CASE WHEN month_ BETWEEN #{startDate} AND #{endDate} THEN 1 ELSE NULL END) > 0
  283. </if>
  284. )a
  285. </select>
  286. <select id="countRenewStudentNum" resultType="java.lang.Integer">
  287. SELECT COUNT(extend_info_) FROM (
  288. SELECT extend_info_ FROM index_base_month_data
  289. <include refid="dateTypeSql"/>
  290. AND extend_info_ IS NOT NULL
  291. <if test="endDate != null and endDate != ''">
  292. AND month_ &lt;= #{endDate}
  293. </if>
  294. GROUP BY extend_info_
  295. HAVING SUM(total_num_) > 1)a
  296. </select>
  297. <select id="countVisitNum" resultType="java.lang.Integer">
  298. SELECT COUNT(DISTINCT student_id_) FROM student_visit
  299. WHERE type_ = '小课回访' AND purpose_ =
  300. <if test="groupType == 'VIP'">
  301. 'VIP课回访'
  302. </if>
  303. <if test="groupType == 'THEORY'">
  304. '乐理课回访'
  305. </if>
  306. <if test="groupType == 'PRACTICE'">
  307. '网管课回访'
  308. </if>
  309. </select>
  310. <select id="countLostStudentNum" resultType="java.lang.Integer">
  311. SELECT SUM(total_num_) FROM index_base_month_data
  312. <include refid="lostDateTypeSql"/>
  313. <if test="startDate != null and startDate != ''">
  314. AND month_ >= #{startDate}
  315. </if>
  316. <if test="endDate != null and endDate != ''">
  317. AND month_ &lt;= #{startDate}
  318. </if>
  319. </select>
  320. <select id="queryTeacherIds" resultType="java.lang.Integer">
  321. SELECT DISTINCT teacher_id_ FROM student_statistics WHERE group_type_ = #{groupType} AND teacher_id_ IS NOT NULL
  322. </select>
  323. <select id="queryDirectorList" resultType="java.lang.Integer">
  324. SELECT DISTINCT music_director_id_ FROM student_statistics WHERE group_type_ = #{groupType} AND music_director_id_ IS NOT NULL
  325. </select>
  326. <sql id="dateTypeSql">
  327. WHERE data_type_ =
  328. <if test="groupType == 'VIP'">
  329. 'STUDENT_VIP_ORDER_NUM'
  330. </if>
  331. <if test="groupType == 'THEORY'">
  332. 'STUDENT_THEORY_ORDER_NUM'
  333. </if>
  334. <if test="groupType == 'PRACTICE'">
  335. 'STUDENT_PRACTICE_ORDER_NUM'
  336. </if>
  337. </sql>
  338. <sql id="lostDateTypeSql">
  339. WHERE data_type_ =
  340. <if test="groupType == 'VIP'">
  341. 'STUDENT_VIP_LOST_NUM'
  342. </if>
  343. <if test="groupType == 'THEORY'">
  344. 'STUDENT_THEORY_LOST_NUM'
  345. </if>
  346. <if test="groupType == 'PRACTICE'">
  347. 'STUDENT_PRACTICE_LOST_NUM'
  348. </if>
  349. </sql>
  350. </mapper>