Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
package io.v.nutz.base.event.user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 1.0
|
||||||
|
* @Author zzr
|
||||||
|
* @name:UserChangeEventListener
|
||||||
|
* @Date 2025/8/13 14:18
|
||||||
|
* @注释
|
||||||
|
*/
|
||||||
|
public interface UserChangeEventListener {
|
||||||
|
|
||||||
|
void receive(UserChangeMsg message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package io.v.nutz.base.event.user;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 1.0
|
||||||
|
* @Author zzr
|
||||||
|
* @name:UserChangeMsg
|
||||||
|
* @Date 2025/8/13 11:51
|
||||||
|
* @注释
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class UserChangeMsg {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变更资源,用户Id
|
||||||
|
*/
|
||||||
|
private List<String> userIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型
|
||||||
|
*/
|
||||||
|
private Integer operationType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变更前的单位Id,当operationType值为1时,该字段有效
|
||||||
|
*/
|
||||||
|
private String sourceUnitId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变更后的单位Id,当operationType值为1时,该字段有效
|
||||||
|
*/
|
||||||
|
private String targetUnitId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单位变动
|
||||||
|
*/
|
||||||
|
public final static int UNIT_CHANGE_OPERATION = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退休
|
||||||
|
*/
|
||||||
|
public final static int RETIRE_OPERATION = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入会
|
||||||
|
*/
|
||||||
|
public final static int RESTORE_OPERATION = 3;
|
||||||
|
|
||||||
|
|
||||||
|
public UserChangeMsg(List<String> userIds, Integer operationType) {
|
||||||
|
super();
|
||||||
|
this.userIds = userIds;
|
||||||
|
this.operationType = operationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserChangeMsg(List<String> userIds, Integer operationType, String sourceUnitId) {
|
||||||
|
super();
|
||||||
|
this.userIds = userIds;
|
||||||
|
this.operationType = operationType;
|
||||||
|
this.sourceUnitId = sourceUnitId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package io.v.nutz.base.event.user;
|
||||||
|
|
||||||
|
import org.nutz.mvc.Mvcs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 1.0
|
||||||
|
* @Author zzr
|
||||||
|
* @name:UserChangePublisher
|
||||||
|
* @Date 2025/8/13 14:23
|
||||||
|
* @注释
|
||||||
|
*/
|
||||||
|
public class UserChangePublisher {
|
||||||
|
|
||||||
|
// 发送消息给所有订阅者
|
||||||
|
public static void broadcast(UserChangeMsg msg) {
|
||||||
|
String[] names = Mvcs.getIoc().getNamesByType(UserChangeEventListener.class);
|
||||||
|
for (String listener : names) {
|
||||||
|
UserChangeEventListener listenerBean = Mvcs.getIoc().get(UserChangeEventListener.class, listener);
|
||||||
|
listenerBean.receive(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package io.v.nutz.data.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import io.v.nutz.base.event.user.UserChangeMsg;
|
||||||
|
import io.v.nutz.base.event.user.UserChangePublisher;
|
||||||
import io.v.nutz.data.constant.SourceData;
|
import io.v.nutz.data.constant.SourceData;
|
||||||
import io.v.nutz.data.constant.UserChangeType;
|
import io.v.nutz.data.constant.UserChangeType;
|
||||||
import io.v.nutz.data.model.UserHistory;
|
import io.v.nutz.data.model.UserHistory;
|
||||||
@@ -155,6 +157,10 @@ public class SourceUserServiceImpl extends ViServiceImpl<UserSource> implements
|
|||||||
newUser.setId(userId);
|
newUser.setId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changeType == UserChangeType.UNIT_CHANGE) {
|
||||||
|
UserChangePublisher.broadcast(new UserChangeMsg(List.of(user.getId()), UserChangeMsg.RESTORE_OPERATION, user.getUnitid(), newUser.getUnitid()));
|
||||||
|
}
|
||||||
|
|
||||||
UserHistory history = new UserHistory();
|
UserHistory history = new UserHistory();
|
||||||
BeanUtils.copyProperties(newUser, history);
|
BeanUtils.copyProperties(newUser, history);
|
||||||
history.setChangeTime(DateUtil.date());
|
history.setChangeTime(DateUtil.date());
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package io.v.nutz.member.handle;
|
package io.v.nutz.member.handle;
|
||||||
|
|
||||||
|
import io.v.nutz.base.event.user.UserChangeMsg;
|
||||||
|
import io.v.nutz.base.event.user.UserChangePublisher;
|
||||||
import io.v.nutz.data.constant.UserChangeType;
|
import io.v.nutz.data.constant.UserChangeType;
|
||||||
import io.v.nutz.data.model.UserHistory;
|
import io.v.nutz.data.model.UserHistory;
|
||||||
import io.v.nutz.member.MemberMode;
|
import io.v.nutz.member.MemberMode;
|
||||||
@@ -19,6 +21,7 @@ import org.nutz.dao.Cnd;
|
|||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员变更Handle
|
* 会员变更Handle
|
||||||
@@ -37,6 +40,11 @@ public enum MemberChangeHandle {
|
|||||||
@Override
|
@Override
|
||||||
public void change(MemberChangeRecord record) {
|
public void change(MemberChangeRecord record) {
|
||||||
archive(record.getUserId(), UserChangeType.UNIT_CHANGE);
|
archive(record.getUserId(), UserChangeType.UNIT_CHANGE);
|
||||||
|
|
||||||
|
// 单位变更发送广播消息
|
||||||
|
UserChangePublisher.broadcast(new UserChangeMsg(List.of(record.getUserId()),
|
||||||
|
UserChangeMsg.UNIT_CHANGE_OPERATION, record.getOriginUnitId(), record.getCurrentUnitId()));
|
||||||
|
|
||||||
sysUserService.update(Chain.make("unitid", record.getCurrentUnitId()).add("unionid", record.getCurrentUnionId()), Cnd.where("id", "=", record.getUserId()));
|
sysUserService.update(Chain.make("unitid", record.getCurrentUnitId()).add("unionid", record.getCurrentUnionId()), Cnd.where("id", "=", record.getUserId()));
|
||||||
|
|
||||||
sysUserService.clearCache();
|
sysUserService.clearCache();
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package io.v.nutz.sys.listener;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import io.v.nutz.base.event.user.UserChangeEventListener;
|
||||||
|
import io.v.nutz.base.event.user.UserChangeMsg;
|
||||||
|
import io.v.nutz.sys.models.Sys_user_role;
|
||||||
|
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||||
|
import org.nutz.dao.Cnd;
|
||||||
|
import org.nutz.dao.Dao;
|
||||||
|
import org.nutz.dao.Sqls;
|
||||||
|
import org.nutz.dao.sql.Sql;
|
||||||
|
import org.nutz.ioc.aop.Aop;
|
||||||
|
import org.nutz.ioc.loader.annotation.Inject;
|
||||||
|
import org.nutz.ioc.loader.annotation.IocBean;
|
||||||
|
import org.nutz.lang.util.NutMap;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @version 1.0
|
||||||
|
* @Author zzr
|
||||||
|
* @name:SysUserChangeListener
|
||||||
|
* @Date 2025/8/13 15:24
|
||||||
|
* @注释 有关系统人员的广播监听
|
||||||
|
*/
|
||||||
|
@IocBean
|
||||||
|
public class SysUserChangeListener implements UserChangeEventListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Dao dao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Aop(TransAop.READ_COMMITTED)
|
||||||
|
public void receive(UserChangeMsg message) {
|
||||||
|
if (ObjectUtil.equals(message.getOperationType(), UserChangeMsg.UNIT_CHANGE_OPERATION)) {
|
||||||
|
// 单位变动,删除原单位的角色
|
||||||
|
dao.clear(Sys_user_role.class, Cnd.where("userId", "in", message.getUserIds()).and("unitid", "=", message.getSourceUnitId()));
|
||||||
|
|
||||||
|
// 判断这两个单位是不是在一个工会,如果不是,删除原来工会的所有角色
|
||||||
|
Sql sql = Sqls.create("""
|
||||||
|
SELECT
|
||||||
|
(SELECT unionId FROM sys_unit WHERE id = @sourceUnitId) AS sourceUnionId,
|
||||||
|
(SELECT unionId FROM sys_unit WHERE id = @targetUnitId) AS targetUnionId,
|
||||||
|
CASE
|
||||||
|
WHEN (SELECT unionId FROM sys_unit WHERE id = @sourceUnitId) IS NULL
|
||||||
|
AND (SELECT unionId FROM sys_unit WHERE id = @targetUnitId) IS NULL THEN true
|
||||||
|
WHEN (SELECT unionId FROM sys_unit WHERE id = @sourceUnitId) =
|
||||||
|
(SELECT unionId FROM sys_unit WHERE id = @targetUnitId) THEN true
|
||||||
|
ELSE false
|
||||||
|
END AS result
|
||||||
|
""").setParam("sourceUnitId", message.getSourceUnitId()).setParam("targetUnitId", message.getTargetUnitId());
|
||||||
|
sql.setCallback(Sqls.callback.map());
|
||||||
|
dao.execute(sql);
|
||||||
|
NutMap result = (NutMap) sql.getResult();
|
||||||
|
|
||||||
|
if (!result.getBoolean("result")) {
|
||||||
|
dao.clear(Sys_user_role.class, Cnd.where("userId", "in", message.getUserIds()).and("unionid", "=", result.getString("sourceUnionId")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user