<?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="org.jeecg.modules.ai.mapper.PreReviewMaterialMapper">

	<resultMap id="baseResultMap" type="org.jeecg.modules.ai.vo.PreReviewMaterialVo" >
		<result column="id" property="id" jdbcType="VARCHAR"/>
		<result column="material_code" property="materialCode" jdbcType="VARCHAR"/>
		<result column="material_name" property="materialName" jdbcType="VARCHAR"/>
		<result column="material_type" property="materialType" jdbcType="VARCHAR"/>
		<result column="depart_name" property="departName" jdbcType="VARCHAR"/>
		<result column="material_url" property="materialUrl" jdbcType="VARCHAR"/>
		<result column="event_code" property="eventCode" jdbcType="VARCHAR"/>
		<result column="valid_status" property="validStatus" jdbcType="INTEGER"/>
	</resultMap>
	
	<sql id="prereviewmaterial_column_body">
         a.id,b.material_name,b.material_type,a.material_code,a.valid_status,c.depart_name,b.material_url,a.event_code
    </sql>
    
	<sql id="prereviewmaterial_column_body_bycode">
         a.id,b.material_name,b.material_type,a.material_code,a.valid_status,b.material_url,a.event_code
    </sql>
	
	<sql id="prereviewmaterial_select_body">
    	<where>
    		<if test="query.materialName != null and query.materialName != ''"> and b.material_name like CONCAT('%', #{query.materialName}, '%') </if>
    		<if test="query.materialCode != null and query.materialCode != ''"> and a.material_code like CONCAT('%', #{query.materialCode}, '%') </if>
    		<if test="query.orgCode != null and query.orgCode != ''"> and a.sys_org_code like CONCAT('%', #{query.orgCode}, '%') </if>
    		<if test="query.materialType != null"> and b.material_type = #{query.materialType,jdbcType=INTEGER} </if>
    		<if test="query.validStatus != null"> and a.valid_status = #{query.validStatus,jdbcType=INTEGER} </if>
    		<if test="query.eventCode != null"> and a.event_code = #{query.eventCode,jdbcType=INTEGER} </if>
    	</where>
    </sql>

	<select id="getPreReviewMaterialList" resultMap="baseResultMap" >
		select <include refid="prereviewmaterial_column_body" />
		from pre_review_material a 
		left join ys_directory_material b on a.material_code = b.material_code
		left join sys_depart c on a.sys_org_code = c.depart_code
		<include refid="prereviewmaterial_select_body" /> 
	</select>
	
	<select id="getPreReviewMaterialByCode" resultMap="baseResultMap" >
		select <include refid="prereviewmaterial_column_body_bycode" />
		from pre_review_material a 
		left join ys_directory_material b on a.material_code = b.material_code
		where a.material_code = #{materialCode,jdbcType=VARCHAR}
	</select>
</mapper>