<?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.DicinfoMapper">
    <resultMap id="BaseResultMap" type="com.saye.hospitalgd.model.Dicinfo">
        <id column="diccode" property="diccode" jdbcType="VARCHAR"/>
        <result column="dicname" property="dicname" jdbcType="VARCHAR"/>
        <result column="dicvalue" property="dicvalue" jdbcType="VARCHAR"/>
        <result column="parent_code" property="parentCode" jdbcType="VARCHAR"/>
        <result column="sort_no" property="sortNo" jdbcType="INTEGER"/>
        <result column="modify_time" property="modifyTime" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 根据父节点查询数据 -->
    <select id="findDicinfoTreeNodeList" resultMap="BaseResultMap">
        select diccode,
               dicname,
               dicvalue,
               parent_code,
               sort_no,
               modify_time,
               create_time
        from dicinfo
        where parent_code = #{parentCode}
        order by sort_no
    </select>
    <select id="findDicinfoBydiccode" resultMap="BaseResultMap">
        select diccode,
               dicname,
               dicvalue,
               parent_code,
               sort_no,
               modify_time,
               create_time
        from dicinfo
        where diccode = #{diccode}
    </select>
    <select id="findDicinfoTreeByCode" resultMap="BaseResultMap">
        select diccode,dicname,dicvalue,parent_code,sort_no,
        modify_time,create_time from dicinfo
        <where>
            parent_code=#{parentCode}
            <if test="dicvalue!=null and dicvalue!=''">
                and dicvalue=#{dicvalue}
            </if>
        </where>
        order by sort_no
    </select>
    <!-- 新增数据 -->
    <insert id="addDicinfo">
        insert into dicinfo(diccode, dicname, dicvalue, parent_code, create_time, modify_time, sort_no)
        values (#{diccode}, #{dicname}, #{dicvalue}, #{parentCode}, #{create_time}, #{create_time}, #{sortNo})
    </insert>


    <update id="modifyDicinfo">
        update dicinfo
        <set>
            <if test="dicname!=null and dicname!=''">
                dicname=#{dicname},
            </if>
            <if test="dicvalue!=null and dicvalue!=''">
                dicvalue=#{dicvalue},
            </if>
            <if test="sortNo!=null and sortNo!=''">
                sort_no=#{sortNo},
            </if>
            <if test="modifyTime!=null and modifyTime!=''">
                modify_time=#{modifyTime}
            </if>
        </set>
        where diccode=#{diccode}
    </update>

    <delete id="deleteDicinfo">
        delete
        from dicinfo
        where diccode = #{diccode}
           or parent_code = #{diccode}
    </delete>

    <select id="selectDicinfoListByCode" parameterType="java.lang.String" resultType="HashMap">
        select dicname, dicvalue, create_time, diccode
        from dicinfo
        where parent_code = #{parent_code}
        order by dicvalue
    </select>

    <select id="selectDicinfoListByCondition" parameterType="HashMap" resultType="HashMap">
        select dicname,dicvalue,create_time,diccode from dicinfo where parent_code = #{parentCode}
        <if test="dicname!=null and dicname!=''">
            and dicname like concat('%',concat(#{dicname},'%'))
        </if>
        order by dicvalue
    </select>
    <!-- 查询最大编码 -->
    <select id="getMaxDicValue" resultType="HashMap" parameterType="HashMap">
        select max(dicvalue) + 1 as maxDicValue
        from dicinfo
        where parent_code = #{parentCode}
    </select>

</mapper>