| 1 | |
package jp.co.y_net.amm.service; |
| 2 | |
|
| 3 | |
import jp.co.y_net.amm.common.AppLogger; |
| 4 | |
import jp.co.y_net.amm.dao.Org; |
| 5 | |
import jp.co.y_net.amm.dao.OrgDao; |
| 6 | |
import jp.co.y_net.amm.dao.Usr; |
| 7 | |
import jp.co.y_net.amm.dao.UsrDao; |
| 8 | |
|
| 9 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 10 | |
import org.springframework.beans.factory.annotation.Qualifier; |
| 11 | |
import org.springframework.stereotype.Component; |
| 12 | |
|
| 13 | |
@Component("mailAddressCheck") |
| 14 | 0 | public class MailAddressCheck { |
| 15 | |
|
| 16 | |
@Autowired(required = true) |
| 17 | |
@Qualifier("usrDao") |
| 18 | |
protected UsrDao usrDao; |
| 19 | |
|
| 20 | |
@Autowired(required = true) |
| 21 | |
@Qualifier("orgDao") |
| 22 | |
protected OrgDao orgDao; |
| 23 | |
|
| 24 | |
public boolean exist(String mail) { |
| 25 | 0 | return exist(mail, null, true); |
| 26 | |
} |
| 27 | |
|
| 28 | |
public boolean existWithoutOrg(String mail) { |
| 29 | 0 | return exist(mail, null, false); |
| 30 | |
} |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
private boolean exist(String mail, Integer myUsrid, boolean checkOrg) { |
| 38 | |
|
| 39 | 0 | boolean exist = false; |
| 40 | 0 | Usr cndUsr = new Usr(); |
| 41 | 0 | cndUsr.setLoginid(mail); |
| 42 | 0 | for(Usr u: usrDao.get(cndUsr)) { |
| 43 | 0 | if(u.getStatus().equals(Usr.STATUS_退会)) { |
| 44 | |
|
| 45 | 0 | AppLogger.debug(u.getName() + "が同一のメールアドレスだが退会済み"); |
| 46 | 0 | continue; |
| 47 | |
} |
| 48 | |
|
| 49 | 0 | if (myUsrid != null && u.getUsrid() == myUsrid) { |
| 50 | 0 | AppLogger.debug(u.getName() + "自分自身のデータ"); |
| 51 | 0 | continue; |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | AppLogger.debug(u.getName() + "が同一のメールアドレス"); |
| 55 | 0 | exist = true; |
| 56 | 0 | break; |
| 57 | |
} |
| 58 | |
|
| 59 | 0 | if(checkOrg) { |
| 60 | 0 | if(exist == false) { |
| 61 | |
|
| 62 | 0 | Org cndOrg = new Org(); |
| 63 | 0 | cndOrg.setMail(mail); |
| 64 | 0 | cndOrg.setStatus(Org.STATUS_未処理); |
| 65 | 0 | for(Org o: orgDao.get(cndOrg)) { |
| 66 | 0 | AppLogger.debug(o.getName() + "が同一のメールアドレス"); |
| 67 | 0 | exist = true; |
| 68 | |
break; |
| 69 | |
} |
| 70 | |
} |
| 71 | |
} |
| 72 | |
|
| 73 | 0 | return exist; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | |
} |