package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxCreditHistory;
import com.iformall.domain.vo.WxCreditHistoryVo;
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("新增接口")
    @PostMapping("/add")
    public ResultData add(@RequestBody WxCreditHistory wxCreditHistory) {
        log.debug("[" + getIpAddr() + "] WxCreditHistoryController::add");
        wxCreditHistory.setTenantId(getTenantId());
        wxCreditHistory.setOperatorId(getUser().getId());
        WxCreditHistory credit = wxCreditHistoryService.saveOrUpdate(wxCreditHistory);
        return new ResultData(Result.SUCCESS,"操作成功",credit);
    }

    @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());
        final PageInfo<WxCreditHistoryVo> page = wxCreditHistoryService.listAsPageMore(wxCreditHistory, pageNum, pageSize);
        return new ResultData(page);
    }
}
