package cn.superdesk.uniorder.redis.model001.channel;

import cn.superdesk.uniorder.service.accounting.unified.supplier.AccountingUnifiedSupplierService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.net.URLEncoder;
import java.util.concurrent.CompletableFuture;


@Slf4j
@Component
public class ProcessMessagesChannelAccountingUnifiedSupplier {


	@Resource
	private AccountingUnifiedSupplierService accountingUnifiedSupplierService;

	public synchronized void monitorBroadcast(/* accountingOrderSn */String message) {


		message = message.replace("\"","");

//		String msg1 = baos.toString("ISO-8859-1");//指定字符集将字节流解码成字符串,否则在订阅时,转换会有问题。
		// msg1 = URLEncoder.encode(msg1, "UTF-8");

		// 异步将操作
//		CompletableFuture.runAsync(() -> {
		try {
			log.info("ProcessMessagesChannelAccountingUnifiedSupplier monitorBroadcast 供应商 对账单 关联商品 供应商对账状态 校正: {}", message);
			accountingUnifiedSupplierService.patchXCheckAndFix(URLEncoder.encode(message, "UTF-8"));
		} catch (Exception e2) {
			log.error("消息监听失败啦 异步将操作:{}", e2);
		}
//		});

	}
}
