OperatingReportNewMapper.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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.OperatingReportNewDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.OperatingReportNew" id="OperatingReportNew">
  9. <result column="id_" property="id" />
  10. <result column="principal_" property="principal" />
  11. <result column="organ_name_" property="organName" />
  12. <result column="organ_id_" property="organId" />
  13. <result column="sale_amount_" property="saleAmount" />
  14. <result column="service_amount_" property="serviceAmount" />
  15. <result column="cloud_amount_" property="cloudAmount" />
  16. <result column="course_amount_" property="courseAmount" />
  17. <result column="maintenance_amount_" property="maintenanceAmount" />
  18. <result column="business_refund_" property="businessRefund" />
  19. <result column="total_income_" property="totalIncome" />
  20. <result column="sale_cost_" property="saleCost" />
  21. <result column="fixed_costs_" property="fixedCosts" />
  22. <result column="variable_costs_" property="variableCosts" />
  23. <result column="internal_settlement_" property="internalSettlement" />
  24. <result column="total_cost_" property="totalCost" />
  25. <result column="quasi_discretionary_profit_" property="quasiDiscretionaryProfit" />
  26. <result column="prepaid_fee_" property="prepaidFee" />
  27. <result column="cloud_prepaid_fee_" property="cloudPrepaidFee" />
  28. <result column="course_prepaid_fee_" property="coursePrepaidFee" />
  29. <result column="sale_prepaid_fee_" property="salePrepaidFee" />
  30. <result column="other_prepaid_fee_" property="otherPrepaidFee" />
  31. <result column="prepayments_" property="prepayments" />
  32. <result column="receivables_" property="receivables" />
  33. <result column="payable_" property="payable" />
  34. <result column="month_" property="month" />
  35. </resultMap>
  36. <!-- 根据主键查询一条记录 -->
  37. <select id="get" resultMap="OperatingReportNew" >
  38. SELECT * FROM operating_report_new WHERE id_ = #{id}
  39. </select>
  40. <!-- 全查询 -->
  41. <select id="findAll" resultMap="OperatingReportNew">
  42. SELECT * FROM operating_report_new ORDER BY id_
  43. </select>
  44. <!-- 向数据库增加一条记录 -->
  45. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.OperatingReportNew" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  46. INSERT INTO operating_report_new (id_,principal_,organ_id_,organ_name_,sale_amount_,service_amount_,cloud_amount_,course_amount_,maintenance_amount_,
  47. business_refund_,total_income_,sale_cost_,fixed_costs_,variable_costs_,internal_settlement_,
  48. total_cost_,quasi_discretionary_profit_,prepaid_fee_,cloud_prepaid_fee_,course_prepaid_fee_,sale_prepaid_fee_,other_prepaid_fee_
  49. ,prepayments_,receivables_,payable_,month_)
  50. VALUES(#{id},#{principal},#{organId},#{organName},#{saleAmount},#{serviceAmount},#{cloudAmount},#{courseAmount},#{maintenanceAmount},
  51. #{businessRefund},#{totalIncome},#{saleCost},#{fixedCosts},#{variableCosts},#{internalSettlement},
  52. #{totalCost},#{quasiDiscretionaryProfit},#{prepaidFee},#{cloudPrepaidFee},#{coursePrepaidFee},#{salePrepaidFee},#{otherPrepaidFee},
  53. #{prepayments},#{receivables},#{payable},#{month})
  54. </insert>
  55. <insert id="batchInsert">
  56. INSERT INTO operating_report_new (principal_,organ_id_,organ_name_,sale_amount_,service_amount_,cloud_amount_,course_amount_,maintenance_amount_,business_refund_,total_income_,sale_cost_,
  57. fixed_costs_,variable_costs_,internal_settlement_,total_cost_,quasi_discretionary_profit_,
  58. prepaid_fee_,cloud_prepaid_fee_,course_prepaid_fee_,sale_prepaid_fee_,other_prepaid_fee_,prepayments_,receivables_,payable_,month_)
  59. VALUES
  60. <foreach collection="operatingList" item="bean" separator=",">
  61. (#{bean.principal},#{bean.organId},#{bean.organName},#{bean.saleAmount},#{bean.serviceAmount},#{bean.cloudAmount},#{bean.courseAmount},#{bean.maintenanceAmount},#{bean.businessRefund},#{bean.totalIncome},
  62. #{bean.saleCost},#{bean.fixedCosts},#{bean.variableCosts},#{bean.internalSettlement},#{bean.totalCost},#{bean.quasiDiscretionaryProfit},
  63. #{bean.prepaidFee},#{bean.cloudPrepaidFee},#{bean.coursePrepaidFee},#{bean.salePrepaidFee},#{bean.otherPrepaidFee},
  64. #{bean.prepayments},#{bean.receivables},#{bean.payable},#{bean.month})
  65. </foreach>
  66. </insert>
  67. <!-- 根据主键查询一条记录 -->
  68. <update id="update" parameterType="com.ym.mec.biz.dal.entity.OperatingReportNew">
  69. UPDATE operating_report_new <set>
  70. <if test="saleAmount != null">
  71. sale_amount_ = #{saleAmount},
  72. </if>
  73. <if test="prepaidFee != null">
  74. prepaid_fee_ = #{prepaidFee},
  75. </if>
  76. <if test="serviceAmount != null">
  77. service_amount_ = #{serviceAmount},
  78. </if>
  79. <if test="payable != null">
  80. payable_ = #{payable},
  81. </if>
  82. <if test="businessRefund != null">
  83. business_refund_ = #{businessRefund},
  84. </if>
  85. <if test="totalCost != null">
  86. total_cost_ = #{totalCost},
  87. </if>
  88. <if test="totalIncome != null">
  89. total_income_ = #{totalIncome},
  90. </if>
  91. <if test="quasiDiscretionaryProfit != null">
  92. quasi_discretionary_profit_ = #{quasiDiscretionaryProfit},
  93. </if>
  94. <if test="fixedCosts != null">
  95. fixed_costs_ = #{fixedCosts},
  96. </if>
  97. <if test="internalSettlement != null">
  98. internal_settlement_ = #{internalSettlement},
  99. </if>
  100. <if test="prepayments != null">
  101. prepayments_ = #{prepayments},
  102. </if>
  103. <if test="month != null">
  104. month_ = #{month},
  105. </if>
  106. <if test="variableCosts != null">
  107. variable_costs_ = #{variableCosts},
  108. </if>
  109. <if test="organName != null">
  110. organ_name_ = #{organName},
  111. </if>
  112. <if test="saleCost != null">
  113. sale_cost_ = #{saleCost},
  114. </if>
  115. <if test="receivables != null">
  116. receivables_ = #{receivables},
  117. </if>
  118. <if test="principal != null">
  119. principal_ = #{principal},
  120. </if>
  121. </set> WHERE id_ = #{id}
  122. </update>
  123. <update id="initCloudStartTime">
  124. update operating_report_cloud orc
  125. left join (
  126. select orc.calender_id_,MIN(cs.class_date_) start_date_ from operating_report_cloud orc
  127. left join music_group_payment_calender mgpc ON mgpc.id_ = orc.calender_id_
  128. left join course_schedule_student_payment cssp ON cssp.batch_no_ = mgpc.batch_no_
  129. left join course_schedule cs ON cs.id_ = cssp.course_schedule_id_
  130. where orc.month_flag_ = false AND orc.settlement_flag_ = false AND orc.start_date_ IS NULL
  131. AND cs.class_date_ &lt;= #{lastDay}
  132. group by orc.calender_id_) mc ON orc.calender_id_ = mc.calender_id_
  133. LEFT JOIN (select calender_id_,DATE_ADD(
  134. DATE_ADD(create_time_, interval CASE WHEN period_ = 'YEAR_HALF' THEN 6
  135. WHEN period_ = 'YEAR' THEN 12
  136. WHEN period_ = 'QUARTERLY' THEN 3 ELSE num_ END MONTH),interval 1 DAY) end_date_
  137. from music_group_payment_calender_member order by id_ DESC) mgpcm
  138. ON mc.calender_id_ = mgpcm.calender_id_
  139. set orc.start_date_ = mc.start_date_,orc.end_date_ = mgpcm.end_date_
  140. where orc.calender_id_ = mc.calender_id_ AND orc.month_flag_ = 0
  141. </update>
  142. <!-- 根据主键删除一条记录 -->
  143. <delete id="delete" >
  144. DELETE FROM operating_report_new WHERE id_ = #{id}
  145. </delete>
  146. <delete id="deleteByMonth">
  147. DELETE FROM operating_report_new WHERE month_ = #{month}
  148. </delete>
  149. <sql id="queryPageSql">
  150. <where>
  151. <if test="organId != null and organId != ''">
  152. AND FIND_IN_SET(organ_id_,#{organId})
  153. </if>
  154. <if test="date != null and date != ''">
  155. AND month_ = #{date}
  156. </if>
  157. </where>
  158. </sql>
  159. <!-- 分页查询 -->
  160. <select id="queryPage" resultMap="OperatingReportNew" parameterType="map">
  161. SELECT * FROM operating_report_new
  162. <include refid="queryPageSql"/>
  163. ORDER BY id_
  164. <include refid="global.limit"/>
  165. </select>
  166. <!-- 查询当前表的总记录数 -->
  167. <select id="queryCount" resultType="int">
  168. SELECT COUNT(id_) FROM operating_report_new
  169. <include refid="queryPageSql"/>
  170. </select>
  171. <select id="initOperatingReport" resultMap="OperatingReportNew">
  172. select id_ organ_id_,name_ organ_name_,#{month} month_ from organization where del_flag_ = 0 and tenant_id_ = 1
  173. </select>
  174. <select id="sumSellAmount" resultMap="OperatingReportNew">
  175. select so.organ_id_,SUM(so.expect_amount_) sale_amount_,SUM(CASE WHEN so.status_ = 1 THEN 0 ELSE so.organ_sell_cost_ * so.num_ END) sale_cost_ from sell_order so
  176. left join student_payment_order spo ON spo.order_no_ = so.order_no_
  177. left join music_group mg ON mg.id_ = spo.music_group_id_ AND spo.group_type_ = 'MUSIC'
  178. where (mg.musical_instruments_provide_status_ = 1 AND mg.musical_instruments_provide_time_ = #{month}) OR
  179. (DATE_FORMAT(spo.pay_time_,'%Y-%m') = #{month} AND (mg.musical_instruments_provide_status_ IS NULL OR mg.musical_instruments_provide_status_ = 1))
  180. group by so.organ_id_
  181. </select>
  182. <select id="sumCourseAmount" resultType="java.util.Map">
  183. SELECT cs.organ_id_ 'key',SUM(cssp.actual_price_) 'value' FROM course_schedule cs
  184. LEFT JOIN course_schedule_student_payment cssp ON cssp.course_schedule_id_ = cs.id_
  185. where cs.del_flag_ = 0 AND cs.is_lock_ = 0 AND cs.pre_course_flag_ = 0 AND (cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_)
  186. AND cssp.actual_price_ > 0 AND cs.class_date_ BETWEEN #{firstDay} AND #{lastDay}
  187. AND DATE_FORMAT(cs.create_time_,'%Y') = #{currentYear} AND cs.settlement_report_flag_ = 0 group by cs.organ_id_;
  188. </select>
  189. <select id="sumPersonalCloudAmount" resultType="java.util.Map">
  190. select cto.organ_id_ 'key',TRUNCATE(SUM(operating_amount_ / (TIMESTAMPDIFF(DAY,cto.start_time_,cto.end_time_) + 1) *
  191. (TIMESTAMPDIFF(DAY,CASE WHEN start_time_ &lt; #{firstDay} THEN #{firstDay} ELSE DATE_FORMAT(start_time_,'%Y-%m-%d') END,
  192. CASE WHEN DATE_FORMAT(end_time_,'%Y-%m') > #{month} THEN #{lastDay} ELSE DATE_FORMAT(end_time_,'%Y-%m-%d') END) + 1)),2) 'value'
  193. from cloud_teacher_order cto
  194. where operating_amount_ > 0 AND #{month} BETWEEN DATE_FORMAT(start_time_,'%Y-%m') AND DATE_FORMAT(end_time_,'%Y-%m')
  195. AND cto.settlement_report_flag_ = 0 AND cto.status_ = 2
  196. group by cto.organ_id_;
  197. </select>
  198. <select id="sumGroupCloudAmount" resultType="java.util.Map">
  199. select orc.organ_id_ 'key',TRUNCATE(SUM(orc.cloud_price_ / (TIMESTAMPDIFF(DAY,orc.start_date_,orc.end_date_) + 1) *
  200. (TIMESTAMPDIFF(DAY,CASE WHEN orc.start_date_ &lt; #{firstDay} THEN #{firstDay} ELSE orc.start_date_ END,
  201. CASE WHEN DATE_FORMAT(orc.end_date_,'%Y-%m') > #{month} THEN #{lastDay} ELSE orc.end_date_ END) + 1) ),2) 'value' from operating_report_cloud orc
  202. where #{month} BETWEEN DATE_FORMAT(orc.start_date_,'%Y-%m') AND DATE_FORMAT(orc.end_date_,'%Y-%m') AND orc.cloud_price_ > 0 AND orc.start_date_ IS NOT NULL;
  203. </select>
  204. <select id="sumRefundAmount" resultType="java.util.Map">
  205. select organ_id_ 'key',SUM(amount_) 'value' from financial_expenditure where process_id_ IN (19,20,23) AND fee_project_ != 25
  206. AND DATE_FORMAT(create_time_,'%Y-%m') = #{month} AND amount_ > 0 group by organ_id_;
  207. </select>
  208. <select id="sumVariableCosts" resultType="java.util.Map">
  209. select fe.organ_id_ 'key',SUM(amount_) 'value' from financial_expenditure fe
  210. where DATE_FORMAT(fe.create_time_,'%Y-%m') = #{month} AND fee_project_ BETWEEN 6 AND 21 AND process_id_ = 28 group by fe.organ_id_;
  211. </select>
  212. <select id="sumFixedCosts" resultType="java.util.Map">
  213. select fe.organ_id_ 'key',SUM(amount_) 'value' from financial_expenditure fe
  214. where DATE_FORMAT(fe.create_time_,'%Y-%m') = #{month} AND fee_project_ IN (1,2,3,4,5) AND process_id_ = 28 group by fe.organ_id_;
  215. </select>
  216. <select id="sumCloudPreAmount" resultType="java.util.Map">
  217. select cto.organ_id_ 'key',TRUNCATE(SUM(operating_amount_ / (TIMESTAMPDIFF(DAY,cto.start_time_,cto.end_time_) + 1) *
  218. (TIMESTAMPDIFF(DAY,CASE WHEN start_time_ &lt; #{lastDay} THEN #{lastDay} ELSE start_time_ END,end_time_) + 1) ),2) 'value'
  219. from cloud_teacher_order cto
  220. where operating_amount_ > 0 AND DATE_FORMAT(end_time_,'%Y-%m') > #{month} group by cto.organ_id_;
  221. </select>
  222. <select id="sumGroupCloudPreAmount" resultType="java.util.Map">
  223. select orc.organ_id_ 'key',TRUNCATE(SUM(orc.cloud_price_ / (TIMESTAMPDIFF(DAY,orc.start_date_,orc.end_date_) + 1) * (TIMESTAMPDIFF(DAY,#{lastDay},orc.end_date_) + 1) ),2) 'value'
  224. from operating_report_cloud orc
  225. where DATE_FORMAT(orc.end_date_,'%Y-%m') > #{month} AND orc.cloud_price_ > 0 AND orc.month_flag_ = false group by orc.organ_id_;
  226. </select>
  227. <select id="sumGroupAmount" resultType="java.util.Map">
  228. select orc.organ_id_ 'key',SUM(orc.cloud_price_) 'value'
  229. from operating_report_cloud orc
  230. where orc.cloud_price_ > 0 AND orc.month_flag_ = true AND DATE_FORMAT(orc.create_time_,'%Y-%m') = #{month} group by orc.organ_id_;
  231. </select>
  232. <select id="sumCoursePreAmount" resultType="java.util.Map">
  233. SELECT cs.organ_id_ 'key',SUM(cssp.actual_price_) 'value' FROM course_schedule cs
  234. LEFT JOIN course_schedule_student_payment cssp ON cssp.course_schedule_id_ = cs.id_
  235. where cs.del_flag_ = 0 AND cs.is_lock_ = 0 AND cs.pre_course_flag_ = 0
  236. AND (cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_) AND cs.class_date_ > #{lastDay}
  237. AND cs.group_type_ != 'MUSIC'
  238. group by cs.organ_id_;
  239. </select>
  240. <select id="sumOtherPreAmount" resultType="java.util.Map">
  241. select orc.organ_id_ 'key',SUM(orc.cloud_price_) 'value' from operating_report_cloud orc
  242. where orc.course_price_ = 0 AND orc.month_flag_ = false AND orc.settlement_flag_ = false GROUP BY orc.organ_id_;
  243. </select>
  244. <select id="sumSalePreAmount" resultType="java.util.Map">
  245. select mg.organ_id_ 'key',SUM(so.actual_amount_) 'value' from sell_order so
  246. left join student_payment_order spo ON spo.order_no_ = so.order_no_
  247. left join music_group mg ON mg.id_ = spo.music_group_id_ AND spo.group_type_ = 'MUSIC'
  248. where mg.musical_instruments_provide_status_ = 0 AND so.actual_amount_ > 0
  249. group by mg.organ_id_;
  250. </select>
  251. <select id="sumArrearsAmount" resultType="java.util.Map">
  252. select a.organ_id_ 'key',SUM(a.amount_) 'value' FROM (
  253. select SUM(mgpc.current_total_amount_) amount_,mgpc.organ_id_ from music_group_payment_calender_detail mgpcd
  254. LEFT JOIN (select * from music_group_payment_student_course_detail where used_course_minutes_ > 0 group by music_group_payment_calender_id_,user_id_) mgpscd ON mgpscd.music_group_payment_calender_detail_id_ = mgpcd.id_
  255. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = mgpscd.music_group_payment_calender_id_
  256. WHERE mgpcd.payment_status_ = 'NON_PAYMENT' AND mgpscd.used_course_minutes_ > 0 AND mgpc.current_total_amount_ > 0
  257. GROUP BY mgpscd.music_group_payment_calender_id_,mgpscd.user_id_) a
  258. group by organ_id_
  259. </select>
  260. <select id="sumSchoolAmount" resultType="java.util.Map">
  261. select mg.organ_id_ 'key',SUM(mg.amount_) 'value' from (
  262. select mgpc.organ_id_,mgpc.current_total_amount_ -
  263. CASE WHEN SUM(spro.service_amount_) IS NULL THEN 0 ELSE SUM(spro.service_amount_) END
  264. - CASE WHEN SUM(spro.sale_amount_) IS NULL THEN 0 ELSE SUM(spro.sale_amount_) END amount_ from (
  265. select mgpc.* from music_group_payment_calender mgpc
  266. left join music_group_payment_calender_detail mgpcd ON mgpc.id_ = mgpcd.music_group_payment_calender_id_
  267. where mgpcd.id_ IS NOT NULL AND mgpc.pay_user_type_ = 'SCHOOL'
  268. group by mgpc.id_) mgpc
  269. left join student_payment_route_order spro ON spro.calender_id_ = mgpc.id_ AND spro.audit_status_ = 'PASS'
  270. group by mgpc.id_) mg group by mg.organ_id_
  271. </select>
  272. <select id="sumMusicMargin" resultType="java.util.Map">
  273. select mm.organ_id_ 'key',SUM(mm.balance_) 'value' from music_margin mm where mm.refund_flag_ = 0 group by mm.organ_id_;
  274. </select>
  275. <select id="sumInternalSettlement" resultType="java.util.Map">
  276. select fe.organ_id_ 'key',SUM(amount_) 'value' from financial_expenditure fe
  277. where DATE_FORMAT(fe.create_time_,'%Y-%m') = #{month} AND fee_project_ = 22 AND process_id_ = 28 group by fe.organ_id_;
  278. </select>
  279. <select id="sumPrepayments" resultType="java.util.Map">
  280. select fe.organ_id_ 'key',SUM(amount_) 'value' from financial_expenditure fe
  281. where DATE_FORMAT(fe.create_time_,'%Y-%m') = #{month} AND fee_project_ = 3 AND process_id_ = 28 group by fe.organ_id_;
  282. </select>
  283. <select id="sumActivityUserMapperAmount" resultType="java.util.Map">
  284. SELECT mgpc.organ_id_ 'key',(SUM(CASE WHEN aum.sub_course_num_ > 0 AND aum.category_id_ != #{categoryId} THEN aum.sub_course_num_ ELSE 0 END) +
  285. SUM(CASE WHEN aum.sub_give_course_num_ > 0 AND aum.give_category_id_ != #{categoryId} THEN aum.sub_give_course_num_ ELSE 0 END)) *
  286. CASE WHEN oct.id_ IS NULL THEN oct1.price_ ELSE oct.price_ END 'value'
  287. FROM activity_user_mapper aum
  288. LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = aum.calender_id_
  289. left join organ_course_type_original_cost oct ON oct.course_type_ = 'VIP' AND oct.organ_id_ = mgpc.organ_id_
  290. left join organ_course_type_original_cost oct1 ON oct1.course_type_ = 'VIP' AND oct1.organ_id_ = 0
  291. WHERE aum.calender_id_ IS NOT NULL AND aum.return_fee_ = 0
  292. AND ((aum.sub_course_num_ > 0 AND aum.category_id_ != #{categoryId}) OR (aum.sub_give_course_num_ > 0 AND aum.give_category_id_ != #{categoryId}))
  293. GROUP BY mgpc.organ_id_
  294. </select>
  295. <select id="sumMusicCourseAmount" resultType="java.util.Map">
  296. select mg.organ_id_ 'key',SUM(sr.surplus_course_fee_) 'value' from student_registration sr
  297. left join music_group mg ON mg.id_ = sr.music_group_id_
  298. where sr.surplus_course_fee_ > 0
  299. group by mg.organ_id_;
  300. </select>
  301. <select id="sumSubActivityUserMapperAmount" resultType="java.util.Map">
  302. select su.organ_id_ 'key',SUM(aum.sub_no_course_price_) 'value' from activity_user_mapper aum
  303. LEFT JOIN sys_user su ON su.id_ = aum.user_id_
  304. where aum.return_fee_ = 0 AND aum.sub_no_course_price_ > 0
  305. group by su.organ_id_
  306. </select>
  307. <select id="sumImportServerOrderAmount" resultType="java.util.Map">
  308. select spo.organ_id_ 'key',SUM(spro.service_amount_) 'value' from student_payment_order spo
  309. LEFT JOIN student_payment_route_order spro ON spro.order_no_ = spo.order_no_
  310. where spo.group_type_ = 'OUTORDER' AND DATE_FORMAT(spo.create_time_,'%Y-%m') = #{month}
  311. GROUP BY spo.organ_id_;
  312. </select>
  313. <select id="sumWaitCloudPreAmount" resultType="java.util.Map">
  314. select cto.organ_id_ 'key',SUM(cto.operating_amount_) 'value' from cloud_teacher_order cto
  315. where cto.status_ = 1 AND cto.operating_amount_ > 0
  316. group by cto.organ_id_;
  317. </select>
  318. <select id="sumMaintenanceAmount" resultType="java.util.Map">
  319. select spo.organ_id_ 'key',SUM(spod.price_) 'value' from student_payment_order_detail spod
  320. left join student_payment_order spo ON spo.id_ = spod.payment_order_id_
  321. where spod.type_ IN ('MAINTENANCE','REPAIR') AND DATE_FORMAT(spod.create_time_,'%Y-%m') = #{month} AND spo.status_ = 'SUCCESS'
  322. group by spo.organ_id_
  323. </select>
  324. <select id="sumLossCloudAmount" resultType="java.util.Map">
  325. select organ_id_ 'key',SUM(cloud_price_) 'value' from operating_report_cloud where cloud_price_ &lt; 0 AND DATE_FORMAT(start_date_,'%Y-%m') = #{month}
  326. group by organ_id_;
  327. </select>
  328. <select id="sumNotStartCloudPreAmount" resultType="java.util.Map">
  329. select orc.organ_id_ 'key',SUM(orc.cloud_price_) 'value' from operating_report_cloud orc
  330. where orc.start_date_ IS NULL AND orc.course_price_ > 0
  331. group by orc.organ_id_
  332. </select>
  333. <select id="sumStudentManagementFee" resultType="java.util.Map">
  334. select mg.organ_id_ 'key',COUNT(DISTINCT sr.user_id_) * 80 'value' from student_registration sr
  335. left join music_group mg ON mg.id_ = sr.music_group_id_
  336. where sr.music_group_status_ = 'NORMAL' AND mg.status_ = 'PROGRESS'
  337. group by mg.organ_id_
  338. </select>
  339. <select id="sumTotalSellAmount" resultMap="OperatingReportNew">
  340. select SUM(so.organ_sell_cost_ * so.num_) sale_amount_,SUM(CASE WHEN so.status_ = 1 THEN 0 ELSE so.sell_cost_ * so.num_ END) sale_cost_ from sell_order so
  341. left join student_payment_order spo ON spo.order_no_ = so.order_no_
  342. left join music_group mg ON mg.id_ = spo.music_group_id_ AND spo.group_type_ = 'MUSIC'
  343. where (mg.musical_instruments_provide_status_ = 1 AND mg.musical_instruments_provide_time_ = #{month}) OR
  344. (DATE_FORMAT(spo.pay_time_,'%Y-%m') = #{month} AND (mg.musical_instruments_provide_status_ IS NULL OR mg.musical_instruments_provide_status_ = 1));
  345. </select>
  346. <select id="queryOASummaryExpenses" resultType="com.ym.mec.biz.dal.dto.OASummaryExpensesDto">
  347. SELECT
  348. o.name_ AS organName,
  349. SUM(CASE WHEN fee_project_ = 3 THEN fe.amount_ ELSE 0 END) AS house,
  350. SUM(CASE WHEN fee_project_ = 4 THEN fe.amount_ ELSE 0 END) AS office,
  351. SUM(CASE WHEN fee_project_ = 5 THEN fe.amount_ ELSE 0 END) AS mainsProperty,
  352. SUM(CASE WHEN fee_project_ = 6 THEN fe.amount_ ELSE 0 END) AS travel,
  353. SUM(CASE WHEN fee_project_ = 7 THEN fe.amount_ ELSE 0 END) AS services,
  354. SUM(CASE WHEN fee_project_ = 8 THEN fe.amount_ ELSE 0 END) AS welfare,
  355. SUM(CASE WHEN fee_project_ = 9 THEN fe.amount_ ELSE 0 END) AS activities,
  356. SUM(CASE WHEN fee_project_ = 10 THEN fe.amount_ ELSE 0 END) AS traffic,
  357. SUM(CASE WHEN fee_project_ = 11 THEN fe.amount_ ELSE 0 END) AS certificates,
  358. SUM(CASE WHEN fee_project_ IN (12,20) THEN fe.amount_ ELSE 0 END) AS instrument,
  359. SUM(CASE WHEN fee_project_ = 15 THEN fe.amount_ ELSE 0 END) AS communications,
  360. SUM(CASE WHEN fee_project_ = 16 THEN fe.amount_ ELSE 0 END) AS postalTransport,
  361. SUM(CASE WHEN fee_project_ = 17 THEN fe.amount_ ELSE 0 END) AS hospitality,
  362. SUM(CASE WHEN fee_project_ = 19 THEN fe.amount_ ELSE 0 END) AS refund,
  363. SUM(CASE WHEN fee_project_ = 26 THEN fe.amount_ ELSE 0 END) AS other,
  364. SUM(CASE WHEN hc.human_cost_type_ = 'FIXED' THEN hc.amount_ ELSE 0 END) AS fixedHumanCost,
  365. SUM(CASE WHEN hc.human_cost_type_ = 'VARIABLE' THEN hc.amount_ ELSE 0 END) AS variableHumanCost,
  366. SUM(CASE WHEN hc.human_cost_type_ = 'NETWORK_CLASSROOM' THEN hc.amount_ ELSE 0 END) AS network,
  367. SUM(CASE WHEN hc.human_cost_type_ = 'CLOUD_COACHING_COST' THEN hc.amount_ ELSE 0 END) AS cloudCoachingCost,
  368. SUM(CASE WHEN hc.human_cost_type_ = 'INTERNAL_SETTLEMENT' THEN hc.amount_ ELSE 0 END) AS internalSettlement,
  369. SUM(CASE WHEN hc.human_cost_type_ = 'STUDENT_MANAGEMENT_FEE_ADJUSTMENT' THEN hc.amount_ ELSE 0 END) AS studentManagementFeeAdjustment
  370. FROM
  371. organization o
  372. left join financial_expenditure fe ON o.id_ = fe.organ_id_ AND fe.process_id_ = 28 AND effective_time_= #{month} AND fe.del_flag_ = 0
  373. left join human_cost hc ON hc.organ_id_ = o.id_ AND hc.month_ = #{month}
  374. WHERE
  375. o.tenant_id_ = 1 AND o.del_flag_ = 0
  376. GROUP BY
  377. o.id_
  378. </select>
  379. <resultMap type="com.ym.mec.biz.dal.entity.FinancialExpenditure" id="FinancialExpenditure">
  380. <result column="name_" property="organName"/>
  381. <result column="batch_no_" property="batchNo"/>
  382. <result column="cooperation_organ_name_" property="cooperationOrganName"/>
  383. <result column="apply_user_" property="applyUser"/>
  384. <result column="student_id_" property="studentId"/>
  385. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  386. <result column="fee_project_" property="feeProject" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  387. <result column="amount_" property="amount"/>
  388. <result column="payment_time_" property="paymentTime"/>
  389. <result column="current_amount_" property="currentAmount"/>
  390. <result column="cause_" property="cause"/>
  391. </resultMap>
  392. <select id="queryOASummaryExpensesDetail" resultMap="FinancialExpenditure">
  393. select o.name_,fe.batch_no_,co.name_ cooperationName,fe.apply_user_,
  394. fe.fee_project_,fe.type_,fe.amount_,fe.payment_time_,fe.cause_,fe.current_amount_,fe.student_id_
  395. from financial_expenditure fe
  396. left join organization o ON o.id_ = fe.organ_id_
  397. left join cooperation_organ co ON co.id_ = fe.cooperation_organ_id_
  398. where fe.process_id_ IN (19,22,28,51) AND fee_project_ NOT IN (1,2,13,14) AND fe.del_flag_ = 0 AND fe.effective_time_ = #{month}
  399. order by fe.id_ DESC
  400. </select>
  401. <select id="sumHumanCost" resultType="com.ym.mec.biz.dal.dto.HumanTypeDto">
  402. select
  403. organ_id_,
  404. SUM(CASE WHEN human_cost_type_ = 'FIXED' THEN amount_ ELSE 0 END) AS fixedCost,
  405. SUM(CASE WHEN human_cost_type_ = 'VARIABLE' THEN amount_ ELSE 0 END) AS variableCost,
  406. SUM(CASE WHEN human_cost_type_ = 'NETWORK_CLASSROOM' THEN amount_ ELSE 0 END) AS networkClassroomCost,
  407. SUM(CASE WHEN human_cost_type_ = 'CLOUD_COACHING_COST' THEN amount_ ELSE 0 END) AS cloudCoachingCost,
  408. SUM(CASE WHEN human_cost_type_ = 'INTERNAL_SETTLEMENT' THEN amount_ ELSE 0 END) AS internalSettlement,
  409. SUM(CASE WHEN human_cost_type_ = 'STUDENT_MANAGEMENT_FEE_ADJUSTMENT' THEN amount_ ELSE 0 END) AS studentManagementFeeAdjustment
  410. from human_cost
  411. where month_ = #{month} group by organ_id_
  412. </select>
  413. </mapper>