commit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package io.v.nutz;
|
||||
|
||||
import io.v.nutz.base.utils.AppIocUtil;
|
||||
import io.v.nutz.sys.models.*;
|
||||
import io.v.nutz.zhgh.proposal.models.ProposalUndertake;
|
||||
import io.v.nutz.sys.services.SysTaskService;
|
||||
@@ -95,6 +96,8 @@ public class MainLauncher {
|
||||
init_task();
|
||||
init_proposal_undertake();
|
||||
ioc.get(Globals.class);
|
||||
|
||||
AppIocUtil.setIoc(ioc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.v.nutz.base.event.common;
|
||||
|
||||
public interface SysCommonDataChange {
|
||||
|
||||
|
||||
/**
|
||||
* 系统通用数据变更
|
||||
*
|
||||
* @param changeType 变更类型
|
||||
* @param tClass 数据类型 例如user、unit...............
|
||||
* @param bizId 业务ID
|
||||
*/
|
||||
void exec(SysCommonDataChangeType changeType, Class<?> tClass, String bizId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.v.nutz.base.event.common;
|
||||
|
||||
import org.nutz.mvc.Mvcs;
|
||||
|
||||
/**
|
||||
* @author zhf
|
||||
* @date 2025/8/14 17:23
|
||||
* @description
|
||||
*/
|
||||
public class SysCommonDataChangeCenter {
|
||||
|
||||
public static void publish(SysCommonDataChangeType changeType, Class<?> tClass, String bizId){
|
||||
String[] names = Mvcs.getIoc().getNamesByType(SysCommonDataChange.class);
|
||||
for (String listener : names) {
|
||||
SysCommonDataChange listenerBean = Mvcs.getIoc().get(SysCommonDataChange.class, listener);
|
||||
listenerBean.exec(changeType, tClass, bizId);
|
||||
// 是否在事务中
|
||||
// boolean transactionNone = Trans.isTransactionNone();
|
||||
// if(transactionNone){
|
||||
//
|
||||
// }else{
|
||||
// ThreadUtil.execAsync(() ->);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.v.nutz.base.event.common;
|
||||
|
||||
/**
|
||||
* 数据变更类型
|
||||
*/
|
||||
public enum SysCommonDataChangeType {
|
||||
|
||||
INSERT(),
|
||||
UPDATE(),
|
||||
DELETE()
|
||||
}
|
||||
@@ -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,70 @@
|
||||
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,25 @@
|
||||
package io.v.nutz.base.event.user;
|
||||
|
||||
import io.v.nutz.base.utils.AppIocUtil;
|
||||
import org.nutz.ioc.Ioc;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:UserChangePublisher
|
||||
* @Date 2025/8/13 14:23
|
||||
* @注释
|
||||
*/
|
||||
public class UserChangePublisher {
|
||||
|
||||
// 发送消息给所有订阅者
|
||||
public static void broadcast(UserChangeMsg msg) {
|
||||
Ioc ioc = AppIocUtil.get();
|
||||
|
||||
String[] names = ioc.getNamesByType(UserChangeEventListener.class);
|
||||
for (String listener : names) {
|
||||
UserChangeEventListener listenerBean = ioc.get(UserChangeEventListener.class, listener);
|
||||
listenerBean.receive(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.v.nutz.base.utils;
|
||||
|
||||
import org.nutz.ioc.Ioc;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:AppIocUtil
|
||||
* @Date 2025/8/26 17:40
|
||||
* @注释
|
||||
*/
|
||||
public class AppIocUtil {
|
||||
|
||||
private static Ioc ioc;
|
||||
|
||||
public static void setIoc(Ioc ioc) {
|
||||
AppIocUtil.ioc = ioc;
|
||||
}
|
||||
|
||||
public static Ioc get() {
|
||||
if (ioc == null) {
|
||||
throw new IllegalStateException("Ioc not initialized yet!");
|
||||
}
|
||||
return ioc;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.base.annontation.ViReturn;
|
||||
import io.v.nutz.base.event.user.UserChangeMsg;
|
||||
import io.v.nutz.base.event.user.UserChangePublisher;
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.base.utils.PageUtil;
|
||||
import io.v.nutz.base.utils.Roles;
|
||||
@@ -30,6 +32,7 @@ import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
@@ -38,10 +41,7 @@ import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.trans.Trans;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -342,9 +342,37 @@ public class SysUnionMangeCon {
|
||||
try {
|
||||
//再删除工会负责人的权限
|
||||
sysUnionService.clear("sys_user_role", Cnd.where("unionid", "=", unionid).and("roleid", "=", Roles.UNION_MANGER));
|
||||
for (String id : Json.fromJsonAsList(String.class, userids)) {
|
||||
sysUnionService.clear("sys_user_role", Cnd.where("unionid", "is", null).and("roleid", "=", Roles.UNION_MANGER));
|
||||
List<String> strings = Json.fromJsonAsList(String.class, userids).stream().distinct().collect(Collectors.toList());
|
||||
for (String id : strings) {
|
||||
sysUnionService.insert("sys_user_role", Chain.make("roleid", Roles.UNION_MANGER).add("userid", id).add("unionid", unionid));
|
||||
}
|
||||
// 删除这个人在其他分工会的角色 096072
|
||||
sysUserService.dao().clear(Sys_user_role.class, Cnd.where("userId", "in", strings)
|
||||
.and("unionId", "!=", unionid));
|
||||
|
||||
// 找出分工会里面所有的工会干部,看这些人的工会与对应的分工会管理员是不是一致的,不一致的删除
|
||||
List<Sys_user_role> userRoleList = sysUserService.dao().query(Sys_user_role.class, Cnd.where("roleId", "=", Roles.UNION_MANGER));
|
||||
|
||||
// 去查询user中的unionid
|
||||
Set<String> userIds = userRoleList.stream().map(Sys_user_role::getUserId).collect(Collectors.toSet());
|
||||
Sql sql = Sqls.create("SELECT u.id,u.unionid from `user` u WHERE u.id in (@userIds)").setParam("userIds", userIds);
|
||||
sql.setCallback(Sqls.callback.maps());
|
||||
sysUserService.dao().execute(sql);
|
||||
List<NutMap> userList = (List<NutMap>) sql.getResult();
|
||||
// 转map,找差异
|
||||
Map<String, String> userMap = userList.stream().collect(Collectors.toMap(v -> v.getString("id"), v -> v.getString("unionid")));
|
||||
|
||||
List<Sys_user_role> diffUnionRoleList = userRoleList.stream().filter(v -> userMap.containsKey(v.getUserId())
|
||||
&& !v.getUnionid().equals(userMap.get(v.getUserId()))).collect(Collectors.toList());
|
||||
// 删除这些人的角色
|
||||
if (org.nutz.lang.Lang.isNotEmpty(diffUnionRoleList)) {
|
||||
sysUserService.dao().clear(Sys_user_role.class, Cnd.where("userId", "in", diffUnionRoleList.stream().map(Sys_user_role::getUserId).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
// 发送广播订阅
|
||||
// UserChangePublisher.broadcast(new UserChangeMsg(List.of("1"), UserChangeMsg.UNIT_CHANGE_OPERATION));
|
||||
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
|
||||
Reference in New Issue
Block a user