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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import com.uas.platform.b2b.mobile.dao.OutSetDao;
import com.uas.platform.b2b.mobile.model.OutSet;
import com.uas.platform.b2b.mobile.service.OutSetService;

@Service
public class OutSetServiceImpl implements OutSetService {

	@Autowired
	private OutSetDao outSetDao;

	@Override
	public ModelMap saveOutSet(OutSet outSet) {
		ModelMap map = new ModelMap();
		OutSet set = outSetDao.getOutSetByEnuu(outSet.getEnuu());
		if (set != null) {
			set.setEnuu(outSet.getEnuu());
			set.setMo_autosign(outSet.getMo_autosign());
			set.setMo_distance(outSet.getMo_distance());
			set.setMo_time(outSet.getMo_time());
			outSetDao.save(set);
			map.put("success", true);
		} else {
			outSet = outSetDao.save(outSet);
			if (outSet.getMo_id() != null) {
				map.put("success", true);
			}
		}
		return map;
	}

	@Override
	public OutSet getOutSet(Long enuu) {
		return outSetDao.getOutSetByEnuu(enuu);
	}

}
