|
@@ -0,0 +1,179 @@
|
|
|
+package com.tourism.webadmin.back.controller;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import com.tourism.common.log.annotation.OperationLog;
|
|
|
+import com.tourism.common.log.model.constant.SysOperationLogType;
|
|
|
+import com.github.pagehelper.page.PageMethod;
|
|
|
+import com.tourism.webadmin.back.vo.*;
|
|
|
+import com.tourism.webadmin.back.dto.*;
|
|
|
+import com.tourism.webadmin.back.model.*;
|
|
|
+import com.tourism.webadmin.back.service.*;
|
|
|
+import com.tourism.common.core.object.*;
|
|
|
+import com.tourism.common.core.util.*;
|
|
|
+import com.tourism.common.core.constant.*;
|
|
|
+import com.tourism.common.core.annotation.MyRequestBody;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户与话题的关联表操作控制器类。
|
|
|
+ *
|
|
|
+ * @author 吃饭睡觉
|
|
|
+ * @date 2024-09-06
|
|
|
+ */
|
|
|
+@Tag(name = "用户与话题的关联表管理接口")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/app/tourUserLikeTopic")
|
|
|
+public class TourUserLikeTopicController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TourUserLikeTopicService tourUserLikeTopicService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户与话题的关联表数据。
|
|
|
+ *
|
|
|
+ * @param tourUserLikeTopicDto 新增对象。
|
|
|
+ * @return 应答结果对象,包含新增对象主键Id。
|
|
|
+ */
|
|
|
+ @ApiOperationSupport(ignoreParameters = {"tourUserLikeTopicDto.id"})
|
|
|
+ @SaCheckPermission("tourUserLikeTopic.add")
|
|
|
+ @OperationLog(type = SysOperationLogType.ADD)
|
|
|
+ @PostMapping("/add")
|
|
|
+ public ResponseResult<Long> add(@MyRequestBody TourUserLikeTopicDto tourUserLikeTopicDto) {
|
|
|
+ String errorMessage = MyCommonUtil.getModelValidationError(tourUserLikeTopicDto, false);
|
|
|
+ if (errorMessage != null) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
|
|
|
+ }
|
|
|
+ TourUserLikeTopic tourUserLikeTopic = MyModelUtil.copyTo(tourUserLikeTopicDto, TourUserLikeTopic.class);
|
|
|
+ tourUserLikeTopic = tourUserLikeTopicService.saveNew(tourUserLikeTopic);
|
|
|
+ return ResponseResult.success(tourUserLikeTopic.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新用户与话题的关联表数据。
|
|
|
+ *
|
|
|
+ * @param tourUserLikeTopicDto 更新对象。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("tourUserLikeTopic.update")
|
|
|
+ @OperationLog(type = SysOperationLogType.UPDATE)
|
|
|
+ @PostMapping("/update")
|
|
|
+ public ResponseResult<Void> update(@MyRequestBody TourUserLikeTopicDto tourUserLikeTopicDto) {
|
|
|
+ String errorMessage = MyCommonUtil.getModelValidationError(tourUserLikeTopicDto, true);
|
|
|
+ if (errorMessage != null) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
|
|
|
+ }
|
|
|
+ TourUserLikeTopic tourUserLikeTopic = MyModelUtil.copyTo(tourUserLikeTopicDto, TourUserLikeTopic.class);
|
|
|
+ TourUserLikeTopic originalTourUserLikeTopic = tourUserLikeTopicService.getById(tourUserLikeTopic.getId());
|
|
|
+ if (originalTourUserLikeTopic == null) {
|
|
|
+ // NOTE: 修改下面方括号中的话述
|
|
|
+ errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ if (!tourUserLikeTopicService.update(tourUserLikeTopic, originalTourUserLikeTopic)) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除用户与话题的关联表数据。
|
|
|
+ *
|
|
|
+ * @param id 删除对象主键Id。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("tourUserLikeTopic.delete")
|
|
|
+ @OperationLog(type = SysOperationLogType.DELETE)
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public ResponseResult<Void> delete(@MyRequestBody Long id) {
|
|
|
+ if (MyCommonUtil.existBlankArgument(id)) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
|
|
+ }
|
|
|
+ return this.doDelete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除用户与话题的关联表数据。
|
|
|
+ *
|
|
|
+ * @param idList 待删除对象的主键Id列表。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("tourUserLikeTopic.delete")
|
|
|
+ @OperationLog(type = SysOperationLogType.DELETE_BATCH)
|
|
|
+ @PostMapping("/deleteBatch")
|
|
|
+ public ResponseResult<Void> deleteBatch(@MyRequestBody List<Long> idList) {
|
|
|
+ if (MyCommonUtil.existBlankArgument(idList)) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
|
|
+ }
|
|
|
+ for (Long id : idList) {
|
|
|
+ ResponseResult<Void> responseResult = this.doDelete(id);
|
|
|
+ if (!responseResult.isSuccess()) {
|
|
|
+ return responseResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列出符合过滤条件的用户与话题的关联表列表。
|
|
|
+ *
|
|
|
+ * @param tourUserLikeTopicDtoFilter 过滤对象。
|
|
|
+ * @param orderParam 排序参数。
|
|
|
+ * @param pageParam 分页参数。
|
|
|
+ * @return 应答结果对象,包含查询结果集。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("tourUserLikeTopic.view")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public ResponseResult<MyPageData<TourUserLikeTopicVo>> list(
|
|
|
+ @MyRequestBody TourUserLikeTopicDto tourUserLikeTopicDtoFilter,
|
|
|
+ @MyRequestBody MyOrderParam orderParam,
|
|
|
+ @MyRequestBody MyPageParam pageParam) {
|
|
|
+ if (pageParam != null) {
|
|
|
+ PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getCount());
|
|
|
+ }
|
|
|
+ TourUserLikeTopic tourUserLikeTopicFilter = MyModelUtil.copyTo(tourUserLikeTopicDtoFilter, TourUserLikeTopic.class);
|
|
|
+ String orderBy = MyOrderParam.buildOrderBy(orderParam, TourUserLikeTopic.class);
|
|
|
+ List<TourUserLikeTopic> tourUserLikeTopicList =
|
|
|
+ tourUserLikeTopicService.getTourUserLikeTopicListWithRelation(tourUserLikeTopicFilter, orderBy);
|
|
|
+ return ResponseResult.success(MyPageUtil.makeResponseData(tourUserLikeTopicList, TourUserLikeTopicVo.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看指定用户与话题的关联表对象详情。
|
|
|
+ *
|
|
|
+ * @param id 指定对象主键Id。
|
|
|
+ * @return 应答结果对象,包含对象详情。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("tourUserLikeTopic.view")
|
|
|
+ @GetMapping("/view")
|
|
|
+ public ResponseResult<TourUserLikeTopicVo> view(@RequestParam Long id) {
|
|
|
+ TourUserLikeTopic tourUserLikeTopic = tourUserLikeTopicService.getByIdWithRelation(id, MyRelationParam.full());
|
|
|
+ if (tourUserLikeTopic == null) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ TourUserLikeTopicVo tourUserLikeTopicVo = MyModelUtil.copyTo(tourUserLikeTopic, TourUserLikeTopicVo.class);
|
|
|
+ return ResponseResult.success(tourUserLikeTopicVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseResult<Void> doDelete(Long id) {
|
|
|
+ String errorMessage;
|
|
|
+ // 验证关联Id的数据合法性
|
|
|
+ TourUserLikeTopic originalTourUserLikeTopic = tourUserLikeTopicService.getById(id);
|
|
|
+ if (originalTourUserLikeTopic == null) {
|
|
|
+ // NOTE: 修改下面方括号中的话述
|
|
|
+ errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ if (!tourUserLikeTopicService.remove(id)) {
|
|
|
+ errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+}
|