package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.base.BaseEntity;
import com.iformall.domain.po.WxCreditHistory;
import com.iformall.service.WxCreditHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/credit")
@Api(description = "积分相关接口")
@Slf4j
public class WxCreditHistoryController extends BaseController{

    @Autowired
    private WxCreditHistoryService wxCreditHistoryService;

    @ApiOperation("用户积分列表")
    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true),
            @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)})
    public ResultData list(@ModelAttribute WxCreditHistory wxCreditHistory, Integer pageNum, Integer pageSize) {
        log.debug("[" + getIpAddr() + "] WxCreditHistoryController::list");
        if (null == wxCreditHistory) wxCreditHistory = new WxCreditHistory();
        wxCreditHistory.setCUserId(getUserId());
        wxCreditHistory.setSortColumns(BaseEntity.SortField.CreateDate_DESC,BaseEntity.SortField.Id_DESC);
        final PageInfo<WxCreditHistory> page = wxCreditHistoryService.listAsPage(wxCreditHistory, pageNum, pageSize);
        return new ResultData(page);
    }
}
