package cn.superdesk.uniorder.controller._openapi.superdeskmall.supplier;

import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.rest.response.ResponseResultInnerUtils;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskmall.SuperMallSupplierReceiveParam;
import cn.superdesk.uniorder.dto.test.ExportToJsonPluginDto;
import cn.superdesk.uniorder.common.mq.kafka.producer.FakeSuperdeskMallProducerHandler;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: f
 * topic: supplierSync
 * message_key: merchant
 * @Author: linjinyu
 * @CreateDate: 2021/6/3 下午5:52
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/6/3 下午5:52
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/openapi/superdesk/mall/supplier/receive")
public class SupplierSyncReceiveController {

	@Autowired
	private FakeSuperdeskMallProducerHandler fakeSuperdeskMallProducerHandler;

	@ApiOperation(value = "测试")
	@RequestMapping(value = "/test/timeline", method = RequestMethod.POST)
	@ResponseBody
	public R<String> test(@RequestBody ExportToJsonPluginDto dto) {

		dto.getData().forEach(dataBean -> {

			log.info("{} {}", dataBean.getMessageKey(), dataBean.getMessageBody());

			// 企业采购[生产环境]
			if ("supplierSync".equals(dataBean.getTopic()) && "merchant".equals(dataBean.getMessageKey())) {
				SuperMallSupplierReceiveParam superMallSupplierReceiveParam = AnJsonUtils.toObject(dataBean.getMessageBody(), SuperMallSupplierReceiveParam.class);
				fakeSuperdeskMallProducerHandler.fakeProducerSupplier(superMallSupplierReceiveParam);
			}
		});

		return new ResponseResultInnerUtils<String>().setData("test/timeline");
	}
}
