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

import com.alibaba.fastjson.JSON;
import net.northking.cctp.dw.db.dao.BugStatusStatisticsDao;
import net.northking.cctp.dw.db.entity.SynBugInfo;
import net.northking.cctp.dw.db.service.BugStatusStatisticsService;
import net.northking.cctp.dw.db.entity.BugStatusStatistics;

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

import net.northking.cctp.dw.db.service.SynBugInfoService;
import net.northking.cctp.dw.dto.BugStatusStatisticsDetailDto;
import net.northking.cctp.dw.dto.ChartDataGeneQueryDto;
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.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import net.northking.cctp.platform.db.entity.CltDictItem;

import java.util.List;


/**
 * 缺陷状态统计
 *
 * <p>文件内容由代码生成器产生，请不要手动修改！ <br>
 * createdate:  2021-12-15 14:58:27  <br>
 * @author:  maven-cctp-plugin  <br>
 * @since:  1.0 <br>
 */
@Service
@ConditionalOnMissingBean(name = "BugStatusStatisticsServiceImpl")
public class BugStatusStatisticsServiceImpl extends PaginationService<BugStatusStatistics> implements BugStatusStatisticsService
{
private static final Logger logger = LoggerFactory.getLogger(BugStatusStatisticsServiceImpl.class);

  private final BugStatusStatisticsDao bugStatusStatisticsDao;

  @Autowired
  private RedisTemplate redisTemplate;
  @Autowired
  private SynBugInfoService synBugInfoService;

  public BugStatusStatisticsServiceImpl(BugStatusStatisticsDao bugStatusStatisticsDao) {this.bugStatusStatisticsDao = bugStatusStatisticsDao;}

  public BasicDao<BugStatusStatistics> getDao() {return bugStatusStatisticsDao;}

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

  @Override
  protected void beforeInsert(BugStatusStatistics bugStatusStatistics) {

  }

  @Override
  protected void beforeUpdate(BugStatusStatistics bugStatusStatistics) {

  }

  @Override
  public List<BugStatusStatisticsDetailDto> listQuery(ChartDataGeneQueryDto chartDataGeneQueryDto) {
    return bugStatusStatisticsDao.listQuery(chartDataGeneQueryDto);
  }

  @Override
  public void insertBatch(List<SynBugInfo> dataList, String tenantId) {

      if (redisTemplate.opsForValue().get("UITEST-dict::" + tenantId + ":bugStatus") != null) {
        bugStatusStatisticsDao.insertBatch(JSON.parseArray(JSON.toJSONString(
                redisTemplate.opsForValue().get("UITEST-dict::" + tenantId + ":bugStatus")), CltDictItem.class), dataList,tenantId);
        bugStatusStatisticsDao.insertBatchWeekData(JSON.parseArray(JSON.toJSONString(
                redisTemplate.opsForValue().get("UITEST-dict::" + tenantId + ":bugStatus")), CltDictItem.class), dataList,tenantId);
      } else {
        logger.error("租户id为" + tenantId+"没有从缓存拿到缺陷状态列表");
      }
  }

  @Override
  public void deleteData(List<SynBugInfo> dataList, String tenantId) {
    bugStatusStatisticsDao.deleteData(dataList,tenantId);
  }

  @Override
  public List<BugStatusStatistics> queryUnresolvedBugModuleData(String projectId,List<String> endStatuss) {
    return bugStatusStatisticsDao.queryUnresolvedBugModuleData(projectId,endStatuss);
  }

  @Override
  public List<BugStatusStatistics> queryTop5TypeBugDataByTenantId(String tenantId,List<String> projectIds) {
    return bugStatusStatisticsDao.queryTop5TypeBugDataByTenantId(tenantId,projectIds);
  }


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




}

