<?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.bonus.material.ma.mapper.PropInfoMapper">
    <resultMap type="com.bonus.material.ma.domain.PropInfo" id="PropInfoResult">
        <result property="propId"    column="prop_id"    />
        <result property="propName"    column="prop_name"    />
        <result property="code"    column="code"    />
        <result property="status"    column="status"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectPropInfoVo">
        select prop_id, prop_name, code, status, dept_id, del_flag, create_by, update_by, create_time, update_time, remark, company_id from ma_prop_info
    </sql>

    <select id="selectPropInfoList" parameterType="com.bonus.material.ma.domain.PropInfo" resultMap="PropInfoResult">
        <include refid="selectPropInfoVo"/>
        <where>  
            <if test="propName != null  and propName != ''"> and prop_name like concat('%', #{propName}, '%')</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="deptId != null  and deptId != ''"> and dept_id = #{deptId}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectPropInfoByPropId" parameterType="Long" resultMap="PropInfoResult">
        <include refid="selectPropInfoVo"/>
        where prop_id = #{propId}
    </select>
        
    <insert id="insertPropInfo" parameterType="com.bonus.material.ma.domain.PropInfo" useGeneratedKeys="true" keyProperty="propId">
        insert into ma_prop_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="propName != null and propName != ''">prop_name,</if>
            <if test="code != null">code,</if>
            <if test="status != null">status,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="propName != null and propName != ''">#{propName},</if>
            <if test="code != null">#{code},</if>
            <if test="status != null">#{status},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updatePropInfo" parameterType="com.bonus.material.ma.domain.PropInfo">
        update ma_prop_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="propName != null and propName != ''">prop_name = #{propName},</if>
            <if test="code != null">code = #{code},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where prop_id = #{propId}
    </update>

    <delete id="deletePropInfoByPropId" parameterType="Long">
        delete from ma_prop_info where prop_id = #{propId}
    </delete>

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