2026-03-10 14:30:24 +08:00

1004 lines
38 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="SchoolAccount">
<!-- 查学校的对账单 -->
<select id="getSchoolAccountBySchoolId" parameterType="java.util.Map" resultType="SchoolAccountDto">
WITH a as ( SELECT classesId , classname , classlevel ,
schoolYear, classOrder
FROM Classes
WHERE SchoolId = #{schoolId} and status=1) ,
e as ( SELECT c.classesId , count( distinct o1.uid ) as payUserCount ,
count(o1.orderInfoId ) as transCount ,
sum( o1.amount ) as payAmount,
sum( o1.fees) as takeAmount, sum(og.years) as yearCount ,
sum( o1.amount - o1.fees ) as accountAmount
FROM ( select orderInfoId ,uid, created , areaId ,
amount , fees
from OrderInfo
where ispayed = 1 and payway &gt; 0
<if test="amount != null">
and amount = #{amount}
</if>
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN OrderOwnGoods as og
on o1.orderInfoId = og.orderInfoId
INNER JOIN StudentOwnClass as sc
on o1.uid = sc.studentId and sc.status = 1
INNER JOIN Classes as c
on sc.classesId = c.classesId and c.status=1
WHERE c.schoolId = #{schoolId}
GROUP BY c.classesId ),
f as ( SELECT t.schoolid as classesId , count( distinct o1.uid ) as payUserCount ,
count(o1.orderInfoId ) as transCount ,
sum( o1.amount ) as payAmount,
sum( o1.fees) as takeAmount, sum(og.years) as yearCount ,
sum( o1.amount - o1.fees ) as accountAmount
FROM ( select orderInfoId ,uid, created , areaId ,
amount , fees
from OrderInfo
where ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN OrderOwnGoods as og
on o1.orderInfoId = og.orderInfoId
INNER JOIN teacher as t
on o1.uid = t.teacherId and t.status = 1
and t.schoolId = #{schoolId}
GROUP BY t.schoolId )
SELECT a.classesId , a.classname , a.classlevel ,
a.schoolYear, a.classOrder ,
coalesce( e.payUserCount ,0 ) as payUserCount ,
coalesce( e.transCount , 0 ) as transCount ,
coalesce( e.payAmount , 0 ) as payAmount ,
coalesce( e.takeAmount , 0 ) as takeAmount ,
coalesce( e.accountAmount , 0 ) as accountAmount ,
coalesce( e.yearCount , 0 ) as yearCount,0 as studentCount,
1 as userType
FROM a
LEFT JOIN e
ON a.classesId = e.classesId
union all
SELECT classesId ,'教师' as classname , 0 classlevel ,
0 schoolYear, 0 classOrder ,
coalesce( e.payUserCount ,0 ) as payUserCount ,
coalesce( e.transCount , 0 ) as transCount ,
coalesce( e.payAmount , 0 ) as payAmount ,
coalesce( e.takeAmount , 0 ) as takeAmount ,
coalesce( e.accountAmount , 0 ) as accountAmount ,
coalesce( e.yearCount , 0 ) as yearCount,0 as studentCount,
2 as userType
from f as e
ORDER BY classesId
limit #{pageSize} offset #{offset}
</select>
<select id="getSchoolAccountCountBySchoolId" parameterType="Long" resultType="Integer">
select count(*) from Classes where schoolId = #{schoolId} and status = 1
</select>
<!-- 查学校的已支付明细 -->
<select id="getSchoolIsPayedBySchoolId" parameterType="java.util.Map" resultType="SchoolAccountDto">
WITH a as ( SELECT classesId , classname , classlevel ,
schoolYear, classOrder
FROM Classes
WHERE SchoolId = #{schoolId} and status = 1) ,
b as ( SELECT c.classesId , count( Distinct sc.studentId ) as studentCount
FROM student as a inner join StudentOwnClass as sc
ON a.studentId = sc.studentId and a.status = 1
INNER JOIN Classes as c
ON sc.status = 1 and sc.classesId = c.classesId and c.status = 1
WHERE c.schoolId = #{schoolId}
GROUP BY c.classesId ) ,
e as ( SELECT c.classesId , count( distinct o1.uid ) as payUserCount ,
count(o1.orderInfoId ) as transCount ,
sum( o1.amount ) as payAmount,
sum( o1.fees) as takeAmount, sum(og.years) as yearCount ,
sum( o1.amount - o1.fees ) as accountAmount
FROM ( select orderInfoId ,uid, created , areaId ,
amount , fees
from OrderInfo
where ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN OrderOwnGoods as og
on o1.orderInfoId = og.orderInfoId
INNER JOIN StudentOwnClass as sc
on o1.uid = sc.studentId and sc.status = 1
INNER JOIN Classes as c
on sc.classesId = c.classesId
WHERE c.schoolId = #{schoolId}
GROUP BY c.classesId ),
<!-- f as ( SELECT t.schoolid as classesId , count( distinct o1.uid ) as payUserCount ,
count(o1.orderInfoId ) as transCount ,
sum( o1.amount ) as payAmount,
sum( o1.fees) as takeAmount, sum(og.years) as yearCount ,
sum( o1.amount - o1.fees ) as accountAmount
FROM ( select orderInfoId ,uid, created , areaId ,
amount , fees
from OrderInfo
where ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN OrderOwnGoods as og
on o1.orderInfoId = og.orderInfoId
INNER JOIN teacher as t
on o1.uid = t.teacherId and t.status = 1
and t.schoolId = #{schoolId}
GROUP BY t.schoolId ) , -->
g as(
SELECT c.classesId,
count( distinct o1.uid ) as payUserCount ,
count(o1.orderInfoId ) as transCount ,
sum( o1.amount ) as payAmount,
sum( o1.fees) as takeAmount, sum(cd.months) as monthCount ,
sum( o1.amount - o1.fees ) as accountAmount
FROM ( select orderInfoId ,uid, created , areaId , fees, amount,orderno
from OrderInfo
where ispayed = -1 and payway=-100
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN student s
on s.studentid = o1.uid
inner join comppaydetail cd on cd.comppayinfoid=to_number(o1.orderno,'999999999G999D9S')
and cd.recognizecode=s.recognizecode and cd.usertype=1
iNNER JOIN StudentOwnClass as sc
ON o1.uid = sc.studentId
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1 and c.classtype = 1
WHERE c.schoolId = #{schoolId}
GROUP BY c.classesId),
h as (
SELECT c.classesId,
count( distinct o1.uid ) as payUserCount
FROM ( select uid
from OrderInfo
where (ispayed = 1 or ispayed=-1) and (payway &gt; 0 or payway=-100)
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
iNNER JOIN StudentOwnClass as sc
ON o1.uid = sc.studentId
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1 and c.classtype = 1
WHERE c.schoolId = #{schoolId}
GROUP BY c.classesId
),
m as (
select a.classesId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,c.classesId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid
and o.created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
and c.schoolid=#{schoolId}
group by o.uid,c.classesId ) as a
inner join
(select uid,count(uid) payCount,c.classesId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid
and <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
and c.schoolid=#{schoolId}
group by o.uid,c.classesId ) as b
on a.uid=b.uid
GROUP BY a.classesId
)
<!-- i as(
SELECT s.schoolId as classesId,
count( distinct o1.uid ) as payUserCount ,
count(o1.orderInfoId ) as transCount ,
sum( o1.amount ) as payAmount,
sum( o1.fees) as takeAmount, sum(cd.months) as monthCount ,
sum( o1.amount - o1.fees ) as accountAmount
FROM ( select orderInfoId ,uid, created , areaId ,fees, amount,orderno
from OrderInfo
where ispayed = -1 and payway=-100
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN teacher s
on s.teacherid = o1.uid
inner join comppaydetail cd on cd.comppayinfoid=to_number(o1.orderno,'999999999G999D9S')
and cd.recognizecode=s.loginno and cd.usertype=2
WHERE s.schoolId = #{schoolId}
GROUP BY s.schoolId), -->
<!-- j as (
SELECT t.schoolId as classesId,
count( distinct o1.uid ) as payUserCount
FROM ( select uid
from OrderInfo
where (ispayed = 1 or ispayed=-1) and (payway &gt; 0 or payway=-100)
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN teacher t on o1.uid=t.teacherid
WHERE t.schoolId= #{schoolId} group by schoolId
) -->
SELECT a.classesId , a.classname , a.classlevel ,
a.schoolYear, a.classOrder ,
coalesce( b.studentCount ,0 ) as studentCount ,
coalesce( e.payUserCount ,0 ) as payUserCount ,
coalesce( e.transCount , 0 ) as transCount ,
coalesce( e.payAmount , 0 ) as payAmount ,
coalesce( e.takeAmount , 0 ) as takeAmount ,
coalesce( e.accountAmount , 0 ) as accountAmount ,
coalesce( e.yearCount , 0 ) as yearCount,
1 as userType,
coalesce( h.payUserCount ,0 ) as payUserAllCount ,
coalesce( g.payUserCount ,0 ) as payUserCashCount ,
coalesce( g.monthCount , 0 ) as monthCount,
coalesce( m.renewCount , 0 ) as renewCount
FROM a
LEFT JOIN b
on a.classesId = b.classesId
LEFT JOIN e
ON a.classesId = e.classesId
LEFT JOIN g
ON a.classesId = g.classesId
LEFT JOIN h
ON a.classesId = h.classesId
LEFT JOIN m
ON a.classesId = m.classesId
<!-- union all
SELECT i.classesId ,'教师' as classname , 0 classlevel ,
0 schoolYear, 0 classOrder ,
0 as studentCount,
coalesce( e.payUserCount ,0 ) as payUserCount ,
coalesce( e.transCount , 0 ) as transCount ,
coalesce( e.payAmount , 0 ) as payAmount ,
coalesce( e.takeAmount , 0 ) as takeAmount ,
coalesce( e.accountAmount , 0 ) as accountAmount ,
coalesce( e.yearCount , 0 ) as yearCount,
2 as userType,
coalesce( j.payUserCount ,0 ) as payUserAllCount ,
coalesce( i.payUserCount ,0 ) as payUserCashCount ,
coalesce( i.monthCount , 0 ) as monthCount
from j
LEFT join
f e on e.classesid=i.classesid
LEFT join
i on i.classesid=j.classesid -->
ORDER BY a.classesId
limit #{pageSize} offset #{offset}
</select>
<!-- 获取未到期 到期 全部的学校班级统计信息 -->
<select id ="getSchoolIsNotPayedAll" parameterType="java.util.Map" resultType="SchoolAccountDto">
with temp1 as (select classesId,className,classLevel,schoolYear,classorder from classes where schoolid =#{schoolId} and classtype = 1 and status =1 GROUP BY classesId),
temp3 as ( select uid from orderinfo
where ispayed =1 and payway &gt; 0
and created &gt; #{startTime} and created &lt;#{endTime}
and areaid = #{areaId} ) ,
temp4 as (select uo.uid, so.classesid as classesid
from UserOwnLesson uo
inner join StudentOwnClass so on uo.uid = so.studentid and so.status =1 and so.areaid = #{areaId}
inner join Classes c on c.classesid = so.classesid and c.classtype = 1 and c.status = 1
and c.schoolid = #{schoolId}
where uo.areaid = #{areaId} and uo.endtime is not null
and uo.uid not in (select uid from temp3)
group by uo.uid,so.classesid
<if test="expire == 0">
having max(uo.endtime) &lt; now() <!-- 过期 -->
</if>
<if test="expire==1">
having max(uo.endtime) &gt; now() <!-- 未过期-->
</if>
)
select a.classesId,a.className,a.classLevel,a.schoolYear,a.classOrder,count(b.classesid) as numberCount
from temp1 as a left join temp4 as b on a.classesId = b.classesid GROUP BY a.classesId,a.className,a.classLevel,a.schoolYear,a.classorder order by a.classesId
</select>
<select id="getSchoolIsNotPayedBySchoolIdExpire" parameterType="java.util.Map" resultType="SchoolAccountDto">
select distinct(c.classesId) as classesId , c.classname as className , c.classlevel as classLevel ,
c.schoolyear as schoolYear, c.classorder as classOrder, count(distinct(uo.uid)) as numberCount
from classes c
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,min(so.classesid) as classesid
from UserOwnLesson uo
inner join StudentOwnClass so on uo.uid = so.studentid and so.status =1
inner join Classes c on c.classesid = so.classesid and c.classtype = 1 and c.status = 1
group by uid
) uo on uo.classesid = c.classesid
and uo.uid in
(select s.studentId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId and so.status =1
inner join Classes c on c.classesId = so.classesId and c.classtype = 1 and c.status = 1
and c.schoolId= #{schoolId}
where s.studentId not in (select uid from orderinfo where payway &gt;0 and ispayed = 1
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
))
and uo.endTime &lt; now()
where c.schoolid = #{schoolId} and c.classtype = 1 and c.status = 1
group by c.classesId
order by c.classesId
limit #{pageSize} offset #{offset}
</select>
<select id="getSchoolIsNotPayedBySchoolIdNotExpire" parameterType="java.util.Map" resultType="SchoolAccountDto">
select distinct(c.classesId) as classesId , c.classname as className , c.classlevel as classLevel ,
c.schoolyear as schoolYear, c.classorder as classOrder, count(distinct(uo.uid)) as numberCount
from classes c
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,min(so.classesid) as classesid
from UserOwnLesson uo
inner join StudentOwnClass so on uo.uid = so.studentid and so.status =1
inner join Classes c on c.classesid = so.classesid and c.classtype = 1 and c.status = 1
group by uid
) uo on uo.classesid = c.classesid
and uo.uid in
(select s.studentId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId and so.status =1
inner join Classes c on c.classesId = so.classesId and c.classtype = 1 and c.status = 1
and c.schoolId= #{schoolId}
where s.studentId not in (select uid from orderinfo where payway &gt;0 and ispayed = 1
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
))
<if test="expire==1">
and uo.endTime &gt;= now()
</if>
<if test="expire==2">
and uo.endTime is not null
</if>
where c.schoolid = #{schoolId} and c.classtype = 1 and c.status = 1
group by c.classesId
order by c.classesId
limit #{pageSize} offset #{offset}
</select>
<select id="getAccountCountBySchoolIdByStudent" parameterType="java.util.Map" resultType="SchoolAccountDto">
select c.classesId as classesId , c.classname as className ,
c.classlevel as classLevel , c.schoolyear as schoolYear,
c.classorder as classOrder, count( sc.studentId ) as numberCount
from Classes c
left join StudentOwnClass sc
on sc.classesId = c.classesId and sc.status =1
where c.schoolId = #{schoolId} and c.classtype = 1 and c.status = 1
group by c.classesId
order by c.classesId
limit #{pageSize} offset #{offset}
</select>
<select id="getDataAccountBySchoolIdByChange" parameterType="java.util.Map" resultType="java.util.HashMap">
select distinct(c.classesId) as classesId, c.className as className, c.classlevel as classLevel , c.schoolyear as schoolYear, c.classorder as classOrder,
count(distinct(ss.studentId)) as payAmount ,count(distinct(o.uid)) as takeAmount ,
case when count(distinct(ss.studentId)) = 0.0000 then 0 else
round(count(distinct(o.uid))*100::numeric/count(distinct(ss.studentId)::numeric),4) end as accountAmount
from Classes c
left join (
select s.studentId , c.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId and so.status = 1
inner join Classes c on c.classesId = so.classesId and c.classtype = 1 and c.status = 1
inner join School sc on c.schoolId = sc.schoolId and sc.schoolId=#{schoolId}
) ss on ss.classesId = c.classesId
left join OrderInfo o on o.uid = ss.studentId and o.ispayed =1 and o.payway &gt;0
<if test="startTime!=null">
<![CDATA[
and o.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o.created < #{endTime}
]]>
</if>
left join OrderOwnGoods oo on o.orderInfoId = oo.orderInfoId
left join Goods g on g.goodsId = oo.goodsId
where c.schoolId = #{schoolId} and c.classtype = 1 and c.status = 1
group by c.classesId
order by c.classesId
limit #{pageSize} offset #{offset}
</select>
<select id="getDataAccountBySchoolIdByUse" parameterType="java.util.Map" resultType="java.util.HashMap">
with temp as(
select count( distinct(sd.studentid)) studentbytimecount,c.classesId from studentownclass st
inner join classes c
on st.classesid=c.classesid and c.classtype=1 and c.status=1 and c.schoolid=#{schoolId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
inner join student sd on st.studentid=sd.studentid
<![CDATA[
and sd.created>=#{startTime} and sd.created<#{endTime} and sd.status=1
]]>
group by c.classesId
),
temp2 as(
select distinct(c.classesId) as classesId, c.className as className, c.classlevel as classLevel , c.schoolyear as schoolYear, c.classorder as classOrder,
count(distinct(ss.studentId)) as payAmount ,count(case when ss.endTime isnull then null else 1 end) as takeAmount ,
case when count(distinct(ss.studentId)) = 0 then 0.00 else
round(count(case when ss.endTime isnull then null else 1 end)*100::numeric/count(distinct(ss.studentId)::numeric),2) end as accountAmount,
count(case when ss.lastsignin&gt;now()-interval '1 month' then 1 else null end) as activeAmount,
count(case when ss.lastsignin&gt;now()-interval '1 week' then 1 else null end) as weekActiveAmount,
count(case when ss.lastsignin&gt;now()-interval '1 day' then 1 else null end) as dayActiveAmount,
<![CDATA[
count(distinct ss.uid) as useAmount
]]>
from Classes c
left join (
select s.studentId ,co.uid, c.classesId , s.lastsignin , max(co.endTime) as endTime from Student s
inner join StudentOwnClass so on so.studentId = s.studentId and so.status = 1 and s.status=1
inner join Classes c on c.classesId = so.classesId and c.classtype = 1 and c.status = 1
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
inner join School sc on c.schoolId = sc.schoolId and sc.schoolId=#{schoolId}
left join connectlog co on co.uid = s.studentid
<if test="startTime!=null">
<![CDATA[
and co.starttime > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and co.starttime < #{endTime}
]]>
</if>
group by s.studentId ,c.classesId,s.lastsignin,co.uid
) ss on ss.classesId = c.classesId
where c.schoolId = #{schoolId} and c.classtype = 1 and c.status = 1
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
group by c.classesId
),
cn as ( select distinct uid from connectlog where <![CDATA[
starttime>=#{startTime} and starttime <#{endTime}
]]>
),
temp3 as(
select count( distinct(sd.studentid)) studentLoginbytimeCount,c.classesId from studentownclass st
inner join classes c
on st.classesid=c.classesid and c.classtype=1 and c.status=1 and c.schoolid=#{schoolId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
inner join student sd on st.studentid=sd.studentid and sd.status=1
<![CDATA[
and sd.created>=#{startTime} and sd.created<#{endTime}
]]>
inner join cn on sd.studentid=cn.uid
group by c.classesId
),
temp4 as(select a.classesId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,c.classesId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid
and o.created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
and c.schoolid=#{schoolId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
group by o.uid,c.classesId ) as a
inner join
(select uid,count(uid) payCount,c.classesId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid
and <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
and c.schoolid=#{schoolId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
group by o.uid,c.classesId ) as b
on a.uid=b.uid
GROUP BY a.classesId)
select t2.classesId,className,classLevel ,schoolYear, classOrder,payAmount ,takeAmount ,
coalesce( accountAmount ,0.00 ) accountAmount, activeAmount,weekActiveAmount,dayActiveAmount,useAmount,coalesce( t.studentbytimecount ,0 ) as studentbytimecount,
case when coalesce( t.studentbytimeCount ,0 ) = 0 then 0.00
when coalesce(t3.studentLoginbytimeCount ,0 ) = 0 then 0.00 else
round( (t3.studentLoginbytimeCount * 100)::numeric / t.studentbytimeCount::numeric , 2 )
end as accountAmountbyTime,
coalesce( t4.renewCount ,0 ) renewCount
from temp2 t2 left join temp t on t.classesid=t2.classesid
left join temp3 t3 on t3.classesid=t2.classesid
left join temp4 t4 on t4.classesid=t2.classesid
order by t2.classesId
limit #{pageSize} offset #{offset}
</select>
<!-- <select id="getDataAccountBySchoolIdByUseNew1" parameterType="java.util.Map" resultType="java.util.HashMap">-->
<!-- with temp as(-->
<!-- select count( distinct(sd.studentid)) studentbytimecount,c.classesId from studentownclass st-->
<!-- inner join classes c-->
<!-- on st.classesid=c.classesid and c.classtype=1 and c.status=1 and c.schoolid=#{schoolId} and st.areaId = #{areaId}-->
<!-- <if test="schoolYear!=null">-->
<!-- and c.schoolyear=#{schoolYear}-->
<!-- </if>-->
<!-- inner join student sd on st.studentid=sd.studentid and sd.areaId = #{areaId}-->
<!-- <if test="startTime!=null">-->
<!-- <![CDATA[-->
<!-- and sd.created>=#{startTime} and sd.created<#{endTime}-->
<!-- ]]>-->
<!-- </if>-->
<!-- and sd.status=1-->
<!-- group by c.classesId-->
<!-- ),-->
<!-- schoolstudent as (-->
<!-- select s.studentId , c.classesId , s.lastsignin from Student s-->
<!-- inner join StudentOwnClass so on so.studentId = s.studentId and so.status = 1 and s.status=1 and so.areaId = #{areaId} and s.areaId = #{areaId}-->
<!-- inner join Classes c on c.classesId = so.classesId and c.classtype = 1 and c.status = 1-->
<!-- <if test="schoolYear!=null">-->
<!-- and c.schoolyear=#{schoolYear}-->
<!-- </if>-->
<!-- inner join School sc on c.schoolId = sc.schoolId and sc.schoolId=#{schoolId}-->
<!-- ),-->
<!-- onlineStudent as (-->
<!-- select s.studentId ,co.uid, s.classesId , s.lastsignin , max(co.endTime) as endTime from schoolstudent as s-->
<!-- inner join connectlog co on co.uid = s.studentid-->
<!-- <if test="startTime!=null">-->
<!-- <![CDATA[-->
<!-- and co.starttime > #{startTime}-->
<!-- ]]>-->
<!-- </if>-->
<!-- <if test="endTime!=null">-->
<!-- <![CDATA[-->
<!-- and co.starttime < #{endTime}-->
<!-- ]]>-->
<!-- </if>-->
<!-- and co.areaid = #{areaId}-->
<!-- group by s.studentId ,s.classesId,s.lastsignin,co.uid-->
<!-- ),-->
<!-- notOnlineStudent as (-->
<!-- select s.studentId , s.classesId from schoolstudent as s-->
<!-- where s.studentId not in (select DISTINCT uid from onlineStudent )-->
<!-- ),-->
<!-- temp2 as(-->
<!-- select distinct(c.classesId) as classesId, c.className as className, c.classlevel as classLevel , c.schoolyear as schoolYear, c.classorder as classOrder,-->
<!-- (count(distinct(ss.studentId))+count(distinct ss.uid)) as payAmount ,count(case when ss.endTime isnull then null else 1 end) as takeAmount ,-->
<!-- case when count(distinct(ss.studentId)) = 0 then 0.00 else-->
<!-- round(count(case when ss.endTime isnull then null else 1 end)*100::numeric/count(distinct(ss.studentId)::numeric),2) end as accountAmount,-->
<!-- count(case when ss.lastsignin&gt;now()-interval '1 month' then 1 else null end) as activeAmount,-->
<!-- count(case when ss.lastsignin&gt;now()-interval '1 week' then 1 else null end) as weekActiveAmount,-->
<!-- count(case when ss.lastsignin&gt;now()-interval '1 day' then 1 else null end) as dayActiveAmount,-->
<!-- <![CDATA[-->
<!-- count(distinct ss.uid) as useAmount-->
<!-- ]]>,-->
<!-- <![CDATA[-->
<!-- count(distinct nss.studentId) as notUseAmount-->
<!-- ]]>-->
<!-- from Classes c-->
<!-- left join onlineStudent ss on ss.classesId = c.classesId-->
<!-- left join notOnlineStudent nss on nss.classesId = c.classesId-->
<!-- where c.schoolId = #{schoolId} and c.classtype = 1 and c.status = 1-->
<!-- <if test="schoolYear!=null">-->
<!-- and c.schoolyear=#{schoolYear}-->
<!-- </if>-->
<!-- group by c.classesId-->
<!-- ),-->
<!-- cn as ( select distinct uid from connectlog where areaid = #{areaId}-->
<!-- <if test="startTime!=null">-->
<!-- <![CDATA[-->
<!-- and starttime>=#{startTime} and starttime <#{endTime}-->
<!-- ]]>-->
<!-- </if>-->
<!-- ),-->
<!-- temp3 as(-->
<!-- select count( distinct(sd.studentid)) studentLoginbytimeCount,c.classesId from studentownclass st-->
<!-- inner join classes c-->
<!-- on st.classesid=c.classesid and c.classtype=1 and c.status=1 and c.schoolid=#{schoolId} and st.areaId = #{areaId}-->
<!-- <if test="schoolYear!=null">-->
<!-- and c.schoolyear=#{schoolYear}-->
<!-- </if>-->
<!-- inner join student sd on st.studentid=sd.studentid and sd.status=1 and sd.areaId = #{areaId}-->
<!-- <if test="startTime!=null">-->
<!-- <![CDATA[-->
<!-- and sd.created>=#{startTime} and sd.created<#{endTime}-->
<!-- ]]>-->
<!-- </if>-->
<!-- inner join cn on sd.studentid=cn.uid-->
<!-- group by c.classesId-->
<!-- ),-->
<!-- temp4 as(select a.classesId,-->
<!-- count(a.uid) as renewCount-->
<!-- from-->
<!-- ( select uid,count(uid) payCount,c.classesId from orderinfo o-->
<!-- inner join studentownclass soc on soc.studentid=o.uid and soc.areaId = #{areaId}-->
<!-- <if test="startTime!=null">-->
<!-- and o.created&lt;#{startTime}-->
<!-- </if>-->
<!-- and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)-->
<!-- and soc.status=1-->
<!-- inner join classes c on c.classesid=soc.classesid and c.classtype=1-->
<!-- and c.schoolid=#{schoolId}-->
<!-- <if test="schoolYear!=null">-->
<!-- and c.schoolyear=#{schoolYear}-->
<!-- </if>-->
<!-- group by o.uid,c.classesId ) as a-->
<!-- inner join-->
<!-- (select uid,count(uid) payCount,c.classesId from orderinfo o-->
<!-- inner join studentownclass soc on soc.studentid=o.uid and soc.areaId = #{areaId}-->
<!-- <if test="startTime!=null">-->
<!-- <![CDATA[-->
<!-- and created>=#{startTime} and created<#{endTime}-->
<!-- ]]>-->
<!-- </if>-->
<!-- and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)-->
<!-- and soc.status=1-->
<!-- inner join classes c on c.classesid=soc.classesid and c.classtype=1-->
<!-- and c.schoolid=#{schoolId}-->
<!-- <if test="schoolYear!=null">-->
<!-- and c.schoolyear=#{schoolYear}-->
<!-- </if>-->
<!-- group by o.uid,c.classesId ) as b-->
<!-- on a.uid=b.uid-->
<!-- GROUP BY a.classesId)-->
<!-- select t2.classesId,className,classLevel ,schoolYear, classOrder,payAmount ,takeAmount ,-->
<!-- coalesce( accountAmount ,0.00 ) accountAmount, activeAmount,weekActiveAmount,dayActiveAmount,useAmount,coalesce( t.studentbytimecount ,0 ) as studentbytimecount,notUseAmount,-->
<!-- case when coalesce( t.studentbytimeCount ,0 ) = 0 then 0.00-->
<!-- when coalesce(t3.studentLoginbytimeCount ,0 ) = 0 then 0.00 else-->
<!-- round( (t3.studentLoginbytimeCount * 100)::numeric / t.studentbytimeCount::numeric , 2 )-->
<!-- end as accountAmountbyTime,-->
<!-- coalesce( t4.renewCount ,0 ) renewCount-->
<!-- from temp2 t2 left join temp t on t.classesid=t2.classesid-->
<!-- left join temp3 t3 on t3.classesid=t2.classesid-->
<!-- left join temp4 t4 on t4.classesid=t2.classesid-->
<!-- order by t2.classesId-->
<!-- limit #{pageSize} offset #{offset}-->
<!-- </select>-->
<select id="getDataAccountBySchoolIdByUseNew1" parameterType="java.util.Map" resultType="java.util.HashMap">
with temp as(
select count( distinct(sd.studentid)) studentbytimecount,c.classesId from studentownclass st
inner join classes c
on st.classesid=c.classesid and c.classtype=1 and c.status=1 and c.schoolid=#{schoolId} and st.areaId = #{areaId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
inner join student sd on st.studentid=sd.studentid and sd.areaId = #{areaId}
<if test="startTime!=null">
<![CDATA[
and sd.created>=#{startTime} and sd.created<#{endTime}
]]>
</if>
and sd.status=1
group by c.classesId
),
temp2 as(
select distinct(c.classesId) as classesId, c.className as className, c.classlevel as classLevel , c.schoolyear as schoolYear, c.classorder as classOrder,
count(distinct(ss.studentId)) as payAmount ,count(case when ss.endTime isnull then null else 1 end) as takeAmount ,
case when count(distinct(ss.studentId)) = 0 then 0.00 else
round(count(case when ss.lastsignin is null then null else 1 end)*100::numeric/count(distinct(ss.studentId)::numeric),2) end as accountAmount,
count(case when ss.lastsignin&gt;now()-interval '1 month' then 1 else null end) as activeAmount,
count(case when ss.lastsignin&gt;now()-interval '1 week' then 1 else null end) as weekActiveAmount,
count(case when ss.lastsignin&gt;now()-interval '1 day' then 1 else null end) as dayActiveAmount,
<![CDATA[
count(distinct ss.uid) as useAmount
]]>
from Classes c
left join (
select s.studentId ,co.uid, c.classesId , s.lastsignin , max(co.endTime) as endTime from Student s
inner join StudentOwnClass so on so.studentId = s.studentId and so.status = 1 and s.status=1 and so.areaId = #{areaId} and s.areaId = #{areaId}
inner join Classes c on c.classesId = so.classesId and c.classtype = 1 and c.status = 1
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
inner join School sc on c.schoolId = sc.schoolId and sc.schoolId=#{schoolId}
left join connectlog co on co.uid = s.studentid
<if test="startTime!=null">
<![CDATA[
and co.starttime > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and co.starttime < #{endTime}
]]>
</if>
and co.areaid = #{areaId}
group by s.studentId ,c.classesId,s.lastsignin,co.uid
) ss on ss.classesId = c.classesId
where c.schoolId = #{schoolId} and c.classtype = 1 and c.status = 1
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
group by c.classesId
),
cn as ( select distinct uid from connectlog where areaid = #{areaId}
<if test="startTime!=null">
<![CDATA[
and starttime>=#{startTime} and starttime <#{endTime}
]]>
</if>
),
temp3 as(
select count( distinct(sd.studentid)) studentLoginbytimeCount,c.classesId from studentownclass st
inner join classes c
on st.classesid=c.classesid and c.classtype=1 and c.status=1 and c.schoolid=#{schoolId} and st.areaId = #{areaId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
inner join student sd on st.studentid=sd.studentid and sd.status=1 and sd.areaId = #{areaId}
<if test="startTime!=null">
<![CDATA[
and sd.created>=#{startTime} and sd.created<#{endTime}
]]>
</if>
inner join cn on sd.studentid=cn.uid
group by c.classesId
),
temp4 as(select a.classesId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,c.classesId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid and soc.areaId = #{areaId}
<if test="startTime!=null">
and o.created&lt;#{startTime}
</if>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
and c.schoolid=#{schoolId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
group by o.uid,c.classesId ) as a
inner join
(select uid,count(uid) payCount,c.classesId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid and soc.areaId = #{areaId}
<if test="startTime!=null">
<![CDATA[
and created>=#{startTime} and created<#{endTime}
]]>
</if>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
and c.schoolid=#{schoolId}
<if test="schoolYear!=null">
and c.schoolyear=#{schoolYear}
</if>
group by o.uid,c.classesId ) as b
on a.uid=b.uid
GROUP BY a.classesId)
select t2.classesId,className,classLevel ,schoolYear, classOrder,payAmount ,takeAmount ,
coalesce( accountAmount ,0.00 ) accountAmount, activeAmount,weekActiveAmount,dayActiveAmount,useAmount,coalesce( t.studentbytimecount ,0 ) as studentbytimecount,
case when coalesce( t.studentbytimeCount ,0 ) = 0 then 0.00
when coalesce(t3.studentLoginbytimeCount ,0 ) = 0 then 0.00 else
round( (t3.studentLoginbytimeCount * 100)::numeric / t.studentbytimeCount::numeric , 2 )
end as accountAmountbyTime,
coalesce( t4.renewCount ,0 ) renewCount
from temp2 t2 left join temp t on t.classesid=t2.classesid
left join temp3 t3 on t3.classesid=t2.classesid
left join temp4 t4 on t4.classesid=t2.classesid
order by t2.classesId
limit #{pageSize} offset #{offset}
</select>
<select id="getSchoolYearBySchoolId" parameterType="java.util.Map" resultType="java.util.HashMap">
select c.schoolyear as schoolYear from classes c where c.schoolid=#{schoolId} and c.status=1 and c.classtype=1
<if test="startTime!=null">
and created &gt; #{startTime}
</if>
<if test="endTime!=null">
and created &lt; #{endTime}
</if>
group by c.schoolyear order by c.schoolyear desc
</select>
</mapper>