package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;

import cn.estsh.i3plus.core.api.iservice.busi.ISysLogExceptionService;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.platform.platbean.SysLogException;
import cn.estsh.i3plus.pojo.platform.platrepositorymongo.SysLogExceptionRepository;
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreBsonPack;
import io.swagger.annotations.ApiOperation;
import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description :异常日志服务接口实现
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2018-11-19 17:30
 * @Modify:
 **/
@Service
public class SysLogExceptionService implements ISysLogExceptionService {
    public static final Logger LOGGER = LoggerFactory.getLogger(SysLogExceptionService.class);

    @Autowired
    private SysLogExceptionRepository sysLogExceptionRDao;

    @Override
    @ApiOperation(value = "系统异常日志复杂查询，分页，排序")
    public ListPager<SysLogException> querySysLogExceptionByPager(SysLogException sysLogException, Pager pager) {
        if(sysLogException == null) {
            pager = PagerHelper.getPager(pager, (int) sysLogExceptionRDao.count());
            return new ListPager(sysLogExceptionRDao.findAll(),pager);
        }else{
            Bson bson = CoreBsonPack.packBsonBySysLogException(sysLogException);
            pager = PagerHelper.getPager(pager,sysLogExceptionRDao.findByBsonCount(bson));
            //分页，排序
            return new ListPager(sysLogExceptionRDao.findByBsonPager(bson,pager,sysLogException.getOrderByParam()
                            ,sysLogException.getAscOrDesc()),pager);
        }
    }
}
