/*
* 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 com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ApiScriptOptionVO;
import net.northking.cctp.common.db.BasicDao;
import net.northking.cctp.common.db.DefaultPagination;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.saas.db.TenantEntityService;
import net.northking.cctp.scriptcase.db.dao.AtuScriptInfoDao;
import net.northking.cctp.scriptcase.db.entity.AtuScriptInfo;
import net.northking.cctp.scriptcase.db.service.AtuScriptInfoService;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptGroup.PublishScriptQueryDto;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptInfo.AtuScriptInfoDetailDto;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptInfo.AtuScriptInfoQueryDto;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptInfo.PrincipalUpdateDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;


/**
 * 脚本信息表
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2022-10-18 17:29:31  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "AtuScriptInfoServiceImpl")
public class AtuScriptInfoServiceImpl extends TenantEntityService<AtuScriptInfo> implements AtuScriptInfoService
{
private static final Logger logger = LoggerFactory.getLogger(AtuScriptInfoServiceImpl.class);

  private final AtuScriptInfoDao atuScriptInfoDao;

  public AtuScriptInfoServiceImpl(AtuScriptInfoDao atuScriptInfoDao) {this.atuScriptInfoDao = atuScriptInfoDao;}

  public BasicDao<AtuScriptInfo> getDao() {return atuScriptInfoDao;}

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

  @Override
  public Integer countScriptByScriptName(String scriptName, String projectId) {
    return atuScriptInfoDao.countScriptByScriptName(scriptName,projectId);
  }

  @Override
  public List<AtuScriptInfoDetailDto> queryScriptList(QueryByPage<AtuScriptInfoQueryDto> query) {
    return atuScriptInfoDao.queryScriptList(query);
  }

  @Override
  public Integer deleteScriptList(AtuScriptInfo scriptInfo, List<String> scriptIds) {
    return atuScriptInfoDao.deleteScriptList(scriptInfo, scriptIds);
  }

  @Override
  public List<AtuScriptInfo> findScriptCopyNum(String projectId, String scriptName) {
    return atuScriptInfoDao.findScriptCopyNum(projectId, scriptName);
  }

  @Override
  public List<AtuScriptInfo> queryScriptByIds(List<String> scriptIds) {
    if (scriptIds == null || scriptIds.isEmpty()) {
      return new ArrayList<>();
    }
    return atuScriptInfoDao.queryScriptByIds(scriptIds);
  }

  @Override
  public Pagination<AtuScriptInfo> queryAppByScript(QueryByPage<List<String>> queryByPage) {
    DefaultPagination<AtuScriptInfo> pagination = new DefaultPagination<>();
    Page<AtuScriptInfo> page = PageMethod.startPage(queryByPage.getPageNo(), queryByPage.getPageSize());
    //查询脚本关联的软件 (已去重)
    List<AtuScriptInfo> infoList = this.atuScriptInfoDao.queryAppByScript(queryByPage.getQuery());
    pagination.setPageNo(queryByPage.getPageNo());
    pagination.setPageSize(queryByPage.getPageSize());
    pagination.setRecords(infoList);
    pagination.setRecordCount(page.getTotal());
    return pagination;
  }

  @Override
  public AtuScriptInfo queryScriptInfo(String caseId) {
    return this.atuScriptInfoDao.queryScriptInfoByCase(caseId);
  }

  @Override
  public List<AtuScriptInfo> queryAppByCaseId(List<String> scriptIds) {
    List<AtuScriptInfo> infoList = this.atuScriptInfoDao.queryAppByScript(scriptIds);
    return infoList;
  }

  @Override
  public List<AtuScriptInfoDetailDto> getPublishScriptList(PublishScriptQueryDto dto) {
    return this.atuScriptInfoDao.getPublishScriptList(dto);
  }

    @Override
    public List<AtuScriptInfoDetailDto> queryScriptDetailList(Set<String> scriptIdSet) {
        return this.atuScriptInfoDao.queryScriptDetailList(scriptIdSet);
    }

  @Override
  public Integer updatePrincipal(PrincipalUpdateDto dto) {
    return this.atuScriptInfoDao.updatePrincipal(dto);
  }

    @Override
    public List<String> queryScriptPlatforms(Set<String> scriptIdSet) {
        return this.atuScriptInfoDao.queryScriptPlatforms(scriptIdSet);
    }

  @Override
  public List<String> selectManagerByProject(String projectId) {
    return this.atuScriptInfoDao.selectManagerByProject(projectId);
  }

  @Override
  public List<String> selectCreatorByProject(String projectId) {
    return this.atuScriptInfoDao.selectCreatorByProject(projectId);
  }

  @Override
  public List<String> selectUpdaterByProject(String projectId) {
    return this.atuScriptInfoDao.selectUpdaterByProject(projectId);
  }

  @Override
  public List<ApiScriptOptionVO> queryScriptVOList(List<String> scriptIdList) {
    return this.atuScriptInfoDao.queryScriptVOList(scriptIdList);
  }

  @Override
  public List<ApiScriptOptionVO> queryScriptVOByCodeAndSystemId(String scriptCode, String systemId) {
    return this.atuScriptInfoDao.queryScriptVOByCodeAndSystemId( scriptCode,  systemId);
  }
}

