107 lines
4.2 KiB
Java
107 lines
4.2 KiB
Java
package com.imeeting.controller.biz;
|
|
|
|
import com.imeeting.dto.biz.SpeakerRegisterDTO;
|
|
import com.imeeting.dto.biz.SpeakerVO;
|
|
import com.imeeting.service.biz.SpeakerService;
|
|
import com.unisbase.common.ApiResponse;
|
|
import com.unisbase.common.annotation.Log;
|
|
import com.unisbase.dto.PageResult;
|
|
import com.unisbase.security.LoginUser;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.List;
|
|
|
|
@Tag(name = "讲话人管理")
|
|
@RestController
|
|
@RequestMapping("/api/biz/speaker")
|
|
public class SpeakerController {
|
|
|
|
private final SpeakerService speakerService;
|
|
|
|
public SpeakerController(SpeakerService speakerService) {
|
|
this.speakerService = speakerService;
|
|
}
|
|
|
|
@Operation(summary = "注册讲话人样本")
|
|
@PostMapping("/register")
|
|
@PreAuthorize("isAuthenticated()")
|
|
@Log(value = "新增讲话人样本", type = "讲话人管理")
|
|
public ApiResponse<SpeakerVO> register(@ModelAttribute SpeakerRegisterDTO registerDTO) {
|
|
LoginUser loginUser = getLoginUser();
|
|
if (loginUser == null || loginUser.getUserId() == null) {
|
|
return ApiResponse.error("未获取到用户信息");
|
|
}
|
|
registerDTO.setCreatorId(loginUser.getUserId());
|
|
return ApiResponse.ok(speakerService.register(registerDTO, loginUser));
|
|
}
|
|
|
|
@Operation(summary = "分页查询讲话人")
|
|
@GetMapping("/page")
|
|
@PreAuthorize("isAuthenticated()")
|
|
public ApiResponse<PageResult<List<SpeakerVO>>> page(
|
|
@RequestParam(defaultValue = "1") Integer current,
|
|
@RequestParam(defaultValue = "8") Integer size,
|
|
@RequestParam(required = false) String name) {
|
|
LoginUser loginUser = getLoginUser();
|
|
if (loginUser == null || loginUser.getUserId() == null) {
|
|
return ApiResponse.error("未获取到用户信息");
|
|
}
|
|
return ApiResponse.ok(speakerService.pageVisible(current, size, name, loginUser));
|
|
}
|
|
|
|
@Operation(summary = "查询可见讲话人")
|
|
@GetMapping("/list")
|
|
@PreAuthorize("isAuthenticated()")
|
|
public ApiResponse<List<SpeakerVO>> list() {
|
|
LoginUser loginUser = getLoginUser();
|
|
if (loginUser == null || loginUser.getUserId() == null) {
|
|
return ApiResponse.error("未获取到用户信息");
|
|
}
|
|
return ApiResponse.ok(speakerService.listVisible(loginUser));
|
|
}
|
|
|
|
@Operation(summary = "同步当前 ASR 声纹")
|
|
@PostMapping("/{id}/sync")
|
|
@PreAuthorize("isAuthenticated()")
|
|
public ApiResponse<Boolean> sync(@PathVariable Long id) {
|
|
LoginUser loginUser = getLoginUser();
|
|
if (loginUser == null || loginUser.getUserId() == null) {
|
|
return ApiResponse.error("未获取到用户信息");
|
|
}
|
|
speakerService.syncCurrentAsr(id, loginUser);
|
|
return ApiResponse.ok(Boolean.TRUE);
|
|
}
|
|
|
|
@Operation(summary = "删除讲话人")
|
|
@DeleteMapping("/{id}")
|
|
@PreAuthorize("isAuthenticated()")
|
|
@Log(value = "删除讲话人", type = "讲话人管理")
|
|
public ApiResponse<Boolean> delete(@PathVariable Long id) {
|
|
LoginUser loginUser = getLoginUser();
|
|
if (loginUser == null || loginUser.getUserId() == null) {
|
|
return ApiResponse.error("未获取到用户信息");
|
|
}
|
|
speakerService.deleteSpeaker(id, loginUser);
|
|
return ApiResponse.ok(Boolean.TRUE);
|
|
}
|
|
|
|
private LoginUser getLoginUser() {
|
|
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
if (principal instanceof LoginUser loginUser) {
|
|
return loginUser;
|
|
}
|
|
return null;
|
|
}
|
|
}
|