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


import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.xhx.module.business.model.BusinessMatterQuery;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.business.dao.BusinessMatterDao;
import com.mortals.xhx.module.business.model.BusinessMatterEntity;

import java.util.ArrayList;
import java.util.Date;

import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;

import java.util.List;

/**
 * 业务事项关联DaoImpl DAO接口
 *
 * @author zxfei
 * @date 2022-01-12
 */
@Repository("businessMatterDao")
public class BusinessMatterDaoImpl extends BaseCRUDDaoMybatis<BusinessMatterEntity, Long> implements BusinessMatterDao {

    @Override
    public Result<BusinessMatterEntity> getListByBusiness(BusinessMatterQuery params, PageInfo pageInfo) {
        Result<BusinessMatterEntity> result = new Result();
        List list = null;
        //判断是否计算总页数与总条数
        int count =this.getSqlSession().selectOne(this.getSqlId("getListByBusinessCount"), getQueryParam(params));

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

        return result;

    }

    @Override
    public Result<BusinessMatterEntity> getListByMatter(BusinessMatterQuery params, PageInfo pageInfo) {
        Result<BusinessMatterEntity> result = new Result();
        List list = null;
        //判断是否计算总页数与总条数
        int count =this.getSqlSession().selectOne(this.getSqlId("getListByMatterCount"), getQueryParam(params));

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

        return result;
    }
}
