package cn.superdesk.uniorder.controller._openapi.superdeskapp.organisation;

import cn.superdesk.app.supercloud.dto.receive.organisation.OrganizationReceiveParam;
import cn.superdesk.app.transfer.constants.receive.TopicReceiveConstants;
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.test.ExportToJsonPluginDto;
import cn.superdesk.uniorder.common.mq.kafka.producer.FakeSuperdeskAppProducerHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/7/6 下午3:10
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/7/6 下午3:10
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "[开放API]-服务之窗-项目" ,tags = "[开放API]-服务之窗-项目")
@Slf4j
@RestController
@RequestMapping("/openapi/superdeskapp/organisation/organization/receive")
public class OrganizationReceiveController {

	@Autowired
	private FakeSuperdeskAppProducerHandler fakeSuperdeskAppProducerHandler;

	/**
	 * http://192.168.6.223:8089/web/openapi/superdeskapp/organisation/organization/receive/test/timeline
	 * @param dto
	 * @return
	 */
	@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());

			/****************************************** 运营商_渠道商 start ******************************************/
			if (TopicReceiveConstants.TOPIC_RECEIVE_ORGANIZATION.equals(dataBean.getTopic()) && "mergeReceiveOrganization".equals(dataBean.getMessageKey())) {

				OrganizationReceiveParam organizationReceiveParam = AnJsonUtils.toObject(dataBean.getMessageBody(), OrganizationReceiveParam.class);

				fakeSuperdeskAppProducerHandler.kafkaMergeReceiveOrganization(organizationReceiveParam);

			} else if (TopicReceiveConstants.TOPIC_RECEIVE_ORGANIZATION.equals(dataBean.getTopic()) && "deleteReceiveOrganization".equals(dataBean.getMessageKey())) {

				OrganizationReceiveParam organizationReceiveParam = AnJsonUtils.toObject(dataBean.getMessageBody(), OrganizationReceiveParam.class);

				fakeSuperdeskAppProducerHandler.kafkaDeleteReceiveOrganization(organizationReceiveParam);
			}
			/****************************************** 运营商_渠道商   end ******************************************/


		});

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