package org.fouram.service;

import java.util.List;

import org.fouram.core.base.model.Page;
import org.fouram.core.base.model.PageData;
import org.fouram.core.base.service.BaseService;
import org.fouram.entity.SysUser;
import org.springframework.stereotype.Service;

@Service
public class SysUserService extends BaseService {

	/*
	 * 新增
	 */
	public void save(PageData pd) throws Exception {
		save("SysUserMapper.save", pd);
	}

	/*
	 * 删除系统用户
	 */
	public void delete(PageData pd) throws Exception {
		update("SysUserMapper.delete", pd);
	}

	/*
	 * 修改
	 */
	public void edit(PageData pd) throws Exception {
		update("SysUserMapper.edit", pd);
	}

	/*
	 * 列表
	 */
	@SuppressWarnings("unchecked")
	public List<PageData> list(Page page) throws Exception {
		return (List<PageData>) findList("SysUserMapper.listPage", page);
	}

	/*
	 * 列表(全部)
	 */
	@SuppressWarnings("unchecked")
	public List<PageData> listAll(PageData pd) throws Exception {
		return (List<PageData>) findList("SysUserMapper.listAll", pd);
	}

	/*
	 * 通过id获取数据
	 */
	public PageData findById(PageData pd) throws Exception {
		return (PageData) findObject("SysUserMapper.findById", pd);
	}

	/*
	 * 通过手机号获取数据
	 */
	public PageData findByPhone(PageData pd) throws Exception {
		return (PageData) findObject("SysUserMapper.findByPhone", pd);
	}

	/*
	 * 通过user_name获取数据
	 */
	public PageData findByName(PageData pd) throws Exception {
		return (PageData) findObject("SysUserMapper.findByName", pd);
	}

	/**
	 * 根据id 更新状态
	 * 
	 * @param pd
	 * @throws Exception
	 */
	public void updateStatusById(PageData pd) throws Exception {
		update("SysUserMapper.updateStatusById", pd);
	}

	/*
	 * 查询列表总数
	 */
	public Long findCount(PageData pd) throws Exception {
		return (Long) findObject("SysUserMapper.findCount", pd);
	}

	/*
	 * 批量删除
	 */
	public void deleteAll(String[] ArrayDATA_IDS) throws Exception {
		delete("SysUserMapper.deleteAll", ArrayDATA_IDS);
	}

	/**
	 * 登录查询
	 * 
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	public PageData checkLogin(PageData pd) throws Exception {
		return (PageData) findObject("SysUserMapper.checkLogin", pd);
	}

	public SysUser getUserInfoByNameAndPwd(PageData pd) throws Exception {
		return (SysUser) findObject("SysUserMapper.getUserInfoByNameAndPwd", pd);
	}

	public void updateLastLogin(PageData pd) throws Exception {
		update("SysUserMapper.updateLastLogin", pd);
	}
}
