<?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.willalp.app.mapper.HsAppHomeMapper">
    <resultMap type="com.willalp.app.domain.HsAppHome" id="HsAppHomeResult">
        <result property="appHomeId" column="app_home_id"/>
        <result property="homeId" column="home_id"/>
        <result property="isIssue" column="is_issue"/>
        <result property="appHomeName" column="app_home_name"/>
        <result property="orgCode" column="org_code"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <resultMap type="com.willalp.common.core.domain.vo.SysDeptVo" id="sysOrgList">
        <result property="deptCode" column="dept_code"/>
        <result property="deptName" column="dept_name"/>
    </resultMap>

    <sql id="selectHsAppHomeVo">
        select app_home_id,
               home_id,
               is_issue,
               app_home_name,
               org_code,
               is_delete,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from hs_app_home hah
    </sql>
    <resultMap id="HsAppHomeSysDeptResult" type="HsAppHome" extends="HsAppHomeResult">
        <collection property="sysDeptList" notNullColumn="sub_dept_id"
                    javaType="java.util.List" resultMap="SysDeptResult"/>
    </resultMap>

    <resultMap type="SysDeptVo" id="SysDeptResult">
        <result property="deptId" column="sub_dept_id"/>
        <result property="deptName" column="sub_dept_name"/>
    </resultMap>

    <select id="selectHsAppHomeList" parameterType="HsAppHome" resultMap="HsAppHomeResult">
        <include refid="selectHsAppHomeVo"/>
        <where>
            is_delete = 0
            <if test="homeId != null">
                and home_id = #{homeId}
            </if>
            <if test="appHomeName != null  and appHomeName != ''">
                and app_home_name like concat('%', #{appHomeName}, '%')
            </if>
            <if test="orgCode != null  and orgCode != ''">
                and org_code = #{orgCode}
            </if>
        </where>
    </select>
    <select id="selectSysDeptList" resultMap="sysOrgList">
        SELECT dept_code, dept_name
        from sys_dept
        WHERE del_flag = 0
          and parent_id = 0
    </select>
    <select id="getHsAppHomeByOrgCodeAndIsIssueTo1" resultMap="HsAppHomeResult">
        <include refid="selectHsAppHomeVo"/>
        <where>
            is_delete = 0 and is_issue = 1
            and org_code = #{orgCode}
        </where>
    </select>
</mapper>
