package com.winsun.controller;

import com.winsun.auth.core.annotion.Permission;
import com.winsun.auth.core.base.controller.BaseController;
import com.winsun.auth.core.common.model.ResponseData;
import com.winsun.auth.core.shiro.ShiroUser;
import com.winsun.bean.AuthCode;
import com.winsun.mapper.AuthCodeMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;

import java.util.List;

/**
 * @Author: chenhaojian
 * @Date: 2021/1/14
 */
@RestController
@RequestMapping("/authCode") //
public class AuthCodeController extends BaseController {

    private static AuthCodeMapper authCodeMapper;

    // 查询验证码
    @Permission(menuname = "查询验证码", value = "queryAuthCode", method = RequestMethod.POST)
    public ResponseData<List<AuthCode>> queryAuthCodeList(@RequestParam(name = "id", required = false) String id) {
        ShiroUser shiroUser = getShiroUser();
        if (!shiroUser.getRoleNames().stream().anyMatch(roleName -> StringUtils.equalsAny(roleName, "超级管理员", "系统管理员", "验证码"))) {
            ResponseData.error("无权限修改订单");
        }
        List<AuthCode> queryAuthCodeList = authCodeMapper.queryAuthCode(id);
        return ResponseData.success(queryAuthCodeList, "查询完毕！");
    }

    @Autowired
    public AuthCodeController(AuthCodeMapper authCodeMapper) {
        AuthCodeController.authCodeMapper = authCodeMapper;
    }
}
