package com.hw.ems.report.service.impl;

import com.hw.common.core.text.Convert;
import com.hw.common.core.utils.DateUtils;
import com.hw.ems.base.mapper.BaseMonitorInfoMapper;
import com.hw.ems.report.domain.ReportPointDnb;
import com.hw.ems.report.domain.ReportPointDnbDTO;
import com.hw.ems.report.mapper.ReportPointDnbMapper;
import com.hw.ems.report.service.IReportPointDnbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 电整点数据Service业务层处理
 *
 * @author YinQ
 * @date 2023-04-05
 */
@Service
public class ReportPointDnbServiceImpl implements IReportPointDnbService {
    @Autowired
    private ReportPointDnbMapper reportPointDnbMapper;

    @Autowired
    private BaseMonitorInfoMapper monitorInfoMapper;

    /**
     * 查询电整点数据
     *
     * @param objid 电整点数据主键
     * @return 电整点数据
     */
    @Override
    //@DS("#header.poolName")
    public ReportPointDnb selectReportPointDnbByObjid(Long objid) {
        return reportPointDnbMapper.selectReportPointDnbByObjid(objid);
    }

    /**
     * 查询电整点数据列表
     *
     * @param reportPointDnb 电整点数据
     * @return 电整点数据
     */
    @Override
    //@DS("#header.poolName")
//    @DataScope(deptAlias = "report_point_dnb")
    public List<ReportPointDnb> selectReportPointDnbList(ReportPointDnb reportPointDnb) {
        return reportPointDnbMapper.selectReportPointDnbList(reportPointDnb);
    }

    /**
     * 新增电整点数据
     *
     * @param reportPointDnb 电整点数据
     * @return 结果
     */
    @Override
    //@DS("#header.poolName")
    public int insertReportPointDnb(ReportPointDnb reportPointDnb) {
        reportPointDnb.setRecordTime(new Date());
        reportPointDnb.setCollectType(1L);
        return reportPointDnbMapper.insertReportPointDnb(reportPointDnb);
    }

    /**
     * 修改电整点数据
     *
     * @param reportPointDnb 电整点数据
     * @return 结果
     */
    @Override
    //@DS("#header.poolName")
    public int updateReportPointDnb(ReportPointDnb reportPointDnb) {
        reportPointDnb.setUpdateTime(DateUtils.getNowDate());
        return reportPointDnbMapper.updateReportPointDnb(reportPointDnb);
    }

    /**
     * 批量删除电整点数据
     *
     * @param objids 需要删除的电整点数据主键
     * @return 结果
     */
    @Override
    //@DS("#header.poolName")
    public int deleteReportPointDnbByObjids(String objids) {
        return reportPointDnbMapper.deleteReportPointDnbByObjids(Convert.toStrArray(objids));
    }

    /**
     * 删除电整点数据信息
     *
     * @param objid 电整点数据主键
     * @return 结果
     */
    @Override
    //@DS("#header.poolName")
    public int deleteReportPointDnbByObjid(Long objid) {
        return reportPointDnbMapper.deleteReportPointDnbByObjid(objid);
    }

    /**
     * 日月年电数据List
     *
     * @param reportPointDnb
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public List<ReportPointDnbDTO> datePointDnbList(ReportPointDnb reportPointDnb) {
        Map<String, Object> params = reportPointDnb.getParams();
        List<ReportPointDnbDTO> pointDnbList = new ArrayList<>();
//        if (!reportPointDnb.getMonitorSubset().equals("")){
//            params.put("monitorId", reportPointDnb.getMonitorSubset());
//        }
//        monitorInfoMapper.selectBaseMonitorInfoByMonitorId()

        if (reportPointDnb.getDateType().equals("day")) {
            params.put("timeSub", 10);
        } else if (reportPointDnb.getDateType().equals("month")) {
            params.put("timeSub", 7);
        } else if (reportPointDnb.getDateType().equals("year")) {
            params.put("timeSub", 4);
        }
        try {
            pointDnbList = reportPointDnbMapper.datePointDnbList(reportPointDnb);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pointDnbList;
    }
}
