<?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.screeningproject.ScreeningProjectMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.manage.domain.screeningproject.ScreeningProject">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <id property="projectId" column="project_id" jdbcType="VARCHAR"/>
            <result property="projectName" column="project_name" jdbcType="VARCHAR"/>
            <result property="projectType" column="project_type" jdbcType="CHAR"/>
            <result property="price" column="price" jdbcType="DECIMAL"/>
            <result property="discount" column="discount" jdbcType="INTEGER"/>
            <result property="discountPrice" column="discount_price" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="CHAR"/>
            <result property="hospitalId" column="hospital_id" jdbcType="BIGINT"/>
            <result property="hospitalName" column="hospital_name" jdbcType="VARCHAR"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="DATE"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="DATE"/>
            <result property="delFlag" column="del_flag" jdbcType="CHAR"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,project_id,project_name,
        project_type,price,discount,
        discount_price,status,hospital_id,
        hospital_name,create_by,create_time,
        update_by,update_time,del_flag,
        remark
    </sql>

	<select id="findList" resultMap="BaseResultMap">
		select <include refid="Base_Column_List" />
		from screening_project
		where del_flag = '0'
		<if test="projectName != null and projectName != ''">
			and project_name like concat( '%' ,#{projectName}, '%')
		</if>
		<if test="hospitalId != null and hospitalId != ''">
			and (hospital_id = #{hospitalId} or hospital_id = 0)
		</if>
        <if test="projectType != null and projectType != ''">
            and project_type = #{projectType}
        </if>
		<if test="status != null and status != ''">
			and `status` = #{status}
		</if>
		<if test="createTime != null">
			and date_format(create_time,'%Y%m%d') = date_format(#{createTime},'%Y%m%d')
		</if>
        order By hospital_id asc
	</select>

    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from screening_project
        where project_id = #{projectId,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete from screening_project
        where project_id = #{projectId,jdbcType=VARCHAR}
    </delete>
    <insert id="insert">
        insert into screening_project
        ( id,project_id,project_name
        ,project_type,price,discount
        ,discount_price,status,hospital_id
        ,hospital_name,create_by,create_time
        ,update_by,update_time,del_flag
        ,remark)
        values (#{id,jdbcType=BIGINT},#{projectId,jdbcType=VARCHAR},#{projectName,jdbcType=VARCHAR}
        ,#{projectType,jdbcType=CHAR},#{price,jdbcType=DECIMAL},#{discount,jdbcType=INTEGER}
        ,#{discountPrice,jdbcType=VARCHAR},#{status,jdbcType=CHAR},#{hospitalId,jdbcType=BIGINT}
        ,#{hospitalName,jdbcType=VARCHAR},#{createBy,jdbcType=VARCHAR},#{createTime,jdbcType=DATE}
        ,#{updateBy,jdbcType=VARCHAR},#{updateTime,jdbcType=DATE},#{delFlag,jdbcType=CHAR}
        ,#{remark,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective">
        insert into screening_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="projectId != null">project_id,</if>
                <if test="projectName != null">project_name,</if>
                <if test="projectType != null">project_type,</if>
                <if test="price != null">price,</if>
                <if test="discount != null">discount,</if>
                <if test="discountPrice != null">discount_price,</if>
                <if test="status != null">status,</if>
                <if test="hospitalId != null">hospital_id,</if>
                <if test="hospitalName != null">hospital_name,</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>
                <if test="delFlag != null">del_flag,</if>
                <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=BIGINT},</if>
                <if test="projectId != null">#{projectId,jdbcType=VARCHAR},</if>
                <if test="projectName != null">#{projectName,jdbcType=VARCHAR},</if>
                <if test="projectType != null">#{projectType,jdbcType=CHAR},</if>
                <if test="price != null">#{price,jdbcType=DECIMAL},</if>
                <if test="discount != null">#{discount,jdbcType=INTEGER},</if>
                <if test="discountPrice != null">#{discountPrice,jdbcType=DECIMAL},</if>
                <if test="status != null">#{status,jdbcType=CHAR},</if>
                <if test="hospitalId != null">#{hospitalId,jdbcType=BIGINT},</if>
                <if test="hospitalName != null">#{hospitalName,jdbcType=VARCHAR},</if>
                <if test="createBy != null">#{createBy,jdbcType=VARCHAR},</if>
                <if test="createTime != null">#{createTime,jdbcType=DATE},</if>
                <if test="updateBy != null">#{updateBy,jdbcType=VARCHAR},</if>
                <if test="updateTime != null">#{updateTime,jdbcType=DATE},</if>
                <if test="delFlag != null">#{delFlag,jdbcType=CHAR},</if>
                <if test="remark != null">#{remark,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.xinelu.manage.domain.screeningproject.ScreeningProject">
        update screening_project
        <set>
                <if test="projectName != null">
                    project_name = #{projectName,jdbcType=VARCHAR},
                </if>
                <if test="projectType != null">
                    project_type = #{projectType,jdbcType=CHAR},
                </if>
                <if test="price != null">
                    price = #{price,jdbcType=DECIMAL},
                </if>
                <if test="discount != null">
                    discount = #{discount,jdbcType=INTEGER},
                </if>
                <if test="discountPrice != null">
                    discount_price = #{discountPrice,jdbcType=VARCHAR},
                </if>
                <if test="status != null">
                    status = #{status,jdbcType=CHAR},
                </if>
                <if test="hospitalId != null">
                    hospital_id = #{hospitalId,jdbcType=BIGINT},
                </if>
                <if test="hospitalName != null">
                    hospital_name = #{hospitalName,jdbcType=VARCHAR},
                </if>
                <if test="createBy != null">
                    create_by = #{createBy,jdbcType=VARCHAR},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=DATE},
                </if>
                <if test="updateBy != null">
                    update_by = #{updateBy,jdbcType=VARCHAR},
                </if>
                <if test="updateTime != null">
                    update_time = #{updateTime,jdbcType=DATE},
                </if>
                <if test="delFlag != null">
                    del_flag = #{delFlag,jdbcType=CHAR},
                </if>
                <if test="remark != null">
                    remark = #{remark,jdbcType=VARCHAR},
                </if>
        </set>
        where project_id = #{projectId,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.xinelu.manage.domain.screeningproject.ScreeningProject">
        update screening_project
        set
            project_name =  #{projectName,jdbcType=VARCHAR},
            project_type =  #{projectType,jdbcType=CHAR},
            price =  #{price,jdbcType=DECIMAL},
            discount =  #{discount,jdbcType=INTEGER},
            discount_price =  #{discountPrice,jdbcType=VARCHAR},
            status =  #{status,jdbcType=CHAR},
            hospital_id =  #{hospitalId,jdbcType=BIGINT},
            hospital_name =  #{hospitalName,jdbcType=VARCHAR},
            create_by =  #{createBy,jdbcType=VARCHAR},
            create_time =  #{createTime,jdbcType=DATE},
            update_by =  #{updateBy,jdbcType=VARCHAR},
            update_time =  #{updateTime,jdbcType=DATE},
            del_flag =  #{delFlag,jdbcType=CHAR},
            remark =  #{remark,jdbcType=VARCHAR}
        where project_id = #{projectId,jdbcType=VARCHAR}
    </update>
	<select id="checkSameName" resultType="java.lang.Integer">
		select 1 from screening_project where del_flag = '0' and project_name = #{projectName} and hospital_id = #{hospitalId}
		<if test="projectId != null and projectId != ''">
			and project_id != #{projectId}
		</if>
		limit 1
	</select>
</mapper>
