/*
* Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.
*
*/
package net.northking.cctp.platform.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.platform.db.dao.CpComponentListDao;
import net.northking.cctp.platform.db.service.CpComponentListService;
import net.northking.cctp.platform.db.entity.CpComponentList;

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

import net.northking.cctp.platform.dto.comlibrary.CpComLibraryTree;
import net.northking.cctp.platform.dto.comlibrary.CpComponentListDetailDto;
import net.northking.cctp.platform.dto.comlibrary.CpComponentListQueryDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 组件清单
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2022-08-29 10:24:48  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "CpComponentListServiceImpl")
public class CpComponentListServiceImpl extends TenantEntityService<CpComponentList> implements CpComponentListService
{
private static final Logger logger = LoggerFactory.getLogger(CpComponentListServiceImpl.class);

  private final CpComponentListDao cpComponentListDao;

  public CpComponentListServiceImpl(CpComponentListDao cpComponentListDao) {this.cpComponentListDao = cpComponentListDao;}

  public BasicDao<CpComponentList> getDao() {return cpComponentListDao;}

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

  @Override
  public List<CpComLibraryTree> queryComListTree(CpComponentList query) {
    //super.initTenantId(query);
    return cpComponentListDao.queryComListTree(query);
  }

  @Override
  public Pagination<CpComponentListDetailDto> pagingQueryNew(QueryByPage<CpComponentListQueryDto> queryByPage) {
    int pageNo = queryByPage.getPageNo();
    int pageSize = queryByPage.getPageSize();
    OrderBy orderBy = queryByPage.toSqlOrderBy();
    CpComponentListQueryDto queryData = queryByPage.getQuery();
    CpComponentList query = new CpComponentList();
    BeanUtils.copyProperties(queryData,query);
    query.setComName(queryData.getSelectName());
    query.setComAlias(queryData.getSelectAlias());
    if (pageNo <= 0) {
      pageNo = 1;
    }

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

    DefaultPagination<CpComponentListDetailDto> pagination = new DefaultPagination();
    pagination.setPageSize(pageSize);
    pagination.setPageNo(pageNo);
    OrderBy sort = orderBy;

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

    Page<CpComponentListDetailDto> page = PageMethod.startPage(pageNo, pageSize);
    List<CpComponentListDetailDto> result = cpComponentListDao.pagingQuery(query);

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

  @Override
  public List<CpComponentList> queryRecordList(CpComponentList entity) {
    return cpComponentListDao.queryRecordList(entity);
  }

}

