diff --git a/src/main/java/com/huoran/iasf/controller/SysFooterSetupController.java b/src/main/java/com/huoran/iasf/controller/SysFooterSetupController.java new file mode 100644 index 0000000..3f478e2 --- /dev/null +++ b/src/main/java/com/huoran/iasf/controller/SysFooterSetupController.java @@ -0,0 +1,237 @@ +package com.huoran.iasf.controller; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.huoran.iasf.common.utils.R; +import com.huoran.iasf.entity.SysFloatingColumnScheme; +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.FooterListVO; +import com.huoran.iasf.vo.SysFloatingColumnSchemeVO; +import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @描述:页脚配置控制类 + * @作者: Rong + * @日期: 2024-06-07 + */ +@RestController +@RequestMapping("/SysFooterSetupService/SysFooterSetup") +@Api(value = "页脚配置:SysFooterSetupController", tags = "页脚配置:页脚配置") +public class SysFooterSetupController { + + @Autowired + public SysFooterSetupService service; + + @Autowired + public SysFooterSetupScopeOfApplicationService footerSetupScopeOfApplicationService; + + + // 根据站点校验方案名称,排除当前ID记录 + private boolean checkSchemeNameExceptSelf(String footerName, Integer siteId, Integer id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("footer_name", footerName); + queryWrapper.eq("site_id", siteId); + // 添加条件,排除当前ID的记录 + if (id != null) { + queryWrapper.ne("id", id); + } + return service.count(queryWrapper) > 0; + } + + + // 现在仅用于新增场景或编辑时名称变更的校验,不需排除自身ID + private boolean verifyTheFooterName(String footerName, Integer siteId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("footer_name", footerName); + queryWrapper.eq("site_id", siteId); + return service.count(queryWrapper) > 0; + } + + + private void handleFloatingColumnSchemeScopeOfApplications(SysFooterSetup footerSetup) { + if (footerSetup.getFooterSetupScopeOfApplications() != null && !footerSetup.getFooterSetupScopeOfApplications().isEmpty()) { + for (SysFooterSetupScopeOfApplication scope : footerSetup.getFooterSetupScopeOfApplications()) { + scope.setFooterId(footerSetup.getId()); + if (footerSetup.getId() == null) { + // 如果页脚方案是新建的,直接保存范围 + footerSetupScopeOfApplicationService.save(scope); + } else { + // 如果页脚方案是更新的,根据情况更新或保存范围 + footerSetupScopeOfApplicationService.saveOrUpdate(scope); + } + } + } + } + + /** + * 保存或更新页脚配置记录 + * 如果ID为空,则执行保存操作;如果ID有值,则视为更新操作。 + * + * @param sysFooterSetup 要保存或更新的页脚配置对象 + * @return R 结果对象,包含操作状态信息 + */ + @PostMapping("/saveOrUpdate") + @ApiOperation(value = "保存或更新页脚配置记录", response = SysFooterSetup.class) + public R saveOrUpdate(@RequestBody @ApiParam(name = "页脚配置对象", value = "包含页脚配置详细信息,若id不存在则新建,否则视为更新", required = true) SysFooterSetup sysFooterSetup) { + + // 新增场景下直接进行校验 + 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())) { + return R.fail("该站点下已存在相同的页脚名称"); + } + } + + //获取floatingColumnSchemeScopeOfApplications中的范围判断是不是0,如果包含为0 + List footerSetupScopeOfApplications = sysFooterSetup.getFooterSetupScopeOfApplications(); + for (SysFooterSetupScopeOfApplication scopeOfApplication : footerSetupScopeOfApplications) { + if (scopeOfApplication.getApplicationScopeId().equals("0")) { + sysFooterSetup.setIsGlobal(1); + + } else { + sysFooterSetup.setIsGlobal(0); + } + } + + // 处理全局页脚逻辑 + if (sysFooterSetup.getIsGlobal() == 1) { + // 确保没有其他全局页脚同时启用 + long globalCount = service.count(new QueryWrapper().eq("is_global", true).eq("site_id", sysFooterSetup.getSiteId()).eq("is_disable", 0).ne("id", sysFooterSetup.getId())); + if (globalCount > 0) { + return R.fail("已经有全局页脚启用,请先禁用后再尝试设置"); + } + } + + boolean result = false; + + + try { + if (sysFooterSetup.getId() == null) { + // 保存操作 + result = service.save(sysFooterSetup); + } else { + // 更新操作 + result = service.updateById(sysFooterSetup); + } + } catch (Exception e) { + return R.fail("操作失败"); + } + + if (!result) { + return R.fail("操作失败"); + } + + //删除原有范围 + footerSetupScopeOfApplicationService.deleteTheRangeBasedOnTheFooterId(sysFooterSetup.getId()); + + handleFloatingColumnSchemeScopeOfApplications(sysFooterSetup); + + return R.success(); + } + + + @PostMapping("/footerList") + @ApiOperation(value = "页脚列表", response = FooterListVO.class) + public R footerList(@RequestBody SuspensionBarListPagingReq sysFloatingColumnScheme) { + return service.footerList(sysFloatingColumnScheme); + } + + + @PostMapping("/showTheFooterAccordingToTheColumn") + @ApiOperation(value = "根据栏目展示页脚", response = SysFloatingColumnSchemeVO.class) + public R columnDisplayFloatingBar(@ApiParam(name = "columnId", value = "栏目id", required = true) @RequestParam String columnId) { + return service.showTheFooterAccordingToTheColumn(columnId); + } + + /** + * * 1.应用全部权限最高,只要是启用应用全部的,除了一开始没有启用页脚的都弹窗提示,当前已启用了的页脚方案将会被取消。 + * 2.启用了应用全部的,后面要启用部分的,提示先禁用应用全部的。 + * 3.部分启用vs部分启用,且有重合的,提示移除重合的。 + */ + @PostMapping("/enableOrDisableScheme") + @ApiOperation(value = "启用或禁用", response = SysFooterSetup.class) + public R enableOrDisableScheme(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id, @ApiParam(name = "isDisable", value = "是否禁用(0启用 1禁用)", required = true) @RequestParam Integer isDisable) { + /* return service.enableOrDisableScheme(id, isDisable);*/ + + //禁启用操作 + SysFooterSetup footSetup = service.getById(id); + footSetup.setIsDisable(isDisable); + boolean operation = service.updateById(footSetup); + //增加判断如果当前的应用权限如果为全部,需要将当前站点下其余已经启用的给禁用了 + if (footSetup.getIsDisable() == 0 && footSetup.getIsGlobal() == 1) { + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.set("is_disable", 1); + updateWrapper.eq("is_disable", 0); + updateWrapper.eq("site_id", footSetup.getSiteId()); + updateWrapper.ne("id", id); + service.update(updateWrapper); + + } + + + return operation ? R.success() : R.fail("操作失败"); + } + + + @PostMapping("/checkEnableOrDisable") + @ApiOperation(value = "检查“启用”或“禁用”()", response = SysFloatingColumnSchemeVO.class) + public R checkEnableOrDisable(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id, @ApiParam(name = "isDisable", value = "是否禁用(0启用 1禁用)", required = true) @RequestParam Integer isDisable) { + + return service.checkEnableOrDisable(id, isDisable); + } + + + @PostMapping("/findById") + @ApiOperation(value = "查询详情", response = SysFooterSetup.class) + public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { + SysFooterSetup sysFooterSetup = service.getById(id); + + if (!ObjectUtil.isEmpty(handleFloatingColumnSchemeScopeOfApplications(id))) { + sysFooterSetup.setFooterSetupScopeOfApplications(handleFloatingColumnSchemeScopeOfApplications(id)); + } + + return R.success(sysFooterSetup); + } + + //根据页脚获取范围 + private List handleFloatingColumnSchemeScopeOfApplications(Integer footerId) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysFooterSetupScopeOfApplication::getFooterId, footerId); + return footerSetupScopeOfApplicationService.list(queryWrapper); + } + + + @PostMapping("/batchDeletion") + @ApiOperation(value = "批量删除页脚数据", response = SysFloatingColumnScheme.class) + public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List ids) { + boolean delState = service.removeByIds(ids); + //删除的同时将页脚方案以及页脚应用范围 + if (delState) { + for (Integer getFooterId : ids) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysFooterSetupScopeOfApplication::getFooterId, getFooterId); + footerSetupScopeOfApplicationService.remove(queryWrapper); + } + } + + return R.success(); + } +} + diff --git a/src/main/java/com/huoran/iasf/entity/SysFooterSetup.java b/src/main/java/com/huoran/iasf/entity/SysFooterSetup.java new file mode 100644 index 0000000..b637c80 --- /dev/null +++ b/src/main/java/com/huoran/iasf/entity/SysFooterSetup.java @@ -0,0 +1,75 @@ +package com.huoran.iasf.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + *

+ * 页脚配置 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "SysFooterSetup对象", description = "页脚配置") +public class SysFooterSetup implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "站点id") + private Integer siteId; + + @ApiModelProperty(value = "页脚名称") + private String footerName; + + @ApiModelProperty(value = "页脚内容") + private String footerContent; + + @ApiModelProperty(value = "状态(0默认草稿箱 1为已发布)") + private Integer status; + + @ApiModelProperty(value = "悬浮栏样式id(关联样式表id)") + private Integer floatingBarStyle; + + @ApiModelProperty(value = "是否禁用(默认1不启用,0启用 1禁用)") + private Integer isDisable; + + @ApiModelProperty(value = "创建人id") + private Integer founderId; + + @ApiModelProperty(value = "编辑人id") + private Integer editorId; + + @ApiModelProperty(value = "创建时间") + @TableField(fill = FieldFill.INSERT) + private Date createTime; + + @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateTime; + + @ApiModelProperty(value = "是否为全局(0否,1是)") + private Integer isGlobal; + + @ApiModelProperty(value = "应用范围") + @TableField(exist = false) + private List footerSetupScopeOfApplications; + + +} diff --git a/src/main/java/com/huoran/iasf/entity/SysFooterSetupScopeOfApplication.java b/src/main/java/com/huoran/iasf/entity/SysFooterSetupScopeOfApplication.java new file mode 100644 index 0000000..66bac98 --- /dev/null +++ b/src/main/java/com/huoran/iasf/entity/SysFooterSetupScopeOfApplication.java @@ -0,0 +1,38 @@ +package com.huoran.iasf.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + *

