<?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.web.modules.circulation.mapper.BizQuarantineStationMapper">

    <resultMap type="com.ruoyi.web.modules.circulation.domain.BizQuarantineStation" id="BizQuarantineStationResult">
        <id     property="id"              column="id"/>
        <result property="stationName"     column="station_name"/>
        <result property="detailAddress"   column="detail_address"/>
        <result property="personInCharge"  column="person_in_charge"/>
        <result property="contactPhone"    column="contact_phone"/>
        <result property="operateStatus"   column="operate_status"/>
        <result property="photoFileUrl"    column="photo_file_url"/>
        <result property="photoFilePath"   column="photo_file_path"/>
        <result property="delFlag"         column="del_flag"/>
        <result property="createBy"        column="create_by"/>
        <result property="createTime"      column="create_time"/>
        <result property="updateBy"        column="update_by"/>
        <result property="updateTime"      column="update_time"/>
    </resultMap>

    <sql id="selectVo">
        select id, station_name, detail_address, person_in_charge, contact_phone, operate_status,
               photo_file_url, photo_file_path, del_flag,
               create_by, create_time, update_by, update_time
        from biz_quarantine_station
    </sql>

    <select id="selectBizQuarantineStationById" parameterType="long" resultMap="BizQuarantineStationResult">
        <include refid="selectVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectBizQuarantineStationByIdAny" parameterType="long" resultMap="BizQuarantineStationResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectBizQuarantineStationByExactName" resultMap="BizQuarantineStationResult">
        <include refid="selectVo"/>
        where del_flag = '0' and station_name = #{stationName}
        limit 1
    </select>

    <select id="countBizQuarantineStationByNameExcludeId" resultType="int">
        select count(1) from biz_quarantine_station
        where del_flag = '0' and station_name = #{stationName}
        <if test="excludeId != null">
            and id != #{excludeId}
        </if>
    </select>

    <select id="selectBizQuarantineStationList" parameterType="com.ruoyi.web.modules.circulation.domain.BizQuarantineStation" resultMap="BizQuarantineStationResult">
        <include refid="selectVo"/>
        <where>
            del_flag = '0'
            <if test="stationName != null and stationName != ''">
                and station_name like concat('%', #{stationName}, '%')
            </if>
            <if test="operateStatus != null">
                and operate_status = #{operateStatus}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizQuarantineStation" parameterType="com.ruoyi.web.modules.circulation.domain.BizQuarantineStation" useGeneratedKeys="true" keyProperty="id">
        insert into biz_quarantine_station (
            station_name, detail_address, person_in_charge, contact_phone, operate_status,
            photo_file_url, photo_file_path, del_flag,
            create_by, create_time
        ) values (
            #{stationName}, #{detailAddress}, #{personInCharge}, #{contactPhone}, #{operateStatus},
            #{photoFileUrl}, #{photoFilePath}, #{delFlag},
            #{createBy}, sysdate()
        )
    </insert>

    <update id="updateBizQuarantineStation" parameterType="com.ruoyi.web.modules.circulation.domain.BizQuarantineStation">
        update biz_quarantine_station set
            station_name = #{stationName},
            detail_address = #{detailAddress},
            person_in_charge = #{personInCharge},
            contact_phone = #{contactPhone},
            operate_status = #{operateStatus},
            photo_file_url = #{photoFileUrl},
            photo_file_path = #{photoFilePath},
            update_by = #{updateBy},
            update_time = sysdate()
        where id = #{id} and del_flag = '0'
    </update>

    <update id="logicDeleteBizQuarantineStationByIds">
        update biz_quarantine_station set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
        where del_flag = '0' and id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="countForScreenByOperateStatus" resultType="int">
        select count(1) from biz_quarantine_station
        where del_flag = '0' and operate_status = #{operateStatus}
    </select>

    <select id="countForScreenDisabled" resultType="int">
        select count(1) from biz_quarantine_station
        where del_flag = '0' and operate_status in (2, 3)
    </select>
</mapper>
