Ver a proveniência

新增:登录事件(用户映射,登录成功之后)

4.0
FLYPHT há 2 anos
ascendente
cometimento
f8e8274d4b
11 ficheiros alterados com 418 adições e 4 eliminações
  1. +10
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java
  2. +1
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java
  3. +20
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginSuccessParam.java
  4. +3
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginVO.java
  5. +19
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MappingUserParam.java
  6. +21
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MappingUserRet.java
  7. +9
    -1
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java
  8. +16
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/IListenerIntf.java
  9. +40
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/SwParameter.java
  10. +166
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/SwReturn.java
  11. +113
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/factory/ListenerFactory.java

+ 10
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java Ver ficheiro

@@ -5,7 +5,10 @@ import cc.smtweb.framework.core.annotation.SwParam;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.cache.CacheManager;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.container.base.SwParameter;
import cc.smtweb.framework.core.container.factory.ListenerFactory;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.exception.BizException;
import cc.smtweb.framework.core.session.SessionManager;
@@ -91,6 +94,13 @@ public class AuthService {
data.put("token", loginAckVO.getToken());
data.put("isOk", true);
data.put("msg", "");
// 发布登录成功事件
SwParameter parameter = new SwParameter();
LoginSuccessParam loginSuccessParam = new LoginSuccessParam();
loginSuccessParam.setUs(userSession);
loginSuccessParam.setExtra(loginPO.getExtra() != null?loginPO.getExtra():new SwMap());
parameter.setSingleParam(loginSuccessParam);
ListenerFactory.fireListenerAsyc(SwConsts.EventConst.LOGIN_SUCCESS,parameter);
return R.success(data);
}



+ 1
- 3
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java Ver ficheiro

