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

master
rong.liu 5 months ago
parent 6511baddcc
commit 40e4fd255f
  1. 4
      pom.xml
  2. 13
      src/main/java/com/huoran/iasf/controller/SysFooterSetupController.java
  3. 8
      src/main/java/com/huoran/iasf/mapper/SysFooterSetupMapper.java
  4. 17
      src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupMapper.xml
  5. 8
      src/main/java/com/huoran/iasf/service/SysFooterSetupService.java
  6. 80
      src/main/java/com/huoran/iasf/service/impl/SysFooterSetupServiceImpl.java
  7. 12
      src/main/java/com/huoran/iasf/vo/SysPageFooterScopeOfApplicationWithSiteIdVO.java

@ -282,14 +282,14 @@
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugin>-->
</plugins>
<resources>

@ -10,6 +10,7 @@ import com.huoran.iasf.entity.SysFooterSetup;
import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication;
import com.huoran.iasf.service.SysFooterSetupScopeOfApplicationService;
import com.huoran.iasf.service.SysFooterSetupService;
import com.huoran.iasf.vo.ConflictCheckResultVO;
import com.huoran.iasf.vo.FooterListVO;
import com.huoran.iasf.vo.SysFloatingColumnSchemeVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
@ -86,12 +87,24 @@ public class SysFooterSetupController {
@ApiOperation(value = "保存或更新页脚配置记录", response = SysFooterSetup.class)
public R saveOrUpdate(@RequestBody @ApiParam(name = "页脚配置对象", value = "包含页脚配置详细信息,若id不存在则新建,否则视为更新", required = true) SysFooterSetup sysFooterSetup) {
if (sysFooterSetup.getId() != null && sysFooterSetup.getIsDisable() == 0) {
ConflictCheckResultVO conflictCheckResultVO = service.preCheckMultiScopeConflictBeforeUpdate(sysFooterSetup.getSiteId(),
sysFooterSetup.getFooterSetupScopeOfApplications(), sysFooterSetup.getId());
if (conflictCheckResultVO.isHasConflict()) {
return R.fail(conflictCheckResultVO.getMessage());
}
}
// 新增场景下直接进行校验
if (sysFooterSetup.getId() == null) {
if (verifyTheFooterName(sysFooterSetup.getFooterName(), sysFooterSetup.getSiteId())) {
return R.fail("该站点下已存在相同的页脚名称");
}
}
// 编辑场景下,只有当名称发生改变时才进行校验,并排除当前记录自身
else if (!sysFooterSetup.getFooterName().equals(service.getById(sysFooterSetup.getId()).getFooterName())) {
if (checkSchemeNameExceptSelf(sysFooterSetup.getFooterName(), sysFooterSetup.getSiteId(), sysFooterSetup.getId())) {

@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huoran.iasf.entity.SysFooterSetup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huoran.iasf.vo.FooterListVO;
import com.huoran.iasf.vo.SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO;
import com.huoran.iasf.vo.SysFloatingColumnSchemeVO;
import com.huoran.iasf.vo.SysPageFooterScopeOfApplicationWithSiteIdVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 页脚配置 Mapper 接口
@ -20,4 +24,8 @@ import org.apache.ibatis.annotations.Param;
public interface SysFooterSetupMapper extends BaseMapper<SysFooterSetup> {
IPage<FooterListVO> footerList(Page<FooterListVO> page, @Param("req") SuspensionBarListPagingReq sysFloatingColumnScheme);
List<SysPageFooterScopeOfApplicationWithSiteIdVO> selectEnabledScopesForMultiConflictCheck(
@Param("siteId") Integer siteId,
@Param("excludeSchemeIds") List<String> excludeSchemeIds,@Param("floatingBarSchemeId")Integer floatingBarSchemeId);
}

@ -51,4 +51,21 @@
ORDER BY
s.id DESC
</select>
<select id="selectEnabledScopesForMultiConflictCheck"
resultType="com.huoran.iasf.vo.SysPageFooterScopeOfApplicationWithSiteIdVO">
SELECT
sfcsoa.*,
sfc.footer_name,
sfc.site_id
FROM
sys_footer_setup_scope_of_application sfcsoa
JOIN sys_footer_setup sfc ON sfcsoa.footer_id = sfc.id
WHERE sfc.status = 1 AND sfc.is_disable = 0
AND sfc.site_id = #{siteId}
AND sfcsoa.footer_id !=#{floatingBarSchemeId}
AND sfcsoa.footer_id NOT IN
<foreach item="id" index="index" collection="excludeSchemeIds" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

@ -1,10 +1,15 @@
package com.huoran.iasf.service;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication;
import com.huoran.iasf.entity.SysFooterSetup;
import com.baomidou.mybatisplus.extension.service.IService;
import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication;
import com.huoran.iasf.vo.ConflictCheckResultVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
import java.util.List;
/**
* <p>
* 页脚配置 服务类
@ -20,4 +25,7 @@ public interface SysFooterSetupService extends IService<SysFooterSetup> {
R checkEnableOrDisable(Integer id, Integer isDisable);
R showTheFooterAccordingToTheColumn(String columnId);
ConflictCheckResultVO preCheckMultiScopeConflictBeforeUpdate(
Integer siteId, List<SysFooterSetupScopeOfApplication> updatedScopes, Integer floatingBarSchemeId);
}

@ -8,16 +8,22 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysColumn;
import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication;
import com.huoran.iasf.entity.SysFooterSetup;
import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication;
import com.huoran.iasf.mapper.SysColumnMapper;
import com.huoran.iasf.mapper.SysFooterSetupMapper;
import com.huoran.iasf.mapper.SysFooterSetupScopeOfApplicationMapper;
import com.huoran.iasf.service.SysFooterSetupService;
import com.huoran.iasf.vo.ConflictCheckResultVO;
import com.huoran.iasf.vo.FooterListVO;
import com.huoran.iasf.vo.SysFloatingColumnSchemeScopeOfApplicationWithSiteIdVO;
import com.huoran.iasf.vo.SysPageFooterScopeOfApplicationWithSiteIdVO;
import com.huoran.iasf.vo.req.SuspensionBarListPagingReq;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@ -127,6 +133,80 @@ public class SysFooterSetupServiceImpl extends ServiceImpl<SysFooterSetupMapper,
return R.success(Collections.emptyList());
}
/* @Override
public ConflictCheckResultVO preCheckMultiScopeConflictBeforeUpdate(Integer siteId, List<SysFooterSetupScopeOfApplication> updatedScopes, Integer floatingBarSchemeId) {
return null;
}*/
@Transactional(readOnly = true)
public ConflictCheckResultVO preCheckMultiScopeConflictBeforeUpdate(
Integer siteId, List<SysFooterSetupScopeOfApplication> updatedScopes, Integer floatingBarSchemeId) {
// 1. 收集待更新方案的ID,用于排除这些方案在冲突检测中的干扰
List<String> excludeSchemeIds = updatedScopes.stream()
.map(SysFooterSetupScopeOfApplication::getApplicationScopeId)
.collect(Collectors.toList());
// 2. 从数据库查询该站点下所有启用的悬浮栏方案,但排除掉当前正在更新的那些方案
List<SysPageFooterScopeOfApplicationWithSiteIdVO> enabledScopes =
baseMapper.selectEnabledScopesForMultiConflictCheck(siteId, excludeSchemeIds,floatingBarSchemeId);
// 初始化冲突标记为false,并准备一个StringBuilder用于记录冲突信息
boolean hasConflict = false;
StringBuilder conflictMessageBuilder = new StringBuilder();
Set<String> conflictColumnNames = new HashSet<>(); // 用于存储所有冲突的栏目名称
// 3. 对比每个待更新的方案与已启用方案,检测应用范围是否有重叠
for (SysPageFooterScopeOfApplicationWithSiteIdVO existingScope : enabledScopes) {
for (SysFooterSetupScopeOfApplication 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());
}
private String getColumnNameById(String overlapId) {
return columnMapper.getColumnNamesById(overlapId);
}
/**
* 检查当前悬浮栏方案与已启用方案是否有重叠

@ -0,0 +1,12 @@
package com.huoran.iasf.vo;
import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication;
import com.huoran.iasf.entity.SysFooterSetup;
import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication;
import lombok.Data;
@Data
public class SysPageFooterScopeOfApplicationWithSiteIdVO extends SysFooterSetupScopeOfApplication {
private String schemeName; // 悬浮栏方案名称,从关联查询中获取
private Integer siteId; // 站点ID,从关联查询中获取
}
Loading…
Cancel
Save