<?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.boco.nbd.wios.manage.mapper.def.OrderInstallItemMapper">

    <resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.OrderInstallItem">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="item_type" jdbcType="INTEGER" property="itemType"/>
        <result column="item_id" jdbcType="VARCHAR" property="itemId"/>
        <result column="item_name" jdbcType="VARCHAR" property="itemName"/>
        <result column="item_model" jdbcType="VARCHAR" property="itemModel"/>
        <result column="item_warehouse_id" jdbcType="VARCHAR" property="itemWarehouseId"/>
        <result column="contract_item_id" jdbcType="INTEGER" property="contractItemId"/>
        <result column="qunatity" jdbcType="DECIMAL" property="qunatity"/>
        <result column="fee" jdbcType="DECIMAL" property="fee"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <result column="create_account" jdbcType="VARCHAR" property="createAccount"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="modify_account" jdbcType="VARCHAR" property="modifyAccount"/>
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
    </resultMap>


    <sql id="Base_Column_List">
        id
        , order_id, type, item_type, item_id, item_name, item_model, item_warehouse_id,
  contract_item_id, qunatity, fee, description, create_account, create_time, modify_account, 
  modify_time
    </sql>


    <delete id="delete" parameterType="java.lang.Integer">
        delete
        from t_order_install_item
        where id = #{id,jdbcType=INTEGER}
    </delete>


    <insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.OrderInstallItem">
        insert into t_order_install_item (id, order_id, type,
                                          item_type, item_id, item_name,
                                          item_model, item_warehouse_id, contract_item_id,
                                          qunatity, fee, description,
                                          create_account, create_time, modify_account,
                                          modify_time)
        values (#{id,jdbcType=INTEGER}, #{orderId,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
                #{itemType,jdbcType=INTEGER}, #{itemId,jdbcType=VARCHAR}, #{itemName,jdbcType=VARCHAR},
                #{itemModel,jdbcType=VARCHAR}, #{itemWarehouseId,jdbcType=VARCHAR}, #{contractItemId,jdbcType=INTEGER},
                #{qunatity,jdbcType=DECIMAL}, #{fee,jdbcType=DECIMAL}, #{description,jdbcType=VARCHAR},
                #{createAccount,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{modifyAccount,jdbcType=VARCHAR},
                #{modifyTime,jdbcType=TIMESTAMP})
    </insert>


    <insert id="insertDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.OrderInstallItem">
        insert into t_order_install_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="orderId != null">
                order_id,
            </if>
            <if test="type != null">
                type,
            </if>
            <if test="itemType != null">
                item_type,
            </if>
            <if test="itemId != null">
                item_id,
            </if>
            <if test="itemName != null">
                item_name,
            </if>
            <if test="itemModel != null">
                item_model,
            </if>
            <if test="itemWarehouseId != null">
                item_warehouse_id,
            </if>
            <if test="contractItemId != null">
                contract_item_id,
            </if>
            <if test="qunatity != null">
                qunatity,
            </if>
            <if test="fee != null">
                fee,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="createAccount != null">
                create_account,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="modifyAccount != null">
                modify_account,
            </if>
            <if test="modifyTime != null">
                modify_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="orderId != null">
                #{orderId,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                #{type,jdbcType=INTEGER},
            </if>
            <if test="itemType != null">
                #{itemType,jdbcType=INTEGER},
            </if>
            <if test="itemId != null">
                #{itemId,jdbcType=VARCHAR},
            </if>
            <if test="itemName != null">
                #{itemName,jdbcType=VARCHAR},
            </if>
            <if test="itemModel != null">
                #{itemModel,jdbcType=VARCHAR},
            </if>
            <if test="itemWarehouseId != null">
                #{itemWarehouseId,jdbcType=VARCHAR},
            </if>
            <if test="contractItemId != null">
                #{contractItemId,jdbcType=INTEGER},
            </if>
            <if test="qunatity != null">
                #{qunatity,jdbcType=DECIMAL},
            </if>
            <if test="fee != null">
                #{fee,jdbcType=DECIMAL},
            </if>
            <if test="description != null">
                #{description,jdbcType=VARCHAR},
            </if>
            <if test="createAccount != null">
                #{createAccount,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="modifyAccount != null">
                #{modifyAccount,jdbcType=VARCHAR},
            </if>
            <if test="modifyTime != null">
                #{modifyTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>


    <update id="updateDynamic" parameterType="com.boco.nbd.wios.manage.entity.bo.OrderInstallItem">
        update t_order_install_item
        <set>
            <if test="orderId != null">
                order_id = #{orderId,jdbcType=VARCHAR},
            </if>
            <if test="type != null">
                type = #{type,jdbcType=INTEGER},
            </if>
            <if test="itemType != null">
                item_type = #{itemType,jdbcType=INTEGER},
            </if>
            <if test="itemId != null">
                item_id = #{itemId,jdbcType=VARCHAR},
            </if>
            <if test="itemName != null">
                item_name = #{itemName,jdbcType=VARCHAR},
            </if>
            <if test="itemModel != null">
                item_model = #{itemModel,jdbcType=VARCHAR},
            </if>
            <if test="itemWarehouseId != null">
                item_warehouse_id = #{itemWarehouseId,jdbcType=VARCHAR},
            </if>
            <if test="contractItemId != null">
                contract_item_id = #{contractItemId,jdbcType=INTEGER},
            </if>
            <if test="qunatity != null">
                qunatity = #{qunatity,jdbcType=DECIMAL},
            </if>
            <if test="fee != null">
                fee = #{fee,jdbcType=DECIMAL},
            </if>
            <if test="description != null">
                description = #{description,jdbcType=VARCHAR},
            </if>
            <if test="createAccount != null">
                create_account = #{createAccount,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="modifyAccount != null">
                modify_account = #{modifyAccount,jdbcType=VARCHAR},
            </if>
            <if test="modifyTime != null">
                modify_time = #{modifyTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>


    <update id="update" parameterType="com.boco.nbd.wios.manage.entity.bo.OrderInstallItem">
        update t_order_install_item
        set order_id          = #{orderId,jdbcType=VARCHAR},
            type              = #{type,jdbcType=INTEGER},
            item_type         = #{itemType,jdbcType=INTEGER},
            item_id           = #{itemId,jdbcType=VARCHAR},
            item_name         = #{itemName,jdbcType=VARCHAR},
            item_model        = #{itemModel,jdbcType=VARCHAR},
            item_warehouse_id = #{itemWarehouseId,jdbcType=VARCHAR},
            contract_item_id  = #{contractItemId,jdbcType=INTEGER},
            qunatity          = #{qunatity,jdbcType=DECIMAL},
            fee               = #{fee,jdbcType=DECIMAL},
            description       = #{description,jdbcType=VARCHAR},
            create_account    = #{createAccount,jdbcType=VARCHAR},
            create_time       = #{createTime,jdbcType=TIMESTAMP},
            modify_account    = #{modifyAccount,jdbcType=VARCHAR},
            modify_time       = #{modifyTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>


    <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_order_install_item
        where id = #{id,jdbcType=INTEGER}
    </select>

    <insert id="batchInsert" parameterType="java.util.List">
        insert into t_order_install_item (id, order_id,type, item_type,
        item_id, item_name, item_model,
        contract_item_id, qunatity, fee,
        description, create_account, create_time,
        modify_account, modify_time)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.id,jdbcType=INTEGER}, #{item.orderId,jdbcType=VARCHAR},#{item.type,jdbcType=INTEGER},
            #{item.itemType,jdbcType=INTEGER},
            #{item.itemId,jdbcType=VARCHAR}, #{item.itemName,jdbcType=VARCHAR}, #{item.itemModel,jdbcType=VARCHAR},
            #{item.contractItemId,jdbcType=INTEGER}, #{item.qunatity,jdbcType=DECIMAL}, #{item.fee,jdbcType=DECIMAL},
            #{item.description,jdbcType=VARCHAR}, #{item.createAccount,jdbcType=VARCHAR},
            #{item.createTime,jdbcType=TIMESTAMP},
            #{item.modifyAccount,jdbcType=VARCHAR}, #{item.modifyTime,jdbcType=TIMESTAMP})
        </foreach>
    </insert>

    <select id="selectByOrderIdAndType" resultType="com.boco.nbd.wios.manage.entity.bo.OrderInstallItemVo">
        select t.*, oci.price as price, oci.tax_rate as taxRate, oci.rate_price as ratePrice
        from t_order_install_item t
                 left join t_oem_contract_item oci on t.contract_item_id = oci.id
        where t.order_id = #{orderId}
          and t.type = #{type}
    </select>
    <select id="selectByOrderId" resultType="com.boco.nbd.wios.manage.entity.bo.OrderInstallItem">
        select
        <include refid="Base_Column_List"/>
        from t_order_install_item
        where order_id = #{orderId}
    </select>

    <delete id="deleteByOrderId">
        delete
        from t_order_install_item
        where order_id = #{orderId}
          and type = #{type}
    </delete>


    <select id="selectPackById" parameterType="String" resultType="com.boco.nbd.wios.manage.entity.bo.OemCascadeBo">
        SELECT
            id,
            NAME,
            parent_id
        FROM
            t_oem_cascade
        WHERE
            id=#{id}
    </select>

</mapper>