package com.gxwebsoft.love.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.love.mapper.UserPlanLogMapper;
import com.gxwebsoft.love.service.UserPlanLogService;
import com.gxwebsoft.love.entity.UserPlanLog;
import com.gxwebsoft.love.param.UserPlanLogParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员特权购买记录表Service实现
 *
 * @author 科技小王子
 * @since 2023-06-20 18:07:50
 */
@Service
public class UserPlanLogServiceImpl extends ServiceImpl<UserPlanLogMapper, UserPlanLog> implements UserPlanLogService {

    @Override
    public PageResult<UserPlanLog> pageRel(UserPlanLogParam param) {
        PageParam<UserPlanLog, UserPlanLogParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<UserPlanLog> list = baseMapper.selectPageRel(page, param);

        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<UserPlanLog> listRel(UserPlanLogParam param) {
        List<UserPlanLog> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<UserPlanLog, UserPlanLogParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public UserPlanLog getByIdRel(Integer logId) {
        UserPlanLogParam param = new UserPlanLogParam();
        param.setLogId(logId);
        return param.getOne(baseMapper.selectListRel(param));
    }

    /**
     * 按订充值单号查询
     */
    @Override
    public UserPlanLog getByOutTradeNo(String OutTradeNo) {
      UserPlanLogParam param = new UserPlanLogParam();
      param.setLogNo(OutTradeNo);
      return param.getOne(baseMapper.getByOutTradeNo(param));
    }

    /**
     * 支付成功 更新充值订单状态
     */
    @Override
    public void updateByOutTradeNo(UserPlanLog OutTradeNo) {
      baseMapper.updateByOutTradeNo(OutTradeNo);
    }

}