+ * 页脚应用范围 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "SysFooterSetupScopeOfApplication对象", description = "页脚应用范围") +public class SysFooterSetupScopeOfApplication implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "主键") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "页脚主键") + private Integer footerId; + + @ApiModelProperty(value = "应用范围id(为0表示网站全局,其余为栏目表主键)") + private String applicationScopeId; + + +} diff --git a/src/main/java/com/huoran/iasf/mapper/SysFooterSetupMapper.java b/src/main/java/com/huoran/iasf/mapper/SysFooterSetupMapper.java new file mode 100644 index 0000000..03ca4ac --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/SysFooterSetupMapper.java @@ -0,0 +1,23 @@ +package com.huoran.iasf.mapper; + +import com.baomidou.mybatisplus.core.metadata.IPage; +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.SysFloatingColumnSchemeVO; +import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * 页脚配置 Mapper 接口 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +public interface SysFooterSetupMapper extends BaseMapper { + + IPage footerList(Page page, @Param("req") SuspensionBarListPagingReq sysFloatingColumnScheme); +} diff --git a/src/main/java/com/huoran/iasf/mapper/SysFooterSetupScopeOfApplicationMapper.java b/src/main/java/com/huoran/iasf/mapper/SysFooterSetupScopeOfApplicationMapper.java new file mode 100644 index 0000000..04a0282 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/SysFooterSetupScopeOfApplicationMapper.java @@ -0,0 +1,20 @@ +package com.huoran.iasf.mapper; + +import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

