修改文章素材等的传参

This commit is contained in:
温文静WWW 2025-07-15 17:09:18 +08:00
parent a8175c6883
commit c010ae8b98
21 changed files with 219 additions and 156 deletions

View File

@ -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<Void> 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<String, Object> 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<CpArticle> 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<String, Object> 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<String, Object> 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<String, Object> 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) {

View File

@ -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,7 +73,7 @@ public class CpLabelController {
@ApiOperation(value = "删除标签")
@RequestMapping(value = "{id}", method = {RequestMethod.DELETE})
@ApiImplicitParam(name = "id", value = "标签ID", required = true, paramType = "path")
public ResponseEntity<Void> delete(@PathVariable final Integer id) {
public ResponseEntity<?> delete(@PathVariable final Integer id) {
try {
CpLabel cpLabel = entityService.getById(id);
if (cpLabel == null) {
@ -77,8 +81,12 @@ public class CpLabelController {
}
cpLabel.setDelFlag(1); // 逻辑删除
entityService.updateDelFlagById(id, cpLabel.getDelFlag());
// entityService.updateById(cpLabel);
return ResponseEntity.noContent().build();
// 3. 删除成功返回成功信息
Map<String, Object> 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<CpLabelVo> 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<CpLabel>()
.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<List<CpLabelVo>> getLabelTree(@PathVariable final Integer moduleId) {
try {
List<CpLabelVo> labelTree = cpLabelMapper.selectLabelTreeByModuleId(moduleId);
return ResponseEntity.ok(labelTree);
} catch (Exception e) {
LOG.error("查询标签树失败", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}

View File

@ -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<CpMaterial> add(@Valid @RequestBody CpMaterial material) {
public ResponseEntity<CpMaterial> 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<Void> 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<String, Object> 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();

View File

@ -53,7 +53,7 @@ public class CpModuleController {
@ApiOperation(value = "删除模块")
@DeleteMapping("{id}")
@ApiImplicitParam(name = "id", value = "模块ID", required = true, paramType = "path")
public ResponseEntity<Void> 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<String, Object> 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();

View File

@ -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;
}

View File

@ -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;

View File

@ -57,5 +57,4 @@ public class CpMaterial {
@ApiModelProperty(value = "删除标记“1”已删除“0”正常")
private Integer delFlag;
}

View File

@ -19,7 +19,6 @@ public class CpArticleDTO {
@ApiModelProperty(value = "文章外链")
private String url;
@NotBlank(message = "标签id不能为空")
@ApiModelProperty(value = "标签ID", required = true)
private int labelId;

View File

@ -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;

View File

@ -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<CpLabelVo> children;

View File

@ -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;
}

View File

@ -21,10 +21,10 @@ public interface CpLabelMapper extends BaseMapper<CpLabel> {
@Select("SELECT * FROM cp_label WHERE name = #{labelName}")
CpLabelVo findByName(String labelName);
List<CpLabelVo> selectLabelTreeByModuleId(Integer moduleId);
List<CpLabel> 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);
}

View File

@ -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;
/**
* <p>

View File

@ -15,12 +15,6 @@ import java.util.List;
* @since 2025-07-10
*/
public interface CpLabelService extends IService<CpLabel> {
/**
* 根据模块ID查询标签树
* @param moduleId 模块ID
* @return 标签树结构
*/
List<CpLabelVo> getLabelTreeByModuleId(Integer moduleId);
/**
* 检查标签名称在模块内是否唯一

View File

@ -14,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface CpModuleService extends IService<CpModule> {
void updateDelFlagById(Integer id, Integer delFlag);
boolean existsById(Integer moduleId);
}

View File

@ -23,38 +23,6 @@ import java.util.Map;
*/
@Service
public class CpLabelServiceImpl extends ServiceImpl<CpLabelMapper, CpLabel> implements CpLabelService {
@Override
public List<CpLabelVo> getLabelTreeByModuleId(Integer moduleId) {
// 查询该模块下的所有标签
List<CpLabelVo> allLabels = baseMapper.selectLabelTreeByModuleId(moduleId);
// 构建树结构
Map<Integer, CpLabelVo> map = new HashMap<>();
List<CpLabelVo> 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) {

View File

@ -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<CpModuleMapper, CpModule> 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<CpModule> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CpModule::getId, moduleId)
.eq(CpModule::getDelFlag, 0);
return moduleMapper.selectCount(queryWrapper) > 0;
}
}

View File

@ -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<String, Object> 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<String, Object> error = new HashMap<>();
@ -183,7 +185,10 @@ public class CpRouteController {
return ResponseEntity.status(404).body(error);
}
entityService.updateById(entity);
return ResponseEntity.ok(entity);
Map<String, Object> success = new HashMap<>();
success.put("code", 200);
success.put("msg", "删除成功");
return ResponseEntity.ok(success);
} catch (Exception e) {
LOG.error("修改路线失败", e); // 调整日志描述

View File

@ -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;
}

View File

@ -1,23 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aircraft.modules.article.mapper.CpLabelMapper">
<!-- 查询标签树(扁平结构) -->
<select id="selectLabelTreeByModuleId" resultType="com.aircraft.modules.article.domain.dto.CpLabelVo">
SELECT
l.id,
l.name,
l.level,
l.parent_id AS parentId,
l.module_id AS moduleId,
m.module_name AS moduleName
FROM cp_label l
LEFT JOIN cp_module m ON l.module_id = m.id
WHERE l.module_id = #{moduleId}
AND l.del_flag = 0
ORDER BY l.parent_id, l.order_num
</select>
<!-- 查询子标签 -->
<select id="selectChildrenByParentId" resultType="com.aircraft.modules.article.domain.CpLabel">
SELECT * FROM cp_label

View File

@ -6,7 +6,7 @@
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="order_id" property="orderId" jdbcType="BIGINT"/>
<result column="device_id" property="deviceId" jdbcType="BIGINT"/>
<result column="routeId" property="routeId" jdbcType="BIGINT"/>
<result column="route_id" property="routeId" jdbcType="BIGINT"/>
<result column="cargo_weight" property="cargoWeight" jdbcType="DECIMAL"/>
<result column="person_count" property="personCount" jdbcType="VARCHAR"/>
<result column="operator_id" property="operatorId" jdbcType="BIGINT"/>
@ -23,7 +23,7 @@
id,
order_id,
device_id,
routeId,
route_id,
cargo_weight,
person_count,
operator_id,