<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.yifu.archives.mapper.FddContractAttachInfoMapper">

  <resultMap id="fddContractAttachInfoMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.FddContractAttachInfo">
    <id property="id" column="ID"/>
    <result property="contractId" column="CONTRACT_ID"/>
    <result property="periodStart" column="PERIOD_START"/>
    <result property="periodEnd" column="PERIOD_END"/>
    <result property="contractStart" column="CONTRACT_START"/>
    <result property="contractEnd" column="CONTRACT_END"/>
    <result property="periodSalaryPerMonth" column="PERIOD_SALARY_PER_MONTH"/>
    <result property="salaryType" column="SALARY_TYPE"/>
    <result property="salaryStandardPerHour" column="SALARY_STANDARD_PER_HOUR"/>
    <result property="salaryStandardPerPiece" column="SALARY_STANDARD_PER_PIECE"/>
    <result property="workSpace" column="WORK_SPACE"/>
    <result property="post" column="POST"/>
    <result property="remark" column="REMARK"/>
    <result property="deleteFlag" column="DELETE_FLAG"/>
    <result property="isMove" column="IS_MOVE"/>
    <result property="fddTemplateId" column="FDD_TEMPLATE_ID"/>
    <result property="empName" column="EMP_NAME"/>
    <result property="empIdcard" column="EMP_IDCARD"/>
    <result property="empPhone" column="EMP_PHONE"/>
    <result property="departNo" column="DEPART_NO"/>
    <result property="createBy" column="CREATE_BY"/>
    <result property="updateBy" column="UPDATE_BY"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="updateTime" column="UPDATE_TIME"/>
    <result property="createName" column="CREATE_NAME"/>
  </resultMap>

	<sql id="Base_Column_List">
				  a.ID,
                  a.CONTRACT_ID,
                  a.PERIOD_START,
                  a.PERIOD_END,
                  a.PERIOD_SALARY_PER_MONTH,
                  a.SALARY_TYPE,
                  a.SALARY_STANDARD_PER_HOUR,
                  a.SALARY_STANDARD_PER_PIECE,
                  a.REMARK,
                  a.DELETE_FLAG,
                  a.WORK_SPACE,
                  a.IS_MOVE,
                  a.FDD_TEMPLATE_ID,
                  a.EMP_NAME,
                  a.EMP_IDCARD,
                  a.EMP_PHONE,
                  a.DEPART_NO,
                  a.CONTRACT_START,
				  a.CONTRACT_END,
				  a.CREATE_BY,
        		  a.CREATE_NAME,
        		  a.CREATE_TIME,
        		  a.UPDATE_BY,
        		  a.UPDATE_TIME
	</sql>
	<sql id="fddContractAttachInfo_where">
		<if test="fddContractAttachInfo != null">
			<if test="fddContractAttachInfo.id != null and fddContractAttachInfo.id.trim() != ''">
				AND a.ID = #{fddContractAttachInfo.id}
			</if>
			<if test="fddContractAttachInfo.contractId != null and fddContractAttachInfo.contractId.trim() != ''">
				AND a.CONTRACT_ID = #{fddContractAttachInfo.contractId}
			</if>
			<if test="fddContractAttachInfo.periodStart != null">
				AND a.PERIOD_START = #{fddContractAttachInfo.periodStart}
			</if>
			<if test="fddContractAttachInfo.periodEnd != null">
				AND a.PERIOD_END = #{fddContractAttachInfo.periodEnd}
			</if>
			<if test="fddContractAttachInfo.periodSalaryPerMonth != null">
				AND a.PERIOD_SALARY_PER_MONTH = #{fddContractAttachInfo.periodSalaryPerMonth}
			</if>
			<if test="fddContractAttachInfo.salaryType != null and fddContractAttachInfo.salaryType.trim() != ''">
				AND a.SALARY_TYPE = #{fddContractAttachInfo.salaryType}
			</if>
			<if test="fddContractAttachInfo.salaryStandardPerHour != null">
				AND a.SALARY_STANDARD_PER_HOUR = #{fddContractAttachInfo.salaryStandardPerHour}
			</if>
			<if test="fddContractAttachInfo.salaryStandardPerPiece != null">
				AND a.SALARY_STANDARD_PER_PIECE = #{fddContractAttachInfo.salaryStandardPerPiece}
			</if>
			<if test="fddContractAttachInfo.fddTemplateId != null and fddContractAttachInfo.fddTemplateId.trim() != ''">
				AND a.FDD_TEMPLATE_ID = #{fddContractAttachInfo.fddTemplateId}
			</if>
			<if test="fddContractAttachInfo.empName != null and fddContractAttachInfo.empName.trim() != ''">
				AND a.EMP_NAME = #{fddContractAttachInfo.empName}
			</if>
			<if test="fddContractAttachInfo.empIdcard != null and fddContractAttachInfo.empIdcard.trim() != ''">
				AND a.EMP_IDCARD = #{fddContractAttachInfo.empIdcard}
			</if>
			<if test="fddContractAttachInfo.empPhone != null and fddContractAttachInfo.empPhone.trim() != ''">
				AND a.EMP_PHONE = #{fddContractAttachInfo.empPhone}
			</if>
			<if test="fddContractAttachInfo.departNo != null and fddContractAttachInfo.departNo.trim() != ''">
				AND a.DEPART_NO = #{fddContractAttachInfo.departNo}
			</if>
			<if test="fddContractAttachInfo.contractStart != null">
				AND a.CONTRACT_START = #{fddContractAttachInfo.contractStart}
			</if>
			<if test="fddContractAttachInfo.contractEnd != null">
				AND a.CONTRACT_END = #{fddContractAttachInfo.contractEnd}
			</if>
			<if test="fddContractAttachInfo.createBy != null and fddContractAttachInfo.createBy.trim() != ''">
				AND a.CREATE_BY = #{fddContractAttachInfo.createBy}
			</if>
			<if test="fddContractAttachInfo.createName != null and fddContractAttachInfo.createName.trim() != ''">
				AND a.CREATE_NAME = #{fddContractAttachInfo.createName}
			</if>
			<if test="fddContractAttachInfo.createTime != null">
				AND a.CREATE_TIME = #{fddContractAttachInfo.createTime}
			</if>
			<if test="fddContractAttachInfo.updateBy != null and fddContractAttachInfo.updateBy.trim() != ''">
				AND a.UPDATE_BY = #{fddContractAttachInfo.updateBy}
			</if>
			<if test="fddContractAttachInfo.updateTime != null">
				AND a.UPDATE_TIME = #{fddContractAttachInfo.updateTime}
			</if>
		</if>
	</sql>
	<!--fddContractAttachInfo简单分页查询-->
	<select id="getFddContractAttachInfoPage" resultMap="fddContractAttachInfoMap">
		SELECT
		<include refid="Base_Column_List"/>,
		i.id FDD_CONTRACT_ID,i.TASK_STATUS,i.SEND_SIGN_STATUS,i.RECEIVE_SIGN_STATUS,i.SIGN_STATUS,i.TASK_ID,i.SIGN_TASK_ID,i.DRAFT_ID,i.REMARK SIGN_REMARK
		FROM fdd_contract_attach_info a
		left join fdd_contract_info i on a.CONTRACT_ID=i.CONTRACT_ID
		<where>
			1=1 and a.DELETE_FLAG='0' and  (i.DELETE_FLAG='0' or i.id is null )
			<include refid="fddContractAttachInfo_where"/>
		</where>
		order by a.CREATE_TIME desc
	</select>

	<select id="getListByNoInfoByEmpIdcard" resultType="com.yifu.cloud.plus.v1.yifu.archives.entity.FddContractAttachInfo">
		select a.*   FROM fdd_contract_attach_info a
							  left join fdd_contract_info i on a.CONTRACT_ID=i.CONTRACT_ID
							  left join t_employee_contract_info c on a.CONTRACT_ID=c.ID
							  left join t_employee_info e on c.EMP_Id=e.ID
		where e.EMP_IDCARD=#{empIdcard}  and i.id is null and a.DELETE_FLAG='0' order by a.CREATE_TIME desc
	</select>
</mapper>