liujie
2025-08-04 ddba15cfd1d654dc41de5dfdc587e12d96d84f4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?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>