class OrderController {

	@PostMapping("/shareprofit")
	public ResBodyData shareProfit(@Validated EcmOrder ecmOrder){
		
		long start = System.currentTimeMillis();
		log.info("share profit for order start:{}", start);
		
		//shareStatus:0-未分润,1-已分润
		Integer shareStatus = 1;
		
		//判断该订单号是否为重复分润
		boolean isExisted = orderService.checkShareProfitExisted(ecmOrder.getOrderSn());
		if(isExisted){
			throw new ServiceException(SettlementApiCode.ORDER_ALREADY_SHAREPROFIT, BaseApiCode.getZhMsg(SettlementApiCode.ORDER_ALREADY_SHAREPROFIT));
		}
		
		EcmMzfShareProfit shareProfit = orderService.buildShareProfit(ecmOrder);
		
		//保存分润数据到DB
		if (shareProfit == null) {
			log.error("订单分润数据为空(shareProfit)");
			throw new ServiceException(SettlementApiCode.ORDER_SHARE_DATA_EMPTY, BaseApiCode.getZhMsg(SettlementApiCode.ORDER_SHARE_DATA_EMPTY));
		}
		
		orderService.saveShareProfit(shareProfit);
		
		//异步同步积分到会员系统
		asyncTaskService.updateScore2MemberSystem(shareProfit, ShareProfitConstants.SHARE_PROFIT_SOURCE_O2O, null);
		
		long end = System.currentTimeMillis();
		log.info("share profit for order end:{}",end);
		log.info("total time(second) for shareprofit:{}", (end-start)/1000);
		
		return SettlementUtil.success(ImmutableMap.of("orderSn", ecmOrder.getOrderSn(), "shareStatus", shareStatus));
	}

}