Files
aida_back/src/main/java/com/ai/da/controller/PythonController.java

123 lines
5.4 KiB
Java
Raw Normal View History

2023-01-06 15:17:37 +08:00
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;
2024-01-19 16:36:34 +08:00
import com.ai.da.mapper.primary.entity.Library;
2023-07-25 17:57:37 +08:00
import com.ai.da.model.dto.ChatFlushDTO;
import com.ai.da.model.dto.ChatRobotLibraryDTO;
2023-07-25 17:57:37 +08:00
import com.ai.da.model.dto.ChatSendDTO;
import com.ai.da.model.dto.SuperResolutionDTO;
import com.ai.da.model.vo.ChatRobotVO;
2023-07-25 17:57:37 +08:00
import com.ai.da.model.vo.PythonLibraryVo;
import com.ai.da.model.vo.SysFileVO;
2023-01-06 15:17:37 +08:00
import com.ai.da.python.PythonService;
2023-07-25 17:57:37 +08:00
import com.ai.da.service.ChatRobotService;
import com.ai.da.service.LibraryService;
import com.ai.da.service.SuperResolutionService;
2023-07-25 17:57:37 +08:00
import com.ai.da.service.SysFileService;
2023-01-06 15:17:37 +08:00
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
2025-11-25 16:46:05 +08:00
import jakarta.annotation.Resource;
import java.math.BigDecimal;
2023-01-06 15:17:37 +08:00
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Api(tags = "python对接模块")
@Slf4j
@RestController
@RequestMapping("/api/python")
public class PythonController {
@Resource
private PythonService pythonService;
@Resource
private SysFileService sysFileService;
@Resource
private LibraryService libraryService;
2023-07-25 17:57:37 +08:00
@Resource
private ChatRobotService chatRobotService;
@Resource
private SuperResolutionService superResolutionService;
2023-01-06 15:17:37 +08:00
@ApiOperation(value = "python服务保存图片到java服务")
@PostMapping("/saveGeneratePicture")
public Response<String> upload(@RequestParam("file") MultipartFile file,
2023-07-25 17:57:37 +08:00
@ApiParam("操作类型 generatePrint ->生成印花 " +
2023-10-20 14:47:18 +08:00
"designCollection ->设计collection generateAdvancedDesign ->生成高级design" +
"generateSketch -> 生成草图")
2023-07-25 17:57:37 +08:00
@RequestParam(value = "operateType") String operateType) {
return Response.success(pythonService.upload(file, operateType));
2023-01-06 15:17:37 +08:00
}
2023-11-02 15:35:07 +08:00
// @ApiOperation(value = "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));
// }
2023-01-06 15:17:37 +08:00
@ApiOperation(value = "通过文件类型获取系统文件")
@GetMapping("/getSysFileByLevel2Type")
public Response<List<SysFileVO>> getSysFileByLevel2Type(/*@RequestParam(value = "level2Type",required = false) String level2Type*/) {
return Response.success(sysFileService.getByLevel2Type("All"));
}
@ApiOperation(value = "通过用户id获取library")
@GetMapping("/getLibraryByUserId")
2023-07-25 17:57:37 +08:00
public Response<Map<String, List<String>>> getLibraryByUserId(@RequestParam(value = "userId") Long userId) {
2023-01-06 15:17:37 +08:00
List<PythonLibraryVo> response = CopyUtil.copyList(libraryService.selectByAccountIdAnd1TypeList(userId,
2023-07-25 17:57:37 +08:00
Collections.singletonList(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName())), PythonLibraryVo.class);
2023-01-06 15:17:37 +08:00
//key转小写 统一
2023-07-25 17:57:37 +08:00
return Response.success(response.stream().collect(Collectors.groupingBy(v -> v.getLevel2Type().toLowerCase(),
Collectors.mapping(PythonLibraryVo::getUrl, Collectors.toList()))));
}
2023-07-26 17:04:24 +08:00
@CrossOrigin
2023-07-25 17:57:37 +08:00
@ApiOperation(value = "发送用户输入消息")
@PostMapping("/chatStream")
public Response<ChatRobotVO> MessageToPythonChatStream(@RequestBody ChatSendDTO chatSendDTO) {
2023-07-25 17:57:37 +08:00
log.info(chatSendDTO.toString());
return Response.success(chatRobotService.sendMessageToChatRobot(chatSendDTO));
}
@ApiOperation(value = "血条")
@GetMapping("/getBloodBars")
public Response<BigDecimal> getBloodBars(@RequestParam(value = "userId") Long userId) {
return Response.success(chatRobotService.getBloodBars(userId));
}
@CrossOrigin
@ApiOperation(value = "likeOrUnlike")
@PostMapping("/pictureLikeOrUnLike")
public Response<Library> pictureLikeOrUnLike(@RequestBody ChatRobotLibraryDTO chatRobotLibraryDTO) {
return Response.success(chatRobotService.pictureLikeOrUnLike(chatRobotLibraryDTO));
2023-07-25 17:57:37 +08:00
}
2023-07-26 17:04:24 +08:00
@CrossOrigin
2023-07-25 17:57:37 +08:00
@ApiOperation(value = "刷新会话缓存")
@PostMapping("/flush")
public Response<String> ChatBufferFlush(@RequestBody ChatFlushDTO chatFlushDTO) {
return Response.success(chatRobotService.chatBufferFlush(chatFlushDTO));
2023-01-06 15:17:37 +08:00
}
@ApiOperation(value = "超分辨率")
@PostMapping("/prepareForSR")
public Response<List<String>> superResolution(@RequestBody List<SuperResolutionDTO> superResolutionDTO) {
return Response.success(superResolutionService.prepareForSR(superResolutionDTO));
}
2023-01-06 15:17:37 +08:00
}