package com.ruoyi.app.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.PointsTransaction;
import com.ruoyi.system.domain.WalletTransaction;
import com.ruoyi.system.service.IPointsTransactionService;
import com.ruoyi.system.utils.Auth;
import com.ruoyi.system.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户积分Controller
 *
 * @author ruoyi
 * @date 2023-05-23
 */
@RestController
@RequestMapping("/system/points")
public class PointController extends BaseController {
    @Autowired
    private IPointsTransactionService  pointsTransactionService;

    
    /**
     * 用户积分流水分页列表
     */
    @Anonymous
    @Auth
    @GetMapping("/getpoints")
    public AjaxResult getpoints(@RequestHeader String token,
                                @RequestParam Long page,
                                @RequestParam Long size) {
        JwtUtil jwtUtil = new JwtUtil();
        Long id = Long.valueOf(jwtUtil.getusid(token));
        IPage<PointsTransaction> pg=new Page<>(page,size);
        LambdaQueryWrapper<PointsTransaction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PointsTransaction::getUserId, id);
       queryWrapper.orderByDesc(PointsTransaction::getCreateTime);
        IPage<PointsTransaction> data = pointsTransactionService.page(pg, queryWrapper);
        return success(data);
    }
}
