<?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.yifu.cloud.plus.v1.permission.mapper.SysMenuMapper">

	<resultMap id="sysMenuMap" type="com.yifu.cloud.plus.v1.yifu.permission.entity.SysMenu">
    <id property="id" column="ID"/>
    <result property="menuName" column="MENU_NAME"/>
    <result property="menuNameParent" column="MENU_NAME_PARENT"/>
    <result property="menuParentId" column="MENU_PARENT_ID"/>
    <result property="modelId" column="MODEL_ID"/>
    <result property="viewId" column="VIEW_ID"/>
	<result property="permissionType" column="PERMISSION_TYPE"/>
    <result property="permissionStatus" column="PERMISSION_STATUS"/>
    <result property="deleteStatus" column="DELETE_STATUS"/>
    <result property="incomeId" column="INCOME_ID"/>
    <result property="customerId" column="CUSTOMER_ID"/>
    <result property="contractId" column="CONTRACT_ID"/>
    <result property="bussinessId" column="BUSSINESS_ID"/>
    <result property="quotationId" column="QUOTATION_ID"/>
    <result property="domainId" column="DOMAIN_ID"/>
    <result property="buId" column="BU_ID"/>
    <result property="lineId" column="LINE_ID"/>
    <result property="deptId" column="DEPT_ID"/>
    <result property="createBy" column="CREATE_BY"/>
    <result property="updateBy" column="UPDATE_BY"/>
    <result property="createName" column="CREATE_NAME"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="updateTime" column="UPDATE_TIME"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.ID,
                a.MENU_NAME,
                a.MENU_NAME_PARENT,
                a.MENU_PARENT_ID,
                a.PERMISSION_TYPE,
                a.PERMISSION_STATUS,
                a.DELETE_STATUS,
                a.CREATE_TIME
    </sql>
    <sql id="sysMenu_where">
        <if test="sysMenu != null">
			<if test="sysMenu.menuName != null and sysMenu.menuName.trim() != ''">
                AND a.MENU_NAME = #{sysMenu.menuName}
			</if>
			<if test="sysMenu.menuNameParent != null and sysMenu.menuNameParent.trim() != ''">
                AND a.MENU_NAME_PARENT = #{sysMenu.menuNameParent}
			</if>
			<if test="sysMenu.menuParentId != null and sysMenu.menuParentId.trim() != ''">
				AND a.MENU_PARENT_ID = #{sysMenu.menuParentId}
			</if>
			<if test="sysMenu.permissionStatus != null and sysMenu.permissionStatus.trim() != ''">
                AND a.PERMISSION_STATUS = #{sysMenu.permissionStatus}
			</if>
        </if>
    </sql>
    <!--sysMenu简单分页查询-->
    <select id="getSysMenuPage" resultMap="sysMenuMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sys_menu a
        <where>
            a.DELETE_STATUS = '1'
            <include refid="sysMenu_where"/>
        </where>
		order by a.CREATE_TIME desc
    </select>

	<select id="selectMenuId" resultType="java.lang.Long">
		SELECT
		 	count(1)
		FROM modeling_app_model a
		WHERE a.fd_id = #{modelId}
	</select>

	<select id="selectColumnList" resultType="java.lang.String">
		SELECT
			a.fd_column
		FROM sys_xform_db_column a
		LEFT JOIN sys_xform_db_table b on a.fd_main_id = b.fd_id
		WHERE b.fd_model_id = #{modelId}
	</select>
</mapper>
