diff --git a/src/main/java/com/huoran/iasf/controller/SysFloatingColumnSchemeController.java b/src/main/java/com/huoran/iasf/controller/SysFloatingColumnSchemeController.java index f1eef3b..9b22452 100644 --- a/src/main/java/com/huoran/iasf/controller/SysFloatingColumnSchemeController.java +++ b/src/main/java/com/huoran/iasf/controller/SysFloatingColumnSchemeController.java @@ -10,6 +10,7 @@ import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; import com.huoran.iasf.service.SysFloatingColumnSchemeModuleService; import com.huoran.iasf.service.SysFloatingColumnSchemeScopeOfApplicationService; import com.huoran.iasf.service.SysFloatingColumnSchemeService; +import com.huoran.iasf.vo.ConflictCheckResultVO; import com.huoran.iasf.vo.SysFloatingColumnSchemeVO; import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; import io.swagger.annotations.Api; @@ -67,6 +68,15 @@ public class SysFloatingColumnSchemeController { } } + if (sysFloatingColumnScheme.getId() != null&&sysFloatingColumnScheme.getIsDisable()==0){ + ConflictCheckResultVO conflictCheckResultVO = service.preCheckMultiScopeConflictBeforeUpdate(sysFloatingColumnScheme.getSiteId(), + sysFloatingColumnScheme.getFloatingColumnSchemeScopeOfApplications(),sysFloatingColumnScheme.getId()); + if (conflictCheckResultVO.isHasConflict()) { + return R.fail(conflictCheckResultVO.getMessage()); + } + } + + // 新增场景下直接进行校验 if (sysFloatingColumnScheme.getId() == null) { if (checkSchemeName(sysFloatingColumnScheme.getSchemeName(), sysFloatingColumnScheme.getSiteId())) { diff --git a/src/main/java/com/huoran/iasf/mapper/SysColumnMapper.java b/src/main/java/com/huoran/iasf/mapper/SysColumnMapper.java index da8bcdc..4c29099 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysColumnMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysColumnMapper.java @@ -40,4 +40,8 @@ public interface SysColumnMapper extends BaseMapper { Integer oneLevelChecksThemAll(@Param("theChildId")Integer theChildId); List queryByColumnType(@Param("ids")String ids); + + List multiIdQueryColumnInformation(@Param("ids")String ids); + + String getColumnNamesById(@Param("ids")String ids); } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/SysFloatingColumnSchemeMapper.java b/src/main/java/com/huoran/iasf/mapper/SysFloatingColumnSchemeMapper.java index 80dc4c3..2a60cd5 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysFloatingColumnSchemeMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysFloatingColumnSchemeMapper.java @@ -4,12 +4,17 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.huoran.iasf.entity.SysFloatingColumnScheme; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; +import com.huoran.iasf.vo.SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO; import com.huoran.iasf.vo.SysFloatingColumnSchemeVO; +import com.huoran.iasf.vo.req.ApplicationScopeCheckReq; import com.huoran.iasf.vo.req.PageContentReqVO; import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; import com.huoran.iasf.vo.resp.PageContentRespVO; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** *

