<?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.ssm.manage.mapper.BaseProjectTypeMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.BaseProjectType">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="project_type_num" jdbcType="VARCHAR" property="projectTypeNum" />
    <result column="project_type_name" jdbcType="VARCHAR" property="projectTypeName" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="founder_staff" jdbcType="VARCHAR" property="founderStaff" />
    <result column="Founder_datetime" jdbcType="TIMESTAMP" property="founderDatetime" />
    <result column="modify_by" jdbcType="VARCHAR" property="modifyBy" />
    <result column="modify_datetime" jdbcType="TIMESTAMP" property="modifyDatetime" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
  </resultMap>

  <resultMap id="BaseResultMapTree" type="com.ssm.manage.query.ProjectTypeRequest">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="project_type_num" jdbcType="VARCHAR" property="projectTypeNum" />
    <result column="project_type_name" jdbcType="VARCHAR" property="projectTypeName" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="founder_staff" jdbcType="VARCHAR" property="founderStaff" />
    <result column="Founder_datetime" jdbcType="TIMESTAMP" property="founderDatetime" />
    <result column="modify_by" jdbcType="VARCHAR" property="modifyBy" />
    <result column="modify_datetime" jdbcType="TIMESTAMP" property="modifyDatetime" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <collection property="projectTypeRequestList" ofType="com.ssm.manage.query.ProjectTypeRequest" column="id" select="getMenuChildren"/>
  </resultMap>

  <sql id="baseColumnList">
    id,
    project_type_num,
    project_type_name,
    state,
    founder_staff,
    founder_datetime,
    modify_by,
    modify_datetime,
    store_id,
    store_name,
    parent_id
  </sql>

  <select id="getMenuChildren" resultMap="BaseResultMapTree">
    SELECT
      *
    FROM
      base_project_type
    WHERE
         parent_id= #{id}
  </select>

  <select id="getMenu" resultMap="BaseResultMapTree">
    SELECT
      *
    FROM
      base_project_type
    WHERE
     parent_id IS NULL and store_id = #{storeId}
  </select>

  <select id="getMenuId" resultMap="BaseResultMapTree">
    SELECT
      *
    FROM
      base_project_type
    WHERE
      project_type_name =  #{projectTypeName} and store_id = #{storeId}
  </select>
  <select id="selectByEveryId" resultType="long">
    SELECT id from base_project_type where parent_id in ( SELECT id FROM `base_project_type` where parent_id = #{parentId}) UNION ALL
    SELECT id FROM `base_project_type` where parent_id = #{parentId}
  </select>
  <select id="selectByChild" resultType="long">
    SELECT id from base_project_type where parent_id = #{parentId}
  </select>


  <insert id="insertBatch" parameterType="java.util.ArrayList" >
    insert into base_project_type (<include refid="baseColumnList"/>) values
    <foreach collection="list" index="index" item="item" separator=",">
    (
    #{item.id},
    #{item.projectTypeNum},
    #{item.projectTypeName},
    #{item.state},
    #{item.founderStaff},
    #{item.founderDatetime},
    #{item.modifyBy},
    #{item.modifyDatetime},
    #{item.storeId},
    #{item.storeName},
    #{item.parentId}
    )
    </foreach>
  </insert>

</mapper>