<?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="cn.cecep.talroad.mapper.FactoryReportingRemindersMapper">

    <sql id="selectFactoryReportingRemindersVo">
        select
            t1.fe_id,
            t1.factory_id as "factoryId",
            t1.submit_status as "submitStatus",
            t1.reminders_status as "remindersStatus",
            t1.submit_time as "submitTime",
            t2.factory_name as "factoryName",
            t2.country_code as "regionCode",
            t2.country_name as "regionName",
            t2.industry_category as "industryCategory",
            t2.industry_permission_name as "industryPermissionName"
        from factory_reporting_reminders t1
        left join pc_factory t2 on t1.factory_id = t2.id
    </sql>

    <select id="factoryReportingRemindersList" resultType="cn.cecep.talroad.vo.FactoryReportingRemindersVo">
        <include refid="selectFactoryReportingRemindersVo"/>
        <where>
            <if test="query.factoryId != null  and query.factoryId != ''"> and t1.factory_id = #{query.factoryId}</if>
            <if test="query.factoryName != null  and query.factoryName != ''"> AND t2.factory_name LIKE CONCAT('%', #{query.factoryName}, '%')</if>
            <if test="query.industryCategory != null  and query.industryCategory != ''"> and t2.industry_category = #{query.industryCategory}</if>
            <if test="query.industryPermissionName != null  and query.industryPermissionName != ''"> and t2.industry_permission_name like concat('%', #{query.industryPermissionName}, '%')</if>
            <if test="query.regionCode != null  and query.regionCode != ''"> and t2.country_code = #{query.regionCode}</if>
            <if test="query.submitStatus != null  and query.submitStatus != ''"> and t1.submit_status = #{query.submitStatus}</if>
            <if test="query.submitTimeStart != null and query.submitTimeStart != ''">
                and t1.submit_time >= to_timestamp(#{query.submitTimeStart}, 'yyyy-mm-dd hh24:MI:SS')
            </if>
            <if test="query.submitTimeEnd != null and query.submitTimeEnd != ''">
                and t1.submit_time &lt;= to_timestamp(#{query.submitTimeEnd}, 'yyyy-mm-dd hh24:MI:SS')
            </if>
        </where>
        ORDER BY t1.submit_time desc nulls last, t1.factory_id
    </select>

    <update id="updateReminder">
        update factory_reporting_reminders set submit_status='1',submit_time=#{factfactoryReportingReminders.submitTime},submit_user=#{factfactoryReportingReminders.submitUser} where factory_id=#{factfactoryReportingReminders.factoryId}
    </update>
</mapper>
