hjl
2024-07-16 ec6d43aa07ee0e8faf34498057ebcfbb446aa015
ruoyi-service/ruoyi-admin/src/main/resources/mapper/admin/OrderMapper.xml
@@ -28,332 +28,4 @@
        <result column="apply_reason" property="applyReason"/>
    </resultMap>
    <select id="orderCountByYear" resultType="com.ruoyi.admin.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m') AS dateTime, COUNT(*) AS number, sum(serve_price) as totalPrice
        FROM t_order
        <where>
            YEAR(createTime) = YEAR(NOW())
            <if test="cityList != null and cityList.size() != 0">
                and city in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null and orderState != ''">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY DATE_FORMAT(createTime, '%Y-%m')
        order by dateTime
    </select>
    <select id="orderCountByWeek" resultType="com.ruoyi.admin.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d') AS dateTime, COUNT(*) AS number, sum(serve_price) as totalPrice
        FROM t_order
        <where>
            YEARWEEK(DATE_FORMAT(createTime, '%Y-%m-%d')) = YEARWEEK(NOW())
            <if test="cityList != null and cityList.size() != 0">
                and city in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null and orderState != ''">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY DATE_FORMAT(createTime, '%Y-%m-%d')
        order by dateTime
    </select>
    <select id="orderCountByMonth" resultType="com.ruoyi.admin.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d') AS dateTime, COUNT(*) AS number, sum(serve_price) as totalPrice
        FROM t_order
        <where>
            MONTH(createTime) = MONTH(NOW())
              AND YEAR(createTime) = YEAR(NOW())
            <if test="cityList != null and cityList.size() != 0">
                and city in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null and orderState != ''">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY DATE_FORMAT(createTime, '%Y-%m-%d')
        order by dateTime
    </select>
    <select id="orderCountByToday" resultType="com.ruoyi.admin.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d %H') AS dateTime, COUNT(*) AS number, sum(serve_price) as totalPrice
        FROM t_order
        <where>
            DATE(createTime) = CURDATE()
            <if test="cityList != null and cityList.size() != 0">
                and city in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null and orderState != ''">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY DATE_FORMAT(createTime, '%Y-%m-%d %H')
        order by dateTime
    </select>
    <select id="totalMoneyByQuarter" resultType="java.math.BigDecimal">
        select sum(order_money)
        from t_order
        <where>
            is_delete = 0
              and state = 4
            <if test="cityList != null and cityList.size() != 0">
                and city in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="start != null and start != ''">
                and createTime <![CDATA[ >= ]]> #{start}
            </if>
            <if test="end != null and end != ''">
                and createTime <![CDATA[ <= ]]> #{end}
            </if>
        </where>
    </select>
    <select id="totalMoneyByYear" resultType="java.math.BigDecimal">
        SELECT sum(serve_price) as totalPrice
        FROM t_order
        where YEAR(createTime) = YEAR(NOW())
          and is_delete = 0
          and state = 4
        <if test="cityList != null and cityList.size() != 0">
            and city in
            <foreach collection="cityList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="totalMoneyByMonth" resultType="java.math.BigDecimal">
        SELECT sum(serve_price) as totalPrice
        FROM t_order
        where MONTH(createTime) = MONTH(NOW())
          AND YEAR(createTime) = YEAR(NOW())
          and is_delete = 0
          and state = 4
        <if test="cityList != null and cityList.size() != 0">
            and city in
            <foreach collection="cityList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="orderCount" resultType="com.ruoyi.admin.vo.OrderCountVO">
        SELECT w.real_name                                  AS realName,
               w.profile_picture                            as profilePicture,
               SUM(CASE WHEN o.state = 2 THEN 1 ELSE 0 END) AS toBeCompletedNumber,
               SUM(CASE WHEN o.state = 3 THEN 1 ELSE 0 END) AS completedNumber,
               SUM(CASE WHEN o.state = 4 THEN 1 ELSE 0 END) AS reInvestment
        FROM t_order o
                 LEFT JOIN sys_master_worker w ON o.server_id = w.id
        WHERE w.is_delete = 0
          AND o.is_delete = 0
        <if test="phone != null and phone != ''">
            and w.phone like concat('%', #{phone}, '%')
        </if>
        <if test="name != null and name != ''">
            and w.real_name like concat('%', #{name}, '%')
        </if>
        GROUP BY w.real_name, w.profile_picture
    </select>
    <select id="queryPage" resultMap="BaseResultMap">
        select *
        from t_order o
        <where>
            o.is_delete = 0
            <if test="data.orderNumber != null and data.orderNumber != ''">
                and o.order_number like concat('%', #{data.orderNumber}, '%')
            </if>
            <if test="data.cityName != null and data.cityName != ''">
                and o.city like concat('%', #{data.cityName}, '%')
            </if>
            <if test="data.reservationName != null and data.reservationName != ''">
                and o.reservation_name like concat('%', #{data.reservationName}, '%')
            </if>
            <if test="data.reservationPhone != null and data.reservationPhone != ''">
                and o.reservation_phone like concat('%', #{data.reservationPhone}, '%')
            </if>
            <if test="data.state != null">
                and o.state = #{data.state}
            </if>
            <if test="data.workerName != null and data.workerName != ''">
                and o.server_name like concat('%', #{data.workerName}, '%')
            </if>
            <if test="data.workerPhone != null and data.workerPhone != ''">
                and o.server_phone like concat('%', #{data.workerPhone}, '%')
            </if>
            <if test="data.serveName != null and data.serveName != ''">
                and o.serve_name like concat('%', #{data.serveName}, '%')
            </if>
            <if test="data.orderTimeStart != null and data.orderTimeStart != ''">
                and DATE(o.createTime) <![CDATA[ >= ]]> #{data.orderTimeStart}
            </if>
            <if test="data.orderTimeEnd != null and data.orderTimeEnd != ''">
                and DATE(o.createTime) <![CDATA[ <= ]]> #{data.orderTimeEnd}
            </if>
            <if test="data.startTime != null and data.startTime != ''">
                and DATE(o.time) <![CDATA[ >= ]]> #{data.startTime}
            </if>
            <if test="data.endTime != null and data.endTime != ''">
                and DATE(o.time) <![CDATA[ <= ]]> #{data.endTime}
            </if>
        </where>
        order by o.createTime desc
    </select>
    <select id="orderPageCount" resultMap="BaseResultMap">
        select o.*
        from t_order o
        <where>
            o.is_delete = 0
            <if test="data.orderNumber != null and data.orderNumber != ''">
                and o.order_number like concat('%', #{data.orderNumber}, '%')
            </if>
            <if test="data.cityName != null and data.cityName != ''">
                and o.city like concat('%', #{data.cityName}, '%')
            </if>
            <if test="data.reservationName != null and data.reservationName != ''">
                and o.reservation_name like concat('%', #{data.reservationName}, '%')
            </if>
            <if test="data.reservationPhone != null and data.reservationPhone != ''">
                and o.reservation_phone like concat('%', #{data.reservationPhone}, '%')
            </if>
            <if test="data.state != null">
                and o.state = #{data.state}
            </if>
            <if test="data.workerName != null and data.workerName != ''">
                and o.server_name like concat('%', #{data.workerName}, '%')
            </if>
            <if test="data.workerPhone != null and data.workerPhone != ''">
                and o.server_phone like concat('%', #{data.workerPhone}, '%')
            </if>
            <if test="data.serveName != null and data.serveName != ''">
                and o.serve_name like concat('%', #{data.serveName}, '%')
            </if>
            <if test="data.orderTimeStart != null and data.orderTimeStart != ''">
                and DATE(o.createTime) <![CDATA[ >= ]]> #{data.orderTimeStart}
            </if>
            <if test="data.orderTimeEnd != null and data.orderTimeEnd != ''">
                and DATE(o.createTime) <![CDATA[ <= ]]> #{data.orderTimeEnd}
            </if>
            <if test="data.startTime != null and data.startTime != ''">
                and DATE(o.time) <![CDATA[ >= ]]> #{data.startTime}
            </if>
            <if test="data.endTime != null and data.endTime != ''">
                and DATE(o.time) <![CDATA[ <= ]]> #{data.endTime}
            </if>
        </where>
    </select>
    <select id="exportByIdList" resultMap="BaseResultMap">
        select reservation_name,
               reservation_phone,
               reservation_address,
               time,
               serve_name,
               server_name,
               server_phone
        from t_order
        <where>
            id in
            <foreach collection="list" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
    </select>
    <select id="exportList" resultMap="BaseResultMap">
        select o.reservation_name,
               o.reservation_phone,
               o.reservation_address,
               o.time,
               o.serve_name,
               o.server_name,
               o.server_phone
        from t_order o
                 left join sys_change_dispatch c on o.id = c.order_id
        <where>
            o.is_delete = 0
              AND (c.is_delete = 0 OR c.is_delete IS NULL)
            <if test="data.orderNumber != null and data.orderNumber != ''">
                and o.order_number like concat('%', #{data.orderNumber}, '%')
            </if>
            <if test="data.cityName != null and data.cityName != ''">
                and o.city like concat('%', #{data.cityName}, '%')
            </if>
            <if test="data.reservationName != null and data.reservationName != ''">
                and o.reservation_name like concat('%', #{data.reservationName}, '%')
            </if>
            <if test="data.reservationPhone != null and data.reservationPhone != ''">
                and o.reservation_phone like concat('%', #{data.reservationPhone}, '%')
            </if>
            <if test="data.state != null">
                and o.state = #{data.state}
            </if>
            <if test="data.workerName != null and data.workerName != ''">
                and o.server_name like concat('%', #{data.workerName}, '%')
            </if>
            <if test="data.workerPhone != null and data.workerPhone != ''">
                and o.server_phone like concat('%', #{data.workerPhone}, '%')
            </if>
            <if test="data.serveName != null and data.serveName != ''">
                and o.serve_name like concat('%', #{data.serveName}, '%')
            </if>
            <if test="data.orderTimeStart != null and data.orderTimeStart != ''">
                and DATE(o.createTime) <![CDATA[ >= ]]> #{data.orderTimeStart}
            </if>
            <if test="data.orderTimeEnd != null and data.orderTimeEnd != ''">
                and DATE(o.createTime) <![CDATA[ <= ]]> #{data.orderTimeEnd}
            </if>
            <if test="data.startTime != null and data.startTime != ''">
                and DATE(o.time) <![CDATA[ >= ]]> #{data.startTime}
            </if>
            <if test="data.endTime != null and data.endTime != ''">
                and DATE(o.time) <![CDATA[ <= ]]> #{data.endTime}
            </if>
        </where>
    </select>
</mapper>