package com.xunhong.erp.turbo.facade.app.executor.cmd;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.xunhong.erp.turbo.api.facade.dto.vo.WxMaOcrBankCardVO;
import com.xunhong.erp.turbo.api.infra.api.SettingServiceI;
import com.xunhong.erp.turbo.facade.app.executor.common.WxCmdExe;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import me.chanjar.weixin.common.bean.ocr.WxOcrBankCardResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @author shenyifei
 */
@Component
@RequiredArgsConstructor
public class WxMaOcrBankCardCmdExe extends WxCmdExe {

	@DubboReference(version = "1.0.0")
	private final SettingServiceI settingService;

	@SneakyThrows
	public WxMaOcrBankCardVO execute(String ocrUrl) {
		WxMaService wxMaService = getWxMaService(settingService);
		WxOcrBankCardResult wxOcrBankCardResult = wxMaService.getOcrService().bankCard(ocrUrl);
		String number = wxOcrBankCardResult.getNumber();
		WxMaOcrBankCardVO wxMaOcrBankCardVO = new WxMaOcrBankCardVO();
		wxMaOcrBankCardVO.setNumber(number);
		wxMaOcrBankCardVO.setOcrUrl(ocrUrl);

		return wxMaOcrBankCardVO;
	}
}
