/*
* Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.
*
*/
package net.northking.cctp.scriptcase.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.common.security.authentication.NKSecurityContext;
import net.northking.cctp.scriptcase.db.dao.LibraryBusComInfoDao;
import net.northking.cctp.scriptcase.db.service.LibraryBusComInfoService;
import net.northking.cctp.scriptcase.db.entity.LibraryBusComInfo;

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

import net.northking.cctp.scriptcase.dto.comLib.LibraryBusComInfoDetailDto;
import net.northking.cctp.scriptcase.dto.comLib.LibraryBusComInfoQueryDto;
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-12-06 10:53:48  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "LibraryBusComInfoServiceImpl")
public class LibraryBusComInfoServiceImpl extends TenantEntityService<LibraryBusComInfo> implements LibraryBusComInfoService
{
private static final Logger logger = LoggerFactory.getLogger(LibraryBusComInfoServiceImpl.class);

  private final LibraryBusComInfoDao libraryBusComInfoDao;

  public LibraryBusComInfoServiceImpl(LibraryBusComInfoDao libraryBusComInfoDao) {this.libraryBusComInfoDao = libraryBusComInfoDao;}

  public BasicDao<LibraryBusComInfo> getDao() {return libraryBusComInfoDao;}

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

  @Override
  public int queryCountByTreeCom(LibraryBusComInfo checkCount) {
    initTenantId(checkCount);
    return libraryBusComInfoDao.queryCountByTreeCom(checkCount);
  }

  @Override
  public List<String> checkRepeatName(String projectId,List<String> nameList, String treeId) {
    LibraryBusComInfo info = new LibraryBusComInfo();
    info.setTreeId(treeId);
    info.setIsDeleted(0);
    initTenantId(info);
    return libraryBusComInfoDao.checkRepeatName(nameList,info);
  }

  @Override
  public Pagination<LibraryBusComInfoDetailDto> pagingQueryNew(QueryByPage<LibraryBusComInfoQueryDto> queryByPage) {
    int pageNo = queryByPage.getPageNo();
    int pageSize = queryByPage.getPageSize();
    OrderBy orderBy = queryByPage.toSqlOrderBy();
    LibraryBusComInfoQueryDto query = queryByPage.getQuery();
    if (pageNo <= 0) {
      pageNo = 1;
    }
    if (pageSize <= 0 || pageSize > 500) {
      pageSize = 500;
    }
    DefaultPagination<LibraryBusComInfoDetailDto> pagination = new DefaultPagination();
    pagination.setPageSize(pageSize);
    pagination.setPageNo(pageNo);
    OrderBy sort = orderBy;
    if (orderBy == null || orderBy.isEmpty()) {
    }

    if (sort != null && sort.isNotEmpty()) {
      PageMethod.orderBy(sort.toString());
    }
    Page<LibraryBusComInfoDetailDto> page = PageMethod.startPage(pageNo, pageSize);
    initTenantId(query);
    List result = libraryBusComInfoDao.pagingQuery(query);
    pagination.setRecords(result);
    pagination.setRecordCount(page.getTotal());
    return pagination;
  }

  @Override
  public String updateByIdList(LibraryBusComInfo info, List<String> ids) {
    beforeUpdate(info);
    return libraryBusComInfoDao.updateByIdList(info,ids);
  }

  @Override
  public List<LibraryBusComInfoDetailDto> queryComListByType(LibraryBusComInfo comQuery, List<Integer> types) {
    initTenantId(comQuery);
    return libraryBusComInfoDao.queryComListByType(comQuery,types);
  }

    @Override
    public List<String> selectCreator() {
      String tenantId = NKSecurityContext.getTenantId();
      return libraryBusComInfoDao.selectCreator(tenantId);
    }

}

