puzhibing
2023-08-16 d5b3e5a413bcfccba294793ee093722f31b2448a
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TOrderMapper.xml
@@ -8,7 +8,7 @@
        <result column="code" property="code" />
        <result column="userId" property="userId" />
        <result column="driverId" property="driverId" />
        <result column="source" property="source" />
        <result column="`source`" property="source" />
        <result column="agentId" property="agentId" />
        <result column="branchOfficeId" property="branchOfficeId" />
        <result column="startTime" property="startTime" />
@@ -27,7 +27,7 @@
        <result column="couponId" property="couponId" />
        <result column="payType" property="payType" />
        <result column="payTime" property="payTime" />
        <result column="state" property="state" />
        <result column="`state`" property="state" />
        <result column="status" property="status" />
        <result column="createTime" property="createTime" />
        <result column="startDistance" property="startLng" />
@@ -50,10 +50,370 @@
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, userId, driverId, source, agentId, branchOfficeId, startTime, startAddress, startLat, startLng, endAddress, endLat, endLng,
            boardingTime, getoffTime, estimatedPrice, orderMoney, payMoney, discountedPrice, couponId, payType, payTime, state, status, createTime,
        id, code, userId, driverId, `source`, agentId, branchOfficeId, startTime, startAddress, startLat, startLng, endAddress, endLat, endLng,
            boardingTime, getoffTime, estimatedPrice, orderMoney, payMoney, discountedPrice, couponId, payType, payTime, `state`, status, createTime,
            startDistance,startPrice,overDriveDistance,overDrivePrice,longDistance,longDistancePrice,overLongDistance,overLongDistancePrice,
