package com.bweb.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.model.ResponseData;
import com.hai.service.HighGoldRecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
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 java.util.Date;
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);

    @Resource
    private HighGoldRecService highGoldRecService;

    @RequestMapping(value="/getGoldRecList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取金币情况")
    public ResponseData getGoldRecList(@RequestParam(name = "goldType", required = false) Integer goldType,
                                       @RequestParam(name = "resType", required = false) Integer resType,
                                       @RequestParam(name = "createTimeS", required = false) Long createTimeS,
                                       @RequestParam(name = "createTimeE", required = false) Long createTimeE,
                                      @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                      @RequestParam(name = "pageSize", required = true) Integer pageSize) {
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("goldType", goldType);
            map.put("resType", resType);
            map.put("createTimeS", createTimeS);
            map.put("createTimeE", createTimeE);


            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="/queryGold",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取金币统计")
    public ResponseData queryGold(@RequestParam(name = "goldType", required = false) Integer goldType,
                                       @RequestParam(name = "resType", required = false) Integer resType,
                                       @RequestParam(name = "createTimeS", required = false) Long createTimeS,
                                       @RequestParam(name = "createTimeE", required = false) Long createTimeE) {
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("goldType", goldType);
            map.put("resType", resType);
            if (createTimeS != null) {
                map.put("createTimeS", DateUtil.date2String(new Date(createTimeS), "yyyy-MM-dd"));
                map.put("createTimeE", DateUtil.date2String(new Date(createTimeE), "yyyy-MM-dd"));

            }
            return ResponseMsgUtil.success(highGoldRecService.queryGold(map));

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

}