@@ -23,7 +23,6 @@ import java.util.Set;
* 登录辅助类
*/
public class LoginHelper {

private static final String PWD_SALT = "goodpj";

public static User login(LoginVO loginPO) {
@@ -31,12 +30,11 @@ public class LoginHelper {
//先提取验证码
String verifyCode = RedisManager.getInstance().get(key, String.class);
RedisManager.getInstance().del(key);
MappingUserParam mappingUserEvent = new MappingUserParam();
if (StringUtils.isBlank(loginPO.getUsername())) {
throw new BizException("账号不能为空");
}


if (StringUtils.isBlank(loginPO.getPassword())) {
throw new BizException("密码不能为空");
}


+ 20
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginSuccessParam.java Ver ficheiro

@@ -0,0 +1,20 @@
package cc.smtweb.system.bpm.web.login;

import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.session.UserSession;
import lombok.Data;

import java.io.Serializable;

/**
* @Author: tanghp
* @Date: 2022-09-14 9:53
* @Desc: 登录成功事件的参数对象
*/
@Data
public class LoginSuccessParam implements Serializable {
// 登录的userSession
private UserSession us;
// 其他信息
private SwMap extra;
}

+ 3
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginVO.java Ver ficheiro

@@ -1,5 +1,6 @@
package cc.smtweb.system.bpm.web.login;

import cc.smtweb.framework.core.common.SwMap;
import lombok.Data;

import java.io.Serializable;
@@ -13,4 +14,6 @@ public class LoginVO implements Serializable {
private String verifyCode;

private String uuid;

private SwMap extra;
}

+ 19
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MappingUserParam.java Ver ficheiro

@@ -0,0 +1,19 @@
package cc.smtweb.system.bpm.web.login;

import cc.smtweb.framework.core.common.SwMap;
import lombok.Data;

import java.io.Serializable;

/**
* @Author: tanghp
* @Date: 2022-09-09 16:52
* @Desc: 用户映射事件参数对象
*/
@Data
public class MappingUserParam implements Serializable {
// 来源
private String source;
// 其他信息
private SwMap extra;
}

+ 21
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MappingUserRet.java Ver ficheiro

@@ -0,0 +1,21 @@
package cc.smtweb.system.bpm.web.login;

import cc.smtweb.framework.core.common.SwMap;
import lombok.Data;

import java.io.Serializable;

/**
* @Author: tanghp
* @Date: 2022-09-09 17:32
* @Desc: 用户映射返回
*/
@Data
public class MappingUserRet implements Serializable {
// 用户ID
private long userId;
// 映射失败信息
private String failMsg;
// 其他响应信息
private SwMap extra;
}

+ 9
- 1
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwConsts.java Ver ficheiro

@@ -16,7 +16,15 @@ public interface SwConsts {
//是否执行定时任务
public static boolean enableJob = false;
}

//事件常量
class EventConst {
// 登录映射
public static final String LOGIN_MAPPING = "LOGIN_MAPPING";
//登录成功后事件
public static final String LOGIN_SUCCESS = "LOGIN_SUCCESS";
//登录失败后事件
public static final String LOGIN_FAIL = "LOGIN_FAIL";
}
//错误码
interface ErrorCode {
//未登录


+ 16
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/IListenerIntf.java Ver ficheiro

@@ -0,0 +1,16 @@
package cc.smtweb.framework.core.container.base;

/**
* Created by Akmm at 12-3-22 下午4:52
* 事件监听
*/
public interface IListenerIntf {
/**
* 监听动作
*
* @param parameter 输入参数
* @param reslt 返回参数
* @throws Exception
*/
void doWork(SwParameter parameter, SwReturn result) throws Exception;
}

+ 40
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/SwParameter.java Ver ficheiro

@@ -0,0 +1,40 @@
package cc.smtweb.framework.core.container.base;

/**
* Created by Akmm at 2011-1-12 9:41:41
* 输入参数
*/
public class SwParameter extends java.util.HashMap<String, Object> {

private Object singleParam;

public <T> T getSingleParam() {
return (T)singleParam;
}

public void setSingleParam(Object singleParam) {
this.singleParam = singleParam;
}

/**
* 得到参数值
*
* @param name 参数名
* @param <T> 参数类型
* @return 参数值
*/
@SuppressWarnings({"unchecked"})
public <T> T getParameter(String name) {
return (T) get(name);
}

/**
* 设置参数值
*
* @param name 参数名
* @param value 参数值
*/
public void setParameter(String name, Object value) {
put(name, value);
}
}

+ 166
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/SwReturn.java Ver ficheiro

@@ -0,0 +1,166 @@
package cc.smtweb.framework.core.container.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by Akmm at 2011-1-12 9:45:04
* 插件服务方法的返回参数
*/
@SuppressWarnings("UnusedDeclaration")
public class SwReturn {
/**
* 是否执行成功
*/
private boolean isSuccess;
/**
* 提示信息列表
*/
private List<String> messages = null;
/**
* 执行结果参数
*/
private Map<String, Object> map = new HashMap<>();

/**
* @param isSuccess
* @param message
*/
public SwReturn(boolean isSuccess, String message) {
this.isSuccess = isSuccess;
this.addMessage(message);
}

public SwReturn(Integer errCode, String message) {
this.isSuccess = false;
this.addMessage(message);
this.setParameter("errCode", errCode);
}

public SwReturn(String errCode, String message) {
this.isSuccess = false;
this.addMessage(message);
this.setParameter("errCode", errCode);
}

/**
*/
public SwReturn() {
this(true, null);
}

/**
* 设置参数
*
* @param name
* @param value
* @pdOid 590f34f1-b661-4a64-8dbb-b1c9a4ec931e
*/
public void setParameter(String name, Object value) {
map.put(name, value);
}

/**
* 获取参数
*
* @param name
* @pdOid a0df6724-734d-4c5d-b156-e96010436ee8
*/
@SuppressWarnings({"unchecked"})
public <T> T getParameter(String name) {
return (T) map.get(name);
}

public boolean containsParameter(String name) {
return map.containsKey(name);
}

/**
* 是否执行成功
*/
public boolean isSuccess() {
return isSuccess;
}

/**
* @param success
* @pdOid bf4fdbfe-a134-43b7-9496-578fb61ab106
*/
public void setSuccess(boolean success) {
isSuccess = success;
}

/**
* 得到提示信息,字符串格式,有多个提示,则以回车符分隔
*/
public String getMessageStr() {
if (this.messages == null) return null;
StringBuilder sb = new StringBuilder(32);
for (String s : messages) {
sb.append("\n").append(s);
}
return sb.substring(1);
}

/**
* 得到结果参数Map
*/
public Map<String, Object> getMap() {
return map;
}

/**
* 增加一条提示信息
*
* @param msg
*/
public void addMessage(String msg) {
if (this.messages == null)
this.messages = new ArrayList<>();
if (msg != null) this.messages.add(msg);
}

/**
* 设置消息
*
* @param msg
*/
public void setMessage(String msg) {
clearMessage();
addMessage(msg);
}

/**
* 清空所有提示信息
*/
public void clearMessage() {
if (this.messages != null) this.messages.clear();
}

/**
* 得到提示信息列表
*
* @return
*/
public List<String> getMessages() {
return messages;
}

/**
* 设置为执行失败,且增加错误信息
*
* @param errmsg
*/
public void setError(String errmsg) {
this.isSuccess = false;
addMessage(errmsg);
}
public int getErrorCode() {
if (!isSuccess() && containsParameter("errCode")) {
return (Integer) getParameter("errCode");
}
return 0;
}
}

+ 113
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/factory/ListenerFactory.java Ver ficheiro

@@ -0,0 +1,113 @@
package cc.smtweb.framework.core.container.factory;

import cc.smtweb.framework.core.container.base.IListenerIntf;
import cc.smtweb.framework.core.container.base.SwParameter;
import cc.smtweb.framework.core.container.base.SwReturn;
import cc.smtweb.framework.core.systask.SysThreadPool;
import cc.smtweb.framework.core.systask.SysThreadWorker;

import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;

/**
* Created by Akmm at 12-3-22 下午4:45
* 事件监听工厂
*/
public class ListenerFactory {
private static Map<String, List<IListenerIntf>> map;

static {
map = new ConcurrentHashMap<>(64);
}

/**
* 注册监听
*
* @param event 事件名
* @param listener 监听类
*/
public static void reg(String event, IListenerIntf listener) {
List<IListenerIntf> list = map.get(event);
if (list == null) {
synchronized (ListenerFactory.class) {
list = map.get(event);
if (list == null) {
list = new Vector<>();
map.put(event, list);
}
}
}
list.add(listener);
}

/**
* 取消注册监听
*
* @param event 事件名
* @param listener 监听类
*/
public static void remove(String event, IListenerIntf listener) {
List<IListenerIntf> list = map.get(event);
if (list != null) list.remove(listener);
}

/**
* 取消指定事件所有监听
*
* @param event 事件名
*/
public static void clear(String event) {
map.remove(event);
}

/**
* 执行监听
*
* @param event 事件名
* @param param 事件参数
* @param result 监听程序的执行结果
* @throws Exception
*/
public static void fireListener(String event, SwParameter param, SwReturn result)throws Exception{
List<IListenerIntf> list = map.get(event);
if (list == null) return;
for (IListenerIntf listener : list) {
listener.doWork(param, result);
if (!result.isSuccess()) return;
}
}

/**
* 执行监听
*
* @param event 事件名
* @param param 事件参数
* @throws Exception
*/
public static void fireListener(String event, SwParameter param) throws Exception {
SwReturn result = new SwReturn();
fireListener(event, param, result);
if (!result.isSuccess()) throw new Exception(result.getMessageStr());
}
/**
* 执行监听\异步执行
*
* @param event 事件名
* @param param 事件参数
* @throws Exception
*/
public static void fireListenerAsyc(String event, SwParameter param){
SysThreadPool.getInstance().addTask(new SysThreadWorker() {
@Override
public void localWork() throws Exception {
try {
fireListener(event, param);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}

Carregando…
Cancelar
Guardar