package com.happy.service.impl;

import com.happy.Model.Admin;
import com.happy.Model.HotelDict;
import com.happy.dao.HotelDictDao;
import com.happy.dto.IPage;
import com.happy.service.HotelDictService;
import org.springframework.stereotype.Service;

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

@Service("HotelDictService")
public class HotelDictImplService implements HotelDictService {

    @Resource
    public HotelDictDao hotelDictDao;

    @Override
    public int insertHotelDict(HotelDict hotelDict) {
        return hotelDictDao.insertHotelDict(hotelDict);
    }

    @Override
    public int updateHotelDict(HotelDict hotelDict) {
        return hotelDictDao.updateHotelDict(hotelDict);
    }

    @Override
    public int delHotelDict(int id) {
        return hotelDictDao.delHotelDict(id);
    }

    @Override
    public HotelDict getById(int id) {
        return hotelDictDao.getById(id);
    }

    @Override
    public String getDictNameById(int id) {
        HotelDict hotelDict = hotelDictDao.getById(id);
        if(hotelDict!=null) return hotelDict.getName();
        return null;
    }

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

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

    @Override
    public String setConfig(String ids) {
        if("".equals(ids)) return "";
        return hotelDictDao.setConfig(ids);
    }

    @Override
    public int saveBacth(List<HotelDict> dicts) {
        return hotelDictDao.saveBacth(dicts);
    }


}
