package com.uas.platform.b2b.service.impl;

import com.uas.platform.b2b.dao.VendorDao;
import com.uas.platform.b2b.model.*;
import com.uas.platform.b2b.service.PurcOrderService;
import com.uas.platform.core.model.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

@Service
public class PurcOrderServiceImpl implements PurcOrderService {

	@Autowired
	private VendorDao vendorDao;

	@Override
	public ModelMap relieve(Long id) {
		ModelMap map = new ModelMap();
		Vendor vendor = vendorDao.findOne(id);
		vendor.setVendswitch(Constant.NO);
		vendorDao.save(vendor);
		map.put("success", "已取消供应商关系");
		return map;
	}

	@Override
	public ModelMap activeVend(Long id) {
		ModelMap map = new ModelMap();
		Vendor vendor = vendorDao.findOne(id);
		vendor.setVendswitch(Constant.YES);
		vendorDao.save(vendor);
		map.put("success", "已建立供应商关系");
		return map;
	}

	@Override
	public ModelMap relieveServicer(Long id) {
		ModelMap map = new ModelMap();
		Vendor vendor = vendorDao.findOne(id);
		vendor.setServicerswitch(Constant.NO);
		vendorDao.save(vendor);
		map.put("success", "已取消服务商关系");
		return map;
	}

	@Override
	public ModelMap activeServicer(Long id) {
		ModelMap map = new ModelMap();
		Vendor vendor = vendorDao.findOne(id);
		vendor.setServicerswitch(Constant.YES);
		vendorDao.save(vendor);
		map.put("success", "已建立服务商关系");
		return map;
	}

	@Override
	public ModelMap disableCust(Long id) {
		ModelMap map = new ModelMap();
		Vendor vendor = vendorDao.findOne(id);
		vendor.setCustswitch(Constant.NO);
		vendorDao.save(vendor);
		map.put("success", "已取消客户关系");
		return map;
	}

	@Override
	public ModelMap activeCust(Long id) {
		ModelMap map = new ModelMap();
		Vendor vendor = vendorDao.findOne(id);
		vendor.setCustswitch(Constant.YES);
		vendorDao.save(vendor);
		map.put("success", "已建立客户关系");
		return map;
	}

}
