<?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.SysUnitConvertMapper">
    
    <resultMap type="SysUnitConvert" id="SysUnitConvertResult">
        <result property="id" column="id" />
        <result property="unitType" column="unit_type" />
        <result property="unitName" column="unit_name" />
        <result property="baseUnit" column="base_unit" />
        <result property="conversionFactor" column="conversion_factor" />
        <result property="unitTypeName" column="unit_type_name" />
        <result property="status" column="status" />
        <result property="unitOrder" column="unit_order" />
    </resultMap>

    <sql id="selectSysUnitConvertVo">
        select 
            suc.id,
            suc.unit_type,
            suc.unit_name,
            suc.base_unit,
            suc.conversion_factor,
            suc.unit_type_name,
            suc.status,
            suc.unit_order
        from sys_unit_convert suc
    </sql>

    <select id="selectSysUnitConvertList" parameterType="SysUnitConvert" resultMap="SysUnitConvertResult">
        <include refid="selectSysUnitConvertVo"/>
        <where>
            <if test="unitType != null  and unitType != ''"> and suc.unit_type = #{unitType}</if>
            <if test="unitName != null  and unitName != ''"> and suc.unit_name like concat('%', #{unitName}, '%')</if>
            <if test="baseUnit != null  and baseUnit != ''"> and suc.base_unit = #{baseUnit}</if>
            <if test="conversionFactor != null "> and suc.conversion_factor = #{conversionFactor}</if>
            <if test="unitTypeName != null  and unitTypeName != ''"> and suc.unit_type_name like concat('%', #{unitTypeName}, '%')</if>
            <if test="status != null  and status != ''"> and suc.status = #{status}</if>
            <if test="unitOrder != null "> and suc.unit_order = #{unitOrder}</if>
        </where>
    </select>
    
    <select id="selectSysUnitConvertById" parameterType="Long" resultMap="SysUnitConvertResult">
        <include refid="selectSysUnitConvertVo"/>
        where suc.id = #{id}
    </select>
        
    <insert id="insertSysUnitConvert" parameterType="SysUnitConvert" useGeneratedKeys="true" keyProperty="id">
        insert into sys_unit_convert
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitType != null and unitType != ''">unit_type,</if>
            <if test="unitName != null and unitName != ''">unit_name,</if>
            <if test="baseUnit != null">base_unit,</if>
            <if test="conversionFactor != null">conversion_factor,</if>
            <if test="unitTypeName != null and unitTypeName != ''">unit_type_name,</if>
            <if test="status != null">status,</if>
            <if test="unitOrder != null">unit_order,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="unitType != null and unitType != ''">#{unitType},</if>
            <if test="unitName != null and unitName != ''">#{unitName},</if>
            <if test="baseUnit != null">#{baseUnit},</if>
            <if test="conversionFactor != null">#{conversionFactor},</if>
            <if test="unitTypeName != null and unitTypeName != ''">#{unitTypeName},</if>
            <if test="status != null">#{status},</if>
            <if test="unitOrder != null">#{unitOrder},</if>
         </trim>
    </insert>

    <select id="selectSysUnitConvertUnitByTypeOrder"
            resultMap="SysUnitConvertResult">
        <!-- 这里编写具体的 SQL 查询语句 -->
        <include refid="selectSysUnitConvertVo"/>
        <where>
            <if test="unitType != null  and unitType != ''">and unit_type = #{unitType}</if>
            <if test="unitOrder != null ">and unit_order = #{unitOrder}</if>
            <if test="baseUnit != null  and baseUnit != ''">and base_unit = #{baseUnit}</if>

        </where>
    </select>

    <update id="updateSysUnitConvert" parameterType="SysUnitConvert">
        update sys_unit_convert
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitType != null and unitType != ''">unit_type = #{unitType},</if>
            <if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
            <if test="baseUnit != null">base_unit = #{baseUnit},</if>
            <if test="conversionFactor != null">conversion_factor = #{conversionFactor},</if>
            <if test="unitTypeName != null and unitTypeName != ''">unit_type_name = #{unitTypeName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="unitOrder != null">unit_order = #{unitOrder},</if>
        </trim>
        where sys_unit_convert.id = #{id}
    </update>

    <delete id="deleteSysUnitConvertById" parameterType="Long">
        delete from sys_unit_convert where id = #{id}
    </delete>

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