<?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="cn.com.countrygarden.bi.main.dao.performance.AssessmentTargetMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.performance.AssessmentTarget">
        <constructor>
            <idArg column="atid" javaType="java.lang.Integer" jdbcType="INTEGER"/>
            <arg column="elementId" javaType="java.lang.String" jdbcType="VARCHAR"/>
            <arg column="elementName" javaType="java.lang.String" jdbcType="VARCHAR"/>
            <arg column="lockStatus" javaType="java.lang.Integer" jdbcType="INTEGER"/>
            <arg column="publicStatus" javaType="java.lang.Integer" jdbcType="INTEGER"/>
            <arg column="year" javaType="java.lang.Integer" jdbcType="INTEGER"/>
            <arg column="quarterly" javaType="java.lang.String" jdbcType="VARCHAR"/>
            <arg column="createDate" javaType="java.lang.String" jdbcType="VARCHAR"/>
            <arg column="createBy" javaType="java.lang.String" jdbcType="VARCHAR"/>
            <arg column="updateDate" javaType="java.lang.String" jdbcType="VARCHAR"/>
            <arg column="updateBy" javaType="java.lang.String" jdbcType="VARCHAR"/>
        </constructor>
    </resultMap>
    <sql id="Base_Column_List">
    atid, elementId, elementName, lockStatus, publicStatus, year, quarterly, createDate, createBy,
    updateDate, updateBy
  </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from assessment_target
        where atid = #{atid,jdbcType=INTEGER}
    </select>

    <!--查询状态-->
    <select id="selectJudgeLock" parameterType="cn.com.countrygarden.bi.main.model.performance.AssessmentTarget" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from assessment_target
        where elementId = #{elementid,jdbcType=VARCHAR} and year = #{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR}
    </select>

    <!--查询最后的季度是否有发布-->
    <select id="selectLastPublic" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from assessment_target where elementId = '0' and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR}
    </select>

    <!--查询最后的季度是否有发布-区域-->
    <select id="selectLastPublicOrgan" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from biapp.assessment_target
        where elementId in
        (select pp.element_id as elementId from performance_app.performance_element pp where pp.type !='城市公司' having CHAR_LENGTH(element_id)=4)
        and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR} and publicStatus=0
    </select>

    <!--查询最后的季度是否有发布-城市公司-->
    <select id="selectLastPublicCompany" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from biapp.assessment_target
        where elementId in
        (select pp.element_id as elementId from performance_app.performance_element pp where pp.type ='城市公司' having CHAR_LENGTH(element_id)=4)
        and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR} and publicStatus=0
    </select>

    <!--得到当前季度未锁定的数据-->
    <select id="selectUnLock" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from assessment_target where elementId != '0' and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR} and lockStatus=0
    </select>

    <!--得到当前季度未锁定的数据-区域-->
    <select id="selectUnLockOrgan" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from biapp.assessment_target
        where elementId in
        (select pp.element_id as elementId from performance_app.performance_element pp where pp.type!='城市公司' having CHAR_LENGTH(element_id)=4)
        and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR} and lockStatus=0
    </select>

    <!--得到当前季度未锁定的数据-城市公司-->
    <select id="selectUnLockCompany" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from biapp.assessment_target
        where elementId in
        (select pp.element_id as elementId from performance_app.performance_element pp where pp.type ='城市公司' having CHAR_LENGTH(element_id)=4)
        and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR} and lockStatus=0
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from assessment_target
    where atid = #{atid,jdbcType=INTEGER}
  </delete>

    <insert id="insertSelective" parameterType="cn.com.countrygarden.bi.main.model.performance.AssessmentTarget">
        insert into assessment_target
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="atid != null">
                atid,
            </if>
            <if test="elementid != null">
                elementId,
            </if>
            <if test="elementname != null">
                elementName,
            </if>
            <if test="lockstatus != null">
                lockStatus,
            </if>
            <if test="publicstatus != null">
                publicStatus,
            </if>
            <if test="year != null">
                year,
            </if>
            <if test="quarterly != null">
                quarterly,
            </if>
            <if test="createdate != null">
                createDate,
            </if>
            <if test="createby != null">
                createBy,
            </if>
            <if test="updatedate != null">
                updateDate,
            </if>
            <if test="updateby != null">
                updateBy,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="atid != null">
                #{atid,jdbcType=INTEGER},
            </if>
            <if test="elementid != null">
                #{elementid,jdbcType=VARCHAR},
            </if>
            <if test="elementname != null">
                #{elementname,jdbcType=VARCHAR},
            </if>
            <if test="lockstatus != null">
                #{lockstatus,jdbcType=INTEGER},
            </if>
            <if test="publicstatus != null">
                #{publicStatus,jdbcType=INTEGER},
            </if>
            <if test="year != null">
                #{year,jdbcType=INTEGER},
            </if>
            <if test="quarterly != null">
                #{quarterly,jdbcType=VARCHAR},
            </if>
            <if test="createdate != null">
                #{createdate,jdbcType=VARCHAR},
            </if>
            <if test="createby != null">
                #{createby,jdbcType=VARCHAR},
            </if>
            <if test="updatedate != null">
                #{updatedate,jdbcType=VARCHAR},
            </if>
            <if test="updateby != null">
                #{updateby,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>

    <!--update 发布状态-区域-->
    <update id="updatePublicStatusOrgan" parameterType="java.util.Map">
        update biapp.assessment_target set publicStatus = 1
        where elementId in
        (select pp.element_id as elementId from performance_app.performance_element pp where pp.type !='城市公司' having CHAR_LENGTH(element_id)=4)
        and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR}
    </update>

    <!--update 发布状态-城市公司-->
    <update id="updatePublicStatusCompany" parameterType="java.util.Map">
        update biapp.assessment_target set publicStatus = 1
        where elementId in
        (select pp.element_id as elementId from performance_app.performance_element pp where pp.type ='城市公司' having CHAR_LENGTH(element_id)=4)
        and year=#{year,jdbcType=INTEGER} and quarterly =#{quarterly,jdbcType=VARCHAR}
    </update>

    <update id="updateByPrimaryKeySelective"
            parameterType="cn.com.countrygarden.bi.main.model.performance.AssessmentTarget">
        update assessment_target
        <set>
            <if test="elementid != null">
                elementId = #{elementid,jdbcType=VARCHAR},
            </if>
            <if test="elementname != null">
                elementName = #{elementname,jdbcType=VARCHAR},
            </if>
            <if test="lockstatus != null">
                lockStatus = #{lockstatus,jdbcType=INTEGER},
            </if>
            <if test="publicstatus != null">
                publicStatus = #{publicstatus,jdbcType=INTEGER},
            </if>
            <if test="year != null">
                year = #{year,jdbcType=INTEGER},
            </if>
            <if test="quarterly != null">
                quarterly = #{quarterly,jdbcType=VARCHAR},
            </if>
            <if test="createdate != null">
                createDate = #{createdate,jdbcType=VARCHAR},
            </if>
            <if test="createby != null">
                createBy = #{createby,jdbcType=VARCHAR},
            </if>
            <if test="updatedate != null">
                updateDate = #{updatedate,jdbcType=VARCHAR},
            </if>
            <if test="updateby != null">
                updateBy = #{updateby,jdbcType=VARCHAR},
            </if>
        </set>
        where atid = #{atid,jdbcType=INTEGER}
    </update>
</mapper>