|  | @@ -13,6 +13,8 @@
 | 
	
		
			
				|  |  |  		<result column="organ_id_" property="organId" />
 | 
	
		
			
				|  |  |  		<result column="sale_amount_" property="saleAmount" />
 | 
	
		
			
				|  |  |  		<result column="service_amount_" property="serviceAmount" />
 | 
	
		
			
				|  |  | +		<result column="cloud_amount_" property="cloudAmount" />
 | 
	
		
			
				|  |  | +		<result column="course_amount_" property="courseAmount" />
 | 
	
		
			
				|  |  |  		<result column="business_refund_" property="businessRefund" />
 | 
	
		
			
				|  |  |  		<result column="total_income_" property="totalIncome" />
 | 
	
		
			
				|  |  |  		<result column="sale_cost_" property="saleCost" />
 | 
	
	
		
			
				|  | @@ -22,6 +24,10 @@
 | 
	
		
			
				|  |  |  		<result column="total_cost_" property="totalCost" />
 | 
	
		
			
				|  |  |  		<result column="quasi_discretionary_profit_" property="quasiDiscretionaryProfit" />
 | 
	
		
			
				|  |  |  		<result column="prepaid_fee_" property="prepaidFee" />
 | 
	
		
			
				|  |  | +		<result column="cloud_prepaid_fee_" property="cloudPrepaidFee" />
 | 
	
		
			
				|  |  | +		<result column="course_prepaid_fee_" property="coursePrepaidFee" />
 | 
	
		
			
				|  |  | +		<result column="sale_prepaid_fee_" property="salePrepaidFee" />
 | 
	
		
			
				|  |  | +		<result column="other_prepaid_fee_" property="otherPrepaidFee" />
 | 
	
		
			
				|  |  |  		<result column="prepayments_" property="prepayments" />
 | 
	
		
			
				|  |  |  		<result column="receivables_" property="receivables" />
 | 
	
		
			
				|  |  |  		<result column="payable_" property="payable" />
 | 
	
	
		
			
				|  | @@ -40,18 +46,25 @@
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	<!-- 向数据库增加一条记录 -->
 | 
	
		
			
				|  |  |  	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.OperatingReportNew" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
 | 
	
		
			
				|  |  | -		INSERT INTO operating_report_new (id_,principal_,organ_name_,sale_amount_,service_amount_,business_refund_,total_income_,sale_cost_,fixed_costs_,variable_costs_,internal_settlement_,total_cost_,quasi_discretionary_profit_,prepaid_fee_,prepayments_,receivables_,payable_,month_)
 | 
	
		
			
				|  |  | -		VALUES(#{id},#{principal},#{organName},#{saleAmount},#{serviceAmount},#{businessRefund},#{totalIncome},#{saleCost},#{fixedCosts},#{variableCosts},#{internalSettlement},#{totalCost},#{quasiDiscretionaryProfit},#{prepaidFee},#{prepayments},#{receivables},#{payable},#{month})
 | 
	
		
			
				|  |  | +		INSERT INTO operating_report_new (id_,principal_,organ_id_,organ_name_,sale_amount_,service_amount_,cloud_amount_,course_amount_,
 | 
	
		
			
				|  |  | +		                                  business_refund_,total_income_,sale_cost_,fixed_costs_,variable_costs_,internal_settlement_,
 | 
	
		
			
				|  |  | +		                                  total_cost_,quasi_discretionary_profit_,prepaid_fee_,cloud_prepaid_fee_,course_prepaid_fee_,sale_prepaid_fee_,other_prepaid_fee_
 | 
	
		
			
				|  |  | +		                                  ,prepayments_,receivables_,payable_,month_)
 | 
	
		
			
				|  |  | +		VALUES(#{id},#{principal},#{organId},#{organName},#{saleAmount},#{serviceAmount},#{cloudAmount},#{courseAmount},
 | 
	
		
			
				|  |  | +		       #{businessRefund},#{totalIncome},#{saleCost},#{fixedCosts},#{variableCosts},#{internalSettlement},
 | 
	
		
			
				|  |  | +		       #{totalCost},#{quasiDiscretionaryProfit},#{prepaidFee},#{cloudPrepaidFee},#{coursePrepaidFee},#{salePrepaidFee},#{otherPrepaidFee},
 | 
	
		
			
				|  |  | +		       #{prepayments},#{receivables},#{payable},#{month})
 | 
	
		
			
				|  |  |  	</insert>
 | 
	
		
			
				|  |  |  	<insert id="batchInsert">
 | 
	
		
			
				|  |  | -		INSERT INTO operating_report_new (principal_,organ_name_,sale_amount_,service_amount_,business_refund_,total_income_,sale_cost_,
 | 
	
		
			
				|  |  | +		INSERT INTO operating_report_new (principal_,organ_id_,organ_name_,sale_amount_,service_amount_,cloud_amount_,course_amount_,business_refund_,total_income_,sale_cost_,
 | 
	
		
			
				|  |  |  		                                  fixed_costs_,variable_costs_,internal_settlement_,total_cost_,quasi_discretionary_profit_,
 | 
	
		
			
				|  |  | -		                                  prepaid_fee_,prepayments_,receivables_,payable_,month_)
 | 
	
		
			
				|  |  | +		                                  prepaid_fee_,cloud_prepaid_fee_,course_prepaid_fee_,sale_prepaid_fee_,other_prepaid_fee_,prepayments_,receivables_,payable_,month_)
 | 
	
		
			
				|  |  |  		VALUES
 | 
	
		
			
				|  |  |  		<foreach collection="operatingList" item="bean" separator=",">
 | 
	
		
			
				|  |  | -			(#{bean.principal},#{bean.organName},#{bean.saleAmount},#{bean.serviceAmount},#{bean.businessRefund},#{bean.totalIncome},
 | 
	
		
			
				|  |  | +			(#{bean.principal},#{bean.organId},#{bean.organName},#{bean.saleAmount},#{bean.serviceAmount},#{bean.cloudAmount},#{bean.courseAmount},#{bean.businessRefund},#{bean.totalIncome},
 | 
	
		
			
				|  |  |  			 #{bean.saleCost},#{bean.fixedCosts},#{bean.variableCosts},#{bean.internalSettlement},#{bean.totalCost},#{bean.quasiDiscretionaryProfit},
 | 
	
		
			
				|  |  | -			 #{bean.prepaidFee},#{bean.prepayments},#{bean.receivables},#{bean.payable},#{bean.month})
 | 
	
		
			
				|  |  | +			 #{bean.prepaidFee},#{bean.cloudPrepaidFee},#{bean.coursePrepaidFee},#{bean.salePrepaidFee},#{bean.otherPrepaidFee},
 | 
	
		
			
				|  |  | +			 #{bean.prepayments},#{bean.receivables},#{bean.payable},#{bean.month})
 | 
	
		
			
				|  |  |  		</foreach>
 | 
	
		
			
				|  |  |  	</insert>
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -137,25 +150,39 @@
 | 
	
		
			
				|  |  |  	<delete id="deleteByMonth">
 | 
	
		
			
				|  |  |  		DELETE FROM operating_report_new WHERE month_ = #{month}
 | 
	
		
			
				|  |  |  	</delete>
 | 
	
		
			
				|  |  | +	<sql id="queryPageSql">
 | 
	
		
			
				|  |  | +		<where>
 | 
	
		
			
				|  |  | +			<if test="organId != null and organId != ''">
 | 
	
		
			
				|  |  | +				AND FIND_IN_SET(organ_id_,#{organId})
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +			<if test="startTime != null and startTime != ''">
 | 
	
		
			
				|  |  | +				AND month_ BETWEEN #{startTime} AND #{endTime}
 | 
	
		
			
				|  |  | +			</if>
 | 
	
		
			
				|  |  | +		</where>
 | 
	
		
			
				|  |  | +	</sql>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	<!-- 分页查询 -->
 | 
	
		
			
				|  |  |  	<select id="queryPage" resultMap="OperatingReportNew" parameterType="map">
 | 
	
		
			
				|  |  | -		SELECT * FROM operating_report_new ORDER BY id_ <include refid="global.limit"/>
 | 
	
		
			
				|  |  | +		SELECT * FROM operating_report_new
 | 
	
		
			
				|  |  | +		<include refid="queryPageSql"/>
 | 
	
		
			
				|  |  | +		ORDER BY id_
 | 
	
		
			
				|  |  | +		<include refid="global.limit"/>
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	<!-- 查询当前表的总记录数 -->
 | 
	
		
			
				|  |  |  	<select id="queryCount" resultType="int">
 | 
	
		
			
				|  |  | -		SELECT COUNT(*) FROM operating_report_new
 | 
	
		
			
				|  |  | +		SELECT COUNT(id_) FROM operating_report_new
 | 
	
		
			
				|  |  | +		<include refid="queryPageSql"/>
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  	<select id="initOperatingReport" resultMap="OperatingReportNew">
 | 
	
		
			
				|  |  | -		select id_ organ_id_,name_ organ_name_ from organization where del_flag_ = 0 and tenant_id_ = 1
 | 
	
		
			
				|  |  | +		select id_ organ_id_,name_ organ_name_,#{month} month_ from organization where del_flag_ = 0 and tenant_id_ = 1
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  	<select id="sumSellAmount" resultMap="OperatingReportNew">
 | 
	
		
			
				|  |  | -		select so.organ_id_,SUM(so.actual_amount_) sale_amount_,SUM(so.sell_cost_) sale_cost_ from sell_order so
 | 
	
		
			
				|  |  | +		select so.organ_id_,SUM(so.actual_amount_) sale_amount_,SUM(CASE WHEN so.status_ = 1 THEN 0 ELSE so.sell_cost_ END) sale_cost_ from sell_order so
 | 
	
		
			
				|  |  |  		left join student_payment_order spo ON spo.order_no_ = so.order_no_
 | 
	
		
			
				|  |  |  		left join music_group mg ON mg.id_ = spo.music_group_id_ AND spo.group_type_ = 'MUSIC'
 | 
	
		
			
				|  |  |  		LEFT JOIN organization o ON o.id_ = so.organ_id_
 | 
	
		
			
				|  |  | -		where (mg.musical_instruments_provide_status_ = 1 AND mg.musical_instruments_provide_date_ = #{month}) OR (DATE_FORMAT(so.create_ime_,'%Y-%m') = #{month} AND (mg.musical_instruments_provide_status_ IS NULL OR mg.musical_instruments_provide_status_ = 1))
 | 
	
		
			
				|  |  | +		where (mg.musical_instruments_provide_status_ = 1 AND mg.musical_instruments_provide_time_ = #{month}) OR (DATE_FORMAT(so.create_ime_,'%Y-%m') = #{month} AND (mg.musical_instruments_provide_status_ IS NULL OR mg.musical_instruments_provide_status_ = 1))
 | 
	
		
			
				|  |  |  		group by so.organ_id_
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  	<select id="sumCloudCourseAmount" resultType="java.util.Map">
 | 
	
	
		
			
				|  | @@ -248,7 +275,7 @@
 | 
	
		
			
				|  |  |  		where spro.calender_id_ IS NOT NULL AND spro.audit_status_ = 'PASS' AND mgpc.id_ = spro.calender_id_
 | 
	
		
			
				|  |  |  		group by mgpc.organ_id_
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  | -	<select id="sumMusicMagrin" resultType="java.util.Map">
 | 
	
		
			
				|  |  | +	<select id="sumMusicMargin" resultType="java.util.Map">
 | 
	
		
			
				|  |  |  		select mm.organ_id_ 'key',SUM(mm.balance_) 'value' from music_margin mm where mm.refund_flag_ = 0 group by mm.organ_id_;
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  |  	<select id="sumInternalSettlement" resultType="java.util.Map">
 | 
	
	
		
			
				|  | @@ -259,4 +286,14 @@
 | 
	
		
			
				|  |  |  		select fe.organ_id_ 'key',SUM(amount_) 'value' from financial_expenditure fe
 | 
	
		
			
				|  |  |  		where DATE_FORMAT(fe.create_time_,'%Y-%m') = #{month} AND fee_project_ = 3 AND process_id_ = 28 group by fe.organ_id_;
 | 
	
		
			
				|  |  |  	</select>
 | 
	
		
			
				|  |  | +	<select id="sumActivityUserMapperAmount" resultType="java.util.Map">
 | 
	
		
			
				|  |  | +		SELECT mgpc.organ_id_ 'key',(SUM(CASE WHEN aum.sub_course_num_ > 0 AND aum.category_id_ != 8 THEN aum.sub_course_num_ ELSE 0 END) +
 | 
	
		
			
				|  |  | +							   SUM(CASE WHEN aum.sub_give_course_num_ > 0 AND aum.give_category_id_ != 8 THEN aum.sub_give_course_num_ ELSE 0 END)) * oct.price_ 'value'
 | 
	
		
			
				|  |  | +		FROM activity_user_mapper aum
 | 
	
		
			
				|  |  | +				 LEFT JOIN music_group_payment_calender mgpc ON mgpc.id_ = aum.calender_id_
 | 
	
		
			
				|  |  | +				 LEFT JOIN organ_course_type_original_cost oct ON oct.course_type_ = 'VIP' AND oct.organ_id_ = mgpc.organ_id_
 | 
	
		
			
				|  |  | +		WHERE aum.calender_id_ IS NOT NULL AND return_fee_ = 0
 | 
	
		
			
				|  |  | +		  AND ((aum.sub_course_num_ > 0 AND aum.category_id_ != 8) OR (aum.sub_give_course_num_ > 0 AND aum.give_category_id_ != 8))
 | 
	
		
			
				|  |  | +		GROUP BY mgpc.organ_id_
 | 
	
		
			
				|  |  | +	</select>
 | 
	
		
			
				|  |  |  </mapper>
 |