package com.ruoyi.web.controller.api;

import com.ruoyi.common.utils.ApiResult;
import com.ruoyi.mall.service.IMallSeckillGoodsService;
import com.ruoyi.mall.service.IMallSeckillTimeService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 秒杀
 * @author chang
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/api/seckill")
@ApiOperation("秒杀")
public class ApiSeckillController {

    @Resource
    private IMallSeckillTimeService mallSeckillTimeService;

    @Resource
    private IMallSeckillGoodsService mallSeckillGoodsService;

    /**
     * 秒杀时间列表
     * @return
     */
    @GetMapping("/getSeckillTimeList")
    public ApiResult getSeckillTimeList(){
        try {
            return mallSeckillTimeService.getSeckillTimeList();
        }catch (Exception e){
            e.printStackTrace();
            return ApiResult.error("服务器异常");
        }
    }

    /**
     * 秒杀商品列表
     * @return
     */
    @GetMapping("/getSeckillGoodsList")
    public ApiResult getSeckillGoodsList(@RequestParam Map<String,Object> param){
//        if (!param.containsKey("seckillTimeId") || MapUtils.getInteger(param,"seckillTimeId") == null){
//            return ApiResult.error("缺少seckillTimeId");
//        }
        if (!param.containsKey("pageNum") || MapUtils.getInteger(param,"pageNum") == null){
            return ApiResult.error("缺少pageNum");
        }
        if (!param.containsKey("pageSize") || MapUtils.getInteger(param,"pageSize") == null){
            return ApiResult.error("缺少pageSize");
        }
        try {
            return mallSeckillGoodsService.getSeckillGoodsList(param);
        }catch (Exception e){
            e.printStackTrace();
            return ApiResult.error("服务器异常");
        }
    }

}
