|
@@ -15,20 +15,34 @@ import com.x.base.core.project.http.ActionResult;
|
|
|
import com.x.base.core.project.jaxrs.WrapBoolean;
|
|
import com.x.base.core.project.jaxrs.WrapBoolean;
|
|
|
import com.x.program.center.core.entity.Code;
|
|
import com.x.program.center.core.entity.Code;
|
|
|
import com.x.program.center.core.entity.Code_;
|
|
import com.x.program.center.core.entity.Code_;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
class ActionValidate extends BaseAction {
|
|
class ActionValidate extends BaseAction {
|
|
|
ActionResult<Wo> execute(String mobile, String answer) throws Exception {
|
|
ActionResult<Wo> execute(String mobile, String answer) throws Exception {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
ActionResult<Wo> result = new ActionResult<>();
|
|
ActionResult<Wo> result = new ActionResult<>();
|
|
|
Wo wo = new Wo();
|
|
Wo wo = new Wo();
|
|
|
- Code code = this.get(emc, mobile, answer);
|
|
|
|
|
- if (null == code) {
|
|
|
|
|
- wo.setValue(false);
|
|
|
|
|
- } else {
|
|
|
|
|
- emc.beginTransaction(Code.class);
|
|
|
|
|
- emc.remove(code);
|
|
|
|
|
- emc.commit();
|
|
|
|
|
- wo.setValue(true);
|
|
|
|
|
|
|
+ wo.setValue(false);
|
|
|
|
|
+ if(StringUtils.isNotEmpty(answer) && StringUtils.isNotEmpty(mobile)) {
|
|
|
|
|
+ Code code = this.get(emc, mobile);
|
|
|
|
|
+ if (null != code) {
|
|
|
|
|
+ if (answer.equals(code.getAnswer())) {
|
|
|
|
|
+ emc.beginTransaction(Code.class);
|
|
|
|
|
+ emc.remove(code);
|
|
|
|
|
+ emc.commit();
|
|
|
|
|
+ wo.setValue(true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ int vn = code.getVerifyNumber() == null ? 0 : code.getVerifyNumber();
|
|
|
|
|
+ vn++;
|
|
|
|
|
+ emc.beginTransaction(Code.class);
|
|
|
|
|
+ if (vn < 6) {
|
|
|
|
|
+ code.setVerifyNumber(vn);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ emc.remove(code);
|
|
|
|
|
+ }
|
|
|
|
|
+ emc.commit();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
result.setData(wo);
|
|
result.setData(wo);
|
|
|
return result;
|
|
return result;
|
|
@@ -38,21 +52,21 @@ class ActionValidate extends BaseAction {
|
|
|
public static class Wo extends WrapBoolean {
|
|
public static class Wo extends WrapBoolean {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Code get(EntityManagerContainer emc, String mobile, String answer) throws Exception {
|
|
|
|
|
|
|
+ private Code get(EntityManagerContainer emc, String mobile) throws Exception {
|
|
|
EntityManager em = emc.get(Code.class);
|
|
EntityManager em = emc.get(Code.class);
|
|
|
CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
CriteriaQuery<Code> cq = cb.createQuery(Code.class);
|
|
CriteriaQuery<Code> cq = cb.createQuery(Code.class);
|
|
|
Root<Code> root = cq.from(Code.class);
|
|
Root<Code> root = cq.from(Code.class);
|
|
|
Calendar cal = Calendar.getInstance();
|
|
Calendar cal = Calendar.getInstance();
|
|
|
- cal.add(Calendar.MINUTE, -30);
|
|
|
|
|
|
|
+ cal.add(Calendar.MINUTE, -5);
|
|
|
Predicate p = cb.greaterThan(root.get(Code_.createTime), cal.getTime());
|
|
Predicate p = cb.greaterThan(root.get(Code_.createTime), cal.getTime());
|
|
|
p = cb.and(p, cb.equal(root.get(Code_.mobile), mobile));
|
|
p = cb.and(p, cb.equal(root.get(Code_.mobile), mobile));
|
|
|
- p = cb.and(p, cb.equal(root.get(Code_.answer), answer));
|
|
|
|
|
- List<Code> list = em.createQuery(cq.where(p)).getResultList();
|
|
|
|
|
|
|
+ //p = cb.and(p, cb.equal(root.get(Code_.answer), answer));
|
|
|
|
|
+ List<Code> list = em.createQuery(cq.where(p).orderBy(cb.desc(root.get(Code_.createTime)))).setMaxResults(1).getResultList();
|
|
|
if (list.isEmpty()) {
|
|
if (list.isEmpty()) {
|
|
|
return null;
|
|
return null;
|
|
|
} else {
|
|
} else {
|
|
|
return list.get(0);
|
|
return list.get(0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|