<?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.farming.mapper.BizTechResourceMapper">

    <resultMap type="com.ruoyi.web.modules.farming.domain.BizTechResource" id="BizTechResourceResult">
        <id     property="id"                    column="id"/>
        <result property="resourceType"          column="resource_type"/>
        <result property="resourceName"          column="resource_name"/>
        <result property="photoFileUrl"          column="photo_file_url"/>
        <result property="photoFilePath"         column="photo_file_path"/>
        <result property="coverFileUrl"          column="cover_file_url"/>
        <result property="coverFilePath"         column="cover_file_path"/>
        <result property="videoFileUrl"          column="video_file_url"/>
        <result property="videoFilePath"         column="video_file_path"/>
        <result property="introduction"          column="introduction"/>
        <result property="achievementSummary"    column="achievement_summary"/>
        <result property="keyTechPrinciple"      column="key_tech_principle"/>
        <result property="techAdvantage"         column="tech_advantage"/>
        <result property="researchDirection"     column="research_direction"/>
        <result property="completionUnit"        column="completion_unit"/>
        <result property="contactPhone"          column="contact_phone"/>
        <result property="affiliatedUnit"        column="affiliated_unit"/>
        <result property="detailAddress"         column="detail_address"/>
        <result property="serviceArea"           column="service_area"/>
        <result property="feeStandard"           column="fee_standard"/>
        <result property="expertRating"          column="expert_rating"/>
        <result property="borrowFee"             column="borrow_fee"/>
        <result property="serviceStartTime"      column="service_start_time"/>
        <result property="serviceEndTime"        column="service_end_time"/>
        <result property="serviceWeekdays"       column="service_weekdays"/>
        <result property="instrumentModel"       column="instrument_model"/>
        <result property="storageLocation"       column="storage_location"/>
        <result property="reservationProcess"    column="reservation_process"/>
        <result property="personInCharge"        column="person_in_charge"/>
        <result property="courseTopic"           column="course_topic"/>
        <result property="longitude"             column="longitude"/>
        <result property="latitude"              column="latitude"/>
        <result property="publishStatus"         column="publish_status"/>
        <result property="publishTime"           column="publish_time"/>
        <result property="offlineTime"           column="offline_time"/>
        <result property="accountAssigned"       column="account_assigned"/>
        <result property="sysUserId"             column="sys_user_id"/>
        <result property="assignedLoginName"     column="assigned_login_name"/>
        <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"/>
        <result property="remark"                column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id, resource_type, resource_name, photo_file_url, photo_file_path,
               cover_file_url, cover_file_path, video_file_url, video_file_path,
               introduction, achievement_summary, key_tech_principle, tech_advantage,
               research_direction, completion_unit, contact_phone, affiliated_unit,
               detail_address, service_area, fee_standard, expert_rating, borrow_fee,
               service_start_time, service_end_time, service_weekdays,
               instrument_model, storage_location, reservation_process, person_in_charge,
               course_topic, longitude, latitude,
               publish_status, publish_time, offline_time,
               account_assigned, sys_user_id, assigned_login_name, del_flag,
               create_by, create_time, update_by, update_time, remark
        from biz_tech_resource
    </sql>

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

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

    <select id="selectExpertResourceBySysUserId" resultMap="BizTechResourceResult">
        <include refid="selectVo"/>
        where sys_user_id = #{sysUserId}
          and resource_type = '004005'
          and account_assigned = 1
          and del_flag = '0'
        limit 1
    </select>

    <select id="countBySysUserId" resultType="int">
        select count(1)
        from biz_tech_resource
        where sys_user_id = #{sysUserId}
          and del_flag = '0'
    </select>

    <select id="selectBizTechResourceList" parameterType="com.ruoyi.web.modules.farming.domain.BizTechResource" resultMap="BizTechResourceResult">
        <include refid="selectVo"/>
        <where>
            del_flag = '0'
            <if test="resourceType != null">
                and resource_type = #{resourceType}
            </if>
            <if test="resourceName != null and resourceName != ''">
                and resource_name like concat('%', #{resourceName}, '%')
            </if>
            <if test="queryPublishStatus != null and queryPublishStatus == 0">
                and publish_status = 0 and offline_time is null
            </if>
            <if test="queryPublishStatus != null and queryPublishStatus == 1">
                and publish_status = 1
            </if>
            <if test="queryPublishStatus != null and queryPublishStatus == 2">
                and publish_status = 0 and offline_time is not null
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizTechResource" parameterType="com.ruoyi.web.modules.farming.domain.BizTechResource" useGeneratedKeys="true" keyProperty="id">
        insert into biz_tech_resource (
            resource_type, resource_name, photo_file_url, photo_file_path,
            cover_file_url, cover_file_path, video_file_url, video_file_path,
            introduction, achievement_summary, key_tech_principle, tech_advantage,
            research_direction, completion_unit, contact_phone, affiliated_unit,
            detail_address, service_area, fee_standard, expert_rating, borrow_fee,
            service_start_time, service_end_time, service_weekdays,
            instrument_model, storage_location, reservation_process, person_in_charge,
            course_topic, longitude, latitude,
            publish_status, publish_time, offline_time,
            account_assigned, sys_user_id, assigned_login_name, del_flag,
            create_by, create_time, remark
        ) values (
            #{resourceType}, #{resourceName}, #{photoFileUrl}, #{photoFilePath},
            #{coverFileUrl}, #{coverFilePath}, #{videoFileUrl}, #{videoFilePath},
            #{introduction}, #{achievementSummary}, #{keyTechPrinciple}, #{techAdvantage},
            #{researchDirection}, #{completionUnit}, #{contactPhone}, #{affiliatedUnit},
            #{detailAddress}, #{serviceArea}, #{feeStandard}, #{expertRating}, #{borrowFee},
            #{serviceStartTime}, #{serviceEndTime}, #{serviceWeekdays},
            #{instrumentModel}, #{storageLocation}, #{reservationProcess}, #{personInCharge},
            #{courseTopic}, #{longitude}, #{latitude},
            #{publishStatus}, #{publishTime}, #{offlineTime},
            #{accountAssigned}, #{sysUserId}, #{assignedLoginName}, #{delFlag},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizTechResource" parameterType="com.ruoyi.web.modules.farming.domain.BizTechResource">
        update biz_tech_resource set
            resource_name = #{resourceName},
            photo_file_url = #{photoFileUrl},
            photo_file_path = #{photoFilePath},
            cover_file_url = #{coverFileUrl},
            cover_file_path = #{coverFilePath},
            video_file_url = #{videoFileUrl},
            video_file_path = #{videoFilePath},
            introduction = #{introduction},
            achievement_summary = #{achievementSummary},
            key_tech_principle = #{keyTechPrinciple},
            tech_advantage = #{techAdvantage},
            research_direction = #{researchDirection},
            completion_unit = #{completionUnit},
            contact_phone = #{contactPhone},
            affiliated_unit = #{affiliatedUnit},
            detail_address = #{detailAddress},
            service_area = #{serviceArea},
            fee_standard = #{feeStandard},
            borrow_fee = #{borrowFee},
            service_start_time = #{serviceStartTime},
            service_end_time = #{serviceEndTime},
            service_weekdays = #{serviceWeekdays},
            instrument_model = #{instrumentModel},
            storage_location = #{storageLocation},
            reservation_process = #{reservationProcess},
            person_in_charge = #{personInCharge},
            course_topic = #{courseTopic},
            longitude = #{longitude},
            latitude = #{latitude},
            publish_status = #{publishStatus},
            publish_time = #{publishTime},
            offline_time = #{offlineTime},
            account_assigned = #{accountAssigned},
            sys_user_id = #{sysUserId},
            assigned_login_name = #{assignedLoginName},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id} and del_flag = '0'
    </update>

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

    <update id="updateExpertRating">
        update biz_tech_resource
        set expert_rating = #{expertRating},
            update_time = sysdate()
        where id = #{id}
          and del_flag = '0'
    </update>
</mapper>
