<?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="twoLevelId" column="TWO_LEVEL_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"/>
    <result property="isOpen" column="IS_OPEN"/>
    <result property="tableName" column="TABLE_NAME"/>
    <result property="queryFields" column="QUERY_FIELDS"/>
    <result property="taxId" column="TAX_ID"/>
	<result property="divisionId" column="DIVISION_ID"/>
	<result property="divisionLineId" column="DIVISION_LINE_ID"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.ID,
                a.MENU_NAME,
                a.MODEL_ID,
                a.MENU_NAME_PARENT,
                a.MENU_PARENT_ID,
                a.PERMISSION_TYPE,
                a.PERMISSION_STATUS,
                a.DELETE_STATUS,
                a.INCOME_ID,
                a.CUSTOMER_ID,
                a.CONTRACT_ID,
                a.BUSSINESS_ID,
                a.QUOTATION_ID,
                a.DOMAIN_ID,
                a.BU_ID,
                a.LINE_ID,
                a.DEPT_ID,
                a.IS_OPEN,
                a.TWO_LEVEL_ID,
                a.VIEW_ID,
                a.CREATE_TIME,
				a.TABLE_NAME,
				a.QUERY_FIELDS,
				a.TAX_ID,
				a.DIVISION_ID,
				a.DIVISION_LINE_ID
    </sql>
    <sql id="sysMenu_where">
        <if test="sysMenu != null">
			<if test="sysMenu.menuName != null and sysMenu.menuName.trim() != ''">
                AND a.MENU_NAME like concat('%',#{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="selectViewId" resultType="java.lang.Long">
		SELECT
			count(1)
		FROM modeling_app_collection_view a
		WHERE a.fd_model_id = #{modelId} and a.fd_id = #{viewId}
	</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>

	<!--根据modelId获取菜单-->
	<select id="getSysMenuByModelId" resultMap="sysMenuMap">
		SELECT
		<include refid="Base_Column_List"/>
		FROM sys_menu a
		where a.DELETE_STATUS = '1' and a.PERMISSION_STATUS='0' and a.MODEL_ID = #{modelId}
		limit 1
	</select>

	<!-- 获取税务主体列表-->
	<select id="getSysTaxVoPage" resultType="com.yifu.cloud.plus.v1.yifu.permission.vo.SysTaxVo">
		select fd_id AS id,a.fd_3afab4c6755286 AS name
		from ekp_7e091e5e36848fb97451 a
		where a.fd_3afab4c6755286 is not null
		<if test="vo != null">
			<if test="vo.name != null and vo.name.trim() != ''">
				AND a.fd_3afab4c6755286 like concat('%',#{vo.name},'%')
			</if>
		</if>
		GROUP BY a.fd_3afab4c6755286 ORDER BY a.fd_3afab4c6755286 desc
	</select>
	<!-- 获取事业部-->
	<select id="getDivisions" resultType="com.yifu.cloud.plus.v1.yifu.permission.vo.SysDivisionVo">
		select DISTINCT(fd_shiyebu) as 'name' from ekp_shenhepeizhi_table
	</select>

	<!-- 获取事业部条线-->
	<select id="getDivisionLines" resultType="com.yifu.cloud.plus.v1.yifu.permission.vo.SysDivisionLineVo">
		select DISTINCT(fd_tiaoxian)  as 'name' from ekp_shenhepeizhi_table
	</select>

</mapper>
