package org.springblade.modules.QRCode.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.common.cache.PaymentCache;
import org.springblade.core.tool.api.R;
import org.springblade.modules.QRCode.entity.PayCodeVO;
import org.springblade.modules.QRCode.entity.SingleCodeDto;
import org.springblade.modules.QRCode.service.QRCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.RestController;


/**
 * 	！！！！！ 已废弃：客户端实现
 *
 *
 * @author: lianghanqiang
 * @description: 二维码控制器
 * @since: 7/29/21 -- 10:23 AM
 */
@RestController
@RequestMapping("/qrcode")
@Api(tags = "二维码模块")
public class QRCodeController {

	@Autowired
	private QRCodeService qrCodeService;



	@ApiOperation("获取商家/个人收款二维码")
	@PostMapping("fetch")
	public R fetchQRCode(@RequestBody @Validated SingleCodeDto singleCodeDto){
		PaymentCache.putCodeInfo(qrCodeService.encodeMD5(singleCodeDto,singleCodeDto.getId()),singleCodeDto);
		return R.data(qrCodeService.fetchQRCode(singleCodeDto,singleCodeDto.getLogo()));
	}


	@ApiOperation("获取商家/个人收款付款码")
	@PostMapping("payCode")
	public R payCode(@RequestBody @Validated SingleCodeDto singleCodeDto){
		PaymentCache.putCodeInfoWithEx(qrCodeService.encodeMD5(singleCodeDto,singleCodeDto.getId()),singleCodeDto,60L);
		String bar = qrCodeService.fetchBar(singleCodeDto);
		String code = qrCodeService.fetchQRCode(singleCodeDto,null);
		return R.data(PayCodeVO.builder().code(code).bar(bar).build());
	}
}
