Explorar o código

用户解锁,用于管理员解锁登录多次失败被锁定的用户.

o2sword %!s(int64=5) %!d(string=hai) anos
pai
achega
5497593829

+ 50 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/person/ActionUnlock.java

@@ -0,0 +1,50 @@
+package com.x.organization.assemble.control.jaxrs.person;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.annotation.CheckPersistType;
+import com.x.base.core.project.cache.CacheManager;
+import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.jaxrs.WrapBoolean;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.organization.assemble.control.Business;
+import com.x.organization.core.entity.Person;
+
+
+class ActionUnlock extends BaseAction {
+	private static Logger logger = LoggerFactory.getLogger(ActionUnlock.class);
+
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<Wo> result = new ActionResult<>();
+			Business business = new Business(emc);
+			Person person = business.person().pick(flag);
+			if (null == person) {
+				throw new ExceptionPersonNotExist(flag);
+			}
+			if (!this.editable(business, effectivePerson, person)) {
+				throw new ExceptionAccessDenied(effectivePerson);
+			}
+
+			emc.beginTransaction(Person.class);
+			Person entityPerson = emc.find(person.getId(), Person.class);
+			entityPerson.setFailureCount(0);
+			emc.check(entityPerson, CheckPersistType.all);
+			emc.commit();
+			CacheManager.notify(Person.class);
+
+			Wo wo = new Wo();
+			wo.setValue(true);
+			result.setData(wo);
+			return result;
+		}
+	}
+
+	public static class Wo extends WrapBoolean {
+
+	}
+
+}

+ 18 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/person/PersonAction.java

@@ -364,4 +364,22 @@ public class PersonAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
+	@JaxrsMethodDescribe(value = "用户解锁,用于管理员解锁登录多次失败被锁定的用户.", action = ActionUnlock.class)
+	@GET
+	@Path("unlock/{flag}")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void unlockPerson(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+					@JaxrsParameterDescribe("人员标识") @PathParam("flag") String flag) {
+		ActionResult<ActionUnlock.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionUnlock().execute(effectivePerson, flag);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
+	}
+
 }