package com.ruoyi.powerdistribution.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.powerdistribution.domain.vo.StopTargetAndRecords;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.powerdistribution.mapper.PdmStopTargeMapper;
import com.ruoyi.powerdistribution.domain.PdmStopTarge;
import com.ruoyi.powerdistribution.service.IPdmStopTargeService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 停电预算Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-09
 */
@Service
public class PdmStopTargeServiceImpl extends ServiceImpl<PdmStopTargeMapper,PdmStopTarge> implements IPdmStopTargeService
{
    @Autowired
    private PdmStopTargeMapper pdmStopTargeMapper;

    /**
     * 查询停电预算
     *
     * @param id 停电预算主键
     * @return 停电预算
     */
    @Override
    public PdmStopTarge selectPdmStopTargeById(Long id)
    {
        return pdmStopTargeMapper.selectPdmStopTargeById(id);
    }

    /**
     * 查询停电预算列表
     *
     * @param pdmStopTarge 停电预算
     * @return 停电预算
     */
    @Override
    public List<PdmStopTarge> selectPdmStopTargeList(PdmStopTarge pdmStopTarge)
    {
        return pdmStopTargeMapper.selectPdmStopTargeList(pdmStopTarge);
    }

    /**
     * 新增停电预算
     *
     * @param pdmStopTarge 停电预算
     * @return 结果
     */
    @Override
    public int insertPdmStopTarge(PdmStopTarge pdmStopTarge)
    {
        pdmStopTarge.setCreateTime(DateUtils.getNowDate());
        return pdmStopTargeMapper.insert(pdmStopTarge);
    }

    /**
     * 修改停电预算
     *
     * @param pdmStopTarge 停电预算
     * @return 结果
     */
    @Override
    public int updatePdmStopTarge(PdmStopTarge pdmStopTarge)
    {
        pdmStopTarge.setUpdateTime(DateUtils.getNowDate());
        return pdmStopTargeMapper.updatePdmStopTarge(pdmStopTarge);
    }

    /**
     * 批量删除停电预算
     *
     * @param ids 需要删除的停电预算主键
     * @return 结果
     */
    @Override
    public int deletePdmStopTargeByIds(Long[] ids)
    {
        return pdmStopTargeMapper.deletePdmStopTargeByIds(ids);
    }

    /**
     * 删除停电预算信息
     *
     * @param id 停电预算主键
     * @return 结果
     */
    @Override
    public int deletePdmStopTargeById(Long id)
    {
        return pdmStopTargeMapper.deletePdmStopTargeById(id);
    }

    @Override
    @Transactional
    public boolean batchSaveOrUpdate(List<PdmStopTarge> list,String reportYear) {
        this.remove(new LambdaUpdateWrapper<PdmStopTarge>().eq(PdmStopTarge::getReportYear,reportYear));
        for(PdmStopTarge target:list){
            target.setReportYear(reportYear);
            pdmStopTargeMapper.insertPdmStopTarge(target);
        }
        return true;
    }

    @Override
    public List<StopTargetAndRecords> selectTargetAndActual(String reportYear) {
        return pdmStopTargeMapper.selectTargetAndActual(reportYear);
    }
}
