package com.njcn.product.event.transientes.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.product.event.transientes.mapper.PqUserLedgerMapper;
import com.njcn.product.event.transientes.pojo.param.PqUserLedgerParam;
import com.njcn.product.event.transientes.pojo.po.PqUserLedgerPO;
import com.njcn.product.event.transientes.service.PqUserLedgerService;

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

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * @Author: cdf
 * @CreateTime: 2025-07-28
 * @Description:
 */
@Service
public class PqUserLedgerServiceImpl extends ServiceImpl<PqUserLedgerMapper, PqUserLedgerPO> implements PqUserLedgerService {

    @Autowired
    private PqUserLedgerMapper ledgerMapper;

    @Override
    public boolean addLedger(PqUserLedgerParam ledgerParam) {
        PqUserLedgerPO ledger = new PqUserLedgerPO();
        BeanUtil.copyProperties(ledgerParam,ledger);
        ledger.setId(UUID.randomUUID().toString());
        ledger.setCreateTime(LocalDateTime.now());
        ledger.setUpdateTime(LocalDateTime.now());
        return ledgerMapper.insert(ledger) > 0;
    }

    @Override
    public boolean updateLedger(PqUserLedgerParam ledgerParam) {
        PqUserLedgerPO ledger = new PqUserLedgerPO();
        BeanUtil.copyProperties(ledgerParam,ledger);
        ledger.setUpdateTime(LocalDateTime.now());
        return ledgerMapper.updateById(ledger) > 0;
    }

    @Override
    public boolean deleteLedger(List<String> ids) {
        // 物理删除（直接删除记录）
        return ledgerMapper.deleteBatchIds(ids) > 0;
    }

    @Override
    public PqUserLedgerPO getLedgerById(String id) {
        return ledgerMapper.selectById(id);
    }

    @Override
    public Page<PqUserLedgerPO> pageList(PqUserLedgerParam param) {
        Page<PqUserLedgerPO> page = new Page<>();
        Page pageResult = ledgerMapper.selectPage(page,new LambdaQueryWrapper<PqUserLedgerPO>());
        return page;
    }
}
