<?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.ruoyi.system.mapper.grid.GridCompanyLawArchivesExtMapper">
  <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.grid.ext.GridCompanyLawArchivesExt">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="archives_no" jdbcType="VARCHAR" property="archivesNo" />
    <result column="archives_type" jdbcType="VARCHAR" property="archivesType" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="create_time" jdbcType="VARCHAR" property="createTime" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
    <result column="create_username" jdbcType="VARCHAR" property="createUsername" />
    <result column="is_valid" jdbcType="VARCHAR" property="isValid" />
    <result column="company_id" jdbcType="VARCHAR" property="companyId" />
    <result column="company_name" jdbcType="VARCHAR" property="companyName" />
    <result column="wg_code" jdbcType="VARCHAR" property="wgCode" />
    <result column="wg_name" jdbcType="VARCHAR" property="wgName" />
    <result column="qylx_code" jdbcType="VARCHAR" property="companyType" />
    <result column="qylx_name" jdbcType="VARCHAR" property="companyTypeName" />
    <result column="archives_type_name" jdbcType="VARCHAR" property="archivesTypeName" />
  </resultMap>
  <sql id="Base_Column_List">
    id, archives_no, archives_type, name, create_time, remark, create_user_id, create_username,
    is_valid, company_id
  </sql>
  <select id="selectByExample" parameterType="map" resultMap="BaseResultMap">
    select
      c1.*,
      c2.company_name,
      c2.qylx_code,
      c2.wg_code,
      bc.name as archives_type_name,
      bc2.name as qylx_name,
      bw.wg_name as wg_name
    from grid_company_law_archives c1
    left join grid_company c2 on c1.company_id = c2.id
    left join bs_common bc on bc.code = c1.archives_type
    left join bs_common bc2 on bc2.code = c2.qylx_code
    left join grid_region bw on bw.wg_code = c2.wg_code
    where 1=1
    <if test="archives.archivesNo != null and archives.archivesNo != ''">
      and c1.archives_no like CONCAT('%',#{archives.archivesNo,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.archivesType != null and archives.archivesType != ''">
      and c1.archives_type = #{archives.archivesType}
    </if>
    <if test="archives.companyId != null and archives.companyId != ''">
      and c1.company_id = #{archives.companyId}
    </if>
    <if test="archives.companyName != null and archives.companyName != ''">
      and c2.company_name like CONCAT('%',#{archives.companyName,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.name != null and archives.name != ''">
      and c2.name like CONCAT('%',#{archives.name,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.companyType != null and archives.companyType != ''">
      and c2.qylx_code = #{archives.companyType}
    </if>
    <if test="archives.startTime != null and archives.startTime !=''">
      and c1.create_time &gt;=#{archives.startTime}
    </if>
    <if test="archives.endTime != null and archives.endTime !=''">
      and c1.create_time &lt;=#{archives.endTime}
    </if>
    <if test="archives.createUserId != null and archives.createUserId != ''">
      and c1.create_user_id = #{archives.createUserId}
    </if>
    <if test="archives.name != null and archives.name != ''">
      and c2.name like CONCAT('%',#{archives.name,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.companyIds != null and archives.companyIds.size &gt; 0">
      and c1.company_id in
      <foreach close=")" collection="archives.companyIds" item="listItem" open="(" separator=",">
        #{listItem}
      </foreach>
    </if>
    <if test="archives.isValid != null and archives.isValid != ''">
      and c1.is_valid = #{archives.isValid}
    </if>
    order by c1.create_time desc
    <if test="archives.currIndex != null and archives.pageSize != null">
        limit #{archives.currIndex} , #{archives.pageSize}
    </if>
  </select>
  <select id="countByExample" parameterType="map" resultType="java.lang.Long">
    select
           count(*)
    from grid_company_law_archives c1
    left join grid_company c2 on c1.company_id = c2.id
    where 1=1
    <if test="archives.archivesNo != null and archives.archivesNo != ''">
      and c1.archives_no like CONCAT('%',#{archives.archivesNo,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.archivesType != null and archives.archivesType != ''">
      and c1.archives_type = #{archives.archivesType}
    </if>
    <if test="archives.companyId != null and archives.companyId != ''">
      and c1.company_id = #{archives.companyId}
    </if>
    <if test="archives.companyName != null and archives.companyName != ''">
      and c2.company_name like CONCAT('%',#{archives.companyName,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.name != null and archives.name != ''">
      and c2.name like CONCAT('%',#{archives.name,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.companyType != null and archives.companyType != ''">
      and c2.qylx_code = #{archives.companyType}
    </if>
    <if test="archives.startTime != null and archives.startTime !=''">
      and c1.create_time &gt;=#{archives.startTime}
    </if>
    <if test="archives.endTime != null and archives.endTime !=''">
      and c1.create_time &lt;=#{archives.endTime}
    </if>
    <if test="archives.createUserId != null and archives.createUserId != ''">
      and c1.create_user_id = #{archives.createUserId}
    </if>
    <if test="archives.name != null and archives.name != ''">
      and c2.name like CONCAT('%',#{archives.name,jdbcType=VARCHAR},'%')
    </if>
    <if test="archives.companyIds != null and archives.companyIds.size &gt; 0">
      and c1.company_id in
      <foreach close=")" collection="archives.companyIds" item="listItem" open="(" separator=",">
        #{listItem}
      </foreach>
    </if>
    <if test="archives.isValid != null and archives.isValid != ''">
      and c1.is_valid = #{archives.isValid}
    </if>
  </select>
</mapper>