OrderAppointmentSMapper.xml 8.46 KB
<?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.zteits.order.mapper.smapper.OrderAppointmentSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.order.domain.OrderAppointment">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="appointment_config_id" jdbcType="BIGINT" property="appointmentConfigId"/>
        <result column="appointment_type" jdbcType="INTEGER" property="appointmentType"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="order_type" jdbcType="INTEGER" property="orderType"/>
        <result column="order_state" jdbcType="INTEGER" property="orderState"/>
        <result column="terminal_source" jdbcType="INTEGER" property="terminalSource"/>
        <result column="order_dicount_fee" jdbcType="BIGINT" property="orderDicountFee"/>
        <result column="order_act_fee" jdbcType="BIGINT" property="orderActFee"/>
        <result column="order_total_fee" jdbcType="BIGINT" property="orderTotalFee"/>
        <result column="cust_type" jdbcType="INTEGER" property="custType"/>
        <result column="cust_id" jdbcType="VARCHAR" property="custId"/>
        <result column="user_phone" jdbcType="VARCHAR" property="userPhone"/>
        <result column="car_number" jdbcType="VARCHAR" property="carNumber"/>
        <result column="car_number_color" jdbcType="VARCHAR" property="carNumberColor"/>
        <result column="pl_no" jdbcType="VARCHAR" property="plNo"/>
        <result column="pl_name" jdbcType="VARCHAR" property="plName"/>
        <result column="berth_no" jdbcType="VARCHAR" property="berthNo"/>
        <result column="appointment_opt_time" jdbcType="TIMESTAMP" property="appointmentOptTime"/>
        <result column="appointment_begin_time" jdbcType="TIMESTAMP" property="appointmentBeginTime"/>
        <result column="appointment_end_time" jdbcType="TIMESTAMP" property="appointmentEndTime"/>
        <result column="push_state" jdbcType="INTEGER" property="pushState"/>
        <result column="org_id" jdbcType="BIGINT" property="orgId"/>
        <result column="rlt_order_id" jdbcType="VARCHAR" property="rltOrderId"/>
        <result column="appointment_state" jdbcType="INTEGER" property="appointmentState"/>
        <result column="data_state" jdbcType="INTEGER" property="dataState"/>
        <result column="create_emp_id" jdbcType="VARCHAR" property="createEmpId"/>
        <result column="create_emp_name" jdbcType="VARCHAR" property="createEmpName"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="modfiy_emp_id" jdbcType="VARCHAR" property="modfiyEmpId"/>
        <result column="modfiy_emp_name" jdbcType="VARCHAR" property="modfiyEmpName"/>
        <result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, appointment_config_id, appointment_type, order_id, order_type, order_state, terminal_source,
    order_dicount_fee, order_act_fee, order_total_fee, cust_type, cust_id, user_phone,
    car_number, car_number_color, pl_no, pl_name, berth_no, appointment_opt_time, appointment_begin_time,
    appointment_end_time, push_state, org_id, rlt_order_id, appointment_state, data_state,
    create_emp_id, create_emp_name, create_date, modfiy_emp_id, modfiy_emp_name, modfiy_date,
    remark
  </sql>
    <!-- 根据车场编号查询已预约订单数 -->
    <select id="countOccupyBerthByPlNos" resultType="com.zteits.clouds.api.dto.order.appointment.dto.CountAppointDTO">
        select pl_no plNo,
        count(1) occupyBerthNum
        from order_appointment
        where data_state = 1
        and appointment_state in (10, 20)
        <if test="plNoList != null and plNoList.size >0">
            and pl_no in
            <foreach collection="plNoList" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="orgId !=null">
            AND org_id = #{orgId,jdbcType=BIGINT},
        </if>
        group by pl_no;
    </select>

    <!-- 根据日期查询车场剩余预约泊位数 -->
    <select id="queryFreeBerthListByDate" resultType="com.zteits.clouds.api.dto.order.appointment.dto.FreeBerthDTO">
        select #{berthTotal}-count(*) freeBerthNum,
        date(appointment_begin_time) day
        from order_appointment
        where data_state = 1
        and pl_no = #{plNo}
        and appointment_state = 10
        <if test="orgId !=null">
            and org_id = #{orgId,jdbcType=BIGINT}
        </if>
        <if test="dateList != null and dateList.size >0">
            and date(appointment_begin_time) in
            <foreach collection="dateList" open="(" close=")" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        group by date(appointment_begin_time);
    </select>

    <select id="queryNoPustAppointmentCarList"  resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from order_appointment
        where data_state = 1 and push_state = 0
        and #{nowDate} > appointment_begin_time
        and appointment_end_time > #{nowDate}
        and appointment_state = 10
    </select>

    <select id="queryOrderAppointment" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from order_appointment
        where data_state = 1
        and appointment_state in
        <foreach collection="appointmentState" open="(" close=")" item="state" separator=",">
            #{state}
        </foreach>
        and cust_id = #{custId}
        and org_id = #{orgId}
        order by id desc
    </select>

    <select id="checkRepeatAppointment" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from order_appointment
        where data_state = 1
        and appointment_state in (10,20)
        and pl_no = #{plNo}
        <if test="orgId !=null">
            and org_id = #{orgId}
        </if>
        and car_number = #{carNumber}
        and (<![CDATA[(appointment_begin_time  <= #{appointmentBeginTime} and appointment_end_time  >= #{appointmentBeginTime})
            or (appointment_begin_time  <= #{appointmentEndTime} and appointment_end_time  >= #{appointmentEndTime})]]>)
        order by id desc
    </select>
    <!--   -->
    <select id="queryOrderAppointmentForBcpPage" resultMap="BaseResultMap" parameterType="com.zteits.clouds.api.dto.order.appointment.param.OrderAppointmentPageRequest">
        select
        <include refid="Base_Column_List" />
        from order_appointment
        where data_state = 1
        <if test="orgId !=null">
            and org_id = #{orgId}
        </if>
        <if test="carNumber != null and carNumber != ''">
            and car_number = #{carNumber,jdbcType=VARCHAR}
        </if>
        <if test="plNoList != null and plNoList.size >0">
            and pl_no in
            <foreach collection="plNoList" open="(" close=")" item="plNo" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="appointmentStates != null and appointmentStates.size >0">
            and appointment_state in
            <foreach collection="appointmentStates" open="(" close=")" item="appointmentState" separator=",">
                #{appointmentState}
            </foreach>
        </if>
        <if test="berthNo != null and berthNo != ''">
            and berth_no = #{berthNo,jdbcType=VARCHAR}
        </if>
        <if test="optBeginTime != null">
            and appointment_opt_time > #{optBeginTime,jdbcType=TIMESTAMP}
        </if>
        <if test="optEndTime != null">
            and #{optEndTime,jdbcType=TIMESTAMP} > appointment_opt_time
        </if>
        order by appointment_opt_time desc
    </select>


    <select id="queryUnDoneAppointment" parameterType="com.zteits.clouds.api.dto.order.param.UnDoneOrderAppointmentRequest"
            resultType="com.zteits.clouds.api.dto.order.dto.UnDoneOrderAppointmentDTO">
        SELECT
	    t.pl_no AS plNo,
	    GROUP_CONCAT(t.order_id separator ',') AS orderIds,
	    count(t.order_id) AS num,
	    GROUP_CONCAT(t.car_number separator ',') AS carNumbers
        FROM
	    order_appointment t
	    where t.appointment_state = #{appointmentState} and t.push_state = #{pushState}
	    GROUP BY t.pl_no
    </select>
</mapper>