package com.platform.util;

import com.platform.entity.*;
import com.platform.service.ApiTmDealLogService;
import com.platform.service.custom.MyApiDealLogService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * @author abnerhou
 * @date 2020/9/24 18:50
 * @desciption
 */
@Service
@Slf4j
public class OrderDealLogUtils {

    @Autowired
    private MyApiDealLogService apiTmDealLogService;

    public void  addOrderDealLogByOrder(BrandVo brandVo , UserVo userVo , OrderVo orderVo){
        if(null == brandVo || null == orderVo){
            log.error("缺失店铺和订单信息，无法登记成交记录");
        }
        ApiTmDealLogVo apiTmDealLogVo = new ApiTmDealLogVo();
        apiTmDealLogVo.setBrandId(brandVo.getId());
        apiTmDealLogVo.setBrandName(brandVo.getName());
        apiTmDealLogVo.setOrderId(orderVo.getId());
        apiTmDealLogVo.setOrderSn(orderVo.getOrder_sn());
        apiTmDealLogVo.setOrderStatus(orderVo.getOrder_status());
        apiTmDealLogVo.setDealDate(LocalDate.now());
        if(null != userVo){
            if(null != userVo.getUserId()){
                apiTmDealLogVo.setUserId(userVo.getUserId().intValue());
            }

            apiTmDealLogVo.setUserName(userVo.getNickname());
        }
        apiTmDealLogService.addNew(apiTmDealLogVo);
        log.info("成功登记成交记录店铺[{}]->订单[{}]" , brandVo.getId() , orderVo.getId());
    }
}
