package com.younike.merchant;

import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.system.param.AccessPasscodeParam;
import com.younike.system.param.AccessPasscodeQueryParam;
import com.younike.system.service.IAccessPasscodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 门岗通行证Controller
 *
 * @author dail
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/merchant/accessPasscode")
public class MerchantAccessPasscodeController extends BaseController {
    @Autowired
    private IAccessPasscodeService accessPasscodeService;


    /**
     * 根据订单信息生成门岗二维码
     */
    @PostMapping(value = "/saveAccessPasscode")
    @PreAuthorize("@ss.hasAnyRoles({'merchant'})")
    public AjaxResult saveAccessPasscode(@RequestBody @Valid AccessPasscodeParam accessPasscodeParam) {
        return accessPasscodeService.saveAccessPasscode(accessPasscodeParam);
    }

    /**
     * 根据ID查询门岗二维码信息
     */
    @GetMapping(value = "/getByAccessPasscodeId/{accessPasscodeId}")
    @PreAuthorize("@ss.hasAnyRoles({'merchant'})")
    public AjaxResult getByAccessPasscodeId(@PathVariable("accessPasscodeId") Long accessPasscodeId) {
        return AjaxResult.success(accessPasscodeService.getByAccessPasscodeId(accessPasscodeId));
    }

    /**
     * 根据订单ID和核销码查询门岗二维码信息
     */
    @GetMapping(value = "/getByOrderIdAndOrderVerificationCode")
    @PreAuthorize("@ss.hasAnyRoles({'merchant'})")
    public AjaxResult getByOrderIdAndOrderVerificationCode(AccessPasscodeQueryParam queryParam) {
        if (queryParam.getOrderId() == null) {
            return AjaxResult.error("查询参数orderId不能为空!");
        }
        return AjaxResult.success(accessPasscodeService.getByOrderIdAndOrderVerificationCode(queryParam));
    }
}
