<?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.ghy.goods.mapper.CategoryInsuranceRelationMapper">

    <resultMap type="CategoryInsuranceRelation" id="CategoryInsuranceRelationResult">
        <result property="id"    column="id"    />
        <result property="insuranceId"    column="insurance_id"    />
        <result property="goodsCategoryId"    column="goods_category_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCategoryInsuranceRelationVo">
        select id, insurance_id, goods_category_id, create_by, update_by, create_time, update_time, remark from category_insurance_relation
    </sql>

    <select id="selectCategoryInsuranceRelationList" parameterType="CategoryInsuranceRelation" resultMap="CategoryInsuranceRelationResult">
        <include refid="selectCategoryInsuranceRelationVo"/>
        <where>
            <if test="insuranceId != null "> and insurance_id = #{insuranceId}</if>
            <if test="goodsCategoryId != null "> and goods_category_id = #{goodsCategoryId}</if>
        </where>
    </select>

    <select id="selectCategoryInsuranceRelationById" parameterType="Long" resultMap="CategoryInsuranceRelationResult">
        <include refid="selectCategoryInsuranceRelationVo"/>
        where id = #{id}
    </select>

    <insert id="insertCategoryInsuranceRelation" parameterType="CategoryInsuranceRelation" useGeneratedKeys="true" keyProperty="id">
        insert into category_insurance_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="insuranceId != null">insurance_id,</if>
            <if test="goodsCategoryId != null">goods_category_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="insuranceId != null">#{insuranceId},</if>
            <if test="goodsCategoryId != null">#{goodsCategoryId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateCategoryInsuranceRelation" parameterType="CategoryInsuranceRelation">
        update category_insurance_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="insuranceId != null">insurance_id = #{insuranceId},</if>
            <if test="goodsCategoryId != null">goods_category_id = #{goodsCategoryId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCategoryInsuranceRelationById" parameterType="Long">
        delete from category_insurance_relation where id = #{id}
    </delete>

    <delete id="deleteCategoryInsuranceRelationByIds" parameterType="String">
        delete from category_insurance_relation where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>