package com.mortals.xhx.module.attendance.dao.ibatis;


import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.ParamDto;
import com.mortals.framework.model.Result;
import com.mortals.xhx.module.attendance.dao.AttendanceStatDao;
import com.mortals.xhx.module.attendance.model.AttendanceStatEntity;
import com.mortals.xhx.module.attendance.model.vo.AttendanceSummaryQuery;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
* 考勤汇总信息DaoImpl DAO接口
*
* @author zxfei
* @date 2023-04-08
*/
@Repository("attendanceStatDao")
public class AttendanceStatDaoImpl extends BaseCRUDDaoMybatis<AttendanceStatEntity,Long> implements AttendanceStatDao {


    @Override
    public AttendanceStatEntity queryEntity(Long staffId) {
        return getSqlSession().selectOne(getSqlId("queryEntity"),staffId);
    }

    @Override
    public Result<AttendanceStatEntity> getListExt(AttendanceSummaryQuery params, PageInfo pageInfo) {
        Result result = new Result();
        List list = null;
        if (pageInfo.isCountPage()) {
            int count = this.getCountExt(params);
            if (count == 0) {
                list = new ArrayList();
            } else if (pageInfo.getPrePageResult() == -1) {
                list = this.getSqlSession().selectList(this.getSqlId("getListExt"), params);
            } else {
                RowBounds rowBounds = new RowBounds(pageInfo.getBeginIndex(), pageInfo.getPrePageResult());
                list = this.getSqlSession().selectList(this.getSqlId("getListExt"), params, rowBounds);
            }

            pageInfo.setTotalResult(count);
            result.setPageInfo(pageInfo);
            result.setList((List)list);
        } else {
            if (pageInfo.getPrePageResult() == -1) {
                list = this.getSqlSession().selectList(this.getSqlId("getListExt"), params);
            } else {
                RowBounds rowBounds = new RowBounds(pageInfo.getBeginIndex(), pageInfo.getPrePageResult());
                list = this.getSqlSession().selectList(this.getSqlId("getListExt"), params, rowBounds);
            }

            pageInfo.setTotalResult(-1);
            result.setPageInfo(pageInfo);
            result.setList(list);
        }
        return result;
    }

    public int getCountExt(AttendanceSummaryQuery paramDto) {
        return (Integer)this.getSqlSession().selectOne(this.getSqlId("getListCountExt"), paramDto);
    }
}
