<?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.FddContractTemplateMapper">

  <resultMap id="fddContractTemplateMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.FddContractTemplate">
    <id property="id" column="ID"/>
    <result property="type" column="TYPE"/>
    <result property="modifyUploadStatus" column="MODIFY_UPLOAD_STATUS"/>
    <result property="province" column="PROVINCE"/>
    <result property="city" column="CITY"/>
    <result property="overtimeWageFlag" column="OVERTIME_WAGE_FLAG"/>
    <result property="fddTemplateId" column="FDD_TEMPLATE_ID"/>
    <result property="localName" column="LOCAL_NAME"/>
    <result property="signerName" column="SIGNER_NAME"/>
    <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.TYPE,
                  a.modify_upload_status,
                  a.province,
                  a.city,
                  a.OVERTIME_WAGE_FLAG,
                  a.FDD_TEMPLATE_ID,
                  a.LOCAL_NAME,
                  a.SIGNER_NAME,
				  a.CREATE_BY,
        		  a.CREATE_NAME,
        		  a.CREATE_TIME,
        		  a.UPDATE_BY,
        		  a.UPDATE_TIME
	</sql>
	<sql id="fddContractTemplate_where">
		<if test="fddContractTemplate != null">
			<if test="fddContractTemplate.id != null and fddContractTemplate.id.trim() != ''">
				AND a.ID = #{fddContractTemplate.id}
			</if>
			<if test="fddContractTemplate.localName != null and fddContractTemplate.localName.trim() != ''">
				AND a.LOCAL_NAME like CONCAT(#{fddContractTemplate.localName},'%')
			</if>
			<if test="fddContractTemplate.type != null and fddContractTemplate.type.trim() != ''">
				AND a.TYPE = #{fddContractTemplate.type}
			</if>
			<if test="fddContractTemplate.modifyUploadStatus != null and fddContractTemplate.modifyUploadStatus.trim() != ''">
				AND a.modify_upload_status = #{fddContractTemplate.modifyUploadStatus}
			</if>
			<if test="fddContractTemplate.province != null">
				AND a.province = #{fddContractTemplate.province}
			</if>
			<if test="fddContractTemplate.city != null">
				AND a.city = #{fddContractTemplate.city}
			</if>
			<if test="fddContractTemplate.overtimeWageFlag != null and fddContractTemplate.overtimeWageFlag.trim() != ''">
				AND a.OVERTIME_WAGE_FLAG = #{fddContractTemplate.overtimeWageFlag}
			</if>
			<if test="fddContractTemplate.signerName != null and fddContractTemplate.signerName.trim() != ''">
				AND a.SIGNER_NAME = #{fddContractTemplate.signerName}
			</if>
			<if test="fddContractTemplate.createBy != null and fddContractTemplate.createBy.trim() != ''">
				AND a.CREATE_BY = #{fddContractTemplate.createBy}
			</if>
			<if test="fddContractTemplate.createName != null and fddContractTemplate.createName.trim() != ''">
				AND a.CREATE_NAME = #{fddContractTemplate.createName}
			</if>
			<if test="fddContractTemplate.createTime != null">
				AND a.CREATE_TIME = #{fddContractTemplate.createTime}
			</if>
			<if test="fddContractTemplate.updateBy != null and fddContractTemplate.updateBy.trim() != ''">
				AND a.UPDATE_BY = #{fddContractTemplate.updateBy}
			</if>
			<if test="fddContractTemplate.updateTime != null">
				AND a.UPDATE_TIME = #{fddContractTemplate.updateTime}
			</if>
		</if>
	</sql>
	<!--fddContractTemplate简单分页查询-->
	<select id="getFddContractTemplatePage" resultMap="fddContractTemplateMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM fdd_contract_template a
		<where>
			1=1
			<include refid="fddContractTemplate_where"/>
		</where>
		order by a.CREATE_TIME desc
	</select>

	<update id="updateTeFddTemplateNull">
		update fdd_contract_template set FDD_TEMPLATE_ID=null where id=#{id}
	</update>
</mapper>
