<?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.microservices.dms.achievementLibrary.mapper.SchoolEnterpriseAchievementsMapper">
    
    <resultMap type="SchoolEnterpriseAchievements" id="SchoolEnterpriseAchievementsResult">
        <result property="id"    column="id"    />
        <result property="achievementName"    column="achievement_name"    />
        <result property="field1"    column="field_1"    />
        <result property="field2"    column="field_2"    />
        <result property="field3"    column="field_3"    />
        <result property="achievementType"    column="achievement_type"    />
        <result property="source"    column="source"    />
        <result property="sourceId"    column="source_id"    />
        <result property="sourceLink"    column="source_link"    />
        <result property="tags"    column="tags"    />
        <result property="summary"    column="summary"    />
        <result property="publishingUnit"    column="publishing_unit"    />
        <result property="address"    column="address"    />
        <result property="isFeatured"    column="is_featured"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="status"    column="status"    />
        <result property="details"    column="details"    />
        <result property="reviewer"    column="reviewer"    />
        <result property="reviewDate"    column="review_date"    />
        <result property="reviewComments"    column="review_comments"    />
        <result property="images"    column="images"    />
        <result property="attachments"    column="attachments"    />
        <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="achievementStatus"    column="achievement_status"    />
        <result property="achievementLittleType"    column="achievement_little_type"    />
        <result property="achievementCurStatus"    column="achievement_cur_status"    />
        <result property="teamName"    column="team_name"    />
    </resultMap>

    <sql id="selectSchoolEnterpriseAchievementsVo">
        select id, achievement_name, achievement_status,field_1, field_2, field_3,
               achievement_type, source, source_id, source_link, tags, summary, publishing_unit,
               address, is_featured, contact_person, contact_number, owner_id, owner_name, status, achievement_little_type,
               details, reviewer, review_date, review_comments, images, attachments, create_by, create_time, achievement_cur_status,team_name,
               update_by, update_time from school_enterprise_achievements
    </sql>

    <select id="selectSchoolEnterpriseAchievementsList" parameterType="SchoolEnterpriseAchievements" resultMap="SchoolEnterpriseAchievementsResult">
        <include refid="selectSchoolEnterpriseAchievementsVo"/>
        <where>  
            <if test="achievementName != null  and achievementName != ''"> and achievement_name like concat('%', #{achievementName}, '%')</if>
            <if test="field1 != null  and field1 != ''"> and field_1 = #{field1}</if>
            <if test="field2 != null  and field2 != ''"> and field_2 = #{field2}</if>
            <if test="field3 != null  and field3 != ''"> and field_3 = #{field3}</if>
            <if test="achievementType != null  and achievementType != ''"> and achievement_type = #{achievementType}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="sourceId != null  and sourceId != ''"> and source_id = #{sourceId}</if>
            <if test="sourceLink != null  and sourceLink != ''"> and source_link = #{sourceLink}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="summary != null  and summary != ''"> and summary = #{summary}</if>
            <if test="publishingUnit != null  and publishingUnit != ''"> and publishing_unit = #{publishingUnit}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="isFeatured != null "> and is_featured = #{isFeatured}</if>
            <if test="contactPerson != null  and contactPerson != ''"> and contact_person = #{contactPerson}</if>
            <if test="contactNumber != null  and contactNumber != ''"> and contact_number = #{contactNumber}</if>
            <if test="ownerId != null  and ownerId != ''"> and owner_id = #{ownerId}</if>
            <if test="ownerName != null  and ownerName != ''"> and owner_name like concat('%', #{ownerName}, '%')</if>
            <if test="status != null  and status != ''"> and `status` = #{status}</if>
            <if test="achievementStatus != null"> and achievement_status = #{achievementStatus}</if>
            <if test="details != null  and details != ''"> and details = #{details}</if>
            <if test="reviewer != null  and reviewer != ''"> and reviewer = #{reviewer}</if>
            <if test="reviewDate != null "> and review_date = #{reviewDate}</if>
            <if test="reviewComments != null  and reviewComments != ''"> and review_comments = #{reviewComments}</if>
            <if test="images != null  and images != ''"> and images = #{images}</if>
            <if test="attachments != null  and attachments != ''"> and attachments = #{attachments}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
            <if test="achievementCurStatus != null  and achievementCurStatus != ''"> and achievement_cur_status = #{achievementCurStatus}</if>
            <if test="achievementLittleType != null  and achievementLittleType != ''"> and achievement_little_type = #{achievementLittleType}</if>
            <if test="teamName != null  and teamName != ''"> and team_name = #{teamName}</if>
        </where>
        order by status desc,create_time desc
    </select>
    
    <select id="selectSchoolEnterpriseAchievementsById" parameterType="Long" resultMap="SchoolEnterpriseAchievementsResult">
        <include refid="selectSchoolEnterpriseAchievementsVo"/>
        where id = #{id}
    </select>

    <select id="selectSchoolEnterpriseAchievementsByName"  resultMap="SchoolEnterpriseAchievementsResult">
        <include refid="selectSchoolEnterpriseAchievementsVo"/>
        where achievement_name = #{achievementName}
        limit 0,1
    </select>

    <select id="topStatistic" resultType="java.lang.Long">
        select count(*) from school_enterprise_achievements
        <where>
            <if test="achievementName != null  and achievementName != ''"> and achievement_name like concat('%', #{achievementName}, '%')</if>
            <if test="field1 != null  and field1 != ''"> and field_1 = #{field1}</if>
            <if test="field2 != null  and field2 != ''"> and field_2 = #{field2}</if>
            <if test="field3 != null  and field3 != ''"> and field_3 = #{field3}</if>
            <if test="achievementType != null  and achievementType != ''"> and achievement_type = #{achievementType}</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="sourceId != null  and sourceId != ''"> and source_id = #{sourceId}</if>
            <if test="sourceLink != null  and sourceLink != ''"> and source_link = #{sourceLink}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="summary != null  and summary != ''"> and summary = #{summary}</if>
            <if test="publishingUnit != null  and publishingUnit != ''"> and publishing_unit = #{publishingUnit}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="isFeatured != null "> and is_featured = #{isFeatured}</if>
            <if test="contactPerson != null  and contactPerson != ''"> and contact_person = #{contactPerson}</if>
            <if test="contactNumber != null  and contactNumber != ''"> and contact_number = #{contactNumber}</if>
            <if test="ownerId != null  and ownerId != ''"> and owner_id = #{ownerId}</if>
            <if test="ownerName != null  and ownerName != ''"> and owner_name like concat('%', #{ownerName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="details != null  and details != ''"> and details = #{details}</if>
            <if test="reviewer != null  and reviewer != ''"> and reviewer = #{reviewer}</if>
            <if test="reviewDate != null "> and review_date = #{reviewDate}</if>
            <if test="reviewComments != null  and reviewComments != ''"> and review_comments = #{reviewComments}</if>
            <if test="images != null  and images != ''"> and images = #{images}</if>
            <if test="attachments != null  and attachments != ''"> and attachments = #{attachments}</if>
            <if test="achievementCurStatus != null  and achievementCurStatus != ''"> and achievement_cur_status = #{achievementCurStatus}</if>
            <if test="achievementLittleType != null  and achievementLittleType != ''"> and achievement_little_type = #{achievementLittleType}</if>
            <if test="teamName != null  and teamName != ''"> and team_name = #{teamName}</if>
        </where>
    </select>

    <insert id="insertSchoolEnterpriseAchievements" parameterType="SchoolEnterpriseAchievements" useGeneratedKeys="true" keyProperty="id">
        insert into school_enterprise_achievements
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="achievementName != null">achievement_name,</if>
            <if test="field1 != null">field_1,</if>
            <if test="field2 != null">field_2,</if>
            <if test="field3 != null">field_3,</if>
            <if test="achievementType != null">achievement_type,</if>
            <if test="source != null">source,</if>
            <if test="sourceId != null">source_id,</if>
            <if test="sourceLink != null">source_link,</if>
            <if test="tags != null">tags,</if>
            <if test="summary != null">summary,</if>
            <if test="publishingUnit != null">publishing_unit,</if>
            <if test="address != null">address,</if>
            <if test="isFeatured != null">is_featured,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="contactNumber != null">contact_number,</if>
            <if test="ownerId != null">owner_id,</if>
            <if test="ownerName != null">owner_name,</if>
            <if test="status != null">status,</if>
            <if test="details != null">details,</if>
            <if test="reviewer != null">reviewer,</if>
            <if test="reviewDate != null">review_date,</if>
            <if test="reviewComments != null">review_comments,</if>
            <if test="images != null">images,</if>
            <if test="attachments != null">attachments,</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="achievementStatus != null">achievement_status,</if>
            <if test="achievementCurStatus != null">achievement_cur_status,</if>
            <if test="achievementLittleType != null">achievement_little_type,</if>
            <if test="teamName != null">team_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="achievementName != null">#{achievementName},</if>
            <if test="field1 != null">#{field1},</if>
            <if test="field2 != null">#{field2},</if>
            <if test="field3 != null">#{field3},</if>
            <if test="achievementType != null">#{achievementType},</if>
            <if test="source != null">#{source},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="sourceLink != null">#{sourceLink},</if>
            <if test="tags != null">#{tags},</if>
            <if test="summary != null">#{summary},</if>
            <if test="publishingUnit != null">#{publishingUnit},</if>
            <if test="address != null">#{address},</if>
            <if test="isFeatured != null">#{isFeatured},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="contactNumber != null">#{contactNumber},</if>
            <if test="ownerId != null">#{ownerId},</if>
            <if test="ownerName != null">#{ownerName},</if>
            <if test="status != null">#{status},</if>
            <if test="details != null">#{details},</if>
            <if test="reviewer != null">#{reviewer},</if>
            <if test="reviewDate != null">#{reviewDate},</if>
            <if test="reviewComments != null">#{reviewComments},</if>
            <if test="images != null">#{images},</if>
            <if test="attachments != null">#{attachments},</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="achievementStatus != null">#{achievementStatus},</if>
            <if test="achievementCurStatus != null">#{achievementCurStatus},</if>
            <if test="achievementLittleType != null">#{achievementLittleType},</if>
            <if test="teamName != null">#{teamName},</if>
         </trim>
    </insert>

    <update id="updateSchoolEnterpriseAchievements" parameterType="SchoolEnterpriseAchievements">
        update school_enterprise_achievements
        <trim prefix="SET" suffixOverrides=",">
            <if test="achievementName != null">achievement_name = #{achievementName},</if>
            <if test="field1 != null">field_1 = #{field1},</if>
            <if test="field2 != null">field_2 = #{field2},</if>
            <if test="field3 != null">field_3 = #{field3},</if>
            <if test="achievementType != null">achievement_type = #{achievementType},</if>
            <if test="source != null">source = #{source},</if>
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="sourceLink != null">source_link = #{sourceLink},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="summary != null">summary = #{summary},</if>
            <if test="publishingUnit != null">publishing_unit = #{publishingUnit},</if>
            <if test="address != null">address = #{address},</if>
            <if test="isFeatured != null">is_featured = #{isFeatured},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</if>
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="ownerName != null">owner_name = #{ownerName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="details != null">details = #{details},</if>
            <if test="reviewer != null">reviewer = #{reviewer},</if>
            <if test="reviewDate != null">review_date = #{reviewDate},</if>
            <if test="reviewComments != null">review_comments = #{reviewComments},</if>
            <if test="images != null">images = #{images},</if>
            <if test="attachments != null">attachments = #{attachments},</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="achievementStatus != null">achievement_status = #{achievementStatus},</if>
            <if test="achievementCurStatus != null">achievement_cur_status = #{achievementCurStatus},</if>
            <if test="achievementLittleType != null">achievement_little_type = #{achievementLittleType},</if>
            <if test="teamName != null">team_name = #{teamName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSchoolEnterpriseAchievementsById" parameterType="Long">
        delete from school_enterprise_achievements where id = #{id}
    </delete>

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