diff --git a/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeController.java b/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeController.java index 1d78f37c..2bb49796 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeController.java @@ -53,6 +53,8 @@ import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; @@ -67,6 +69,9 @@ import java.util.stream.Collectors; @Slf4j public class ActivityBasicScopeController { + private static final int GROUP_TYPE_RESULT = 1; + private static final int GROUP_TYPE_SQL = 2; + @Inject private BaseService baseService; @@ -135,51 +140,18 @@ public class ActivityBasicScopeController { @SLog(tag = "活动人员设置", msg = "设置活动人员") @SaCheckPermission("activity.basic.scope") public Object doSetActivityUser(@Param("data") ActivityUserScopePageParam activityUserScopePageParam) { - Sql sql = Sqls.create(""" - SELECT DISTINCT - ( u.id ) AS userId - FROM - `vw_user` u - LEFT JOIN sys_user_role sur ON sur.userid = u.id - LEFT JOIN club_user clubuser ON clubuser.userid=u.id - $condition - """); - Cnd cnd = getCnd(activityUserScopePageParam); - - sql.setCondition(cnd); - sql.setCallback(Sqls.callback.entities()); - sql.setEntity(dao.getEntity(ActivityUserScope.class)); - dao.execute(sql); - - List list = sql.getList(ActivityUserScope.class); - - String groupName = null; - int maxCount = 0; - - if (activityUserScopePageParam.getSetGroupType() == 1) { - groupName = dao.execute(Sqls.fetchString("select groupName from activity_user_scope where groupId = @groupId").setParam("groupId", activityUserScopePageParam.getSetGroupId())).getString(); - } else if (activityUserScopePageParam.getSetGroupType() == 2) { - maxCount = baseService.count(Sqls.create("select max(groupId) from activity_user_scope")); + Integer groupType = normalizeGroupType(activityUserScopePageParam.getGroupType()); + if (activityUserScopePageParam.getSetGroupType() == null) { + return Result.error("请选择添加方式"); + } + if (groupType == null) { + return Result.error("请选择分组保存方式"); } - for (ActivityUserScope userScope : list) { - if (activityUserScopePageParam.getSetGroupType() == 1) { - userScope.setGroupId(activityUserScopePageParam.getSetGroupId()); - userScope.setGroupName(groupName); - } else if (activityUserScopePageParam.getSetGroupType() == 2) { - userScope.setGroupId(maxCount + 1); - userScope.setGroupName(activityUserScopePageParam.getSetGroupName()); - } - userScope.setCreator(SecurityUtil.getUserId()); + if (GROUP_TYPE_SQL == groupType) { + return saveSqlScopeGroup(activityUserScopePageParam); } - - if (list.size() < 500) { - dao.insert(list); - return Result.success(activityUserScopePageParam.getSetGroupType() == 1 ? activityUserScopePageParam.getSetGroupId() : maxCount + 1); - } - //多线程插入 - activityBasicScopeService.largeDataInsert(list); - return Result.success(activityUserScopePageParam.getSetGroupType() == 1 ? activityUserScopePageParam.getSetGroupId() : maxCount + 1); + return saveResultScopeGroup(activityUserScopePageParam); } /** @@ -192,7 +164,8 @@ public class ActivityBasicScopeController { Sql sql = Sqls.create(""" SELECT groupId, - groupName + groupName, + IFNULL(MAX(groupType), 1) AS groupType FROM activity_user_scope $condition @@ -208,7 +181,7 @@ public class ActivityBasicScopeController { } cnd.and("groupId", "IS NOT", null); cnd.and("groupName", "IS NOT", null); - cnd.groupBy("groupId"); + cnd.groupBy("groupId,groupName"); sql.setCondition(cnd); return Result.success(baseService.listMap(sql)); } @@ -222,8 +195,7 @@ public class ActivityBasicScopeController { @At public Object getScopeUser(String activityGroupId, @Param(value = "userId") String userId) { String userid = StrUtil.isNotBlank(userId) ? userId : SecurityUtil.getUserId(); - int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", activityGroupId).and("userId", "=", userid)); - return Result.success(count); + return Result.success(activityBasicScopeService.isUserInGroup(Integer.valueOf(activityGroupId), userid) ? 1 : 0); } @At @@ -340,7 +312,7 @@ public class ActivityBasicScopeController { } if (activityUserScopePageParam.getActivityGroupId() != null) { - Sql sqlx = Sqls.createf("SELECT userId FROM activity_user_scope where groupId = '%s'", activityUserScopePageParam.getActivityGroupId()); + Sql sqlx = activityBasicScopeService.buildGroupUserIdSubSql(activityUserScopePageParam.getActivityGroupId()); cnd.and("u.id", activityUserScopePageParam.getReverseSelection() ? "IN" : "NOT IN", sqlx); } @@ -395,6 +367,271 @@ public class ActivityBasicScopeController { } + /** + * 结果分组会把当前筛选出的用户快照保存下来,因此只落 userId 明细数据。 + */ + private Result saveResultScopeGroup(ActivityUserScopePageParam activityUserScopePageParam) { + List matchedUserScopeList = queryMatchedUserScopeList(activityUserScopePageParam); + String creator = SecurityUtil.getUserId(); + Integer groupId; + String groupName; + + if (activityUserScopePageParam.getSetGroupType() == 1) { + if (activityUserScopePageParam.getSetGroupId() == null) { + return Result.error("请选择原有分组"); + } + ActivityUserScope groupMeta = getGroupBaseInfo(activityUserScopePageParam.getSetGroupId()); + if (groupMeta == null) { + return Result.error("未查询到原有分组"); + } + if (!Objects.equals(normalizeGroupType(groupMeta.getGroupType()), GROUP_TYPE_RESULT)) { + return Result.error("结果分组只能添加到结果分组中"); + } + groupId = groupMeta.getGroupId(); + groupName = groupMeta.getGroupName(); + } else { + if (StrUtil.isBlank(activityUserScopePageParam.getSetGroupName())) { + return Result.error("请输入新分组名称"); + } + groupId = getNextGroupId(); + groupName = activityUserScopePageParam.getSetGroupName(); + } + + Set existsUserIdSet = dao.query(ActivityUserScope.class, Cnd.where("groupId", "=", groupId).and("userId", "IS NOT", null)) + .stream() + .map(ActivityUserScope::getUserId) + .filter(StrUtil::isNotBlank) + .collect(Collectors.toSet()); + + List insertList = matchedUserScopeList.stream() + .filter(item -> StrUtil.isNotBlank(item.getUserId()) && !existsUserIdSet.contains(item.getUserId())) + .peek(item -> { + item.setGroupId(groupId); + item.setGroupName(groupName); + item.setGroupType(GROUP_TYPE_RESULT); + item.setGroupSql(null); + item.setCreator(creator); + }) + .toList(); + + if (insertList.isEmpty()) { + return Result.success(groupId); + } + if (insertList.size() < 500) { + dao.insert(insertList); + } else { + activityBasicScopeService.largeDataInsert(insertList); + } + return Result.success(groupId); + } + + /** + * SQL条件分组在 activity_user_scope 中只保存一条元数据记录。 + * 后续所有按分组取人的地方统一通过 groupSql 动态解析,不再额外落 userId 快照。 + */ + private Result saveSqlScopeGroup(ActivityUserScopePageParam activityUserScopePageParam) { + String currentGroupSql = buildGroupSql(activityUserScopePageParam); + if (StrUtil.isBlank(currentGroupSql)) { + return Result.error("未生成有效的SQL条件"); + } + + Integer groupId; + String groupName; + String creator = SecurityUtil.getUserId(); + String mergedGroupSql = currentGroupSql; + + if (activityUserScopePageParam.getSetGroupType() == 1) { + if (activityUserScopePageParam.getSetGroupId() == null) { + return Result.error("请选择原有分组"); + } + ActivityUserScope groupMeta = getGroupBaseInfo(activityUserScopePageParam.getSetGroupId()); + if (groupMeta == null) { + return Result.error("未查询到原有分组"); + } + if (!Objects.equals(normalizeGroupType(groupMeta.getGroupType()), GROUP_TYPE_SQL)) { + return Result.error("SQL条件分组只能添加到SQL条件分组中"); + } + groupId = groupMeta.getGroupId(); + groupName = groupMeta.getGroupName(); + creator = StrUtil.isNotBlank(groupMeta.getCreator()) ? groupMeta.getCreator() : creator; + if (StrUtil.isNotBlank(groupMeta.getGroupSql())) { + mergedGroupSql = "(" + groupMeta.getGroupSql() + ") OR (" + currentGroupSql + ")"; + } + dao.clear(ActivityUserScope.class, Cnd.where("groupId", "=", groupId)); + } else { + if (StrUtil.isBlank(activityUserScopePageParam.getSetGroupName())) { + return Result.error("请输入新分组名称"); + } + groupId = getNextGroupId(); + groupName = activityUserScopePageParam.getSetGroupName(); + } + + ActivityUserScope groupSqlMeta = new ActivityUserScope(); + groupSqlMeta.setGroupId(groupId); + groupSqlMeta.setGroupName(groupName); + groupSqlMeta.setGroupType(GROUP_TYPE_SQL); + groupSqlMeta.setGroupSql(mergedGroupSql); + groupSqlMeta.setCreator(creator); + dao.insert(groupSqlMeta); + return Result.success(groupId); + } + + private List queryMatchedUserScopeList(ActivityUserScopePageParam activityUserScopePageParam) { + Sql sql = Sqls.create(""" + SELECT DISTINCT + ( u.id ) AS userId + FROM + `vw_user` u + LEFT JOIN sys_user_role sur ON sur.userid = u.id + LEFT JOIN club_user clubuser ON clubuser.userid=u.id + $condition + """); + Cnd cnd = getCnd(activityUserScopePageParam); + sql.setCondition(cnd); + sql.setCallback(Sqls.callback.entities()); + sql.setEntity(dao.getEntity(ActivityUserScope.class)); + dao.execute(sql); + return sql.getList(ActivityUserScope.class); + } + + private ActivityUserScope getGroupBaseInfo(Integer groupId) { + if (groupId == null) { + return null; + } + Sql sql = Sqls.create(""" + SELECT + groupId, + groupName, + creator, + IFNULL(MAX(groupType), 1) AS groupType, + MAX(groupSql) AS groupSql + FROM activity_user_scope + WHERE groupId = @groupId + GROUP BY groupId, groupName, creator + LIMIT 1 + """); + sql.setParam("groupId", groupId); + ActivityUserScope o = activityBasicScopeService.fetchVO(sql, ActivityUserScope.class); + return o; + } + + private Integer getNextGroupId() { + Integer maxGroupId = baseService.count(Sqls.create("select max(groupId) from activity_user_scope")); + return maxGroupId == null ? 1 : maxGroupId + 1; + } + + private Integer normalizeGroupType(Integer groupType) { + return groupType == null ? GROUP_TYPE_RESULT : groupType; + } + + /** + * 把页面条件转换成可复用的 SQL 片段,后续同类分组追加时直接按 OR 拼接。 + */ + private String buildGroupSql(ActivityUserScopePageParam activityUserScopePageParam) { + List conditionList = new ArrayList<>(); + boolean reverseSelection = Boolean.TRUE.equals(activityUserScopePageParam.getReverseSelection()); + String inOrNotIn = reverseSelection ? "NOT IN" : "IN"; + String eqOrNeq = reverseSelection ? "!=" : "="; + + if (activityUserScopePageParam.getActivityGroupId() != null) { + conditionList.add("u.id " + (reverseSelection ? "IN" : "NOT IN") + + " (" + activityBasicScopeService.buildGroupUserIdSubSqlText(activityUserScopePageParam.getActivityGroupId()) + ")"); + } + + if (Lang.isNotEmpty(activityUserScopePageParam.getUserId())) { + conditionList.add("u.id " + inOrNotIn + " (" + buildSqlStringList(activityUserScopePageParam.getUserId()) + ")"); + } + + if (Lang.isNotEmpty(activityUserScopePageParam.getMemberTypes())) { + if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "工会会员")) { + conditionList.add("u.member " + eqOrNeq + " 1"); + } + if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "福利会员")) { + conditionList.add("u.welfareMember " + eqOrNeq + " 1"); + } + if (ArrayUtils.contains(activityUserScopePageParam.getMemberTypes(), "基金会员")) { + conditionList.add("u.loginname " + inOrNotIn + " (select loginname from sick_fund_member)"); + } + } + + if (!Lang.isEmptyArray(activityUserScopePageParam.getAge()) && activityUserScopePageParam.getAge().length >= 2 + && !"0".equals(activityUserScopePageParam.getAge()[1])) { + String ageBetweenSql = "TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) BETWEEN " + + sanitizeNumber(activityUserScopePageParam.getAge()[0]) + " AND " + sanitizeNumber(activityUserScopePageParam.getAge()[1]); + conditionList.add(reverseSelection ? "NOT (" + ageBetweenSql + ")" : ageBetweenSql); + } + + if (StrUtil.isNotBlank(activityUserScopePageParam.getExistsLoginNameRedisKey())) { + List loginNames = redisService.lrange(activityUserScopePageParam.getExistsLoginNameRedisKey(), 0, -1); + if (Lang.isEmpty(loginNames)) { + conditionList.add("1 = 0"); + } else { + conditionList.add("u.loginname IN (" + buildSqlStringList(loginNames.toArray(new String[0])) + ")"); + } + } + + if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) { + conditionList.add("u.unionid = " + wrapSqlValue(SecurityUtil.getUnionId())); + } + + addSingleValueCondition(conditionList, "u.unionid", eqOrNeq, activityUserScopePageParam.getUnionId()); + addSingleValueCondition(conditionList, "u.unitid", eqOrNeq, activityUserScopePageParam.getUnitId()); + addArrayCondition(conditionList, "u.personType", inOrNotIn, activityUserScopePageParam.getPersonTypes()); + addArrayCondition(conditionList, "u.userState", inOrNotIn, activityUserScopePageParam.getUserStates()); + addArrayCondition(conditionList, "u.sex", inOrNotIn, activityUserScopePageParam.getSexTypes()); + addSingleValueCondition(conditionList, "sur.tcSessionId", eqOrNeq, activityUserScopePageParam.getSessionId()); + addArrayCondition(conditionList, "sur.roleId", inOrNotIn, activityUserScopePageParam.getRoleIds()); + addSingleValueCondition(conditionList, "clubuser.clubid", eqOrNeq, activityUserScopePageParam.getClubId()); + + return conditionList.isEmpty() ? "1 = 1" : String.join(" AND ", conditionList); + } + + private List queryUserIdListByGroupSql(String groupSql) { + Sql sql = Sqls.create(""" + SELECT DISTINCT + u.id AS userId + FROM + `vw_user` u + LEFT JOIN sys_user_role sur ON sur.userid = u.id + LEFT JOIN club_user clubuser ON clubuser.userid = u.id + WHERE + """ + groupSql); + sql.setCallback(Sqls.callback.maps()); + dao.execute(sql); + return sql.getList(NutMap.class).stream() + .map(item -> item.getString("userId")) + .filter(StrUtil::isNotBlank) + .collect(Collectors.toList()); + } + + private void addSingleValueCondition(List conditionList, String columnName, String operator, String value) { + if (StrUtil.isNotBlank(value)) { + conditionList.add(columnName + " " + operator + " " + wrapSqlValue(value)); + } + } + + private void addArrayCondition(List conditionList, String columnName, String operator, String[] values) { + if (Lang.isNotEmpty(values)) { + conditionList.add(columnName + " " + operator + " (" + buildSqlStringList(values) + ")"); + } + } + + private String buildSqlStringList(String[] values) { + return buildSqlStringList(List.of(values)); + } + + private String buildSqlStringList(List values) { + return values.stream().filter(StrUtil::isNotBlank).map(this::wrapSqlValue).collect(Collectors.joining(",")); + } + + private String wrapSqlValue(String value) { + return "'" + StrUtil.replace(value, "'", "''") + "'"; + } + + private String sanitizeNumber(String value) { + return StrUtil.replace(value, "'", ""); + } + @At @Ok("void") diff --git a/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeUserDataController.java b/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeUserDataController.java index 925fb6c0..de119ce0 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeUserDataController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/basic/controller/ActivityBasicScopeUserDataController.java @@ -19,6 +19,7 @@ import com.budwk.app.base.utils.CommonDownloadUtil; import com.budwk.app.base.utils.easyexcel.EasyExcelUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.basic.template.UserTemp; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.formula.functions.T; @@ -28,7 +29,6 @@ import org.nutz.dao.Cnd; import org.nutz.dao.Sqls; import org.nutz.dao.sql.Sql; import org.nutz.dao.util.cri.SqlExpressionGroup; -import org.nutz.dao.util.cri.Static; import org.nutz.integration.jedis.RedisService; import org.nutz.ioc.aop.Aop; import org.nutz.ioc.loader.annotation.Inject; @@ -59,9 +59,14 @@ import java.util.stream.Collectors; @Ok("json:full") public class ActivityBasicScopeUserDataController { + private static final int GROUP_TYPE_SQL = 2; + @Inject private BaseService baseService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; + @Inject private RedisService redisService; @@ -81,9 +86,10 @@ public class ActivityBasicScopeUserDataController { @Param(value = "userState") String userState, @Param(value = "groupId") Integer groupId, @Param(value = "existsLoginNameRedisKey") String existsLoginNameRedisKey) { + ActivityUserScope groupInfo = activityBasicScopeService.getGroupInfo(groupId); Sql sql = Sqls.create(""" SELECT - aus.id, + u.id, u.username AS userName, u.loginname AS loginName, u.sex, @@ -93,15 +99,15 @@ public class ActivityBasicScopeUserDataController { u.userState, u.unitname AS unitName, u.unionname AS unionName, - aus.groupId, - aus.groupName + @groupId AS groupId, + @groupName AS groupName FROM - activity_user_scope aus - LEFT JOIN `vw_user` u ON u.id = aus.userId + `vw_user` u $condition - """); + """).setParam("groupId", groupId).setParam("groupName", groupInfo == null ? "" : groupInfo.getGroupName()); Cnd cnd = Cnd.NEW(); + cnd.and("u.id", "in", activityBasicScopeService.buildGroupUserIdSubSql(groupId)); if (StrUtil.isNotBlank(pageForm.getSearchKeyword())){ SqlExpressionGroup group = new SqlExpressionGroup(); group.orLike("u.username", pageForm.getSearchKeyword()); @@ -111,15 +117,10 @@ public class ActivityBasicScopeUserDataController { if (StrUtil.isNotBlank(pageForm.getPageOrderName()) && StrUtil.isNotBlank(pageForm.getPageOrderBy())) { cnd.orderBy(pageForm.getPageOrderName(), pageForm.getPageOrderBy().equalsIgnoreCase("ascending") ? "ASC" : "DESC"); } - cnd.andEX("aus.groupId", "=", groupId); cnd.andEX("u.unionid", "=", unionId); cnd.andEX("u.unitid", "=", unitId); cnd.andEX("u.personType", "=", personType); cnd.andEX("u.userState", "=", userState); - if (!StpUtil.hasRole(RoleConstant.SYSADMIN.name()) && - !StpUtil.hasRole(RoleConstant.SCHOOL_UNION_ADMIN.name())) { - cnd.and("aus.creator", "=", SecurityUtil.getUserId()); - } if (StrUtil.isNotBlank(existsLoginNameRedisKey)) { List loginNames = redisService.lrange(existsLoginNameRedisKey, 0, -1); cnd.andEX("u.loginname", "in", loginNames); @@ -159,32 +160,25 @@ public class ActivityBasicScopeUserDataController { } } - Sql sql = Sqls.create("select id from `vw_user` u $condition"); - Cnd userCnd = Cnd.NEW(); - if (StrUtil.isNotBlank(searchName) && StrUtil.isNotBlank(searchKeyword)) { - userCnd.and(Cnd.likeEX(searchName, searchKeyword)); + List targetUserIds = queryGroupUserIds(groupId, id, searchKeyword, searchName, unionId, unitId, personType, userState, existsLoginNames); + if (Lang.isEmpty(targetUserIds)) { + return Result.success(); } - userCnd.andEX("u.unionid", "=", unionId); - userCnd.andEX("u.unitid", "=", unitId); - userCnd.andEX("u.personType", "=", personType); - userCnd.andEX("u.userState", "=", userState); - userCnd.andEX("u.id", "=", id); - userCnd.andEX("u.loginname","in",existsLoginNames); - sql.setCondition(userCnd); - Cnd cnd = Cnd.NEW(); - cnd.and("groupId", "=", groupId); - if (!StpUtil.hasRole(RoleConstant.SYSADMIN.name()) && - !StpUtil.hasRole(RoleConstant.SCHOOL_UNION_ADMIN.name())) { - cnd.and("creator", "=", SecurityUtil.getUserId()); - } - if (StrUtil.isNotBlank(id)) { - cnd.and("id", "=", id); + Integer groupType = activityBasicScopeService.getGroupType(groupId); + if (GROUP_TYPE_SQL == groupType) { + // SQL分组不落 userId 明细,删除人员时通过追加排除条件来持久化删除结果。 + activityBasicScopeService.excludeUsersFromSqlGroup(groupId, targetUserIds); } else { - cnd.and(new Static("userId in (" + sql + ")")); + Cnd cnd = Cnd.where("groupId", "=", groupId).and("userId", "in", targetUserIds); + cnd.and("userId", "IS NOT", null); + if (!StpUtil.hasRole(RoleConstant.SYSADMIN.name()) && + !StpUtil.hasRole(RoleConstant.SCHOOL_UNION_ADMIN.name())) { + cnd.and("creator", "=", SecurityUtil.getUserId()); + } + baseService.dao().clear(ActivityUserScope.class, cnd); } - baseService.dao().clear(ActivityUserScope.class, cnd); - baseService.dao().clear(ActivityUserScope.class, Cnd.where(ActivityUserScope::getUserId, "not in", Sqls.create("select id from sys_user"))); + baseService.dao().clear(ActivityUserScope.class, Cnd.where("userId", "IS NOT", null).and("userId", "not in", Sqls.create("select id from sys_user"))); return Result.success(); } @@ -202,11 +196,12 @@ public class ActivityBasicScopeUserDataController { SELECT u.loginname FROM - activity_user_scope aus - LEFT JOIN sys_user u ON u.id = aus.userId + sys_user u WHERE - aus.groupId = @groupId - """).setParam("groupId", groupId); + u.id IN ( + """ + activityBasicScopeService.buildGroupUserIdSubSqlText(Integer.valueOf(groupId)) + """ + ) + """); baseService.execute(sql); String[] sysLoginNames = (String[]) sql.getResult(); @@ -259,13 +254,12 @@ public class ActivityBasicScopeUserDataController { u.unitname AS unitName, u.unionName AS unionName FROM - activity_user_scope aus - LEFT JOIN `vw_user` u ON u.id = aus.userId + `vw_user` u $condition """); Cnd cnd = Cnd.NEW(); - cnd.andEX("aus.groupId", "=", groupId); + cnd.and("u.id", "in", activityBasicScopeService.buildGroupUserIdSubSql(groupId)); sql.setCondition(cnd); List listMap = baseService.listMap(sql); @@ -286,4 +280,34 @@ public class ActivityBasicScopeUserDataController { } } + + /** + * 删除时需要先按页面当前筛选条件圈定目标人员,再根据分组类型删除对应存储表中的快照数据。 + */ + private List queryGroupUserIds(Integer groupId, String id, String searchKeyword, String searchName, + String unionId, String unitId, String personType, String userState, + List existsLoginNames) { + Sql sql = Sqls.queryString(""" + SELECT + u.id + FROM + `vw_user` u + $condition + """); + Cnd cnd = Cnd.NEW(); + cnd.and("u.id", "in", activityBasicScopeService.buildGroupUserIdSubSql(groupId)); + if (StrUtil.isNotBlank(searchName) && StrUtil.isNotBlank(searchKeyword)) { + cnd.and(Cnd.likeEX(searchName, searchKeyword)); + } + cnd.andEX("u.unionid", "=", unionId); + cnd.andEX("u.unitid", "=", unitId); + cnd.andEX("u.personType", "=", personType); + cnd.andEX("u.userState", "=", userState); + cnd.andEX("u.id", "=", id); + cnd.andEX("u.loginname", "in", existsLoginNames); + sql.setCondition(cnd); + baseService.execute(sql); + String[] userIds = (String[]) sql.getResult(); + return userIds == null ? new ArrayList<>() : List.of(userIds); + } } diff --git a/src/main/java/com/budwk/app/zhgh/activity/basic/models/ActivityUserScope.java b/src/main/java/com/budwk/app/zhgh/activity/basic/models/ActivityUserScope.java index e2517cd0..509f6236 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/basic/models/ActivityUserScope.java +++ b/src/main/java/com/budwk/app/zhgh/activity/basic/models/ActivityUserScope.java @@ -46,6 +46,16 @@ public class ActivityUserScope extends BaseModel implements Serializable { @Comment("userid") private String userId; + @Column + @ColDefine(type = ColType.INT, width = 2) + @Comment("分组类型 1.结果分组 2.SQL条件分组") + private Integer groupType; + + @Column + @ColDefine(customType = "longtext") + @Comment("SQL条件分组保存的查询SQL") + private String groupSql; + @Column @ColDefine(type = ColType.VARCHAR, width = 32) @Comment("创建人") diff --git a/src/main/java/com/budwk/app/zhgh/activity/basic/param/ActivityUserScopePageParam.java b/src/main/java/com/budwk/app/zhgh/activity/basic/param/ActivityUserScopePageParam.java index f519c25c..133bc3e6 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/basic/param/ActivityUserScopePageParam.java +++ b/src/main/java/com/budwk/app/zhgh/activity/basic/param/ActivityUserScopePageParam.java @@ -32,6 +32,10 @@ public class ActivityUserScopePageParam extends PageForm { private Integer setGroupType; private Integer setGroupId; private String setGroupName; + /** + * 分组保存方式 1.结果分组 2.SQL条件分组 + */ + private Integer groupType; // 教师会议id private String sessionId; // 角色id diff --git a/src/main/java/com/budwk/app/zhgh/activity/basic/service/ActivityBasicScopeService.java b/src/main/java/com/budwk/app/zhgh/activity/basic/service/ActivityBasicScopeService.java index 9e253678..e1c5121a 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/basic/service/ActivityBasicScopeService.java +++ b/src/main/java/com/budwk/app/zhgh/activity/basic/service/ActivityBasicScopeService.java @@ -21,4 +21,49 @@ public interface ActivityBasicScopeService extends BaseService list) ; + /** + * 查询分组基础信息。 + * SQL条件分组与结果分组都只从同一张 activity_user_scope 表读取。 + */ + ActivityUserScope getGroupInfo(Integer groupId); + + /** + * 查询分组类型,未配置时默认按结果分组处理。 + */ + Integer getGroupType(Integer groupId); + + /** + * 构造分组对应的人员ID子查询。 + * 结果分组直接取 activity_user_scope.userId,SQL条件分组则按保存的 groupSql 动态生成查询。 + */ + Sql buildGroupUserIdSubSql(Integer groupId); + + /** + * 构造可直接拼接到业务SQL中的人员ID子查询文本。 + * 仅用于已有大量原生SQL场景,避免每个模块重复拼接 groupSql 逻辑。 + */ + String buildGroupUserIdSubSqlText(Integer groupId); + + /** + * 查询分组当前命中的人员ID列表。 + */ + List listGroupUserIds(Integer groupId); + + /** + * 判断指定用户是否在某个分组内。 + * SQL条件分组会按保存的 groupSql 动态校验,而不是依赖落库的 userId 明细。 + */ + boolean isUserInGroup(Integer groupId, String userId); + + /** + * 批量过滤出当前用户可见的分组ID。 + * 用于列表页先查活动、再按活动分组做二次权限过滤的场景。 + */ + List filterGroupIdsByUser(List groupIds, String userId); + + /** + * SQL条件分组删除人员时,不再删除主表记录,而是把排除条件追加到已保存的 groupSql 中。 + */ + void excludeUsersFromSqlGroup(Integer groupId, List userIds); + } diff --git a/src/main/java/com/budwk/app/zhgh/activity/basic/service/impl/ActivityBasicScopeServiceImpl.java b/src/main/java/com/budwk/app/zhgh/activity/basic/service/impl/ActivityBasicScopeServiceImpl.java index 9a4905b1..7090d9b7 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/basic/service/impl/ActivityBasicScopeServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/activity/basic/service/impl/ActivityBasicScopeServiceImpl.java @@ -1,6 +1,7 @@ package com.budwk.app.zhgh.activity.basic.service.impl; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; import com.budwk.app.base.service.impl.BaseServiceImpl; import com.budwk.app.base.utils.DateUtil; import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; @@ -10,15 +11,18 @@ import org.nutz.dao.Cnd; import org.nutz.dao.Dao; import org.nutz.dao.impl.NutTxDao; import org.nutz.dao.sql.Sql; +import org.nutz.dao.Sqls; import org.nutz.ioc.loader.annotation.IocBean; import java.util.ArrayList; import java.util.List; +import java.util.LinkedHashSet; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; /** * @author zxy @@ -29,6 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger; @Slf4j public class ActivityBasicScopeServiceImpl extends BaseServiceImpl implements ActivityBasicScopeService { + private static final int GROUP_TYPE_RESULT = 1; public ActivityBasicScopeServiceImpl(Dao dao) { super(dao); @@ -80,4 +85,122 @@ public class ActivityBasicScopeServiceImpl extends BaseServiceImpl list = dao().query(ActivityUserScope.class, Cnd.where("groupId", "=", groupId).desc("id")); + return CollectionUtil.isEmpty(list) ? null : list.get(0); + } + + @Override + public Integer getGroupType(Integer groupId) { + ActivityUserScope userScope = getGroupInfo(groupId); + if (userScope == null || userScope.getGroupType() == null) { + return GROUP_TYPE_RESULT; + } + return userScope.getGroupType(); + } + + @Override + public Sql buildGroupUserIdSubSql(Integer groupId) { + return Sqls.create(buildGroupUserIdSubSqlText(groupId)); + } + + @Override + public String buildGroupUserIdSubSqlText(Integer groupId) { + ActivityUserScope groupInfo = getGroupInfo(groupId); + if (groupInfo == null) { + return "SELECT NULL AS userId WHERE 1 = 0"; + } + if (GROUP_TYPE_RESULT == getGroupType(groupId)) { + return "SELECT userId FROM activity_user_scope WHERE groupId = " + groupId + " AND userId IS NOT NULL"; + } + if (StrUtil.isBlank(groupInfo.getGroupSql())) { + return "SELECT NULL AS userId WHERE 1 = 0"; + } + return """ + SELECT DISTINCT + u.id AS userId + FROM + `vw_user` u + LEFT JOIN sys_user_role sur ON sur.userid = u.id + LEFT JOIN club_user clubuser ON clubuser.userid = u.id + WHERE + """ + groupInfo.getGroupSql(); + } + + @Override + public List listGroupUserIds(Integer groupId) { + Sql sql = Sqls.queryString(buildGroupUserIdSubSqlText(groupId)); + dao().execute(sql); + String[] userIds = (String[]) sql.getResult(); + return userIds == null ? new ArrayList<>() : List.of(userIds); + } + + @Override + public boolean isUserInGroup(Integer groupId, String userId) { + if (groupId == null || StrUtil.isBlank(userId)) { + return false; + } + if (GROUP_TYPE_RESULT == getGroupType(groupId)) { + return dao().count(ActivityUserScope.class, Cnd.where("groupId", "=", groupId).and("userId", "=", userId)) > 0; + } + ActivityUserScope groupInfo = getGroupInfo(groupId); + if (groupInfo == null || StrUtil.isBlank(groupInfo.getGroupSql())) { + return false; + } + Sql sql = Sqls.create(""" + SELECT + COUNT(1) + FROM + `vw_user` u + LEFT JOIN sys_user_role sur ON sur.userid = u.id + LEFT JOIN club_user clubuser ON clubuser.userid = u.id + WHERE + u.id = @userId + AND + """ + "(" + groupInfo.getGroupSql() + ")"); + sql.setParam("userId", userId); + return count(sql) > 0; + } + + @Override + public List filterGroupIdsByUser(List groupIds, String userId) { + LinkedHashSet result = new LinkedHashSet<>(); + if (CollectionUtil.isEmpty(groupIds) || StrUtil.isBlank(userId)) { + return new ArrayList<>(result); + } + groupIds.stream() + .filter(groupId -> groupId != null) + .distinct() + .forEach(groupId -> { + if (isUserInGroup(groupId, userId)) { + result.add(groupId); + } + }); + return new ArrayList<>(result); + } + + @Override + public void excludeUsersFromSqlGroup(Integer groupId, List userIds) { + ActivityUserScope groupInfo = getGroupInfo(groupId); + if (groupInfo == null || getGroupType(groupId) != 2 || CollectionUtil.isEmpty(userIds) || StrUtil.isBlank(groupInfo.getGroupSql())) { + return; + } + String excludeUserSql = userIds.stream() + .filter(StrUtil::isNotBlank) + .distinct() + .map(userId -> "'" + StrUtil.replace(userId, "'", "''") + "'") + .collect(Collectors.joining(",")); + if (StrUtil.isBlank(excludeUserSql)) { + return; + } + // SQL分组只有一条主记录,删除人员时通过追加排除条件持久化删除结果。 + String groupSql = "(" + groupInfo.getGroupSql() + ") AND u.id NOT IN (" + excludeUserSql + ")"; + groupInfo.setGroupSql(groupSql); + dao().updateIgnoreNull(groupInfo); + } } diff --git a/src/main/java/com/budwk/app/zhgh/activity/culture/service/impl/ActivityCultureApplyUserServiceImpl.java b/src/main/java/com/budwk/app/zhgh/activity/culture/service/impl/ActivityCultureApplyUserServiceImpl.java index 3e2fe075..c186e67f 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/culture/service/impl/ActivityCultureApplyUserServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/activity/culture/service/impl/ActivityCultureApplyUserServiceImpl.java @@ -12,7 +12,7 @@ import com.budwk.app.base.service.impl.BaseServiceImpl; import com.budwk.app.sys.views.View_user; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.culture.models.ActivityTissue; import com.budwk.app.zhgh.activity.culture.models.ActivityTissuePerson; import com.budwk.app.zhgh.activity.culture.service.ActivityCultureApplyUserService; @@ -21,6 +21,7 @@ import org.nutz.dao.Dao; import org.nutz.dao.Sqls; import org.nutz.dao.sql.Sql; import org.nutz.dao.util.cri.Static; +import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.lang.Strings; import org.nutz.lang.util.NutMap; @@ -36,6 +37,9 @@ import java.util.Optional; */ @IocBean(args = {"refer:dao"}) public class ActivityCultureApplyUserServiceImpl extends BaseServiceImpl implements ActivityCultureApplyUserService { + @Inject + private ActivityBasicScopeService activityBasicScopeService; + public ActivityCultureApplyUserServiceImpl(Dao dao) { super(dao); } @@ -100,23 +104,21 @@ public class ActivityCultureApplyUserServiceImpl extends BaseServiceImpl list = listMap(sql); + // SQL分组只保存条件,报名列表需要在业务层动态判断当前用户是否命中活动范围。 + list = list.stream() + .filter(item -> activityBasicScopeService.isUserInGroup(item.getInt("groupId"), SecurityUtil.getUserId())) + .toList(); + int total = list.size(); + int start = Math.max((page.getPageNumber() - 1) * page.getPageSize(), 0); + int end = Math.min(start + page.getPageSize(), total); + List pageList = start >= total ? List.of() : list.subList(start, end); + return new Pagination<>(page.getPageNumber(), page.getPageSize(), total, pageList); } @Override @@ -126,10 +128,7 @@ public class ActivityCultureApplyUserServiceImpl extends BaseServiceImpl @Inject private SysClubService sysClubService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @Override public List getUnionData(String activityScopeGroupId) { @@ -60,7 +63,7 @@ public class ActivityCultureServiceImpl extends BaseServiceImpl SELECT gh.id, gh.name unionname, - ( SELECT count( 1 ) FROM `user` WHERE id IN ( SELECT userid FROM activity_user_scope WHERE groupId = @activityScopeGroupId ) AND unionId = gh.id ) as teacherCount + ( SELECT count( 1 ) FROM `user` WHERE id IN ( $scopeUserSql ) AND unionId = gh.id ) as teacherCount FROM sys_union gh @@ -68,7 +71,7 @@ public class ActivityCultureServiceImpl extends BaseServiceImpl GROUP BY gh.id """); - sql.setParam("activityScopeGroupId", activityScopeGroupId); + sql.setVar("scopeUserSql", activityBasicScopeService.buildGroupUserIdSubSqlText(Integer.valueOf(activityScopeGroupId))); return listMap(sql); } } diff --git a/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityApplyController.java b/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityApplyController.java index 2e85cd64..8d2004dc 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityApplyController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityApplyController.java @@ -13,7 +13,7 @@ import com.budwk.app.sys.models.Sys_user; import com.budwk.app.sys.services.SysDictService; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.family.models.*; import com.budwk.app.zhgh.activity.family.service.FamilyActivityService; import com.budwk.app.zhgh.activity.family.service.FamilyActivityStatisticsService; @@ -55,6 +55,8 @@ public class FamilyActivityApplyController { private FamilyActivityStatisticsService statisticsService; @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("/") @SaCheckPermission("family.apply") @@ -232,8 +234,7 @@ public class FamilyActivityApplyController { } //判断活动组别 - int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", activity.getActivityGroupId()).and("userId", "=", SecurityUtil.getUserId())); - if(count == 0) { + if(!activityBasicScopeService.isUserInGroup(activity.getActivityGroupId(), SecurityUtil.getUserId())) { return Result.error(99,"抱歉,您没有此次活动的权限"); } diff --git a/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityController.java b/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityController.java index 915cec6a..b77320b8 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/family/controller/manage/FamilyActivityController.java @@ -7,6 +7,7 @@ import com.budwk.app.base.annotation.SLog; import com.budwk.app.base.param.PageForm; import com.budwk.app.base.result.Result; import com.budwk.app.sys.models.Sys_home_activity; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.family.models.*; import com.budwk.app.zhgh.activity.family.service.FamilyActivityService; import io.swagger.annotations.Api; @@ -48,6 +49,8 @@ public class FamilyActivityController { @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @SaCheckPermission("family.manage") @@ -176,7 +179,7 @@ public class FamilyActivityController { order by gh.unioncode """); if (StrUtil.isNotBlank(activityScopeId)) { - sql.setVar("cnd", "AND id in (select userId from activity_user_scope where groupId = '" + activityScopeId + "')"); + sql.setVar("cnd", "AND id in (" + activityBasicScopeService.buildGroupUserIdSubSqlText(Integer.valueOf(activityScopeId)) + ")"); } List list = familyActivityManageService.listMap(sql); return Result.success().addData(list); diff --git a/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipApplyController.java b/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipApplyController.java index 8de3fc7a..7f408725 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipApplyController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipApplyController.java @@ -13,7 +13,7 @@ import com.budwk.app.sys.models.Sys_user; import com.budwk.app.sys.services.SysDictService; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.fellowship.models.*; import com.budwk.app.zhgh.activity.fellowship.service.FellowshipActivityService; import com.budwk.app.zhgh.activity.fellowship.service.FellowshipActivityStatisticsService; @@ -58,6 +58,8 @@ public class FellowshipApplyController { private FellowshipActivityStatisticsService statisticsService; @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("/") @SaCheckPermission("fellowship.apply") @@ -236,8 +238,7 @@ public class FellowshipApplyController { } //判断活动组别 - int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", activity.getActivityGroupId()).and("userId", "=", SecurityUtil.getUserId())); - if (count == 0) { + if (!activityBasicScopeService.isUserInGroup(activity.getActivityGroupId(), SecurityUtil.getUserId())) { return Result.error("抱歉,您没有此次活动的权限"); } diff --git a/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipManageController.java b/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipManageController.java index 73ccdab1..0dea890a 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipManageController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/fellowship/controller/manage/FellowshipManageController.java @@ -7,6 +7,7 @@ import com.budwk.app.base.annotation.SLog; import com.budwk.app.base.param.PageForm; import com.budwk.app.base.result.Result; import com.budwk.app.sys.models.Sys_home_activity; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.fellowship.models.*; import com.budwk.app.zhgh.activity.fellowship.service.FellowshipActivityService; import io.swagger.annotations.Api; @@ -47,6 +48,8 @@ public class FellowshipManageController { private FellowshipActivityService fellowshipActivityManageService; @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @SaCheckPermission("fellowship.manage") @@ -175,7 +178,7 @@ public class FellowshipManageController { order by gh.unioncode """); if (StrUtil.isNotBlank(activityScopeId)) { - sql.setVar("cnd", "AND id in (select userId from activity_user_scope where groupId = '" + activityScopeId + "')"); + sql.setVar("cnd", "AND id in (" + activityBasicScopeService.buildGroupUserIdSubSqlText(Integer.valueOf(activityScopeId)) + ")"); } List list = fellowshipActivityManageService.listMap(sql); return Result.success().addData(list); diff --git a/src/main/java/com/budwk/app/zhgh/activity/sports/h5Controller/H5ActivitySportsApplyUserController.java b/src/main/java/com/budwk/app/zhgh/activity/sports/h5Controller/H5ActivitySportsApplyUserController.java index b730e2d6..5da34115 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/sports/h5Controller/H5ActivitySportsApplyUserController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/sports/h5Controller/H5ActivitySportsApplyUserController.java @@ -9,7 +9,7 @@ import com.budwk.app.web.commons.auth.utils.SecurityUtil; import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnion; import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit; import com.budwk.app.zhgh.activity.basic.models.ActivityEvent; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.sports.models.ActivitySchool; import com.budwk.app.zhgh.activity.sports.models.ActivitySchoolApply; import com.budwk.app.zhgh.activity.sports.models.ActivitySchoolEvent; @@ -47,6 +47,8 @@ public class H5ActivitySportsApplyUserController { @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("/index") @Ok("beetl:platform/zhghh5/activity/sports/applyUser.html") @@ -102,10 +104,7 @@ public class H5ActivitySportsApplyUserController { //判断是否在活动组别内 - int count = dao.count(ActivityUserScope.class, - Cnd.where(ActivityUserScope::getGroupId, "=", activitySchool.getActivityGroupId()) - .and(ActivityUserScope::getUserId, "=", SecurityUtil.getUserId())); - if (count == 0) { + if (!activityBasicScopeService.isUserInGroup(activitySchool.getActivityGroupId(), SecurityUtil.getUserId())) { return Result.error("您没有权限参与该活动"); } //如果不等于空代表是个人项目 diff --git a/src/main/java/com/budwk/app/zhgh/activity/sports/service/impl/ActivitySportsApplyUserServiceImpl.java b/src/main/java/com/budwk/app/zhgh/activity/sports/service/impl/ActivitySportsApplyUserServiceImpl.java index 32e5cd2e..d1124bdb 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/sports/service/impl/ActivitySportsApplyUserServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/activity/sports/service/impl/ActivitySportsApplyUserServiceImpl.java @@ -9,6 +9,7 @@ import com.budwk.app.base.service.impl.BaseServiceImpl; import com.budwk.app.sys.models.Sys_user; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnion; import com.budwk.app.zhgh.activity.basic.models.ActivityBasicUnit; import com.budwk.app.zhgh.activity.sports.models.ActivitySchool; @@ -25,6 +26,7 @@ import org.nutz.dao.sql.Sql; import org.nutz.dao.util.cri.SqlExpressionGroup; import org.nutz.dao.util.cri.Static; import org.nutz.ioc.aop.Aop; +import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.lang.Lang; import org.nutz.lang.Strings; @@ -44,6 +46,9 @@ import java.util.stream.Collectors; */ @IocBean(args = {"refer:dao"}) public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl implements ActivitySportsApplyUserService { + @Inject + private ActivityBasicScopeService activityBasicScopeService; + public ActivitySportsApplyUserServiceImpl(Dao dao) { super(dao); } @@ -99,12 +104,6 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl0".formatted(SecurityUtil.getUserId()))); - - } cnd.andEX("abs.`name`", "=", pageParam.getGroupName()); if (Strings.isNotBlank(pageParam.getIsAudit())) { cnd.and(new Static("(SELECT COUNT(1) FROM activity_school_apply WHERE eventId = ase.eventId AND activityId = ase.activityId AND userId='%s')%s0".formatted(SecurityUtil.getUserId(), (pageParam.getIsAudit().equals("true") ? ">" : "=")))); @@ -116,8 +115,15 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl list = listMap(sql); + if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.BRANCH_UNION_CHAIRMAN.name())) { + list = list.stream().filter(item -> activityBasicScopeService.isUserInGroup(item.getInt("activityGroupId"), SecurityUtil.getUserId())).toList(); + } + int total = list.size(); + int start = Math.max((pageParam.getPageNumber() - 1) * pageParam.getPageSize(), 0); + int end = Math.min(start + pageParam.getPageSize(), total); + List pageList = start >= total ? List.of() : list.subList(start, end); + return new Pagination<>(pageParam.getPageNumber(), pageParam.getPageSize(), total, pageList); } @Override @@ -177,17 +183,15 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl0".formatted(SecurityUtil.getUserId()))); } - if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), - RoleConstant.BRANCH_UNION_CHAIRMAN.name())) { -// cnd.and(new Static("JSON_CONTAINS(school.applyWay,JSON_ARRAY( 1))>0")); - cnd.and(new Static("(SELECT COUNT(1) FROM activity_user_scope WHERE groupId=school.activityGroupId AND userId='%s') >0".formatted(SecurityUtil.getUserId()))); - } cnd.and("YEAR(school.applyStartTime)", "=", year); cnd.desc("school.applyStartTime"); sql.setCondition(cnd); - Pagination pagination = listPageMap(1, 50, sql); - return pagination; + List list = listMap(sql); + if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.BRANCH_UNION_CHAIRMAN.name())) { + list = list.stream().filter(item -> activityBasicScopeService.isUserInGroup(item.getInt("activityGroupId"), SecurityUtil.getUserId())).toList(); + } + return new Pagination<>(1, 50, list.size(), list.size() > 50 ? list.subList(0, 50) : list); } @Override @@ -295,7 +299,7 @@ public class ActivitySportsApplyUserServiceImpl extends BaseServiceImpl list = trainSignUpActivityManageService.listMap(sql); return Result.success().addData(list); diff --git a/src/main/java/com/budwk/app/zhgh/activity/trainSignUp/service/TrainSignUpActivityService.java b/src/main/java/com/budwk/app/zhgh/activity/trainSignUp/service/TrainSignUpActivityService.java index f7a3c547..bab6eaea 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/trainSignUp/service/TrainSignUpActivityService.java +++ b/src/main/java/com/budwk/app/zhgh/activity/trainSignUp/service/TrainSignUpActivityService.java @@ -103,6 +103,17 @@ public interface TrainSignUpActivityService extends BaseService @activityId + """); + sql.setParam("userId", userId); + sql.setParam("year", activity.getYear()); + sql.setParam("trainType", activity.getTrainType()); + sql.setParam("activityId", activity.getId()); + + // 同一活动下可能存在多个课程,这里按活动去重,避免同一活动重复消耗年度次数。 + int annualSignUpCount = count(sql); + return annualSignUpCount >= limitCount; + } + @Override public boolean isSignCourseByUser(String courseId, String userId) { return dao().count(TrainSignUpUser.class, Cnd.where("courseId", "=", courseId).and("userId", "=", userId)) > 0; diff --git a/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionManageController.java b/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionManageController.java index 6a7ba4ab..ffa90e4c 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionManageController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionManageController.java @@ -12,7 +12,7 @@ import com.budwk.app.base.service.BaseService; import com.budwk.app.sys.models.Sys_user; import com.budwk.app.sys.services.SysMsgService; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.workscollection.models.Activity_works_collection; import com.budwk.app.zhgh.activity.workscollection.models.Activity_works_collection_upload; import com.budwk.app.zhgh.activity.workscollection.models.Activity_works_subjectType; @@ -48,6 +48,8 @@ public class ActivityWorksCollectionManageController { private BaseService baseService; @Inject private SysMsgService sysMsgService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @Ok("beetl:/platform/zhgh/activity/workscollection/manage/index.html") @@ -164,9 +166,10 @@ public class ActivityWorksCollectionManageController { FROM sys_user WHERE - id IN (SELECT userId FROM activity_user_scope WHERE groupId = @groupId) + id IN ( + """ + activityBasicScopeService.buildGroupUserIdSubSqlText(activityGroupId) + """ + ) """); - sql.setParam("groupId", activityGroupId); sql.setCallback(Sqls.callback.strList()); dao.execute(sql); loginNames = sql.getList(String.class); diff --git a/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionUploadController.java b/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionUploadController.java index 795f076b..07bd3bf0 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionUploadController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/ActivityWorksCollectionUploadController.java @@ -7,7 +7,7 @@ import com.budwk.app.base.result.Result; import com.budwk.app.base.service.BaseService; import com.budwk.app.sys.views.View_user; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.activity.workscollection.models.Activity_works_collection; import com.budwk.app.zhgh.activity.workscollection.models.Activity_works_collection_upload; import io.swagger.annotations.ApiOperation; @@ -40,6 +40,8 @@ public class ActivityWorksCollectionUploadController { @Inject private BaseService baseService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @Ok("beetl:/platform/zhgh/activity/workscollection/upload/index.html") @@ -100,9 +102,7 @@ public class ActivityWorksCollectionUploadController { return Result.error("活动已结束!"); } if (activity.getActivityGroupId() != null) { - int count = dao.count(ActivityUserScope.class, Cnd.where(ActivityUserScope::getGroupId, "=", activity.getActivityGroupId()) - .and(ActivityUserScope::getUserId, "=", SecurityUtil.getUserId())); - if (count == 0) { + if (!activityBasicScopeService.isUserInGroup(activity.getActivityGroupId(), SecurityUtil.getUserId())) { return Result.error("您没有权限参与该活动"); } } @@ -161,13 +161,14 @@ public class ActivityWorksCollectionUploadController { Dao extDao = Daos.ext(dao, FieldFilter.create(Activity_works_collection.class, "id|name|")); Cnd cnd = Cnd.NEW(); cnd.and(Activity_works_collection::getEnable,"=",1); - SqlExpressionGroup seg = new SqlExpressionGroup(); - seg.or(Activity_works_collection::getActivityGroupId,"=",""); - seg.or(Activity_works_collection::getActivityGroupId,"is",null); - seg.or(Activity_works_collection::getActivityGroupId,"in",Sqls.create("select groupId from activity_user_scope where userId = @userId").setParam("userId",SecurityUtil.getUserId())); - cnd.and(seg); cnd.desc(Activity_works_collection::getStartDateTime); List list = extDao.query(Activity_works_collection.class, cnd); + list = list.stream().filter(item -> { + if (item.getActivityGroupId() == null) { + return true; + } + return activityBasicScopeService.isUserInGroup(item.getActivityGroupId(), SecurityUtil.getUserId()); + }).toList(); return Result.success(list); } diff --git a/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/h5/H5ActivityWorksUploadCollectionController.java b/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/h5/H5ActivityWorksUploadCollectionController.java index 240e73fe..73414a94 100644 --- a/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/h5/H5ActivityWorksUploadCollectionController.java +++ b/src/main/java/com/budwk/app/zhgh/activity/workscollection/controller/h5/H5ActivityWorksUploadCollectionController.java @@ -7,6 +7,8 @@ import com.budwk.app.base.param.PageForm; import com.budwk.app.base.result.Result; import com.budwk.app.base.service.BaseService; import com.budwk.app.web.commons.auth.utils.SecurityUtil; +import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import io.swagger.annotations.ApiOperation; import org.nutz.dao.Cnd; import org.nutz.dao.Dao; @@ -15,10 +17,13 @@ import org.nutz.dao.sql.Sql; import org.nutz.dao.util.cri.Static; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.util.NutMap; import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; import org.nutz.mvc.annotation.Param; +import java.util.List; + /** * 手机端作品征集 */ @@ -32,6 +37,8 @@ public class H5ActivityWorksUploadCollectionController { private BaseService baseService; @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @Ok("beetl:/platform/zhghh5/activity/workscollection/upload/index.html") @@ -50,13 +57,10 @@ public class H5ActivityWorksUploadCollectionController { @Param(value = "activityType") Integer activityType) { Sql sql = Sqls.create(""" SELECT - awc.*, - aus.groupName activityGroupName + awc.* FROM `activity_works_collection` awc - LEFT JOIN activity_user_scope aus ON aus.groupId = awc.activityGroupId - AND aus.userId = @userId - """).setParam("userId", SecurityUtil.getUserId()); + """); Cnd cnd = Cnd.NEW(); cnd.andEX("YEAR(awc.startDateTime)", "=", year); //查询报名中 @@ -71,8 +75,23 @@ public class H5ActivityWorksUploadCollectionController { cnd.and("awc.enable", "=", 1); cnd.and("awc.type", "=", 1); sql.setCondition(cnd); - Pagination pagination = baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); - return Result.success(pagination); + // SQL分组只保存条件,列表页需要先查活动,再按当前用户动态过滤可参与范围。 + List list = baseService.listMap(sql); + List filterList = list.stream().filter(item -> { + Integer groupId = item.getInt("activityGroupId"); + return groupId == null || activityBasicScopeService.isUserInGroup(groupId, SecurityUtil.getUserId()); + }).peek(item -> { + Integer groupId = item.getInt("activityGroupId"); + if (groupId != null) { + ActivityUserScope groupInfo = activityBasicScopeService.getGroupInfo(groupId); + item.setv("activityGroupName", groupInfo == null ? "" : groupInfo.getGroupName()); + } + }).toList(); + int total = filterList.size(); + int start = Math.max((pageForm.getPageNumber() - 1) * pageForm.getPageSize(), 0); + int end = Math.min(start + pageForm.getPageSize(), total); + List pageList = start >= total ? List.of() : filterList.subList(start, end); + return Result.success(new Pagination<>(pageForm.getPageNumber(), pageForm.getPageSize(), total, pageList)); } diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/cadreTraining/controller/CadreTrainingSignUpController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/cadreTraining/controller/CadreTrainingSignUpController.java index fae38090..7ae9d864 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/cadreTraining/controller/CadreTrainingSignUpController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/cadreTraining/controller/CadreTrainingSignUpController.java @@ -17,6 +17,7 @@ import com.budwk.app.flow.entity.ProcessTask; import com.budwk.app.flow.enums.ProcessSubmitTypeEnum; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.cadreTraining.model.CadreTrainingAct; import com.budwk.app.zhgh.dayofficework.cadreTraining.model.CadreTrainingSignUp; import com.budwk.app.zhgh.dayofficework.cadreTraining.service.CadreTrainingActService; @@ -53,6 +54,8 @@ public class CadreTrainingSignUpController { private CadreTrainingActService cadreTrainingActService; @Inject private CadreTrainingSignUpService cadreTrainingSignUpService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @Ok("beetl:/platform/zhgh/dayofficework/cadreTraining/signUp/index.html") @@ -74,18 +77,21 @@ public class CadreTrainingSignUpController { $condition """).setParam("userId", SecurityUtil.getUserId()); Cnd cnd = Cnd.NEW(); - if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), - RoleConstant.BRANCH_UNION_CHAIRMAN.name())) { - cnd.and(new Static("(SELECT COUNT(1) FROM activity_user_scope WHERE groupId=activityGroupId AND userId='%s') >0".formatted(SecurityUtil.getUserId()))); - } cnd.andEX("year(signUpStartTime)", "=", year); if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) { cnd.where().andLike(CadreTrainingAct::getName, pageForm.getSearchKeyword()); } cnd.and("cts.id", isEnrolled ? "IS NOT" : "IS", null); sql.setCondition(cnd); - Pagination pagination = cadreTrainingActService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); - return Result.success(pagination); + List list = cadreTrainingActService.listMap(sql); + if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.BRANCH_UNION_CHAIRMAN.name())) { + list = list.stream().filter(item -> activityBasicScopeService.isUserInGroup(item.getInt("activityGroupId"), SecurityUtil.getUserId())).toList(); + } + int total = list.size(); + int start = Math.max((pageForm.getPageNumber() - 1) * pageForm.getPageSize(), 0); + int end = Math.min(start + pageForm.getPageSize(), total); + List pageList = start >= total ? List.of() : list.subList(start, end); + return Result.success(new Pagination<>(pageForm.getPageNumber(), pageForm.getPageSize(), total, pageList)); } @At diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/healthCheckup/controller/HealthCheckupSingleController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/healthCheckup/controller/HealthCheckupSingleController.java index a91705d5..340f9a0e 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/healthCheckup/controller/HealthCheckupSingleController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/healthCheckup/controller/HealthCheckupSingleController.java @@ -14,6 +14,7 @@ import com.budwk.app.base.utils.CommonDownloadUtil; import com.budwk.app.base.utils.ConditionGroupUtil; import com.budwk.app.base.utils.ManyAddOrRenewUtil; import com.budwk.app.sys.views.View_user; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.healthCheckup.model.HealthCheckupProject; import com.budwk.app.zhgh.dayofficework.healthCheckup.model.HealthCheckupProjectSubject; import com.budwk.app.zhgh.dayofficework.healthCheckup.model.HealthCheckupProjectSubjectMoney; @@ -58,6 +59,8 @@ public class HealthCheckupSingleController { @Inject private HealthCheckupSingleService healthCheckupSingleService; @Inject + private ActivityBasicScopeService activityBasicScopeService; + @Inject private ManyAddOrRenewUtil manyAddOrRenewUtil; @At("") @@ -254,12 +257,11 @@ public class HealthCheckupSingleController { u.idcard idCard, u.mobile FROM - `activity_user_scope` aus - LEFT JOIN `vw_user` u ON u.id = aus.userId + `vw_user` u $projectCnd $condition """); - cnd.and("aus.groupId", "=", project.getActivityGroupId()); + cnd.and("u.id", "in", activityBasicScopeService.buildGroupUserIdSubSql(project.getActivityGroupId())); sql.setVar("projectCnd", "AND u.id NOT IN ( SELECT selectUserId FROM `health_checkup_user_selection` WHERE projectId = '" + projectId + "' AND selectUserId IS NOT NULL )"); cnd.groupBy("u.loginname"); sql.setCondition(cnd); diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyApplyController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyApplyController.java index e77d1065..bd0c5df4 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyApplyController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyApplyController.java @@ -13,7 +13,7 @@ import com.budwk.app.sys.models.Sys_user; import com.budwk.app.sys.services.SysDictService; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.literacy.models.*; import com.budwk.app.zhgh.dayofficework.literacy.service.LiteracyActivityService; import com.budwk.app.zhgh.dayofficework.literacy.service.LiteracyActivityStatisticsService; @@ -58,6 +58,8 @@ public class LiteracyApplyController { private LiteracyActivityStatisticsService statisticsService; @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("/") @SaCheckPermission("literacy.apply") @@ -236,8 +238,7 @@ public class LiteracyApplyController { } //判断活动组别 - int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", activity.getActivityGroupId()).and("userId", "=", SecurityUtil.getUserId())); - if (count == 0) { + if (!activityBasicScopeService.isUserInGroup(activity.getActivityGroupId(), SecurityUtil.getUserId())) { return Result.error("抱歉,您没有此次活动的权限"); } diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyManageController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyManageController.java index dd16c02b..bb9bffb5 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyManageController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/literacy/controller/manage/LiteracyManageController.java @@ -7,6 +7,7 @@ import com.budwk.app.base.annotation.SLog; import com.budwk.app.base.param.PageForm; import com.budwk.app.base.result.Result; import com.budwk.app.sys.models.Sys_home_activity; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.literacy.models.*; import com.budwk.app.zhgh.dayofficework.literacy.service.LiteracyActivityService; import io.swagger.annotations.Api; @@ -42,6 +43,8 @@ public class LiteracyManageController { private LiteracyActivityService literacyActivityManageService; @Inject private Dao dao; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @SaCheckPermission("literacy.manage") @@ -170,7 +173,7 @@ public class LiteracyManageController { order by gh.unioncode """); if (StrUtil.isNotBlank(activityScopeId)) { - sql.setVar("cnd", "AND id in (select userId from activity_user_scope where groupId = '" + activityScopeId + "')"); + sql.setVar("cnd", "AND id in (" + activityBasicScopeService.buildGroupUserIdSubSqlText(Integer.valueOf(activityScopeId)) + ")"); } List list = literacyActivityManageService.listMap(sql); return Result.success().addData(list); diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvQuizController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvQuizController.java index 02e32378..ebe56109 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvQuizController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvQuizController.java @@ -8,7 +8,7 @@ import cn.hutool.json.JSONObject; import com.budwk.app.base.annotation.SLog; import com.budwk.app.base.result.Result; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.qsv.dto.QsvCheckAnswerResult; import com.budwk.app.zhgh.dayofficework.qsv.models.QsvActivity; import com.budwk.app.zhgh.dayofficework.qsv.models.QsvSubject; @@ -43,6 +43,8 @@ public class H5QsvQuizController { @Inject private Dao dao; @Inject + private ActivityBasicScopeService activityBasicScopeService; + @Inject private QsvUserAnswerRecordService qsvUserAnswerRecordService; @Inject private QsvQuizService qsvQuizService; @@ -68,9 +70,7 @@ public class H5QsvQuizController { QsvActivity activity = dao.fetch(QsvActivity.class, activityId); if (activity.getGroupId() != null) { - int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", activity.getGroupId()) - .and("userId", "=", SecurityUtil.getUserId())); - if (count != 1) { + if (!activityBasicScopeService.isUserInGroup(activity.getGroupId(), SecurityUtil.getUserId())) { return Result.error("您无需参加此次答题,感谢您的关注!"); } } diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvSurveyController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvSurveyController.java index 664aed44..e784fa55 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvSurveyController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/qsv/h5controller/H5QsvSurveyController.java @@ -4,7 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONObject; import com.budwk.app.base.result.Result; import com.budwk.app.web.commons.auth.utils.SecurityUtil; -import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.qsv.models.QsvActivity; import com.budwk.app.zhgh.dayofficework.qsv.models.QsvSubject; import com.budwk.app.zhgh.dayofficework.qsv.models.QsvUserAnswerRecord; @@ -32,6 +32,8 @@ public class H5QsvSurveyController { @Inject private Dao dao; @Inject + private ActivityBasicScopeService activityBasicScopeService; + @Inject private QsvUserAnswerRecordService qsvUserAnswerRecordService; @At("") @@ -43,9 +45,7 @@ public class H5QsvSurveyController { public Result subjects(String activityId) { QsvActivity activity = dao.fetch(QsvActivity.class, activityId); - int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", activity.getGroupId()) - .and("userId", "=", SecurityUtil.getUserId())); - if (count != 1) { + if (!activityBasicScopeService.isUserInGroup(activity.getGroupId(), SecurityUtil.getUserId())) { return Result.error("您无需参加此次投票,感谢您的关注!"); } diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminManageController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminManageController.java index ab42d9b2..3549af5e 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminManageController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminManageController.java @@ -52,8 +52,6 @@ public class HuiminManageController { t1.* FROM huimin t1 - LEFT JOIN activity_user_scope aus ON t1.groupId = aus.groupId - AND aus.userId = @userId $condition """); Cnd cnd = Cnd.NEW(); diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminMineController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminMineController.java index cb18bf12..20b33dd9 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminMineController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/huimin/controller/HuiminMineController.java @@ -7,6 +7,7 @@ import com.budwk.app.base.page.Pagination; import com.budwk.app.base.param.PageForm; import com.budwk.app.base.result.Result; import com.budwk.app.web.commons.auth.utils.SecurityUtil; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.staffbenefit.huimin.models.Huimin; import com.budwk.app.zhgh.staffbenefit.huimin.service.HuiminService; import io.swagger.annotations.Api; @@ -16,9 +17,12 @@ import org.nutz.dao.Sqls; import org.nutz.dao.sql.Sql; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.util.NutMap; import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; +import java.util.List; + @IocBean @At("/platform/huimin/mine") @Api(tags = "惠民服务-我的") @@ -28,6 +32,8 @@ public class HuiminMineController { @Inject private HuiminService huiminService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @SaCheckPermission("huimin.mine") @@ -50,8 +56,6 @@ public class HuiminMineController { t1.* FROM huimin t1 - LEFT JOIN activity_user_scope aus ON t1.groupId = aus.groupId - AND aus.userId = @userId $condition """); Cnd cnd = Cnd.NEW(); @@ -61,12 +65,17 @@ public class HuiminMineController { } // 添加启用状态过滤(只显示启用的记录) cnd.and("t1.enable", "=", true); - // 添加权限过滤 - cnd.and(Cnd.exps("t1.groupId", "is", null).or("aus.groupId", "is not", null)); - sql.params().set("userId", SecurityUtil.getUserId()); sql.setCondition(cnd); - Pagination pagination = huiminService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); - return Result.success(pagination); + List list = huiminService.listMap(sql); + List filterList = list.stream().filter(item -> { + Integer groupId = item.getInt("groupId"); + return groupId == null || activityBasicScopeService.isUserInGroup(groupId, SecurityUtil.getUserId()); + }).toList(); + int total = filterList.size(); + int start = Math.max((pageForm.getPageNumber() - 1) * pageForm.getPageSize(), 0); + int end = Math.min(start + pageForm.getPageSize(), total); + List pageList = start >= total ? List.of() : filterList.subList(start, end); + return Result.success(new Pagination<>(pageForm.getPageNumber(), pageForm.getPageSize(), total, pageList)); } diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/mutualInsurance/controller/MutualInsuranceApplyController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/mutualInsurance/controller/MutualInsuranceApplyController.java index 2efa4235..087a7fe3 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/mutualInsurance/controller/MutualInsuranceApplyController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/mutualInsurance/controller/MutualInsuranceApplyController.java @@ -22,6 +22,7 @@ import com.budwk.app.flow.enums.ProcessSubmitTypeEnum; import com.budwk.app.flow.service.FlowCommonService; import com.budwk.app.web.commons.auth.utils.AuthUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.dayofficework.exerciseCard.vo.ExercisePeopleImportVo; import com.budwk.app.zhgh.staffbenefit.maternityLeave.models.MaternityLeave; import com.budwk.app.zhgh.staffbenefit.mutualInsurance.model.MutualInsuranceProject; @@ -82,6 +83,8 @@ public class MutualInsuranceApplyController { private MutualInsuranceProjectService mutualInsuranceProjectService; @Inject private MutualInsuranceUserService mutualInsuranceUserService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("/index") @Ok("beetl:/platform/zhgh/staffbenefit/mutualInsurance/apply/index.html") @@ -118,8 +121,9 @@ public class MutualInsuranceApplyController { Cnd cnd = Cnd.NEW(); cnd.andEX("`year`", "=", year == null ? DateUtil.thisYear() : year); cnd.and("isOpen", "=", true); - cnd.and(new Static("(SELECT COUNT(1) FROM activity_user_scope WHERE groupId=activityGroupId AND userId='%s') >0".formatted(SecurityUtil.getUserId()))); - List query = mutualInsuranceProjectService.query(cnd); + List query = mutualInsuranceProjectService.query(cnd).stream() + .filter(item -> activityBasicScopeService.isUserInGroup(item.getActivityGroupId(), SecurityUtil.getUserId())) + .toList(); return Result.success(query); } diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/controller/RecuperationSchoolUnionUserQueryController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/controller/RecuperationSchoolUnionUserQueryController.java index 4ebf88a7..4cf28bc9 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/controller/RecuperationSchoolUnionUserQueryController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/controller/RecuperationSchoolUnionUserQueryController.java @@ -14,6 +14,7 @@ import com.budwk.app.base.param.PageForm; import com.budwk.app.base.result.Result; import com.budwk.app.base.utils.CommonDownloadUtil; import com.budwk.app.web.commons.auth.utils.SecurityUtil; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.staffbenefit.recuperation.constant.RecuperationState; import com.budwk.app.zhgh.staffbenefit.recuperation.model.RecuperationConfig; import com.budwk.app.zhgh.staffbenefit.recuperation.model.RecuperationEnroll; @@ -65,6 +66,8 @@ public class RecuperationSchoolUnionUserQueryController { private Dao dao; @Inject private RecuperationEnrollService enrollService; + @Inject + private ActivityBasicScopeService activityBasicScopeService; @At("") @Ok("beetl:/platform/zhgh/staffbenefit/recuperation/schoolUnionUserQuery/index.html") @@ -462,12 +465,11 @@ public class RecuperationSchoolUnionUserQueryController { u.unitname as unitName, u.unionname as unionName from - activity_user_scope us - left join vw_user u on u.id = us.userId + vw_user u $condition """); Cnd cnd = Cnd.NEW(); - cnd.and("us.groupId", "=", config.getActivityGroupId()); + cnd.and("u.id", "in", activityBasicScopeService.buildGroupUserIdSubSql(config.getActivityGroupId())); cnd.and(new Static(" u.loginname not in (select loginName from recuperation_enroll where year(signingUptime) = '%s' and isNormal = true)".formatted(DateUtil.thisYear()))); cnd.asc("unitcode"); sql.setCondition(cnd); diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/service/impl/RecuperationEnrollServiceImpl.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/service/impl/RecuperationEnrollServiceImpl.java index be57a42f..f34c1ff1 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/service/impl/RecuperationEnrollServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/recuperation/service/impl/RecuperationEnrollServiceImpl.java @@ -10,6 +10,7 @@ import com.budwk.app.sys.models.Sys_union; import com.budwk.app.sys.models.Sys_user; import com.budwk.app.web.commons.auth.utils.SecurityUtil; import com.budwk.app.zhgh.activity.basic.models.ActivityUserScope; +import com.budwk.app.zhgh.activity.basic.service.ActivityBasicScopeService; import com.budwk.app.zhgh.staffbenefit.recuperation.constant.*; import com.budwk.app.zhgh.staffbenefit.recuperation.model.*; import com.budwk.app.zhgh.staffbenefit.recuperation.service.RecuperationEnrollService; @@ -46,6 +47,8 @@ public class RecuperationEnrollServiceImpl extends BaseServiceImpl @@ -257,11 +257,19 @@ module.exports = { clearImportDialog() { this.importDialogVisible = false }, + formatGroupDisplayName(group) { + if (Number(group.groupType) === 2) { + return group.groupName + "(SQL条件)" + } + return group.groupName + "(人员结果)" + }, viewGroupName() { - if (this.pageForm?.groupId) { + if (this.pageForm.groupId) { const group = this.activityGroupList.find((v) => v.groupId === this.pageForm.groupId) - this.currentGroupName = group.groupName + "人员" - return + if (group) { + this.currentGroupName = this.formatGroupDisplayName(group) + "人员" + return + } } this.currentGroupName = "全部人员" }, @@ -288,6 +296,7 @@ module.exports = { this.$emit("group_change") } else { } + return } }, async flushUnits() { @@ -301,17 +310,19 @@ module.exports = { }, async getActivityGroup(id) { const resp = await $.get("/platform/activity/basic/scope/getActivityUserScopeGroup") - this.activityGroupList = resp.data - if (resp.data && resp.data.length > 0) { + this.activityGroupList = resp.data || [] + if (this.activityGroupList.length > 0) { if (id) { if (this.activityGroupList.some((v) => v.groupId === id)) { this.$set(this.pageForm, "groupId", id) } else { - this.$set(this.pageForm, "groupId", resp.data[0].groupId) + this.$set(this.pageForm, "groupId", this.activityGroupList[0].groupId) } } else { - this.$set(this.pageForm, "groupId", resp.data[0].groupId) + this.$set(this.pageForm, "groupId", this.activityGroupList[0].groupId) } + } else { + this.$set(this.pageForm, "groupId", null) } await this.doSearch() }, diff --git a/src/main/resources/static/components/module/activity/UserScope.vue b/src/main/resources/static/components/module/activity/UserScope.vue index 5abc2db8..74bf8d55 100644 --- a/src/main/resources/static/components/module/activity/UserScope.vue +++ b/src/main/resources/static/components/module/activity/UserScope.vue @@ -301,7 +301,7 @@ 导入XLSX设置分组 导出查询人员 - 设置为活动人员 + 设置为活动人员 @@ -336,25 +336,32 @@ :close-on-click-modal="false"> - + 添加至原有分组 添加到新分组 + + + 保存人员结果 + 保存SQL条件 + + + - {{ item.groupName }} + {{ formatGroupDisplayName(item) }} +
当前还没有同类型分组,请先创建新分组。
@@ -391,9 +398,12 @@ module.exports = { clubOptions: [], settingLoading: false, setDialogVisible: false, - setGroupType: null, - setGroupId: null, - setGroupName: null, + formData: { + setGroupType: 2, + setGroupId: null, + setGroupName: "", + groupType: 1 + }, personTypeOptions: [], userStateOptions: [], activityGroupList: [], @@ -460,6 +470,7 @@ module.exports = { ], rules: { setGroupType: [{required: true, message: "请选择添加方式", trigger: ["blur", "change"]}], + groupType: [{required: true, message: "请选择保存方式", trigger: ["blur", "change"]}], setGroupId: [{required: true, message: "请选择分组", trigger: ["blur", "change"]}], setGroupName: [{required: true, message: "请输入分组名称", trigger: ["blur", "change"]}] }, @@ -487,6 +498,9 @@ module.exports = { }, unionid() { return this.roleData.unionid + }, + sameTypeGroupList() { + return this.activityGroupList.filter((item) => Number(item.groupType) === Number(this.formData.groupType)) } }, components: { @@ -494,6 +508,44 @@ module.exports = { "activity-import-user": httpVueLoader("/components/module/activity/ActivityImportUser.vue?v=" + new Date().getTime()) }, methods: { + getDefaultFormData() { + return { + setGroupType: 2, + setGroupId: null, + setGroupName: "", + groupType: 1 + } + }, + openSetDialog() { + this.formData = this.getDefaultFormData() + this.setDialogVisible = true + this.$nextTick(() => { + if (this.$refs.setForm) { + this.$refs.setForm.clearValidate() + } + }) + }, + handleSetGroupModeChange() { + if (this.formData.setGroupType === 1) { + this.formData.setGroupName = "" + if (!this.sameTypeGroupList.some((item) => item.groupId === this.formData.setGroupId)) { + this.formData.setGroupId = null + } + return + } + this.formData.setGroupId = null + }, + handleGroupTypeChange() { + if (!this.sameTypeGroupList.some((item) => item.groupId === this.formData.setGroupId)) { + this.formData.setGroupId = null + } + }, + formatGroupDisplayName(group) { + if (Number(group.groupType) === 2) { + return group.groupName + "(SQL条件)" + } + return group.groupName + "(人员结果)" + }, listSession() { this.$axios.post("/platform/teacherCongress/common/listSession").then((res) => { if (res.code === 0) { @@ -595,7 +647,7 @@ module.exports = { return } - if (this.tableData.length === 0) { + if (this.formData.groupType !== 2 && this.tableData.length === 0) { this.$message.warning("请先指定筛选条件!") return } @@ -625,11 +677,7 @@ module.exports = { await this.getActivityGroup() this.doSearch() this.$message.success(resp.msg) - this.formData = { - setGroupType: null, - setGroupId: null, - setGroupName: null - } + this.formData = this.getDefaultFormData() } else { this.$message.error(resp.msg) } @@ -640,12 +688,12 @@ module.exports = { }, async getActivityGroup() { const resp = await $.get("/platform/activity/basic/scope/getActivityUserScopeGroup") - this.activityGroupList = resp.data + this.activityGroupList = resp.data || [] this.activityGroupList2 = [] - resp.data.forEach((v) => { + this.activityGroupList.forEach((v) => { this.activityGroupList2.push({ groupId: v.groupId, - groupName: v.groupName + "范围之外人员" + groupName: this.formatGroupDisplayName(v) + "范围之外人员" }) }) }, @@ -748,4 +796,11 @@ module.exports = { .reverseCheckBox { margin: 0 10px 0 0 !important; } + +.form-tip { + color: #909399; + font-size: 12px; + line-height: 20px; + margin-top: 8px; +} diff --git a/src/main/resources/views/platform/zhgh/activity/trainSignUp/apply/index.html b/src/main/resources/views/platform/zhgh/activity/trainSignUp/apply/index.html index a7c74d82..fc79f7cc 100644 --- a/src/main/resources/views/platform/zhgh/activity/trainSignUp/apply/index.html +++ b/src/main/resources/views/platform/zhgh/activity/trainSignUp/apply/index.html @@ -144,10 +144,20 @@ layout("/layouts/platform.html"){ this.onView(row) return } - this.infoVisible = false - this.$nextTick(() => { - this.$refs.guava.view(() => { - this.$refs.courseListRef.onOpen(row) + // 先校验年度同活动类型报名次数,避免进入课程页后才提示不可报名。 + this.$axios.post("/platform/trainSignUp/apply/validateYearTrainTypeSignUp", {activityId: row.id}).then((res) => { + if (res.code !== 0) { + this.$alert(res.msg, "提示", { + confirmButtonText: "确定", + type: "warning" + }) + return + } + this.infoVisible = false + this.$nextTick(() => { + this.$refs.guava.view(() => { + this.$refs.courseListRef.onOpen(row) + }) }) }) }, diff --git a/src/main/resources/views/platform/zhgh/activity/trainSignUp/type/index.html b/src/main/resources/views/platform/zhgh/activity/trainSignUp/type/index.html index cd84b021..b57eb1a3 100644 --- a/src/main/resources/views/platform/zhgh/activity/trainSignUp/type/index.html +++ b/src/main/resources/views/platform/zhgh/activity/trainSignUp/type/index.html @@ -24,6 +24,10 @@ layout("/layouts/platform.html"){ + + + 年度次数配置 + 新增类型 @@ -75,6 +79,9 @@ layout("/layouts/platform.html"){ } }) }, + openAnnualLimit() { + window.location.href = '/platform/trainSignUp/annualLimit' + }, openAdd() { this.$refs.guava.edit(() => { this.$refs.basicFormRef.initData() diff --git a/src/main/resources/views/platform/zhghh5/activity/trainSignUp/apply/index.html b/src/main/resources/views/platform/zhghh5/activity/trainSignUp/apply/index.html index eefe286a..d2ee2ee7 100644 --- a/src/main/resources/views/platform/zhghh5/activity/trainSignUp/apply/index.html +++ b/src/main/resources/views/platform/zhghh5/activity/trainSignUp/apply/index.html @@ -131,7 +131,18 @@ layout("/layouts/platform_h5.html"){ this.onView(row) return } - this.$pjaxReplace('/platform/trainSignUp/apply/list/h5?id=' + row.id) + // 先校验年度同活动类型报名次数,避免进入课程页后才提示不可报名。 + this.$axios.post('/platform/trainSignUp/apply/validateYearTrainTypeSignUp', {activityId: row.id}).then((res) => { + if (res.code !== 0) { + vant.Dialog.alert({ + title: '提示', + message: res.msg, + confirmButtonColor: '#1867b0' + }) + return + } + this.$pjaxReplace('/platform/trainSignUp/apply/list/h5?id=' + row.id) + }) }, fetchOne() { this.$axios.post('/platform/trainSignUp/manage/findOne', {id: this.id}).then((res) => {