<?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.srs.comprehensive.mapper.CphOwnGoodTypeMapper">
    
    <resultMap type="CphOwnGoodType" id="CphOwnGoodTypeResult">
        <result property="id"    column="id"    />
        <result property="typeName"    column="type_name"    />
        <result property="typeCode"    column="type_code"    />
        <result property="parentCode"    column="parent_code"    />
        <result property="stuYearId"    column="stu_year_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="enableStatus"    column="enable_status"    />
        <result property="startStatus"    column="start_status"    />
        <result property="trees"    column="trees"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="onlyCode"    column="only_code"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="stuYearName"    column="stu_year_name"    />
    </resultMap>

    <sql id="selectCphOwnGoodTypeVo">
        select a.*,b.stu_year_name
        from cph_own_good_type as a
        left join srs_stu_year as b on a.stu_year_id = b.id
    </sql>

    <select id="selectCphOwnGoodTypeList" parameterType="CphOwnGoodType" resultMap="CphOwnGoodTypeResult">
        <include refid="selectCphOwnGoodTypeVo"/>
        <where>  
            <if test="typeName != null  and typeName != ''"> and a.type_name like concat('%', #{typeName}, '%')</if>
            <if test="typeCode != null  and typeCode != ''"> and a.type_code = #{typeCode}</if>
            <if test="parentCode != null  and parentCode != ''"> and a.parent_code = #{parentCode}</if>
            <if test="stuYearId != null "> and a.stu_year_id = #{stuYearId}</if>
            <if test="startTime != null "> and a.start_time = #{startTime}</if>
            <if test="endTime != null "> and a.end_time = #{endTime}</if>
            <if test="enableStatus != null  and enableStatus != ''"> and a.enable_status = #{enableStatus}</if>
            <if test="startStatus != null  and startStatus != ''"> and a.start_status = #{startStatus}</if>
            <if test="trees != null  and trees != ''"> and a.trees = #{trees}</if>
            <if test="status != null  and status != ''"> and a.status = #{status}</if>
            <if test="onlyCode != null  and onlyCode != ''"> and a.only_code = #{onlyCode}</if>
        </where>
    </select>
    
    <select id="selectCphOwnGoodTypeById" parameterType="Long" resultMap="CphOwnGoodTypeResult">
        <include refid="selectCphOwnGoodTypeVo"/>
        where a.id = #{id}
    </select>

    <select id="selectByCode"  parameterType="String" resultMap="CphOwnGoodTypeResult">
        <include refid="selectCphOwnGoodTypeVo"/>
        where a.type_code = #{code}
    </select>
        
    <insert id="insertCphOwnGoodType" parameterType="CphOwnGoodType" useGeneratedKeys="true" keyProperty="id">
        insert into cph_own_good_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeName != null">type_name,</if>
            <if test="typeCode != null and typeCode != ''">type_code,</if>
            <if test="parentCode != null">parent_code,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="enableStatus != null">enable_status,</if>
            <if test="startStatus != null">start_status,</if>
            <if test="trees != null">trees,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null and delFlag != ''">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>
            <if test="onlyCode != null">only_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeName != null">#{typeName},</if>
            <if test="typeCode != null and typeCode != ''">#{typeCode},</if>
            <if test="parentCode != null">#{parentCode},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="enableStatus != null">#{enableStatus},</if>
            <if test="startStatus != null">#{startStatus},</if>
            <if test="trees != null">#{trees},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null and delFlag != ''">#{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>
            <if test="onlyCode != null">#{onlyCode},</if>
         </trim>
    </insert>

    <update id="updateCphOwnGoodType" parameterType="CphOwnGoodType">
        update cph_own_good_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeName != null">type_name = #{typeName},</if>
            <if test="typeCode != null and typeCode != ''">type_code = #{typeCode},</if>
            <if test="parentCode != null">parent_code = #{parentCode},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="enableStatus != null">enable_status = #{enableStatus},</if>
            <if test="startStatus != null">start_status = #{startStatus},</if>
            <if test="trees != null">trees = #{trees},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null and delFlag != ''">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>
            <if test="onlyCode != null">only_code = #{onlyCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphOwnGoodTypeById" parameterType="Long">
        delete from cph_own_good_type where id = #{id}
    </delete>

    <delete id="deleteCphOwnGoodTypeByIds" parameterType="String">
        delete from cph_own_good_type where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>