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


import com.hw.common.core.text.Convert;
import com.hw.common.core.utils.DateUtils;
import com.hw.common.datascope.annotation.DataScope;
import com.hw.ems.report.domain.ReportPointWater;
import com.hw.ems.report.domain.ReportPointWaterDTO;
import com.hw.ems.report.mapper.ReportPointWaterMapper;
import com.hw.ems.report.service.IReportPointWaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 水整点数据Service业务层处理
 *
 * @author YinQ
 * @date 2023-04-09
 */
@Service
public class ReportPointWaterServiceImpl implements IReportPointWaterService {
    @Autowired
    private ReportPointWaterMapper reportPointWaterMapper;

    /**
     * 查询水整点数据
     *
     * @param objid 水整点数据主键
     * @return 水整点数据
     */
    @Override
    //@DS("#header.poolName")
    public ReportPointWater selectReportPointWaterByObjid(Long objid) {
        return reportPointWaterMapper.selectReportPointWaterByObjid(objid);
    }

    /**
     * 查询水整点数据列表
     *
     * @param reportPointWater 水整点数据
     * @return 水整点数据
     */
    @Override
    //@DS("#header.poolName")
    @DataScope(deptAlias = "null")
    public List<ReportPointWater> selectReportPointWaterList(ReportPointWater reportPointWater) {
        return reportPointWaterMapper.selectReportPointWaterList(reportPointWater);
    }

    /**
     * 新增水整点数据
     *
     * @param reportPointWater 水整点数据
     * @return 结果
     */
    @Override
    //@DS("#header.poolName")
    public int insertReportPointWater(ReportPointWater reportPointWater) {
        reportPointWater.setCreateTime(DateUtils.getNowDate());
        return reportPointWaterMapper.insertReportPointWater(reportPointWater);
    }

    /**
     * 修改水整点数据
     *
     * @param reportPointWater 水整点数据
     * @return 结果
     */
    @Override
    //@DS("#header.poolName")
    public int updateReportPointWater(ReportPointWater reportPointWater) {
        reportPointWater.setUpdateTime(DateUtils.getNowDate());
        return reportPointWaterMapper.updateReportPointWater(reportPointWater);
    }

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

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

    /**
     * 日月年电数据List
     *
     * @param reportPointWater
     * @return
     */
    @Override
    //@DS("#header.poolName")
    public List<ReportPointWaterDTO> datePointWaterList(ReportPointWater reportPointWater) {
        Map<String, Object> params = reportPointWater.getParams();
        List<ReportPointWaterDTO> pointWaterDTOList = new ArrayList<>();

        if (reportPointWater.getDateType().equals("day")) {
            params.put("timeSub", 10);
        } else if (reportPointWater.getDateType().equals("month")) {
            params.put("timeSub", 7);
        } else if (reportPointWater.getDateType().equals("year")) {
            params.put("timeSub", 4);
        }
        try {
            pointWaterDTOList = reportPointWaterMapper.datePointWaterList(reportPointWater);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pointWaterDTOList;
    }

}


