package com.chinacreator.video.web;

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.chinacreator.video.bean.OrderInfo;
import com.chinacreator.video.bean.TrafficOrderInfo;
import com.chinacreator.video.dto.DataOutPipe;
import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.service.TrafficOrderService;

/**
 * 手网厅订购关系实时同步-接口
 * @author zhouxu
 * @date 20190719
 */
@RestController
public class TrafficOrderControl {
	private static final  Logger logger = LoggerFactory.getLogger(TrafficOrderControl.class);
	
	private static final  Logger log = LoggerFactory.getLogger("trafficOrder");
	
	@Autowired
	private TrafficOrderService service;
		
	@RequestMapping("/trafficOrder")
	public DataOutPipe<?> hand(TrafficOrderInfo orderInfo) throws Exception {
		Map<String,Object> logmap = new HashMap<String,Object>();
		DataOutPipe outpipe = new DataOutPipe();
		String resultcode = "";
		String errorinfo = "";
		logmap.put("reqData", orderInfo);
		try {
			service.checkBusi(orderInfo);
			String result = service.busiOper(orderInfo);
			resultcode = "0";
			errorinfo = "ok";
		}catch(Exception e) {
			e.printStackTrace();
			resultcode = "80003";
			errorinfo = "出现异常，"+e.getMessage();
			if(e instanceof BussinessException) {
				resultcode = ((BussinessException) e).getCode();
				errorinfo = ((BussinessException) e).getMessage();
				throw e;
			}else {
				throw new BussinessException(resultcode, errorinfo);
			}
		}finally {
			outpipe.setResultcode(resultcode);
			outpipe.setErrorinfo(errorinfo);
			logmap.put("resultcode", resultcode);
			logmap.put("errorinfo", errorinfo);
			log.info(JSON.toJSONString(logmap));
		}
		return outpipe;
	}
}
