<?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.sgzb.base.mapper.MaPropInfoMapper">

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


    <insert id="insertProp" parameterType="com.bonus.sgzb.base.mapper.MaPropInfoMapper" useGeneratedKeys="true" keyProperty="propId">
        insert into ma_prop_info(
        <if test="propId != null and propId != 0">prop_id,</if>
        <if test="paName != null and paName != ''">prop_name,</if>
        <if test="status != null and status != 0">status,</if>
        <if test="deptId != null and deptId != ''">dept_id,</if>
        <if test="delFlag != null and delFlag != 0">del_flag,</if>
        <if test="createBy != null and createBy != ''">create_by,</if>
        <if test="remark != null and remark != ''">remark,</if>
        <if test="companyId != null and companyId != ''">company_id,</if>
        create_time
        )values(
        <if test="propId != null and propId != 0">#{propId},</if>
        <if test="paName != null and paName != ''">#{paName},</if>
        <if test="status != null and status != 0">#{status},</if>
        <if test="deptId != null and deptId != ''">#{deptId},</if>
        <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
        <if test="createBy != null and createBy != ''">#{createBy},</if>
        <if test="remark != null and remark != ''">#{remark},</if>
        <if test="companyId != null and companyId != ''">#{companyId},</if>
        sysdate()
        )
    </insert>

    <update id="updateMaProp">
        update ma_prop_info
        <set>
            <if test="propName != null and propName != ''">prop_name = #{propName},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="companyId != null and companyId != ''">company_id = #{companyId},</if>
            update_time = sysdate()
        </set>
        where prop_id = #{propId}
    </update>

    <delete id="deleteMaProp">
        update ma_prop_info set del_flag = '2' where prop_id = #{propId}
    </delete>

    <select id="selectMaPropSet" resultType="com.bonus.sgzb.base.domain.MaPropInfo">
        <include refid="selectMaPropInfoVo"/>
        <where>
            <if test="propName != null and propName != ''">
                AND prop_name like concat('%', #{propName}, '%')
            </if>
        </where>
    </select>

    <select id="checkPropNameUnique" resultType="com.bonus.sgzb.base.domain.MaPropInfo">
        <include refid="selectMaPropInfoVo"/>
        where prop_name = #{propName} limit 1
    </select>

</mapper>