<?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.yiqi.core.mapper.ClothWashModeRelationMapper">

    <resultMap type="ClothWashModeRelation" id="ClothWashModeRelationResult">
        <result property="id" column="id"/>
        <result property="washModeId" column="wash_mode_id"/>
        <result property="clothTypeId" column="cloth_type_id"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectClothWashModeRelationVo">
        select id, wash_mode_id, cloth_type_id, create_by_id, create_by, create_time, update_by_id, update_by, update_time, remark
        from cloth_wash_mode_relation
    </sql>

    <select id="selectClothWashModeRelationList" parameterType="ClothWashModeRelation" resultMap="ClothWashModeRelationResult">
        <include refid="selectClothWashModeRelationVo"/>
        <where>
            <if test="washModeId != null ">
                and wash_mode_id = #{washModeId}
            </if>
            <if test="clothTypeId != null ">
                and cloth_type_id = #{clothTypeId}
            </if>
        </where>
    </select>

    <select id="selectClothWashModeRelationById" parameterType="Long"
            resultMap="ClothWashModeRelationResult">
        <include refid="selectClothWashModeRelationVo"/>
        where id = #{id}
    </select>
    <select id="selectWashModePriceByClothId" resultType="com.yiqi.core.domain.vo.ClothPriceVO">
        select wmr.wash_mode_id,
               wm.name             as wash_mode_name,
               ifnull(cp.price, 0) as price
        from cloth_wash_mode_relation as wmr
                 left join cloth_wash_mode as wm on wm.id = wmr.wash_mode_id
                 left join cloth_price as cp
                           on cp.wash_mode_id = wmr.wash_mode_id and cp.price_type = '0' and store_area_id = #{storeAreaId} and cloth_id = #{clothId}
        where wmr.cloth_type_id = (select type_id from cloth_item where id = #{clothId})
          and wm.status = '0'
          and del_flag = '0';
    </select>

    <insert id="insertClothWashModeRelation" parameterType="ClothWashModeRelation" useGeneratedKeys="true"
            keyProperty="id">
        insert into cloth_wash_mode_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="washModeId != null">wash_mode_id,
            </if>
            <if test="clothTypeId != null">cloth_type_id,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="washModeId != null">#{washModeId},
            </if>
            <if test="clothTypeId != null">#{clothTypeId},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateClothWashModeRelation" parameterType="ClothWashModeRelation">
        update cloth_wash_mode_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="washModeId != null">wash_mode_id =
                #{washModeId},
            </if>
            <if test="clothTypeId != null">cloth_type_id =
                #{clothTypeId},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteClothWashModeRelationById" parameterType="Long">
            delete from cloth_wash_mode_relation where id = #{id}
        </delete>

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



</mapper>