<?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.com.energy.mapper.DvMachineryMapper">
    
    <resultMap type="DvMachinery" id="DvMachineryResult">
        <result property="machineryId"    column="machinery_id"    />
        <result property="machineryCode"    column="machinery_code"    />
        <result property="machineryName"    column="machinery_name"    />
        <result property="machineryBrand"    column="machinery_brand"    />
        <result property="machinerySpec"    column="machinery_spec"    />
        <result property="machineryTypeId"    column="machinery_type_id"    />
        <result property="machineryTypeCode"    column="machinery_type_code"    />
        <result property="machineryTypeName"    column="machinery_type_name"    />
        <result property="workshopId"    column="workshop_id"    />
        <result property="workshopCode"    column="workshop_code"    />
        <result property="workshopName"    column="workshop_name"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="attr1"    column="attr1"    />
        <result property="attr2"    column="attr2"    />
        <result property="attr3"    column="attr3"    />
        <result property="attr4"    column="attr4"    />
        <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="selectDvMachineryVo">
        select dm.machinery_id, dm.machinery_code, machinery_name, machinery_brand, machinery_spec, machinery_type_id, machinery_type_code, machinery_type_name, workshop_id, workshop_code, workshop_name, status, dm.remark, attr1, attr2, attr3, attr4
        from dv_machinery dm inner join dv_machinery_param dmp on dm.machinery_id = dmp.machinery_id
    </sql>

    <select id="selectDvMachineryList" parameterType="DvMachinery" resultMap="DvMachineryResult">
        <include refid="selectDvMachineryVo"/>
        <where>
            <if test="machineryCode != null  and machineryCode != ''"> and machinery_code = #{machineryCode}</if>
            <if test="machineryName != null  and machineryName != ''"> and machinery_name like concat('%', #{machineryName}, '%')</if>
            <if test="machineryBrand != null  and machineryBrand != ''"> and machinery_brand = #{machineryBrand}</if>
            <if test="machinerySpec != null  and machinerySpec != ''"> and machinery_spec = #{machinerySpec}</if>
            <if test="machineryTypeId != null ">
                AND (machinery_type_id = #{machineryTypeId} OR machinery_type_id in (select machinery_type_id from dv_machinery_type where find_in_set(#{machineryTypeId},ancestors)))
            </if>
            <if test="machineryTypeCode != null  and machineryTypeCode != ''"> and machinery_type_code = #{machineryTypeCode}</if>
            <if test="machineryTypeName != null  and machineryTypeName != ''"> and machinery_type_name like concat('%', #{machineryTypeName}, '%')</if>
            <if test="workshopId != null "> and workshop_id = #{workshopId}</if>
            <if test="workshopCode != null  and workshopCode != ''"> and workshop_code = #{workshopCode}</if>
            <if test="workshopName != null  and workshopName != ''"> and workshop_name like concat('%', #{workshopName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

</mapper>