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

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.feeLog.domain.FeeLog;
import com.ruoyi.bst.feeLog.domain.FeeLogQuery;
import com.ruoyi.bst.feeLog.domain.FeeLogVO;
import com.ruoyi.bst.feeLog.mapper.FeeLogMapper;
import com.ruoyi.bst.feeLog.service.FeeLogService;
import com.ruoyi.common.utils.DateUtils;

/**
 * 改价记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-22
 */
@Service
public class FeeLogServiceImpl implements FeeLogService
{
    @Autowired
    private FeeLogMapper feeLogMapper;

    /**
     * 查询改价记录
     *
     * @param id 改价记录主键
     * @return 改价记录
     */
    @Override
    public FeeLogVO selectFeeLogById(Long id, boolean scope) {
        if (id == null) {
            return null;
        }
        FeeLogQuery query = new FeeLogQuery();
        query.setId(id);
        query.setScope(scope);
        query.addAreaPermission(AreaJoinPermission.ORDER_VIEW.getCode());
        return selectOne(query);
    }

    /**
     * 查询改价记录列表
     *
     * @param feeLog 改价记录
     * @return 改价记录
     */
    @Override
    public List<FeeLogVO> selectFeeLogList(FeeLogQuery feeLog)
    {
        return feeLogMapper.selectFeeLogList(feeLog);
    }

    /**
     * 新增改价记录
     *
     * @param feeLog 改价记录
     * @return 结果
     */
    @Override
    public int insertFeeLog(FeeLog feeLog)
    {
        feeLog.setCreateTime(DateUtils.getNowDate());
        return feeLogMapper.insertFeeLog(feeLog);
    }

    /**
     * 修改改价记录
     *
     * @param feeLog 改价记录
     * @return 结果
     */
    @Override
    public int updateFeeLog(FeeLog feeLog)
    {
        return feeLogMapper.updateFeeLog(feeLog);
    }

    /**
     * 批量删除改价记录
     *
     * @param ids 需要删除的改价记录主键
     * @return 结果
     */
    @Override
    public int deleteFeeLogByIds(Long[] ids)
    {
        return feeLogMapper.deleteFeeLogByIds(ids);
    }

    /**
     * 删除改价记录信息
     *
     * @param id 改价记录主键
     * @return 结果
     */
    @Override
    public int deleteFeeLogById(Long id)
    {
        return feeLogMapper.deleteFeeLogById(id);
    }

    @Override
    public FeeLogVO selectOne(FeeLogQuery query)
    {
        PageHelper.startPage(1, 1);
        List<FeeLogVO> list = feeLogMapper.selectFeeLogList(query);
        return CollectionUtils.firstElement(list);
    }
}
