package com.ym.mec.web.controller;

import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
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 com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.AppRedemptionCode;
import com.ym.mec.biz.service.AppRedemptionCodeService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;

/**
 * 兑换码分配表(RedemptionCode)表控制层
 *
 * @author makejava
 * @since 2021-12-27 14:27:56
 */
@RestController
@RequestMapping("appRedemptionCode")
public class AppRedemptionCodeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private AppRedemptionCodeService appRedemptionCodeService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "分配url")
    @GetMapping(value = "allocation")
    public HttpResponseResult<AppRedemptionCode> allocation(@RequestParam("userId")Integer userId) throws Exception {
        if (userId == null) {
            throw new Exception("用户Id必须填写");
        }
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        return succeed(appRedemptionCodeService.allocation(userId));
    }

    @ApiOperation(value = "使用量检测")
    @GetMapping(value = "checkLowVolume")
    // @PreAuthorize("@pcs.hasPermissions('appRedemptionCode/checkLowVolume')")
    public Object checkLowVolume() {
        appRedemptionCodeService.checkLowVolume();
        return null;
    }

}

