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

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
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.db.PaginationService;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.scriptcase.db.dao.AtuCaseDataSetDao;
import net.northking.cctp.scriptcase.db.entity.AtuCaseDataSet;
import net.northking.cctp.scriptcase.db.entity.AtuScriptInfo;
import net.northking.cctp.scriptcase.db.service.AtuCaseDataSetService;
import net.northking.cctp.scriptcase.dto.IdAndStatusDto;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptInfo.PrincipalUpdateDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseScriptQueryDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseScriptResultDto;
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;


/**
 * 用例集目录表
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2023-08-26 14:52:39  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "AtuCaseDataSetServiceImpl")
public class AtuCaseDataSetServiceImpl extends PaginationService<AtuCaseDataSet> implements AtuCaseDataSetService
{
private static final Logger logger = LoggerFactory.getLogger(AtuCaseDataSetServiceImpl.class);

  private final AtuCaseDataSetDao atuCaseDataSetDao;

  public AtuCaseDataSetServiceImpl(AtuCaseDataSetDao atuCaseDataSetDao) {this.atuCaseDataSetDao = atuCaseDataSetDao;}

  public BasicDao<AtuCaseDataSet> getDao() {return atuCaseDataSetDao;}

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

  @Override
  protected void beforeInsert(AtuCaseDataSet record) {

  }

  @Override
  protected void beforeUpdate(AtuCaseDataSet record) {

  }

  @Override
  public List<AtuCaseDataSet> querySetByName(AtuCaseDataSet dto) {
    return this.atuCaseDataSetDao.querySetByName(dto);
  }

  @Override
  public List<AtuCaseDataSet> queryTreeNode(List<String> list) {
    return this.atuCaseDataSetDao.queryTreeNode(list);
  }

  @Override
  public void replaceTreeSet(List<AtuCaseDataSet> setList) {
      this.atuCaseDataSetDao.replaceTreeSet(setList);
  }

  @Override
  public List<AtuScriptInfo> queryScriptByPath(String parentId) {
    return atuCaseDataSetDao.queryScriptByPath(parentId);
  }

  @Override
  public List<String> queryByPath(String path) {
    return atuCaseDataSetDao.queryByPath(path);
  }

  @Override
  public Pagination<AtuCaseScriptResultDto> queryCommonNode(QueryByPage<AtuCaseScriptQueryDto> dto) {
    DefaultPagination<AtuCaseScriptResultDto> pagination = new DefaultPagination<>();
    Page<AtuCaseScriptResultDto> page = PageHelper.startPage(dto.getPageNo(), dto.getPageSize());
    List<AtuCaseScriptResultDto> pageDto = atuCaseDataSetDao.queryCommonNode(dto.getQuery());
    pagination.setPageNo(dto.getPageNo());
    pagination.setPageSize(dto.getPageSize());
    pagination.setRecordCount(page.getTotal());
    pagination.setRecords(pageDto);
    return pagination;
  }

  @Override
  public Pagination<AtuCaseScriptResultDto> querySceneNode(QueryByPage<AtuCaseScriptQueryDto> dto) {
    DefaultPagination<AtuCaseScriptResultDto> pagination = new DefaultPagination<>();
    Page<AtuCaseScriptResultDto> page = PageHelper.startPage(dto.getPageNo(), dto.getPageSize());
    List<AtuCaseScriptResultDto> pageDto = atuCaseDataSetDao.querySceneNode(dto.getQuery());
    pageDto.forEach( one ->{one.setScriptType("5");});
    pagination.setPageNo(dto.getPageNo());
    pagination.setPageSize(dto.getPageSize());
    pagination.setRecordCount(page.getTotal());
    pagination.setRecords(pageDto);
    return pagination;
  }

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

  @Override
  public List<AtuCaseScriptResultDto> queryScriptPage(List<String> list, String setName) {
    List<AtuCaseScriptResultDto> scriptList = new ArrayList<>();

    List<AtuCaseScriptResultDto> commonList = atuCaseDataSetDao.queryCommonList(list,setName);
    if (commonList.size() > 0) {
      scriptList.addAll(commonList);
    }
    List<AtuCaseScriptResultDto> sceneList = atuCaseDataSetDao.querySceneList(list,setName);
    if (sceneList.size() > 0) {
      scriptList.addAll(sceneList);
    }
    return scriptList;
  }

  @Override
  public List<AtuCaseDataSet> queryPlanScriptByPath(String proId, String path) {
    return atuCaseDataSetDao.queryPlanScriptByPath(proId,path);
  }

  @Override
  public List<AtuCaseDataSet> querySetByList(List<String> list) {
    return atuCaseDataSetDao.querySetByList(list);
  }

  @Override
  public AtuCaseDataSet queryAtuCaseDataSetByScriptId(String scriptId) {
    return atuCaseDataSetDao.queryAtuCaseDataSetByScriptId(scriptId);
  }

  @Override
  public List<String> queryScriptIdBySetIdList(List<Object> batch) {
    return atuCaseDataSetDao.queryScriptIdBySetIdList(batch);
  }

  /**
   * 用例集管理查询所有用例集 包括一般用力集，场景用例集
   * @param dto
   * @return
   */
  @Override
  public Pagination<AtuCaseScriptResultDto> queryCommonNodeAndSceneNode(QueryByPage<AtuCaseScriptQueryDto> dto) {
    DefaultPagination<AtuCaseScriptResultDto> pagination = new DefaultPagination<>();
    Page page = PageHelper.startPage(dto.getPageNo(), dto.getPageSize(), "createdTime DESC");
    List<AtuCaseScriptResultDto> pageDto = atuCaseDataSetDao.queryCommonNodeAndSceneNode(dto.getQuery());
    pagination.setPageNo(dto.getPageNo());
    pagination.setPageSize(dto.getPageSize());
    pagination.setRecordCount(page.getTotal());
    pagination.setRecords(pageDto);
    return pagination;
  }

  @Override
  public List<IdAndStatusDto> picusQueryByScriptIds(List<String> ids) {
    return atuCaseDataSetDao.picusQueryDeletedByScriptIds(ids);
  }

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

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

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







}

