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

  <resultMap id="tFascCompanyMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TFascCompany">
    <id property="id" column="id"/>
    <result property="companyName" column="company_name"/>
    <result property="appId" column="app_id"/>
    <result property="openId" column="open_id"/>
    <result property="appSecret" column="app_secret"/>
    <result property="appUrl" column="app_url"/>
    <result property="createBy" column="CREATE_BY"/>
    <result property="createName" column="CREATE_NAME"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="updateBy" column="UPDATE_BY"/>
    <result property="updateTime" column="UPDATE_TIME"/>
    <result property="businessId" column="business_id"/>
	<result property="deleteFlag" column="DELETE_FLAG"/>
    <result property="deleteName" column="DELETE_NAME"/>
    <result property="deleteTime" column="DELETE_TIME"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.id,
                a.company_name,
                a.app_id,
                a.app_secret,
                a.app_url,
                a.open_id,
                a.CREATE_BY,
                a.CREATE_NAME,
                a.CREATE_TIME,
                a.UPDATE_BY,
                a.UPDATE_TIME,
                a.business_id,
                a.DELETE_FLAG,
                a.DELETE_NAME,
                a.DELETE_TIME
    </sql>
    <sql id="tFascCompany_where">
        <if test="tFascCompany != null">
                    <if test="tFascCompany.id != null and tFascCompany.id.trim() != ''">
                        AND a.id = #{tFascCompany.id}
                    </if>
                    <if test="tFascCompany.companyName != null and tFascCompany.companyName.trim() != ''">
                        AND a.company_name like concat('%', #{tFascCompany.companyName}, '%')
                    </if>
                    <if test="tFascCompany.appId != null and tFascCompany.appId.trim() != ''">
                        AND a.app_id = #{tFascCompany.appId}
                    </if>
                    <if test="tFascCompany.appSecret != null and tFascCompany.appSecret.trim() != ''">
                        AND a.app_secret = #{tFascCompany.appSecret}
                    </if>
                    <if test="tFascCompany.appUrl != null and tFascCompany.appUrl.trim() != ''">
                        AND a.app_url = #{tFascCompany.appUrl}
                    </if>
                    <if test="tFascCompany.createBy != null and tFascCompany.createBy.trim() != ''">
                        AND a.CREATE_BY = #{tFascCompany.createBy}
                    </if>
                    <if test="tFascCompany.createName != null and tFascCompany.createName.trim() != ''">
                        AND a.CREATE_NAME = #{tFascCompany.createName}
                    </if>
                    <if test="tFascCompany.createTime != null">
                        AND a.CREATE_TIME = #{tFascCompany.createTime}
                    </if>
                    <if test="tFascCompany.updateBy != null and tFascCompany.updateBy.trim() != ''">
                        AND a.UPDATE_BY = #{tFascCompany.updateBy}
                    </if>
                    <if test="tFascCompany.updateTime != null">
                        AND a.UPDATE_TIME = #{tFascCompany.updateTime}
                    </if>
        </if>
    </sql>
    <select id="getTFascCompanyAllList" resultMap="tFascCompanyMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_fasc_company a
        where a.DELETE_FLAG = '0'
			<if test="companyName != null and companyName.trim() != ''">
			  AND a.company_name like concat('%', #{companyName}, '%')
			</if>
		order by a.CREATE_TIME asc
    </select>

	<!--tFascCompany简单分页查询，排序顺序，为了总公司在第一位-->
	<select id="getTFascCompanyPage" resultMap="tFascCompanyMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM t_fasc_company a
		<where>
			a.DELETE_FLAG = '0'
			<include refid="tFascCompany_where"/>
		</where>
		order by a.CREATE_TIME asc
	</select>

	<!--查重 -->
	<select id="getTFascCompanyByNameAndId" resultType="java.lang.Integer">
		SELECT
			count(1)
		FROM t_fasc_company a
		where a.DELETE_FLAG = '0' and a.company_name = #{companyName}
		<if test="id != null and id.trim() != ''">
			AND a.id != #{id}
		</if>
	</select>

</mapper>
