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

  <resultMap id="tAutoInsurStandardMap" type="com.yifu.cloud.plus.v1.yifu.archives.entity.TAutoInsurStandard">
    <id property="id" column="ID"/>
    <result property="name" column="NAME"/>
    <result property="company" column="COMPANY"/>
    <result property="riskType" column="RISK_TYPE"/>
	<result property="companyId" column="COMPANY_ID"/>
	<result property="riskTypeId" column="RISK_TYPE_ID"/>
    <result property="standard" column="STANDARD"/>
    <result property="buyProvince" column="BUY_PROVINCE"/>
    <result property="buyCity" column="BUY_CITY"/>
    <result property="buyTown" column="BUY_TOWN"/>
    <result property="mainId" column="MAIN_ID"/>
    <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"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.ID,
                a.NAME,
                a.COMPANY,
                a.RISK_TYPE,
                a.STANDARD,
                a.BUY_PROVINCE,
                a.BUY_CITY,
                a.BUY_TOWN,
                a.MAIN_ID,
                a.CREATE_BY,
                a.CREATE_NAME,
                a.CREATE_TIME,
                a.UPDATE_BY,
                a.UPDATE_TIME,a.COMPANY_ID,a.RISK_TYPE_ID
    </sql>
    <sql id="tAutoInsurStandard_where">
        <if test="tAutoInsurStandard != null">
                    <if test="tAutoInsurStandard.id != null and tAutoInsurStandard.id.trim() != ''">
                        AND a.ID = #{tAutoInsurStandard.id}
                    </if>
                    <if test="tAutoInsurStandard.name != null and tAutoInsurStandard.name.trim() != ''">
                        AND a.NAME = #{tAutoInsurStandard.name}
                    </if>
                    <if test="tAutoInsurStandard.company != null">
                        AND a.COMPANY = #{tAutoInsurStandard.company}
                    </if>
					<if test="tAutoInsurStandard.riskType != null">
						AND a.RISK_TYPE = #{tAutoInsurStandard.riskType}
					</if>
					<if test="tAutoInsurStandard.riskTypeId != null">
						AND a.RISK_TYPE_ID = #{tAutoInsurStandard.riskTypeId}
					</if>
					<if test="tAutoInsurStandard.companyId != null">
						AND a.COMPANY_ID = #{tAutoInsurStandard.companyId}
					</if>
					<if test="tAutoInsurStandard.standard != null and tAutoInsurStandard.standard.trim() != ''">
                        AND a.STANDARD = #{tAutoInsurStandard.standard}
                    </if>
                    <if test="tAutoInsurStandard.buyProvince != null">
                        AND a.BUY_PROVINCE = #{tAutoInsurStandard.buyProvince}
                    </if>
                    <if test="tAutoInsurStandard.buyCity != null">
                        AND a.BUY_CITY = #{tAutoInsurStandard.buyCity}
                    </if>
                    <if test="tAutoInsurStandard.buyTown != null">
                        AND a.BUY_TOWN = #{tAutoInsurStandard.buyTown}
                    </if>
                    <if test="tAutoInsurStandard.mainId != null and tAutoInsurStandard.mainId.trim() != ''">
                        AND a.MAIN_ID = #{tAutoInsurStandard.mainId}
                    </if>
                    <if test="tAutoInsurStandard.createBy != null and tAutoInsurStandard.createBy.trim() != ''">
                        AND a.CREATE_BY = #{tAutoInsurStandard.createBy}
                    </if>
                    <if test="tAutoInsurStandard.createName != null and tAutoInsurStandard.createName.trim() != ''">
                        AND a.CREATE_NAME = #{tAutoInsurStandard.createName}
                    </if>
                    <if test="tAutoInsurStandard.createTime != null">
                        AND a.CREATE_TIME = #{tAutoInsurStandard.createTime}
                    </if>
                    <if test="tAutoInsurStandard.updateBy != null and tAutoInsurStandard.updateBy.trim() != ''">
                        AND a.UPDATE_BY = #{tAutoInsurStandard.updateBy}
                    </if>
                    <if test="tAutoInsurStandard.updateTime != null">
                        AND a.UPDATE_TIME = #{tAutoInsurStandard.updateTime}
                    </if>
        </if>
    </sql>
    <!--tAutoInsurStandard简单分页查询-->
    <select id="getTAutoInsurStandardPage" resultMap="tAutoInsurStandardMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_auto_insur_standard a
		<if test="(tAutoInsurStandard.standardMin != null and tAutoInsurStandard.standardMin.trim() != '') or (tAutoInsurStandard.standardMax != null and tAutoInsurStandard.standardMax.trim() != '')">
				LEFT JOIN (select * from t_auto_standard_info  where 1=1
					<if test="tAutoInsurStandard.standardMin != null and tAutoInsurStandard.standardMin.trim() != ''">
						  and STANDARD+0 >=  #{tAutoInsurStandard.standardMin}+0
					</if>
					<if test="tAutoInsurStandard.standardMax != null and tAutoInsurStandard.standardMax.trim() != ''">
						and STANDARD+0 <![CDATA[ <= ]]>  #{tAutoInsurStandard.standardMax}+0
					</if>
				) b on a.id=b.MAIN_ID
		</if>

        <where>
            1=1
			<if test="(tAutoInsurStandard.standardMin != null and tAutoInsurStandard.standardMin.trim() != '') or (tAutoInsurStandard.standardMax != null and tAutoInsurStandard.standardMax.trim() != '')">
				and b.id is not null
			</if>
			<if test="tAutoInsurStandard != null">
				<if test="tAutoInsurStandard.mainId != null and tAutoInsurStandard.mainId.trim() != ''">
					AND a.MAIN_ID = #{tAutoInsurStandard.mainId}
				</if>
				<if test="tAutoInsurStandard.name != null and tAutoInsurStandard.name.trim() != ''">
					AND a.NAME like concat('%',#{tAutoInsurStandard.name}, '%')
				</if>
				<if test="tAutoInsurStandard.company != null">
					AND a.COMPANY like concat('%',#{tAutoInsurStandard.company}, '%')
				</if>
				<if test="tAutoInsurStandard.riskType != null">
					AND a.RISK_TYPE like concat('%',#{tAutoInsurStandard.riskType}, '%')
				</if>
			</if>
        </where>
		group by a.id
    </select>
</mapper>
