package com.happy.service.impl;

import com.happy.Model.Admin;
import com.happy.Model.AdminManager;
import com.happy.dto.IPage;
import com.happy.dao.AdminManagerDao;
import com.happy.dto.ManageHouseDto;
import com.happy.dto.OwnerHouseDto;
import com.happy.dto.townshipCountDTO;
import com.happy.service.AdminManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("AdminManagerService")
public class AdminManagerImplService implements AdminManagerService {

    @Resource
    private AdminManagerDao adminManagerDao;

    @Override
    public int insertAdmin(AdminManager adminManager) {
        return adminManagerDao.insertAdmin(adminManager);
    }

    @Override
    public int updateAdmin(AdminManager adminManager) {
        return adminManagerDao.updateAdmin(adminManager);
    }

    @Override
    public int delAdmin(int id) {
        return adminManagerDao.delAdmin(id);
    }

    @Override
    public AdminManager getById(int id) {
        return adminManagerDao.getById(id);
    }

    @Override
    public IPage<AdminManager> queryPage(String sqlx, int page, int rows) {
        IPage<AdminManager> iPage = new IPage();
        List<AdminManager> adminManagerList = adminManagerDao.queryPage(sqlx,page,rows);
        int total = adminManagerDao.queryTotal(sqlx);
        iPage.setPageList(adminManagerList);
        iPage.setPage(page);
        iPage.setTotalPage( (int)Math.ceil((double)total/rows));
        iPage.setRows(rows);
        iPage.setTotal(total);
        return iPage;
    }

    @Override
    public List<AdminManager> queryList(String sqlx) {
        return adminManagerDao.queryList(sqlx);
    }

    @Override
    public AdminManager getOen(String sqlx) {
        List<AdminManager> list = adminManagerDao.queryList(sqlx);
        if(list!=null && list.size()>0) return list.get(0);
        return null;
    }

    @Override
    public List<townshipCountDTO> getTownshipCount() {
        return adminManagerDao.getTownshipCount();
    }

    @Override
    public List<townshipCountDTO> getResidueCount() {
        return adminManagerDao.getResidueCount();
    }

    @Override
    public List<ManageHouseDto> getTotalHouseCount(){
        return adminManagerDao.getTotalHouseCount();
    }

    @Override
    public List<OwnerHouseDto> getTotalManageCount(String hotelTownship, Integer type){
        return adminManagerDao.getTotalManageCount(hotelTownship, type);
    }
}
