编辑启用状态的悬浮栏应用范围时增加校验判断能否编辑成功

master
rong.liu 5 months ago
parent 321db56def
commit 6511baddcc
  1. 10
      src/main/java/com/huoran/iasf/controller/SysFloatingColumnSchemeController.java
  2. 4
      src/main/java/com/huoran/iasf/mapper/SysColumnMapper.java
  3. 19
      src/main/java/com/huoran/iasf/mapper/SysFloatingColumnSchemeMapper.java
  4. 13
      src/main/java/com/huoran/iasf/mapper/xml/SysColumnMapper.xml
  5. 61
      src/main/java/com/huoran/iasf/mapper/xml/SysFloatingColumnSchemeMapper.xml
  6. 2
      src/main/java/com/huoran/iasf/service/SysColumnService.java
  7. 4
      src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeScopeOfApplicationService.java
  8. 12
      src/main/java/com/huoran/iasf/service/SysFloatingColumnSchemeService.java
  9. 23
      src/main/java/com/huoran/iasf/service/impl/SysColumnServiceImpl.java
  10. 20
      src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeScopeOfApplicationServiceImpl.java
  11. 200
      src/main/java/com/huoran/iasf/service/impl/SysFloatingColumnSchemeServiceImpl.java
  12. 43
      src/main/java/com/huoran/iasf/vo/ConflictCheckResultVO.java
  13. 10
      src/main/java/com/huoran/iasf/vo/SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO.java
  14. 19
      src/main/java/com/huoran/iasf/vo/req/ApplicationScopeCheckReq.java

