<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.app.mapper.AppUserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.springblade.modules.app.entity.UserDO">
        <result column="id" property="id"/>
        <result column="zmt_id" property="zmtId"/>
        <result column="zmt_name" property="zmtName"/>
        <result column="zmt_type" property="zmtType"/>
        <result column="zmt_user_id" property="zmtUserId"/>
        <result column="zmt_user_name" property="zmtUserName"/>
        <result column="breed_code" property="breedCode"/>
        <result column="version" property="version"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="created_time" property="createdTime"/>
        <result column="creator" property="creator"/>
        <result column="modified_time" property="modifiedTime"/>
        <result column="modifier" property="modifier"/>
        <result column="phone" property="phone"/>
        <result column="user_password" property="password"/>
        <result column="type" property="type"/>
        <result column="state" property="state"/>
        <result column="business_link_man" property="businessLinkMan"/>
        <result column="user_name" property="userName"/>
        <result column="prov_id" property="provId"/>
        <result column="prov_name" property="provName"/>
        <result column="city_id" property="cityId"/>
        <result column="city_name" property="cityName"/>
        <result column="area_id" property="areaId"/>
        <result column="area_name" property="areaName"/>
        <result column="address" property="address"/>
        <result column="business_industry_categrory" property="businessIndustryCategrory"/>
        <result column="business_legal_person" property="businessLegalPerson"/>
        <result column="business_register_money" property="businessRegisterMoney"/>
        <result column="business_register_date" property="businessRegisterDate"/>
        <result column="business_term" property="businessTerm"/>
        <result column="business_scope" property="businessScope"/>
        <result column="credit_code" property="creditCode"/>
        <result column="business_url" property="businessUrl"/>
        <result column="id_card_front_url" property="idCardFrontUrl"/>
        <result column="id_card_behind_url" property="idCardBehindUrl"/>
        <result column="livestock_prevention_pass_code" property="livestockPreventionPassCode"/>
        <result column="livestock_prevention_pass_url" property="livestockPreventionPassUrl"/>
        <result column="livestock_slaughter_permit_code" property="livestockSlaughterPermitCode"/>
        <result column="livestock_slaughter_permit_url" property="livestockSlaughterPermitUrl"/>
        <result column="pollutant_discharge_permit_code" property="pollutantDischargePermitCode"/>
        <result column="pollutant_discharge_permit_industry" property="pollutantDischargePermitIndustry"/>
        <result column="pollutant_discharge_permit_date" property="pollutantDischargePermitDate"/>
        <result column="pollutant_discharge_permit_license_url" property="pollutantDischargePermitLicenseUrl"/>
        <result column="no_epidemic_proof_pass_date" property="noEpidemicProofPassDate"/>
        <result column="no_epidemic_proof_pass_url" property="noEpidemicProofPassUrl"/>
        <result column="driver_licence_code" property="driverLicenceCode"/>
        <result column="driver_licence_url" property="driverLicenceUrl"/>
        <result column="driver_car_type" property="driverCarType"/>
        <result column="driver_issuing" property="driverIssuing"/>
        <result column="driver_first_issue_date" property="driverFirstIssueDate"/>
        <result column="driver_licence_expiry_date" property="driverLicenceExpiryDate"/>
        <result column="vehicle_license_code" property="vehicleLicenseCode"/>
        <result column="vehicle_license_url" property="vehicleLicenseUrl"/>
        <result column="transport_permit_code" property="transportPermitCode"/>
        <result column="transport_permit_url" property="transportPermitUrl"/>
        <result column="slaughter_house_parent_id" property="slaughterHouseParentId"/>
        <result column="slaughter_house_parent_name" property="slaughterHouseParentName"/>
        <result column="slaughter_house_type" property="slaughterHouseType"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        version,
        is_deleted,
        created_time,
        creator,
        modified_time,
        modifier,
        phone, zmt_id, zmt_name, zmt_type, zmt_user_id, zmt_user_name, breed_code, user_password,type, state, business_link_man, user_name, prov_id, prov_name, city_id, city_name, area_id, area_name, address, business_industry_categrory, business_legal_person, business_register_money, business_register_date, business_term, business_scope, credit_code, business_url, id_card_front_url, id_card_behind_url, livestock_prevention_pass_code, livestock_prevention_pass_url, livestock_slaughter_permit_code, livestock_slaughter_permit_url, pollutant_discharge_permit_code, pollutant_discharge_permit_industry, pollutant_discharge_permit_date, pollutant_discharge_permit_license_url, no_epidemic_proof_pass_date, no_epidemic_proof_pass_url, driver_licence_code, driver_licence_url, driver_car_type, driver_issuing, driver_first_issue_date, driver_licence_expiry_date, vehicle_license_code, vehicle_license_url, transport_permit_code, transport_permit_url, slaughter_house_parent_id, slaughter_house_type, slaughter_house_parent_name
    </sql>

    <select id="pageRegisterUser" resultType="org.springblade.modules.app.common.dto.UserDTO">
        select u.*,a.state checkState from tb_user u left join
        (select id,link_id,state,type,created_time from tb_application_info where id in(select Max(id) FROM
        tb_application_info GROUP BY link_id,type) AND type = 6) a
        on u.id = a.link_id and a.type = 6
        <where>
            <if test="query.phone != null and query.phone != ''">
                and u.phone = #{query.phone}
            </if>
            <if test="query.userName != null and query.userName != ''">
                and u.user_name like CONCAT('%',#{query.userName},'%')
            </if>
            <if test="query.checkState != null and query.checkState != 1">
                and a.state = #{query.checkState}
            </if>
            <if test="query.checkState != null and query.checkState == 1">
                and (a.state = #{query.checkState} or a.state is NULL)
            </if>
            <if test="query.type != null and query.type != 0">
                and u.type = #{query.type}
            </if>
            <if test="query.startTime != null">
                and a.created_time >= #{query.stateTime}
            </if>
            <if test="query.endTime != null">
                and a.created_time = #{query.endTime}
            </if>
            and u.is_deleted = 0
        </where>
        order by u.created_time desc
    </select>

    <select id="getUserByIdAll" resultType="org.springblade.modules.app.entity.UserDO">
        select * from tb_user where id = #{id}
    </select>

</mapper>
