package com.iamberry.wechat.service.admin;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iamberry.wechat.core.entity.PaperBean;
import com.iamberry.wechat.core.entity.admin.AdminChildInfo;
import com.iamberry.wechat.core.entity.admin.AdminInfo;
import com.iamberry.wechat.face.admin.AdminAdministratorService;
import com.iamberry.wechat.service.admin.dao.AdminAdministratorDAO;


@Service
public class AdminAdministratorServiceImpl implements AdminAdministratorService {

	@Autowired
	private AdminAdministratorDAO adminadministratordao;
	public void setAdminAdministratorDAO(AdminAdministratorDAO adminadministratordao) {
		this.adminadministratordao = adminadministratordao;
	}
	/**
	 * 新增二級管理員
	 */
	public void insertadmin(AdminChildInfo adminchildinfo) throws Exception{
		adminadministratordao.insertadmin(adminchildinfo);
	}
	/**
	 * 根據用戶名查詢是否有重複用戶
	 */
	public AdminChildInfo selectAdminChildInfoByName(String adminLoginName) throws Exception {
		// TODO Auto-generated method stub
		return adminadministratordao.selectAdminChildInfoByName(adminLoginName);
	}
	/**
	 * 查詢所有二級管理員
	 */
	public List<AdminChildInfo>  selectAdminChildInfoByList(Integer pageNO, Integer pageSize) throws Exception {
		
		PaperBean bean = new PaperBean();
		bean.setMinNum((pageNO-1)*pageSize);
		bean.setMaxNum(pageSize);
		List<AdminChildInfo> adminChildInfoList = adminadministratordao.selectAdminChildInfoByList(bean);
		/*Map<Object, Object> tempMap = new HashMap<Object, Object>();
		if(adminChildInfoList.size()>0){
			for(AdminChildInfo adminChildInfo : adminChildInfoList){
				tempMap.put("adminId", adminUtils.encryptObject(adminChildInfo.getAdminId(),"admin"));
				tempMap.put("adminLoginName", adminChildInfo.getAdminLoginName());
				tempMap.put("adminLoginPwd", adminChildInfo.getAdminLoginPwd());
				tempMap.put("adminSex", adminChildInfo.getAdminSex());
				tempMap.put("adminTel", adminChildInfo.getAdminTel());
				tempMap.put("adminEmail", adminChildInfo.getAdminEmail());
				tempMap.put("adminDesc", adminChildInfo.getAdminDesc());
				tempMap.put("adminStatus", adminChildInfo.getAdminStatus());
				tempMap.put("adminCreateDate", adminChildInfo.getAdminCreateDate());
			}
		}*/
		return adminChildInfoList;
	}
	
	/**
	 * 模糊查詢二級管理員
	 */
	public List<AdminChildInfo> selectAdminChildInfoByNameList(String adminLoginName,Integer pageNO, Integer pageSize) throws Exception {
		PaperBean bean = new PaperBean();
		bean.setMinNum((pageNO-1)*pageSize);
		bean.setMaxNum(pageSize);
		bean.setStr(adminLoginName);
		List<AdminChildInfo> adminChildInfoList = adminadministratordao.selectAdminChildInfoByNameList(bean);
		return adminChildInfoList;
	}
	
	
	/*public List<Map<Object, Object>> selectImageInfoList(String wxPublicNo, Integer pageNO, Integer pageSize) throws Exception {
		PaperBean bean = new PaperBean();
		bean.setMinNum((pageNO-1)*pageSize);
		bean.setMaxNum(pageSize);
		bean.setStr(wxPublicNo);
		List<Map<Object, Object>> imageTextList = new ArrayList<Map<Object, Object>>();
		List<AdminChildInfo> list = adminadministratordao.selectAdminChildInfoByList(bean);
		return imageTextList;
	}*/
	
	/**
	 * 删除二级管理员
	 */
	public int deleteAdminChildInfoById(String adminid) throws Exception {
		return adminadministratordao.deleteAdminChildInfoById(adminid);
		
	}
	/**
	 * 根据id查找二级管理员
	 */
	public AdminChildInfo selectAdminChildInfoById(String adminid) throws Exception {
		// TODO Auto-generated method stub
		return adminadministratordao.selectAdminChildInfoById(adminid);
	}
	/**
	 * 根據id修改二級管理員
	 */
	public Integer updateAdminChildInfoById(AdminChildInfo adminchildinfo) throws Exception {
		return adminadministratordao.updateAdminChildInfoById(adminchildinfo);
	}
	/**
	 *根据id修改二级管理员权限 
	 */
	public Integer updatePermissionsById(String adminid, String adminStatus) throws Exception {
		// TODO Auto-generated method stub
		return adminadministratordao.updatePermissionsById(adminid,adminStatus);
	}
	/**
	 * 查询所有管理员所有条数
	 */
	public int selectAdminChildInfoByCount(int pageSize) {
		int count = adminadministratordao.selectAdminChildInfoByCount();
		count = count % pageSize == 0? count/pageSize:(count/pageSize)+1;
		return count;
	}
	
	/**
	 * 模糊查询所有管理员所有条数
	 */
	public int selectAdminChildInfoByNameCount(String adminLoginName, int pageSize) {
		int count = adminadministratordao.selectAdminChildInfoByNameCount(adminLoginName);
		count = count % pageSize == 0? count/pageSize:(count/pageSize)+1;
		return count;
	}
	/**
	 * 修改二级管理员密码
	 */
	public void updateAdminByPwd(AdminChildInfo adminchildinfo) {
		// TODO Auto-generated method stub
		adminadministratordao.updateAdminByPwd(adminchildinfo);
	}
	/**
	 * 修改超级管理员密码
	 */
	public void updateSuperAdminByPwd(AdminInfo admininfo) {
		// TODO Auto-generated method stub
		adminadministratordao.updateSuperAdminByPwd(admininfo);
	}
}
