package cn.superdesk.uniorder.controller.order.base;

import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderReturnVo;
import cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderCommonHeadSum;
import cn.superdesk.uniorder.dubbo.consumer.order.base.UnifiedOrderReturnDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO 退单的后台管理??
 * @Author: linjinyu 补充 修改
 * @CreateDate: 5/12/20 5:37 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 5/12/20 5:37 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/order/back")
public class UnifiedOrderReturnController extends BaseController {

	@Autowired
	private UnifiedOrderReturnDubboConsumerService unifiedOrderReturnDubboConsumerService;

	/***
	 * 退单列表分页
	 * @return
	 */
	@PostMapping("/page")
	@ResponseBody
	public R<List<UnifiedOrderReturnVo>> getnotdzpage() {

		R<List<UnifiedOrderReturnVo>> result = new R<>();

		try {
			Map<String, Object> params = new HashMap<>();

			params.put("orderSn", getString("orderSn"));
			params.put("orderType", getString("orderType"));
			params.put("returnSn", getString("returnSn"));
			params.put("saleName", getString("saleName"));
			params.put("virtName", getString("virtName"));
			params.put("startime", getString("startime"));
			params.put("endtime", getString("endtime"));

			result = unifiedOrderReturnDubboConsumerService.getPage(getToken(), params, getPageNum(), getPageSize());

			UnifiedOrderCommonHeadSum unifiedOrderCommonHeadSum = unifiedOrderReturnDubboConsumerService.getPageH(getToken(), params);
			//unifiedOrderCommonHeadSum.setRealAmount(unifiedOrderCommonHeadSum.getOrderAmount().subtract(unifiedOrderCommonHeadSum.getReturnAmount()));

			// 修下为 标记 1
//			Map<String, Object> headData = new HashMap<>();
//			headData.put("total", unifiedOrderCommonHeadSum.getTotal());
//			headData.put("returnAmount", unifiedOrderCommonHeadSum.getReturnAmount());
			// 标记 1
			Map<String, Object> headData = AnBeanUtils.beanToMap(unifiedOrderCommonHeadSum);

			result.setHeadData(headData);

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage(e.getMessage());

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}
		return result;
	}
}
