<?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.assess.projectRecords.mapper.ProjectMapper">
  <resultMap id="BaseResultMap" type="com.jeeplus.assess.projectRecords.domain.Project">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="create_by_id" jdbcType="VARCHAR" property="createById" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by_id" jdbcType="VARCHAR" property="updateById" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
    <result column="customer_name" jdbcType="VARCHAR" property="customerName" />
    <result column="project_name" jdbcType="VARCHAR" property="projectName" />
    <result column="evaluation_objective" jdbcType="VARCHAR" property="evaluationObjective" />
    <result column="project_type" jdbcType="VARCHAR" property="projectType" />
    <result column="evaluation_base_date" jdbcType="TIMESTAMP" property="evaluationBaseDate" />
    <result column="evaluation_report_date" jdbcType="TIMESTAMP" property="evaluationReportDate" />
    <result column="protocol_num" jdbcType="VARCHAR" property="protocolNum" />
    <result column="document_num" jdbcType="VARCHAR" property="documentNum" />
    <result column="project_head" jdbcType="VARCHAR" property="projectHead" />
    <result column="wayst_evaluation" jdbcType="VARCHAR" property="waystEvaluation" />
    <result column="fixed_assets_evaluation" jdbcType="VARCHAR" property="fixedAssetsEvaluation" />
    <result column="net_assets_evaluation" jdbcType="VARCHAR" property="netAssetsEvaluation" />
    <result column="rent_evaluation" jdbcType="VARCHAR" property="rentEvaluation" />
    <result column="forensics" jdbcType="VARCHAR" property="forensics" />
    <result column="report_charges" jdbcType="VARCHAR" property="reportCharges" />
    <result column="current_dispose_person" jdbcType="VARCHAR" property="currentDisposePerson" />
    <result column="is_invoice" jdbcType="VARCHAR" property="isInvoice" />
    <result column="invoice_date" jdbcType="TIMESTAMP" property="invoiceDate" />
    <result column="actual_charges" jdbcType="VARCHAR" property="actualCharges" />
    <result column="is_contract_archive" jdbcType="VARCHAR" property="isContractArchive" />
    <result column="is_papers_intact" jdbcType="VARCHAR" property="isPapersIntact" />
    <result column="is_papers_archive" jdbcType="VARCHAR" property="isPapersArchive" />
    <result column="ops_amount" jdbcType="VARCHAR" property="opsAmount" />
    <result column="is_ops_reimbursement" jdbcType="VARCHAR" property="isOpsReimbursement" />
    <result column="reimbursement_amount" jdbcType="VARCHAR" property="reimbursementAmount" />
    <result column="unreimbursed_amount" jdbcType="VARCHAR" property="unreimbursedAmount" />
    <result column="reimbursement_num" jdbcType="VARCHAR" property="reimbursementNum" />
    <result column="reimbursement_date" jdbcType="TIMESTAMP" property="reimbursementDate" />
    <result column="evaluation_person_one" jdbcType="VARCHAR" property="evaluationPersonOne" />
    <result column="evaluation_person_two" jdbcType="VARCHAR" property="evaluationPersonTwo" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="assess_report_message" jdbcType="VARCHAR" property="assessReportMessage" />
    <result column="assess_base_message" jdbcType="VARCHAR" property="assessBaseMessage" />
    <result column="invoice_message" jdbcType="VARCHAR" property="invoiceMessage" />
    <result column="is_commission_reimbursement" jdbcType="VARCHAR" property="isCommissionReimbursement" />
    <result column="item_type" jdbcType="VARCHAR" property="itemType" />
  </resultMap>
  <sql id="Base_Column_List">
    id, create_by_id, create_time, update_by_id, update_time, remarks, del_flag, customer_name,
    project_name, evaluation_objective, project_type, evaluation_base_date, evaluation_report_date,
    protocol_num, document_num, project_head, wayst_evaluation, fixed_assets_evaluation,
    net_assets_evaluation, rent_evaluation, forensics, report_charges, current_dispose_person,
    is_invoice, invoice_date, actual_charges, is_contract_archive, is_papers_intact,
    is_papers_archive, ops_amount, is_ops_reimbursement, reimbursement_amount, unreimbursed_amount,
    reimbursement_num, reimbursement_date, evaluation_person_one, evaluation_person_two,
    `status`, assess_report_message, assess_base_message, invoice_message, is_commission_reimbursement,
    item_type
  </sql>

  <sql id="to_list">
    pr.id,
    pr.create_by_id,
    pr.create_time,
    pr.update_by_id,
    pr.update_time,
    pr.remarks,
    pr.del_flag,
    pr.customer_name,
    pr.project_name,
    pr.year,
    pr.evaluation_objective,
    pr.project_type,
    pr.evaluation_base_date,
    pr.evaluation_report_date,
    pr.protocol_num,
    pr.document_num,
    pr.wayst_evaluation,
    pr.fixed_assets_evaluation,
    pr.net_assets_evaluation,
    pr.rent_evaluation,
    pr.forensics,
    pr.report_charges,
    pr.current_dispose_person,
    pr.is_invoice,
    pr.invoice_date,
    pr.actual_charges,
    pr.is_contract_archive,
    pr.is_papers_intact,
    pr.is_papers_archive,
    pr.ops_amount,
    pr.is_ops_reimbursement,
    pr.reimbursement_amount,
    pr.unreimbursed_amount,
    pr.reimbursement_num,
    pr.reimbursement_date,
    pr.`status`,
    pr.assess_report_message,
    pr.assess_base_message,
    pr.invoice_message,
    pr.is_commission_reimbursement,
    pr.item_type,
    pr.file_upload_type
  </sql>


  <select id="selectByDocumentNum" resultType="com.jeeplus.assess.projectRecords.domain.Project">
    select
    <include refid="Base_Column_List"></include>
    from
    project_records
    <where>
      del_flag = '0' and document_num = #{documentNum}
      <if test="id != null and id != ''">
        and id = #{id}
      </if>
    </where>
  </select>

  <select id="selectByProjectId" resultType="com.jeeplus.assess.projectRecords.domain.Project">
    select
    <include refid="to_list"></include>,
    su1.id as projectHead,
    pr.evaluation_person_one,
    pr.evaluation_person_two
