<?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.zcloud.domain.persistence.mapper.ProjectTaskMapper">
    <select id="listPage" resultType="com.zcloud.domain.persistence.dataobject.ProjectTaskDO">
        select pt.*, c.corp_name as executeCorpinfoName, d.name as masterDepartmentName,dg.domain_group_name as domainGroupName,dg.team_user_id
            from project_task pt
            left join domain_group dg on pt.domain_group_id = dg.domain_group_id and dg.delete_enum = 'false'
            left join domain_department dd
            on pt.domain_department_id = dd.domain_department_id and dd.delete_enum = 'false'
            left join corp_info c on c.id = pt.execute_corpinfo_id
            left join department d on d.id = dd.master_department_id
            left join project_task_score_info ptsi on ptsi.project_task_id = pt.project_task_id
            left join project_task_group_user pti on pti.project_task_id = pt.project_task_id
         where pt.delete_enum = 'false'
            <if test="params.domainType != null and params.domainType != '' ">
                and pt.domain_type = #{params.domainType}
            </if>
            <if test="params.executeCorpinfoId != null  ">
                and pt.execute_corpinfo_id = #{params.executeCorpinfoId}
            </if>
            <if test="params.executeStatus != null  ">
                and pt.execute_status = #{params.executeStatus}
            </if>
            <if test="params.corpinfoId != null  ">
                and c.id = #{params.corpinfoId}
            </if>

            <if test="params.projectName != null and params.projectName != '' ">
                and pt.project_name like  CONCAT('%', #{params.projectName}, '%')
            </if>
            <if test="params.startDate != null and params.startDate != '' ">
                and pt.executed_start_date <![CDATA[<=]]> #{params.startDate}
            </if>
            <if test="params.endDate != null and params.endDate != '' ">
                and pt.executed_end_date >= #{params.endDate}
            </if>
            <if test="params.scoreStatus != null  ">
                and pt.score_status = #{params.scoreStatus}
            </if>
        group by pt.id
        order by pt.execute_status asc,pt.create_time desc
    </select>

    <select id="getInfoById" resultType="com.zcloud.domain.persistence.dataobject.ProjectTaskDO">

        select pt.*, c.corp_name as executeCorpinfoName, d.name as masterDepartmentName,dg.domain_group_name as domainGroupName
        from project_task pt
                 left join domain_group dg on pt.domain_group_id = dg.domain_group_id and dg.delete_enum = 'false'
                 left join domain_department dd
                           on pt.domain_department_id = dd.domain_department_id and dd.delete_enum = 'false'
                 left join corp_info c on c.id = pt.execute_corpinfo_id
                 left join department d on d.id = dd.master_department_id
        where pt.delete_enum = 'false' and pt.id=#{id}
    </select>
    <update id="updateScoreStatus">
         update project_task set score_status = #{code}
        <if test="averageScore != null">
            ,score = #{averageScore}
        </if>
            where project_task_id = #{projectTaskId}
    </update>
    <update id="updateExecuteStatusBatchById">
        update project_task set execute_status = #{code} where
             id in
            <foreach item="item" collection="idList" separator="," open="(" close=")" index="">
                #{item}
            </foreach>
    </update>
</mapper>