waitTime,waitTimePrice,outWaitTime,outWaitTimePrice,badWeatherDistance,badWeatherPrice,overBadWeatherDistance,overBadWeatherPrice
    </sql>
    <sql id="Base_Column_Order">
        o.id, o.code, o.userId, o.driverId, o.`source`, o.agentId, o.branchOfficeId, o.startTime, o.startAddress, o.startLat, o.startLng, o.endAddress, o.endLat, o.endLng,
        o.boardingTime, o.getoffTime, o.estimatedPrice, o.orderMoney, o.payMoney, o.discountedPrice, o.couponId, o.payType, o.payTime, o.`state`, o.status, o.createTime,
        o.startDistance,o.startPrice,o.overDriveDistance,o.overDrivePrice,o.longDistance,o.longDistancePrice,o.overLongDistance,o.overLongDistancePrice,
        o.waitTime,o.waitTimePrice,o.outWaitTime,o.outWaitTimePrice,o.badWeatherDistance,o.badWeatherPrice,o.overBadWeatherDistance,o.overBadWeatherPrice,
        o.userPhone,o.userName,a.cancelCount,a.status AS userStatus,d.name AS driverName,d.phone AS driverPhone
    </sql>
    <sql id="Base_Column_Server_Order">
        o.id, o.code, o.userId, o.driverId, o.`source`, o.agentId, o.branchOfficeId, o.startTime, o.startAddress, o.startLat, o.startLng, o.endAddress, o.endLat, o.endLng,
        o.boardingTime, o.getoffTime, o.estimatedPrice, o.orderMoney, o.payMoney, o.discountedPrice, o.couponId, o.payType, o.payTime, o.`state`, o.status, o.createTime,
        o.startDistance,o.startPrice,o.overDriveDistance,o.overDrivePrice,o.longDistance,o.longDistancePrice,o.overLongDistance,o.overLongDistancePrice,
        o.waitTime,o.waitTimePrice,o.outWaitTime,o.outWaitTimePrice,o.badWeatherDistance,o.badWeatherPrice,o.overBadWeatherDistance,o.overBadWeatherPrice,
        o.userPhone,o.userName,d.name AS driverName,d.phone AS driverPhone
    </sql>
    <select id="getOrderList" resultType="com.stylefeng.guns.modular.system.controller.resp.TOrderResp">
        select <include refid="Base_Column_Order"></include>
        from t_order o
        left join t_app_user a on o.userId = a.id
        left join t_driver d on o.driverId = d.id
        <where>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                AND o.createTime between #{startTime} and #{endTime}
            </if>
            <if test="code != null and code != ''">
                AND o.code LIKE concat('%',#{code},'%')
            </if>
            <if test="source != null">
                AND o.source = #{source}
            </if>
            <if test="userName != null and userName != ''">
                AND a.nickname LIKE concat('%',#{userName},'%')
            </if>
            <if test="userPhone != null and userPhone != ''">
                AND a.phone LIKE concat('%',#{userPhone},'%')
            </if>
            <if test="state != null">
                AND o.state = #{state}
            </if>
            <if test="driverName != null and driverName != ''">
                AND d.name LIKE concat('%',#{driverName},'%')
            </if>
            <if test="roleType != null and roleType == 2">
                AND o.branchOfficeId = #{objectId}
            </if>
            <if test="roleType != null and roleType == 3">
                AND o.agentId = #{objectId}
            </if>
        </where>
        ORDER BY o.createTime DESC
    </select>
    <select id="getDataStatisticsByYear" resultType="com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp">
        SELECT date_format(createTime, '%m') AS `month`,COUNT(id) AS orderCount
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="yearDate != null and yearDate != ''">
                AND date_format(createTime, '%Y') LIKE concat('',#{yearDate},'%')
            </if>
        </where>
        GROUP BY `month`
    </select>
    <select id="getDataStatisticsOrderCount" resultType="com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp">
        SELECT date_format(o.payTime, '%Y-%m') AS monthTime,COUNT(o.id) AS amount,d.userName
        FROM t_order o
        LEFT JOIN (SELECT id,name AS userName from t_driver) d ON o.driverId = d.id
        <where>
            <if test="agentId != null">
                AND o.agentId = #{agentId}
            </if>
            <if test="monthDate != null and monthDate != ''">
                AND date_format(o.payTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
            </if>
            AND (o.`state` = 107 OR o.`state` = 108 OR o.`state` = 109)
            AND d.userName is not null
        </where>
        GROUP BY monthTime,userName
        ORDER BY amount DESC
        LIMIT 10
    </select>
    <select id="getDataStatisticsCount" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="type != null">
                AND `state` = #{type}
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
        </where>
    </select>
    <select id="getDataStatisticsServerCount" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
            AND (`state` = 102
                OR `state` = 103
                OR `state` = 104
                OR `state` = 105
                OR `state` = 106
                OR `state` = 201
                OR `state` = 401
            )
        </where>
    </select>
    <select id="getDataStatisticsServerList" resultType="com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp">
        select <include refid="Base_Column_Server_Order"></include>
        FROM t_order o
        LEFT JOIN t_driver d ON o.driverId = d.id
        <where>
            <if test="agentId != null">
                AND o.agentId = #{agentId}
            </if>
            <if test="localDate != null">
                AND date_format(o.createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
            AND (o.`state` = 102
            OR o.`state` = 103
            OR o.`state` = 104
            OR o.`state` = 105
            OR o.`state` = 106
            OR o.`state` = 201
            OR o.`state` = 401
            )
        </where>
    </select>
    <select id="getDataStatisticsAllList" resultType="com.stylefeng.guns.modular.system.model.TOrder">
        select <include refid="Base_Column_List"></include>
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="type != null and type == 1">
                AND `state` = 101
            </if>
            <if test="type != null and type == 2">
                AND (`state` = 102
                OR `state` = 103
                OR `state` = 104
                OR `state` = 105
                OR `state` = 106
                OR `state` = 201
                OR `state` = 401
                )
            </if>
            <if test="type != null and type == 3">
                AND (`state` = 107 OR `state` = 108 OR `state` = 109)
            </if>
            <if test="type != null and type == 4">
                AND `state` = 301
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
        </where>
    </select>
    <select id="getDataStatisticsCountByIds" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM t_order
        <where>
            <if test="ids != null and ids.size() > 0">
                AND agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="type == 1">
                AND `state` = 101
            </if>
            <if test="type == 2">
                AND (`state` = 107
                OR `state` = 108
                OR `state` = 109)
            </if>
            <if test="type == 3">
                AND `state` = 301
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
        </where>
    </select>
    <select id="getDataStatisticsServerCountByIds" resultType="java.lang.Integer">
        SELECT COUNT(id)
        FROM t_order
        <where>
            <if test="ids != null and ids.size() > 0">
                AND agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
            AND (`state` = 102
            OR `state` = 103
            OR `state` = 104
            OR `state` = 105
            OR `state` = 106
            OR `state` = 201
            OR `state` = 401
            )
        </where>
    </select>
    <select id="getDataStatisticsServerListByIds" resultType="com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp">
        select <include refid="Base_Column_Server_Order"></include>
        FROM t_order o
        LEFT JOIN t_driver d ON o.driverId = d.id
        <where>
            <if test="ids != null and ids.size() > 0">
                AND o.agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="localDate != null">
                AND date_format(o.createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
            AND (o.`state` = 102
            OR o.`state` = 103
            OR o.`state` = 104
            OR o.`state` = 105
            OR o.`state` = 106
            OR o.`state` = 201
            OR o.`state` = 401
            )
        </where>
    </select>
    <select id="getDataStatisticsAllListByIds" resultType="com.stylefeng.guns.modular.system.model.TOrder">
        select <include refid="Base_Column_List"></include>
        FROM t_order
        <where>
            <if test="ids != null and ids.size() > 0">
                AND agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="type != null and type == 1">
                AND `state` = 101
            </if>
            <if test="type != null and type == 2">
                AND (`state` = 102
                OR `state` = 103
                OR `state` = 104
                OR `state` = 105
                OR `state` = 106
                OR `state` = 201
                OR `state` = 401
                )
            </if>
            <if test="type != null and type == 3">
                AND (`state` = 107 OR `state` = 108 OR `state` = 109)
            </if>
            <if test="type != null and type == 4">
                AND `state` = 301
            </if>
            <if test="localDate != null">
                AND date_format(createTime, '%Y-%m-%d') LIKE concat('',#{localDate},'%')
            </if>
        </where>
    </select>
    <select id="getDataStatisticsByYearByIds" resultType="com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp">
        SELECT date_format(createTime, '%m') AS `month`,COUNT(id) AS orderCount
        FROM t_order
        <where>
            <if test="ids != null and ids.size() > 0">
                AND agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="yearDate != null and yearDate != ''">
                AND date_format(createTime, '%Y') LIKE concat('',#{yearDate},'%')
            </if>
        </where>
        GROUP BY `month`
    </select>
    <select id="getDataStatisticsOrderCountByIds" resultType="com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp">
        SELECT date_format(o.createTime, '%Y-%m') AS monthTime,COUNT(o.id) AS amount,d.userName
        FROM t_order o
        LEFT JOIN (SELECT id,name AS userName from t_driver) d ON o.driverId = d.id
        <where>
            <if test="ids != null and ids.size() > 0">
                AND o.agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="monthDate != null and monthDate != ''">
                AND date_format(o.createTime, '%Y-%m') LIKE concat('',#{monthDate},'%')
            </if>
            AND (o.`state` = 107 OR o.`state` = 108 OR o.`state` = 109)
            AND d.userName is not null
        </where>
        GROUP BY monthTime,userName
        ORDER BY amount DESC
        LIMIT 10
    </select>
    <select id="getStatisticsOrderByMonth" resultType="com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp">
        SELECT date_format(createTime, '%d') AS `month`,COUNT(id) AS orderCount
        FROM t_order
        <where>
            <if test="agentId != null">
                AND agentId = #{agentId}
            </if>
            <if test="dayDate != null and dayDate != ''">
                AND date_format(createTime, '%Y-%m') LIKE concat('',#{dayDate},'%')
            </if>
        </where>
        GROUP BY `month`
    </select>
    <select id="getStatisticsOrderByMonthIds" resultType="com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp">
        SELECT date_format(createTime, '%d') AS `month`,COUNT(id) AS orderCount
        FROM t_order
        <where>
            <if test="ids != null and ids.size() > 0">
                AND agentId IN
                <foreach collection="ids" close=")" open="(" item="id" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="dayDate != null and dayDate != ''">
                AND date_format(createTime, '%Y-%m') LIKE concat('',#{dayDate},'%')
            </if>
        </where>
        GROUP BY `month`
    </select>
    <select id="getValidOrderCount" resultType="java.lang.Integer">
        select count(id)
        from t_order
        <where>
            <if test="driverId != null">
                AND driverId = #{driverId}
            </if>
            <if test="orderMoney != null">
                AND orderMoney &gt; #{orderMoney}
            </if>
            <if test="month != null">
                AND DATE_FORMAT(createTime, '%Y-%m') = #{month}
            </if>
            AND (`state` = 107 OR `state` = 108 OR `state` = 109)
        </where>
    </select>
</mapper>