package com.kym.service.impl;

import com.github.pagehelper.PageHelper;
import com.kym.entity.PlatformRevenueRecord;
import com.kym.entity.SettlementRecord;
import com.kym.entity.common.PageBean;
import com.kym.entity.queryParams.CommonQueryParam;
import com.kym.mapper.PlatformRevenueRecordMapper;
import com.kym.service.PlatformRevenueRecordService;
import com.kym.service.mybatisplus.MyBaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 平台收入记录服务实现
 *
 * @author skyline
 * @since 2026-05-18
 */
@Service
public class PlatformRevenueRecordServiceImpl extends MyBaseServiceImpl<PlatformRevenueRecordMapper, PlatformRevenueRecord> implements PlatformRevenueRecordService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveRecord(SettlementRecord settlement, String stationId) {
        var record = new PlatformRevenueRecord()
                .setSettlementRecordId(settlement.getId())
                .setStationId(stationId)
                .setSettlementPeriod(settlement.getSettlementPeriod())
                .setAmount(settlement.getPlatformFee());
        save(record);
    }

    @Override
    public PageBean<PlatformRevenueRecord> listRevenueRecords(CommonQueryParam params) {
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        var list = lambdaQuery()
                .orderByDesc(PlatformRevenueRecord::getId)
                .list();
        return new PageBean<>(list);
    }
}
