<?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.xinelu.manage.mapper.materialsinfo.MaterialsInfoMapper">

    <resultMap type="MaterialsInfo" id="MaterialsInfoResult">
            <result property="id" column="id"/>
            <result property="materialsName" column="materials_name"/>
            <result property="materialsType" column="materials_type"/>
            <result property="materialsOption" column="materials_option"/>
            <result property="materialsFilePath" column="materials_file_path"/>
            <result property="videoCoverType" column="video_cover_type"/>
            <result property="videoCoverFilePath" column="video_cover_file_path"/>
            <result property="materialsAbstract" column="materials_abstract"/>
            <result property="indications" column="indications"/>
            <result property="applicableDiseases" column="applicable_diseases"/>
            <result property="drugName" column="drug_name"/>
            <result property="surgicalName" column="surgical_name"/>
            <result property="checkItems" column="check_items"/>
            <result property="inspectionItems" column="inspection_items"/>
            <result property="crowdId" column="crowd_id"/>
            <result property="crowName" column="crow_name"/>
            <result property="materialsStatus" column="materials_status"/>
            <result property="materialsRemark" column="materials_remark"/>
            <result property="materialsSort" column="materials_sort"/>
	        <result property="delFlag" column="del_flag"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMaterialsInfoVo">
        select id, materials_name, materials_type, materials_option, materials_file_path, video_cover_type, video_cover_file_path, materials_abstract, indications, applicable_diseases, drug_name, surgical_name, check_items, inspection_items, crowd_id, crow_name, materials_status, materials_remark, materials_sort, del_flag, create_by, create_time, update_by, update_time from materials_info
    </sql>

    <select id="selectMaterialsInfoList" parameterType="com.xinelu.manage.dto.materialsinfo.MaterialsInfoDto" resultMap="MaterialsInfoResult">
        <include refid="selectMaterialsInfoVo"/>
        <where>
			del_flag = 0
            <if test="materialsName != null  and materialsName != ''">
                and materials_name like concat('%', #{materialsName}, '%')
            </if>
            <if test="materialsStatus != null  and materialsStatus != ''">
                and materials_status = #{materialsStatus}
            </if>
	        <if test="materialsType != null  and materialsType != ''">
		        and materials_type = #{materialsType}
	        </if>
            <if test="createTimeStart != null">
	            and date_format(create_time,'%y%m%d') >= date_format(#{createTimeStart},'%y%m%d')
            </if>
	        <if test="createTimeEnd != null">
		        and date_format(create_time,'%y%m%d') &lt;= date_format(#{createTimeEnd},'%y%m%d')
	        </if>
        </where>
        order by materials_sort, create_time desc
    </select>

    <select id="selectMaterialsInfoById" parameterType="Long"
            resultMap="MaterialsInfoResult">
            <include refid="selectMaterialsInfoVo"/>
            where id = #{id}
    </select>

    <insert id="insertMaterialsInfo" parameterType="MaterialsInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into materials_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="materialsName != null">materials_name,
                    </if>
                    <if test="materialsType != null">materials_type,
                    </if>
                    <if test="materialsOption != null">materials_option,
                    </if>
                    <if test="materialsFilePath != null">materials_file_path,
                    </if>
                    <if test="videoCoverType != null">video_cover_type,
                    </if>
                    <if test="videoCoverFilePath != null">video_cover_file_path,
                    </if>
                    <if test="materialsAbstract != null">materials_abstract,
                    </if>
                    <if test="indications != null">indications,
                    </if>
                    <if test="applicableDiseases != null">applicable_diseases,
                    </if>
                    <if test="drugName != null">drug_name,
                    </if>
                    <if test="surgicalName != null">surgical_name,
                    </if>
                    <if test="checkItems != null">check_items,
                    </if>
                    <if test="inspectionItems != null">inspection_items,
                    </if>
                    <if test="crowdId != null">crowd_id,
                    </if>
                    <if test="crowName != null">crow_name,
                    </if>
                    <if test="materialsStatus != null">materials_status,
                    </if>
                    <if test="materialsRemark != null">materials_remark,
                    </if>
                    <if test="materialsSort != null">materials_sort,
                    </if>
			        <if test="delFlag != null">del_flag,
			        </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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="materialsName != null">#{materialsName},
                    </if>
                    <if test="materialsType != null">#{materialsType},
                    </if>
                    <if test="materialsOption != null">#{materialsOption},
                    </if>
                    <if test="materialsFilePath != null">#{materialsFilePath},
                    </if>
                    <if test="videoCoverType != null">#{videoCoverType},
                    </if>
                    <if test="videoCoverFilePath != null">#{videoCoverFilePath},
                    </if>
                    <if test="materialsAbstract != null">#{materialsAbstract},
                    </if>
                    <if test="indications != null">#{indications},
                    </if>
                    <if test="applicableDiseases != null">#{applicableDiseases},
                    </if>
                    <if test="drugName != null">#{drugName},
                    </if>
                    <if test="surgicalName != null">#{surgicalName},
                    </if>
                    <if test="checkItems != null">#{checkItems},
                    </if>
                    <if test="inspectionItems != null">#{inspectionItems},
                    </if>
                    <if test="crowdId != null">#{crowdId},
                    </if>
                    <if test="crowName != null">#{crowName},
                    </if>
                    <if test="materialsStatus != null">#{materialsStatus},
                    </if>
                    <if test="materialsRemark != null">#{materialsRemark},
                    </if>
                    <if test="materialsSort != null">#{materialsSort},
                    </if>
			        <if test="delFlag != null">#{delFlag},
			        </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>
        </trim>
    </insert>

    <update id="updateMaterialsInfo" parameterType="MaterialsInfo">
        update materials_info
        <trim prefix="SET" suffixOverrides=",">
                    <if test="materialsName != null">materials_name =
                        #{materialsName},
                    </if>
                    <if test="materialsType != null">materials_type =
                        #{materialsType},
                    </if>
                    <if test="materialsOption != null">materials_option =
                        #{materialsOption},
                    </if>
                    <if test="materialsFilePath != null">materials_file_path =
                        #{materialsFilePath},
                    </if>
                    <if test="videoCoverType != null">video_cover_type =
                        #{videoCoverType},
                    </if>
                    <if test="videoCoverFilePath != null">video_cover_file_path =
                        #{videoCoverFilePath},
                    </if>
                    <if test="materialsAbstract != null">materials_abstract =
                        #{materialsAbstract},
                    </if>
                    <if test="indications != null">indications =
                        #{indications},
                    </if>
                    <if test="applicableDiseases != null">applicable_diseases =
                        #{applicableDiseases},
                    </if>
                    <if test="drugName != null">drug_name =
                        #{drugName},
                    </if>
                    <if test="surgicalName != null">surgical_name =
                        #{surgicalName},
                    </if>
                    <if test="checkItems != null">check_items =
                        #{checkItems},
                    </if>
                    <if test="inspectionItems != null">inspection_items =
                        #{inspectionItems},
                    </if>
                    <if test="crowdId != null">crowd_id =
                        #{crowdId},
                    </if>
                    <if test="crowName != null">crow_name =
                        #{crowName},
                    </if>
                    <if test="materialsStatus != null">materials_status =
                        #{materialsStatus},
                    </if>
                    <if test="materialsRemark != null">materials_remark =
                        #{materialsRemark},
                    </if>
                    <if test="materialsSort != null">materials_sort =
                        #{materialsSort},
                    </if>
			        <if test="delFlag != null">del_flag =
				        #{delFlag},
			        </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>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteMaterialsInfoById" parameterType="Long">
        update materials_info set del_flag = 1 where id = #{id}
    </update>

    <update id="deleteMaterialsInfoByIds" parameterType="String">
	    update materials_info set del_flag = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>