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

import net.northking.cctp.common.db.BasicService;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.db.annotation.DatabaseReadOnly;
import net.northking.cctp.common.db.excel.AbstractExcelService;
import net.northking.cctp.common.db.excel.ExcelHeader;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.scriptcase.db.entity.AtuScriptVersion;
import net.northking.cctp.scriptcase.db.service.AtuScriptVersionService;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptVersion.AtuScriptVersionDetailDto;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptVersion.AtuScriptVersionQueryDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 脚本版本信息表服务实现类
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */

@Service
@ConditionalOnMissingBean(name = "AtuScriptVersionApiServiceImpl")
public class AtuScriptVersionApiServiceImpl extends AbstractExcelService<AtuScriptVersion> implements AtuScriptVersionApiService
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(AtuScriptVersionApiServiceImpl.class);

  @Autowired
  private AtuScriptInfoApiService atuScriptInfoApiService;
  @Autowired
  private AtuScriptVersionService atuScriptVersionService;

  //= Excel 导入导出相关代码 start ==================//
  @Override
  public BasicService<AtuScriptVersion> getService()
  {
    return this.atuScriptVersionService;
  }

  @Override
  public ExcelHeader[] excelHeaders()
  {
    ExcelHeader scriptId = new ExcelHeader("脚本ID", "scriptId", String.class);
    ExcelHeader versionId = new ExcelHeader("脚本版本ID", "versionId", Integer.class);
    ExcelHeader versionName = new ExcelHeader("版本名称", "versionName", String.class);
    ExcelHeader scriptName = new ExcelHeader("脚本名称", "scriptName", String.class);
    ExcelHeader url = new ExcelHeader("脚本版本内容地址", "url", String.class);
    ExcelHeader dataUrl = new ExcelHeader("脚本版本数据地址", "dataUrl", String.class);
    ExcelHeader projectId = new ExcelHeader("系统ID", "projectId", String.class);
    ExcelHeader tenentId = new ExcelHeader("租户号", "tenentId", String.class);
    ExcelHeader createdBy = new ExcelHeader("创建人", "createdBy", String.class);
    ExcelHeader createdTime = new ExcelHeader("创建时间", "createdTime", Date.class);
    ExcelHeader updatedBy = new ExcelHeader("更新人", "updatedBy", String.class);
    ExcelHeader updatedTime = new ExcelHeader("更新时间", "updatedTime", Date.class);
    return new ExcelHeader[]{};
  }

  /**
   * Excel导入，入库之前的处理
   * @param records 从Excel读取到的记录
   * @return 待入库的记录
   */
  @Override
  protected List<AtuScriptVersion> beforeInsertBatch(List<AtuScriptVersion> records)
  {
    return records;
  }

  /**
   * 写入Excel之前的处理<br>
   * 数据的特殊处理在此处加工处理
   *
   * @param record 来自数据库记录
   * @return 待写入Excel的记录
   */
  @Override
  protected AtuScriptVersion beforeWriteExcel(AtuScriptVersion record)
  {
    return record;
  }

  //= Excel 导入导出相关代码 end =======================//

  //= 增删改查 相关代码 start ==================//
  @Override
  @DatabaseReadOnly
  public Pagination<AtuScriptVersionDetailDto> pagingQuery(QueryByPage<AtuScriptVersionQueryDto> queryByPage)
  {
    return this.atuScriptVersionService.pagingQuery(queryByPage);
  }

  @Override
  @DatabaseReadOnly
  public List<AtuScriptVersion> scriptVersionList(String scriptId) {
    AtuScriptVersion query = new AtuScriptVersion();
    query.setScriptId(scriptId);
    return atuScriptVersionService.query(query);
  }

}
