package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.deviceStock.DeviceStockService;
import cn.pluss.platform.entity.QrCode;
import cn.pluss.platform.exception.MsgException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 商户扫码绑定接口类
 */
@Controller
@RequestMapping("/merchantScanQrCode")
@Transactional
@Api(value = "merchantScanQrCode控制类", tags = {"MerchantScanQrCode接口"})
public class MerchantScanQrCodeController {

    @Setter(onMethod_ = {@Autowired})
    private DeviceStockService deviceStockService;

    @PostMapping(value = "bind")
    @ResponseBody
    @ApiOperation(value = "商户扫码绑定收款二维码", notes = "商户绑定收款码", httpMethod = "POST")
    public Result bindCollectAmtQrCode(@RequestBody QrCode qrCode) {
        String snNo = qrCode.getSnNo();
        if (snNo == null) {
            snNo = qrCode.getQrNo();
        }

        snNo = snNo.replace("ALI_", "");
        MsgException.checkBlank(snNo, "设备编号不能为空！");

        deviceStockService.bindPayCode(snNo);
        return ResultGenerator.genSuccessResult("绑定成功！",null);
    }
}
