<?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.interfaces.mapper.SysCateMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.interfaces.domain.SysCate">
        <id column="CATE_CODE" property="cateCode" jdbcType="VARCHAR"/>
        <result column="CATE_PCODE" property="catePcode" jdbcType="VARCHAR"/>
        <result column="CATE_TABLE" property="cateTable" jdbcType="VARCHAR"/>
        <result column="CATE_NAME" property="cateName" jdbcType="VARCHAR"/>
        <result column="CATE_DESC" property="cateDesc" jdbcType="VARCHAR"/>
        <result column="CATE_SEQ" property="cateSeq" jdbcType="DECIMAL"/>
        <result column="CATE_STATUS" property="cateStatus" jdbcType="VARCHAR"/>
        <result column="num" property="num" jdbcType="DECIMAL"/>
    </resultMap>
    <sql id="Base_Column_List">
        CATE_CODE
        , CATE_PCODE, CATE_TABLE, CATE_NAME, CATE_DESC, CATE_SEQ, CATE_STATUS
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from SYS_CATE
        where CATE_CODE = #{cateCode,jdbcType=VARCHAR}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete
        from SYS_CATE
        where CATE_CODE = #{cateCode,jdbcType=VARCHAR}
    </delete>
    <insert id="insert" parameterType="com.ruoyi.interfaces.domain.SysCate">
        insert into SYS_CATE (CATE_CODE, CATE_PCODE, CATE_TABLE,
                              CATE_NAME, CATE_DESC, CATE_SEQ,
                              CATE_STATUS)
        values (#{cateCode,jdbcType=VARCHAR}, #{catePcode,jdbcType=VARCHAR}, #{cateTable,jdbcType=VARCHAR},
                #{cateName,jdbcType=VARCHAR}, #{cateDesc,jdbcType=VARCHAR}, #{cateSeq,jdbcType=DECIMAL},
                #{cateStatus,jdbcType=DECIMAL})
    </insert>
    <insert id="insertSelective" parameterType="com.ruoyi.interfaces.domain.SysCate">
        insert into SYS_CATE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cateCode != null">
                CATE_CODE,
            </if>
            <if test="catePcode != null">
                CATE_PCODE,
            </if>
            <if test="cateTable != null">
                CATE_TABLE,
            </if>
            <if test="cateName != null">
                CATE_NAME,
            </if>
            <if test="cateDesc != null">
                CATE_DESC,
            </if>
            <if test="cateSeq != null">
                CATE_SEQ,
            </if>
            <if test="cateStatus != null">
                CATE_STATUS,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cateCode != null">
                #{cateCode,jdbcType=VARCHAR},
            </if>
            <if test="catePcode != null">
                #{catePcode,jdbcType=VARCHAR},
            </if>
            <if test="cateTable != null">
                #{cateTable,jdbcType=VARCHAR},
            </if>
            <if test="cateName != null">
                #{cateName,jdbcType=VARCHAR},
            </if>
            <if test="cateDesc != null">
                #{cateDesc,jdbcType=VARCHAR},
            </if>
            <if test="cateSeq != null">
                #{cateSeq,jdbcType=DECIMAL},
            </if>
            <if test="cateStatus != null">
                #{cateStatus,jdbcType=DECIMAL},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.interfaces.domain.SysCate">
        update SYS_CATE
        <set>
            <if test="catePcode != null">
                CATE_PCODE = #{catePcode,jdbcType=VARCHAR},
            </if>
            <if test="cateTable != null">
                CATE_TABLE = #{cateTable,jdbcType=VARCHAR},
            </if>
            <if test="cateName != null">
                CATE_NAME = #{cateName,jdbcType=VARCHAR},
            </if>
            <if test="cateDesc != null">
                CATE_DESC = #{cateDesc,jdbcType=VARCHAR},
            </if>
            <if test="cateSeq != null">
                CATE_SEQ = #{cateSeq,jdbcType=DECIMAL},
            </if>
            <if test="cateStatus != null">
                CATE_STATUS = #{cateStatus,jdbcType=DECIMAL},
            </if>
        </set>
        where CATE_CODE = #{cateCode,jdbcType=VARCHAR}
    </update>
    <update id="updateStatus" parameterType="com.ruoyi.interfaces.domain.SysCate">
        update SYS_CATE
        <set>
            <if test="cateStatus != null">
                CATE_STATUS = #{cateStatus,jdbcType=DECIMAL},
            </if>
        </set>
        where CATE_CODE = #{cateCode,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ruoyi.interfaces.domain.SysCate">
        update SYS_CATE
        set CATE_PCODE  = #{catePcode,jdbcType=VARCHAR},
            CATE_TABLE  = #{cateTable,jdbcType=VARCHAR},
            CATE_NAME   = #{cateName,jdbcType=VARCHAR},
            CATE_DESC   = #{cateDesc,jdbcType=VARCHAR},
            CATE_SEQ    = #{cateSeq,jdbcType=DECIMAL},
            CATE_STATUS = #{cateStatus,jdbcType=DECIMAL}
        where CATE_CODE = #{cateCode,jdbcType=VARCHAR}
    </update>

    <select id="findAll" parameterType="com.ruoyi.interfaces.domain.SysCate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        SYS_CATE
        <if test="cateTable != null and cateTable != ''">
            where CATE_TABLE = #{cateTable}
        </if>
        <if test="cateName != null and cateName != ''">
            where CATE_NAME LIKE CONCAT('%',#{cateName},'%')
        </if>
        <if test="cateStatus != null">
            where CATE_STATUS = #{cateStatus}
        </if>
        order by CATE_SEQ asc
    </select>

    <select id="countNum" resultMap="BaseResultMap">
        SELECT
        SC.CATE_PCODE,
        SC.CATE_NAME,
        SC.CATE_CODE,
        (SELECT COUNT(*) FROM PT_SERVICE
        WHERE CATE_CODE LIKE CONCAT(SC.CATE_CODE,'%')
        <if test="status != null and status !=''">
            and STATUS = #{status}
        </if>
        ) NUM
        FROM SYS_CATE SC
        WHERE SC.CATE_TABLE='PT_SERVICE'
        ORDER BY CATE_PCODE,CATE_SEQ
    </select>

    <select id="findParent" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        SYS_CATE
        where CATE_PCODE = '0'
    </select>

    <select id="findChildren" resultMap="BaseResultMap" parameterType="com.ruoyi.interfaces.domain.SysCate">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        SYS_CATE
        where CATE_PCODE != '0'
        <if test="catePcode != null and catePcode !=''">
            and CATE_PCODE = #{catePcode}
        </if>
    </select>

    <select id="findAllO" parameterType="com.ruoyi.interfaces.domain.SysCate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        SYS_CATE
        <if test="cateTable != null and cateTable != ''">
            where CATE_TABLE = #{cateTable}
            and CATE_PCODE != '0'
        </if>
        order by CATE_SEQ asc
    </select>
    <select id="getCount" resultType="java.lang.Integer">
        select count(*)
        from SYS_CATE CATE_PCODE
    </select>


    <select id="selectFirstCate" resultMap="BaseResultMap">
        SELECT *
        FROM SYS_CATE
        where CATE_PCODE in (SELECT CATE_CODE FROM SYS_CATE where CATE_PCODE = '0')
    </select>

    <select id="listByPcode" resultMap="BaseResultMap">
        SELECT *
        FROM SYS_CATE
        where CATE_PCODE = #{catePcode}
    </select>
</mapper>
