package com.ruoyi.bst.changeRecord.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.lightingNum.domain.LightingNumQuery;
import com.ruoyi.bst.lightingNum.domain.LightingNumVO;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bst.changeRecord.mapper.ChangeRecordMapper;
import com.ruoyi.bst.changeRecord.domain.ChangeRecord;
import com.ruoyi.bst.changeRecord.domain.ChangeRecordVO;
import com.ruoyi.bst.changeRecord.domain.ChangeRecordQuery;
import com.ruoyi.bst.changeRecord.service.ChangeRecordService;

/**
 * 爆灯次数变化Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@Service
public class ChangeRecordServiceImpl implements ChangeRecordService
{
    @Autowired
    private ChangeRecordMapper changeRecordMapper;

    /**
     * 查询爆灯次数变化
     *
     * @param id 爆灯次数变化主键
     * @return 爆灯次数变化
     */
    @Override
    public ChangeRecordVO selectChangeRecordByRecordId(Long id, boolean scope)
    {
        if (id == null) {
            return null;
        }
        ChangeRecordQuery query = new ChangeRecordQuery();
        query.setRecordId(id);
        query.setScope(scope);
        return this.selectOne(query);
    }

    /**
     * 查询一个
     * @param query
     * @return
     */
    @Override
    public ChangeRecordVO selectOne(ChangeRecordQuery query) {
        PageHelper.startPage(1, 1);
        List<ChangeRecordVO> list = changeRecordMapper.selectChangeRecordList(query);
        if(list.isEmpty()) {
            ServiceUtil.assertion(true,"当前次数变化信息您无权限查看");
        }
        return CollectionUtils.firstElement(list);
    }


    /**
     * 查询爆灯次数变化列表
     *
     * @param changeRecord 爆灯次数变化
     * @return 爆灯次数变化
     */
    @Override
    public List<ChangeRecordVO> selectChangeRecordList(ChangeRecordQuery changeRecord)
    {
        return changeRecordMapper.selectChangeRecordList(changeRecord);
    }

    /**
     * 新增爆灯次数变化
     *
     * @param changeRecord 爆灯次数变化
     * @return 结果
     */
    @Override
    public int insertChangeRecord(ChangeRecord changeRecord)
    {
        changeRecord.setCreateTime(DateUtils.getNowDate());
        return changeRecordMapper.insertChangeRecord(changeRecord);
    }

    /**
     * 修改爆灯次数变化
     *
     * @param changeRecord 爆灯次数变化
     * @return 结果
     */
    @Override
    public int updateChangeRecord(ChangeRecord changeRecord)
    {
        return changeRecordMapper.updateChangeRecord(changeRecord);
    }

    /**
     * 批量删除爆灯次数变化
     *
     * @param recordIds 需要删除的爆灯次数变化主键
     * @return 结果
     */
    @Override
    public int deleteChangeRecordByRecordIds(Long[] recordIds)
    {
        return changeRecordMapper.deleteChangeRecordByRecordIds(recordIds);
    }

    /**
     * 删除爆灯次数变化信息
     *
     * @param recordId 爆灯次数变化主键
     * @return 结果
     */
    @Override
    public int deleteChangeRecordByRecordId(Long recordId)
    {
        return changeRecordMapper.deleteChangeRecordByRecordId(recordId);
    }
}