+ * 页脚应用范围 Mapper 接口 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +public interface SysFooterSetupScopeOfApplicationMapper extends BaseMapper { + + List checkBoundByColumnId(@Param("columnId") String columnId); +} diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupMapper.xml new file mode 100644 index 0000000..73c89f6 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupMapper.xml @@ -0,0 +1,54 @@ + + + + + + diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupScopeOfApplicationMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupScopeOfApplicationMapper.xml new file mode 100644 index 0000000..0e16bf0 --- /dev/null +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysFooterSetupScopeOfApplicationMapper.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/src/main/java/com/huoran/iasf/service/SysFooterSetupScopeOfApplicationService.java b/src/main/java/com/huoran/iasf/service/SysFooterSetupScopeOfApplicationService.java new file mode 100644 index 0000000..42b7ea5 --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/SysFooterSetupScopeOfApplicationService.java @@ -0,0 +1,17 @@ +package com.huoran.iasf.service; + +import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 页脚应用范围 服务类 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +public interface SysFooterSetupScopeOfApplicationService extends IService { + + void deleteTheRangeBasedOnTheFooterId(Integer id); +} diff --git a/src/main/java/com/huoran/iasf/service/SysFooterSetupService.java b/src/main/java/com/huoran/iasf/service/SysFooterSetupService.java new file mode 100644 index 0000000..05d8fa7 --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/SysFooterSetupService.java @@ -0,0 +1,23 @@ +package com.huoran.iasf.service; + +import com.huoran.iasf.common.utils.R; +import com.huoran.iasf.entity.SysFooterSetup; +import com.baomidou.mybatisplus.extension.service.IService; +import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; + +/** + *

+ * 页脚配置 服务类 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +public interface SysFooterSetupService extends IService { + + R footerList(SuspensionBarListPagingReq sysFloatingColumnScheme); + + R checkEnableOrDisable(Integer id, Integer isDisable); + + R showTheFooterAccordingToTheColumn(String columnId); +} diff --git a/src/main/java/com/huoran/iasf/service/impl/SysFooterSetupScopeOfApplicationServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysFooterSetupScopeOfApplicationServiceImpl.java new file mode 100644 index 0000000..1cf0262 --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/impl/SysFooterSetupScopeOfApplicationServiceImpl.java @@ -0,0 +1,28 @@ +package com.huoran.iasf.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.huoran.iasf.entity.SysFloatingColumnSchemeScopeOfApplication; +import com.huoran.iasf.entity.SysFooterSetupScopeOfApplication; +import com.huoran.iasf.mapper.SysFooterSetupScopeOfApplicationMapper; +import com.huoran.iasf.service.SysFooterSetupScopeOfApplicationService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 页脚应用范围 服务实现类 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +@Service +public class SysFooterSetupScopeOfApplicationServiceImpl extends ServiceImpl implements SysFooterSetupScopeOfApplicationService { + + @Override + public void deleteTheRangeBasedOnTheFooterId(Integer id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("footer_id", id); + this.remove(queryWrapper); + } +} diff --git a/src/main/java/com/huoran/iasf/service/impl/SysFooterSetupServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysFooterSetupServiceImpl.java new file mode 100644 index 0000000..257b3f2 --- /dev/null +++ b/src/main/java/com/huoran/iasf/service/impl/SysFooterSetupServiceImpl.java @@ -0,0 +1,202 @@ +package com.huoran.iasf.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +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.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.FooterListVO; +import com.huoran.iasf.vo.req.SuspensionBarListPagingReq; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * 页脚配置 服务实现类 + *

+ * + * @author cheney + * @since 2024-06-07 + */ +@Service +public class SysFooterSetupServiceImpl extends ServiceImpl implements SysFooterSetupService { + @Resource + private SysFooterSetupScopeOfApplicationMapper scopeOfApplicationMapper; + + @Autowired + public SysColumnMapper columnMapper; + + @Override + public R footerList(SuspensionBarListPagingReq sysFloatingColumnScheme) { + Page page = new Page(sysFloatingColumnScheme.getPageNum(), sysFloatingColumnScheme.getPageSize()); + IPage pageList = baseMapper.footerList(page, sysFloatingColumnScheme); + return R.success(pageList); + } + + @Override + public R checkEnableOrDisable(Integer id, Integer enable) { + SysFooterSetup scheme = baseMapper.selectById(id); + if (scheme == null) { + return R.fail("悬浮窗方案不存在"); + } + + Integer siteId = scheme.getSiteId(); + + // 1. 当前操作为启用时,检查逻辑 + if (enable == 0) { + // 全局悬浮栏启用逻辑 + // 对于启用操作,先检查是否是全局应用 + if (scheme.getIsGlobal() == 1) { + // 检查站点下是否存在任何已启用的悬浮栏方案,不论全局还是部分应用 + long enabledCount = baseMapper.selectCount(new LambdaQueryWrapper().eq(SysFooterSetup::getSiteId, siteId).eq(SysFooterSetup::getIsDisable, 0)); + if (enabledCount > 0) { + // 弹窗提示,表明启用新的全局悬浮栏会覆盖当前已启用的悬浮栏 + return R.warn("当前站点已存在启用的悬浮栏方案,启用新方案将会覆盖原有设置,请确认是否继续?"); + } + } else { // 非全局悬浮栏启用逻辑 + // 检查是否存在启用的全局悬浮栏 + if (existsEnabledGlobal(siteId)) { + return R.fail("当前已启用全局悬浮栏,无法直接启用部分应用的悬浮栏,请先禁用全局悬浮栏!"); + } + // 检查与其它部分应用悬浮栏的冲突 + if (hasOverlapWithOtherEnabled(id, siteId)) { + return R.fail(generateConflictMessage(id, siteId, enable)); + } + } + } else if (enable == 1) { // 禁用操作逻辑 + // 禁用操作直接允许,无需特殊检查 + } else { + return R.fail("无效的操作类型"); + } + + // 如果没有冲突,直接返回成功提示 + return R.success("操作可执行"); + } + + @Override + public R showTheFooterAccordingToTheColumn(String columnId) { + // 获取栏目信息,提前返回错误信息如果栏目不存在 + SysColumn column = columnMapper.selectById(columnId); + if (column == null) { + return R.fail("未找到该栏目"); + } + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(SysFooterSetup::getSiteId, column.getSiteId()) + .eq(SysFooterSetup::getIsDisable, 0) + .eq(SysFooterSetup::getStatus, 1); + + // 查询当前站点下已启用且已发布的悬浮栏方案 + List floatingColumnSchemeList = baseMapper.selectList(queryWrapper); + + // 检查是否存在全局启用的悬浮栏方案,存在则直接返回 + Optional globalSetupOptional = floatingColumnSchemeList.stream() + .filter(setup -> setup.getIsGlobal() == 1) + .findFirst(); + if (globalSetupOptional.isPresent()) { + return R.success(globalSetupOptional.get()); + } + + // 如果没有全局方案,检查当前栏目绑定的悬浮栏方案 + List boundSetupIds = scopeOfApplicationMapper.checkBoundByColumnId(columnId); + if (!boundSetupIds.isEmpty()) { + // 根据绑定的ID列表查询启用的悬浮栏方案 + List setupsForColumn = baseMapper.selectList( + new LambdaQueryWrapper() + .in(SysFooterSetup::getId, boundSetupIds) + .eq(SysFooterSetup::getIsDisable, 0) + ); + return R.success(setupsForColumn); + } + return R.success(Collections.emptyList()); + } + + + /** + * 检查当前悬浮栏方案与已启用方案是否有重叠。 + * + * @param id 悬浮栏方案ID + * @return 是否有重叠 + */ + private boolean hasOverlapWithOtherEnabled(Integer id, Integer siteId) { + // 获取当前要检查的方案的应用范围 + List currentScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper().eq(SysFooterSetupScopeOfApplication::getFooterId, id)); + + if (currentScopes.isEmpty()) { + return false; // 当前方案无应用范围,自然无重叠 + } + + Set currentScopeIds = currentScopes.stream().flatMap(scope -> Arrays.stream(scope.getApplicationScopeId().split(","))).map(Integer::parseInt).collect(Collectors.toSet()); + + // 构造查询条件,确保比较的方案属于同一个站点 + String sqlInCondition = "SELECT id FROM sys_footer_setup WHERE is_disable = 0 AND site_id = " + siteId; + + // 查询所有启用且ID不等于当前id且属于相同站点的悬浮栏方案的应用范围 + List enabledScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper().ne(SysFooterSetupScopeOfApplication::getFooterId, id).inSql(SysFooterSetupScopeOfApplication::getFooterId, sqlInCondition)); + + // 检查是否有重叠 + for (SysFooterSetupScopeOfApplication enabledScope : enabledScopes) { + Set enabledScopeIds = Arrays.stream(enabledScope.getApplicationScopeId().split(",")).map(Integer::parseInt).collect(Collectors.toSet()); + + if (!Collections.disjoint(currentScopeIds, enabledScopeIds)) { + return true; // 存在重叠 + } + } + + return false; // 无重叠 + } + + /** + * 生成冲突提示信息,展示冲突的栏目名称。 + * + * @param id 悬浮栏方案ID + * @return 冲突提示信息 + */ + private String generateConflictMessage(Integer id, Integer siteId, Integer enableAction) { + // 调用 hasOverlapWithOtherEnabled 确认是否有重叠 + if (!hasOverlapWithOtherEnabled(id, siteId)) { + return ""; // 无冲突则返回空字符串 + } + + // 获取当前方案冲突的范围ID + List conflictingScopes = scopeOfApplicationMapper.selectList(new LambdaQueryWrapper().eq(SysFooterSetupScopeOfApplication::getFooterId, id)); + + Set conflictScopeIds = conflictingScopes.stream().flatMap(scope -> Arrays.stream(scope.getApplicationScopeId().split(","))).map(Integer::parseInt).collect(Collectors.toSet()); + + // 查询冲突范围对应的栏目名称 + 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 if (enableAction == 1) { // 禁用操作 + return "“" + String.join("”, “", conflictingScopeNames) + "”存在悬浮栏配置冲突,请注意操作可能影响这些栏目的现有悬浮栏设置。"; + } else { + return "未知的操作类型"; + } + } + + private boolean existsEnabledGlobal(Integer siteId) { + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("is_global", 1); + queryWrapper.eq("is_disable", 0); + queryWrapper.eq("site_id", siteId); + return !baseMapper.selectList(queryWrapper).isEmpty(); + + } + +} diff --git a/src/main/java/com/huoran/iasf/vo/FooterListVO.java b/src/main/java/com/huoran/iasf/vo/FooterListVO.java new file mode 100644 index 0000000..f0c8c28 --- /dev/null +++ b/src/main/java/com/huoran/iasf/vo/FooterListVO.java @@ -0,0 +1,62 @@ +package com.huoran.iasf.vo; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + *

+ * 页脚 + *

+ * + * @author cheney + * @since 2024-06-04 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "SysFloatingColumnScheme对象", description = "页脚") +public class FooterListVO { + + + @ApiModelProperty(value = "页脚主键") + private Integer footerId; + + @ApiModelProperty(value = "页脚名称") + private String footerName; + + + @ApiModelProperty(value = "应用范围") + private String scopeOfApplication; + + @ApiModelProperty(value = "悬浮栏样式id(前端自定义1/2/3)") + private Integer floatingBarStyle; + + @ApiModelProperty(value = "模板名称") + private String templateName; + + @ApiModelProperty(value = "是否禁用(0默认,0启用 1禁用)") + private Integer isDisable; + + + @ApiModelProperty(value = "编辑人id", hidden = true) + private Integer editorId; + + @ApiModelProperty(value = "编辑人名称") + private String editorSName; + + + @ApiModelProperty(value = "创建时间") + @TableField(fill = FieldFill.INSERT) + private Date createTime; + + @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateTime; + + +} diff --git a/src/test/java/com/company/project/CodeGenerator.java b/src/test/java/com/company/project/CodeGenerator.java index fa06bd7..c5788c8 100644 --- a/src/test/java/com/company/project/CodeGenerator.java +++ b/src/test/java/com/company/project/CodeGenerator.java @@ -61,7 +61,7 @@ public class CodeGenerator { // 5、策略配置 StrategyConfig strategy = new StrategyConfig(); - strategy.setInclude("sys_floating_column_scheme","sys_floating_column_scheme_module","sys_floating_column_scheme_scope_of_application"); + strategy.setInclude("sys_footer_setup","sys_footer_setup_scope_of_application"); strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 // strategy.setTablePrefix("sys_"); //生成实体时去掉表前缀