<?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="cn.com.tenlion.materialstore.dao.materialstore.IMaterialStoreDao">

    <resultMap id="materialStoreDTO" type="cn.com.tenlion.materialstore.pojo.dtos.materialstore.MaterialStoreDTO">
        <result column="material_store_id" property="materialStoreId"/>
        <result column="material_store_title" property="materialStoreTitle"/>
        <result column="material_store_open" property="materialStoreOpen"/>
        <result column="material_store_order" property="materialStoreOrder"/>
        <result column="material_store_status" property="materialStoreStatus"/>
        <result column="material_store_photo" property="materialStorePhoto"/>
        <result column="material_store_type" property="materialStoreType"/>
        <result column="material_store_check_status" property="materialStoreCheckStatus"/>
        <result column="material_store_check_remark" property="materialStoreCheckRemark"/>
        <result column="material_store_mode" property="materialStoreMode"/>
        <result column="material_store_url" property="materialStoreUrl"/>
        <result column="material_store_top" property="materialStoreTop"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="materialStoreBO" type="cn.com.tenlion.materialstore.pojo.bos.materialstore.MaterialStoreBO">
        <result column="material_store_id" property="materialStoreId"/>
        <result column="material_store_title" property="materialStoreTitle"/>
        <result column="material_store_open" property="materialStoreOpen"/>
        <result column="material_store_order" property="materialStoreOrder"/>
        <result column="material_store_status" property="materialStoreStatus"/>
        <result column="material_store_photo" property="materialStorePhoto"/>
        <result column="material_store_type" property="materialStoreType"/>
        <result column="material_store_check_status" property="materialStoreCheckStatus"/>
        <result column="material_store_check_remark" property="materialStoreCheckRemark"/>
        <result column="material_store_mode" property="materialStoreMode"/>
        <result column="material_store_url" property="materialStoreUrl"/>
        <result column="material_store_top" property="materialStoreTop"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="materialStorePO" type="cn.com.tenlion.materialstore.pojo.pos.materialstore.MaterialStorePO">
        <result column="material_store_id" property="materialStoreId"/>
        <result column="material_store_title" property="materialStoreTitle"/>
        <result column="material_store_open" property="materialStoreOpen"/>
        <result column="material_store_order" property="materialStoreOrder"/>
        <result column="material_store_status" property="materialStoreStatus"/>
        <result column="material_store_photo" property="materialStorePhoto"/>
        <result column="material_store_type" property="materialStoreType"/>
        <result column="material_store_check_status" property="materialStoreCheckStatus"/>
        <result column="material_store_check_remark" property="materialStoreCheckRemark"/>
        <result column="material_store_mode" property="materialStoreMode"/>
        <result column="material_store_url" property="materialStoreUrl"/>
        <result column="material_store_top" property="materialStoreTop"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <!-- 新增CBC素材包 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_material_store(
            material_store_id,
            material_store_title,
            material_store_open,
            material_store_order,
            material_store_status,
            material_store_photo,
            material_store_type,
            material_store_check_status,
            material_store_check_remark,
            material_store_mode,
            material_store_url,
            material_store_top,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{materialStoreId},
            #{materialStoreTitle},
            #{materialStoreOpen},
            #{materialStoreOrder},
            #{materialStoreStatus},
            #{materialStorePhoto},
            #{materialStoreType},
            #{materialStoreCheckStatus},
            #{materialStoreCheckRemark},
            #{materialStoreMode},
            #{materialStoreUrl},
            #{materialStoreTop},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除CBC素材包 -->
    <update id="remove" parameterType="map">
        UPDATE
            m_material_store
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            material_store_id IN
        <foreach collection="materialStoreIds" index="index" open="(" separator="," close=")">
            #{materialStoreIds[${index}]}
        </foreach>
    </update>

    <!-- 删除CBC素材包（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            m_material_store
        WHERE
            material_store_id IN
        <foreach collection="materialStoreIds" index="index" open="(" separator="," close=")">
            #{materialStoreIds[${index}]}
        </foreach>
    </update>

    <!-- 修改CBC素材包 -->
    <update id="update" parameterType="map">
        UPDATE
            m_material_store
        SET
        <if test="materialStoreTitle != null and materialStoreTitle != ''">
            material_store_title = #{materialStoreTitle},
        </if>
        <if test="materialStoreOpen != null">
            material_store_open = #{materialStoreOpen},w
        </if>
        <if test="materialStoreOrder != null">
            material_store_order = #{materialStoreOrder},
        </if>
        <if test="materialStoreStatus != null">
            material_store_status = #{materialStoreStatus},w
        </if>
        <if test="materialStorePhoto != null and materialStorePhoto != ''">
            material_store_photo = #{materialStorePhoto},
        </if>
        <if test="materialStoreType != null">
            material_store_type = #{materialStoreType},w
        </if>
        <if test="materialStoreCheckStatus != null">
            material_store_check_status = #{materialStoreCheckStatus},w
        </if>
        <if test="materialStoreCheckRemark != null and materialStoreCheckRemark != ''">
            material_store_check_remark = #{materialStoreCheckRemark},
        </if>
        <if test="materialStoreMode != null">
            material_store_mode = #{materialStoreMode},w
        </if>
        <if test="materialStoreUrl != null and materialStoreUrl != ''">
            material_store_url = #{materialStoreUrl},
        </if>
        <if test="materialStoreTop != null and materialStoreTop != ''">
            material_store_top = #{materialStoreTop},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            material_store_id = material_store_id
        WHERE
            material_store_id = #{materialStoreId}
    </update>

    <!-- CBC素材包详情 -->
    <select id="get" parameterType="map" resultMap="materialStoreDTO">
        SELECT
            t1.material_store_title,
            t1.material_store_open,
            t1.material_store_order,
            t1.material_store_status,
            t1.material_store_photo,
            t1.material_store_type,
            t1.material_store_check_status,
            t1.material_store_check_remark,
            t1.material_store_mode,
            t1.material_store_url,
            t1.material_store_top,
            t1.material_store_id
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
            <if test="materialStoreId != null and materialStoreId != ''">
        AND
            t1.material_store_id = #{materialStoreId}
            </if>
    </select>

    <!-- CBC素材包详情 -->
    <select id="getBO" parameterType="map" resultMap="materialStoreBO">
        SELECT
            t1.material_store_id,
            t1.material_store_title,
            t1.material_store_open,
            t1.material_store_order,
            t1.material_store_status,
            t1.material_store_photo,
            t1.material_store_type,
            t1.material_store_check_status,
            t1.material_store_check_remark,
            t1.material_store_mode,
            t1.material_store_url,
            t1.material_store_top,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
            <if test="materialStoreId != null and materialStoreId != ''">
        AND
            t1.material_store_id = #{materialStoreId}
            </if>
    </select>

    <!-- CBC素材包详情 -->
    <select id="getPO" parameterType="map" resultMap="materialStorePO">
        SELECT
            t1.material_store_id,
            t1.material_store_title,
            t1.material_store_open,
            t1.material_store_order,
            t1.material_store_status,
            t1.material_store_photo,
            t1.material_store_type,
            t1.material_store_check_status,
            t1.material_store_check_remark,
            t1.material_store_mode,
            t1.material_store_url,
            t1.material_store_top,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
            <if test="materialStoreId != null and materialStoreId != ''">
        AND
            t1.material_store_id = #{materialStoreId}
            </if>
    </select>

    <!-- CBC素材包列表 -->
    <select id="list" parameterType="map" resultMap="materialStoreDTO">
        SELECT
            t1.material_store_id,
            t1.material_store_title,
            t1.material_store_open,
            t1.material_store_order,
            t1.material_store_status,
            t1.material_store_photo,
            t1.material_store_type,
            t1.material_store_check_status,
            t1.material_store_check_remark,
            t1.material_store_mode,
            t1.material_store_url,
            t1.material_store_top,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            1
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="materialStoreIds != null and materialStoreIds.size > 0">
        AND
            t1.material_store_id IN
            <foreach collection="materialStoreIds" index="index" open="(" separator="," close=")">
                #{materialStoreIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC素材包列表 -->
    <select id="listBO" parameterType="map" resultMap="materialStoreBO">
        SELECT
            t1.material_store_id,
            t1.material_store_title,
            t1.material_store_open,
            t1.material_store_order,
            t1.material_store_status,
            t1.material_store_photo,
            t1.material_store_type,
            t1.material_store_check_status,
            t1.material_store_check_remark,
            t1.material_store_mode,
            t1.material_store_url,
            t1.material_store_top,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="materialStoreIds != null and materialStoreIds.size > 0">
        AND
            t1.material_store_id IN
            <foreach collection="materialStoreIds" index="index" open="(" separator="," close=")">
                #{materialStoreIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC素材包列表 -->
    <select id="listPO" parameterType="map" resultMap="materialStorePO">
        SELECT
            t1.material_store_id,
            t1.material_store_title,
            t1.material_store_open,
            t1.material_store_order,
            t1.material_store_status,
            t1.material_store_photo,
            t1.material_store_type,
            t1.material_store_check_status,
            t1.material_store_check_remark,
            t1.material_store_mode,
            t1.material_store_url,
            t1.material_store_top,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="materialStoreIds != null and materialStoreIds.size > 0">
        AND
            t1.material_store_id IN
            <foreach collection="materialStoreIds" index="index" open="(" separator="," close=")">
                #{materialStoreIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC素材包统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_material_store t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>