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

import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.exception.InvalidException;
import net.northking.cctp.common.db.BasicDao;
import net.northking.cctp.common.db.PaginationService;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.executePlan.db.dao.AtuPlanTaskDao;
import net.northking.cctp.executePlan.db.entity.AtuPlanTask;
import net.northking.cctp.executePlan.db.service.AtuPlanTaskService;
import net.northking.cctp.executePlan.dto.planTask.AtuPlanTaskPageDto;
import net.northking.cctp.executePlan.dto.planTask.AtuPlanTaskQueryDto;
import net.northking.cctp.executePlan.dto.planTask.AtuTaskSendBugDto;
import net.northking.cctp.executePlan.pub.dto.ScriptFirstExecutionDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;


/**
 * 计划执行任务表
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2022-12-06 11:00:17  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "AtuPlanTaskServiceImpl")
public class AtuPlanTaskServiceImpl extends PaginationService<AtuPlanTask> implements AtuPlanTaskService
{
private static final Logger logger = LoggerFactory.getLogger(AtuPlanTaskServiceImpl.class);

  private final AtuPlanTaskDao atuPlanTaskDao;

  public AtuPlanTaskServiceImpl(AtuPlanTaskDao atuPlanTaskDao) {this.atuPlanTaskDao = atuPlanTaskDao;}

  @Override
  public BasicDao<AtuPlanTask> getDao() {return atuPlanTaskDao;}

  @Override
  public AtuPlanTask createEntity() { return new AtuPlanTask();}

  @Override
  protected void beforeInsert(AtuPlanTask record) {

  }

  @Override
  protected void beforeUpdate(AtuPlanTask record) {

  }

  @Override
  public List<AtuPlanTaskPageDto> queryList(QueryByPage<AtuPlanTaskQueryDto> queryByPage) {
    return atuPlanTaskDao.queryList(queryByPage.getQuery());
  }

  @Override
    public boolean checkBatchFinish(String batchId) {
      Integer count = atuPlanTaskDao.countUnFinishedTask(batchId);
      return count == null;
    }

  @Override
  public Long queryBatchLastTaskEndTime(String batchId) {
    return atuPlanTaskDao.queryBatchLastTaskEndTime(batchId);
  }

    @Override
    public List<AtuPlanTask> queryUnfinishedTaskByBatchId(String batchId) {
        return atuPlanTaskDao.queryUnfinishedTaskByBatchId(batchId);
    }

  @Override
  public Long queryBatchFirstTaskStartTime(String batchId) {
    return atuPlanTaskDao.queryBatchFirstTaskStartTime(batchId);
  }



  @Override
  public List<AtuPlanTaskPageDto> queryCaseListByBatchId(String batchId) {
    return atuPlanTaskDao.selectCaseListByBatchId(batchId);
  }

    @Override
    public String queryEnvIdByBatchId(String batchId) {
        return this.atuPlanTaskDao.queryEnvIdByBatchId(batchId);
    }

    @Override
    public List<String> queryAppIdListByBatchId(String batchId) {
        return this.atuPlanTaskDao.queryAppIdListByBatchId(batchId);
    }


    @Override
    public int deleteByPlanIdLimit(String planId, int num) {
        return this.atuPlanTaskDao.deleteByPlanIdLimit(planId, num);
    }

  @Override
  public int countByPlanId(String planId) {
    return this.atuPlanTaskDao.countByPlanId(planId);
  }

    @Override
    public List<String> queryMobilePerDataPathByBatchId(String batchId) {
        return this.atuPlanTaskDao.queryMobilePerDataPathByBatchId(batchId);
    }

    @Override
    public AtuTaskSendBugDto querySendBugTaskInfo(String taskId) {
        return this.atuPlanTaskDao.querySendBugTaskInfo(taskId);
    }

    @Override
    public ScriptFirstExecutionDTO getFirstExecuteInfo(String scriptId) {
      List<ScriptFirstExecutionDTO> scriptFirstExecutionDTOS = this.atuPlanTaskDao.getFirstExecuteInfo(scriptId);
      if (CollectionUtils.isEmpty(scriptFirstExecutionDTOS)) {
        return new ScriptFirstExecutionDTO();
      }
      return scriptFirstExecutionDTOS.get(0);
    }

  @Override
  public Integer getScriptExecuteSuccessNum(String scriptId, LocalDate now) {
    return this.atuPlanTaskDao.getScriptExecuteSuccessNum(scriptId, now);
  }

    @Override
    public List<AtuPlanTask> getTasksByPlanId(String planId) {
      return this.atuPlanTaskDao.getTasksByPlanId(planId);
    }

  @Override
  public List<String> getTaskIdsByScriptIdsAndPlanId(List<String> oldScriptIds, String planId) {
    return this.atuPlanTaskDao.getTaskIdsByScriptIdsAndPlanId(oldScriptIds, planId);
  }

  @Override
  public List<AtuPlanTask> queryTasksByBatchIds(List<String> batchIds) {
    if (CollectionUtils.isEmpty(batchIds)) {
      return new ArrayList<>();
    }
    return this.atuPlanTaskDao.queryTasksByBatchIds(batchIds);
  }

// ----      The End by Generator     ----//




}

