diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpArticleController.java b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpArticleController.java index 1a66282..797f397 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpArticleController.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpArticleController.java @@ -1,6 +1,7 @@ package com.aircraft.modules.article.controller; +import cn.hutool.core.date.DateTime; import com.aircraft.modules.article.domain.CpArticle; import com.aircraft.modules.article.domain.CpLabel; import com.aircraft.modules.article.domain.CpModule; @@ -78,7 +79,7 @@ public class CpArticleController { @ApiOperation(value = "删除文章") @RequestMapping(value = "{id}", method = {RequestMethod.DELETE}) @ApiImplicitParam(name = "id", value = "文章ID", required = true, paramType = "path") - public ResponseEntity delete(@PathVariable final Long id) { + public ResponseEntity delete(@PathVariable final Long id) { try { CpArticle cpArticle = entityService.getById(id); if (cpArticle == null) { @@ -86,7 +87,10 @@ public class CpArticleController { } cpArticle.setDelFlag(1); entityService.updateDelFlagById(id, cpArticle.getDelFlag()); - return ResponseEntity.noContent().build(); + Map success = new HashMap<>(); + success.put("code", 200); + success.put("msg", "删除成功"); + return ResponseEntity.ok(success); } catch (DataIntegrityViolationException e) { LOG.error("删除文章失败: 数据完整性冲突", e); return ResponseEntity.status(HttpStatus.CONFLICT).build(); @@ -99,16 +103,24 @@ public class CpArticleController { @ApiOperation(value = "查询单个文章") @RequestMapping(value = "{id}", method = {RequestMethod.GET}) @ApiImplicitParam(name = "id", value = "文章ID", required = true, paramType = "path") - public ResponseEntity one(@PathVariable final Integer id) { + public ResponseEntity one(@PathVariable final Integer id) { try { CpArticle entity = cpArticleMapper.getArticleById(id); if (entity == null || entity.getDelFlag() == 1) { - return ResponseEntity.notFound().build(); + // 返回包含错误信息的JSON响应 + Map errorResponse = new HashMap<>(); + errorResponse.put("code", HttpStatus.NOT_FOUND.value()); + errorResponse.put("message", "不存在该文章"); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorResponse); } return ResponseEntity.ok(entity); } catch (Exception e) { LOG.error("查询单个文章失败", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + // 同样返回包含错误信息的JSON响应 + Map errorResponse = new HashMap<>(); + errorResponse.put("code", HttpStatus.INTERNAL_SERVER_ERROR.value()); + errorResponse.put("message", "查询文章失败,请稍后重试"); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); } } @@ -151,7 +163,7 @@ public class CpArticleController { CpArticle cpArticle = new CpArticle(); BeanUtils.copyProperties(cpArticleDTO, cpArticle); // 设置文章基础信息 - cpArticle.setCreateTime(Timestamp.valueOf(LocalDateTime.now())); + cpArticle.setCreateTime(LocalDateTime.now()); cpArticle.setCheckState("t");// 默认已审核 cpArticle.setDelFlag(0); cpArticle.setCplabelId(cpLabel.getId());// 关联标签ID @@ -211,7 +223,7 @@ public class CpArticleController { } // 查找标签信息 - CpLabelVo cpLabelVo = cpLabelMapper.findByName(entity.getLabelName()); + CpLabel cpLabelVo = cpLabelMapper.findById(entity.getCplabelId()); if (cpLabelVo == null) { Map error = new HashMap<>(); error.put("code", 400); @@ -227,9 +239,6 @@ public class CpArticleController { error.put("msg", "文章不存在"); return ResponseEntity.status(404).body(error); } - // 更新文章标签ID并保存 - entity.setCplabelId(cpLabelVo.getLabelId()); - entityService.updateById(entity); // 更新文章内容 if (existingArticle.getTextid() == null) { 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 0e4c450..8849a63 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 @@ -4,6 +4,7 @@ import com.aircraft.modules.article.domain.CpLabel; import com.aircraft.modules.article.domain.dto.CpLabelVo; import com.aircraft.modules.article.mapper.CpLabelMapper; import com.aircraft.modules.article.service.CpLabelService; +import com.aircraft.modules.article.service.CpModuleService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -13,6 +14,7 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpStatus; @@ -47,6 +49,8 @@ public class CpLabelController { @Autowired private CpLabelMapper cpLabelMapper; + @Autowired + private CpModuleService cpModuleService; @ApiOperation(value = "分页查询标签", notes = "分页查询标签") @RequestMapping(method = RequestMethod.GET) @@ -69,16 +73,20 @@ public class CpLabelController { @ApiOperation(value = "删除标签") @RequestMapping(value = "{id}", method = {RequestMethod.DELETE}) @ApiImplicitParam(name = "id", value = "标签ID", required = true, paramType = "path") - public ResponseEntity delete(@PathVariable final Integer id) { + public ResponseEntity delete(@PathVariable final Integer id) { try { CpLabel cpLabel = entityService.getById(id); if (cpLabel == null) { return ResponseEntity.notFound().build(); } cpLabel.setDelFlag(1); // 逻辑删除 - entityService.updateDelFlagById( id, cpLabel.getDelFlag()); -// entityService.updateById(cpLabel); - return ResponseEntity.noContent().build(); + entityService.updateDelFlagById(id, cpLabel.getDelFlag()); + // 3. 删除成功,返回成功信息 + Map success = new HashMap<>(); + 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(); @@ -106,51 +114,46 @@ 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 CpLabelVo cpLabelVo, final BindingResult result) { try { if (result.hasErrors()) { - String errorMsg = null; - for (FieldError error : result.getFieldErrors()) { - errorMsg = error.getDefaultMessage(); - break; - } - if (errorMsg == null) { - errorMsg = "参数验证失败"; - } - return ResponseEntity.badRequest().body(null); + String errorMsg = result.getFieldErrors().stream() + .map(FieldError::getDefaultMessage) + .findFirst() + .orElse("参数验证失败"); + return ResponseEntity.badRequest().body(Map.of("message", errorMsg)); } - // 检查标签名称是否已存在(同一模块下) - CpLabel existingLabel = cpLabelMapper.selectOne( - new QueryWrapper() - .eq("name", cpLabelVo.getName()) - .eq("module_id", cpLabelVo.getModuleId()) - .eq("del_flag", 0) - ); - if (existingLabel != null) { - return ResponseEntity.badRequest().body(null); + // 检查模块是否存在 + Integer moduleId = cpLabelVo.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); // 设置默认值 - cpLabelVo.setCreateTime(LocalDateTime.now()); - cpLabelVo.setDelFlag(0); + cpLabel.setCreateTime(LocalDateTime.now()); + cpLabel.setDelFlag(0); // 保存标签 - entityService.save(cpLabelVo); + entityService.save(cpLabel); // 返回201 Created状态和创建的资源 return ResponseEntity - .created(URI.create("/cpLabel/" + cpLabelVo.getId())) + .created(URI.create("/cpLabel/" + cpLabel.getId())) .body(cpLabelVo); } catch (Exception e) { LOG.error("添加标签失败", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Map.of("message", "添加标签失败,请稍后重试")); } } @ApiOperation(value = "修改标签") @RequestMapping(method = {RequestMethod.PUT}) - public ResponseEntity update(@Valid @RequestBody final CpLabelVo entity, final BindingResult result) { + public ResponseEntity update(@Valid @RequestBody final CpLabel entity, final BindingResult result) { try { // 处理参数校验错误 if (result.hasErrors()) { @@ -182,7 +185,8 @@ public class CpLabelController { entityService.updateById(entity); // 成功响应 - return ResponseEntity.ok(entity); + return ResponseEntity.ok(Map.of("code", 200, "msg", "修改标签成功")); +// return ResponseEntity.ok(entity); } catch (Exception e) { LOG.error("修改标签失败", e); @@ -204,17 +208,4 @@ public class CpLabelController { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } - - @ApiOperation(value = "根据模块查询标签树") - @RequestMapping(value = "tree/{moduleId}", method = RequestMethod.GET) - @ApiImplicitParam(name = "moduleId", value = "模块ID", required = true, paramType = "path") - public ResponseEntity> getLabelTree(@PathVariable final Integer moduleId) { - try { - List labelTree = cpLabelMapper.selectLabelTreeByModuleId(moduleId); - return ResponseEntity.ok(labelTree); - } catch (Exception e) { - LOG.error("查询标签树失败", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } } \ No newline at end of file diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpMaterialController.java b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpMaterialController.java index 6655b9d..98230c5 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpMaterialController.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpMaterialController.java @@ -1,6 +1,7 @@ package com.aircraft.modules.article.controller; import com.aircraft.modules.article.domain.CpMaterial; +import com.aircraft.modules.article.domain.dto.CpMaterialDTO; import com.aircraft.modules.article.mapper.CpMaterialMapper; import com.aircraft.modules.system.mapper.UserMapper; import com.aircraft.modules.article.service.CpMaterialService; @@ -13,6 +14,7 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpStatus; @@ -22,6 +24,8 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.net.URI; import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; import static com.aircraft.utils.SecurityUtils.getCurrentUserId; @@ -84,23 +88,25 @@ public class CpMaterialController { @ApiOperation(value = "添加素材", notes = "向cp_material表插入新素材,自动填充创建时间和创建人") @PostMapping - public ResponseEntity add(@Valid @RequestBody CpMaterial material) { + public ResponseEntity add(@Valid @RequestBody CpMaterialDTO material) { try { + CpMaterial cpMaterial=new CpMaterial(); + BeanUtils.copyProperties(material, cpMaterial); // 填充默认值 - material.setCreateTime(LocalDateTime.now()); - material.setUpdateTime(LocalDateTime.now()); - material.setDelFlag(0); // 未删除 + cpMaterial.setCreateTime(LocalDateTime.now()); + cpMaterial.setUpdateTime(LocalDateTime.now()); + cpMaterial.setDelFlag(0); // 默认未删除 // 设置创建人ID Long creatorId = getCurrentUserId(); String name = userMapper.getNameById(creatorId); - material.setCreateBy(name); // 假设表中有creator_id字段 + cpMaterial.setCreateBy(name); // 假设表中有creator_id字段 // 保存素材 - materialService.save(material); + materialService.save(cpMaterial); // 返回创建的素材(包含自增ID) return ResponseEntity - .created(URI.create("/cpMaterial/" + material.getId())) - .body(material); + .created(URI.create("/cpMaterial/" + cpMaterial.getId())) + .body(cpMaterial); } catch (DataIntegrityViolationException e) { LOG.error("添加素材失败:数据完整性冲突", e); return ResponseEntity.badRequest().build(); @@ -137,7 +143,7 @@ public class CpMaterialController { @ApiOperation(value = "删除素材", notes = "逻辑删除:将cp_material表中的del_flag设为1") @ApiImplicitParam(name = "id", value = "素材ID", required = true, paramType = "path", dataType = "int") @DeleteMapping("/{id}") - public ResponseEntity delete(@PathVariable Integer id) { + public ResponseEntity delete(@PathVariable Integer id) { try { // 检查素材是否存在 CpMaterial material = materialService.getById(id); @@ -148,7 +154,11 @@ public class CpMaterialController { // 逻辑删除:更新del_flag=1 material.setDelFlag(1); materialService.updateDelFlagById(material.getId(),material.getDelFlag()); - return ResponseEntity.noContent().build(); + // 3. 删除成功,返回成功信息 + Map success = new HashMap<>(); + success.put("code", 200); + success.put("msg", "删除成功"); + return ResponseEntity.ok(success); } catch (Exception e) { LOG.error("删除素材失败(ID:{})", id, e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpModuleController.java b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpModuleController.java index 9f58442..dac61bb 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpModuleController.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/controller/CpModuleController.java @@ -53,7 +53,7 @@ public class CpModuleController { @ApiOperation(value = "删除模块") @DeleteMapping("{id}") @ApiImplicitParam(name = "id", value = "模块ID", required = true, paramType = "path") - public ResponseEntity delete(@PathVariable final Integer id) { + public ResponseEntity delete(@PathVariable final Integer id) { try { CpModule cpModule = entityService.getById(id); if (cpModule == null) { @@ -61,7 +61,11 @@ public class CpModuleController { } cpModule.setDelFlag(1); // 逻辑删除 entityService.updateDelFlagById(id, cpModule.getDelFlag()); - return ResponseEntity.noContent().build(); + // 3. 删除成功,返回成功信息 + Map success = new HashMap<>(); + success.put("code", 200); + success.put("msg", "删除成功"); + return ResponseEntity.ok(success); } catch (DataIntegrityViolationException e) { LOG.error("删除模块失败: 数据完整性冲突", e); return ResponseEntity.status(HttpStatus.CONFLICT).build(); diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpArticle.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpArticle.java index 3c33338..2c87533 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpArticle.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpArticle.java @@ -1,14 +1,14 @@ package com.aircraft.modules.article.domain; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.annotation.IdType; +import cn.hutool.core.date.DateTime; +import com.baomidou.mybatisplus.annotation.*; import com.aircraft.base.BaseEntity; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import java.sql.Timestamp; import java.time.LocalDateTime; /** @@ -21,7 +21,7 @@ import java.time.LocalDateTime; */ @Data @TableName("cp_article") -public class CpArticle extends BaseEntity { +public class CpArticle { private static final long serialVersionUID = 1L; @@ -50,10 +50,19 @@ public class CpArticle extends BaseEntity { @ApiModelProperty(value = "是否置顶:1-置顶,0-不置顶") private Integer top; + @ApiModelProperty(value = "创建时间") + private LocalDateTime createTime; + + @ApiModelProperty(value = "更新时间") + private LocalDateTime updateTime; + @ApiModelProperty(value = "发布者id(用户表或管理员表由发布者类型决定)") private Long authorId; @ApiModelProperty(value = "审核状态:t-审核通过,f-不通过,w-未审核") private String checkState = "t"; + @ApiModelProperty(value = "逻辑删除:1-删除,0-正常") + private Integer delFlag; + } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpLabel.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpLabel.java index e11b31f..408fa88 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpLabel.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpLabel.java @@ -36,7 +36,10 @@ public class CpLabel { private Integer level; @ApiModelProperty(value = "父节点id") - private Integer parentId; + private Integer parentId=null; + + @ApiModelProperty(value = "子节点id") + private Integer childrenId=null; @ApiModelProperty(value = "标签备注") private String remark; diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpMaterial.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpMaterial.java index 40e3f1c..917dfcd 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpMaterial.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/CpMaterial.java @@ -57,5 +57,4 @@ public class CpMaterial { @ApiModelProperty(value = "删除标记:“1”已删除,“0”正常") private Integer delFlag; - } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleDTO.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleDTO.java index 0e7e786..6a766b9 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleDTO.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleDTO.java @@ -19,7 +19,6 @@ public class CpArticleDTO { @ApiModelProperty(value = "文章外链") private String url; - @NotBlank(message = "标签id不能为空") @ApiModelProperty(value = "标签ID", required = true) private int labelId; diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleVo.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleVo.java index d54a590..1645fb7 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleVo.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpArticleVo.java @@ -9,12 +9,6 @@ import lombok.Data; @ApiModel public class CpArticleVo extends CpArticle { - @ApiModelProperty("模块") - private String moduleName; - - @ApiModelProperty("标签") - private String labelName; - @ApiModelProperty("内容") private String text; 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 47caff5..c9d0eca 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 @@ -9,19 +9,25 @@ import java.util.List; @Data @ApiModel -public class CpLabelVo extends CpLabel { +public class CpLabelVo { - @ApiModelProperty("模块") - private String moduleName; + @ApiModelProperty("模块id") + private Integer moduleId; @ApiModelProperty("标签") - private String labelName; + private String name; @ApiModelProperty("标签id") - private Integer labelId; + private Integer id; - @ApiModelProperty("父标签名称") - private String parentName; + @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/CpMaterialDTO.java b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpMaterialDTO.java new file mode 100644 index 0000000..99cd8ff --- /dev/null +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/domain/dto/CpMaterialDTO.java @@ -0,0 +1,23 @@ +package com.aircraft.modules.article.domain.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class CpMaterialDTO { + @ApiModelProperty(value = "素材名称") + private String name; + + @ApiModelProperty(value = "素材类型:1-轮播图,2-宣传视频") + private Integer type; + + @ApiModelProperty(value = "素材存储路径") + private String path; + + @ApiModelProperty(value = "链接地址") + private String url; + + @ApiModelProperty(value = "排序号") + private Integer orderNum; + +} 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 2f2633f..923be42 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 @@ -21,10 +21,10 @@ public interface CpLabelMapper extends BaseMapper { @Select("SELECT * FROM cp_label WHERE name = #{labelName}") CpLabelVo findByName(String labelName); - List selectLabelTreeByModuleId(Integer moduleId); + List selectLabelTreeByModuleId(Integer moduleId); void updateDelFlagById(Integer id, Integer delFlag); @Select("SELECT * FROM cp_label WHERE id = #{labelId}") - CpLabelVo findById(int labelId); + CpLabel findById(int labelId); } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpModuleMapper.java b/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpModuleMapper.java index 862b1fe..79bfd95 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpModuleMapper.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/mapper/CpModuleMapper.java @@ -1,8 +1,10 @@ package com.aircraft.modules.article.mapper; import com.aircraft.modules.article.domain.CpModule; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; /** *

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 1b919aa..f805e13 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 @@ -15,12 +15,6 @@ import java.util.List; * @since 2025-07-10 */ public interface CpLabelService extends IService { - /** - * 根据模块ID查询标签树 - * @param moduleId 模块ID - * @return 标签树结构 - */ - List getLabelTreeByModuleId(Integer moduleId); /** * 检查标签名称在模块内是否唯一 diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpModuleService.java b/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpModuleService.java index 3b8f432..e0aec8f 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpModuleService.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/service/CpModuleService.java @@ -14,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService; public interface CpModuleService extends IService { void updateDelFlagById(Integer id, Integer delFlag); + + boolean existsById(Integer moduleId); } 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 1aa07fe..4d04db1 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 @@ -23,38 +23,6 @@ import java.util.Map; */ @Service public class CpLabelServiceImpl extends ServiceImpl implements CpLabelService { - @Override - public List getLabelTreeByModuleId(Integer moduleId) { - // 查询该模块下的所有标签 - List allLabels = baseMapper.selectLabelTreeByModuleId(moduleId); - - // 构建树结构 - Map map = new HashMap<>(); - List rootLabels = new ArrayList<>(); - - // 先将所有节点放入Map中以便快速查找 - for (CpLabelVo label : allLabels) { - map.put(label.getId(), label); - } - - // 构建父子关系 - for (CpLabelVo label : allLabels) { - Integer parentId = label.getParentId(); - if (parentId == null || parentId == 0) { - rootLabels.add(label); // 根节点 - } else { - CpLabelVo parent = map.get(parentId); - if (parent != null) { - if (parent.getChildren() == null) { - parent.setChildren(new ArrayList<>()); - } - parent.getChildren().add(label); - } - } - } - - return rootLabels; - } @Override public boolean isLabelNameUnique(Integer moduleId, String labelName, Integer excludeId) { diff --git a/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpModuleServiceImpl.java b/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpModuleServiceImpl.java index c407be9..aa2f8f0 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpModuleServiceImpl.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/article/service/impl/CpModuleServiceImpl.java @@ -3,7 +3,10 @@ package com.aircraft.modules.article.service.impl; import com.aircraft.modules.article.domain.CpModule; import com.aircraft.modules.article.mapper.CpModuleMapper; import com.aircraft.modules.article.service.CpModuleService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -16,9 +19,25 @@ import org.springframework.stereotype.Service; */ @Service public class CpModuleServiceImpl extends ServiceImpl implements CpModuleService { + @Autowired + private CpModuleMapper moduleMapper; @Override public void updateDelFlagById(Integer id, Integer delFlag) { baseMapper.updateDelFlagById(id, delFlag); } + + @Override + public boolean existsById(Integer moduleId) { + if (moduleId == null) { + return false; + } + + // 使用LambdaQueryWrapper,类型安全且自动处理参数 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(CpModule::getId, moduleId) + .eq(CpModule::getDelFlag, 0); + + return moduleMapper.selectCount(queryWrapper) > 0; + } } diff --git a/aircraft-system/src/main/java/com/aircraft/modules/route/controller/CpRouteController.java b/aircraft-system/src/main/java/com/aircraft/modules/route/controller/CpRouteController.java index a978219..d9fcf00 100644 --- a/aircraft-system/src/main/java/com/aircraft/modules/route/controller/CpRouteController.java +++ b/aircraft-system/src/main/java/com/aircraft/modules/route/controller/CpRouteController.java @@ -1,7 +1,7 @@ package com.aircraft.modules.route.controller; import com.aircraft.modules.route.domain.CpRoute; -import com.aircraft.modules.route.domain.dto.CpRouteVo; +import com.aircraft.modules.route.domain.dto.CpRouteDTO; import com.aircraft.modules.route.mapper.CpRouteMapper; import com.aircraft.modules.system.mapper.UserMapper; import com.aircraft.modules.route.service.CpRouteService; @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpStatus; @@ -108,7 +109,7 @@ public class CpRouteController { @ApiOperation(value = "添加路线") @RequestMapping(method = {RequestMethod.POST}) - public ResponseEntity add(@Valid @RequestBody final CpRouteVo cpRouteVo, final BindingResult result) { + public ResponseEntity add(@Valid @RequestBody final CpRouteDTO cpRouteDTO, final BindingResult result) { try { // 处理参数校验错误 if (result.hasErrors()) { @@ -125,25 +126,26 @@ public class CpRouteController { error.put("msg", errorMsg); return ResponseEntity.badRequest().body(error); } - + CpRoute cpRoute = new CpRoute(); + BeanUtils.copyProperties(cpRouteDTO, cpRoute); // 设置路线基础信息 - cpRouteVo.setCreateTime(LocalDateTime.now()); - cpRouteVo.setDelFlag(0); + cpRoute.setCreateTime(LocalDateTime.now()); + cpRoute.setDelFlag(0); Long creatorId = getCurrentUserId(); String createBy = userMapper.getNameById(creatorId);//创建人的名 - cpRouteVo.setCreateBy(createBy); + cpRoute.setCreateBy(createBy); // 保存路线主信息 - entityService.save(cpRouteVo); + entityService.save(cpRoute); // 返回创建成功的响应 Map success = new HashMap<>(); success.put("code", 201); success.put("msg", "路线创建成功"); // 调整响应描述 - success.put("data", cpRouteVo); + success.put("data", cpRoute); return ResponseEntity - .created(URI.create("/cpRoute/" + cpRouteVo.getId())) // 调整路径 + .created(URI.create("/cpRoute/" + cpRoute.getId())) // 调整路径 .body(success); } catch (Exception e) { LOG.error("添加路线失败", e); // 调整日志描述 @@ -156,7 +158,7 @@ public class CpRouteController { @ApiOperation(value = "修改路线") // 调整接口描述 @RequestMapping(method = {RequestMethod.PUT}) - public ResponseEntity update(@Valid @RequestBody final CpRouteVo entity, final BindingResult result) { + public ResponseEntity update(@Valid @RequestBody final CpRoute entity, final BindingResult result) { try { if (result.hasErrors()) { Map error = new HashMap<>(); @@ -183,7 +185,10 @@ public class CpRouteController { return ResponseEntity.status(404).body(error); } entityService.updateById(entity); - return ResponseEntity.ok(entity); + Map success = new HashMap<>(); + success.put("code", 200); + success.put("msg", "删除成功"); + return ResponseEntity.ok(success); } catch (Exception e) { LOG.error("修改路线失败", e); // 调整日志描述 diff --git a/aircraft-system/src/main/java/com/aircraft/modules/route/domain/dto/CpRouteDTO.java b/aircraft-system/src/main/java/com/aircraft/modules/route/domain/dto/CpRouteDTO.java new file mode 100644 index 0000000..0ffa62a --- /dev/null +++ b/aircraft-system/src/main/java/com/aircraft/modules/route/domain/dto/CpRouteDTO.java @@ -0,0 +1,43 @@ +package com.aircraft.modules.route.domain.dto; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +@Data +public class CpRouteDTO { + @ApiModelProperty(value = "路线名称") + private String name; + + @ApiModelProperty(value = "区域id,关联区域表id") + private Long areaId; + + @ApiModelProperty(value = "景区id,关联景区表id") + private Long scenicId; + + @ApiModelProperty(value = "起点,手动存储经纬度,不调用地图") + private String startPoint; + + @ApiModelProperty(value = "终点") + private String endPoint; + + @ApiModelProperty(value = "价格") + private BigDecimal price; + + @ApiModelProperty(value = "文章链接") + private String link; + + @ApiModelProperty(value = "跳转地址") + private String url; + + @ApiModelProperty(value = "封面图存储路径") + private String imgPath; + + @ApiModelProperty(value = "排序号") + private Integer orderNum; + + @ApiModelProperty(value = "是否展示在用户列表:“1”展示,“0”不展示") + @TableField("`show`") + private String show; +} diff --git a/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml b/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml index c479b92..1f346a2 100644 --- a/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml +++ b/aircraft-system/src/main/resources/mapper/article/CpLabelMapper.xml @@ -1,23 +1,6 @@ - - - -