<?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.eleadmin.oa.mapper.AssetsDataMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
        b.assets_code,
        b.assets_name
        FROM sys_assets_data a
        LEFT JOIN sys_assets b ON a.assets_id = b.assets_id
        <where>
            AND a.deleted = 0
            <if test="param.assetsDataId != null">
                AND a.assets_data_id = #{param.assetsDataId}
            </if>
            <if test="param.assetsId != null">
                AND a.assets_id = #{param.assetsId}
            </if>
            <if test="param.assetsDataCode != null">
                AND a.assets_data_code LIKE CONCAT('%', #{param.assetsDataCode}, '%')
            </if>
            <if test="param.assetsDataName != null">
                AND a.assets_data_name LIKE CONCAT('%', #{param.assetsDataName}, '%')
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.assetsCode != null">
                AND b.assets_code = #{param.assetsCode}
            </if>
            <if test="param.assetsName != null">
                AND b.assets_name = #{param.assetsName}
            </if>
            <if test="param.keywords != null">
                AND (
                a.assets_data_code LIKE CONCAT('%', #{param.keywords}, '%')
                OR a.assets_data_name LIKE CONCAT('%', #{param.keywords}, '%')
                )
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.eleadmin.oa.entity.AssetsData">
        <include refid="selectSql"/>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.eleadmin.oa.entity.AssetsData">
        <include refid="selectSql"/>
    </select>

    <!-- 根据assetsCode和assetsDataName查询 -->
    <select id="getByAssetsCodeAndName" resultType="com.eleadmin.oa.entity.AssetsData">
        SELECT a.*,
               b.assets_code,
               b.assets_name
        FROM sys_assets_data a
                 LEFT JOIN sys_assets b ON a.assets_id = b.assets_id
        WHERE a.assets_data_name = #{assetsDataName}
          AND b.assets_code = #{assetsCode}
    </select>

</mapper>
