<?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.muyu.system.mapper.SysFirmMapper">

    <resultMap type="com.muyu.system.domain.SysFirm" id="SysFirmResult">
        <result property="id"    column="id"    />
        <result property="firmCreditCode"    column="firm_credit_code"    />
        <result property="firmCode"    column="firm_code"    />
        <result property="firmName"    column="firm_name"    />
        <result property="firmLogs"    column="firm_logs"    />
        <result property="state"    column="state"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysFirmVo">
        select id, firm_credit_code, firm_code, firm_name, firm_logs , state, create_by, create_time, update_by, update_time, remark from sys_firm
    </sql>

    <select id="selectSysFirmList" parameterType="com.muyu.system.domain.SysFirm" resultMap="SysFirmResult">
        <include refid="selectSysFirmVo"/>
        <where>
            <if test="firmName != null  and firmName != ''"> and firm_name like concat('%', #{firmName}, '%')</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
        </where>
    </select>

    <select id="selectSysFirmById" parameterType="Long" resultMap="SysFirmResult">
        <include refid="selectSysFirmVo"/>
        where id = #{id}
    </select>


    <insert id="insertSysFirm" parameterType="com.muyu.system.domain.SysFirm" useGeneratedKeys="true" keyProperty="id">
        insert into sys_firm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="firmCreditCode != null and firmCreditCode != ''">firm_credit_code,</if>
            <if test="firmCode != null">firm_code,</if>
            <if test="firmName != null">firm_name,</if>
            <if test="firmLogs != null">firm_logs,</if>
            <if test="state != null">state,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="firmCreditCode != null and firmCreditCode != ''">#{firmCreditCode},</if>
            <if test="firmCode != null">#{firmCode},</if>
            <if test="firmName != null">#{firmName},</if>
            <if test="firmLogs != null">#{firmLogs},</if>
            <if test="state != null">#{state},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysFirm" parameterType="com.muyu.system.domain.SysFirm">
        update sys_firm
        <trim prefix="SET" suffixOverrides=",">
            <if test="firmCreditCode != null and firmCreditCode != ''">firm_credit_code = #{firmCreditCode},</if>
            <if test="firmCode != null">firm_code = #{firmCode},</if>
            <if test="firmName != null">firm_name = #{firmName},</if>
            <if test="firmLogs != null">firm_logs = #{firmLogs},</if>
            <if test="state != null">state = #{state},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysFirmById" parameterType="Long">
        delete from sys_firm where id = #{id}
    </delete>

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