package com.xzzn.ems.service.impl;

import java.util.List;

import com.xzzn.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xzzn.ems.mapper.EmsBatteryDailyLatestMapper;
import com.xzzn.ems.domain.EmsBatteryDataDailyLatest;
import com.xzzn.ems.service.IEmsBatteryDailyLatestService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 单体电池每日最新数据Service业务层处理
 *
 * @author xzzn
 * @date 2025-07-18
 */
@Service
public class EmsBatteryDailyLatestServiceImpl implements IEmsBatteryDailyLatestService
{
    @Autowired
    private EmsBatteryDailyLatestMapper emsBatteryDataDailyLatestMapper;

    /**
     * 查询单体电池每日最新数据
     *
     * @param batteryPack 单体电池每日最新数据主键
     * @return 单体电池每日最新数据
     */
    @Override
    public EmsBatteryDataDailyLatest selectEmsBatteryDataDailyLatestByBatteryPack(String batteryPack)
    {
        return emsBatteryDataDailyLatestMapper.selectEmsBatteryDataDailyLatestByBatteryPack(batteryPack);
    }

    /**
     * 查询单体电池每日最新数据列表
     *
     * @param emsBatteryDataDailyLatest 单体电池每日最新数据
     * @return 单体电池每日最新数据
     */
    @Override
    public List<EmsBatteryDataDailyLatest> selectEmsBatteryDataDailyLatestList(EmsBatteryDataDailyLatest emsBatteryDataDailyLatest)
    {
        return emsBatteryDataDailyLatestMapper.selectEmsBatteryDataDailyLatestList(emsBatteryDataDailyLatest);
    }

    /**
     * 新增单体电池每日最新数据
     *
     * @param emsBatteryDataDailyLatest 单体电池每日最新数据
     * @return 结果
     */
    @Override
    public int insertEmsBatteryDataDailyLatest(EmsBatteryDataDailyLatest emsBatteryDataDailyLatest)
    {
        emsBatteryDataDailyLatest.setCreateTime(DateUtils.getNowDate());
        return emsBatteryDataDailyLatestMapper.insertEmsBatteryDataDailyLatest(emsBatteryDataDailyLatest);
    }

    /**
     * 修改单体电池每日最新数据
     *
     * @param emsBatteryDataDailyLatest 单体电池每日最新数据
     * @return 结果
     */
    @Override
    public int updateEmsBatteryDataDailyLatest(EmsBatteryDataDailyLatest emsBatteryDataDailyLatest)
    {
        emsBatteryDataDailyLatest.setUpdateTime(DateUtils.getNowDate());
        return emsBatteryDataDailyLatestMapper.updateEmsBatteryDataDailyLatest(emsBatteryDataDailyLatest);
    }

    /**
     * 批量删除单体电池每日最新数据
     *
     * @param batteryPacks 需要删除的单体电池每日最新数据主键
     * @return 结果
     */
    @Override
    public int deleteEmsBatteryDataDailyLatestByBatteryPacks(String[] batteryPacks)
    {
        return emsBatteryDataDailyLatestMapper.deleteEmsBatteryDataDailyLatestByBatteryPacks(batteryPacks);
    }

    /**
     * 删除单体电池每日最新数据信息
     *
     * @param batteryPack 单体电池每日最新数据主键
     * @return 结果
     */
    @Override
    public int deleteEmsBatteryDataDailyLatestByBatteryPack(String batteryPack)
    {
        return emsBatteryDataDailyLatestMapper.deleteEmsBatteryDataDailyLatestByBatteryPack(batteryPack);
    }

    @Override
    @Transactional
    public void batchProcessBatteryData(List<EmsBatteryDataDailyLatest> dailyList) {
        // 批量更新每日最新数据表（使用 ON DUPLICATE KEY UPDATE）
        emsBatteryDataDailyLatestMapper.batchUpsert(dailyList);
    }
}
