/*
 * Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.
 *
 */
package net.northking.cctp.testbug.db.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import net.northking.cctp.common.db.DefaultPagination;
import net.northking.cctp.common.db.OrderBy;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.testbug.db.dao.MqSynchronizeTaskDao;
import net.northking.cctp.testbug.db.service.MqSynchronizeTaskService;
import net.northking.cctp.testbug.db.entity.MqSynchronizeTask;

import net.northking.cctp.common.db.BasicDao;
import net.northking.cctp.common.saas.db.TenantEntityService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 缺陷同步表
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2022-03-07 10:26:57  <br>
 *
 * @author: maven-cctp-plugin  <br>
 * @since: 1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "MqSynchronizeTaskServiceImpl")
public class MqSynchronizeTaskServiceImpl extends TenantEntityService<MqSynchronizeTask> implements MqSynchronizeTaskService {
    private static final Logger logger = LoggerFactory.getLogger(MqSynchronizeTaskServiceImpl.class);

    private final MqSynchronizeTaskDao mqSynchronizeTaskDao;

    public MqSynchronizeTaskServiceImpl(MqSynchronizeTaskDao mqSynchronizeTaskDao) {
        this.mqSynchronizeTaskDao = mqSynchronizeTaskDao;
    }

    public BasicDao<MqSynchronizeTask> getDao() {
        return mqSynchronizeTaskDao;
    }

    public MqSynchronizeTask createEntity() {
        return new MqSynchronizeTask();
    }

    @Override
    public Pagination<MqSynchronizeTask> pagingQueryNew(QueryByPage<MqSynchronizeTask> queryByPage) {
        int pageNo = queryByPage.getPageNo();
        int pageSize = queryByPage.getPageSize();
        OrderBy orderBy = queryByPage.toSqlOrderBy();
        Object queryData = queryByPage.getQuery();
        MqSynchronizeTask example = queryByPage.getQuery();

        if (pageNo <= 0) {
            pageNo = 1;
        }

        if (pageSize <= 0 || pageSize > 500) {
            pageSize = 500;
        }

        DefaultPagination<MqSynchronizeTask> pagination = new DefaultPagination();
        pagination.setPageSize(pageSize);
        pagination.setPageNo(pageNo);
        OrderBy sort = orderBy;
        if (orderBy == null || orderBy.isEmpty()) {
            sort = this.defaultOrderBy();
        }

        if (sort != null && sort.isNotEmpty()) {
            PageMethod.orderBy(sort.toString());
        }

        Page<MqSynchronizeTask> page = PageMethod.startPage(pageNo, pageSize);
        List result;
        if (mqSynchronizeTaskDao == null) {
            result = this.getDao().query(example);
        } else {
            result = mqSynchronizeTaskDao.pagingQuery(example);
        }

        pagination.setRecords(result);
        pagination.setRecordCount(page.getTotal());
        return pagination;
    }

}

