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

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
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.security.authentication.NKSecurityContext;
import net.northking.cctp.executePlan.db.dao.AtuPlanScriptLinkMdDao;
import net.northking.cctp.executePlan.db.service.AtuPlanScriptLinkMdService;
import net.northking.cctp.executePlan.db.entity.AtuPlanScriptLinkMd;

import net.northking.cctp.common.db.BasicDao;
import net.northking.cctp.common.db.PaginationService;

import net.northking.cctp.executePlan.dto.planScript.AtuPlanScriptDeleteDto;
import net.northking.cctp.executePlan.dto.planScript.AtuPlanScriptLinkDto;
import net.northking.cctp.executePlan.feign.dto.PlanScriptQueryPageDto;
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-09-04 09:44:18  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "AtuPlanScriptLinkMdServiceImpl")
public class AtuPlanScriptLinkMdServiceImpl extends PaginationService<AtuPlanScriptLinkMd> implements AtuPlanScriptLinkMdService
{
private static final Logger logger = LoggerFactory.getLogger(AtuPlanScriptLinkMdServiceImpl.class);

  private final AtuPlanScriptLinkMdDao atuPlanScriptLinkMdDao;

  public AtuPlanScriptLinkMdServiceImpl(AtuPlanScriptLinkMdDao atuPlanScriptLinkMdDao) {this.atuPlanScriptLinkMdDao = atuPlanScriptLinkMdDao;}

  public BasicDao<AtuPlanScriptLinkMd> getDao() {return atuPlanScriptLinkMdDao;}

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

  @Override
  protected void beforeInsert(AtuPlanScriptLinkMd record) {

  }

  @Override
  protected void beforeUpdate(AtuPlanScriptLinkMd record) {

  }

  @Override
  public List<AtuPlanScriptLinkDto> queryLinkMdPage(String planId,List<String> selectList) {
    return atuPlanScriptLinkMdDao.queryLinkMdPage(planId,NKSecurityContext.getUserId(),new ArrayList<>());
  }

  @Override
  public Integer deleteLinkMd(AtuPlanScriptDeleteDto deleteDto) {
    return atuPlanScriptLinkMdDao.deleteLinkMd(deleteDto);
  }

  @Override
  public Integer insertMdBatch(List<AtuPlanScriptLinkMd> list) {
    return atuPlanScriptLinkMdDao.insertMdBatch(list);
  }

  @Override
  public Pagination<String> queryScriptLink(QueryByPage<PlanScriptQueryPageDto> dto) {
    DefaultPagination<String> pagination = new DefaultPagination<>();
    Page<AtuPlanScriptLinkDto> page = PageHelper.startPage(dto.getPageNo(), dto.getPageSize());
    List<AtuPlanScriptLinkDto> list = atuPlanScriptLinkMdDao.queryLinkMdPage(dto.getQuery().getPlanId(), NKSecurityContext.getUserId(),dto.getQuery().getScriptList());

    List<String> listId = new ArrayList<>();
    list.forEach( one ->{listId.add(one.getScriptId());});

    pagination.setRecords(listId);
    pagination.setPageNo(dto.getPageNo());
    pagination.setPageSize(dto.getPageSize());
    pagination.setRecordCount(page.getTotal());
    return pagination;
  }


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




}

