<?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.PreReviewRecordsMapper">

	<resultMap id="baseResultMap" type="org.jeecg.modules.ai.vo.PreReviewRecordsVo" >
		<result column="id" property="id" jdbcType="VARCHAR"/>
		<result column="display_name" property="displayName" jdbcType="VARCHAR"/>
		<result column="event_code" property="eventCode" jdbcType="VARCHAR"/>
		<result column="evaluate_status" property="evaluateStatus" jdbcType="INTEGER"/>
		<result column="valid_status" property="validStatus" jdbcType="INTEGER"/>
		<result column="material_bag" property="materialBag" jdbcType="VARCHAR"/>
		<result column="is_material" property="isMaterial" jdbcType="INTEGER"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
	</resultMap>
	
	<sql id="prereviewrecords_column_body">
         a.id,b.display_name,a.event_code,a.valid_status,a.evaluate_status,a.material_bag,
         a.is_material,a.create_time
    </sql>
	
	<sql id="prereviewrecords_select_body">
    	<where>
    		<if test="query.displayName != null and query.displayName != ''"> and b.display_name like CONCAT('%', #{query.displayName}, '%') </if>
    		<if test="query.eventCode != null and query.eventCode != ''"> and a.event_code like CONCAT('%', #{query.eventCode}, '%') </if>
    		<if test="query.materialBag != null and query.materialBag != ''"> and a.material_bag = #{query.materialBag,jdbcType=VARCHAR} </if>
    		<if test="query.materialType != null and query.materialType != ''"> and c.type = #{query.materialType,jdbcType=VARCHAR} </if>
    		<if test="query.orgCode != null and query.orgCode != ''"> and c.site = #{query.orgCode,jdbcType=VARCHAR} </if>
    		<if test="query.validStatus != null"> and a.valid_status = #{query.validStatus,jdbcType=INTEGER} </if>
    		<if test="query.evaluateStatus != null"> and a.evaluate_status = #{query.evaluateStatus,jdbcType=INTEGER} </if>
    	</where>
    </sql>

	<select id="getPreReviewRecordsList" resultMap="baseResultMap" >
		select <include refid="prereviewrecords_column_body" />
		from pre_review_records a 
		left join pre_examination_matters b on a.event_code = b.event_code
		left join material_bag c on a.material_bag = c.code
		<include refid="prereviewrecords_select_body" /> 
	</select>
	
	<select id="getSendMsgRecordsCount" resultMap="baseResultMap" >
		select count(1) as sendCount,b.display_name,a.event_code
		from pre_review_records a 
		left join pre_examination_matters b on a.event_code = b.event_code
		where a.send_sms_flag = 1 and DATE(a.send_sms_time) = CURDATE() group by a.event_code
	</select>
	

</mapper>