package com.lightinit.hsdataportal.impl;

import com.lightinit.hsdataportal.entity.Order;
import com.lightinit.hsdataportal.mapper.OrderMapper;
import com.lightinit.hsdataportal.model.ResultState;
import com.lightinit.hsdataportal.model.ResultStateCode;
import com.lightinit.hsdataportal.service.IOderService;
import com.lightinit.hsdataportal.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: sunxiang
 * @Date: 2018/6/14 16:36
 * @Description:
 **/
@Service
public class OderServiceImpl implements IOderService {

    @Autowired
    private OrderMapper orderMapper;
    @Transactional
    @Override
    public ResultState<Long> addOrder(Order order) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState<Long> resultState = new ResultState<>();
        try{
            orderMapper.insert(order);
            resultState.setMsg("订单提交成功");
            return resultState;
        }catch (Exception e){
            e.printStackTrace();
        }
        resultState.setStateCode(ResultStateCode.INVALID_DATA);
        resultState.setMsg("订单提交失败");
        return resultState;
    }
}
