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

import net.northking.cctp.common.db.PaginationService;
import net.northking.cctp.common.security.authentication.NKSecurityContext;
import net.northking.cctp.dw.db.dao.MidProjectInfoDao;
import net.northking.cctp.dw.db.service.MidProjectInfoService;
import net.northking.cctp.dw.db.entity.MidProjectInfo;

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

import net.northking.cctp.dw.dto.MidProjectInfoAddDto;
import net.northking.cctp.dw.dto.ProjectDataVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * 系统信息中间表
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2021-12-16 11:43:35  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "MidProjectInfoServiceImpl")
public class MidProjectInfoServiceImpl extends PaginationService<MidProjectInfo> implements MidProjectInfoService
{
private static final Logger logger = LoggerFactory.getLogger(MidProjectInfoServiceImpl.class);

  private final MidProjectInfoDao midProjectInfoDao;

  public MidProjectInfoServiceImpl(MidProjectInfoDao midProjectInfoDao) {this.midProjectInfoDao = midProjectInfoDao;}

  public BasicDao<MidProjectInfo> getDao() {return midProjectInfoDao;}

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

  @Override
  protected void beforeInsert(MidProjectInfo midProjectInfo) {

  }

  @Override
  protected void beforeUpdate(MidProjectInfo midProjectInfo) {

  }

  /**
   * 新增或修改信息
   *
   * @param dto
   */
  @Override
  public void addOrUpdateInfo(MidProjectInfoAddDto dto) {
    MidProjectInfo entity = createEntity();
    entity.setProjectId(dto.getProjectId());
    List<MidProjectInfo> query = midProjectInfoDao.query(entity);

    entity.setStartTime(dto.getStartTime());
    entity.setTenantId(NKSecurityContext.getTenantId());
    entity.setProductionTime(dto.getProductionTime());

    if (CollectionUtils.isEmpty(query)) {
      midProjectInfoDao.insert(entity);
    } else {
      entity.setId(query.get(0).getId());
      midProjectInfoDao.updateById(entity);
    }
  }

  /**
   * 逻辑删除
   *
   * @param projectIds
   */
  @Override
  public void deleteByProjectIds(List<String> projectIds) {
    midProjectInfoDao.deleteByProjectIds(projectIds);
  }

  @Override
  public List<String> findByTenantId(String tenantId) {
    return midProjectInfoDao.findByTenantId(tenantId);
  }

  @Override
  public List<MidProjectInfo> findByProjectIds(List<MidProjectInfo> dataList) {
    return midProjectInfoDao.findByProjectIds(dataList);
  }

  @Override
  public ProjectDataVo getFinishedProjectAmountByTenantId(String tenantId,List<String> projectIds) {
    return midProjectInfoDao.getFinishedProjectAmountByTenantId(tenantId,projectIds);
  }

  @Override
  public List<ProjectDataVo> getProjectStatuss(List<String> projectIds) {
    return midProjectInfoDao.getProjectStatuss(projectIds);
  }


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

}

