136 lines
6.0 KiB
Java
136 lines
6.0 KiB
Java
package com.ai.da.controller;
|
|
|
|
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
|
import com.ai.da.common.response.Response;
|
|
import com.ai.da.common.utils.CopyUtil;
|
|
import com.ai.da.mapper.primary.entity.Library;
|
|
import com.ai.da.model.dto.ChatFlushDTO;
|
|
import com.ai.da.model.dto.ChatRobotLibraryDTO;
|
|
import com.ai.da.model.dto.ChatSendDTO;
|
|
import com.ai.da.model.dto.SuperResolutionDTO;
|
|
import com.ai.da.model.vo.ChatRobotVO;
|
|
import com.ai.da.model.vo.PythonLibraryVo;
|
|
import com.ai.da.model.vo.SysFileVO;
|
|
import com.ai.da.python.PythonService;
|
|
import com.ai.da.service.ChatRobotService;
|
|
import com.ai.da.service.LibraryService;
|
|
import com.ai.da.service.SuperResolutionService;
|
|
import com.ai.da.service.SysFileService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import jakarta.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Tag(name = "python对接模块")
|
|
@Slf4j
|
|
@RestController
|
|
@RequestMapping("/api/python")
|
|
public class PythonController {
|
|
|
|
@Resource
|
|
private PythonService pythonService;
|
|
@Resource
|
|
private SysFileService sysFileService;
|
|
@Resource
|
|
private LibraryService libraryService;
|
|
@Resource
|
|
private ChatRobotService chatRobotService;
|
|
|
|
@Resource
|
|
private SuperResolutionService superResolutionService;
|
|
|
|
@Operation(summary = "python服务保存图片到java服务")
|
|
@PostMapping("/saveGeneratePicture")
|
|
public Response<String> upload(@RequestParam("file") MultipartFile file,
|
|
@Parameter(description = "操作类型 generatePrint ->生成印花 " +
|
|
"designCollection ->设计collection generateAdvancedDesign ->生成高级design" +
|
|
"generateSketch -> 生成草图")
|
|
@RequestParam(value = "operateType") String operateType) {
|
|
return Response.success(pythonService.upload(file, operateType));
|
|
}
|
|
|
|
// @Operation(summary = "python服务保存多张图片到java服务")
|
|
// @PostMapping("/saveMultiGeneratePicture")
|
|
// public Response<List<String>> uploadMultiple(@RequestParam("files") MultipartFile[] files,
|
|
// @ApiParam("操作类型 generatePrint ->生成印花 " +
|
|
// "designCollection ->设计collection generateAdvancedDesign ->生成高级design" +
|
|
// "generateSketch -> 生成草图")
|
|
// @RequestParam(value = "operateType") String operateType) {
|
|
// return Response.success(pythonService.upload(files, operateType));
|
|
// }
|
|
|
|
@Operation(summary = "通过文件类型获取系统文件")
|
|
@GetMapping("/getSysFileByLevel2Type")
|
|
public Response<List<SysFileVO>> getSysFileByLevel2Type(/*@RequestParam(value = "level2Type",required = false) String level2Type*/) {
|
|
return Response.success(sysFileService.getByLevel2Type("All"));
|
|
}
|
|
|
|
@Operation(summary = "通过用户id获取library")
|
|
@GetMapping("/getLibraryByUserId")
|
|
public Response<Map<String, List<String>>> getLibraryByUserId(@RequestParam(value = "userId") Long userId) {
|
|
List<PythonLibraryVo> response = CopyUtil.copyList(libraryService.selectByAccountIdAnd1TypeList(userId,
|
|
Collections.singletonList(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName())), PythonLibraryVo.class);
|
|
//key转小写 统一
|
|
return Response.success(response.stream().collect(Collectors.groupingBy(v -> v.getLevel2Type().toLowerCase(),
|
|
Collectors.mapping(PythonLibraryVo::getUrl, Collectors.toList()))));
|
|
}
|
|
|
|
@CrossOrigin
|
|
@Operation(summary = "发送用户输入消息")
|
|
@PostMapping("/chatStream")
|
|
public Response<ChatRobotVO> MessageToPythonChatStream(@RequestBody ChatSendDTO chatSendDTO) {
|
|
log.info(chatSendDTO.toString());
|
|
return Response.success(chatRobotService.sendMessageToChatRobot(chatSendDTO));
|
|
}
|
|
|
|
@Operation(summary = "血条")
|
|
@GetMapping("/getBloodBars")
|
|
public Response<BigDecimal> getBloodBars(@RequestParam(value = "userId") Long userId) {
|
|
return Response.success(chatRobotService.getBloodBars(userId));
|
|
}
|
|
|
|
@CrossOrigin
|
|
@Operation(summary = "likeOrUnlike")
|
|
@PostMapping("/pictureLikeOrUnLike")
|
|
public Response<Library> pictureLikeOrUnLike(@RequestBody ChatRobotLibraryDTO chatRobotLibraryDTO) {
|
|
return Response.success(chatRobotService.pictureLikeOrUnLike(chatRobotLibraryDTO));
|
|
}
|
|
|
|
@CrossOrigin
|
|
@Operation(summary = "刷新会话缓存")
|
|
@PostMapping("/flush")
|
|
public Response<String> ChatBufferFlush(@RequestBody ChatFlushDTO chatFlushDTO) {
|
|
return Response.success(chatRobotService.chatBufferFlush(chatFlushDTO));
|
|
}
|
|
|
|
@Operation(summary = "超分辨率")
|
|
@PostMapping("/prepareForSR")
|
|
public Response<List<String>> superResolution(@RequestBody List<SuperResolutionDTO> superResolutionDTO) {
|
|
return Response.success(superResolutionService.prepareForSR(superResolutionDTO));
|
|
}
|
|
|
|
@CrossOrigin
|
|
@Operation(summary = "Seg Anything 转发接口")
|
|
@PostMapping("/segAnything")
|
|
public Response<String> segAnything(@RequestBody Map<String, Object> payload) {
|
|
// 将前端传来的 Map 转为 fastjson JSONObject 并转发给 python 服务
|
|
JSONObject requestJson = (JSONObject) JSON.toJSON(payload);
|
|
String url = pythonService.segAnything(requestJson);
|
|
return Response.success(url);
|
|
}
|
|
|
|
}
|