package com.cweb.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.service.HighGoldRecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: 胡锐
 * @Description:
 * @Date: 2021/3/28 23:54
 */
@Controller
@RequestMapping(value = "/highGoldRec")
@Api(value = "金币接口")
public class HighGoldRecController {

    private static Logger log = LoggerFactory.getLogger(HighGoldRecController.class);

    @Autowired
    private UserCenter userCenter;

    @Resource
    private HighGoldRecService highGoldRecService;

    @RequestMapping(value="/getUserGoldRecList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取用户金币使用情况")
    public ResponseData getUserGoldRecList(@RequestParam(name = "goldType", required = false) Integer goldType,
                                      @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                      @RequestParam(name = "pageSize", required = true) Integer pageSize,
                                      HttpServletRequest request) {
        try {
            // 用户
            SessionObject sessionObject = userCenter.getSessionObject(request);
            HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();

            Map<String, Object> map = new HashMap<>();
            map.put("userId", userInfoModel.getHighUser().getId());
            map.put("goldType", goldType);

            PageHelper.startPage(pageNum,pageSize);
            return ResponseMsgUtil.success(new PageInfo<>(highGoldRecService.getGoldRec(map)));

        } catch (Exception e) {
            log.error("HighCouponController -> getCouponList() error!",e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/selectByExpiringSoon",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取用户积分七天内即将过期积分")
    public ResponseData selectByExpiringSoon(HttpServletRequest request) {
        try {
            // 用户
            SessionObject sessionObject = userCenter.getSessionObject(request);
            HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();

            return ResponseMsgUtil.success(highGoldRecService.selectByExpiringSoon(userInfoModel.getHighUser().getId() , 358));

        } catch (Exception e) {
            log.error("HighCouponController -> getCouponList() error!",e);
            return ResponseMsgUtil.exception(e);
        }
    }

}
