<?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="com.stylefeng.guns.rest.modular.system.dao.FinancialMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.shunfeng.model.Financial">
|
<id column="id" property="id" />
|
<result column="addTime" property="addTime" />
|
<result column="type" property="type" />
|
<result column="payType" property="payType" />
|
<result column="money" property="money" />
|
<result column="pwType" property="pwType" />
|
<result column="orderNum" property="orderNum" />
|
<result column="companyId" property="companyId" />
|
<result column="lsType" property="lsType" />
|
<result column="userId" property="userId" />
|
<result column="lx" property="lx" />
|
</resultMap>
|
|
<!-- 通用查询结果列 -->
|
<sql id="Base_Column_List">
|
id, addTime, type, payType, money, pwType, orderNum, companyId, lsType,userId,lx
|
</sql>
|
<!--获取司机消费记录-->
|
<select id="getOrderRecord" resultType="map">
|
select ss.* from (
|
select oo.*,1 as type from (
|
select o.orderNum,o.busTime,z.busStartTime,o.checkNum*o.djMoney as money,s1.name as startName,s2.`name` as endName,o.num-o.tuiNum as num,DATE_FORMAT( o.addTime, '%Y-%m-%d' ) as addTime,o.id as orderId
|
from (select * from app_order od where od.driverId=#{driverId} and od.checkNum*od.djMoney > 0 and od.state in (4,5)) o
|
left join (select CONCAT_WS(' ',zs.busTime,zs.startTime) as busStartTime,zs.id,zs.lineId,zs.bq from app_shift_zs zs) z on o.shiftId=z.id
|
left join app_line l on l.id=z.lineId
|
left join app_site s1 on s1.id = l.beginId
|
left join app_site s2 on s2.id = l.endId
|
WHERE
|
DATE_FORMAT(o.addTime, '%Y-%m') = #{searchDate}
|
) oo
|
group by oo.orderId
|
UNION
|
select f.id as orderNum,'' as busTime ,DATE_FORMAT(f.addTime, '%Y-%m-%d %H:%m') AS busStartTime,money
|
,'' as startName,'' as endName,0 as num, DATE_FORMAT( f.addTime, '%Y-%m-%d' ) as addTime,2 as type,f.id as orderId from app_withdrawal f where f.driverId=#{driverId} and type=1
|
) ss
|
<where>
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT( ss.addTime, '%Y-%m' ) =#{searchDate}
|
</if>
|
<if test="type!=null">
|
and ss.type=#{type}
|
</if>
|
</where>
|
order by ss.busStartTime desc
|
<if test="start!=null">
|
LIMIT #{start},#{end}
|
</if>
|
</select>
|
<!--获取收入和支出总数据-->
|
<select id="getOrderSum" resultType="map">
|
select ss.* from (
|
select IFNULL(sum(oo.money),0) as moneys,oo.addTime,1 as type from (
|
select o.checkNum*o.djMoney as money,DATE_FORMAT( o.addTime, '%Y-%m-%d' ) as addTime
|
from (select * from app_order od where od.driverId=#{driverId} and od.checkNum*od.djMoney>0 and od.state in (4,5)) o
|
left join (select zs.id,zs.lineId,zs.bq from app_shift_zs zs ) z on o.shiftId=z.id
|
left join app_line l on l.id=z.lineId
|
left join app_site s1 on s1.id = l.beginId
|
left join app_site s2 on s2.id = l.endId
|
<where>
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT(o.addTime, '%Y-%m') =#{searchDate}
|
</if>
|
</where>
|
) oo
|
UNION
|
select IFNULL(sum(f.money),0) as moneys, DATE_FORMAT( f.addTime, '%Y-%m-%d' ) as addTime,2 as type from app_withdrawal f where f.driverId=#{driverId} and type=1
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT(f.addTime, '%Y-%m') =#{searchDate}
|
</if>
|
) ss
|
<where>
|
<!--<if test="type!=null">
|
and ss.type=#{type}
|
</if>-->
|
</where>
|
</select>
|
|
<!--出租车司机记录-->
|
<select id="getOrderRecordTaxi" resultType="map">
|
select * from (
|
select DATE_FORMAT(t.addTime,'%Y-%m-%d %H:%i') as addTime,t.money,1 as type from app_order_taxi t
|
left join app_order_taxi_time i on t.id=i.orderId
|
where t.money>0 and t.driverId=#{driverId} and t.state=7
|
UNION
|
select DATE_FORMAT(reassignmentTime,'%Y-%m-%d %H:%i') as addTime,serviceMoney as money,2 as type from app_order_taxi
|
where driverId=#{driverId} and isReassignment=2
|
UNION
|
select DATE_FORMAT(addTime,'%Y-%m-%d %H:%i') as addTime,money,3 as type from app_withdrawal
|
where driverId=#{driverId} and type=2
|
) ss
|
<where>
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT( ss.addTime, '%Y-%m' ) =#{searchDate}
|
</if>
|
<if test="type==1">
|
and ss.type=1
|
</if>
|
<if test="type==2">
|
and ss.type=3
|
</if>
|
<if test="type==3">
|
and ss.type=2
|
</if>
|
</where>
|
order by ss.addTime desc
|
<if test="start!=null">
|
LIMIT #{start},#{end}
|
</if>
|
</select>
|
<!--出租车司机记录-->
|
<select id="getOrderSumTaxi" resultType="map">
|
select IFNULL(sum(t.money),0) as moneys,1 as type from app_order_taxi t
|
left join app_order_taxi_time i on t.id=i.orderId
|
where t.money>0 and t.driverId=#{driverId} and t.state=7
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT(t.addTime, '%Y-%m') =#{searchDate}
|
</if>
|
UNION
|
select IFNULL(sum(t.moneys),0),2 as type from(
|
select sum(money) as moneys,1 as type from app_withdrawal
|
where driverId=#{driverId} and type=2
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT(addTime, '%Y-%m') =#{searchDate}
|
</if>
|
UNION
|
select sum(serviceMoney) as money,2 as type from app_order_taxi
|
where driverId=#{driverId} and isReassignment=2
|
<if test="searchDate!=null and searchDate!=''">
|
and DATE_FORMAT(addTime, '%Y-%m') =#{searchDate}
|
</if>
|
) t
|
<where>
|
<!--<if test="type==1">
|
and t.type=1
|
</if>
|
<if test="type==2">
|
and t.type=2
|
</if>
|
<if test="type==3">
|
and t.type=2
|
</if>-->
|
</where>
|
</select>
|
<!--获取用户我的消费记录-->
|
<select id="getFinancialUser" resultType="map">
|
select id, DATE_FORMAT(addTime, '%Y-%m-%d') as addTime,type,payType, money, pwType from app_financial f
|
<where>
|
and f.lx= 1
|
<if test="userId!=null">
|
and userId = #{userId}
|
</if>
|
</where>
|
order by f.addTime desc
|
<if test="start!=null">
|
LIMIT #{start},#{end}
|
</if>
|
</select>
|
|
</mapper>
|