<?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.ningdatech.carapi.company.mapper.NdCompanySecurityProductDutyMapper">

    <select id="securityProductDutyList"
            resultType="com.ningdatech.carapi.company.entity.dto.ResSecurityProductDutyDTO">
        SELECT
            ncspd.file_path AS filePath,
            ncspd.file_type As fileType,
            ncspd.create_on AS createOn,
            ncspd.region_id as regionId,
            r.name AS regionName,
            ncspd.company_id as companyId,
            c.name AS companyName
            FROM nd_company_security_product_duty ncspd
            left join nd_company_info c on ncspd.company_id = c.id
            left join nd_region r on ncspd.region_id = r.id
        <where>
            1 = 1
            AND ncspd.file_type = #{po.fileType}
            <if test="po.startTime != null and po.startTime != ''">
                AND ncspd.create_on <![CDATA[ >= ]]> #{po.startTime}
            </if>

            <if test="po.endTime != null and po.endTime != ''">
                AND ncspd.create_on <![CDATA[ <= ]]> #{po.endTime}
            </if>

            <if test="po.regionIds != null and po.regionIds.size > 0">
                AND ncspd.region_id in
                <foreach collection="po.regionIds" item="item" open="(" close= ")" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="po.companyName != null and po.companyName != ''">
                AND ncspd.company_name LIKE CONCAT(CONCAT('%',
                #{po.companyName}),'%')
            </if>
        </where>
        ${po.dataScopeSql}
        ORDER BY ncspd.id DESC
    </select>
</mapper>
