<?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.system.mapper.CommunityAssetsMapper">
    
    <resultMap type="CommunityAssets" id="CommunityAssetsResult">
        <result property="assetId"    column="asset_id"    />
        <result property="ssetType"    column="sset_type"    />
        <result property="equipmentName"    column="equipment_name"    />
        <result property="equipmentCoverPhoto"    column="equipment_cover_photo"    />
        <result property="equipmentNumber"    column="equipment_number"    />
        <result property="equipmentQrCode"    column="equipment_qr_code"    />
        <result property="equipmentStatus"    column="equipment_status"    />
        <result property="equipmentModel"    column="equipment_model"    />
        <result property="purchaseDate"    column="purchase_date"    />
        <result property="equipmentPurpose"    column="equipment_purpose"    />
        <result property="equipmentLocation"    column="equipment_location"    />
        <result property="equipmentPrice"    column="equipment_price"    />
        <result property="storageTime"    column="storage_time"    />
        <result property="storagePerson"    column="storage_person"    />
        <result property="outboundTime"    column="outbound_time"    />
        <result property="outboundPerson"    column="outbound_person"    />
        <result property="plateNumber"    column="plate_number"    />
        <result property="equipmentPhotos"    column="equipment_photos"    />
        <result property="maintenanceDate"    column="maintenance_date"    />
        <result property="maintenancePerson"    column="maintenance_person"    />
        <result property="warrantyPeriod"    column="warranty_period"    />
        <result property="depreciationRate"    column="depreciation_rate"    />
        <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="selectCommunityAssetsVo">
        select asset_id, sset_type, equipment_name, equipment_cover_photo, equipment_number, equipment_qr_code, equipment_status, equipment_model, purchase_date, equipment_purpose, equipment_location, equipment_price, storage_time, storage_person, outbound_time, outbound_person, plate_number, equipment_photos, maintenance_date, maintenance_person, warranty_period, depreciation_rate, create_by, create_time, update_by, update_time, remark from community_assets
    </sql>

    <select id="selectCommunityAssetsList" parameterType="CommunityAssets" resultMap="CommunityAssetsResult">
        <include refid="selectCommunityAssetsVo"/>
        <where>  
            <if test="ssetType != null  and ssetType != ''"> and sset_type = #{ssetType}</if>
            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
            <if test="equipmentCoverPhoto != null  and equipmentCoverPhoto != ''"> and equipment_cover_photo = #{equipmentCoverPhoto}</if>
            <if test="equipmentNumber != null  and equipmentNumber != ''"> and equipment_number = #{equipmentNumber}</if>
            <if test="equipmentQrCode != null  and equipmentQrCode != ''"> and equipment_qr_code = #{equipmentQrCode}</if>
            <if test="equipmentStatus != null  and equipmentStatus != ''"> and equipment_status = #{equipmentStatus}</if>
            <if test="equipmentModel != null  and equipmentModel != ''"> and equipment_model = #{equipmentModel}</if>
            <if test="purchaseDate != null "> and purchase_date = #{purchaseDate}</if>
            <if test="equipmentPurpose != null  and equipmentPurpose != ''"> and equipment_purpose = #{equipmentPurpose}</if>
            <if test="equipmentLocation != null  and equipmentLocation != ''"> and equipment_location = #{equipmentLocation}</if>
            <if test="equipmentPrice != null "> and equipment_price = #{equipmentPrice}</if>
            <if test="storageTime != null "> and storage_time = #{storageTime}</if>
            <if test="storagePerson != null  and storagePerson != ''"> and storage_person = #{storagePerson}</if>
            <if test="outboundTime != null "> and outbound_time = #{outboundTime}</if>
            <if test="outboundPerson != null  and outboundPerson != ''"> and outbound_person = #{outboundPerson}</if>
            <if test="plateNumber != null  and plateNumber != ''"> and plate_number = #{plateNumber}</if>
            <if test="equipmentPhotos != null  and equipmentPhotos != ''"> and equipment_photos = #{equipmentPhotos}</if>
            <if test="maintenanceDate != null "> and maintenance_date = #{maintenanceDate}</if>
            <if test="maintenancePerson != null  and maintenancePerson != ''"> and maintenance_person = #{maintenancePerson}</if>
            <if test="warrantyPeriod != null  and warrantyPeriod != ''"> and warranty_period = #{warrantyPeriod}</if>
            <if test="depreciationRate != null "> and depreciation_rate = #{depreciationRate}</if>
        </where>
    </select>
    
    <select id="selectCommunityAssetsByAssetId" parameterType="Long" resultMap="CommunityAssetsResult">
        <include refid="selectCommunityAssetsVo"/>
        where asset_id = #{assetId}
    </select>

    <insert id="insertCommunityAssets" parameterType="CommunityAssets" useGeneratedKeys="true" keyProperty="assetId">
        insert into community_assets
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ssetType != null and ssetType != ''">sset_type,</if>
            <if test="equipmentName != null and equipmentName != ''">equipment_name,</if>
            <if test="equipmentCoverPhoto != null">equipment_cover_photo,</if>
            <if test="equipmentNumber != null">equipment_number,</if>
            <if test="equipmentQrCode != null">equipment_qr_code,</if>
            <if test="equipmentStatus != null and equipmentStatus != ''">equipment_status,</if>
            <if test="equipmentModel != null">equipment_model,</if>
            <if test="purchaseDate != null">purchase_date,</if>
            <if test="equipmentPurpose != null">equipment_purpose,</if>
            <if test="equipmentLocation != null">equipment_location,</if>
            <if test="equipmentPrice != null">equipment_price,</if>
            <if test="storageTime != null">storage_time,</if>
            <if test="storagePerson != null">storage_person,</if>
            <if test="outboundTime != null">outbound_time,</if>
            <if test="outboundPerson != null">outbound_person,</if>
            <if test="plateNumber != null">plate_number,</if>
            <if test="equipmentPhotos != null">equipment_photos,</if>
            <if test="maintenanceDate != null">maintenance_date,</if>
            <if test="maintenancePerson != null">maintenance_person,</if>
            <if test="warrantyPeriod != null">warranty_period,</if>
            <if test="depreciationRate != null">depreciation_rate,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ssetType != null and ssetType != ''">#{ssetType},</if>
            <if test="equipmentName != null and equipmentName != ''">#{equipmentName},</if>
            <if test="equipmentCoverPhoto != null">#{equipmentCoverPhoto},</if>
            <if test="equipmentNumber != null">#{equipmentNumber},</if>
            <if test="equipmentQrCode != null">#{equipmentQrCode},</if>
            <if test="equipmentStatus != null and equipmentStatus != ''">#{equipmentStatus},</if>
            <if test="equipmentModel != null">#{equipmentModel},</if>
            <if test="purchaseDate != null">#{purchaseDate},</if>
            <if test="equipmentPurpose != null">#{equipmentPurpose},</if>
            <if test="equipmentLocation != null">#{equipmentLocation},</if>
            <if test="equipmentPrice != null">#{equipmentPrice},</if>
            <if test="storageTime != null">#{storageTime},</if>
            <if test="storagePerson != null">#{storagePerson},</if>
            <if test="outboundTime != null">#{outboundTime},</if>
            <if test="outboundPerson != null">#{outboundPerson},</if>
            <if test="plateNumber != null">#{plateNumber},</if>
            <if test="equipmentPhotos != null">#{equipmentPhotos},</if>
            <if test="maintenanceDate != null">#{maintenanceDate},</if>
            <if test="maintenancePerson != null">#{maintenancePerson},</if>
            <if test="warrantyPeriod != null">#{warrantyPeriod},</if>
            <if test="depreciationRate != null">#{depreciationRate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCommunityAssets" parameterType="CommunityAssets">
        update community_assets
        <trim prefix="SET" suffixOverrides=",">
            <if test="ssetType != null and ssetType != ''">sset_type = #{ssetType},</if>
            <if test="equipmentName != null and equipmentName != ''">equipment_name = #{equipmentName},</if>
            <if test="equipmentCoverPhoto != null">equipment_cover_photo = #{equipmentCoverPhoto},</if>
            <if test="equipmentNumber != null">equipment_number = #{equipmentNumber},</if>
            <if test="equipmentQrCode != null">equipment_qr_code = #{equipmentQrCode},</if>
            <if test="equipmentStatus != null and equipmentStatus != ''">equipment_status = #{equipmentStatus},</if>
            <if test="equipmentModel != null">equipment_model = #{equipmentModel},</if>
            <if test="purchaseDate != null">purchase_date = #{purchaseDate},</if>
            <if test="equipmentPurpose != null">equipment_purpose = #{equipmentPurpose},</if>
            <if test="equipmentLocation != null">equipment_location = #{equipmentLocation},</if>
            <if test="equipmentPrice != null">equipment_price = #{equipmentPrice},</if>
            <if test="storageTime != null">storage_time = #{storageTime},</if>
            <if test="storagePerson != null">storage_person = #{storagePerson},</if>
            <if test="outboundTime != null">outbound_time = #{outboundTime},</if>
            <if test="outboundPerson != null">outbound_person = #{outboundPerson},</if>
            <if test="plateNumber != null">plate_number = #{plateNumber},</if>
            <if test="equipmentPhotos != null">equipment_photos = #{equipmentPhotos},</if>
            <if test="maintenanceDate != null">maintenance_date = #{maintenanceDate},</if>
            <if test="maintenancePerson != null">maintenance_person = #{maintenancePerson},</if>
            <if test="warrantyPeriod != null">warranty_period = #{warrantyPeriod},</if>
            <if test="depreciationRate != null">depreciation_rate = #{depreciationRate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where asset_id = #{assetId}
    </update>

    <delete id="deleteCommunityAssetsByAssetId" parameterType="Long">
        delete from community_assets where asset_id = #{assetId}
    </delete>

    <delete id="deleteCommunityAssetsByAssetIds" parameterType="String">
        delete from community_assets where asset_id in 
        <foreach item="assetId" collection="array" open="(" separator="," close=")">
            #{assetId}
        </foreach>
    </delete>
</mapper>