StudentStatisticsMapper.xml 15 KB

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