<?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.nantian.cloud.jly.mapper.MemorandumMapper">
    <cache eviction="LRU" flushInterval="60000" size="512" readOnly="false"/>
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jly.vo.MemorandumVo">
        <id column="id" property="id"/>
        <result column="enterpriseCode" property="enterpriseCode"/>
        <result column="cmpName" property="cmpName"/>
        <result column="regionCode" property="regionCode"/>
        <result column="corporationName" property="corporationName"/>
        <result column="address" property="address"/>
        <result column="tId" property="tId"/>
        <result column="file_name" property="fileName"/>
    </resultMap>

    <select id="selectPageAll" resultType="com.nantian.cloud.jly.vo.MemorandumVo">
<!--        select m.id id, a.enterprise_code enterpriseCode,a.cmp_name cmpName,a.region_code regionCode,-->
<!--        a.corporation_name corporationName,a.address,a.t_id tId,m.file_name fileName,a.region_code dept_id-->
<!--        from enterprise_info a-->
<!--        &lt;!&ndash;INNER JOIN  enterprise_info_em e ON e.enterpriseCode = a.enterprise_code&ndash;&gt;-->
<!--        left JOIN energy_record.enterprise_info r on r.enterpriseCode=a.enterprise_code-->
<!--        left JOIN memorandum m-->
        select m.id id, a.enterpriseCode,a.cmpName,a.regionCode,
        a.corporationName ,a.address,a.tId ,m.file_name fileName,a.regionCode dept_id
        from energy_record.enterprise_info a
        left JOIN memorandum m on m.epc=a.enterpriseCode
        <trim prefix="where" prefixOverrides="and">
            <if test="param.enterpriseCode!=null and param.enterpriseCode != ''">
                and a.enterpriseCode =#{param.enterpriseCode}
            </if>
            <if test="param.cmpName!=null and param.cmpName != ''">
                and a.cmpName like concat("%",#{param.cmpName},"%")
            </if>
            <if test="param.tId!=null and param.tId != ''">
                and a.tId =#{param.tId}
            </if>
            <if test="code!=null and code != ''">
                and a.regionCode like concat("%",#{code},"%")
            </if>
            and a.isRegister != '0'
            order by a.regionCode,a.enterpriseCode
        </trim>
        limit #{page.offset}, #{page.limit}
    </select>

    <select id="count" resultType="int">
        select a.regionCode dept_id
        from energy_record.enterprise_info a
        left JOIN memorandum m
        on m.epc=a.enterpriseCode
        <trim prefix="where" prefixOverrides="and">
            <if test="param.enterpriseCode!=null and param.enterpriseCode != ''">
                and a.enterpriseCode =#{param.enterpriseCode}
            </if>
            <if test="param.cmpName!=null and param.cmpName != ''">
                and a.cmpName like concat("%",#{param.cmpName},"%")
            </if>
            <if test="param.tId!=null and param.tId != ''">
                and a.tId =#{param.tId}
            </if>
            <if test="code!=null and code != ''">
                and a.regionCode like concat("%",#{code},"%")
            </if>
            and a.isRegister != '0'
        </trim>
    </select>


    <select id="selectByEpc" resultType="com.nantian.cloud.jly.entity.Memorandum">
        SELECT * FROM memorandum WHERE epc=#{memorandum.epc}
    </select>

</mapper>
