<?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.cyl.manager.oms.mapper.OmsOrderServiceMapper">
    
    <resultMap type="OmsOrderService" id="OmsOrderServiceResult">
        <result property="id" column="id"/>
        <result property="orderId" column="order_id"/>
        <result property="pet" column="pet"/>
        <result property="serviceFrequency" column="service_frequency"/>
        <result property="serviceDate" column="service_date"/>
        <result property="serviceTimeFirst" column="service_time_first"/>
        <result property="serviceTimeSecond" column="service_time_second"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>

        <result property="feedCount" column="feed_count"/>
        <result property="petId" column="pet_id"/>
        <result property="expectServiceTime" column="expect_service_time"/>
    </resultMap>

    <sql id="selectOmsOrderServiceVo">
        select id, order_id, pet, service_frequency, service_date, service_time_first, service_time_second, create_by, create_time, update_by, update_time, del_flag , create_by, create_time, update_by, update_time, feed_count, pet_id, expect_service_time from oms_order_service
    </sql>

    <select id="selectListBySql" parameterType="OmsOrderService" resultMap="OmsOrderServiceResult">
        <include refid="selectOmsOrderServiceVo"/>
        <where>  
            <if test="orderId != null "> and order_id = #{orderId}</if>
            <if test="pet != null  and pet != ''"> and pet = #{pet}</if>
            <if test="serviceFrequency != null  and serviceFrequency != ''"> and service_frequency = #{serviceFrequency}</if>
            <if test="serviceDate != null  and serviceDate != ''"> and service_date = #{serviceDate}</if>
            <if test="serviceTimeFirst != null  and serviceTimeFirst != ''"> and service_time_first = #{serviceTimeFirst}</if>
            <if test="serviceTimeSecond != null "> and service_time_second = #{serviceTimeSecond}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectById" parameterType="Long" resultMap="OmsOrderServiceResult">
        <include refid="selectOmsOrderServiceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insert" parameterType="OmsOrderService">
        insert into oms_order_service
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="pet != null">pet,</if>
            <if test="serviceFrequency != null">service_frequency,</if>
            <if test="serviceDate != null">service_date,</if>
            <if test="serviceTimeFirst != null">service_time_first,</if>
            <if test="serviceTimeSecond != null">service_time_second,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="petId != null">pet_id,</if>
            <if test="expectServiceTime != null">expect_service_time,</if>
            <if test="feedCount != null">feed_count,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="pet != null">#{pet},</if>
            <if test="serviceFrequency != null">#{serviceFrequency},</if>
            <if test="serviceDate != null">#{serviceDate},</if>
            <if test="serviceTimeFirst != null">#{serviceTimeFirst},</if>
            <if test="serviceTimeSecond != null">#{serviceTimeSecond},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="petId != null">#{petId},</if>
            <if test="expectServiceTime != null">#{expectServiceTime},</if>
            <if test="feedCount != null">#{feedCount},</if>
        </trim>
    </insert>

    <update id="update" parameterType="OmsOrderService">
        update oms_order_service
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="pet != null">pet = #{pet},</if>
            <if test="serviceFrequency != null">service_frequency = #{serviceFrequency},</if>
            <if test="serviceDate != null">service_date = #{serviceDate},</if>
            <if test="serviceTimeFirst != null">service_time_first = #{serviceTimeFirst},</if>
            <if test="serviceTimeSecond != null">service_time_second = #{serviceTimeSecond},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="petId != null">pet_id = #{petId},</if>
            <if test="expectServiceTime != null">expect_service_time = #{expectServiceTime},</if>
            <if test="feedCount != null">feed_count = #{feedCount},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteById" parameterType="Long">
        delete from oms_order_service where id = #{id}
    </delete>

    <delete id="deleteByIds" parameterType="String">
        delete from oms_order_service where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertOrUpdate" parameterType="OmsOrderService" useGeneratedKeys="true" keyProperty="id">
        insert into oms_order_service
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
             order_id, pet, service_frequency, service_date, service_time_first, service_time_second, create_by, create_time, update_by, update_time, del_flag,pet_id,expect_service_time,feed_count
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id, jdbcType=BIGINT},
        </if>
        #{orderId, jdbcType=BIGINT},#{pet, jdbcType=VARCHAR},#{serviceFrequency, jdbcType=VARCHAR},#{serviceDate, jdbcType=VARCHAR},#{serviceTimeFirst, jdbcType=VARCHAR},#{serviceTimeSecond, jdbcType=DATE},#{createBy, jdbcType=BIGINT},#{createTime, jdbcType=DATE},#{updateBy, jdbcType=BIGINT},#{updateTime, jdbcType=DATE},#{delFlag, jdbcType=TINYINT},#{petId, jdbcType=BIGINT},#{expectServiceTime, jdbcType=VARCHAR},#{feedCount, jdbcType=INTEGER}
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=BIGINT},
            </if>
            order_id = #{orderId, jdbcType=BIGINT},
            pet = #{pet, jdbcType=VARCHAR},
            service_frequency = #{serviceFrequency, jdbcType=VARCHAR},
            service_date = #{serviceDate, jdbcType=VARCHAR},
            service_time_first = #{serviceTimeFirst, jdbcType=VARCHAR},
            service_time_second = #{serviceTimeSecond, jdbcType=DATE},
            create_by = #{createBy, jdbcType=BIGINT},
            create_time = #{createTime, jdbcType=DATE},
            update_by = #{updateBy, jdbcType=BIGINT},
            update_time = #{updateTime, jdbcType=DATE},
            del_flag = #{delFlag, jdbcType=TINYINT},
            pet_id = #{petId, jdbcType=BIGINT},
            expect_service_time = #{expectServiceTime, jdbcType=VARCHAR},
            feed_count = #{feedCount, jdbcType=INTEGER},
        </trim>
    </insert>
</mapper>
