package cn.superdesk.uniorder.controller._patch.superdeskapp.services.flashdeliver;

import cn.superdesk.uniorder.common.mq.kafka.producer.FakeSuperdeskUniOrderProducerHandler;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.numerical.AnCollectionUtils;
import cn.superdesk.uniorder.common.pagination.PageQueryParam;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.base.UnifiedOrder;
import cn.superdesk.uniorder.dto.receive.consumer.superdeskappservices.flashdeliver.FlashDeliverOrderPatchUnifiedOrderFieldOutVirt;
import cn.superdesk.uniorder.dubbo.consumer.order.receive.ReceiveFlashDeliverOrderDubboConsumerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/7/13 上午11:49
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/7/13 上午11:49
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/patch/superdeskapp/services/flashdeliver")
public class FlashDeliverOrderPatchController {

	@Autowired
	private ReceiveFlashDeliverOrderDubboConsumerService receiveFlashDeliverOrderDubboConsumerService;

	@Autowired
	private FakeSuperdeskUniOrderProducerHandler fakeSuperdeskUniOrderProducerHandler;

	/**
	 * /patch/superdeskapp/services/flashdeliver/patchUnifiedOrderFieldOutVirt
	 *
	 * @param pageQueryParam
	 * @return
	 */
	@ApiOperation(value = "修正 楼闪送 订单 下单人企业")
	@RequestMapping(value = "patchUnifiedOrderFieldOutVirt", method = RequestMethod.POST)
	@ResponseBody
	public R<List<UnifiedOrder>> patchUnifiedOrderFieldOutVirt(@RequestBody PageQueryParam pageQueryParam) {


		R<List<UnifiedOrder>> response = new R<>();

		// TODO 参数合法性判定


		// TODO 取要修正的数据
		response = receiveFlashDeliverOrderDubboConsumerService.patchFlashDeliverPatchUnifiedOrderFieldOutVirt(pageQueryParam);

		if (AnCollectionUtils.isNotEmpty(response.getData())) {
			response.getData().forEach(order -> {
				FlashDeliverOrderPatchUnifiedOrderFieldOutVirt item = AnBeanUtils.copy(order, FlashDeliverOrderPatchUnifiedOrderFieldOutVirt.class);
				fakeSuperdeskUniOrderProducerHandler.kafkaFlashdeliverOrderPatchUnifiedOrderFieldOutVirt(item);
			});
		}

		return response;
	}

}
