package com.ylx.point.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.core.domain.R;
import com.ylx.point.domain.dto.UserPointDetailQueryDTO;
import com.ylx.point.domain.vo.UserPointDetailVO;
import com.ylx.point.service.IPointUserLogService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * PC后端积分Controller
 */
@RestController
@RequestMapping("/admin/point")
public class AdminPointController {

    @Resource
    private IPointUserLogService pointUserLogService;

    /**
     * 根据用户openId查询用户积分详情
     *
     * @param page 分页参数
     * @param queryDTO 查询条件，包含用户openId、积分项目、开始时间、结束时间
     * @return R<Page<UserPointDetailVO>> 用户积分详情分页列表
     */
    @GetMapping("/getUserPointDetailList")
    @ApiOperation("PC端根据用户openId查询用户积分详情")
    public R<Page<UserPointDetailVO>> getUserPointDetailList(Page<UserPointDetailVO> page, UserPointDetailQueryDTO queryDTO) {
        try {
            if (StringUtils.isBlank(queryDTO.getOpenId())) {
                return R.fail("openId不能为空");
            }
            return R.ok(pointUserLogService.getPcUserPointDetailList(page, queryDTO));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
