package com.mortals.xhx.module.sheet.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.sheet.dao.SheetMatterDao;
import com.mortals.xhx.module.sheet.model.SheetMatterEntity;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

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

/**
* 基础事项DaoImpl DAO接口
*
* @author zxfei
* @date 2022-09-27
*/
@Repository("sheetMatterDao")
public class SheetMatterDaoImpl extends BaseCRUDDaoMybatis<SheetMatterEntity,Long> implements SheetMatterDao {


    @Override
    public Result<SheetMatterEntity> getSubList(SheetMatterEntity matterQuery, PageInfo pageInfo) {
        Result<SheetMatterEntity> result = new Result();
        ParamDto paramDto = this.getQueryParam(matterQuery);
        int count = this.getSubCount(paramDto);
        List list = null;
        if (count == 0) {
            list = new ArrayList();
        } else if (pageInfo.getPrePageResult() == -1) {
            list = this.getSqlSession().selectList(this.getSqlId(SQLID_SUB_LIST), paramDto);
        } else {
            RowBounds rowBounds = new RowBounds(pageInfo.getBeginIndex(), pageInfo.getPrePageResult());
            list = this.getSqlSession().selectList(this.getSqlId(SQLID_SUB_LIST), this.cpyQueryParamDto(paramDto), rowBounds);
        }
        pageInfo.setTotalResult(count);
        result.setPageInfo(pageInfo);
        result.setList(list);
        return result;
    }

    public int getSubCount(ParamDto paramDto) {
        return this.getSqlSession().selectOne(this.getSqlId(SQLID_SUB_COUNT), this.cpyQueryParamDto(paramDto));
    }

}
