粉丝管理

This commit is contained in:
2026-06-03 12:43:07 +08:00
parent bdad17d77a
commit c40d7aabcb
8 changed files with 435 additions and 3 deletions

View File

@@ -0,0 +1,89 @@
package com.rj.controller;
import com.rj.entity.FanManagement;
import com.rj.service.IFanManagementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 粉丝管理fan_management前端控制器
*/
@RestController
@RequestMapping("/api/fanManagement")
@Tag(name = "粉丝管理", description = "fan_management 增删改查与分页")
public class FanManagementController {
@Autowired
private IFanManagementService fanManagementService;
@PostMapping("/add")
@Operation(summary = "新增粉丝")
public ResponseEntity<Map<String, Object>> add(
@Parameter(description = "粉丝实体id 必填)", required = true)
@RequestBody FanManagement entity) {
Map<String, Object> result = fanManagementService.add(entity);
return toResponse(result);
}
@PutMapping("/update")
@Operation(summary = "修改粉丝")
public ResponseEntity<Map<String, Object>> update(
@Parameter(description = "粉丝实体id 必填)", required = true)
@RequestBody FanManagement entity) {
Map<String, Object> result = fanManagementService.update(entity);
return toResponse(result);
}
@DeleteMapping("/delete/{id}")
@Operation(summary = "删除粉丝")
public ResponseEntity<Map<String, Object>> delete(
@Parameter(description = "粉丝ID", required = true) @PathVariable Long id) {
Map<String, Object> result = fanManagementService.deleteById(id);
return toResponse(result);
}
@GetMapping("/list")
@Operation(summary = "分页查询粉丝")
public ResponseEntity<Map<String, Object>> list(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String nickname,
@RequestParam(required = false) String mobile,
@RequestParam(required = false) Integer shareNumMin,
@RequestParam(required = false) Integer shareNumMax,
@Parameter(description = "创建时间起,格式 yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false) String createdAtStart,
@Parameter(description = "创建时间止,格式 yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false) String createdAtEnd) {
Map<String, Object> result = fanManagementService.pageQuery(
current, size, nickname, mobile, shareNumMin, shareNumMax,
createdAtStart, createdAtEnd);
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
if (result.get("message") != null
&& result.get("message").toString().contains("格式错误")) {
return ResponseEntity.badRequest().body(result);
}
return ResponseEntity.internalServerError().body(result);
}
private ResponseEntity<Map<String, Object>> toResponse(Map<String, Object> result) {
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
String message = result.get("message") != null ? result.get("message").toString() : "";
if (message.contains("不能为空") || message.contains("格式错误")) {
return ResponseEntity.badRequest().body(result);
}
return ResponseEntity.badRequest().body(result);
}
}