* 悬浮栏方案 Mapper 接口 @@ -21,4 +26,18 @@ import org.apache.ibatis.annotations.Param; public interface SysFloatingColumnSchemeMapper extends BaseMapper { IPage floatingBarList(Page page, @Param("req") SuspensionBarListPagingReq req); + List getsTheGloballyEnabledFloatingBarSchemeRadius(@Param("req") ApplicationScopeCheckReq req); + + + // 查询当前站点下所有已启用的悬浮栏方案(排除当前方案ID),并关联获取站点ID + List selectEnabledScopesExcludingCurrent( + @Param("floatingBarSchemeId") Integer floatingBarSchemeId, + @Param("siteId") Integer siteId); + + + // 查询该站点下所有其他启用的悬浮栏方案及其应用范围,排除指定的方案ID列表 + List selectEnabledScopesForMultiConflictCheck( + @Param("siteId") Integer siteId, + @Param("excludeSchemeIds") List excludeSchemeIds,@Param("floatingBarSchemeId")Integer floatingBarSchemeId); } + diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysColumnMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysColumnMapper.xml index 5200724..bd24521 100644 --- a/src/main/java/com/huoran/iasf/mapper/xml/SysColumnMapper.xml +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysColumnMapper.xml @@ -195,6 +195,19 @@ WHERE FIND_IN_SET(s.id, #{ids}) GROUP BY list_style_id + + \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysFloatingColumnSchemeMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysFloatingColumnSchemeMapper.xml index 3bc88ad..cc05193 100644 --- a/src/main/java/com/huoran/iasf/mapper/xml/SysFloatingColumnSchemeMapper.xml +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysFloatingColumnSchemeMapper.xml @@ -48,4 +48,65 @@ ORDER BY s.id DESC + + + + + + + diff --git a/src/main/java/com/huoran/iasf/service/SysColumnService.java b/src/main/java/com/huoran/iasf/service/SysColumnService.java index 61ddc67..c04eeb2 100644 --- a/src/main/java/com/huoran/iasf/service/SysColumnService.java +++ b/src/main/java/com/huoran/iasf/service/SysColumnService.java @@ -8,6 +8,7 @@ import com.huoran.iasf.vo.req.LongPageColumnReqVO; import com.huoran.iasf.vo.req.PageContentReqVO; import com.huoran.iasf.vo.req.PaginationColumnReqVO; +import java.util.Collection; import java.util.List; /** @@ -43,4 +44,5 @@ public interface SysColumnService extends IService { R queryArticlesByColumnType(String ids,Integer id); + List getColumnNamesByIds(Collection applicationScopeIds); } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeScopeOfApplicationService.java b/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeScopeOfApplicationService.java index 61514da..1a0c57b 100644 --- a/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeScopeOfApplicationService.java +++ b/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeScopeOfApplicationService.java @@ -4,6 +4,7 @@ import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; +import java.util.Set; /** *

@@ -20,4 +21,7 @@ public interface SysFloatingColumnSchemeScopeOfApplicationService extends IServi //删除 void deleteByFloatingBarSchemeId(Integer floatingBarSchemeId); + + + List getScopeIdsBySchemeId(Integer id); } diff --git a/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeService.java b/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeService.java index 761351c..08d5ff8 100644 --- a/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeService.java +++ b/src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeService.java @@ -1,10 +1,15 @@ package com.huoran.iasf.service; +import com.baomidou.mybatisplus.extension.service.IService; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysFloatingColumnScheme; -import com.baomidou.mybatisplus.extension.service.IService; +import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; +import com.huoran.iasf.vo.ConflictCheckResultVO; +import com.huoran.iasf.vo.req.ApplicationScopeCheckReq; import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; +import java.util.List; + /** *

* 悬浮栏方案 服务类 @@ -19,7 +24,12 @@ public interface SysFloatingColumnSchemeService extends IService updatedScopes,Integer floatingBarSchemeId); - R columnDisplayFloatingBar(String columnId); } diff --git a/src/main/java/com/huoran/iasf/service/impl/SysColumnServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysColumnServiceImpl.java index 582682b..1f4a61c 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysColumnServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysColumnServiceImpl.java @@ -21,7 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** * @描述: 服务类 @@ -209,6 +212,26 @@ public class SysColumnServiceImpl extends ServiceImpl getColumnNamesByIds(Collection applicationScopeIds) { + if (CollectionUtils.isEmpty(applicationScopeIds)) { + return Collections.emptyList(); + } + + // 将ID集合转换为逗号分隔的字符串,以便在IN子句中使用 + String scopeIdsStr = String.join(",", applicationScopeIds); + + // 执行SQL查询,这里直接使用BaseMapper的selectList方法并传入自定义的Wrapper + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("id", applicationScopeIds); + queryWrapper.select("column_name"); // 只选择columnName列 + + return baseMapper.selectObjs(queryWrapper).stream() + .map(Object::toString) // 假设columnName为String类型,转换对象为String + .collect(Collectors.toList()); + } + + } diff --git a/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeScopeOfApplicationServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeScopeOfApplicationServiceImpl.java index a4dc3bf..44c0b08 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeScopeOfApplicationServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeScopeOfApplicationServiceImpl.java @@ -1,13 +1,14 @@ package com.huoran.iasf.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; import com.huoran.iasf.mapper.SysFloatingColumnSchemeScopeOfApplicationMapper; import com.huoran.iasf.service.SysFloatingColumnSchemeScopeOfApplicationService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Set; /** *

@@ -33,4 +34,21 @@ public class SysFloatingColumnSchemeScopeOfApplicationServiceImpl extends Servic queryWrapper.eq("floating_bar_scheme_id", floatingBarSchemeId); this.remove(queryWrapper); } + + @Override + public List getScopeIdsBySchemeId(Integer id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("floating_bar_scheme_id", id); + if (this.list(queryWrapper) != null) { + List list = this.list(queryWrapper); + Set set = list.stream().map(SysFloatingColumnSchemeScopeOfApplication::getApplicationScopeId).collect(java.util.stream.Collectors.toSet()); + if (set != null) { + return new java.util.ArrayList<>(set); + } + } + + return null; + } + + } diff --git a/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeServiceImpl.java index 9007c81..6b5daae 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeServiceImpl.java @@ -16,8 +16,11 @@ import com.huoran.iasf.mapper.SysFloatingColumnSchemeMapper; import com.huoran.iasf.mapper.SysFloatingColumnSchemeModuleMapper; import com.huoran.iasf.mapper.SysFloatingColumnSchemeScopeOfApplicationMapper; import com.huoran.iasf.service.SysFloatingColumnSchemeService; +import com.huoran.iasf.vo.ConflictCheckResultVO; +import com.huoran.iasf.vo.SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO; import com.huoran.iasf.vo.SysFloatingColumnSchemeVO; import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; +import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -205,94 +208,129 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl floatingColumnSchemeList = baseMapper.selectList(new LambdaQueryWrapper() - .eq(SysFloatingColumnScheme::getSiteId, column.getSiteId()) - .eq(SysFloatingColumnScheme::getIsDisable, 0) - .eq(SysFloatingColumnScheme::getStatus, 1)); + List floatingColumnSchemeList = baseMapper.selectList(new LambdaQueryWrapper().eq(SysFloatingColumnScheme::getSiteId, column.getSiteId()).eq(SysFloatingColumnScheme::getIsDisable, 0).eq(SysFloatingColumnScheme::getStatus, 1)); for (SysFloatingColumnScheme scheme : floatingColumnSchemeList) { //判断当前启用的栏目如果为全局的直接返回全局的已启用的方案 if (scheme.getIsGlobal() == 1) { //查询悬浮栏当前绑定的方案 - List columnSchemeModule = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper() - .eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, scheme.getId()).eq(SysFloatingColumnSchemeModule::getIsDisable, 0)); + List columnSchemeModule = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper().eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, scheme.getId()).eq(SysFloatingColumnSchemeModule::getIsDisable, 0)); ; if (!ObjectUtil.isEmpty(columnSchemeModule)) { return R.success(columnSchemeModule); } - }else{ + } else { //查询栏目绑定过的悬浮栏 List floatingBarIds = scopeOfApplicationMapper.checkBoundByColumnId(columnId); //查询悬浮栏绑定的方案 - for (Integer floatingBarId: floatingBarIds) { - List list = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper() - .eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, floatingBarId).eq(SysFloatingColumnSchemeModule::getIsDisable, 0)); + for (Integer floatingBarId : floatingBarIds) { + List list = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper().eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, floatingBarId).eq(SysFloatingColumnSchemeModule::getIsDisable, 0)); columnSchemeModuleList.addAll(list); } - - - return R.success(columnSchemeModuleList); - } } - - - return R.success(columnSchemeModuleList); } - /*@Override - public R columnDisplayFloatingBar(String columnId) { - //获取站点 - SysColumn column = columnMapper.selectById(columnId); - if (ObjectUtil.isEmpty(column)) { - return R.fail("未找到该栏目"); - } - - //查询范围应用为栏目的 - *//* List sysFloatingColumnSchemeScopeOfApplications = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper() - .eq(SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, columnId) - ); -*//* - - - - //查询栏目绑定过的悬浮栏 - List sysFloatingColumnSchemeScopeOfApplications = scopeOfApplicationMapper.checkBoundByColumnId(columnId); - - List columnSchemeModuleList = new ArrayList<>(); + /** + * 在多个悬浮栏方案更新前,预先检查是否存在应用范围冲突。 + * + * @param siteId 当前操作所在的站点ID。 + * @param updatedScopes 待更新的悬浮栏方案列表。 + * @return 冲突检测结果,包含是否有冲突及详细的冲突信息。 + */ + @Transactional(readOnly = true) + public ConflictCheckResultVO preCheckMultiScopeConflictBeforeUpdate( + Integer siteId, List updatedScopes,Integer floatingBarSchemeId) { - for (Integer floatingBarId : sysFloatingColumnSchemeScopeOfApplications) { - //查询启用的悬浮栏 - SysFloatingColumnScheme scheme = floatingColumnSchemeMapper.selectById(floatingBarId); + // 1. 收集待更新方案的ID,用于排除这些方案在冲突检测中的干扰 + List excludeSchemeIds = updatedScopes.stream() + .map(SysFloatingColumnSchemeScopeOfApplication::getApplicationScopeId) + .collect(Collectors.toList()); - if (!ObjectUtil.isEmpty(scheme)) { - //且为启用状态下才查询绑定的方案 - if (scheme.getIsDisable() == 0) { - //查询悬浮栏当前绑定的方案 - List columnSchemeModule = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper() - .eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, scheme.getId()).eq(SysFloatingColumnSchemeModule::getIsDisable, 0));; - if (!ObjectUtil.isEmpty(columnSchemeModule)) { - columnSchemeModuleList.addAll(columnSchemeModule); + // 2. 从数据库查询该站点下所有启用的悬浮栏方案,但排除掉当前正在更新的那些方案 + List enabledScopes = + baseMapper.selectEnabledScopesForMultiConflictCheck(siteId, excludeSchemeIds,floatingBarSchemeId); + + /*// 初始化冲突标记为false,并准备一个StringBuilder用于记录冲突信息 + boolean hasConflict = false; + StringBuilder conflictMessage = new StringBuilder(); + + // 3. 对比每个待更新的方案与已启用方案,检测应用范围是否有重叠 + for (SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO existingScope : enabledScopes) { + for (SysFloatingColumnSchemeScopeOfApplication newScope : updatedScopes) { + // 假设冲突基于应用范围的直接比较,实际情况可能需要更复杂的逻辑 + if (existingScope.getApplicationScopeId().equals(newScope.getApplicationScopeId())) { + hasConflict = true; + conflictMessage.append("发现冲突:方案“") + .append(existingScope.getSchemeName()) + .append("”与待更新的方案在应用范围“") + .append(newScope.getApplicationScopeId()) + .append("”上重叠。\n"); + } + } + }*/ + // 初始化冲突标记为false,并准备一个StringBuilder用于记录冲突信息 + boolean hasConflict = false; + StringBuilder conflictMessageBuilder = new StringBuilder(); + Set conflictColumnNames = new HashSet<>(); // 用于存储所有冲突的栏目名称 + + // 3. 对比每个待更新的方案与已启用方案,检测应用范围是否有重叠 + for (SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO existingScope : enabledScopes) { + for (SysFloatingColumnSchemeScopeOfApplication newScope : updatedScopes) { + // 分割应用范围ID为集合,以便逐个比较 + Set existingScopeIds = Arrays.stream(existingScope.getApplicationScopeId().split(",")) + .map(String::trim) + .filter(id -> !id.isEmpty() && NumberUtils.isCreatable(id)) + .map(Integer::parseInt) + .collect(Collectors.toSet()); + Set newScopeIds = Arrays.stream(newScope.getApplicationScopeId().split(",")) + .map(String::trim) + .filter(id -> !id.isEmpty() && NumberUtils.isCreatable(id)) + .map(Integer::parseInt) + .collect(Collectors.toSet()); + + // 找出重叠的范围ID + Set overlapIds = new HashSet<>(existingScopeIds); + overlapIds.retainAll(newScopeIds); + + // 避免重复处理相同的冲突范围 + if (!overlapIds.isEmpty()) { + for (Integer overlapId : overlapIds) { + String columnName = getColumnNameById(String.valueOf(overlapId)); // 假设这是获取栏目名称的方法 + conflictColumnNames.add(columnName); // 收集冲突的栏目名称 } } - - } } + // 构建最终的冲突信息,如果存在冲突 + if (!conflictColumnNames.isEmpty()) { + hasConflict = true; + conflictMessageBuilder.append("栏目:"); + boolean isFirst = true; + for (String columnName : conflictColumnNames) { + if (!isFirst) { + conflictMessageBuilder.append("、"); // 使用中文逗号作为分隔符 + } + conflictMessageBuilder.append(columnName); + isFirst = false; + } + conflictMessageBuilder.append(" 已设置有悬浮栏,请先移除相关设置再尝试启用。\n"); + } + // 4. 根据检测结果创建并返回ConflictCheckResult对象 + return new ConflictCheckResultVO(hasConflict, conflictMessageBuilder.toString()); + } - return R.success(columnSchemeModuleList); - }*/ // 辅助方法检查站点下是否存在启用的全局悬浮栏 private boolean existsEnabledGlobal(Integer siteId) { @@ -333,6 +371,7 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl enabledScopeIds = Arrays.stream(enabledScope.getApplicationScopeId().split(",")).map(Integer::parseInt).collect(Collectors.toSet()); if (!Collections.disjoint(currentScopeIds, enabledScopeIds)) { +// System.err.println("--------------->>>>重叠的范围ID: " + currentScopeIds.stream()); return true; // 存在重叠 } } @@ -346,51 +385,56 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl allScopes = scopeOfApplicationMapper.selectList(null); - Map> allScopeIdMap = allScopes.stream() - .collect(Collectors.groupingBy( - SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, - Collectors.flatMapping(scope -> Arrays.stream(scope.getApplicationScopeId().split(",")), Collectors.mapping(Integer::parseInt, Collectors.toSet())) - )); - - // 获取当前方案的范围ID - Set currentScopeIds = allScopeIdMap.getOrDefault(schemeId, Collections.emptySet()); - - // 找出与其他悬浮栏方案重复的范围ID - Set duplicateScopeIds = allScopeIdMap.values().stream() - .filter(ids -> !ids.equals(currentScopeIds) && !ids.isEmpty()) - .flatMap(Set::stream) - .filter(currentScopeIds::contains) - .collect(Collectors.toSet()); - - // 查询重复范围对应的栏目名称 - List duplicateScopeNames = columnMapper.selectList(new LambdaQueryWrapper().in(SysColumn::getId, duplicateScopeIds)) - .stream() - .map(SysColumn::getColumnName) - .collect(Collectors.toList()); + // 获取与当前悬浮栏方案ID相关的冲突范围ID集合 + List conflictingScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper().eq(SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, schemeId)); - // 构建并返回提示信息 - if (!duplicateScopeNames.isEmpty()) { - String scopesJoined = String.join("”, “", duplicateScopeNames); - if (enableAction == 0) { // 启用操作 - return "栏目:“" + scopesJoined + "”已存在于其他悬浮栏配置中,请处理重复后再尝试启用。"; - } else if (enableAction == 1) { // 禁用操作 - return "注意:禁用操作可能会影响到栏目“" + scopesJoined + "”在其他悬浮栏的配置,请谨慎操作。"; - } else { - return "未知的操作类型"; - } + // 将范围ID字符串转换为整数集合 + Set conflictScopeIds = conflictingScopes.stream().flatMap(scope -> Arrays.stream(scope.getApplicationScopeId().split(","))).map(Integer::parseInt).collect(Collectors.toSet()); + + //查询当前已经启用的悬浮栏方案下的的应用范围跟当前设置的范围有重复的就只提出出来重复的id + conflictScopeIds.retainAll(checkBoundByColumnId(conflictScopeIds, siteId)); + + // 根据冲突范围ID查询对应的栏目名称 + List conflictingScopeNames = columnMapper.selectList(new LambdaQueryWrapper().in(SysColumn::getId, conflictScopeIds)).stream().map(SysColumn::getColumnName).collect(Collectors.toList()); + + // 根据操作类型生成具体的提示信息 + if (enableAction == 0) { // 启用操作 + // 拼接冲突范围名称,提醒用户需先解决冲突 + return "栏目:“" + String.join("”, “", conflictingScopeNames) + "”已设置有悬浮栏,请先移除相关设置再尝试启用。"; } else { - return ""; // 逻辑上这里应该不会到达,因为之前已确认有重叠,但为了完整性保留 + return "未知的操作类型"; } } + private Set checkBoundByColumnId(Set columnIds, Integer siteId) { + // 构造SQL查询条件,用于查找所有启用的悬浮栏方案及其范围 + /*String sqlInCondition = columnIds.stream().map(Object::toString).collect(Collectors.joining(","));*/ // 移除了外部的括号 + + List enabledConflictingScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper().inSql(SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, "SELECT id FROM sys_floating_column_scheme WHERE is_disable = 0 AND site_id = " + siteId).in(SysFloatingColumnSchemeScopeOfApplication::getApplicationScopeId, columnIds)); + + // 转换为范围ID集合 + Set duplicateScopeIds = new HashSet<>(); + for (SysFloatingColumnSchemeScopeOfApplication scope : enabledConflictingScopes) { + duplicateScopeIds.addAll(Arrays.stream(scope.getApplicationScopeId().split(",")).map(Integer::parseInt).collect(Collectors.toSet())); + } + + return duplicateScopeIds; + } // 新增方法:统计当前站点下已启用的全局悬浮栏数量 @@ -398,4 +442,8 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl().eq(SysFloatingColumnScheme::getSiteId, siteId).eq(SysFloatingColumnScheme::getIsGlobal, 1).eq(SysFloatingColumnScheme::getIsDisable, false)); } + + private String getColumnNameById(String overlapId) { + return columnMapper.getColumnNamesById(overlapId); + } } diff --git a/src/main/java/com/huoran/iasf/vo/ConflictCheckResultVO.java b/src/main/java/com/huoran/iasf/vo/ConflictCheckResultVO.java new file mode 100644 index 0000000..000adae --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/ConflictCheckResultVO.java @@ -0,0 +1,43 @@ +package com.huoran.iasf.vo; + +import lombok.Data; + +@Data +public class ConflictCheckResultVO { + private boolean hasConflict; // 表示是否有冲突 + private String message; // 存储冲突的详细信息,可以是冲突的描述或为空 + + /** + * 构造函数,初始化冲突检测结果。 + * + * @param hasConflict 是否存在冲突 + * @param message 冲突的详细信息,没有冲突时可以为空 + */ + public ConflictCheckResultVO(boolean hasConflict, String message) { + this.hasConflict = hasConflict; + this.message = message; + } + + // Getter 和 Setter 方法 + public boolean isHasConflict() { + return hasConflict; + } + + public void setHasConflict(boolean hasConflict) { + this.hasConflict = hasConflict; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + // 可选:提供一个方便的toString方法,便于打印或查看结果 + @Override + public String toString() { + return "ConflictCheckResultVO{" + "hasConflict=" + hasConflict + ", message='" + message + '\'' + '}'; + } +} diff --git a/src/main/java/com/huoran/iasf/vo/SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO.java b/src/main/java/com/huoran/iasf/vo/SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO.java new file mode 100644 index 0000000..aaa3379 --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO.java @@ -0,0 +1,10 @@ +package com.huoran.iasf.vo; + +import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; +import lombok.Data; + +@Data +public class SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO extends SysFloatingColumnSchemeScopeOfApplication { + private String schemeName; // 悬浮栏方案名称,从关联查询中获取 + private Integer siteId; // 站点ID,从关联查询中获取 +} diff --git a/src/main/java/com/huoran/iasf/vo/req/ApplicationScopeCheckReq.java b/src/main/java/com/huoran/iasf/vo/req/ApplicationScopeCheckReq.java new file mode 100644 index 0000000..4f5ec7f --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/req/ApplicationScopeCheckReq.java @@ -0,0 +1,19 @@ +package com.huoran.iasf.vo.req; + +import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ApplicationScopeCheckReq { + @ApiModelProperty(value = "站点id", required = true) + Integer siteId; + + @ApiModelProperty(value = "应用范围Id", required = true) + List applicationScopeId; + + @ApiModelProperty(value = "悬浮栏方案id", required = true) + Integer floatingBarSchemeId; +}