<?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.saye.hospitalgd.mapper.system.ServiceParamsMapper">
    <resultMap id="BaseResultMap" type="com.saye.hospitalgd.model.ServiceParams">
        <id column="param_id" property="paramId" jdbcType="VARCHAR"/>
        <result column="param_name" property="paramName" jdbcType="VARCHAR"/>
        <result column="param_code" property="paramCode" jdbcType="VARCHAR"/>
        <result column="param_val" property="paramVal" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="VARCHAR"/>
        <result column="modify_time" property="modifyTime" jdbcType="VARCHAR"/>
        <result column="modify_user_name" property="modifyUserName" jdbcType="VARCHAR"/>
        <result column="modify_true_name" property="modifyTrueName" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="selectServiceParams" resultMap="BaseResultMap">
        select param_id,param_name,param_code,param_val,create_time,modify_time,modify_user_name,modify_true_name
        from service_params
        <where>
            1=1
            <if test="paramCode!=null and paramCode!=''">
                and param_code =#{paramCode}
            </if>
            <if test="paramName!=null and paramName!=''">
                and param_name like concat('%',concat(#{paramName},'%'))
            </if>
        </where>
        order by create_time desc
    </select>

    <insert id="insertServiceParams">
        insert into service_params(param_name, param_code, param_val, modify_user_name, modify_true_name)
        values (#{paramName}, #{paramCode}, #{paramVal}, #{modifyUserName}, #{modifyTrueName})
    </insert>

    <update id="updateServiceParams">
        update service_params
        <set>
            <if test="paramName!=null and paramName!=''">
                param_name =#{paramName},
            </if>
            <if test="paramCode!=null and paramCode!=''">
                param_code =#{paramCode},
            </if>
            <if test="paramVal!=null and paramVal!=''">
                param_val =#{paramVal},
            </if>
            <if test="modifyTime!=null and modifyTime!=''">
                modify_time =#{modifyTime},
            </if>
            <if test="modifyUserName!=null and modifyUserName!=''">
                modify_user_name =#{modifyUserName},
            </if>
            <if test="modifyTrueName!=null and modifyTrueName!=''">
                modify_true_name =#{modifyTrueName}
            </if>
        </set>
        where param_id=#{paramId}
    </update>

    <delete id="deleteServiceParams">
        delete
        from service_params
        where param_id = #{paramId}
    </delete>


    <select id="findParamVal" resultType="HashMap">
        select *
        from service_params
    </select>

    <select id="findParamValByParamCode" resultType="HashMap">
        select PARAM_NAME, PARAM_CODE, PARAM_VAL
        from service_params
        where PARAM_CODE = #{code}
    </select>
    <update id="updateServiceParamsValBycode" parameterType="HashMap">
        update service_params
        set param_val = #{param_val}
        where param_code = #{param_code}
    </update>
</mapper>