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

3036 lines
115 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="AreaAccount">
<!-- 区级查询-->
<!-- 获取地域下所有学校 以及学校对应的班级数量 -->
<sql id="sql_isNotPayed_bySchool">
with temp0 as ( select * from School where areaid = #{areaId} ) ,
temp1 as ( select a.schoolid , count( a.classesid ) as classcount
from classes a
where a.areaid = #{areaId} and a.status = 1 and a.classtype = 1
group by a.schoolid ) ,
</sql>
<!-- 查询 区级下 学校 未缴费数量 已到期 和未到期 -->
<sql id="sql_isNotPayed_bySchool_Expired">
temp3 as ( select uid from orderinfo
where payway = 0 and isdeleted = 0
and created &gt; #{startTime} and created &lt; #{endTime}
and areaid = #{areaId} ) ,
temp4 as ( select b.uid , max( b.endtime ) as endtime
from UserOwnLesson b
where b.areaid = #{areaId}
and b.uid not in ( select uid from temp3 )
group by b.uid
<if test="expire == 0">
having max( b.endtime ) &lt; now() <!-- 过期 -->
</if>
<if test="expire == 1">
having max( b.endtime ) &gt; now() <!-- 未过期 -->
</if>
) ,
temp2 as ( select a.schoolid ,
count( b.studentid ) as studentcount
from classes a
inner join StudentOwnClass b
on a.status = 1 and a.areaid = #{areaId}
and a.classesid = b.classesid and b.status = 1 and b.areaid = #{areaId}
inner join temp4 c
on b.studentid = c.uid
group by schoolid )
</sql>
<!-- sql片段未支付查询结果为学校 -->
<sql id="sql_IsNotPayed_BySchool_main_S">
select a.schoolid as objectId , a.schoolname as objectName ,case when b.classcount is null then 0 else b.classcount end as numbercount ,
case when c.studentcount is null then 0 else c.studentcount end as payAmount
from temp0 a
left join temp1 b
on a.schoolid = b.schoolid
left join temp2 c
on a.schoolid = c.schoolid
order by a.schoolid
<if test="pageSize != '' and offset != ''">
limit #{pageSize} offset #{offset}
</if>
</sql>
<!-- 查询父级地区下 自己区域数量及详情 -->
<sql id="sql_isNotPayed_byParentId">
with temp0 as ( select * from Area where parentid = #{areaId} ) ,
temp5 as (select a.parentid, count(a.areaid) as areaCount from area as a inner join temp0 as b on a.parentid = b.areaid
group by a.parentid ),
</sql>
<!-- 获取 地域下学校数量 -->
<sql id="sql_isNotPayed_schoolCount">
temp1 as ( select ${floor_str} as areaid ,
count(*) as schoolcount
from School a
where a.status = 1
and a.areaid &gt; #{startArea} and a.areaid &lt; #{endArea}
group by ${floor_str} ),
</sql>
<!-- 查询结果区域 未支付的 -->
<sql id="sql_isNotPayed_byParentId_expireId">
temp3 as ( select uid from orderinfo
where payway &gt; 0 and ispayed = 1
and isdeleted = 0
and created &gt; #{startTime} and created &lt; #{endTime}
and areaid &gt; #{startArea} and areaid &lt; #{endArea} ) ,
temp4 as ( select b.uid , max( b.endtime ) as endtime
from UserOwnLesson b
inner join StudentOwnClass so on b.uid = so.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.status=1
where b.areaid &gt; #{startArea} and b.areaid &lt; #{endArea}
and b.uid not in ( select uid from temp3 )
group by b.uid
<if test="expire == 0">
having max( b.endtime ) &lt; now() <!-- 过期 -->
</if>
<if test="expire == 1">
having max( b.endtime ) &gt; now() <!-- 未过期 -->
</if>
) ,
temp2 as ( select ${floor_str} as areaid ,
count( a.studentid ) as studentcount
from Student a
inner join temp4 b
on a.status = 1 and a.areaid &gt; #{startArea} and a.areaid &lt; #{endArea}
and a.studentid = b.uid
group by ${floor_str} )
</sql>
<!-- 查询地区 市级 未支付 总查询 -->
<sql id="sql_isNotPayed_byParentId_main_A">
select a.areaid as objectId, a.areaname as objectName ,case when b.schoolcount is null then 0 else b.schoolcount end as numbercount ,
case when c.studentcount is null then 0 else c.studentcount end as payAmount
from temp0 a
left join temp1 b
on a.areaid = b.areaid
left join temp2 c
on a.areaid = c.areaid
order by a.areaid
<if test="pageSize != '' and offset != ''">
limit #{pageSize} offset #{offset}
</if>
</sql>
<!-- 查询地区 省级 未支付 总查询 -->
<sql id="sql_isNotPayed_byParentId_main_B">
select a.areaid as objectId, a.areaname as objectName ,case when d.areaCount is null then 0 else d.areaCount end as numberCount,
case when c.studentcount is null then 0 else c.studentcount end as payAmount
from temp0 a
<!-- left join temp1 b
on a.areaid = b.areaid -->
left join temp2 c
on a.areaid = c.areaid
left join temp5 d
on d.parentid = a.areaid
order by a.areaid
<if test="pageSize != '' and offset != ''">
limit #{pageSize} offset #{offset}
</if>
</sql>
<!-- 查全国各省的对账单 -->
<select id="getAreaAccountByAll" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT a2.parentId , count( distinct a2.areaId ) as numberCount ,
count( st.studentId ) as studentCount
FROM Student as st
INNER JOIN Area as a1
ON st.areaId = a1.areaId
INNER JOIN Area as a2
ON a1.parentId = a2.areaId
GROUP BY a2.parentId ) ,
e as ( SELECT a2.parentId , 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 Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
GROUP BY a2.parentId )
SELECT a.areaId as objectId, a.areaName as objectName,
coalesce( b.numberCount , 0 ) as numberCount ,
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
FROM a
LEFT JOIN b
ON a.areaId = b.parentId
LEFT JOIN e
ON a.areaId = e.parentId
ORDER BY a.areaId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<!-- 查某省各个市的对账单 -->
<select id="getAreaAccountByBaseId" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT a1.parentId , count( distinct a1.areaId ) as numberCount ,
count(st.studentId ) as studentCount
FROM Student as st
INNER JOIN Area as a1
ON st.status = 1 and st.areaId = a1.areaId
INNER JOIN Area as a2
ON a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ) ,
e as ( SELECT a1.parentId , 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 Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId )
SELECT a.areaId as objectId, a.areaName as objectName,
coalesce( b.numberCount , 0 ) as numberCount ,
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
FROM a
LEFT JOIN b
ON a.areaId = b.parentId
LEFT JOIN e
ON a.areaId = e.parentId
ORDER BY a.areaId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<!-- 查某市下面各县的对账单 -->
<select id="getAreaAccountByParentId" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT s.areaid , count( s.schoolId) as numberCount
FROM School as s
INNER JOIN Area as a1
ON s.status = 1 and s.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY s.areaid ) ,
e as ( SELECT a1.areaId , 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 a.orderInfoId ,a.uid, a.created , c.areaId ,a.amount , a.fees from OrderInfo as a inner join
studentownclass as b on a.uid =b.studentid inner join classes as d on b.classesid = d.classesid inner join
school as c on d.schoolid = c.schoolid where a.ispayed = 1 and a.payway> 0
<if test="amount != null">
and a.amount = #{amount}
</if>
<if test="startTime!=null">
<![CDATA[
and a.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and a.created < #{endTime}]]>
</if>
) as o1
<!-- 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 Area as a1
on o1.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId )
SELECT a.areaId as objectId, a.areaName as objectName,
coalesce( b.numberCount , 0 ) as numberCount ,
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
FROM a
LEFT JOIN b
ON a.areaId = b.areaId
LEFT JOIN e
ON a.areaId = e.areaId
ORDER BY a.areaId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<select id="getAreaAccountCountByParentId" parameterType="Integer" resultType="Integer">
select count(*) from Area where parentId = #{areaId}
</select>
<select id="getAreaAccountCountByBaseId" parameterType="Integer" resultType="Integer">
select count(*) from Area where parentId = #{areaId}
</select>
<!-- 按县来查对账单 -->
<select id="getAreaAccountByAreaId" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT schoolId , schoolname FROM School
where areaId = #{areaId} and status=1) ,
b as ( SELECT c.schoolId , count( distinct c.classesId) as classCount ,
count(st.studentId ) as studentCount
FROM Student as st
INNER JOIN StudentOwnClass as sc
ON st.status = 1 and st.studentId = sc.studentId
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1 and c.classtype = 1
WHERE st.areaId = #{areaId}
GROUP BY c.schoolId ) ,
e as ( SELECT c.schoolId , 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 a.orderInfoId ,a.uid, a.created , c.areaId ,a.amount , a.fees from OrderInfo as a inner join
studentownclass as b on a.uid =b.studentid inner join classes as d on b.classesid = d.classesid inner join
school as c on d.schoolid = c.schoolid where a.ispayed = 1 and a.payway &gt; 0
<if test="amount != null">
and a.amount = #{amount}
</if>
<if test="startTime!=null">
<![CDATA[
and a.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and a.created < #{endTime}]]>
</if>
) as o1
<!-- 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
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1 and c.classtype = 1
WHERE o1.areaId = #{areaId}
GROUP BY c.schoolId ),
f as(
SELECT t.schoolId , 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 t on t.teacherid=o1.uid and t.status=1
and t.areaid=#{areaId} group by t.schoolid
),
g as(select schoolid,sum (payUserCount) payUserCount,sum(transCount) transCount,sum(payAmount) payAmount,
sum(takeAmount) takeAmount,sum(yearCount) yearCount,sum(accountAmount) accountAmount
from (select * from e union all select * from f) as h group by schoolId )
SELECT a.schoolId as objectId, a.schoolname as objectName,
coalesce( b.classCount , 0 ) as numberCount ,
coalesce( b.classCount , 0 ) as classCount ,
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
FROM a
LEFT JOIN b
ON a.schoolId = b.schoolId
LEFT JOIN g e
ON a.schoolId = e.schoolId
ORDER BY a.schoolId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<select id="getAreaAccountCountByAreaId" parameterType="Integer" resultType="Integer">
select count(*) from School where areaId = #{areaId} and status = 1
</select>
<!-- 查全国多少个省 -->
<select id="getAreaAccountCountByAll" parameterType="Integer" resultType="Integer">
select count(*) from Area where parentid = 0
</select>
<!-- 查全国各个省的已支付 -->
<select id="getAreaIsPayedByAll" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT a2.parentId , count( distinct a2.areaId ) as numberCount ,
count(st.studentId ) as studentCount
FROM Student as st
INNER JOIN Area as a1
ON st.areaId = a1.areaId
INNER JOIN Area as a2
ON a1.parentId = a2.areaId
GROUP BY a2.parentId ) ,
c as ( SELECT a2.parentId ,
count( s.schoolId ) as schoolCount
FROM School as s
INNER JOIN Area as a1
ON s.status = 1 and s.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
GROUP BY a2.parentId ) ,
d as ( SELECT a2.parentId ,
count( c1.classesId ) as classCount
FROM Classes as c1
INNER JOIN Area as a1
ON c1.status = 1 and c1.classtype =1 and c1.areaId = a1.areaId
INNER JOIN Area as a2
ON a1.parentId = a2.areaId
GROUP BY a2.parentId ) ,
e as ( SELECT a2.parentId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(og.years) as yearCount
FROM ( select orderInfoId ,uid, created , areaId , amount
from OrderInfo
where ispayed = 1 and payway &gt; 0
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
<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 Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
GROUP BY a2.parentId ),
f as(
SELECT a2.parentId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , 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 Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
GROUP BY a2.parentId ),
<!-- g as(
SELECT a2.parentId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , 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
INNER JOIN Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
GROUP BY a2.parentId ), -->
h as(
SELECT a2.parentId ,
count( distinct o1.uid ) as payUserCount
FROM ( select orderInfoId ,uid, created , areaId , amount
from OrderInfo
where (ispayed = 1 or ispayed=-1) and (payway &gt; 0 or payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
GROUP BY a2.parentId),
m as(
select floor( a.areaId / 10000) * 10000 as tempAreaId ,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY floor( a.areaId / 10000) * 10000)
SELECT a.areaId as objectId, a.areaName as objectName,
coalesce( b.numberCount , 0 ) as numberCount ,
coalesce( c.schoolCount , 0 ) as schoolCount ,
coalesce( d.classCount , 0 ) as classCount ,
coalesce( b.studentCount , 0 ) as studentCount ,
coalesce( e.payUserCount , 0 ) as payUserCount ,
coalesce( e.payAmount , 0 ) as payAmount ,
coalesce( e.yearCount , 0 ) as yearCount,
coalesce( h.payUserCount , 0 ) as payUserAllCount ,
coalesce( f.payUserCount , 0 ) as payUserCashCount ,
coalesce( f.payAmount , 0 ) as payAmountCash,
coalesce( f.monthCount , 0 ) as monthCount,
coalesce( m.renewCount ,0 ) as renewCount
<!-- coalesce( f.payUserCount , 0 )+coalesce( g.payUserCount , 0 ) as payUserCashCount ,
coalesce( f.payAmount , 0 )+coalesce( g.payAmount , 0 ) as payAmountCash,
coalesce( f.monthCount , 0 )+coalesce( g.monthCount , 0 ) as monthCount -->
FROM a
LEFT JOIN b
ON a.areaId = b.parentId
LEFT JOIN c
ON a.areaId = c.parentId
LEFT JOIN d
ON a.areaId = d.parentId
LEFT JOIN e
ON a.areaId = e.parentId
LEFT JOIN f
ON a.areaId = f.parentId
<!-- LEFT JOIN g
ON a.areaId = g.parentId -->
LEFT JOIN h
ON a.areaId = h.parentId
LEFT JOIN m
ON a.areaId = m.tempAreaId
ORDER BY a.areaId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<!-- 查某省各个市的已支付 -->
<select id="getAreaIsPayedByBaseId" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT a1.parentId , count( distinct a1.areaId ) as numberCount ,
count(st.studentId ) as studentCount
FROM Student as st
INNER JOIN Area as a1
ON st.status = 1 and st.areaId = a1.areaId
INNER JOIN Area as a2
ON a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ) ,
c as ( SELECT a1.parentId ,
count( s.schoolId ) as schoolCount
FROM School as s
INNER JOIN Area as a1
ON s.status = 1 and s.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ) ,
d as ( SELECT a1.parentId ,
count( c1.classesId ) as classCount
FROM Classes as c1
INNER JOIN Area as a1
ON c1.status = 1 and c1.classtype =1 and c1.areaId = a1.areaId
INNER JOIN Area as a2
ON a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ) ,
e as ( SELECT a1.parentId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(og.years) as yearCount
FROM ( select orderInfoId ,uid, created , areaId , amount
from OrderInfo
where ispayed = 1 and payway &gt; 0
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
<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 Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ),
f as(
SELECT a1.parentId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , 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 Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ),
<!-- g as(
SELECT a1.parentId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , 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
INNER JOIN Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId ), -->
h as(
SELECT a1.parentId ,
count( distinct o1.uid ) as payUserCount
FROM ( select orderInfoId ,uid, created , areaId , amount
from OrderInfo
where (ispayed = 1 or ispayed=-1) and (payway &gt; 0 or payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
) as o1
INNER JOIN Area as a1
on o1.areaId = a1.areaId
INNER JOIN Area as a2
on a1.parentId = a2.areaId
WHERE a2.parentId = #{areaId}
GROUP BY a1.parentId),
m as (
select floor( a.areaId / 100) * 100 as tempAreaId ,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o
where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and floor( areaId / 10000) * 10000 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and floor( areaId / 10000) * 10000 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY floor( a.areaId / 100) * 100
)
SELECT a.areaId as objectId, a.areaName as objectName,
coalesce( b.numberCount , 0 ) as numberCount ,
coalesce( c.schoolCount , 0 ) as schoolCount,
coalesce( d.classCount , 0 ) as classCount,
coalesce( b.studentCount , 0 ) as studentCount ,
coalesce( e.payUserCount , 0 ) as payUserCount ,
coalesce( e.payAmount , 0 ) as payAmount,
coalesce( e.yearCount , 0 ) as yearCount,
coalesce( h.payUserCount , 0 ) as payUserAllCount ,
coalesce( f.payUserCount , 0 ) as payUserCashCount ,
coalesce( f.payAmount , 0 ) as payAmountCash,
coalesce( f.monthCount , 0 ) as monthCount,
coalesce( m.renewCount ,0 ) as renewCount
<!-- coalesce( f.payUserCount , 0 )+coalesce( g.payUserCount , 0 ) as payUserCashCount ,
coalesce( f.payAmount , 0 )+coalesce( g.payAmount , 0 ) as payAmountCash,
coalesce( f.monthCount , 0 )+coalesce( g.monthCount , 0 ) as monthCount -->
FROM a
LEFT JOIN b
ON a.areaId = b.parentId
LEFT JOIN c
ON a.areaId = c.parentId
LEFT JOIN d
ON a.areaId = d.parentId
LEFT JOIN e
ON a.areaId = e.parentId
LEFT JOIN f
ON a.areaId = f.parentId
<!-- LEFT JOIN g
ON a.areaId = g.parentId -->
LEFT JOIN h
ON a.areaId = h.parentId
LEFT JOIN m
ON a.areaId = m.tempAreaId
ORDER BY a.areaId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<!-- 查某市各个县的已支付 -->
<select id="getAreaIsPayedByParentId" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT a1.areaId , count( distinct a1.areaId ) as numberCount ,
count( Distinct st.studentId ) as studentCount
FROM Student as st
INNER JOIN StudentOwnClass as sc
ON st.status = 1 and st.studentId = sc.studentId
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1
inner join school sl on c.schoolId = sl.schoolId and sl.status=1
INNER JOIN Area as a1
ON st.status = 1 and c.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId ) ,
c as ( SELECT a1.areaId ,
count( s.schoolId ) as schoolCount
FROM School as s
INNER JOIN Area as a1
ON s.status = 1 and s.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId ) ,
d as ( SELECT a1.areaId ,
count( c1.classesId ) as classCount
FROM Classes as c1
INNER JOIN Area as a1
ON c1.status = 1 and c1.classtype =1 and c1.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId ) ,
e as ( SELECT a1.areaId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(og.years) as yearCount
FROM ( select orderInfoId ,uid, created , areaId , amount
from OrderInfo
where ispayed = 1 and payway &gt; 0
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
<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 Area as a1
on o1.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId ),
f as(
SELECT a1.areaId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , amount,orderno
from OrderInfo
where ispayed = -1 and payway=-100 and amount >0
<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 Area as a1
on o1.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId ),
<!-- g as(
SELECT a1.areaId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , 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
INNER JOIN Area as a1
on o1.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId), -->
h as(
SELECT a1.areaId ,
count( distinct o1.uid ) as payUserCount
FROM ( select orderInfoId ,uid, created , areaId , amount
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 Area as a1
on o1.areaId = a1.areaId
WHERE a1.parentId = #{areaId}
GROUP BY a1.areaId),
m as (select a.areaId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o
where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and floor( areaId / 100) * 100 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and floor( areaId / 100) * 100 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY a.areaId )
SELECT a.areaId as objectId, a.areaName as objectName,
coalesce( b.numberCount , 0 ) as numberCount,
coalesce( c.schoolCount , 0 ) as schoolCount,
coalesce( d.classCount , 0 ) as classCount,
coalesce( b.studentCount , 0 ) as studentCount,
coalesce( e.payUserCount , 0 ) as payUserCount ,
coalesce( e.payAmount , 0 ) as payAmount,
coalesce( e.yearCount , 0 ) as yearCount,
coalesce( h.payUserCount , 0 ) as payUserAllCount ,
coalesce( f.payUserCount , 0 ) as payUserCashCount ,
coalesce( f.payAmount , 0 ) as payAmountCash,
coalesce( f.monthCount , 0 ) as monthCount,
coalesce( m.renewCount ,0 ) as renewCount
<!-- coalesce( f.payUserCount , 0 )+coalesce( g.payUserCount , 0 ) as payUserCashCount ,
coalesce( f.payAmount , 0 )+coalesce( g.payAmount , 0 ) as payAmountCash,
coalesce( f.monthCount , 0 )+coalesce( g.monthCount , 0 ) as monthCount -->
FROM a
LEFT JOIN b
ON a.areaId = b.areaId
LEFT JOIN c
ON a.areaId = c.areaId
LEFT JOIN d
ON a.areaId = d.areaId
LEFT JOIN e
ON a.areaId = e.areaId
LEFT JOIN f
ON a.areaId = f.areaId
<!-- LEFT JOIN g
ON a.areaId = g.areaId -->
LEFT JOIN h
ON a.areaId = h.areaId
LEFT JOIN m
ON a.areaId = m.areaId
ORDER BY a.areaId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<!-- 查某县各个学校的已支付 -->
<select id="getAreaIsPayedByAreaId" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT schoolId , schoolname FROM School
where areaId = #{areaId} and status = 1 ) ,
b as ( SELECT c.schoolId , count( distinct c.schoolId) as numberCount ,
count(Distinct st.studentId ) as studentCount
FROM Student as st
INNER JOIN StudentOwnClass as sc
ON st.status = 1 and st.studentId = sc.studentId
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1
WHERE st.areaId = #{areaId}
GROUP BY c.schoolId ) ,
d as ( SELECT c1.schoolId ,
count( c1.classesId ) as classCount
FROM Classes as c1
WHERE c1.areaId = #{areaId}
AND c1.status = 1 and c1.classtype =1
GROUP BY c1.schoolId ) ,
e as ( SELECT c.schoolId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(og.years) as yearCount
FROM ( select orderInfoId ,uid, created , areaId , amount
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
INNER JOIN Classes c
ON sc.classesId = c.classesId and c.status = 1 and c.classtype = 1
WHERE o1.areaId = #{areaId}
GROUP BY c.schoolId ),
<!-- f as ( SELECT te.schoolId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(og.years) as yearCount
FROM ( select orderInfoId ,uid, created , areaId , amount
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 te
ON o1.uid = te.teacherId and
te.status = 1
WHERE o1.areaId = #{areaId}
GROUP BY te.schoolId ), -->
i as(
SELECT c.schoolId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , amount,orderno
from OrderInfo
where ispayed = -1 and payway=-100 and amount &gt; 0
<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 o1.areaId = #{areaId}
GROUP BY c.schoolId ),
<!-- g as(
SELECT s.schoolId ,
count( distinct o1.uid ) as payUserCount ,
sum( o1.amount ) as payAmount, sum(cd.months) as monthCount
FROM ( select orderInfoId ,uid, created , areaId , 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 o1.areaId = #{areaId}
GROUP BY s.schoolId), -->
h as( select schoolId,count( distinct uid ) as payUserCount from
( select orderInfoId ,uid, created , areaId , amount
from OrderInfo
where (ispayed = 1 or ispayed=-1) and (payway &gt; 0 or payway=-100) and amount &gt; 0
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
and areaid=#{areaId}
) 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
group by schoolId
),
m as (select a.schoolId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,c.schoolId 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 amount &gt; 0
and o.areaId = #{areaId} and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
group by o.uid,c.schoolId ) as a
inner join
(select uid,count(uid) payCount,c.schoolId 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 o.amount &gt; 0
and o.areaId = #{areaId} and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1
group by o.uid,c.schoolId ) as b
on a.uid=b.uid
GROUP BY a.schoolId)
SELECT a.schoolId as objectId, a.schoolName as objectName,
coalesce( d.classCount , 0 ) as numberCount ,
coalesce( b.numberCount , 0 ) as schoolCount ,
coalesce( d.classCount , 0 ) as classCount ,
coalesce( b.studentCount , 0 ) as studentCount ,
<!-- coalesce( e.payUserCount , 0 ) + coalesce( f.payUserCount , 0 ) as payUserCount ,
coalesce( e.payAmount , 0 )+coalesce( f.payAmount , 0 ) as payAmount ,
coalesce( e.yearCount , 0 )+coalesce( f.yearCount , 0 ) as yearCount, -->
coalesce( e.payUserCount , 0 ) as payUserCount ,
coalesce( e.payAmount , 0 ) as payAmount ,
coalesce( e.yearCount , 0 ) as yearCount,
coalesce( h.payUserCount , 0 ) as payUserAllCount ,
<!-- coalesce( i.payUserCount , 0 )+coalesce( g.payUserCount , 0 ) as payUserCashCount ,
coalesce( i.payAmount , 0 )+coalesce( g.payAmount , 0 ) as payAmountCash,
coalesce( i.monthCount , 0 )+coalesce( g.monthCount , 0 ) as monthCount -->
coalesce( i.payUserCount , 0 ) as payUserCashCount ,
coalesce( i.payAmount , 0 ) as payAmountCash,
coalesce( i.monthCount , 0 ) as monthCount,
coalesce( m.renewCount ,0 ) as renewCount
FROM a
LEFT JOIN b
ON a.schoolId = b.schoolId
LEFT JOIN d
ON a.schoolId = d.schoolId
LEFT JOIN e
ON a.schoolId = e.schoolId
<!-- LEFT JOIN f
ON a.schoolId = e.schoolId -->
LEFT JOIN i
ON a.schoolId = i.schoolId
<!-- LEFT JOIN g
ON a.schoolId = g.schoolId -->
LEFT JOIN h
ON a.schoolId = h.schoolId
LEFT JOIN m
ON a.schoolId = m.schoolId
ORDER BY a.schoolId
LIMIT #{pageSize} OFFSET #{offset}
</select>
<select id="getAreaIsNotPayedByAllExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(b.areaid)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from Area a
inner join Area b on a.areaid = b.parentid
inner join Area d on b.areaid = d.parentid
left join school s on d.areaId = s.areaid and s.status=1
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,max(c.schoolid) as schoolid
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.schoolid = s.schoolid
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid
inner join area b on b.areaid = a.parentid
inner join Area d on b.areaid = d.parentid
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()
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByBaseIdExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(b.areaid)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from Area a
inner join Area b on a.areaid = b.parentid
left join school s on b.areaId = s.areaid and s.status=1
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,max(c.schoolid) as schoolid
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.schoolid = s.schoolid
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid
inner join area b on b.areaid = a.parentid and b.parentId= #{areaId}
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 a.parentid = #{areaId}
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByParentIdExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(s.schoolid)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from Area a left join school s on a.areaId = s.areaid and s.status=1
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,max(c.schoolid) as schoolid
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.schoolid = s.schoolid
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid and a.parentId= #{areaId}
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 a.parentid = #{areaId}
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByAreaIdExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(s.schoolId) as objectId, s.schoolName as objectName , count(distinct(c.classesId)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from school s
left join classes c on s.schoolid = c.schoolid and c.classtype = 1 and c.status =1 and s.status=1
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid and a.areaid= #{areaId}
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 s.areaid = #{areaId} and s.status=1
group by s.schoolId
order by s.schoolId
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByAllNotExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(b.areaid)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from Area a
inner join Area b on a.areaid = b.parentid
inner join Area d on b.areaid = d.parentid
left join school s on d.areaId = s.areaid and s.status=1
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,max(c.schoolid) as schoolid
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.schoolid = s.schoolid
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid
inner join area b on b.areaid = a.parentid
inner join Area d on b.areaid = d.parentid
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>
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByBaseIdNotExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(b.areaid)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from Area a
inner join Area b on a.areaid = b.parentid
left join school s on b.areaId = s.areaid and s.status=1
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,max(c.schoolid) as schoolid
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.schoolid = s.schoolid
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid
inner join area b on b.areaid = a.parentid and b.parentId= #{areaId}
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 a.parentid = #{areaId}
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByParentIdNotExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(s.schoolid)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from Area a left join school s on a.areaId = s.areaid and s.status=1
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime ,max(c.schoolid) as schoolid
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.schoolid = s.schoolid
and uo.uid in
(select s.studentId from Student s
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid and a.parentId= #{areaId}
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 a.parentid = #{areaId}
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getAreaIsNotPayedByAreaIdNotExpire" parameterType="java.util.Map" resultType="AreaAccountDto">
select distinct(s.schoolId) as objectId, s.schoolName as objectName , count(distinct(c.classesId)) as numberCount ,
count(distinct(uo.uid)) as payAmount
from school s
left join classes c on s.schoolid = c.schoolid and c.classtype = 1 and c.status =1 and s.status=1
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 and uo.areaid=#{areaId}
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 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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
and sc.areaid= #{areaId}
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 s.areaid = #{areaId} and s.status=1
group by s.schoolId
order by s.schoolId
limit #{pageSize} offset #{offset}
</select>
<!-- 查全国省学生的使用统计 -->
<select id="getAccountCountByAllByStudent" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT floor( areaId / 10000 ) * 10000 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
GROUP BY floor( areaId / 10000 ) * 10000 ),
c as ( SELECT floor( areaId / 10000 ) * 10000 as tempAreaId ,
count( studentId ) as studentCount
FROM Student
GROUP BY floor( areaId / 10000 ) * 10000 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 查某个省学生的使用统计 -->
<select id="getAccountCountByBaseIdByStudent" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT floor( areaId / 100 ) * 100 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
AND floor( areaId / 10000 ) * 10000 = #{areaId}
GROUP BY floor( areaId / 100 ) * 100 ),
c as ( SELECT floor( areaId / 100 ) * 100 as tempAreaId ,
count( studentId ) as studentCount
FROM Student
WHERE floor( areaId / 10000 ) * 10000 = #{areaId}
GROUP BY floor( areaId / 100 ) * 100 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 查某个市学生的使用统计 -->
<select id="getAccountCountByParentIdByStudent" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT areaId as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
AND floor( areaId / 100 ) * 100 = #{areaId}
GROUP BY areaId ),
c as ( SELECT areaId as tempAreaId ,
count( studentId ) as studentCount
FROM Student
WHERE floor( areaId / 100 ) * 100 = #{areaId}
GROUP BY areaId )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 查某个县学生的使用统计 -->
<select id="getAccountCountByAreaIdByStudent" parameterType="java.util.Map" resultType="AreaAccountDto">
select s.schoolId as objectId, s.schoolName as objectName,
count(distinct c.classesId) as numberCount ,
count(distinct sc.studentId) as payAmount
from School s
inner join Classes c
on s.schoolId = c.schoolId and c.classtype = 1 and c.status =1 and s.status=1
inner join StudentOwnClass sc
on sc.classesId = c.classesId and sc.status =1 inner join student st on st.studentId = sc.studentId and st.status =1
where s.areaid = #{areaId} and s.status=1
group by s.schoolId , s.schoolName
order by s.schoolId
limit #{pageSize} offset #{offset}
</select>
<!-- 查全国省教师的使用统计 -->
<select id="getAccountCountByAllByTeacher" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT floor( areaId / 10000 ) * 10000 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
GROUP BY floor( areaId / 10000 ) * 10000 ),
c as ( SELECT floor( areaId / 10000 ) * 10000 as tempAreaId ,
count( teacherId ) as studentCount
FROM Teacher
GROUP BY floor( areaId / 10000 ) * 10000 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 查某个省教师的使用统计 -->
<select id="getAccountCountByBaseIdByTeacher" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT floor( areaId / 100 ) * 100 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
AND floor( areaId / 10000 ) * 10000 = #{areaId}
GROUP BY floor( areaId / 100 ) * 100 ),
c as ( SELECT floor( areaId / 100 ) * 100 as tempAreaId ,
count( teacherId ) as studentCount
FROM Teacher
WHERE floor( areaId / 10000 ) * 10000 = #{areaId}
GROUP BY floor( areaId / 100 ) * 100 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 某个市的教师使用统计 -->
<select id="getAccountCountByParentIdByTeacher" parameterType="java.util.Map" resultType="AreaAccountDto">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT areaId as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
AND floor( areaId / 100 ) * 100 = #{areaId}
GROUP BY areaId ),
c as ( SELECT areaId as tempAreaId ,
count( teacherId ) as studentCount
FROM Teacher
WHERE floor( areaId / 100 ) * 100 = #{areaId}
GROUP BY areaId )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 查某个县教师的使用统计 -->
<select id="getAccountCountByAreaIdByTeacher" parameterType="java.util.Map" resultType="AreaAccountDto">
with ss as ( select schoolId as objectId, schoolName as objectName
from School
where areaid = #{areaId} and status = 1
order by schoolId
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if> )
select ss.objectId , ss.objectName ,
case when m.numberCount &gt;0 then
m.numberCount else 0 end as numberCount ,
case when n.payAmount &gt;0 then
n.payAmount else 0 end as payAmount
from SS
left join ( select a.objectId , count( b.classesId ) as numberCount
from SS as a
inner join Classes b
on b.schoolId = a.objectid
and b.status = 1
group by a.objectId ) as m
on ss.objectId = m.objectId
left join ( select a.objectId , count( t.teacherId ) as payAmount
from SS as a
inner join Teacher t
on t.schoolId = a.objectId and t.status = 1
group by a.objectId ) as n
on ss.objectId = n.objectId
order by ss.objectId
</select>
<!-- 查全国的转换率 -->
<select id="getDataAccountByAllByChange" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
GROUP BY floor( areaId / 10000) * 10000 ),
c as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentCount
FROM Student
GROUP BY floor( areaId / 10000) * 10000 ) ,
e as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( distinct uid ) as payUserCount
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>
GROUP BY floor( areaId / 10000) * 10000 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount ,
coalesce( e.payUserCount ,0 ) as payUserCount ,
coalesce( e.payUserCount ,0 ) as takeAmount ,
case when coalesce( c.studentCount ,0 ) = 0 then 0.0000 else
round(coalesce( e.payUserCount ,0 )*100::numeric/c.studentCount::numeric , 2 ) end
as accountAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
LEFT JOIN e
ON a.areaId = e.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<!-- 查某个省的转换率 -->
<select id="getDataAccountByBaseIdByChange" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
AND floor( areaId / 10000 ) * 10000 = #{areaId}
GROUP BY floor( areaId / 100) * 100 ),
c as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as studentCount
FROM Student
WHERE floor( areaId / 10000 ) * 10000 = #{areaId}
GROUP BY floor( areaId / 100) * 100 ) ,
e as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( distinct uid ) as payUserCount
FROM Orderinfo
WHERE floor( areaId / 10000 ) * 10000 = #{areaId}
AND
ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and created < #{endTime}
]]>
</if>
GROUP BY floor( areaId / 100) * 100 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount ,
coalesce( e.payUserCount ,0 ) as payUserCount ,
coalesce( e.payUserCount ,0 ) as takeAmount ,
case when coalesce( c.studentCount ,0 ) = 0 then 0.0000 else
round(coalesce( e.payUserCount ,0 )*100::numeric/c.studentCount::numeric,2 ) end
as accountAmount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
LEFT JOIN e
ON a.areaId = e.tempAreaId
ORDER BY a.areaId
limit #{pageSize} offset #{offset}
</select>
<select id="getDataAccountByParentIdByChange" parameterType="java.util.Map" resultType="java.util.HashMap">
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(s.schoolId)) as numberCount ,
count(distinct(ss.studentId)) as payAmount ,count(distinct(o.uid)) as takeAmount ,
case when count(distinct(ss.studentId)) = 0 then 0.0000 else
round(count(distinct(o.uid))*100::numeric/count(distinct(ss.studentId)::numeric),4) end as accountAmount
from Area a
left join School s on s.areaId = a.areaId and s.status=1
left join (
select s.studentId , sc.schoolId 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.status=1
inner join Area a on a.areaId = sc.areaid and a.parentId= #{areaId}
) ss on ss.schoolId = s.schoolId
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 a.parentid = #{areaId}
group by a.areaid
order by a.areaid
limit #{pageSize} offset #{offset}
</select>
<select id="getDataAccountByAreaIdByChange" parameterType="java.util.Map" resultType="java.util.HashMap">
select distinct(s.schoolId) as objectId, s.schoolName as objectName, count(distinct(c.classesId)) as numberCount ,
count(distinct(ss.studentId)) as payAmount ,count(distinct(o.uid)) as takeAmount ,
case when count(distinct(ss.studentId)) = 0 then 0.0000 else
round(count(distinct(o.uid))*100::numeric/count(distinct(ss.studentId)::numeric),4) end as accountAmount
from School s
left join Classes c on c.schoolId = s.schoolId and s.status = 1
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.status=1
inner join Area a on a.areaId = sc.areaid and a.areaid= #{areaId}
) 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 s.areaId = #{areaId} and s.status=1
group by s.schoolId
order by s.schoolId
limit #{pageSize} offset #{offset}
</select>
<select id="getSchoolCountAndNumberCountForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
GROUP BY floor( areaId / 10000) * 10000 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount from a left join b ON a.areaId = b.tempAreaId ORDER BY a.areaId
</select>
<select id="getStudentCountAndPayAmountAndTakeAmountAndAccountAmountForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
c as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentCount
FROM Student where status = 1
GROUP BY floor( areaId / 10000) * 10000 ) ,
f as ( SELECT floor( M.areaId / 10000) * 10000 as tempAreaId ,
count( distinct M.studentId ) as takeAmount
FROM Student M
WHERE M.lastsignin is not null and status = 1
GROUP BY floor( M.areaId / 10000) * 10000 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount ,
coalesce( f.takeAmount ,0 ) as takeAmount ,
case when coalesce( c.studentCount ,0 ) = 0 then 0.00
when coalesce( f.takeAmount ,0 ) = 0 then 0.00
else
round( (f.takeAmount * 100)::numeric / c.studentCount::numeric , 2 )
end as accountAmount
FROM a
LEFT JOIN c
ON a.areaId = c.tempAreaId
LEFT JOIN f
ON a.areaId = f.tempAreaId
ORDER BY a.areaId
</select>
<select id="getActiveAmountForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
g as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as activeAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 month'
and status = 1
GROUP BY floor( areaId / 10000) * 10000 )
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( g.activeAmount ,0 ) as activeAmount
from a
LEFT JOIN g
ON a.areaId = g.tempAreaId
ORDER BY a.areaId
</select>
<select id="getWeekActiveAmountForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
h as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as weekActiveAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 week'
and status = 1
GROUP BY floor( areaId / 10000) * 10000 )
select a.areaId as objectId , a.areaName as objectName,
coalesce( h.weekActiveAmount ,0 ) as weekActiveAmount
from a
LEFT JOIN h
ON a.areaId = h.tempAreaId
ORDER BY a.areaId
</select>
<select id="getDayActiveAmountForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
i as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as dayActiveAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 day'
and status = 1
GROUP BY floor( areaId / 10000) * 10000 )
select a.areaId as objectId , a.areaName as objectName, coalesce( i.dayActiveAmount ,0 ) as dayActiveAmount
from a
LEFT JOIN i
ON a.areaId =i.tempAreaId
ORDER BY a.areaId
</select>
<select id="getUseAmountForUser" parameterType="java.util.Map" resultType="java.util.Map">
<!-- WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
j as ( SELECT floor( c.areaId / 10000) * 10000 as tempAreaId ,
count( distinct c.uid ) as useAmount
FROM connectlog c
inner join student as s on s.studentid = c.uid where s.status =1 and
<![CDATA[
c.startTime >= #{startTime} and c.startTime<#{endTime}
]]>
GROUP BY floor( c.areaId / 10000) * 10000 )
select a.areaId as objectId , a.areaName as objectName, coalesce( j.useAmount ,0 ) as useAmount
from a
LEFT JOIN j
ON a.areaId =j.tempAreaId
ORDER BY a.areaId-->
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as (select distinct c.uid from connectlog c where <![CDATA[
c.startTime >= #{startTime} and c.startTime<#{endTime}
]]>),
j as (select floor( s.areaId / 10000) * 10000 as tempAreaId ,
count( b.uid ) as useAmount from b inner join student as s on s.studentid = b.uid where s.status =1 group by floor( s.areaId / 10000) * 10000 )
select a.areaId as objectId , a.areaName as objectName, coalesce( j.useAmount ,0 ) as useAmount
from a
LEFT JOIN j
ON a.areaId =j.tempAreaId
ORDER BY a.areaId
</select>
<select id="getStudentbytimeCountAndAccountAmountbyTimeForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
s as (SELECT areaId , studentId
FROM Student
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1),
k as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentbytimeCount
FROM s
GROUP BY floor( areaId / 10000) * 10000 ),
<!--k as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentbytimeCount
FROM Student
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1
GROUP BY floor( areaId / 10000) * 10000 ) ,
l as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentLoginbytimeCount
FROM Student
where <![CDATA[
created>=#{startTime} and created<#{endTime}
and lastsignin>=#{startTime} and lastsignin<#{endTime}
]]>
and status=1
GROUP BY floor( areaId / 10000) * 10000 ),-->
cn as ( select distinct uid from connectlog where <![CDATA[
starttime>=#{startTime} and endtime <#{endTime}
]]>
),
l as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,count( studentId ) as studentLoginbytimeCount from cn inner join s on s.studentid = cn.uid group by floor( areaId / 10000) * 10000 )
select a.areaId as objectId , a.areaName as objectName,
coalesce( k.studentbytimeCount ,0 ) as studentbytimeCount,
case when coalesce( k.studentbytimeCount ,0 ) = 0 then 0.00
when coalesce( l.studentLoginbytimeCount ,0 ) = 0 then 0.00 else
round( (l.studentLoginbytimeCount * 100)::numeric / k.studentbytimeCount::numeric , 2 )
end as accountAmountbyTime
from a
LEFT JOIN k
ON a.areaId =k.tempAreaId
left join l
on a.areaId = l.tempAreaId
ORDER BY a.areaId
</select>
<select id="getRenewCountForUser" parameterType="java.util.Map" resultType="java.util.Map">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
m as(select floor( a.areaId / 10000) * 10000 as tempAreaId ,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY floor( a.areaId / 10000) * 10000)
SELECT a.areaId as objectId , a.areaName as objectName, coalesce(m.renewCount ,0 ) as renewCount
from a
LEFT JOIN m
ON a.areaId = m.tempAreaId
ORDER BY a.areaId
</select>
<!-- 全国各省的使用率按地域查询-->
<select id="getDataAccountByAllByUseByAreaId" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH a as ( SELECT areaId , areaname FROM Area where areaId = #{areaId}) ,
b as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ),
c as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentCount
FROM Student where status = 1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ) ,
f as ( SELECT floor( M.areaId / 10000) * 10000 as tempAreaId ,
count( distinct M.studentId ) as takeAmount
FROM Student M
WHERE M.lastsignin is not null and status = 1 and floor( M.areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( M.areaId / 10000) * 10000 ) ,
g as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as activeAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 month'
and status = 1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ),
h as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as weekActiveAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 week'
and status = 1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ),
i as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as dayActiveAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 day'
and status = 1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ) ,
j as ( SELECT floor( c.areaId / 10000) * 10000 as tempAreaId ,
count( distinct c.uid ) as useAmount
FROM connectlog c inner join student s on c.uid=s.studentid
and
<![CDATA[
endTime>=#{startTime} and endTime<#{endTime} and s.status=1
]]>
and floor( c.areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( c.areaId / 10000) * 10000 ),
k as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentbytimeCount
FROM Student
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ) ,
cn as ( select distinct uid from connectlog where <![CDATA[
starttime>=#{startTime} and endtime <#{endTime}
]]>
),
l as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentLoginbytimeCount
FROM cn inner join Student on studentid=cn.uid
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1 and floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 10000) * 10000 ),
m as(select floor( a.areaId / 10000) * 10000 as tempAreaId ,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid and floor( a.areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( a.areaId / 10000) * 10000)
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount ,
coalesce( f.takeAmount ,0 ) as takeAmount ,
case when coalesce( c.studentCount ,0 ) = 0 then 0.00
when coalesce( f.takeAmount ,0 ) = 0 then 0.00
else
round( (f.takeAmount * 100)::numeric / c.studentCount::numeric , 2 )
end as accountAmount ,
coalesce( g.activeAmount ,0 ) as activeAmount,
coalesce( h.weekActiveAmount ,0 ) as weekActiveAmount,
coalesce( i.dayActiveAmount ,0 ) as dayActiveAmount,
coalesce( j.useAmount ,0 ) as useAmount,
coalesce( k.studentbytimeCount ,0 ) as studentbytimeCount,
case when coalesce( k.studentbytimeCount ,0 ) = 0 then 0.00
when coalesce( l.studentLoginbytimeCount ,0 ) = 0 then 0.00 else
round( (l.studentLoginbytimeCount * 100)::numeric / k.studentbytimeCount::numeric , 2 )
end as accountAmountbyTime ,
coalesce(m.renewCount ,0 ) as renewCount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
LEFT JOIN f
ON a.areaId = f.tempAreaId
LEFT JOIN g
ON a.areaId = g.tempAreaId
LEFT JOIN h
ON a.areaId = h.tempAreaId
LEFT JOIN i
ON a.areaId = i.tempAreaId
LEFT JOIN j
ON a.areaId = j.tempAreaId
LEFT JOIN k
ON a.areaId = k.tempAreaId
LEFT JOIN l
ON a.areaId = l.tempAreaId
LEFT JOIN m
ON a.areaId = m.tempAreaId
ORDER BY a.areaId
</select>
<!-- 按全国查各个省的使用率 -->
<select id="getDataAccountByAllByUse" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH a as ( SELECT areaId , areaname FROM Area where parentId = 0 ) ,
b as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
GROUP BY floor( areaId / 10000) * 10000 ),
c as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentCount
FROM Student where status = 1
GROUP BY floor( areaId / 10000) * 10000 ) ,
f as ( SELECT floor( M.areaId / 10000) * 10000 as tempAreaId ,
count( distinct M.studentId ) as takeAmount
FROM Student M
WHERE M.lastsignin is not null and status = 1
GROUP BY floor( M.areaId / 10000) * 10000 ) ,
g as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as activeAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 month'
and status = 1
GROUP BY floor( areaId / 10000) * 10000 ),
h as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as weekActiveAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 week'
and status = 1
GROUP BY floor( areaId / 10000) * 10000 ),
i as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as dayActiveAmount
FROM Student
WHERE
lastsignin&gt;now()-interval '1 day'
and status = 1
GROUP BY floor( areaId / 10000) * 10000 ) ,
j as ( SELECT floor( c.areaId / 10000) * 10000 as tempAreaId ,
count( distinct c.uid ) as useAmount
FROM connectlog c inner join student s on c.uid=s.studentid
and
<![CDATA[
endTime>=#{startTime} and endTime<#{endTime} and s.status=1
]]>
GROUP BY floor( c.areaId / 10000) * 10000 ),
k as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentbytimeCount
FROM Student
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1
GROUP BY floor( areaId / 10000) * 10000 ) ,
l as ( SELECT floor( areaId / 10000) * 10000 as tempAreaId ,
count( studentId ) as studentLoginbytimeCount
FROM Student
where <![CDATA[
created>=#{startTime} and created<#{endTime}
and lastsignin>=#{startTime} and lastsignin<#{endTime}
]]>
and status=1
GROUP BY floor( areaId / 10000) * 10000 ),
m as(select floor( a.areaId / 10000) * 10000 as tempAreaId ,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY floor( a.areaId / 10000) * 10000)
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount ,
coalesce( f.takeAmount ,0 ) as takeAmount ,
case when coalesce( c.studentCount ,0 ) = 0 then 0.00
when coalesce( f.takeAmount ,0 ) = 0 then 0.00
else
round( (f.takeAmount * 100)::numeric / c.studentCount::numeric , 2 )
end as accountAmount ,
coalesce( g.activeAmount ,0 ) as activeAmount,
coalesce( h.weekActiveAmount ,0 ) as weekActiveAmount,
coalesce( i.dayActiveAmount ,0 ) as dayActiveAmount,
coalesce( j.useAmount ,0 ) as useAmount,
coalesce( k.studentbytimeCount ,0 ) as studentbytimeCount,
case when coalesce( k.studentbytimeCount ,0 ) = 0 then 0.00
when coalesce( l.studentLoginbytimeCount ,0 ) = 0 then 0.00 else
round( (l.studentLoginbytimeCount * 100)::numeric / k.studentbytimeCount::numeric , 2 )
end as accountAmountbyTime ,
coalesce(m.renewCount ,0 ) as renewCount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
LEFT JOIN f
ON a.areaId = f.tempAreaId
LEFT JOIN g
ON a.areaId = g.tempAreaId
LEFT JOIN h
ON a.areaId = h.tempAreaId
LEFT JOIN i
ON a.areaId = i.tempAreaId
LEFT JOIN j
ON a.areaId = j.tempAreaId
LEFT JOIN k
ON a.areaId = k.tempAreaId
LEFT JOIN l
ON a.areaId = l.tempAreaId
LEFT JOIN m
ON a.areaId = m.tempAreaId
ORDER BY a.areaId
</select>
<!-- 按省查各个市的使用率 -->
<select id="getDataAccountByBaseIdByUse" parameterType="java.util.Map" resultType="java.util.HashMap">
with a as ( SELECT areaId , areaname FROM Area where parentId = #{areaId} ) ,
b as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( schoolId ) as schoolCount
FROM School
WHERE status = 1
AND floor( areaId / 10000) * 10000 = #{areaId}
GROUP BY floor( areaId / 100) * 100 ),
c as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as studentCount
FROM Student
WHERE floor( areaId / 10000) * 10000 = #{areaId} and status=1
GROUP BY floor( areaId / 100) * 100 ) ,
f as ( SELECT floor( M.areaId / 100) * 100 as tempAreaId ,
count( distinct M.studentId ) as takeAmount
FROM Student M
<!-- INNER JOIN ConnectLog N
ON M.studentId = N.uid -->
WHERE floor( M.areaId / 10000) * 10000 = #{areaId} and status=1
and M.lastsignin is not null
GROUP BY floor( M.areaId / 100) * 100 ) ,
g as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as activeAmount
FROM Student
WHERE floor( areaId / 10000) * 10000 = #{areaId}
AND
lastsignin&gt;now()-interval '1 month'
and status=1
GROUP BY floor( areaId / 100) * 100 ),
h as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as weekActiveAmount
FROM Student
WHERE floor( areaId / 10000) * 10000 = #{areaId}
AND
lastsignin&gt;now()-interval '1 week'
and status=1
GROUP BY floor( areaId / 100) * 100 ),
i as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as dayActiveAmount
FROM Student
WHERE floor( areaId / 10000) * 10000 = #{areaId}
AND
lastsignin&gt;now()-interval '1 day'
and status=1
GROUP BY floor( areaId / 100) * 100 ),
j as ( SELECT floor( c.areaId / 100) * 100 as tempAreaId ,
count( distinct uid ) as useAmount
FROM connectlog c inner join student s on
c.uid=s.studentid and
floor( c.areaId / 10000) * 10000 = #{areaId}
AND
<![CDATA[
endTime>=#{startTime} and endTime<#{endTime}
]]>
and s.status=1
GROUP BY floor( c.areaId / 100) * 100 ),
k as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as studentbytimeCount
FROM Student
WHERE floor( areaId / 10000) * 10000 = #{areaId}
AND
<![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1
GROUP BY floor( areaId / 100) * 100 ) ,
cn as ( select distinct uid from connectlog where <![CDATA[
starttime>=#{startTime} and starttime <#{endTime}
]]> and floor( areaId / 10000) * 10000 = #{areaId}
),
l as ( SELECT floor( areaId / 100) * 100 as tempAreaId ,
count( studentId ) as studentLoginbytimeCount
FROM cn inner join student on studentid=uid
WHERE floor( areaId / 10000) * 10000 = #{areaId}
AND
<![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and status=1
GROUP BY floor( areaId / 100) * 100 ),
m as(select floor( a.areaId / 100) * 100 as tempAreaId ,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o
where created&lt;#{startTime}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and floor( areaId / 10000) * 10000 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and floor( areaId / 10000) * 10000 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY floor( a.areaId / 100) * 100)
SELECT a.areaId as objectId , a.areaName as objectName,
coalesce( b.schoolCount ,0 ) as schoolCount ,
coalesce( b.schoolCount ,0 ) as numberCount ,
coalesce( c.studentCount ,0 ) as studentCount ,
coalesce( c.studentCount ,0 ) as payAmount ,
coalesce( f.takeAmount ,0 ) as takeAmount ,
case when coalesce( c.studentCount ,0 ) = 0 then 0.00
when coalesce( f.takeAmount ,0 ) = 0 then 0.00
else
round( (f.takeAmount * 100)::numeric / c.studentCount::numeric , 2 )
end as accountAmount ,
coalesce( g.activeAmount ,0 ) as activeAmount,
coalesce( h.weekActiveAmount ,0 ) as weekActiveAmount,
coalesce( i.dayActiveAmount ,0 ) as dayActiveAmount,
coalesce( j.useAmount ,0 ) as useAmount ,
coalesce( k.studentbytimeCount ,0 ) as studentbytimeCount ,
case when coalesce( k.studentbytimeCount ,0 ) = 0 then 0.00
when coalesce( l.studentLoginbytimeCount ,0 ) = 0 then 0.00
else
round( (l.studentLoginbytimeCount * 100)::numeric / k.studentbytimeCount::numeric , 2 )
end as accountAmountbyTime ,
coalesce(m.renewCount ,0 ) as renewCount
FROM a
LEFT JOIN b
ON a.areaId = b.tempAreaId
LEFT JOIN c
ON a.areaId = c.tempAreaId
LEFT JOIN f
ON a.areaId = f.tempAreaId
LEFT JOIN g
ON a.areaId = g.tempAreaId
LEFT JOIN h
ON a.areaId = h.tempAreaId
LEFT JOIN i
ON a.areaId = i.tempAreaId
LEFT JOIN j
ON a.areaId = j.tempAreaId
LEFT JOIN k
ON a.areaId = k.tempAreaId
LEFT JOIN l
ON a.areaId = l.tempAreaId
LEFT JOIN m
ON a.areaId = m.tempAreaId
ORDER BY a.areaId
</select>
<select id="getDataAccountByParentIdByUse" parameterType="java.util.Map" resultType="java.util.HashMap">
with temp as(
select count(studentid) studentbytimecount,a.areaId from student st
inner join area a
on st.areaid=a.areaId
<if test="startTime != NULL and endTime != NULL">
<![CDATA[
and st.created>=#{startTime} and st.created<#{endTime}
]]>
</if>
<!--and a.parentid = #{areaId}-->
and a.areaid &gt; #{areaId} and a.areaid &lt;#{areaId}+100 and st.areaid &gt; #{areaId} and st.areaid &lt;#{areaId}+100
and st.status=1
group by a.areaid
),
temp2 as(
select distinct(a.areaId) as objectId, a.areaName as objectName, count(distinct(s.schoolId)) as numberCount ,
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 ,
round(count(case when ss.lastsignin 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 Area a
left join School s on s.areaId = a.areaId and s.status=1
left join (
select s.studentId,co.uid,sc.schoolId , 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 &gt; #{areaId} and so.areaid &lt;#{areaId}+100 and s.areaid &gt; #{areaId} and s.areaid &lt;#{areaId}+100
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.status=1
inner join Area a on a.areaId = sc.areaid and
a.areaid &gt; #{areaId} and a.areaid &lt;#{areaId}+100
<!-- and a.parentId= #{areaId}-->
left join connectlog co on co.uid = s.studentid and co.areaid &gt; #{areaId} and co.areaid &lt;#{areaId}+100
<if test="startTime!=null">
<![CDATA[
and co.starttime > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and co.starttime < #{endTime}
]]>
</if>
group by s.studentId ,sc.schoolId, s.lastsignin,co.uid
) ss on ss.schoolId = s.schoolId
where a.parentid = #{areaId}
group by a.areaid
),
cn as ( select distinct uid from connectlog where
areaid &gt; #{areaId} and areaid &lt;#{areaId}+100
<if test="startTime != null and endTime != null">
<![CDATA[
and starttime>=#{startTime} and endtime <#{endTime}
]]>
</if>
),
temp3 as(select count(studentid) studentLoginbytimeCount,a.areaId from student st inner join cn on st.studentid=cn.uid
inner join area a
on st.areaid=a.areaId
<if test="startTime != null and endTime != null">
<![CDATA[
and st.created>=#{startTime} and st.created<#{endTime}
]]>
</if>
and st.areaid &gt; #{areaId} and st.areaid &lt;#{areaId}+100
and a.parentid = #{areaId}
and st.status=1
group by a.areaid),
temp4 as(select a.areaId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,areaid from orderinfo o
where
(o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
<if test="startTime != null">
and created&lt;#{startTime}
</if>
and floor( areaId / 100) * 100 = #{areaId}
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as a
inner join
(select uid,count(uid) payCount,areaid from orderinfo o
where
(o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
<if test="startTime != null and endTime != null">
<![CDATA[
and created>=#{startTime} and created<#{endTime}
]]>
</if>and
areaId &gt; #{areaId} and areaId &lt;#{areaId}+100
and substring(to_char(uid, '9999999999999999') from 9 for 1 )='1'
group by uid,areaId) as b
on a.uid=b.uid
GROUP BY a.areaId ),
temp5 as(select areaId,count(schoolId) schoolCount from school where
areaId &gt; #{areaId} and areaId &lt;#{areaId}+100
<if test="startTime != null and endTime != null">
<![CDATA[
and created>=#{startTime} and created<#{endTime}
]]>
</if>and status=1
GROUP BY areaId)
select objectId, objectName, numberCount , 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,
coalesce( t5.schoolCount ,0 ) schoolCount
from temp2 t2 left join temp t on t.areaid=t2.objectId
left join temp3 t3 on t3.areaid=t2.objectId
left join temp4 t4 on t4.areaid=t2.objectId
left join temp5 t5 on t5.areaid=t2.objectId
order by objectId
limit #{pageSize} offset #{offset}
</select>
<select id="getDataAccountByAreaIdByUse" parameterType="java.util.Map" resultType="java.util.HashMap">
with temp as(
select count( distinct(sd.studentid)) studentbytimecount,sl.schoolId from studentownclass st
inner join classes c
on st.classesid=c.classesid and c.classtype=1 and c.status=1 and st.areaid=#{areaId}
inner join student sd on st.studentid=sd.studentid and sd.areaid=#{areaId}
<![CDATA[
and sd.created>=#{startTime} and sd.created<#{endTime} and sd.status=1
]]>
inner join school sl on sl.schoolid=c.schoolid
and sl.areaid = #{areaId}
group by sl.schoolId
),
temp2 as(
select distinct(s.schoolId) as objectId, s.schoolName as objectName, count(distinct(c.classesId)) as numberCount ,
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 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 School s
left join Classes c on c.schoolId = s.schoolId and s.status=1 and c.status=1 and c.classtype = 1
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
inner join School sc on c.schoolId = sc.schoolId and sc.status=1
inner join Area a on a.areaId = sc.areaid and a.areaId= #{areaId}
left join connectlog co on co.uid = s.studentid and co.areaId=#{areaId}
<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 s.areaId = #{areaId} and s.status=1
group by s.schoolId
),
cn as ( select distinct uid from connectlog where areaid = #{areaId} and <![CDATA[
starttime>=#{startTime} and endtime <#{endTime}
]]>
),
temp3 as(
select count( distinct(sd.studentid)) studentLoginbytimeCount,sl.schoolId from studentownclass st
inner join classes c
on st.classesid=c.classesid and c.classtype=1 and c.status=1 and st.areaid=#{areaId}
inner join student sd on st.studentid=sd.studentid inner join cn on sd.studentid = cn.uid and sd.status=1 and sd.areaid=#{areaId}
<![CDATA[
and sd.created>=#{startTime} and sd.created<#{endTime}
]]>
inner join school sl on sl.schoolid=c.schoolid
and sl.areaid = #{areaId}
group by sl.schoolId
),
temp4 as(select a.schoolId,
count(a.uid) as renewCount
from
( select uid,count(uid) payCount,c.schoolId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid
and o.created&lt;#{startTime} and soc.areaid = #{areaId}
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and o.areaId = #{areaId} and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1 and c.status=1
group by o.uid,c.schoolId ) as a
inner join
(select uid,count(uid) payCount,c.schoolId from orderinfo o
inner join studentownclass soc on soc.studentid=o.uid and soc.areaid = #{areaId}
and <![CDATA[
created>=#{startTime} and created<#{endTime}
]]>
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay > 0 or o.payway=-100)
and o.areaId = #{areaId} and soc.status=1
inner join classes c on c.classesid=soc.classesid and c.classtype=1 and c.status =1
group by o.uid,c.schoolId ) as b
on a.uid=b.uid
GROUP BY a.schoolId ),
temp5 as(select schoolId,count(classesId) classCount from classes where areaid=#{areaId}
and <![CDATA[
created>=#{startTime} and created<#{endTime}
]]> and classtype=1 and status=1 GROUP BY schoolId )
select objectId, objectName, numberCount , 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,
coalesce( t5.classCount ,0 ) classCount
from temp2 t2 left join temp t on t.schoolId=t2.objectId
left join temp3 t3 on t2.objectId=t3.schoolId
left join temp4 t4 on t2.objectId=t4.schoolId
left join temp5 t5 on t2.objectId=t5.schoolId
order by objectId
limit #{pageSize} offset #{offset}
</select>
<!-- 查询省级 全查询 未过期 已过期 -->
<select id="getAreaIsNotPayedBypParentId_B_expire" parameterType="java.util.Map" resultType="AreaAccountDto">
<include refid="sql_isNotPayed_byParentId" />
<include refid="sql_isNotPayed_byParentId_expireId"/>
<include refid="sql_isNotPayed_byParentId_main_B"/>
</select>
<!-- 查询省级 全查询 全部 -->
<select id="getAreaIsNotPayedBypParentId_B_all" parameterType="java.util.Map" resultType="AreaAccountDto">
<include refid="sql_isNotPayed_byParentId" />
<include refid="sql_isNotPayed_byParentId_expireId"/>
<include refid="sql_isNotPayed_byParentId_main_B"/>
</select>
<!-- 查询市级 全查询 未过期 已过期 -->
<select id="getAreaIsNotPayedBypParentId_A_expire" parameterType="java.util.Map" resultType="AreaAccountDto">
<include refid="sql_isNotPayed_byParentId" />
<include refid="sql_isNotPayed_schoolCount"/>
<include refid="sql_isNotPayed_byParentId_expireId"/>
<include refid="sql_isNotPayed_byParentId_main_A"/>
</select>
<!-- 查询市级 全查询 全部 -->
<select id="getAreaIsNotPayedBypParentId_A_all" parameterType="java.util.Map" resultType="AreaAccountDto">
<include refid="sql_isNotPayed_byParentId" />
<include refid="sql_isNotPayed_schoolCount"/>
<include refid="sql_isNotPayed_byParentId_expireId"/>
<include refid="sql_isNotPayed_byParentId_main_A"/>
</select>
<!-- 获取区级 全查询 全部 -->
<select id="getAreaIsNotPayedBySchool_S_all" parameterType="java.util.Map" resultType="AreaAccountDto">
<include refid="sql_isNotPayed_bySchool" />
<include refid="sql_isNotPayed_bySchool_Expired" />
<include refid="sql_IsNotPayed_BySchool_main_S" />
</select>
<!--获取区级 全查询 已过期和未过期 -->
<select id="getAreaIsNotPayedBySchool_S_expire" parameterType="java.util.Map" resultType="AreaAccountDto">
<include refid="sql_isNotPayed_bySchool" />
<include refid="sql_isNotPayed_bySchool_Expired" />
<include refid="sql_IsNotPayed_BySchool_main_S" />
</select>
</mapper>