<?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">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
<mapper namespace="com.iamberry.wechat.service.mapper.AdminInfoMapper">

	<!-- 超级管理员所有字段，并可以映射实体类 -->
	<sql id="adminInfoField">
		a_id adminId, a_login_name adminLoginName, a_login_pwd adminLoginPwd, a_sex adminSex,
		a_tel  adminTel, a_email adminEmail, a_photo_url  adminPhotoUrl, a_city adminCity, 
		a_desc adminDesc, a_status adminStatus
	</sql>
	
	<!-- 二级管理员所有字段，并可以映射实体类 -->
	<sql id="adminChildInfoField">
		<include refid="adminInfoField"/>, a_create_id adminCreateAdminId, a_create_date adminCreateDate
	</sql>
	
	<!-- 根据用户名密码查询超级管理员 -->
	<select id="selectAdminInfoByNameAndPwd" parameterType="AdminLoginDTO" resultType="AdminInfo">
		SELECT <include refid="adminInfoField"/> FROM TB_ADMIN_ADMININFO WHERE A_LOGIN_NAME = #{adminLoginName} AND A_LOGIN_PWD = #{adminLoginPwd}
	</select>
	
	<!-- 根据用户名和密码查询二级管理员 -->
	<select id="selectAdminChildInfoByNameAndPwd" parameterType="AdminLoginDTO" resultType="AdminChildInfo">
		SELECT <include refid="adminChildInfoField"/> FROM TB_ADMIN_ADMINCHILD_INFO WHERE A_LOGIN_NAME = #{adminLoginName} AND A_LOGIN_PWD = #{adminLoginPwd}
	</select>
	<!-- 新增二级管理员 -->
	<insert id="insertadmin" parameterType="AdminChildInfo">
		 INSERT INTO TB_ADMIN_ADMINCHILD_INFO(a_id,a_login_name,a_login_pwd,
		 								a_sex,a_tel,a_email,a_photo_url,a_city,
		 								a_create_id,
		 								a_desc,a_status,a_create_date)
		  VALUES ( 
		  #{adminId},  
		  #{adminLoginName}, 
		  #{adminLoginPwd},
		  #{adminSex},
		  #{adminTel},  
		  #{adminEmail},   
		  #{adminPhotoUrl}, 
		  #{adminCity}, 
		  #{adminCreateAdminId}, 
		  #{adminDesc}, 
		  #{adminStatus},
		  #{adminCreateDate}
		  )
	</insert>
	
	<!-- 根据用户名二级管理员是否存在 -->
	<select id="selectAdminChildInfoByName" parameterType="AdminChildInfo" resultType="AdminChildInfo">
		SELECT <include refid="adminChildInfoField"/> FROM TB_ADMIN_ADMINCHILD_INFO WHERE A_LOGIN_NAME = #{adminLoginName}
	</select>
	
	<!-- 查詢所有二级管理员 -->
	<select id="selectAdminChildInfoByList" parameterType="PaperBean" resultType="AdminChildInfo">
		SELECT <include refid="adminChildInfoField"/> FROM TB_ADMIN_ADMINCHILD_INFO order by a_create_date desc limit #{minNum},#{maxNum}
	</select>
	
	<!-- 模糊查詢二级管理员 -->
	<select id="selectAdminChildInfoByNameList" parameterType="PaperBean" resultType="AdminChildInfo">
		SELECT <include refid="adminChildInfoField"/> FROM TB_ADMIN_ADMINCHILD_INFO where A_LOGIN_NAME order by a_create_date desc LIKE #{str} limit #{minNum},#{maxNum}
	</select>
	<!-- 模糊查詢二级管理员条数 -->
	<select id="selectAdminChildInfoByNameCount" parameterType="String" resultType="int">
		SELECT COUNT(A_ID) FROM TB_ADMIN_ADMINCHILD_INFO where A_LOGIN_NAME LIKE #{str}
	</select>
	
	<!-- 查詢所有二级管理员的数量 -->
	<select id="selectAdminChildInfoByCount" resultType="int">
		SELECT count(a_id) FROM TB_ADMIN_ADMINCHILD_INFO
	</select>
	
	<!-- 删除二级管理员 -->
	<delete id="deleteAdminChildInfoById">
		delete FROM TB_ADMIN_ADMINCHILD_INFO WHERE A_ID = #{adminid}
	</delete>
	
	<!-- 根据id查找二级管理员 -->
	<select id="selectAdminChildInfoById" resultType="AdminChildInfo">
		SELECT <include refid="adminChildInfoField"/> FROM TB_ADMIN_ADMINCHILD_INFO WHERE A_ID = #{adminid}
	</select>
	
	<!-- 根据id修改二级管理员 -->
	<update id="updateAdminChildInfoById" parameterType="AdminChildInfo">
		update TB_ADMIN_ADMINCHILD_INFO SET 
		a_id = #{adminId},
		a_sex = #{adminSex},
		a_tel = #{adminTel},
		a_email = #{adminEmail},
		a_photo_url = #{adminPhotoUrl},
		a_city = #{adminCity},
		a_create_id = #{adminCreateAdminId},
		a_desc = #{adminDesc},
		a_status = #{adminStatus},
		a_create_date = #{adminCreateDate}
		  WHERE A_ID = #{adminId}
	</update>
	<!-- 根据id修改二级管理员权限 -->
	<update id="updatePermissionsById" parameterType="String">
		update TB_ADMIN_ADMINCHILD_INFO SET 
		a_id = #{adminid},
		a_status = #{adminStatus}
		  WHERE A_ID = #{adminid}
	</update>
	<!-- 根据二级管理员的ID，修改密码  -->
	<update id="updateAdminByPwd" parameterType="AdminChildInfo">
		update TB_ADMIN_ADMINCHILD_INFO SET 
		A_LOGIN_PWD = #{adminLoginPwd}
		  WHERE a_id = #{adminId}
	</update>
	<!-- 根据超级管理员的ID，修改密码  -->
	<update id="updateSuperAdminByPwd" parameterType="AdminInfo">
		update TB_ADMIN_ADMININFO SET 
		A_LOGIN_PWD = #{adminLoginPwd}
		  WHERE a_id = #{adminId}
	</update>
</mapper>
