package com.njzscloud.dispose.cst.order.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.cst.order.mapper.OrderPaymentRecordMapper;
import com.njzscloud.dispose.cst.order.pojo.entity.OrderPaymentRecordEntity;
import com.njzscloud.dispose.cst.order.pojo.param.SearchOrderPaymentRecordParam;
import com.njzscloud.dispose.cst.order.pojo.result.SearchOrderPaymentRecordResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 付费记录
 *
 * @author ljw
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class OrderPaymentRecordService extends ServiceImpl<OrderPaymentRecordMapper, OrderPaymentRecordEntity> {

    /**
     * 新增
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(OrderPaymentRecordEntity orderPaymentRecordEntity) {
        this.save(orderPaymentRecordEntity);
    }

    /**
     * 修改
     */
    @Transactional(rollbackFor = Exception.class)
    public void modify(OrderPaymentRecordEntity orderPaymentRecordEntity) {
        this.updateById(orderPaymentRecordEntity);
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    public void del(List<Long> ids) {
        this.removeBatchByIds(ids);
    }

    /**
     * 详情
     */
    public OrderPaymentRecordEntity detail(Long id) {
        return this.getById(id);
    }

    /**
     * 分页查询
     */
    public PageResult<OrderPaymentRecordEntity> paging(PageParam pageParam, SearchOrderPaymentRecordParam param) {
        return PageResult.of(this.page(pageParam.toPage(), Wrappers.<OrderPaymentRecordEntity>lambdaQuery()
            .eq(param.getOrderId() != null, OrderPaymentRecordEntity::getOrderId, param.getOrderId())
            .eq(param.getExpenseItemId() != null, OrderPaymentRecordEntity::getExpenseItemId, param.getExpenseItemId())
            .eq(param.getTransId() != null, OrderPaymentRecordEntity::getTransId, param.getTransId())
            .eq(param.getPaymentStatus() != null, OrderPaymentRecordEntity::getPaymentStatus, param.getPaymentStatus())));
    }

    public List<SearchOrderPaymentRecordResult> listPaymentRecord(QueryWrapper<Object> ew) {
        return baseMapper.listPaymentRecord(ew);
    }
}
