package com.shanghaichengdi.ghjgitem.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.shanghaichengdi.ghjgitem.domain.BoatWaterPollutantAcceptF;
import com.shanghaichengdi.ghjgitem.domain.BoatWaterPollutantWarningS;
import com.shanghaichengdi.ghjgitem.mapper.BoatWaterPollutantAcceptFMapper;
import com.shanghaichengdi.ghjgitem.service.BoatWaterPollutantAcceptFService;
import com.shanghaichengdi.ghjgitem.vo.PollutanWarningInfoVo;
import com.shanghaichengdi.ghjgitem.vo.PollutantAcceptVo;
import com.shanghaichengdi.ghjgitem.vo.request.PollutantBoatWaterReq;
import com.shanghaichengdi.ghjgitem.vo.request.PollutantWarningInfoReq;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 14390
 * @description 针对表【BOAT_WATER_POLLUTANT_ACCEPT_F】的数据库操作Service实现
 * @createDate 2024-06-18 11:48:43
 */
@Service
@Slf4j
public class BoatWaterPollutantAcceptFServiceImpl extends
    ServiceImpl<BoatWaterPollutantAcceptFMapper, BoatWaterPollutantAcceptF>
    implements BoatWaterPollutantAcceptFService {

  @Resource
  BoatWaterPollutantAcceptFMapper mapper;

  @Override
  public List<PollutantAcceptVo> selectBoatWaterList(PollutantBoatWaterReq pollutantBoatWaterReq,
      List<String> datesBetween) {
    List<String> tableNameList = new ArrayList<>();
    String partitionPrefix = "POLLUTANT_ACCEPT_F";
    datesBetween.forEach(
        x -> tableNameList.add("ghjg_bussiness.boat_water_pollutant_accept_f " + "partition(" +
            partitionPrefix + x + ")" + " t"));
    log.info("查询的表名为:{}", JSONObject.toJSONString(tableNameList));
    if (Objects.isNull(pollutantBoatWaterReq.getSource())) {
      pollutantBoatWaterReq.setSource("");
    }
    PageHelper.startPage(pollutantBoatWaterReq.getPageIndex(),
        pollutantBoatWaterReq.getPageSize());
    List<PollutantAcceptVo> voList = mapper.selectBoatWaterList(tableNameList,
        pollutantBoatWaterReq.getBoatName(),
        pollutantBoatWaterReq.getPollutantType(), pollutantBoatWaterReq.getMmsi(),
        pollutantBoatWaterReq.getSource());
    return voList;
  }

  @Override
  public List<PollutanWarningInfoVo> selectWarningInfoList(
      PollutantWarningInfoReq queryParam) {
    PageHelper.startPage(queryParam.getPageIndex(),
        queryParam.getPageSize());
    List<PollutanWarningInfoVo> voList = mapper.selectWarningInfoList(queryParam);
    return voList;
  }

  @Override
  public List<PollutanWarningInfoVo> selectWarningHisInfoList(
      PollutantWarningInfoReq queryParam) {
    PageHelper.startPage(queryParam.getPageIndex(),
        queryParam.getPageSize());
    List<PollutanWarningInfoVo> voList = mapper.selectWarningHisInfoList(queryParam);
    return voList;
  }

  @Override
  public List<BoatWaterPollutantAcceptF> selectBoatWaterListSync(
      PollutantBoatWaterReq pollutantBoatWaterReq, List<String> datesBetween) {
    List<String> tableNameList = new ArrayList<>();
    String partitionPrefix = "POLLUTANT_ACCEPT_F";
    datesBetween.forEach(
        x -> tableNameList.add("ghjg_bussiness.boat_water_pollutant_accept_f " + "partition(" +
            partitionPrefix + x + ")" + " t"));
    if (Objects.isNull(pollutantBoatWaterReq.getSource())) {
      pollutantBoatWaterReq.setSource("");
    }
    PageHelper.startPage(pollutantBoatWaterReq.getPageIndex(),
        pollutantBoatWaterReq.getPageSize());
    return mapper.selectBoatWaterListSync(tableNameList,
        pollutantBoatWaterReq.getBoatName(),
        pollutantBoatWaterReq.getPollutantType(), pollutantBoatWaterReq.getMmsi(),
        pollutantBoatWaterReq.getSource(), pollutantBoatWaterReq.getStartTime(),
        pollutantBoatWaterReq.getEndTime());
  }

  @Override
  public List<BoatWaterPollutantWarningS> selectWarningInfoListSync(
      PollutantWarningInfoReq queryParam) {
    PageHelper.startPage(queryParam.getPageIndex(),
        queryParam.getPageSize());
    return mapper.selectWarningInfoListSync(queryParam);
  }
}




