| 1 | |
package jp.co.y_net.amm.service; |
| 2 | |
|
| 3 | |
import java.util.List; |
| 4 | |
|
| 5 | |
import jp.co.y_net.amm.common.AppLogger; |
| 6 | |
import jp.co.y_net.amm.common.AppUtils; |
| 7 | |
import jp.co.y_net.amm.dao.AppDef; |
| 8 | |
import jp.co.y_net.amm.dao.Pwtckt; |
| 9 | |
import jp.co.y_net.amm.dao.PwtcktDao; |
| 10 | |
import jp.co.y_net.amm.dao.UsrDao; |
| 11 | |
|
| 12 | |
import org.apache.commons.lang.RandomStringUtils; |
| 13 | |
import org.apache.wicket.spring.injection.annot.SpringBean; |
| 14 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 15 | |
import org.springframework.beans.factory.annotation.Qualifier; |
| 16 | |
import org.springframework.stereotype.Component; |
| 17 | |
|
| 18 | |
@Component("passwordTicketManager") |
| 19 | 0 | public class PasswordTicketManager { |
| 20 | |
|
| 21 | |
@SpringBean(name="usrDao") |
| 22 | |
protected UsrDao usrDao; |
| 23 | |
|
| 24 | |
@Autowired(required = true) |
| 25 | |
@Qualifier("pwtcktDao") |
| 26 | |
private PwtcktDao pwtcktDao; |
| 27 | |
|
| 28 | |
public String execute新規パスワード発行(Integer usrid) { |
| 29 | 0 | return execute(usrid, 60*60* AppDef.新規パスワード発行の登録有効期間); |
| 30 | |
} |
| 31 | |
|
| 32 | |
public String executeパスワードリセット(Integer usrid) { |
| 33 | 0 | return execute(usrid, 60*60* AppDef.パスワードリセット後のパスワード登録有効期間); |
| 34 | |
} |
| 35 | |
|
| 36 | |
public String execute(Integer usrid, int ticketdateOffset) { |
| 37 | |
|
| 38 | |
{ |
| 39 | 0 | Pwtckt cnd = new Pwtckt(); |
| 40 | 0 | cnd.setUsrid(usrid); |
| 41 | 0 | cnd.setStatus(Pwtckt.STATUS_受付中); |
| 42 | |
|
| 43 | 0 | List<Pwtckt> tickets = pwtcktDao.get(cnd); |
| 44 | 0 | for(Pwtckt tiket: tickets) { |
| 45 | 0 | tiket.setStatus(Pwtckt.STATUS_中止); |
| 46 | 0 | tiket.setCanceldate(AppUtils.createNowLong()); |
| 47 | 0 | pwtcktDao.update(tiket, AppDef.USERID_NONE); |
| 48 | |
|
| 49 | 0 | pwtcktDao.removeLogical(tiket, AppDef.USERID_NONE); |
| 50 | |
} |
| 51 | |
} |
| 52 | |
|
| 53 | |
{ |
| 54 | 0 | Pwtckt cnd = new Pwtckt(); |
| 55 | 0 | cnd.setUsrid(usrid); |
| 56 | 0 | cnd.setStatus(Pwtckt.STATUS_有効期限切れ); |
| 57 | |
|
| 58 | 0 | List<Pwtckt> tickets = pwtcktDao.get(cnd); |
| 59 | 0 | for(Pwtckt tiket: tickets) { |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 0 | pwtcktDao.removeLogical(tiket, AppDef.USERID_NONE); |
| 65 | |
} |
| 66 | |
} |
| 67 | |
|
| 68 | 0 | String random = null; |
| 69 | 0 | for (int i = 0; i < 100; i++) { |
| 70 | 0 | random = RandomStringUtils.randomAlphabetic(16); |
| 71 | 0 | Pwtckt cnd = new Pwtckt(); |
| 72 | 0 | cnd.setTicket(random); |
| 73 | 0 | if(pwtcktDao.get(cnd).isEmpty()) { |
| 74 | 0 | break; |
| 75 | |
} |
| 76 | |
} |
| 77 | 0 | if(random == null) { |
| 78 | 0 | throw new RuntimeException("チケットが決定しませんでした。無限ループ防止のため、処理を中止します。"); |
| 79 | |
} |
| 80 | 0 | Pwtckt ticket = new Pwtckt(); |
| 81 | 0 | ticket.setUsrid(usrid); |
| 82 | 0 | ticket.setTicket(random); |
| 83 | 0 | ticket.setCreatedate(AppUtils.createNowLong()); |
| 84 | 0 | ticket.setTicketdate(AppUtils.createNowLong(ticketdateOffset)); |
| 85 | 0 | ticket.setStatus(Pwtckt.STATUS_受付中); |
| 86 | 0 | pwtcktDao.add(ticket, AppDef.USERID_NONE); |
| 87 | |
|
| 88 | 0 | return random; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public Pwtckt getユーザに紐づくチケット(Integer usrid) { |
| 92 | 0 | Pwtckt ticket = new Pwtckt(); |
| 93 | 0 | ticket.setUsrid(usrid); |
| 94 | 0 | ticket.setStatus(Pwtckt.STATUS_受付中); |
| 95 | 0 | List<Pwtckt> results = pwtcktDao.get(ticket); |
| 96 | 0 | if(results.isEmpty()) { |
| 97 | 0 | return null; |
| 98 | |
} |
| 99 | 0 | if(results.size() != 1) { |
| 100 | 0 | AppLogger.error("1つのユーザに紐づく、受付中のチケットが複数件、検出されました。"); |
| 101 | 0 | return null; |
| 102 | |
} |
| 103 | 0 | return results.get(0); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
} |