package shop.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import shop.service.CustomerService;
import shop.entity.Customer;
import shop.dao.CustomerDao;

@Service("customerService")
@Transactional
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao customerDao;

    @Override
    public List<Customer> getList() {
        return customerDao.getList("");
    }

    @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
    @Override
    public Boolean updateOrInsert(Customer customer) {
        if ("".equals(customer.getRef())) {
            return false;
        }
        
        Customer buff = customerDao.findByRef(customer.getRef());
        if (buff==null && !"".equals(customer.getEmail())) {
            buff = customerDao.findByEmail(customer.getEmail());
        }
        
        if (buff != null) {
            customer.setId(buff.getId());
            customerDao.update(customer);
        } else {
            customerDao.create(customer);
        }
        return true;
    }

    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW)
    @Override
    public Boolean updateList(List<Customer> list) {
        list.stream().forEach(customer -> updateOrInsert(customer));
        return true;
    }

    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW)
    @Override
    public Boolean delete(Customer customer) {
        if (customer != null) {
            customerDao.delete(customer);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Boolean checkPass(String login, String pass) {
        Customer entity = customerDao.findByEmail(login);
        if (entity != null) {
            return pass.equalsIgnoreCase(entity.getPass());
        } else {
            return false;
        }
    }

    @Override
    public Customer getByRef(String ref) {
        return customerDao.findByRef(ref);
    }
}

@@ -952,32 +952,24 @@
 ;%0A        %7D%0A
-        
 %0A        Cus
@@ -1043,10 +1043,12 @@
 buff
+ 
 ==
+ 
 null
@@ -1161,24 +1161,16 @@
       %7D%0A
-        
 %0A       
@@ -2046,16 +2046,109 @@
 entity =
+ null;%0A        if ((entity = customerDao.findByNumber(login)) == null) %7B%0A            entity =
  custome
@@ -2172,16 +2172,35 @@
 login);%0A
+        %7D%0A        %0A
         

Add autentiphicate for number