package com.ym.mec.biz.service.impl;

import com.ym.mec.biz.dal.dto.PageInfoTenantDto;
import com.ym.mec.biz.dal.page.TenantAccountDetailQueryInfo;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.util.collection.MapUtil;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.SysTenantAccountDetailDao;
import com.ym.mec.biz.dal.entity.SysTenantAccountDetail;
import com.ym.mec.biz.service.SysTenantAccountDetailService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysTenantAccountDetailServiceImpl extends BaseServiceImpl<Long, SysTenantAccountDetail> implements SysTenantAccountDetailService {

    @Autowired
    private SysTenantAccountDetailDao sysTenantAccountDetailDao;

    @Override
    public BaseDAO<Long, SysTenantAccountDetail> getDAO() {
        return sysTenantAccountDetailDao;
    }

    @Override
    public PageInfoTenantDto<SysTenantAccountDetail> getPageList(TenantAccountDetailQueryInfo queryInfo) {
        PageInfoTenantDto<SysTenantAccountDetail> pageInfo = new PageInfoTenantDto<>(queryInfo.getPage(), queryInfo.getRows());
        Map<String, Object> params = new HashMap<String, Object>();
        MapUtil.populateMap(params, queryInfo);

        List<SysTenantAccountDetail> dataList = null;
        int count = this.findCount(params);
        if (count > 0) {
            pageInfo.setTotal(count);
            params.put("offset", pageInfo.getOffset());
            dataList = this.getDAO().queryPage(params);
            Integer totalTransMinutes = sysTenantAccountDetailDao.sumTransMinutes(params);
            if (totalTransMinutes != null) {
                pageInfo.setTotalTransMinutes(totalTransMinutes);
            }
        }
        if (count == 0) {
            dataList = new ArrayList<>();
        }
        pageInfo.setRows(dataList);
        return pageInfo;
    }
}