<?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="com.njzscloud.supervisory.biz.mapper.BizProjectMapper">

    <resultMap id="SearchBizProjectResultMap" autoMapping="true" type="com.njzscloud.supervisory.biz.pojo.result.SearchBizProjectResult">
        <result property="contract" column="contract" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
        <result property="auditStatus" column="audit_status" typeHandler="com.njzscloud.common.mp.support.handler.e.EnumTypeHandlerDealer"/>
        <result property="contractDate" column="contract_date" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
    </resultMap>

    <select id="paging" resultMap="SearchBizProjectResultMap">
        SELECT a.id,
               a.user_id,
               a.other_user_id,
               a.other_company_id,
               a.project_name,
               a.contract,
               a.province,
               a.city,
               a.area,
               a.town,
               a.province_name,
               a.city_name,
               a.area_name,
               a.town_name,
               a.address,
               a.lng,
               a.lat,
               a.creator_id,
               a.modifier_id,
               a.create_time,
               a.modify_time,
               a.deleted,
               a.audit_status,
               a.audit_memo,
        a.contract_date,
               b.company_name other_company_name,
               c.company_name,
               c.id           company_id,
               d.nickname,
               e.nickname other_nickname
        FROM biz_project a
        Left JOIN biz_company b ON b.id = a.other_company_id
        Left JOIN biz_company c ON c.user_id = a.user_id
        Left JOIN sys_user d ON a.user_id = d.id
        Left JOIN sys_user e ON a.other_user_id = e.id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
        ORDER BY a.modify_time DESC
    </select>
    <select id="companyAudit" resultType="java.lang.Integer">
        SELECT count(*)
        FROM biz_company
    </select>
</mapper>
