<?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.social.mapper.THouseHoldLimitMapper">

  <resultMap id="tHouseHoldLimitMap" type="com.yifu.cloud.plus.v1.yifu.social.entity.THouseHoldLimit">
    <id property="id" column="ID"/>
    <result property="name" column="NAME"/>
    <result property="type" column="TYPE"/>
    <result property="province" column="PROVINCE"/>
    <result property="city" column="CITY"/>
    <result property="town" column="TOWN"/>
    <result property="houseHoldId" column="HOUSE_HOLD_ID"/>
    <result property="deadLineDay" column="DEAD_LINE_DAY"/>
    <result property="addHandleRule" column="ADD_HANDLE_RULE"/>
    <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>
	<resultMap id="tHouseHoldLimitExportMap" type="com.yifu.cloud.plus.v1.yifu.social.vo.THouseHoldLimitExportVo">
		<result property="name" column="NAME"/>
		<result property="type" column="TYPE"/>
		<result property="province" column="PROVINCE"/>
		<result property="deadLineDay" column="DEAD_LINE_DAY"/>
		<result property="addHandleRule" column="ADD_HANDLE_RULE"/>
		<result property="updateTime" column="UPDATE_TIME"/>
		<result property="createName" column="CREATE_NAME"/>
	</resultMap>
    <sql id="Base_Column_List">
		a.ID,
		a.NAME,
		a.TYPE,
		a.PROVINCE,
		a.CITY,
		a.TOWN,
		a.HOUSE_HOLD_ID,
		a.DEAD_LINE_DAY,
		a.ADD_HANDLE_RULE,
		a.CREATE_BY,
		a.UPDATE_BY,
		a.CREATE_TIME,
		a.UPDATE_TIME,
		a.CREATE_NAME
    </sql>
    <sql id="tHouseHoldLimit_where">
        <if test="tHouseHoldLimit != null">
                    <if test="tHouseHoldLimit.id != null and tHouseHoldLimit.id.trim() != ''">
                        AND a.ID = #{tHouseHoldLimit.id}
                    </if>
                    <if test="tHouseHoldLimit.name != null and tHouseHoldLimit.name.trim() != ''">
                        AND a.NAME like concat('%', #{tHouseHoldLimit.name}, '%')
                    </if>
                    <if test="tHouseHoldLimit.type != null and tHouseHoldLimit.type.trim() != ''">
                        AND a.TYPE = #{tHouseHoldLimit.type}
                    </if>
                    <if test="tHouseHoldLimit.province != null and tHouseHoldLimit.province.trim() != ''">
                        AND a.PROVINCE = #{tHouseHoldLimit.province}
                    </if>
                    <if test="tHouseHoldLimit.city != null and tHouseHoldLimit.city.trim() != ''">
                        AND a.CITY = #{tHouseHoldLimit.city}
                    </if>
                    <if test="tHouseHoldLimit.town != null and tHouseHoldLimit.town.trim() != ''">
                        AND a.TOWN = #{tHouseHoldLimit.town}
                    </if>
                    <if test="tHouseHoldLimit.houseHoldId != null and tHouseHoldLimit.houseHoldId.trim() != ''">
                        AND a.HOUSE_HOLD_ID = #{tHouseHoldLimit.houseHoldId}
                    </if>
                    <if test="tHouseHoldLimit.deadLineDay != null and tHouseHoldLimit.deadLineDay.trim() != ''">
                        AND a.DEAD_LINE_DAY = #{tHouseHoldLimit.deadLineDay}
                    </if>
                    <if test="tHouseHoldLimit.addHandleRule != null and tHouseHoldLimit.addHandleRule.trim() != ''">
                        AND a.ADD_HANDLE_RULE = #{tHouseHoldLimit.addHandleRule}
                    </if>
                    <if test="tHouseHoldLimit.createBy != null and tHouseHoldLimit.createBy.trim() != ''">
                        AND a.CREATE_BY = #{tHouseHoldLimit.createBy}
                    </if>
                    <if test="tHouseHoldLimit.updateBy != null and tHouseHoldLimit.updateBy.trim() != ''">
                        AND a.UPDATE_BY = #{tHouseHoldLimit.updateBy}
                    </if>
                    <if test="tHouseHoldLimit.createTime != null">
                        AND a.CREATE_TIME = #{tHouseHoldLimit.createTime}
                    </if>
                    <if test="tHouseHoldLimit.updateTime != null">
                        AND a.UPDATE_TIME = #{tHouseHoldLimit.updateTime}
                    </if>
					<if test="tHouseHoldLimit.updateTimeEnd != null">
						AND a.UPDATE_TIME <![CDATA[<=]]> #{tHouseHoldLimit.updateTimeEnd}
					</if>
					<if test="tHouseHoldLimit.updateTimeStart != null">
						AND a.UPDATE_TIME <![CDATA[>=]]> #{tHouseHoldLimit.updateTimeStart}
					</if>
                    <if test="tHouseHoldLimit.createName != null and tHouseHoldLimit.createName.trim() != ''">
                        AND a.CREATE_NAME = #{tHouseHoldLimit.createName}
                    </if>
        </if>
    </sql>
    <!--tHouseHoldLimit简单分页查询-->
    <select id="getTHouseHoldLimitPage" resultMap="tHouseHoldLimitMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_house_hold_limit a
        <where>
            1=1
            <include refid="tHouseHoldLimit_where"/>
        </where>
    </select>

	<select id="exportCountDiy" resultType="int">
		SELECT
		count(1)
		FROM t_house_hold_limit a
		<where>
			1=1
			<include refid="tHouseHoldLimit_where"/>
		</where>
	</select>

	<select id="exportDiy" resultMap="tHouseHoldLimitExportMap">
		SELECT
		a.NAME,
		a.TYPE,
		CONCAT_WS('-',p.AREA_NAME,c.AREA_NAME,t.AREA_NAME) as 'PROVINCE',
		a.DEAD_LINE_DAY,
		a.ADD_HANDLE_RULE,
		a.UPDATE_TIME,
		a.CREATE_NAME
		FROM t_house_hold_limit a
		LEFT JOIN sys_area p on p.id=a.PROVINCE
		LEFT JOIN sys_area c on c.id=a.CITY
		LEFT JOIN sys_area t on t.id=a.TOWN
		<where>
			1=1
			<include refid="tHouseHoldLimit_where"/>
			<if test="tHouseHoldLimit != null">
				<if test="tHouseHoldLimit.limitStart != null">
					limit #{tHouseHoldLimit.limitStart},#{tHouseHoldLimit.limitEnd}
				</if>
			</if>
		</where>
	</select>
</mapper>
