From 593c534cfc68cec9beb933ff754e28b675b50295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E6=96=87=E9=9D=99WWW?= <15144434+wen-wenjing-www@user.noreply.gitee.com> Date: Fri, 18 Jul 2025 15:18:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=AE=A1=E7=90=86=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../article/controller/CpLabelController.java | 23 +++++++------ .../article/domain/dto/CpLabelDTO.java | 33 +++++++++++++++++++ .../modules/article/domain/dto/CpLabelVo.java | 29 ++-------------- .../modules/article/mapper/CpLabelMapper.java | 7 +++- .../article/service/CpLabelService.java | 16 +++------ .../service/impl/CpLabelServiceImpl.java | 27 +++++++-------- .../mapper/article/CpLabelMapper.xml | 14 ++++++++ 7 files changed, 82 insertions(+), 67 deletions(-) create mode 100644 aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelDTO.java diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpLabelController.java b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpLabelController.java index 8849a63..5690fe6 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpLabelController.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpLabelController.java @@ -1,6 +1,7 @@ package com.aircraft.modules.article.controller; import com.aircraft.modules.article.domain.CpLabel; +import com.aircraft.modules.article.domain.dto.CpLabelDTO; import com.aircraft.modules.article.domain.dto.CpLabelVo; import com.aircraft.modules.article.mapper.CpLabelMapper; import com.aircraft.modules.article.service.CpLabelService; @@ -52,17 +53,16 @@ public class CpLabelController { @Autowired private CpModuleService cpModuleService; - @ApiOperation(value = "分页查询标签", notes = "分页查询标签") + @ApiOperation(value = "分页查询标签(name模糊查询)", notes = "分页查询标签") @RequestMapping(method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "size", value = "分页大小", paramType = "query"), - @ApiImplicitParam(name = "current", value = "当前页面:从1开始", paramType = "query") + @ApiImplicitParam(name = "current", value = "当前页面:从1开始", paramType = "query"), + @ApiImplicitParam(name = "name", value = "name进行模糊查询", paramType = "query") }) - public ResponseEntity> findByPage(final CpLabel example, final Page page) { + public ResponseEntity> findByPage(final Page page, @RequestParam(required = false) String name) { try { - QueryWrapper wrapper = new QueryWrapper<>(example); - // 正确调用page方法:(分页对象, 查询条件) - IPage records = entityService.page(page, wrapper); + IPage records = entityService.findByPage(page, name); return new ResponseEntity<>(records, HttpStatus.OK); } catch (Exception e) { LOG.error("分页查询标签时出错", e); @@ -86,7 +86,6 @@ public class CpLabelController { success.put("code", 200); success.put("msg", "删除成功"); return ResponseEntity.ok(success); -// return ResponseEntity.noContent().build(); } catch (DataIntegrityViolationException e) { LOG.error("删除标签失败: 数据完整性冲突", e); return ResponseEntity.status(HttpStatus.CONFLICT).build(); @@ -114,7 +113,7 @@ public class CpLabelController { @ApiOperation(value = "添加标签") @RequestMapping(method = {RequestMethod.POST}) - public ResponseEntity add(@Valid @RequestBody final CpLabelVo cpLabelVo, final BindingResult result) { + public ResponseEntity add(@Valid @RequestBody final CpLabelDTO cpLabelDTO, final BindingResult result) { try { if (result.hasErrors()) { String errorMsg = result.getFieldErrors().stream() @@ -125,14 +124,14 @@ public class CpLabelController { } // 检查模块是否存在 - Integer moduleId = cpLabelVo.getModuleId(); + Integer moduleId = cpLabelDTO.getModuleId(); if (moduleId == null || !cpModuleService.existsById(moduleId)) { return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(Map.of("message", "不存在该模块")); } CpLabel cpLabel = new CpLabel(); - BeanUtils.copyProperties(cpLabelVo, cpLabel); + BeanUtils.copyProperties(cpLabelDTO, cpLabel); // 设置默认值 cpLabel.setCreateTime(LocalDateTime.now()); cpLabel.setDelFlag(0); @@ -143,7 +142,7 @@ public class CpLabelController { // 返回201 Created状态和创建的资源 return ResponseEntity .created(URI.create("/cpLabel/" + cpLabel.getId())) - .body(cpLabelVo); + .body(cpLabelDTO); } catch (Exception e) { LOG.error("添加标签失败", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) @@ -185,7 +184,7 @@ public class CpLabelController { entityService.updateById(entity); // 成功响应 - return ResponseEntity.ok(Map.of("code", 200, "msg", "修改标签成功")); + return ResponseEntity.ok(Map.of("code", 200, "msg", "修改标签成功")); // return ResponseEntity.ok(entity); } catch (Exception e) { diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelDTO.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelDTO.java new file mode 100644 index 0000000..4472683 --- /dev/null +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelDTO.java @@ -0,0 +1,33 @@ +package com.aircraft.modules.article.domain.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +@ApiModel +public class CpLabelDTO { + + @ApiModelProperty("模块id") + private Integer moduleId; + + @ApiModelProperty("标签") + private String name; + + @ApiModelProperty("标签id") + private Integer id; + + @ApiModelProperty(value = "标签备注") + private String remark; + + @ApiModelProperty(value = "排序号") + private Integer orderNum; + + @ApiModelProperty("父标签名称,可为null") + private Integer parentId; + + @ApiModelProperty("子标签列表") + private List children; +} diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelVo.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelVo.java index c9d0eca..404389b 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelVo.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpLabelVo.java @@ -1,34 +1,9 @@ package com.aircraft.modules.article.domain.dto; import com.aircraft.modules.article.domain.CpLabel; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import java.util.List; - @Data -@ApiModel -public class CpLabelVo { - - @ApiModelProperty("模块id") - private Integer moduleId; - - @ApiModelProperty("标签") - private String name; - - @ApiModelProperty("标签id") - private Integer id; - - @ApiModelProperty(value = "标签备注") - private String remark; - - @ApiModelProperty(value = "排序号") - private Integer orderNum; - - @ApiModelProperty("父标签名称,可为null") - private Integer parentId; - - @ApiModelProperty("子标签列表") - private List children; +public class CpLabelVo extends CpLabel { + private String moduleName;//模块名 } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpLabelMapper.java b/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpLabelMapper.java index 923be42..b6c099e 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpLabelMapper.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpLabelMapper.java @@ -1,8 +1,11 @@ package com.aircraft.modules.article.mapper; import com.aircraft.modules.article.domain.CpLabel; +import com.aircraft.modules.article.domain.dto.CpLabelDTO; import com.aircraft.modules.article.domain.dto.CpLabelVo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @@ -19,7 +22,7 @@ import java.util.List; @Mapper public interface CpLabelMapper extends BaseMapper { @Select("SELECT * FROM cp_label WHERE name = #{labelName}") - CpLabelVo findByName(String labelName); + CpLabelDTO findByName(String labelName); List selectLabelTreeByModuleId(Integer moduleId); @@ -27,4 +30,6 @@ public interface CpLabelMapper extends BaseMapper { @Select("SELECT * FROM cp_label WHERE id = #{labelId}") CpLabel findById(int labelId); + + IPage selectVoPage(Page page, String name); } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpLabelService.java b/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpLabelService.java index f805e13..b8c7546 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpLabelService.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpLabelService.java @@ -2,10 +2,10 @@ package com.aircraft.modules.article.service; import com.aircraft.modules.article.domain.CpLabel; import com.aircraft.modules.article.domain.dto.CpLabelVo; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; -import java.util.List; - /** *

* 标签表 服务类 @@ -15,15 +15,7 @@ import java.util.List; * @since 2025-07-10 */ public interface CpLabelService extends IService { - - /** - * 检查标签名称在模块内是否唯一 - * @param moduleId 模块ID - * @param labelName 标签名称 - * @param excludeId 排除的标签ID(更新时使用) - * @return 是否唯一 - */ - boolean isLabelNameUnique(Integer moduleId, String labelName, Integer excludeId); - void updateDelFlagById(Integer id, Integer delFlag); + + IPage findByPage(Page page, String name); } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpLabelServiceImpl.java b/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpLabelServiceImpl.java index 4d04db1..58d1f83 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpLabelServiceImpl.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpLabelServiceImpl.java @@ -1,18 +1,17 @@ package com.aircraft.modules.article.service.impl; import com.aircraft.modules.article.domain.CpLabel; +import com.aircraft.modules.article.domain.dto.CpArticleVo; import com.aircraft.modules.article.domain.dto.CpLabelVo; import com.aircraft.modules.article.mapper.CpLabelMapper; import com.aircraft.modules.article.service.CpLabelService; 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 org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** *

* 标签表 服务实现类 @@ -23,19 +22,17 @@ import java.util.Map; */ @Service public class CpLabelServiceImpl extends ServiceImpl implements CpLabelService { - - @Override - public boolean isLabelNameUnique(Integer moduleId, String labelName, Integer excludeId) { - CpLabel label = baseMapper.selectOne(new QueryWrapper() - .eq("module_id", moduleId) - .eq("name", labelName) - .eq("del_flag", 0) - .ne(excludeId != null, "id", excludeId)); - return label == null; - } + @Autowired + private CpLabelMapper cpLabelMapper; @Override public void updateDelFlagById(Integer id, Integer delFlag) { baseMapper.updateDelFlagById(id, delFlag); } + + @Override + public IPage findByPage(Page page, String name) { + IPage cpLabelVoIPage = cpLabelMapper.selectVoPage(page, name); + return cpLabelVoIPage; + } } diff --git a/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml b/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml index 1f346a2..746bfc5 100644 --- a/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml +++ b/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml @@ -14,4 +14,18 @@ WHERE id = #{id} AND del_flag = 0 + +