package office.service.impl;

import office.model.BussinessMan;
import office.repository.BussinessManRepository;
import office.service.BussinussManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by mxq on 2018/1/2.
 */
@Service
public class BussinussManServiceImpl implements BussinussManService {
    @Autowired
    BussinessManRepository bussinessManRepository;
    @Override
    public void create(String loginEmail, String email, String name, String area) {
        BussinessMan bussinessMan = new BussinessMan();
        bussinessMan.setArea(area);
        bussinessMan.setEmail(email);
        bussinessMan.setName(name);

        BussinessMan bussinessManLeader = bussinessManRepository.findByEmail(loginEmail);
        if(null != bussinessManLeader){
            bussinessMan.setLeader(bussinessManLeader.getId());
            bussinessManRepository.save(bussinessMan);
        }else{
            BussinessMan save = bussinessManRepository.save(bussinessMan);
            save.setLeader(save.getId());
            bussinessManRepository.save(save);
        }

    }
}
