package userio.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import userio.model.SalesManLeader;
import userio.repository.IOSalesManLeaderRepository;
import userio.service.IOSalesManService;

/**
 * Created by mxq on 2018/1/2.
 */
@Service
public class IOSaleManServiceImpl implements IOSalesManService {
    @Autowired
    IOSalesManLeaderRepository salesManLeaderRepository;
    @Override
    public void create(String loginEmail, String email, String name) {
        SalesManLeader salesManLeader = new SalesManLeader();
        salesManLeader.setEmail(email);
        salesManLeader.setName(name);

        SalesManLeader manLeader = salesManLeaderRepository.findOneByEmail(loginEmail);
        if(null != manLeader){
            salesManLeader.setLeader(manLeader.getLeader());
            salesManLeaderRepository.save(salesManLeader);
        }else{
            SalesManLeader save = salesManLeaderRepository.save(salesManLeader);
            save.setLeader(save.getId());
            salesManLeaderRepository.save(save);
        }

    }
}