--     su2.id as evaluationPersonOne,
--     su3.id as evaluationPersonTwo
    from project_records pr
    left join sys_user su1 on pr.project_head = su1.id
    left join sys_user su2 on pr.evaluation_person_one = su2.id
    left join sys_user su3 on pr.evaluation_person_two = su3.id
    where pr.del_flag = '0' and pr.id = #{projectId}
  </select>

  <select id="selectPage" resultType="com.jeeplus.assess.projectRecords.domain.Project">
    select
    <include refid="to_list"></include>,
    su1.name as projectHead,
    su1.id as projectHeadId,
    pr.evaluation_person_one,
    pr.evaluation_person_two
--     su2.name as evaluationPersonOne,
--     su3.name as evaluationPersonTwo
    from project_records pr
    left join sys_user su1 on pr.project_head = su1.id
    left join sys_user su2 on pr.evaluation_person_one = su2.id
    left join sys_user su3 on pr.evaluation_person_two = su3.id
    <where >
      pr.del_flag = '0'
      <if test="project.customerName != null and project.customerName != ''">
        and pr.customer_name like concat('%',#{project.customerName},'%')
      </if>
      <if test="project.projectName != null and project.projectName != ''">
        and pr.project_name like concat('%',#{project.projectName},'%')
      </if>
      <if test="project.itemType != null and project.itemType != ''">
        and pr.item_type = #{project.itemType}
      </if>
    </where>
    order by pr.create_time desc
  </select>

  <select id="findList" resultType="com.jeeplus.assess.projectRecords.domain.Project">
    select
    <include refid="to_list"></include>,
    su1.name as projectHead,
    su1.id as projectHeadId,
    pr.evaluation_person_one,
    pr.evaluation_person_two
--     su2.name as evaluationPersonOne,
--     su3.name as evaluationPersonTwo
    from project_records pr
    left join sys_user su on pr.project_head = su.id
    left join sys_user su1 on pr.project_head = su1.id
    left join sys_user su2 on pr.evaluation_person_one = su2.id
    left join sys_user su3 on pr.evaluation_person_two = su3.id
    ${ew.customSqlSegment}
    order by pr.create_time desc
  </select>

  <select id="proportion" resultType="java.lang.Integer">
    SELECT
        count(1)
    FROM
        project_records pr
    left join sys_user su on pr.project_head = su.id
    ${ew.customSqlSegment}
  </select>

  <select id="projectAllList" resultType="com.jeeplus.assess.projectRecords.service.dto.FileUploadListDTO">
    SELECT
        su.`name`,
        COUNT(1) AS allNum
    FROM
        project_records pr
        LEFT JOIN sys_user su ON pr.project_head = su.id
    <where>
      su.del_flag=0
      and pr.del_flag=0
      and pr.item_type = #{itemType}
      <if test="year != null and year != ''">
        and pr.year = #{year}
      </if>
      <if test="customerName != null and customerName != ''">
        and pr.customer_name like concat('%',#{customerName},'%')
      </if>
      <if test="protocolNum != null and protocolNum != ''">
        and pr.protocol_num like concat('%',#{protocolNum},'%')
      </if>
      <if test="projectName != null and projectName != ''">
        and pr.project_name like concat('%',#{projectName},'%')
      </if>
      <if test="documentNum != null and documentNum != ''">
        and pr.document_num like concat('%',#{documentNum},'%')
      </if>
      <if test="projectHead != null and projectHead != ''">
        and pr.project_head = #{projectHead}
      </if>
    </where>
        GROUP BY su.id
  </select>

  <select id="projectList" resultType="com.jeeplus.assess.projectRecords.service.dto.FileUploadListDTO">
    SELECT
        su.`name`,
        COUNT(1) AS num
    FROM
        project_records pr
        LEFT JOIN sys_user su ON pr.project_head = su.id
    <where>
      su.del_flag=0
      and pr.del_flag=0
      and pr.file_upload_type = 1
      and pr.item_type = #{itemType}
      <if test="year != null and year != ''">
        and pr.year = #{year}
      </if>
      <if test="customerName != null and customerName != ''">
        and pr.customer_name like concat('%',#{customerName},'%')
      </if>
      <if test="protocolNum != null and protocolNum != ''">
        and pr.protocol_num like concat('%',#{protocolNum},'%')
      </if>
      <if test="projectName != null and projectName != ''">
        and pr.project_name like concat('%',#{projectName},'%')
      </if>
      <if test="documentNum != null and documentNum != ''">
        and pr.document_num like concat('%',#{documentNum},'%')
      </if>
      <if test="projectHead != null and projectHead != ''">
        and pr.project_head = #{projectHead}
      </if>
    </where>
        GROUP BY su.id
  </select>

</mapper>