<?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.jarvis.mapper.ErpOpenConfigMapper">

    <resultMap id="ErpOpenConfigResult" type="com.ruoyi.jarvis.domain.ErpOpenConfig">
        <id     property="id" column="id"/>
        <result property="appKey" column="app_key"/>
        <result property="appSecret" column="app_secret"/>
        <result property="xyUserName" column="xy_user_name"/>
        <result property="expressCode" column="express_code"/>
        <result property="expressName" column="express_name"/>
        <result property="status" column="status"/>
        <result property="orderNum" column="order_num"/>
        <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="selectVo">
        select id, app_key, app_secret, xy_user_name, express_code, express_name, status, order_num,
               create_by, create_time, update_by, update_time, remark
        from erp_open_config
    </sql>

    <select id="selectById" resultMap="ErpOpenConfigResult">
        <include refid="selectVo"/> where id = #{id}
    </select>

    <select id="selectByAppKey" resultMap="ErpOpenConfigResult">
        <include refid="selectVo"/> where app_key = #{appKey} limit 1
    </select>

    <select id="selectList" parameterType="com.ruoyi.jarvis.domain.ErpOpenConfig" resultMap="ErpOpenConfigResult">
        <include refid="selectVo"/>
        <where>
            <if test="appKey != null and appKey != ''">and app_key = #{appKey}</if>
            <if test="status != null and status != ''">and status = #{status}</if>
            <if test="xyUserName != null and xyUserName != ''">and xy_user_name like concat('%', #{xyUserName}, '%')</if>
        </where>
        order by order_num asc, id asc
    </select>

    <select id="selectEnabledOrderBySort" resultMap="ErpOpenConfigResult">
        <include refid="selectVo"/>
        where status = '0'
        order by order_num asc, id asc
    </select>

    <insert id="insert" parameterType="com.ruoyi.jarvis.domain.ErpOpenConfig" useGeneratedKeys="true" keyProperty="id">
        insert into erp_open_config
        (app_key, app_secret, xy_user_name, express_code, express_name, status, order_num, create_by, create_time, remark)
        values
        (#{appKey}, #{appSecret}, #{xyUserName}, #{expressCode}, #{expressName}, #{status}, #{orderNum}, #{createBy}, #{createTime}, #{remark})
    </insert>

    <update id="update" parameterType="com.ruoyi.jarvis.domain.ErpOpenConfig">
        update erp_open_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="appKey != null">app_key = #{appKey},</if>
            <if test="appSecret != null">app_secret = #{appSecret},</if>
            <if test="xyUserName != null">xy_user_name = #{xyUserName},</if>
            <if test="expressCode != null">express_code = #{expressCode},</if>
            <if test="expressName != null">express_name = #{expressName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="orderNum != null">order_num = #{orderNum},</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="deleteById">
        delete from erp_open_config where id = #{id}
    </delete>
</mapper>
