package com.supplier.service.impl;

import com.supplier.mapper.SupplierReleaseMapper;
import com.supplier.model.*;
import com.supplier.service.SupplierReleaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SupplierReleaseServiceImpl implements SupplierReleaseService {

    @Autowired
    private SupplierReleaseMapper supplierReleaseMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRelease(SupplierRelease supplierRelease) {
        supplierReleaseMapper.addRelease(supplierRelease);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addReleaseDay(SupplierReleaseDay supplierReleaseDay) {
        supplierReleaseMapper.addReleaseDay(supplierReleaseDay);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addReleasePlay(SupplierReleasePlay supplierReleasePlay) {
        supplierReleaseMapper.addReleasePlay(supplierReleasePlay);
    }

    @Override
    public List<SupplierRelease> getSupplierRelease(SupplierRelease supplierRelease) {
        return supplierReleaseMapper.getSupplierRelease(supplierRelease);
    }

    @Override
    public List<SupplierReleaseDay> getSupplierReleaseDay(String uuid) {
        return supplierReleaseMapper.getSupplierReleaseDay(uuid);
    }

    @Override
    public List<SupplierReleasePlay> getSupplierReleasePlay(String uuid) {
        return supplierReleaseMapper.getSupplierReleasePlay(uuid);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateSupplierRelease(SupplierRelease supplierRelease) {
        supplierReleaseMapper.updateSupplierRelease(supplierRelease);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addPrivateType(SupplierRelease supplierRelease) {
        supplierReleaseMapper.addPrivateType(supplierRelease);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updatePrivateType(SupplierRelease supplierRelease) {
        supplierReleaseMapper.updatePrivateType(supplierRelease);
    }

    @Override
    public ConfirmOrdering getConfirmOrdering(ConfirmOrdering confirmOrdering) {
        return supplierReleaseMapper.getConfirmOrdering(confirmOrdering);
    }

    @Override
    public List<UsedUser> getConfirmUsed(String uuid) {
        return supplierReleaseMapper.getConfirmUsed(uuid);
    }

    @Override
    public List<SupplierRelease> getSupplierReleaseType(String demandUuid) {
        return supplierReleaseMapper.getSupplierReleaseType(demandUuid);
    }

    @Override
    public void updateSupplierOffer(SupplierRelease supplierRelease2) {
        supplierReleaseMapper.updateSupplierOffer(supplierRelease2);
    }

    @Override
    public ConfirmOrdering getConfirmOrderingUser(ConfirmOrdering confirmOrdering) {
        return supplierReleaseMapper.getConfirmOrderingUser(confirmOrdering);
    }

    @Override
    public Map<String, Object> updateTraffic(SupplierRelease supplierRelease) {
        Map<String, Object> map = new HashMap<>();
        try{
            String orderType = supplierReleaseMapper.getReleasOrderType(supplierRelease);
            if(orderType.equals("2")){
                //修改状态
                supplierRelease.setOrderType("12");
                supplierReleaseMapper.updatePrivateType(supplierRelease);
            }
            //修改信息
            supplierReleaseMapper.updateSupplierRelease(supplierRelease);
            map.put("msg", "200");
        } catch (Exception e){
            e.printStackTrace();
            map.put("msg", "500");
            map.put("errMsg", "服务器请求异常，请稍后再试");
        }
        return map;
    }

    @Override
    public String getSupplierOrderType(SupplierRelease supplierRelease1) {
        return supplierReleaseMapper.getSupplierOrderType(supplierRelease1);
    }
}
