package com.ruoyi.ss.billEleRecord.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.billEleRecord.domain.BillEleRecord;
import com.ruoyi.ss.billEleRecord.domain.BillEleRecordQuery;
import com.ruoyi.ss.billEleRecord.domain.BillEleRecordVO;
import com.ruoyi.ss.billEleRecord.mapper.BillEleRecordMapper;
import com.ruoyi.ss.billEleRecord.service.BillEleRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单电量记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-04
 */
@Service
public class BillEleRecordServiceImpl implements BillEleRecordService
{
    @Autowired
    private BillEleRecordMapper billEleRecordMapper;

    /**
     * 查询订单电量记录
     *
     * @param id 订单电量记录主键
     * @return 订单电量记录
     */
    @Override
    public BillEleRecordVO selectBillEleRecordById(Long id)
    {
        return billEleRecordMapper.selectBillEleRecordById(id);
    }

    /**
     * 查询订单电量记录列表
     *
     * @param billEleRecord 订单电量记录
     * @return 订单电量记录
     */
    @Override
    public List<BillEleRecordVO> selectBillEleRecordList(BillEleRecordQuery billEleRecord)
    {
        return billEleRecordMapper.selectBillEleRecordList(billEleRecord);
    }

    /**
     * 新增订单电量记录
     *
     * @param billEleRecord 订单电量记录
     * @return 结果
     */
    @Override
    public int insertBillEleRecord(BillEleRecord billEleRecord)
    {
        billEleRecord.setCreateTime(DateUtils.getNowDate());
        return billEleRecordMapper.insertBillEleRecord(billEleRecord);
    }

    /**
     * 修改订单电量记录
     *
     * @param billEleRecord 订单电量记录
     * @return 结果
     */
    @Override
    public int updateBillEleRecord(BillEleRecord billEleRecord)
    {
        return billEleRecordMapper.updateBillEleRecord(billEleRecord);
    }

    /**
     * 批量删除订单电量记录
     *
     * @param ids 需要删除的订单电量记录主键
     * @return 结果
     */
    @Override
    public int deleteBillEleRecordByIds(Long[] ids)
    {
        return billEleRecordMapper.deleteBillEleRecordByIds(ids);
    }

    /**
     * 删除订单电量记录信息
     *
     * @param id 订单电量记录主键
     * @return 结果
     */
    @Override
    public int deleteBillEleRecordById(Long id)
    {
        return billEleRecordMapper.deleteBillEleRecordById(id);
    }

    @Override
    public int batchInsert(List<BillEleRecord> list) {
        if (CollectionUtils.isEmptyElement(list)) {
            return 0;
        }
        Date now = DateUtils.getNowDate();
        for (BillEleRecord record : list) {
            record.setCreateTime(now);
        }
        return billEleRecordMapper.batchInsert(list);
    }

    @Override
    public BigDecimal selectMaxEleByBillId(Long billId) {
        if (billId == null) {
            return null;
        }
        BillEleRecordQuery query = new BillEleRecordQuery();
        query.setBillId(billId);
        return billEleRecordMapper.selectMaxEle(query);
    }

    @Override
    public BigDecimal selectSumOfTotalPrice(BillEleRecordQuery query) {
        return billEleRecordMapper.selectSumOfTotalPrice(query);
    }

}
