<?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.NdCompanyQualityManageMapper">

    <select id="qualityManageList"
            parameterType="com.ningdatech.carapi.company.entity.po.CompanyQualityPO"
            resultType="com.ningdatech.carapi.company.entity.dto.ResQualityManageDTO">
        SELECT ncqm.file_time AS fileTime,
        ncqm.file_path AS filePath,
        ncqm.download_count AS downloadCount,
        ncqm.id AS id,
        ncqm.region_name AS regionName,
        ncqm.file_name AS fileName
        FROM nd_company_quality_manage ncqm
        left join nd_company_info c on ncqm.company_id = c.id
        left join nd_region r on ncqm.region_id = r.id
        <where>
            1 = 1
            <if test="po.year != null and po.year != ''">
                AND ncqm.file_time <![CDATA[ >= ]]> #{po.year}
            </if>

            <if test="po.regionIds != null and po.regionIds.size > 0">
                AND ncqm.region_id in
                <foreach collection="po.regionIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        ${po.dataScopeSql} or ncqm.region_id = 116
        ORDER BY ncqm.id DESC
    </select>
    <select id="qualityAllManageList" resultType="com.ningdatech.carapi.company.entity.dto.ResQualityManageDTO">
        SELECT ncqm.file_time AS fileTime,
        ncqm.file_path AS filePath,
        ncqm.download_count AS downloadCount,
        ncqm.id AS id,
        ncqm.region_name AS regionName,
        ncqm.file_name AS fileName
        FROM nd_company_quality_manage ncqm
        left join nd_company_info c on ncqm.company_id = c.id
        left join nd_region r on ncqm.region_id = r.id
        <where>
            1 = 1
            <if test="po.year != null and po.year != ''">
                AND ncqm.file_time <![CDATA[ >= ]]> #{po.year}
            </if>

            <if test="po.regionIds != null and po.regionIds.size > 0">
                AND ncqm.region_id in
                <foreach collection="po.regionIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        ${po.dataScopeSql}
        ORDER BY ncqm.id DESC
    </select>

    <update id="incrementDownCount">
        update nd_company_quality_manage set download_count = download_count + 1 where id = #{id}
    </update>
</mapper>
