package com.fs.his.utils;

import cn.hutool.json.JSONUtil;
import com.fs.his.domain.FsStore;
import com.fs.his.domain.FsStoreOrder;
import com.fs.his.mapper.FsStoreMapper;
import com.fs.his.mapper.FsStoreOrderMapper;
import com.fs.his.mapper.FsTestReportMapper;
import com.fs.his.service.IFsStoreOrderService;
import com.fs.his.vo.FsStoreOrderVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.ParseException;

@Service
public class TuiOrderUtil {
    @Autowired
    IFsStoreOrderService fsStoreOrderService;
    @Autowired
    FsStoreMapper fsStoreMapper;
    Logger logger= LoggerFactory.getLogger(getClass());
    @Async
    public void TuiOrder(Long orderId)  {
        FsStoreOrderVO order = fsStoreOrderService.selectFsStoreOrderByOrderIdVO(orderId);
        logger.info("创建推送订单"+order);
        if (order.getStoreId()==31||order.getStoreId()==34){
            logger.info("创建智慧药房订单"+orderId);
            fsStoreOrderService.tuiOrder(orderId);
        }else if (order.getStoreId()==30){
            try {
                logger.info("创建oms订单"+orderId);
                fsStoreOrderService.createOmsOrder(orderId);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Async
    public void TuiOrderByPackage(FsStoreOrder order) {
        logger.info("创建推送订单"+order);
        FsStore fsStore = fsStoreMapper.selectFsStoreByStoreId(order.getStoreId());
        Integer deliveryType = fsStore.getDeliveryType();
        if (deliveryType==1){
            logger.info("创建智慧药房订单"+order);
            fsStoreOrderService.tuiOrder(order.getOrderId());
        }else if (deliveryType==2){
            try {
                logger.info("创建oms订单"+order);
                fsStoreOrderService.createOmsOrder(order.getOrderId());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
