diff --git a/src/main/java/com/huoran/iasf/controller/SysNavigationIconController.java b/src/main/java/com/huoran/iasf/controller/SysNavigationIconController.java index f5e8683..64679ab 100644 --- a/src/main/java/com/huoran/iasf/controller/SysNavigationIconController.java +++ b/src/main/java/com/huoran/iasf/controller/SysNavigationIconController.java @@ -1,5 +1,6 @@ package com.huoran.iasf.controller; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.huoran.iasf.common.utils.R; import com.huoran.iasf.entity.SysNavigationIcon; import com.huoran.iasf.service.SysNavigationIconService; @@ -10,6 +11,7 @@ import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; import java.util.List; /** @@ -26,6 +28,22 @@ public class SysNavigationIconController { public SysNavigationIconService service; + @PostMapping("/checkIfTheTitleIsRepeat") + @ApiOperation(value = "标题判重——适用于新增、编辑及发布前的校验", response = Boolean.class) + public R checkIfTheTitleIsRepeat(@RequestBody @Valid SysNavigationIcon icon) { + boolean isDuplicate = false; + + // 如果ID不为空,说明是编辑操作,需要排除当前记录自身 + if (icon.getId() != null) { + isDuplicate = service.existsOtherByTitle(icon.getTitle(), icon.getId(), icon.getSiteId()); + } else { + // ID为空,说明是新增操作 + isDuplicate = service.existsByTitle(icon.getTitle(), icon.getSiteId()); + } + + return R.result(!isDuplicate, !isDuplicate ? "标题可用" : "该标题已重复!"); + } + /** * 保存或更新导航图标设置记录 * 如果ID为空,则执行保存操作;如果ID有值,则视为更新操作。 @@ -61,8 +79,9 @@ public class SysNavigationIconController { @PostMapping("/list") @ApiOperation(value = "根据站点ID查询列表数据,可选过滤禁用状态", response = SysNavigationIcon.class, responseContainer = "List") - public R listSysNavigationIconsByCondition(@ApiParam(value = "站点ID", required = true) @RequestParam Integer siteId, @ApiParam(value = "禁用状态:0-启用,1-禁用,默认查询所有状态") @RequestParam(required = false) Integer isDisable) { - List sysNavigationIcons = service.listBySiteIdAndStatus(siteId, isDisable); + public R listSysNavigationIconsByCondition(@ApiParam(value = "站点ID", required = true) @RequestParam Integer siteId, @ApiParam(value = "禁用状态:0-启用,1-禁用,默认查询所有状态") @RequestParam(required = false) Integer isDisable, + @ApiParam(value = "查询关键词") @RequestParam(required = false) String search) { + List sysNavigationIcons = service.listBySiteIdAndStatus(siteId, isDisable,search); return R.success(sysNavigationIcons); } @@ -81,5 +100,16 @@ public class SysNavigationIconController { boolean delState = service.removeByIds(ids); return delState ? R.success() : R.fail("删除失败"); } + + + @PostMapping("/enableDisable") + @ApiOperation(value = "启用禁用", response = SysNavigationIcon.class) + public R enableDisable(@ApiParam(name = "id", value = "主键id", required = true) @RequestParam Integer id, @ApiParam(name = "isDisable", value = "是否禁用:0-启用,1-禁用", required = true) @RequestParam Integer isDisable) { + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.set("is_disable", isDisable); + updateWrapper.eq("id", id); + boolean ret = service.update(updateWrapper); + return ret ? R.success() : R.fail("禁用/启用失败"); + } } diff --git a/src/main/java/com/huoran/iasf/entity/SysNavigationIcon.java b/src/main/java/com/huoran/iasf/entity/SysNavigationIcon.java index 433cc95..62b325b 100644 --- a/src/main/java/com/huoran/iasf/entity/SysNavigationIcon.java +++ b/src/main/java/com/huoran/iasf/entity/SysNavigationIcon.java @@ -85,5 +85,6 @@ public class SysNavigationIcon implements Serializable { @ApiModelProperty(value = "排序顺序") private Integer sortOrder; - + @ApiModelProperty(value = "编辑人姓名") + private String editorSName; } diff --git a/src/main/java/com/huoran/iasf/mapper/SysNavigationIconMapper.java b/src/main/java/com/huoran/iasf/mapper/SysNavigationIconMapper.java index 03c077a..399ec6f 100644 --- a/src/main/java/com/huoran/iasf/mapper/SysNavigationIconMapper.java +++ b/src/main/java/com/huoran/iasf/mapper/SysNavigationIconMapper.java @@ -1,10 +1,12 @@ package com.huoran.iasf.mapper; -import com.huoran.iasf.entity.SysNavigationIcon; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.huoran.iasf.entity.SysNavigationIcon; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Update; +import java.util.List; + /** *

* 导航图标设置 Mapper 接口 @@ -18,4 +20,9 @@ public interface SysNavigationIconMapper extends BaseMapper { @Update("UPDATE sys_navigation_icon SET sort_order = #{sortOrder} WHERE id = #{id}") void updateSortOrder(@Param("id") Integer id, @Param("sortOrder") Integer sortOrder); + List listBySiteIdAndStatus(@Param("siteId") Integer siteId, + @Param("isDisable") Integer disableStatus, + @Param("search") String search); + + } diff --git a/src/main/java/com/huoran/iasf/mapper/xml/SysNavigationIconMapper.xml b/src/main/java/com/huoran/iasf/mapper/xml/SysNavigationIconMapper.xml index a37e1a7..477f3b1 100644 --- a/src/main/java/com/huoran/iasf/mapper/xml/SysNavigationIconMapper.xml +++ b/src/main/java/com/huoran/iasf/mapper/xml/SysNavigationIconMapper.xml @@ -2,4 +2,23 @@ + + + diff --git a/src/main/java/com/huoran/iasf/service/SysNavigationIconService.java b/src/main/java/com/huoran/iasf/service/SysNavigationIconService.java index da4c2c3..ef121e7 100644 --- a/src/main/java/com/huoran/iasf/service/SysNavigationIconService.java +++ b/src/main/java/com/huoran/iasf/service/SysNavigationIconService.java @@ -15,8 +15,12 @@ import java.util.List; * @since 2024-07-04 */ public interface SysNavigationIconService extends IService { - List listBySiteIdAndStatus(Integer siteId, Integer disableStatus); + List listBySiteIdAndStatus(Integer siteId, Integer disableStatus,String search); void batchUpdateSortOrder(List sortOrderRequests); + + boolean existsOtherByTitle(String title, Integer id, Integer siteId); + + boolean existsByTitle(String title, Integer siteId); } diff --git a/src/main/java/com/huoran/iasf/service/impl/SysNavigationIconServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/SysNavigationIconServiceImpl.java index d5def9f..4694ef6 100644 --- a/src/main/java/com/huoran/iasf/service/impl/SysNavigationIconServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/SysNavigationIconServiceImpl.java @@ -1,10 +1,10 @@ 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.SysNavigationIcon; import com.huoran.iasf.mapper.SysNavigationIconMapper; import com.huoran.iasf.service.SysNavigationIconService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.huoran.iasf.vo.req.SortOrderReq; import org.springframework.stereotype.Service; @@ -22,13 +22,9 @@ import java.util.List; public class SysNavigationIconServiceImpl extends ServiceImpl implements SysNavigationIconService { @Override - public List listBySiteIdAndStatus(Integer siteId, Integer disableStatus) { - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("site_id", siteId); - if (disableStatus != null) { - queryWrapper.eq("disable_status", disableStatus); - } - return this.list(queryWrapper); + public List listBySiteIdAndStatus(Integer siteId, Integer disableStatus,String search) { + return baseMapper.listBySiteIdAndStatus(siteId, disableStatus,search); + } @Override @@ -38,4 +34,20 @@ public class SysNavigationIconServiceImpl extends ServiceImpl().eq("title", title).ne("id", id).eq("site_id", siteId)) > 0) { + return true; + } + return false; + } + + @Override + public boolean existsByTitle(String title, Integer siteId) { + if (this.count(new QueryWrapper().eq("title", title).eq("site_id", siteId)) > 0) { + return true; + } + return false; + } }