691 lines
18 KiB
XML
Raw Permalink Normal View History

2026-03-10 14:30:24 +08:00
<?xml version="1.0" encoding="UTF-8"?><!--Converted at: Wed Jul 11 17:43:20 CST 2018-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="ClassAccount">
<!-- 班级对账单明细 -->
<select id="getClassAccountByClassId" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH so as ( select studentId
from StudentOwnClass
where classesId= #{classesId} and status =1)
SELECT ss.studentId , ss.recognizecode , ss.trueName , o.payTime, o.description ,
o.amount as payAmount ,o.fees as takeAmount ,(o.amount - o.fees ) as accountAmount
FROM so
INNER JOIN Student ss
ON so.studentId = ss.studentId
INNER JOIN Orderinfo o
ON so.studentId = o.uid
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>
INNER JOIN OrderOwnGoods oo
ON o.orderInfoId = oo.orderInfoId
INNER JOIN Goods g
ON g.goodsId = oo.goodsId
ORDER BY ss.studentId , o.payTime
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="getClassIsPayedByClassId" parameterType="java.util.Map" resultType="java.util.HashMap">
select ss.studentId , ss.recognizecode , ss.trueName , o.payTime, o.description ,
o.payAmount , o.yearcount ,o.payway
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId} and so.status =1
) ss
inner join(select o.orderinfoid ,o.uid, o.description ,o.created , o.payTime ,o.payway, sum(coalesce(oo.amount,0)) as payAmount , sum(oo.years) as yearcount
from orderinfo o
inner join OrderOwnGoods oo on o.orderInfoId = oo.orderInfoId
inner join Goods g on g.goodsId = oo.goodsId
where 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>
group by o.orderinfoid , o.description , o.uid,o.created , o.payTime ,o.payway
) o
on o.uid = ss.studentId
where ss.classesId = #{classesId}
union all
select ss.studentId , ss.recognizecode , ss.trueName , o.payTime, o.description ,
o.amount payAmount , cd.months as yearcount , o.payway
from
student ss
inner join studentownclass sc on ss.studentid=sc.studentid and sc.classesid=#{classesId}
inner join orderinfo o on o.isPayed = -1 and o.payWay=-100
<if test="startTime!=null">
<![CDATA[
and o.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o.created < #{endTime}
]]>
</if>
and o.uid = ss.studentId
inner join comppaydetail cd on cd.comppayinfoid=to_number(o.orderno,'999999999G999D9S')
and cd.recognizecode=ss.recognizecode and cd.usertype=1
order by studentId , payTime
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<!--查看班级报表 已过期 未过期 全部 -->
<select id="getClassIsNotPayedAll" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH temp3 AS ( SELECT uid FROM orderinfo WHERE ispayed = 1 AND payway > 0 AND created &gt; #{startTime} AND created &lt; #{endTime} AND areaid = #{areaId} ),
A AS (
SELECT
ss.studentId,
ss.recognizecode,
ss.trueName,
MAX ( uo.startTime ) AS startTime,
MAX ( uo.endTime ) AS endTime,
MAX ( uh.howmuch ) AS howmuch
FROM
(
SELECT
s.studentId,
s.recognizecode,
s.trueName,
so.classesId
FROM
Student s
INNER JOIN StudentOwnClass so ON so.studentId = s.studentId and s.areaid = #{areaId} and s.status = 1
AND so.classesId = #{classesId}
AND so.status = 1
AND so.areaid = #{areaId}
WHERE
s.studentId NOT IN ( SELECT uid FROM temp3 )
) ss
LEFT JOIN (
SELECT DISTINCT
( uid ),
MIN ( uo.startTime ) AS startTime,
MAX ( uo.endTime ) AS endTime
FROM
UserOwnLesson uo
WHERE
uo.areaid = #{areaId}
GROUP BY
uid
) uo ON uo.uid = ss.studentId
LEFT JOIN UserHonor uh ON uh.uid = ss.studentId
AND uh.areaid = #{areaId}
where
uo.endTime is not null
<if test="expire == 0">
and uo.endTime &lt; now()
</if>
<if test="expire == 1">
and uo.endTime &gt; now()
</if>
GROUP BY
ss.studentId,
ss.recognizecode,
ss.trueName
ORDER BY
ss.studentId
),
b AS (
SELECT SUM
(
EXTRACT (
epoch
FROM
( endtime - starttime ))) tryUseTime,
uid
FROM
goodsauthlog
WHERE
uid IN ( SELECT studentId FROM A )
GROUP BY
uid
)
SELECT
studentId,
recognizecode,
trueName,
startTime,
endTime,
case when howmuch is null then 0 else howmuch end as
howmuch,
tryUseTime
FROM
A LEFT JOIN b ON A.studentid = b.uid
ORDER BY
studentId
</select>
<!--查看班级报表 已过期 未过期 全部 -->
<select id="getClassIsNotPayedAllCount" parameterType="java.util.Map" resultType="java.lang.Integer">
WITH temp3 AS ( SELECT uid FROM orderinfo WHERE ispayed = 1 AND payway > 0 AND created &gt; #{startTime} AND created &lt; #{endTime} AND areaid = #{areaId} ),
A AS (
SELECT
ss.studentId,
ss.recognizecode,
ss.trueName,
MAX ( uo.startTime ) AS startTime,
MAX ( uo.endTime ) AS endTime,
MAX ( uh.howmuch ) AS howmuch
FROM
(
SELECT
s.studentId,
s.recognizecode,
s.trueName,
so.classesId
FROM
Student s
INNER JOIN StudentOwnClass so ON so.studentId = s.studentId and s.areaid = #{areaId} and s.status = 1
AND so.classesId = #{classesId}
AND so.status = 1
AND so.areaid = #{areaId}
WHERE
s.studentId NOT IN ( SELECT uid FROM temp3 )
) ss
LEFT JOIN (
SELECT DISTINCT
( uid ),
MIN ( uo.startTime ) AS startTime,
MAX ( uo.endTime ) AS endTime
FROM
UserOwnLesson uo
WHERE
uo.areaid = #{areaId}
GROUP BY
uid
) uo ON uo.uid = ss.studentId
LEFT JOIN UserHonor uh ON uh.uid = ss.studentId
AND uh.areaid = #{areaId}
where
uo.endTime is not null
<if test="expire == 0">
and uo.endTime &lt; now()
</if>
<if test="expire == 1">
and uo.endTime &gt; now()
</if>
GROUP BY
ss.studentId,
ss.recognizecode,
ss.trueName
ORDER BY
ss.studentId
),
b AS (
SELECT SUM
(
EXTRACT (
epoch
FROM
( endtime - starttime ))) tryUseTime,
uid
FROM
goodsauthlog
WHERE
uid IN ( SELECT studentId FROM A )
GROUP BY
uid
)
SELECT
count(*)
FROM
A LEFT JOIN b ON A.studentid = b.uid
</select>
<select id="getClassIsNotPayedByClassIdExpire" parameterType="java.util.Map" resultType="java.util.HashMap">
with a as (select ss.studentId , ss.recognizecode , ss.trueName , max(uo.startTime) as startTime , max(uo.endTime) as endTime , max(uh.howmuch) as howmuch
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId} and so.status =1
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>
)
) ss
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime
from UserOwnLesson uo group by uid) uo on uo.uid =ss.studentId
left join UserHonor uh on uh.uid = ss.studentId
where uo.endTime &lt;now()
group by ss.studentId, ss.recognizecode ,ss.trueName
order by ss.studentId
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
) ,
b as(
select sum(extract(epoch FROM (endtime-starttime ))) tryUseTime,uid
from goodsauthlog
where uid in (select studentId from a) group by uid)
select
studentId , recognizecode , trueName , startTime , endTime , howmuch ,tryUseTime
from a left join b on a.studentid=b.uid
</select>
<select id="getClassIsNotPayedByClassIdNotExpire" parameterType="java.util.Map" resultType="java.util.HashMap">
with a as(select ss.studentId , ss.recognizecode , ss.trueName , max(uo.startTime) as startTime , max(uo.endTime) as endTime , max(uh.howmuch) as howmuch
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId} and so.status =1
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>
)
) ss
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime
from UserOwnLesson uo group by uid) uo on uo.uid =ss.studentId
left join UserHonor uh on uh.uid = ss.studentId
<if test="expire==1">
where uo.endTime &gt;= now()
</if>
<if test="expire==2">
where uo.endTime is not null
</if>
group by ss.studentId, ss.recognizecode ,ss.trueName
order by ss.studentId
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
),
b as(
select sum(extract(epoch FROM (endtime-starttime ))) tryUseTime,uid
from goodsauthlog
where uid in (select studentId from a) group by uid)
select
studentId , recognizecode , trueName , startTime , endTime , howmuch ,tryUseTime
from a left join b on a.studentid=b.uid
</select>
<select id="getClassAccountCountByClassId" parameterType="java.util.Map" resultType="Integer">
select count(ss.studentId)
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId}
and so.status =1
) ss
inner join(select o.orderinfoid ,o.uid, o.description ,o.created , o.payTime , sum(coalesce(oo.amount,0)) as payAmount,
sum(coalesce(g.tradeprice,0)*oo.years) as takeAmount, sum(coalesce(oo.amount,0))-sum(coalesce(g.tradeprice,0)*oo.years) as accountAmount
from orderinfo o
inner join OrderOwnGoods oo on o.orderInfoId = oo.orderInfoId
inner join Goods g on g.goodsId = oo.goodsId
where o.isPayed = 1 and o.payWay &gt; 0
group by o.orderinfoid , o.description , o.uid
) o
on o.uid = ss.studentId
where ss.classesId = #{classesId}
</select>
<select id="getClassIsPayedCountByClassId" parameterType="java.util.Map" resultType="Integer">
<!-- select count(ss.studentId)
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId}
and so.status =1
) ss
inner join(select o.orderinfoid ,o.uid, o.description ,o.created , o.payTime , sum(coalesce(oo.amount,0)) as payAmount
from orderinfo o
inner join OrderOwnGoods oo on o.orderInfoId = oo.orderInfoId
inner join Goods g on g.goodsId = oo.goodsId
where 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>
group by o.orderinfoid , o.description , o.uid
) o
on o.uid = ss.studentId
where ss.classesId = #{classesId} -->
select count(ss.studentId)
from student ss inner join
studentownclass sc on ss.studentid=sc.studentid and sc.classesid=#{classesId}
inner join
orderinfo o on o.uid=ss.studentid
and (o.isPayed = 1 or o.ispayed=-1) and (o.payWay &gt; 0 or o.payway=-100)
<if test="startTime!=null">
<![CDATA[
and o.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o.created < #{endTime}
]]>
</if>
</select>
<select id="getClassIsNotPayedCountByClassIdExpire" parameterType="java.util.Map" resultType="Integer">
select count(distinct(ss.studentId))
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId} and so.status =1
where s.studentId not in (select uid from orderinfo where payway &gt;0 and ispayed = 1)
) ss
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime
from UserOwnLesson uo group by uid) uo on uo.uid =ss.studentId
left join UserHonor uh on uh.uid = ss.studentId
where
uo.endTime &lt; #{endTime}
</select>
<select id="getClassIsNotPayedCountByClassIdNotExpire" parameterType="java.util.Map" resultType="Integer">
select count(distinct(ss.studentId))
from (
select s.studentId , s.recognizecode , s.trueName , so.classesId from Student s
inner join StudentOwnClass so on so.studentId = s.studentId
and so.classesId=#{classesId} and so.status =1
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>
)
) ss
left join (select distinct(uid), min(uo.startTime) as startTime , max(uo.endTime) as endTime
from UserOwnLesson uo group by uid) uo on uo.uid =ss.studentId
left join UserHonor uh on uh.uid = ss.studentId
<if test="expire==1">
where uo.endTime &gt; #{endTime}
</if>
<if test="expire==2">
where uo.endTime is not null
</if>
</select>
<!-- 教师对账单明细 -->
<select id="getTeacherAccountBySchoolId" parameterType="java.util.Map" resultType="java.util.HashMap">
WITH so as ( select teacherId
from teacher
where schoolId= #{schoolId} and status =1)
SELECT so.teacherid studentId , ss.loginno recognizecode , ss.trueName , o.payTime, o.description ,
o.amount as payAmount ,o.fees as takeAmount ,(o.amount - o.fees ) as accountAmount
FROM so
INNER JOIN teacher ss
ON so.teacherid = ss.teacherid
INNER JOIN Orderinfo o
ON so.teacherid = o.uid
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>
INNER JOIN OrderOwnGoods oo
ON o.orderInfoId = oo.orderInfoId
INNER JOIN Goods g
ON g.goodsId = oo.goodsId
ORDER BY ss.teacherid , o.payTime
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<!-- 教师对账单明细 -->
<select id="getTeacherAccountCountBySchoolId" parameterType="java.util.Map" resultType="java.lang.Integer">
WITH so as ( select teacherId
from teacher
where schoolId= #{schoolId} and status =1)
SELECT count(so.teacherid)
FROM so
INNER JOIN teacher ss
ON so.teacherid = ss.teacherid
INNER JOIN Orderinfo o
ON so.teacherid = o.uid
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>
INNER JOIN OrderOwnGoods oo
ON o.orderInfoId = oo.orderInfoId
INNER JOIN Goods g
ON g.goodsId = oo.goodsId
</select>
<select id="getTeacherIsPayBySchoolId" parameterType="java.util.Map" resultType="java.util.HashMap">
select ss.teacherid studentId , ss.loginno recognizecode , ss.trueName , o.payTime, o.description ,
o.payAmount , o.yearcount,o.payway
from
teacher ss
inner join(
select o.orderinfoid ,o.uid, o.description ,o.created , o.payTime ,o.payway, sum(coalesce(oo.amount,0)) as payAmount , sum(oo.years) as yearcount
from orderinfo o
inner join OrderOwnGoods oo on o.orderInfoId = oo.orderInfoId
inner join Goods g on g.goodsId = oo.goodsId
where 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>
group by o.orderinfoid , o.description , o.uid,o.created , o.payTime
) o
on o.uid = ss.teacherId
where ss.schoolId = #{schoolId}
union all
select ss.teacherid studentId , ss.loginno recognizecode , ss.trueName , o.payTime, o.description ,
o.amount payAmount , cd.months as yearcount , o.payway
from
teacher ss
inner join orderinfo o on o.isPayed = -1 and o.payWay=-100
<if test="startTime!=null">
<![CDATA[
and o.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o.created < #{endTime}
]]>
</if>
and o.uid = ss.teacherId and ss.schoolId = #{schoolId}
inner join comppaydetail cd on cd.comppayinfoid=to_number(o.orderno,'999999999G999D9S')
and cd.recognizecode=ss.loginno and cd.usertype=2
order by studentId , payTime desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<select id="getTeacherIsPayCountBySchoolId" parameterType="java.util.Map" resultType="java.lang.Integer">
select count(*)
from
teacher ss
inner join
orderinfo o
on (o.isPayed = 1 or o.ispayed=-1) and (o.payWay &gt; 0 or o.payway=-100)
<if test="startTime!=null">
<![CDATA[
and o.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o.created < #{endTime}
]]>
</if>
and o.uid = ss.teacherId
and ss.schoolId = #{schoolId}
</select>
</mapper>