<?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.jeeplus.modules.workprojectcompletion.dao.WorkProjectCompletionDao">

    <sql id="workProjectJoinClient">
        LEFT JOIN work_client_info client on a.client_id=client.id
    </sql>

    <sql id="workProjectJoinClientCompelete">
        LEFT JOIN work_project_completion wpc on a.id=wpc.project_id
        LEFT JOIN sys_user u on u.id = a.create_by
		LEFT JOIN sys_office o ON o.id = u.office_id
    </sql>

    <!--获取单条信息-->
    <select id="get" parameterType="java.lang.String" resultType="WorkProjectCompletionInfo">
        SELECT
        a.id AS id,
        a.project_id AS projectId,
        a.process_instance_id AS processInstanceId,
        a.update_date AS updateDate,
        a.create_date AS createDate,
        a.project_stutas AS projectStatus,
        a.create_by AS "createBy.id",
        a.remarks AS remarks,
        a.del_flag AS delFlag,
        a.apply_view AS "applyView"
        FROM work_project_completion a
        WHERE a.id=#{id}
    </select>

    <!--项目竣工列表信息-->
    <!--<select id="findList" resultType="WorkProjectCompletionInfo">-->
        <!--SELECT-->
        <!--a.id AS projectId,-->
        <!--a.full_project_number AS projectNo,-->
        <!--a.full_project_name AS projectName,-->
        <!--a.host_master AS projectLeaderId,-->
        <!--a.create_date AS createDate,-->
        <!--a.company_id AS companyId,-->
        <!--wpc.process_instance_id AS processInstanceId,-->
        <!--wpc.project_stutas AS projectStatus,-->
        <!--wpc.id AS completeManagerId,-->
        <!--client.name AS clientName,-->
        <!--client.id AS clientId-->
        <!--FROM work_full_manage a-->
        <!--<include refid="workProjectJoinClientCompelete"/>-->
        <!--<where>-->
        <!--a.del_flag = #{DEL_FLAG_NORMAL}-->
        <!--<if test="projectNo != null and projectNo != '' ">-->
          <!--AND a.full_project_number LIKE-->
            <!--<if test="dbName == 'mysql'">concat('%',#{projectNo},'%')</if>-->
        <!--</if>-->
        <!--<if test="projectStatus != null and projectStatus != '' ">-->
            <!--wpc.project_stutas=#{projectStatus}-->
        <!--</if>-->

        <!--<if test="projectName !=null and projectName !=''">-->
          <!--AND a.full_project_name LIKE-->
            <!--<if test="dbName == 'oracle'">'%'||#{projectName}||'%'</if>-->
            <!--<if test="dbName == 'mssql'">'%'+#{projectName}+'%'</if>-->
            <!--<if test="dbName == 'mysql'">concat('%',#{projectName},'%')</if>-->
        <!--</if>-->
        <!--</where>-->
        <!--<choose>-->
            <!--<otherwise>-->
                <!--${sqlMap.dsf}-->
            <!--</otherwise>-->
        <!--</choose>-->
        <!--<choose>-->
            <!--<when test="page !=null and page.orderBy != null and page.orderBy != ''">-->
                <!--ORDER BY ${page.orderBy}-->
            <!--</when>-->
            <!--<otherwise>-->
                <!--ORDER BY a.update_date DESC-->
            <!--</otherwise>-->

        <!--</choose>-->

    <!--</select>-->

    <insert id="insert">
        INSERT INTO work_project_completion
        (
        id,
        project_id,
        process_instance_id,
        create_date,
        update_date,
        remarks,
        del_flag,
        apply_view,
        create_by,
        project_stutas
        )
        VALUES (
        #{id},
        #{projectId},
        #{processInstanceId},
        #{createDate},
        #{updateDate},
        #{remarks},
        #{delFlag},
        #{applyView},
        #{createBy.id},
        #{projectStatus}
        )
    </insert>

    <!--更新流程id-->
    <update id="updateProcessInstanceId">
        UPDATE work_project_completion SET
        process_instance_id = #{processInstanceId}
        WHERE id = #{id}
    </update>

    <update id="update">
        UPDATE work_project_completion SET
            process_instance_id = #{processInstanceId},
            update_date = #{updateDate},
            remarks = #{remarks},
            del_flag = #{delFlag},
            apply_view = #{applyView},
            project_stutas = #{projectStatus}
        WHERE id=#{id}
    </update>

    <update id="updateStatus">
        UPDATE work_project_completion SET
          project_stutas=#{projectStatus}
        WHERE
        process_instance_id=#{processInstanceId}
    </update>

    <update id="updateWorkFullManage" parameterType="java.util.HashMap">
        UPDATE work_full_manage SET
        full_project_status = #{status}
        WHERE
        id = #{projectId}
    </update>


    <select id="getByProcessInstanceId" resultType="WorkProjectCompletionInfo">
        SELECT
            a.id AS id,
            a.project_id AS projectId,
            a.process_instance_id AS processInstanceId,
            a.update_date AS updateDate,
            a.create_date AS createDate,
            a.project_stutas AS projectStatus,
            a.create_by AS "createBy.id",
            a.remarks AS remarks,
            a.del_flag AS delFlag,
            a.apply_view AS "applyView",
            u.name AS "createBy.name"
        FROM work_project_completion a
        <include refid="workProjectJoinClientCompelete"/>
        WHERE a.process_instance_id = #{processInstanceId}
    </select>

    <select id="getByProjectId" resultType="WorkProjectCompletionInfo">
        SELECT
            a.id AS id,
            a.project_id AS projectId,
            a.process_instance_id AS processInstanceId,
            a.update_date AS updateDate,
            a.create_date AS createDate,
            a.project_stutas AS projectStatus,
            a.create_by AS "createBy.id",
            a.remarks AS remarks,
            a.del_flag AS delFlag,
            a.apply_view AS "applyView",
            u.name AS "createBy.name"
        FROM work_project_completion a
        <include refid="workProjectJoinClientCompelete"/>
        WHERE  a.project_id = #{projectId}
    </select>

    <delete id="deleteProject" parameterType="java.lang.String">
      DELETE FROM work_full_manage WHERE id=#{projectId};
      DELETE FROM work_project_completion WHERE id=#{id}
    </delete>

    <update id="updateFlag">
        UPDATE work_project_completion SET
        del_flag = #{delFlag}
        WHERE id=#{id}
    </update>
</mapper>