<?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.fjs.scenic.mapper.system.ManageMapper">
    <!--<resultMap id="BaseResultMap" type="com.fjs.scenic.entity.system.Manage">
        <constructor>
            <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
            <arg column="name" jdbcType="VARCHAR" javaType="java.lang.String"/>
            <arg column="account" jdbcType="VARCHAR" javaType="java.lang.String"/>
            <arg column="password" jdbcType="VARCHAR" javaType="java.lang.String"/>
            <arg column="phone" jdbcType="VARCHAR" javaType="java.lang.String"/>
            <arg column="status" jdbcType="VARCHAR" javaType="java.lang.Byte"/>
            <arg column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
            <arg column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
            <arg column="manage_id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
        </constructor>
    </resultMap>-->
    <resultMap id="BaseResultMap" type="com.fjs.scenic.entity.system.Manage" >
        <id property="id" column="id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
        <result property="name" column="name" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="account" column="account" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="password" column="password" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="phone" column="phone" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="status" column="status" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result property="manageId" column="manage_id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
        <result property="type" column="type" jdbcType="VARCHAR" javaType="java.lang.String"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, `name`, account, password, phone, status, create_time, update_time, manage_id
  </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from manage
        where id = #{id,jdbcType=INTEGER} and type='0'
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from manage
    where id = #{id,jdbcType=INTEGER}
  </delete>
    <insert id="insert" parameterType="com.fjs.scenic.entity.system.Manage">
    insert into manage (id, name, account, 
      password, phone, status, 
      create_time, update_time, manage_id, type
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{account,jdbcType=VARCHAR}, 
      #{password,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{manageId,jdbcType=INTEGER},'1'
      )
  </insert>
  
  <select id="selectRepet" resultMap="BaseResultMap" parameterType="com.fjs.scenic.entity.system.Manage">
        select * from manage
        where `type`='0'
       		<if test="id != null">
                and id =   #{id,jdbcType=INTEGER}
            </if>
            <if test="name != null">
                and name = #{name,jdbcType=VARCHAR}
            </if>
            <if test="account != null">
                and account = #{account,jdbcType=VARCHAR}
            </if>
            <if test="password != null">
                and password = #{password,jdbcType=VARCHAR}
            </if>
            <if test="phone != null">
                and phone = #{phone,jdbcType=VARCHAR}
            </if>
            <if test="status != null">
                and status = #{status,jdbcType=VARCHAR}
            </if>
            <if test="createTime != null">
                and create_time =  #{createTime,jdbcType=TIMESTAMP}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime,jdbcType=TIMESTAMP}
            </if>
            <if test="manageId != null">
                and manage_id = #{manageId,jdbcType=INTEGER}
            </if>
    </select>
    <insert id="insertSelective" parameterType="com.fjs.scenic.entity.system.Manage">
        insert into manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="account != null">
                account,
            </if>
            <if test="password != null">
                password,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="manageId != null">
                manage_id,
            </if>
            `type`
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="account != null">
                #{account,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                #{password,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                #{phone,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="manageId != null">
                #{manageId,jdbcType=INTEGER},
            </if>
            '0'
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.fjs.scenic.entity.system.Manage">
        update manage
        <set>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="account != null">
                account = #{account,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                password = #{password,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="manageId != null">
                manage_id = #{manageId,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.fjs.scenic.entity.system.Manage">
    update manage
    set name = #{name,jdbcType=VARCHAR},
      account = #{account,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      status = #{status,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      manage_id = #{manageId,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

    <resultMap id="ListMap1" type="com.fjs.scenic.dto.ManageDto" >
        <id property="id" column="id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
        <result property="name" column="name" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="account" column="account" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="phone" column="phone" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="status" column="status" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result property="manageId" column="manage_id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
        <collection property="roleList" ofType="com.fjs.scenic.entity.system.Role">
            <id property="id" column="id1" javaType="java.lang.Integer"/>
            <result property="name" column="name1" jdbcType="VARCHAR" javaType="java.lang.String"/>
            <result property="code" column="code" jdbcType="VARCHAR" javaType="java.lang.String"/>
        </collection>
    </resultMap>

    <resultMap id="ListMap" type="com.fjs.scenic.dto.ManageDto" >
        <id property="id" column="id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
        <result property="name" column="name" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="account" column="account" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="password" column="password" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="phone" column="phone" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="status" column="status" jdbcType="VARCHAR" javaType="java.lang.String"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result property="manageId" column="manage_id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
    </resultMap>

    <!--自定义sql-->
    <!--<select id="selectAll" resultMap="BaseResultMap" parameterType="com.fjs.scenic.entity.system.Manage">
        SELECT * FROM manage
        <where>
            <if test="name != null and name != ''">
                AND name like CONCAT('%',#{name},'%')
            </if>
        </where>
    </select>-->

    <select id="selectAll1" resultMap="ListMap1" parameterType="com.fjs.scenic.dto.ManageDto">
        SELECT m.*,r.id id1,r.name name1,r.code FROM manage m
        LEFT JOIN manage_role mr ON
        m.id=mr.manage_id LEFT JOIN
        role r ON mr.role_id=r.id
        <where>
            `type`='0'
            <if test="name != null">
                AND m.name like CONCAT('%',#{name},'%')
            </if>
        </where>
        ORDER BY m.create_time DESC
    </select>

    <select id="selectAll" resultMap="ListMap" parameterType="com.fjs.scenic.entity.system.Manage">
        select
        id, name, account,'' AS password, phone, status, create_time, update_time, manage_id
        from manage
        <where>
            `type`='0'
            <if test="name != null and name != ''">
                AND `name` like CONCAT('%',#{name},'%')
            </if>
            <if test="password != null and password != '' ">
                AND password = #{password}
            </if>
            <if test="id != null and id != 0 ">
                AND id = #{id}
            </if>
        </where>
    </select>

    <select id="selectByAccount" resultMap="BaseResultMap"  parameterType="java.lang.String">
        SELECT
        <include refid="Base_Column_List"/>
        from manage WHERE account = #{account,jdbcType=VARCHAR} and `type`='0'
    </select>

    <!--查询角色未领导决策的管理员-->
    <select id="selectLDJCManage" resultMap="BaseResultMap">
        SELECT * FROM manage WHERE id in(
          SELECT manage_id FROM manage_role WHERE role_id in(
            SELECT id FROM role WHERE `code` = 'ldjc'
          )
        )
    </select>

    <!--通过账号修改-->
    <update id="updateByAccountKeySelective" parameterType="com.fjs.scenic.entity.system.Manage">
        update manage
        <set>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="account != null">
                account = #{account,jdbcType=VARCHAR},
            </if>
            <if test="password != null">
                password = #{password,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="manageId != null">
                manage_id = #{manageId,jdbcType=INTEGER},
            </if>
        </set>
        where account = #{account,jdbcType=VARCHAR} and `type`='0'
    </update>
</mapper>