<?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.yanzhu.jh.project.mapper.SmzProjectQuarterlyAssessMapper">
    
    <resultMap type="SmzProjectQuarterlyAssess" id="SmzProjectQuarterlyAssessResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="year"    column="year"    />
        <result property="quarterly"    column="quarterly"    />
        <result property="date"    column="date"    />
        <result property="planTarget"    column="plan_target"    />
        <result property="curProgress"    column="cur_progress"    />
        <result property="laggingMatters"    column="lagging_matters"    />
        <result property="problem"    column="problem"    />
        <result property="planDate"    column="plan_date"    />
        <result property="finishDate"    column="finish_date"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="isDel"    column="is_del"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
    <resultMap type="SmzProjectQuarterlyAssess" id="SmzProjectQuarterlyAssessResultToProject">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="year"    column="year"    />
        <result property="quarterly"    column="quarterly"    />
        <result property="date"    column="date"    />
        <result property="planTarget"    column="plan_target"    />
        <result property="curProgress"    column="cur_progress"    />
        <result property="laggingMatters"    column="lagging_matters"    />
        <result property="problem"    column="problem"    />
        <result property="planDate"    column="plan_date"    />
        <result property="finishDate"    column="finish_date"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="isDel"    column="is_del"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <association property="project" javaType="surProject">
            <result property="id"    column="project_id"    />
            <result property="projectName"    column="projectName"    />
            <result property="paretProjectName"    column="paretProjectName"    />
            <result property="projectSchedule" column="projectSchedule"/>
            <result property="deptName" column="dept_name"/>
        </association>
    </resultMap>

    <sql id="selectSmzProjectQuarterlyAssessVo">
        select id, project_id, year, quarterly, date, plan_target, cur_progress, lagging_matters, problem, plan_date, finish_date, status, remark, is_del, create_by, create_time, update_by, update_time from smz_project_quarterly_assess
    </sql>
    <select id="currentListByDept" parameterType="SmzProjectQuarterlyAssess" resultMap="SmzProjectQuarterlyAssessResultToProject">

        SELECT a.*,p.projectName,d.dept_name,p.paretProjectName,p.projectSchedule
        FROM smz_project_quarterly_assess a,sur_project p,sys_dept d
        WHERE a.project_id IN
    (SELECT id FROM sur_project
        <where>
            <if test="deptId>0"> deptid=#{deptId} </if>
            <if test="prjIds !=null and prjIds.size()>0">
                and id in
                <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        ) AND a.project_id=p.id and  plan_target is not null AND p.deptId=d.dept_id

        <if test="year != null "> and year = #{year}</if>
        <if test="quarterly != null "> and quarterly = #{quarterly}</if>
        order by p.projectSort

    </select>

    <select id="queryByProjectType" parameterType="SmzProjectQuarterlyAssess" resultMap="SmzProjectQuarterlyAssessResultToProject">
        SELECT p.id, p.projectName,p.projectSchedule,a.plan_target
        FROM sur_project p LEFT JOIN smz_project_quarterly_assess a ON a.project_id=p.id
        WHERE p.projecttype=#{id} AND a.year=#{year} AND a.quarterly=#{quarterly} AND p.isdel=0
        <if test="deptId>0">and p.deptId=#{deptId}</if>
        <if test="prjIds !=null and prjIds.size()>0">
            and p.id in
            <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>

        order by p.projectSort
    </select>
    <select id="selectSmzProjectQuarterlyAssessList" parameterType="SmzProjectQuarterlyAssess" resultMap="SmzProjectQuarterlyAssessResult">
        <include refid="selectSmzProjectQuarterlyAssessVo"/>
        <where>  
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="quarterly != null "> and quarterly = #{quarterly}</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="planTarget != null  and planTarget != ''"> and plan_target = #{planTarget}</if>
            <if test="curProgress != null  and curProgress != ''"> and cur_progress = #{curProgress}</if>
            <if test="laggingMatters != null  and laggingMatters != ''"> and lagging_matters = #{laggingMatters}</if>
            <if test="problem != null  and problem != ''"> and problem = #{problem}</if>
            <if test="planDate != null "> and plan_date = #{planDate}</if>
            <if test="finishDate != null "> and finish_date = #{finishDate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="prjIds !=null and prjIds.size()>0">
                and project_id in
                <foreach collection="prjIds"  item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectSmzProjectQuarterlyAssessById" parameterType="Long" resultMap="SmzProjectQuarterlyAssessResult">
        <include refid="selectSmzProjectQuarterlyAssessVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSmzProjectQuarterlyAssess" parameterType="SmzProjectQuarterlyAssess" useGeneratedKeys="true" keyProperty="id">
        insert into smz_project_quarterly_assess
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="year != null">year,</if>
            <if test="quarterly != null">quarterly,</if>
            <if test="date != null">date,</if>
            <if test="planTarget != null">plan_target,</if>
            <if test="curProgress != null">cur_progress,</if>
            <if test="laggingMatters != null">lagging_matters,</if>
            <if test="problem != null">problem,</if>
            <if test="planDate != null">plan_date,</if>
            <if test="finishDate != null">finish_date,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="isDel != null">is_del,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="year != null">#{year},</if>
            <if test="quarterly != null">#{quarterly},</if>
            <if test="date != null">#{date},</if>
            <if test="planTarget != null">#{planTarget},</if>
            <if test="curProgress != null">#{curProgress},</if>
            <if test="laggingMatters != null">#{laggingMatters},</if>
            <if test="problem != null">#{problem},</if>
            <if test="planDate != null">#{planDate},</if>
            <if test="finishDate != null">#{finishDate},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isDel != null">#{isDel},</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>
         </trim>
    </insert>

    <update id="updateSmzProjectQuarterlyAssess" parameterType="SmzProjectQuarterlyAssess">
        update smz_project_quarterly_assess
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="year != null">year = #{year},</if>
            <if test="quarterly != null">quarterly = #{quarterly},</if>
            <if test="date != null">date = #{date},</if>
            <if test="planTarget != null">plan_target = #{planTarget},</if>
            <if test="curProgress != null">cur_progress = #{curProgress},</if>
            <if test="laggingMatters != null">lagging_matters = #{laggingMatters},</if>
            <if test="problem != null">problem = #{problem},</if>
            <if test="planDate != null">plan_date = #{planDate},</if>
            finish_date = #{finishDate},
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isDel != null">is_del = #{isDel},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSmzProjectQuarterlyAssessById" parameterType="Long">
        delete from smz_project_quarterly_assess where id = #{id}
    </delete>

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