<?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.zcxk.evaluation.dao.EvaluationCycleMapper">


    <resultMap type="com.zcxk.evaluation.entity.EvaluationCycleEntity" id="EvaluationCycleResult">
        <result property="id" column="id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="companyOrgId" column="company_org_id"/>
        <result property="type" column="type"/>
        <result property="evaluationDay" column="evaluation_day"/>
        <result property="remarks" column="remarks"/>
        <result property="status" column="status"/>
        <result property="dateCreate" column="date_create"/>
        <result property="createBy" column="create_by"/>
        <result property="dateUpdate" column="date_update"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <!--  实体栏位  -->
    <sql id="evaluationCycleColumns">
         a.id as "id" ,
         a.tenant_id as "tenantId" ,
         a.company_org_id as "companyOrgId" ,
         a.type as "type" ,
         a.evaluation_day as "evaluationDay" ,
         a.remarks as "remarks" ,
         a.status as "status" ,
         a.date_create as "dateCreate" ,
         a.create_by as "createBy" ,
         a.date_update as "dateUpdate" ,
         a.update_by as "updateBy" 
     </sql>


    <!--  根据主键获取实体   -->
    <select id="findEvaluationCycleById" resultType="com.zcxk.evaluation.entity.EvaluationCycleEntity">
        SELECT
        <include refid="evaluationCycleColumns"/>
        FROM sc_evaluation_cycle a
        WHERE a.id = #{id} and a.status=1
    </select>

    <!--  根据获取实体List   -->
    <select id="findList" resultType="com.zcxk.evaluation.entity.EvaluationCycleEntity">
        SELECT
        <include refid="evaluationCycleColumns"/>
        FROM sc_evaluation_cycle a

        <where>
            <if test="companyOrgId!=null">
                and a.COMPANY_ORG_ID = #{companyOrgId}
            </if>
            and a.status=1
            <if test="type != null ">and a.type = #{type}</if>
            <if test="tenantId != null ">and a.TENANT_ID = #{tenantId}</if>
            <if test="id != null ">and a.id &lt;&gt; #{id}</if>
            <if test="evaluationDay != null ">and a.EVALUATION_DAY = #{evaluationDay}</if>
        </where>
    </select>

    <!--  根据获取实体 page   -->
    <select id="findPage" resultType="com.zcxk.evaluation.entity.EvaluationCycleEntity">
        SELECT
        <include refid="evaluationCycleColumns"/>
        FROM sc_evaluation_cycle a
        <where>
            <if test="evaluationCycle.companyOrgId!=null">
                and a.COMPANY_ORG_ID = #{evaluationCycle.companyOrgId}
            </if>
            and a.status=1
            <if test="evaluationCycle.type != null ">and a.type = #{evaluationCycle.type}</if>
            <if test="evaluationCycle.tenantId != null ">and a.TENANT_ID = #{evaluationCycle.tenantId}</if>
            <if test="evaluationCycle.userType!=null and evaluationCycle.userType!=-999 and evaluationCycle.userType!=-9999 and  evaluationCycle.programItems != null and evaluationCycle.programItems.size() > 0">
                <if test="evaluationCycle.permissonType == 5 or evaluationCycle.permissonType == 2">
                    and
                    a.COMPANY_ORG_ID in
                    <foreach collection="evaluationCycle.programItems" item="item" open="(" close=")" separator=",">
                        #{item.orgId}
                    </foreach>
                </if>
                <if test="evaluationCycle.permissonType == 1">
                    and a.COMPANY_ORG_ID in
                    <foreach collection="evaluationCycle.programItems" item="item" open="(" close=")" separator=",">
                        #{item.orgId}
                    </foreach>
                </if>
            </if>
        </where>
    </select>
</mapper>