@ -10,6 +10,7 @@ import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication;
import com.huoran.iasf.service.SysFloatingColumnSchemeModuleService; import com.huoran.iasf.service.SysFloatingColumnSchemeModuleService;
import com.huoran.iasf.service.SysFloatingColumnSchemeScopeOfApplicationService; import com.huoran.iasf.service.SysFloatingColumnSchemeScopeOfApplicationService;
import com.huoran.iasf.service.SysFloatingColumnSchemeService; import com.huoran.iasf.service.SysFloatingColumnSchemeService;
import com.huoran.iasf.vo.ConflictCheckResultVO;
import com.huoran.iasf.vo.SysFloatingColumnSchemeVO; import com.huoran.iasf.vo.SysFloatingColumnSchemeVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; import com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
import io.swagger.annotations.Api; 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 (sysFloatingColumnScheme.getId() == null) {
if (checkSchemeName(sysFloatingColumnScheme.getSchemeName(), sysFloatingColumnScheme.getSiteId())) { if (checkSchemeName(sysFloatingColumnScheme.getSchemeName(), sysFloatingColumnScheme.getSiteId())) {

@ -40,4 +40,8 @@ public interface SysColumnMapper extends BaseMapper<SysColumn> {
Integer oneLevelChecksThemAll(@Param("theChildId")Integer theChildId); Integer oneLevelChecksThemAll(@Param("theChildId")Integer theChildId);
List<SysColumn> queryByColumnType(@Param("ids")String ids); List<SysColumn> queryByColumnType(@Param("ids")String ids);
List<SysColumn> multiIdQueryColumnInformation(@Param("ids")String ids);
String getColumnNamesById(@Param("ids")String ids);
} }

@ -4,12 +4,17 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huoran.iasf.entity.SysFloatingColumnScheme; import com.huoran.iasf.entity.SysFloatingColumnScheme;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; 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.SysFloatingColumnSchemeVO;
import com.huoran.iasf.vo.req.ApplicationScopeCheckReq;
import com.huoran.iasf.vo.req.PageContentReqVO; import com.huoran.iasf.vo.req.PageContentReqVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; import com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
import com.huoran.iasf.vo.resp.PageContentRespVO; import com.huoran.iasf.vo.resp.PageContentRespVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p> * <p>
* 悬浮栏方案 Mapper 接口 * 悬浮栏方案 Mapper 接口
@ -21,4 +26,18 @@ import org.apache.ibatis.annotations.Param;
public interface SysFloatingColumnSchemeMapper extends BaseMapper<SysFloatingColumnScheme> { public interface SysFloatingColumnSchemeMapper extends BaseMapper<SysFloatingColumnScheme> {
IPage<SysFloatingColumnSchemeVO> floatingBarList(Page<SysFloatingColumnSchemeVO> page, @Param("req") SuspensionBarListPagingReq req); IPage<SysFloatingColumnSchemeVO> floatingBarList(Page<SysFloatingColumnSchemeVO> page, @Param("req") SuspensionBarListPagingReq req);
List<SysFloatingColumnSchemeScopeOfApplication> getsTheGloballyEnabledFloatingBarSchemeRadius(@Param("req") ApplicationScopeCheckReq req);
// 查询当前站点下所有已启用的悬浮栏方案(排除当前方案ID),并关联获取站点ID
List<SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO> selectEnabledScopesExcludingCurrent(
@Param("floatingBarSchemeId") Integer floatingBarSchemeId,
@Param("siteId") Integer siteId);
// 查询该站点下所有其他启用的悬浮栏方案及其应用范围,排除指定的方案ID列表
List<SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO> selectEnabledScopesForMultiConflictCheck(
@Param("siteId") Integer siteId,
@Param("excludeSchemeIds") List<String> excludeSchemeIds,@Param("floatingBarSchemeId")Integer floatingBarSchemeId);
} }

@ -195,6 +195,19 @@
WHERE FIND_IN_SET(s.id, #{ids}) WHERE FIND_IN_SET(s.id, #{ids})
GROUP BY list_style_id GROUP BY list_style_id
</select> </select>
<select id="multiIdQueryColumnInformation" resultType="com.huoran.iasf.entity.SysColumn">
SELECT
column_name
FROM sys_column s
WHERE FIND_IN_SET(s.id, #{ids})
</select>
<select id="getColumnNamesById" resultType="java.lang.String">
SELECT
GROUP_CONCAT(s.column_name)
FROM
sys_column s
WHERE FIND_IN_SET(s.id, #{ids})
</select>
</mapper> </mapper>

@ -48,4 +48,65 @@
ORDER BY ORDER BY
s.id DESC s.id DESC
</select> </select>
<select id="getsTheGloballyEnabledFloatingBarSchemeRadius"
resultType="com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication">
SELECT
s.*
FROM
sys_floating_column_scheme s
INNER JOIN sys_floating_column_scheme_scope_of_application a ON a.floating_bar_scheme_id = s.id
WHERE
s.site_id = #{req.siteId}
AND s.is_disable = 0
AND a.floating_bar_scheme_id != #{req.floatingBarSchemeId}
AND (
#{req.applicationScopeIds} = '0' OR
FIND_IN_SET('0', a.application_scope_id) OR
#{req.applicationScopeIds} != '0' AND
(
FIND_IN_SET(#{req.applicationScopeIds}, a.application_scope_id) OR
FIND_IN_SET('0', a.application_scope_id)
)
)
</select>
<select id="selectEnabledScopesExcludingCurrent"
resultType="com.huoran.iasf.vo.SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO">
SELECT
sfcsoa.*,
sfc.scheme_name,
sfc.site_id
FROM
sys_floating_column_scheme_scope_of_application sfcsoa
JOIN sys_floating_column_scheme sfc ON sfcsoa.floating_bar_scheme_id = sfc.id
WHERE
sfcsoa.floating_bar_scheme_id != #{floatingBarSchemeId} AND sfc.status = 1 AND sfc.is_disable = 0
AND sfc.site_id = #{siteId}
</select>
<select id="selectEnabledScopesForMultiConflictCheck"
resultType="com.huoran.iasf.vo.SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO">
SELECT sfcsoa.*, sfc.scheme_name, sfc.site_id
FROM sys_floating_column_scheme_scope_of_application sfcsoa
JOIN sys_floating_column_scheme sfc ON sfcsoa.floating_bar_scheme_id = sfc.id
WHERE sfc.status = 1 AND sfc.is_disable = 0
AND sfc.site_id = #{siteId}
AND sfcsoa.floating_bar_scheme_id !=#{floatingBarSchemeId}
AND sfcsoa.floating_bar_scheme_id NOT IN
<foreach item="id" index="index" collection="excludeSchemeIds" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper> </mapper>

@ -8,6 +8,7 @@ import com.huoran.iasf.vo.req.LongPageColumnReqVO;
import com.huoran.iasf.vo.req.PageContentReqVO; import com.huoran.iasf.vo.req.PageContentReqVO;
import com.huoran.iasf.vo.req.PaginationColumnReqVO; import com.huoran.iasf.vo.req.PaginationColumnReqVO;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -43,4 +44,5 @@ public interface SysColumnService extends IService<SysColumn> {
R queryArticlesByColumnType(String ids,Integer id); R queryArticlesByColumnType(String ids,Integer id);
List<String> getColumnNamesByIds(Collection<String> applicationScopeIds);
} }

@ -4,6 +4,7 @@ import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* <p> * <p>
@ -20,4 +21,7 @@ public interface SysFloatingColumnSchemeScopeOfApplicationService extends IServi
//删除 //删除
void deleteByFloatingBarSchemeId(Integer floatingBarSchemeId); void deleteByFloatingBarSchemeId(Integer floatingBarSchemeId);
List<String> getScopeIdsBySchemeId(Integer id);
} }

@ -1,10 +1,15 @@
package com.huoran.iasf.service; package com.huoran.iasf.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huoran.iasf.common.utils.R; import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysFloatingColumnScheme; 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 com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
import java.util.List;
/** /**
* <p> * <p>
* 悬浮栏方案 服务类 * 悬浮栏方案 服务类
@ -22,4 +27,9 @@ public interface SysFloatingColumnSchemeService extends IService<SysFloatingColu
R checkEnableOrDisable(Integer schemeId, Integer enable); R checkEnableOrDisable(Integer schemeId, Integer enable);
R columnDisplayFloatingBar(String columnId); R columnDisplayFloatingBar(String columnId);
ConflictCheckResultVO preCheckMultiScopeConflictBeforeUpdate(
Integer siteId, List<SysFloatingColumnSchemeScopeOfApplication> updatedScopes,Integer floatingBarSchemeId);
} }

@ -21,7 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @描述 服务类 * @描述 服务类
@ -209,6 +212,26 @@ public class SysColumnServiceImpl extends ServiceImpl<SysColumnMapper, SysColumn
return R.success(contentMapper.columnConditionsFilterArticles(id + "")); return R.success(contentMapper.columnConditionsFilterArticles(id + ""));
} }
@Override
public List<String> getColumnNamesByIds(Collection<String> applicationScopeIds) {
if (CollectionUtils.isEmpty(applicationScopeIds)) {
return Collections.emptyList();
}
// 将ID集合转换为逗号分隔的字符串,以便在IN子句中使用
String scopeIdsStr = String.join(",", applicationScopeIds);
// 执行SQL查询,这里直接使用BaseMapper的selectList方法并传入自定义的Wrapper
QueryWrapper<SysColumn> 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());
}
} }

@ -1,13 +1,14 @@
package com.huoran.iasf.service.impl; package com.huoran.iasf.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.entity.SysFloatingColumnSchemeScopeOfApplication;
import com.huoran.iasf.mapper.SysFloatingColumnSchemeScopeOfApplicationMapper; import com.huoran.iasf.mapper.SysFloatingColumnSchemeScopeOfApplicationMapper;
import com.huoran.iasf.service.SysFloatingColumnSchemeScopeOfApplicationService; import com.huoran.iasf.service.SysFloatingColumnSchemeScopeOfApplicationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* <p> * <p>
@ -33,4 +34,21 @@ public class SysFloatingColumnSchemeScopeOfApplicationServiceImpl extends Servic
queryWrapper.eq("floating_bar_scheme_id", floatingBarSchemeId); queryWrapper.eq("floating_bar_scheme_id", floatingBarSchemeId);
this.remove(queryWrapper); this.remove(queryWrapper);
} }
@Override
public List<String> getScopeIdsBySchemeId(Integer id) {
QueryWrapper<SysFloatingColumnSchemeScopeOfApplication> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("floating_bar_scheme_id", id);
if (this.list(queryWrapper) != null) {
List<SysFloatingColumnSchemeScopeOfApplication> list = this.list(queryWrapper);
Set<String> set = list.stream().map(SysFloatingColumnSchemeScopeOfApplication::getApplicationScopeId).collect(java.util.stream.Collectors.toSet());
if (set != null) {
return new java.util.ArrayList<>(set);
}
}
return null;
}
} }

@ -16,8 +16,11 @@ import com.huoran.iasf.mapper.SysFloatingColumnSchemeMapper;
import com.huoran.iasf.mapper.SysFloatingColumnSchemeModuleMapper; import com.huoran.iasf.mapper.SysFloatingColumnSchemeModuleMapper;
import com.huoran.iasf.mapper.SysFloatingColumnSchemeScopeOfApplicationMapper; import com.huoran.iasf.mapper.SysFloatingColumnSchemeScopeOfApplicationMapper;
import com.huoran.iasf.service.SysFloatingColumnSchemeService; 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.SysFloatingColumnSchemeVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -205,17 +208,13 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl<SysFloatingC
//查询当前站点下已启用,且已发布的悬浮栏 //查询当前站点下已启用,且已发布的悬浮栏
List<SysFloatingColumnScheme> floatingColumnSchemeList = baseMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnScheme>() List<SysFloatingColumnScheme> floatingColumnSchemeList = baseMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnScheme>().eq(SysFloatingColumnScheme::getSiteId, column.getSiteId()).eq(SysFloatingColumnScheme::getIsDisable, 0).eq(SysFloatingColumnScheme::getStatus, 1));
.eq(SysFloatingColumnScheme::getSiteId, column.getSiteId())
.eq(SysFloatingColumnScheme::getIsDisable, 0)
.eq(SysFloatingColumnScheme::getStatus, 1));
for (SysFloatingColumnScheme scheme : floatingColumnSchemeList) { for (SysFloatingColumnScheme scheme : floatingColumnSchemeList) {
//判断当前启用的栏目如果为全局的直接返回全局的已启用的方案 //判断当前启用的栏目如果为全局的直接返回全局的已启用的方案
if (scheme.getIsGlobal() == 1) { if (scheme.getIsGlobal() == 1) {
//查询悬浮栏当前绑定的方案 //查询悬浮栏当前绑定的方案
List<SysFloatingColumnSchemeModule> columnSchemeModule = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeModule>() List<SysFloatingColumnSchemeModule> columnSchemeModule = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeModule>().eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, scheme.getId()).eq(SysFloatingColumnSchemeModule::getIsDisable, 0));
.eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, scheme.getId()).eq(SysFloatingColumnSchemeModule::getIsDisable, 0));
; ;
if (!ObjectUtil.isEmpty(columnSchemeModule)) { if (!ObjectUtil.isEmpty(columnSchemeModule)) {
return R.success(columnSchemeModule); return R.success(columnSchemeModule);
@ -225,74 +224,113 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl<SysFloatingC
List<Integer> floatingBarIds = scopeOfApplicationMapper.checkBoundByColumnId(columnId); List<Integer> floatingBarIds = scopeOfApplicationMapper.checkBoundByColumnId(columnId);
//查询悬浮栏绑定的方案 //查询悬浮栏绑定的方案
for (Integer floatingBarId : floatingBarIds) { for (Integer floatingBarId : floatingBarIds) {
List<SysFloatingColumnSchemeModule> list = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeModule>() List<SysFloatingColumnSchemeModule> list = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeModule>().eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, floatingBarId).eq(SysFloatingColumnSchemeModule::getIsDisable, 0));
.eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, floatingBarId).eq(SysFloatingColumnSchemeModule::getIsDisable, 0));
columnSchemeModuleList.addAll(list); columnSchemeModuleList.addAll(list);
} }
return R.success(columnSchemeModuleList); return R.success(columnSchemeModuleList);
} }
} }
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<SysFloatingColumnSchemeScopeOfApplication> sysFloatingColumnSchemeScopeOfApplications = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeScopeOfApplication>()
.eq(SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, columnId)
);
*//*
/**
* 在多个悬浮栏方案更新前预先检查是否存在应用范围冲突
*
* @param siteId 当前操作所在的站点ID
* @param updatedScopes 待更新的悬浮栏方案列表
* @return 冲突检测结果包含是否有冲突及详细的冲突信息
*/
@Transactional(readOnly = true)
public ConflictCheckResultVO preCheckMultiScopeConflictBeforeUpdate(
Integer siteId, List<SysFloatingColumnSchemeScopeOfApplication> updatedScopes,Integer floatingBarSchemeId) {
//查询栏目绑定过的悬浮栏 // 1. 收集待更新方案的ID,用于排除这些方案在冲突检测中的干扰
List<Integer> sysFloatingColumnSchemeScopeOfApplications = scopeOfApplicationMapper.checkBoundByColumnId(columnId); List<String> excludeSchemeIds = updatedScopes.stream()
.map(SysFloatingColumnSchemeScopeOfApplication::getApplicationScopeId)
List<SysFloatingColumnSchemeModule> columnSchemeModuleList = new ArrayList<>(); .collect(Collectors.toList());
// 2. 从数据库查询该站点下所有启用的悬浮栏方案,但排除掉当前正在更新的那些方案
List<SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO> enabledScopes =
baseMapper.selectEnabledScopesForMultiConflictCheck(siteId, excludeSchemeIds,floatingBarSchemeId);
for (Integer floatingBarId : sysFloatingColumnSchemeScopeOfApplications) { /*// 初始化冲突标记为false,并准备一个StringBuilder用于记录冲突信息
//查询启用的悬浮栏 boolean hasConflict = false;
SysFloatingColumnScheme scheme = floatingColumnSchemeMapper.selectById(floatingBarId); StringBuilder conflictMessage = new StringBuilder();
if (!ObjectUtil.isEmpty(scheme)) { // 3. 对比每个待更新的方案与已启用方案,检测应用范围是否有重叠
//且为启用状态下才查询绑定的方案 for (SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO existingScope : enabledScopes) {
if (scheme.getIsDisable() == 0) { for (SysFloatingColumnSchemeScopeOfApplication newScope : updatedScopes) {
//查询悬浮栏当前绑定的方案 // 假设冲突基于应用范围的直接比较,实际情况可能需要更复杂的逻辑
List<SysFloatingColumnSchemeModule> columnSchemeModule = floatingColumnSchemeModuleMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeModule>() if (existingScope.getApplicationScopeId().equals(newScope.getApplicationScopeId())) {
.eq(SysFloatingColumnSchemeModule::getFloatingBarSchemeId, scheme.getId()).eq(SysFloatingColumnSchemeModule::getIsDisable, 0));; hasConflict = true;
if (!ObjectUtil.isEmpty(columnSchemeModule)) { conflictMessage.append("发现冲突:方案“")
columnSchemeModuleList.addAll(columnSchemeModule); .append(existingScope.getSchemeName())
.append("”与待更新的方案在应用范围“")
.append(newScope.getApplicationScopeId())
.append("”上重叠。\n");
} }
} }
}*/
// 初始化冲突标记为false,并准备一个StringBuilder用于记录冲突信息
boolean hasConflict = false;
StringBuilder conflictMessageBuilder = new StringBuilder();
Set<String> conflictColumnNames = new HashSet<>(); // 用于存储所有冲突的栏目名称
// 3. 对比每个待更新的方案与已启用方案,检测应用范围是否有重叠
for (SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO existingScope : enabledScopes) {
for (SysFloatingColumnSchemeScopeOfApplication newScope : updatedScopes) {
// 分割应用范围ID为集合,以便逐个比较
Set<Integer> existingScopeIds = Arrays.stream(existingScope.getApplicationScopeId().split(","))
.map(String::trim)
.filter(id -> !id.isEmpty() && NumberUtils.isCreatable(id))
.map(Integer::parseInt)
.collect(Collectors.toSet());
Set<Integer> newScopeIds = Arrays.stream(newScope.getApplicationScopeId().split(","))
.map(String::trim)
.filter(id -> !id.isEmpty() && NumberUtils.isCreatable(id))
.map(Integer::parseInt)
.collect(Collectors.toSet());
// 找出重叠的范围ID
Set<Integer> 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) { private boolean existsEnabledGlobal(Integer siteId) {
@ -333,6 +371,7 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl<SysFloatingC
Set<Integer> enabledScopeIds = Arrays.stream(enabledScope.getApplicationScopeId().split(",")).map(Integer::parseInt).collect(Collectors.toSet()); Set<Integer> enabledScopeIds = Arrays.stream(enabledScope.getApplicationScopeId().split(",")).map(Integer::parseInt).collect(Collectors.toSet());
if (!Collections.disjoint(currentScopeIds, enabledScopeIds)) { if (!Collections.disjoint(currentScopeIds, enabledScopeIds)) {
// System.err.println("--------------->>>>重叠的范围ID: " + currentScopeIds.stream());
return true; // 存在重叠 return true; // 存在重叠
} }
} }
@ -346,51 +385,56 @@ public class SysFloatingColumnSchemeServiceImpl extends ServiceImpl<SysFloatingC
* @param schemeId 悬浮栏方案ID * @param schemeId 悬浮栏方案ID
* @return 冲突提示信息 * @return 冲突提示信息
*/ */
/**
* 生成关于悬浮栏方案范围冲突的提示信息
* 只有当尝试启用的悬浮栏方案与现有启用的方案存在范围重叠时才会生成冲突信息
*
* @param schemeId 当前操作的悬浮栏方案ID
* @param siteId 站点ID当前示例中未直接使用根据需求可能用于扩展功能
* @param enableAction 操作类型0 表示启用操作其他值视为未知操作
* @return 包含冲突范围栏目的提示信息如果没有冲突则返回空字符串
*/
private String generateConflictMessage(Integer schemeId, Integer siteId, Integer enableAction) { private String generateConflictMessage(Integer schemeId, Integer siteId, Integer enableAction) {
// 调用 hasOverlapWithOtherEnabled 确认是否有重叠 // 确认当前悬浮栏方案是否与其他方案存在范围重叠
if (!hasOverlapWithOtherEnabled(schemeId, siteId)) { if (!hasOverlapWithOtherEnabled(schemeId, siteId)) {
return ""; // 无冲突则返回空字符串 return ""; // 若无重叠,直接返回空字符串表示无冲突
} }
// 获取所有悬浮栏方案的范围ID // 获取与当前悬浮栏方案ID相关的冲突范围ID集合
List<SysFloatingColumnSchemeScopeOfApplication> allScopes = scopeOfApplicationMapper.selectList(null); List<SysFloatingColumnSchemeScopeOfApplication> conflictingScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeScopeOfApplication>().eq(SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, schemeId));
Map<Integer, Set<Integer>> allScopeIdMap = allScopes.stream()
.collect(Collectors.groupingBy(
SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId,
Collectors.flatMapping(scope -> Arrays.stream(scope.getApplicationScopeId().split(",")), Collectors.mapping(Integer::parseInt, Collectors.toSet()))
));
// 获取当前方案的范围ID // 将范围ID字符串转换为整数集合
Set<Integer> currentScopeIds = allScopeIdMap.getOrDefault(schemeId, Collections.emptySet()); Set<Integer> conflictScopeIds = conflictingScopes.stream().flatMap(scope -> Arrays.stream(scope.getApplicationScopeId().split(","))).map(Integer::parseInt).collect(Collectors.toSet());
// 找出与其他悬浮栏方案重复的范围ID //查询当前已经启用的悬浮栏方案下的的应用范围跟当前设置的范围有重复的就只提出出来重复的id
Set<Integer> duplicateScopeIds = allScopeIdMap.values().stream() conflictScopeIds.retainAll(checkBoundByColumnId(conflictScopeIds, siteId));
.filter(ids -> !ids.equals(currentScopeIds) && !ids.isEmpty())
.flatMap(Set::stream)
.filter(currentScopeIds::contains)
.collect(Collectors.toSet());
// 查询重复范围对应的栏目名称 // 根据冲突范围ID查询对应的栏目名称
List<String> duplicateScopeNames = columnMapper.selectList(new LambdaQueryWrapper<SysColumn>().in(SysColumn::getId, duplicateScopeIds)) List<String> conflictingScopeNames = columnMapper.selectList(new LambdaQueryWrapper<SysColumn>().in(SysColumn::getId, conflictScopeIds)).stream().map(SysColumn::getColumnName).collect(Collectors.toList());
.stream()
.map(SysColumn::getColumnName)
.collect(Collectors.toList());
// 构建并返回提示信息 // 根据操作类型生成具体的提示信息
if (!duplicateScopeNames.isEmpty()) {
String scopesJoined = String.join("”, “", duplicateScopeNames);
if (enableAction == 0) { // 启用操作 if (enableAction == 0) { // 启用操作
return "栏目:“" + scopesJoined + "”已存在于其他悬浮栏配置中,请处理重复后再尝试启用。"; // 拼接冲突范围名称,提醒用户需先解决冲突
} else if (enableAction == 1) { // 禁用操作 return "栏目:“" + String.join("”, “", conflictingScopeNames) + "”已设置有悬浮栏,请先移除相关设置再尝试启用。";
return "注意:禁用操作可能会影响到栏目“" + scopesJoined + "”在其他悬浮栏的配置,请谨慎操作。";
} else { } else {
return "未知的操作类型"; return "未知的操作类型";
} }
} else {
return ""; // 逻辑上这里应该不会到达,因为之前已确认有重叠,但为了完整性保留
} }
private Set<Integer> checkBoundByColumnId(Set<Integer> columnIds, Integer siteId) {
// 构造SQL查询条件,用于查找所有启用的悬浮栏方案及其范围
/*String sqlInCondition = columnIds.stream().map(Object::toString).collect(Collectors.joining(","));*/ // 移除了外部的括号
List<SysFloatingColumnSchemeScopeOfApplication> enabledConflictingScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper<SysFloatingColumnSchemeScopeOfApplication>().inSql(SysFloatingColumnSchemeScopeOfApplication::getFloatingBarSchemeId, "SELECT id FROM sys_floating_column_scheme WHERE is_disable = 0 AND site_id = " + siteId).in(SysFloatingColumnSchemeScopeOfApplication::getApplicationScopeId, columnIds));
// 转换为范围ID集合
Set<Integer> 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<SysFloatingC
return baseMapper.selectCount(new LambdaQueryWrapper<SysFloatingColumnScheme>().eq(SysFloatingColumnScheme::getSiteId, siteId).eq(SysFloatingColumnScheme::getIsGlobal, 1).eq(SysFloatingColumnScheme::getIsDisable, false)); return baseMapper.selectCount(new LambdaQueryWrapper<SysFloatingColumnScheme>().eq(SysFloatingColumnScheme::getSiteId, siteId).eq(SysFloatingColumnScheme::getIsGlobal, 1).eq(SysFloatingColumnScheme::getIsDisable, false));
} }
private String getColumnNameById(String overlapId) {
return columnMapper.getColumnNamesById(overlapId);
}
} }

@ -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 + '\'' + '}';
}
}

@ -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,从关联查询中获取
}

@ -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<String> applicationScopeId;
@ApiModelProperty(value = "悬浮栏方案id", required = true)
Integer floatingBarSchemeId;
}
Loading…
Cancel
Save