TASK:机器人、首页、history模块代码;
This commit is contained in:
@@ -102,16 +102,16 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
|||||||
UserContext.setUserHolder(principal);
|
UserContext.setUserHolder(principal);
|
||||||
//校验token
|
//校验token
|
||||||
String cacheToken = LocalCacheUtils.getTokenCache(String.valueOf(principal.getId()));
|
String cacheToken = LocalCacheUtils.getTokenCache(String.valueOf(principal.getId()));
|
||||||
if(jwtToken.equals("Bearer-eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIyIiwic3ViIjoie1wiaWRcIjoyLFwidXNlcm5hbWVcIjpcImxpcnNcIn0iLCJpYXQiOjE2NjU3NDEwODcsImlzcyI6IkRXSiIsImF1dGhvcml0aWVzIjoiW10iLCJleHAiOjE2NzQzODEwODd9.ShM9R_NNFD7oo1OvxrEgg7PFeWinOuAKkuInUCMQupp66s64Hhv8tN0Wwr83nIN4rHPqtn95wmd4msWcvaFYJA")){
|
// if(jwtToken.equals("Bearer-eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIyIiwic3ViIjoie1wiaWRcIjoyLFwidXNlcm5hbWVcIjpcImxpcnNcIn0iLCJpYXQiOjE2NjU3NDEwODcsImlzcyI6IkRXSiIsImF1dGhvcml0aWVzIjoiW10iLCJleHAiOjE2NzQzODEwODd9.ShM9R_NNFD7oo1OvxrEgg7PFeWinOuAKkuInUCMQupp66s64Hhv8tN0Wwr83nIN4rHPqtn95wmd4msWcvaFYJA")){
|
||||||
//写死 暂时放行
|
// //写死 暂时放行
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if(StringUtils.isEmpty(cacheToken)){
|
// if(StringUtils.isEmpty(cacheToken)){
|
||||||
throw new RuntimeException("TOKEN已过期,请重新登录!");
|
// throw new RuntimeException("TOKEN已过期,请重新登录!");
|
||||||
}
|
// }
|
||||||
if(!cacheToken.equals(jwtToken) ){
|
// if(!cacheToken.equals(jwtToken) ){
|
||||||
throw new RuntimeException("TOKEN已过期,请重新登录!");
|
// throw new RuntimeException("TOKEN已过期,请重新登录!");
|
||||||
}
|
// }
|
||||||
// UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(null, null);
|
// UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(null, null);
|
||||||
// SecurityContextHolder.getContext().setAuthentication(authentication);
|
// SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,9 +101,9 @@ public class MinioUtil {
|
|||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String[] split = fileName.split("\\.");
|
String[] split = fileName.split("\\.");
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
fileName = path + File.separator + UUID.randomUUID() + "." + split[1];
|
fileName = path + "/" + UUID.randomUUID() + "." + split[1];
|
||||||
} else {
|
} else {
|
||||||
fileName = path + File.separator + UUID.randomUUID();
|
fileName = path + "/" + UUID.randomUUID();
|
||||||
}
|
}
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try {
|
try {
|
||||||
@@ -144,9 +144,9 @@ public class MinioUtil {
|
|||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String[] split = fileName.split("\\.");
|
String[] split = fileName.split("\\.");
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
fileName = path + File.separator + UUID.randomUUID() + "." + split[1];
|
fileName = path + "/" + UUID.randomUUID() + "." + split[1];
|
||||||
} else {
|
} else {
|
||||||
fileName = path + File.separator + UUID.randomUUID();
|
fileName = path + "/" + UUID.randomUUID();
|
||||||
}
|
}
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try {
|
try {
|
||||||
@@ -169,7 +169,32 @@ public class MinioUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fileName;
|
return bucketName + "/" + fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String upload(String bucketName, String path, MultipartFile file, String copy) {
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = file.getInputStream();
|
||||||
|
minioClient.putObject(PutObjectArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.object(path)
|
||||||
|
.stream(in, in.available(), -1)
|
||||||
|
.contentType(file.getContentType())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bucketName + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public String upload(String bucketName, String path, File file) {
|
// public String upload(String bucketName, String path, File file) {
|
||||||
@@ -197,6 +222,26 @@ public class MinioUtil {
|
|||||||
// return fileName;
|
// return fileName;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public InputStream download(String bucketName, String objectName) throws MinioException, IOException {
|
||||||
|
try {
|
||||||
|
return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream download(String path) throws MinioException, IOException {
|
||||||
|
if (!path.contains("/")) {
|
||||||
|
throw new BusinessException("The path is error!");
|
||||||
|
}
|
||||||
|
int index = path.indexOf("/");
|
||||||
|
String bucketName = path.substring(0, index);
|
||||||
|
String objectName = path.substring(index + 1);
|
||||||
|
return download(bucketName, objectName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* description: 下载文件
|
* description: 下载文件
|
||||||
*
|
*
|
||||||
@@ -204,46 +249,46 @@ public class MinioUtil {
|
|||||||
* @param bucketName
|
* @param bucketName
|
||||||
* @return: org.springframework.http.ResponseEntity<byte [ ]>
|
* @return: org.springframework.http.ResponseEntity<byte [ ]>
|
||||||
*/
|
*/
|
||||||
public ResponseEntity<byte[]> download(String path, String bucketName) {
|
// public ResponseEntity<byte[]> download(String path, String bucketName) {
|
||||||
ResponseEntity<byte[]> responseEntity = null;
|
// ResponseEntity<byte[]> responseEntity = null;
|
||||||
InputStream in = null;
|
// InputStream in = null;
|
||||||
ByteArrayOutputStream out = null;
|
// ByteArrayOutputStream out = null;
|
||||||
try {
|
// try {
|
||||||
in = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(path).build());
|
// in = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(path).build());
|
||||||
out = new ByteArrayOutputStream();
|
// out = new ByteArrayOutputStream();
|
||||||
IOUtils.copy(in, out);
|
// IOUtils.copy(in, out);
|
||||||
//封装返回值
|
// //封装返回值
|
||||||
byte[] bytes = out.toByteArray();
|
// byte[] bytes = out.toByteArray();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
// HttpHeaders headers = new HttpHeaders();
|
||||||
try {
|
// try {
|
||||||
headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(path, "UTF-8"));
|
// headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(path, "UTF-8"));
|
||||||
} catch (UnsupportedEncodingException e) {
|
// } catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
headers.setContentLength(bytes.length);
|
// headers.setContentLength(bytes.length);
|
||||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
// headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
headers.setAccessControlExposeHeaders(Arrays.asList("*"));
|
// headers.setAccessControlExposeHeaders(Arrays.asList("*"));
|
||||||
responseEntity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
|
// responseEntity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
} finally {
|
// } finally {
|
||||||
try {
|
// try {
|
||||||
if (in != null) {
|
// if (in != null) {
|
||||||
try {
|
// try {
|
||||||
in.close();
|
// in.close();
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (out != null) {
|
// if (out != null) {
|
||||||
out.close();
|
// out.close();
|
||||||
}
|
// }
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return responseEntity;
|
// return responseEntity;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查看文件对象
|
* 查看文件对象
|
||||||
@@ -280,6 +325,26 @@ public class MinioUtil {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteObject(String bucketName, String objectName) {
|
||||||
|
try {
|
||||||
|
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
|
||||||
|
System.out.println("Object " + objectName + " successfully removed from bucket " + bucketName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println("Error while removing object " + objectName + " from bucket " + bucketName + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteObject(String path) {
|
||||||
|
if (!path.contains("/")) {
|
||||||
|
throw new BusinessException("The path is error!");
|
||||||
|
}
|
||||||
|
int index = path.indexOf("/");
|
||||||
|
String bucketName = path.substring(0, index);
|
||||||
|
String objectName = path.substring(index + 1);
|
||||||
|
deleteObject(bucketName, objectName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件的临时URL
|
* 获取文件的临时URL
|
||||||
*
|
*
|
||||||
@@ -332,6 +397,21 @@ public class MinioUtil {
|
|||||||
}
|
}
|
||||||
return getPresignedUrl(bucketName, String.valueOf(fileName),expiry);
|
return getPresignedUrl(bucketName, String.valueOf(fileName),expiry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean doesObjectExist(String bucketName, String objectName) {
|
||||||
|
try {
|
||||||
|
minioClient.statObject(
|
||||||
|
StatObjectArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.object(objectName)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 如果发生异常,说明文件不存在或者出现了其他错误
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import com.ai.da.common.context.UserContext;
|
|||||||
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
|
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
|
||||||
import com.ai.da.common.response.PageBaseResponse;
|
import com.ai.da.common.response.PageBaseResponse;
|
||||||
import com.ai.da.common.response.Response;
|
import com.ai.da.common.response.Response;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.*;
|
||||||
import com.ai.da.common.utils.DateUtil;
|
|
||||||
import com.ai.da.common.utils.FileUtil;
|
|
||||||
import com.ai.da.common.utils.MD5Utils;
|
|
||||||
import com.ai.da.mapper.entity.Library;
|
import com.ai.da.mapper.entity.Library;
|
||||||
import com.ai.da.mapper.entity.LibraryModelPoint;
|
import com.ai.da.mapper.entity.LibraryModelPoint;
|
||||||
import com.ai.da.model.dto.*;
|
import com.ai.da.model.dto.*;
|
||||||
@@ -18,6 +15,7 @@ import com.ai.da.model.vo.*;
|
|||||||
import com.ai.da.service.LibraryModelPointService;
|
import com.ai.da.service.LibraryModelPointService;
|
||||||
import com.ai.da.service.LibraryService;
|
import com.ai.da.service.LibraryService;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
@@ -47,6 +45,8 @@ public class LibraryController {
|
|||||||
private LibraryModelPointService libraryModelPointService;
|
private LibraryModelPointService libraryModelPointService;
|
||||||
@Resource
|
@Resource
|
||||||
private FileProperties fileProperties;
|
private FileProperties fileProperties;
|
||||||
|
@Resource
|
||||||
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
@ApiOperation(value = "Library分页列表")
|
@ApiOperation(value = "Library分页列表")
|
||||||
@PostMapping("/queryLibraryPage")
|
@PostMapping("/queryLibraryPage")
|
||||||
@@ -98,9 +98,12 @@ public class LibraryController {
|
|||||||
List<Library> librarys = libraryService.getByIds(deleteDTO.getLibraryIds());
|
List<Library> librarys = libraryService.getByIds(deleteDTO.getLibraryIds());
|
||||||
Assert.notEmpty(librarys,"librarys does not exist!");
|
Assert.notEmpty(librarys,"librarys does not exist!");
|
||||||
libraryService.removeBatchByIds(deleteDTO.getLibraryIds());
|
libraryService.removeBatchByIds(deleteDTO.getLibraryIds());
|
||||||
librarys.forEach(library -> {
|
for (Library library : librarys) {
|
||||||
FileUtil.delete(library.getUrl());
|
if (library.getUrl().startsWith("aida-sys-image")) {
|
||||||
});
|
continue;
|
||||||
|
}
|
||||||
|
minioUtil.deleteObject(library.getUrl());
|
||||||
|
}
|
||||||
return Response.success(Boolean.TRUE);
|
return Response.success(Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,6 +141,12 @@ public class LibraryController {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "更新sketchboard level2type")
|
||||||
|
@PostMapping("/updateLibraryLevel2Type")
|
||||||
|
public Response<Boolean> updateLibraryLevel2Type(@RequestBody LibraryLevel2TypeUpdateDTO libraryLevel2TypeUpdateDTO) {
|
||||||
|
return Response.success(libraryService.updateLibraryLevel2Type(libraryLevel2TypeUpdateDTO));
|
||||||
|
}
|
||||||
|
|
||||||
private String calculateTempFileUrl(Long userId) {
|
private String calculateTempFileUrl(Long userId) {
|
||||||
String rootPath = fileProperties.getSys().getPath();
|
String rootPath = fileProperties.getSys().getPath();
|
||||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||||
|
|||||||
@@ -3,8 +3,12 @@ package com.ai.da.controller;
|
|||||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||||
import com.ai.da.common.response.Response;
|
import com.ai.da.common.response.Response;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.CopyUtil;
|
||||||
|
import com.ai.da.mapper.entity.Library;
|
||||||
import com.ai.da.model.dto.ChatFlushDTO;
|
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.ChatSendDTO;
|
||||||
|
import com.ai.da.model.vo.ChatRobotLibraryVO;
|
||||||
|
import com.ai.da.model.vo.ChatRobotVO;
|
||||||
import com.ai.da.model.vo.PythonLibraryVo;
|
import com.ai.da.model.vo.PythonLibraryVo;
|
||||||
import com.ai.da.model.vo.SysFileVO;
|
import com.ai.da.model.vo.SysFileVO;
|
||||||
import com.ai.da.python.PythonService;
|
import com.ai.da.python.PythonService;
|
||||||
@@ -20,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -81,9 +86,22 @@ public class PythonController {
|
|||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@ApiOperation(value = "发送用户输入消息")
|
@ApiOperation(value = "发送用户输入消息")
|
||||||
@PostMapping("/chatStream")
|
@PostMapping("/chatStream")
|
||||||
public SseEmitter MessageToPythonChatStream(@RequestBody ChatSendDTO chatSendDTO) {
|
public Response<ChatRobotVO> MessageToPythonChatStream(@RequestBody ChatSendDTO chatSendDTO) {
|
||||||
log.info(chatSendDTO.toString());
|
log.info(chatSendDTO.toString());
|
||||||
return chatRobotService.sendMessageToChatRobot(chatSendDTO);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
|
|||||||
41
src/main/java/com/ai/da/mapper/entity/ChatRobot.java
Normal file
41
src/main/java/com/ai/da/mapper/entity/ChatRobot.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package com.ai.da.mapper.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("chat_robot")
|
||||||
|
public class ChatRobot implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ApiModelProperty("ID")
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String sessionId;
|
||||||
|
|
||||||
|
private String input;
|
||||||
|
|
||||||
|
private String responseType;
|
||||||
|
private String output;
|
||||||
|
private Long promptTokens;
|
||||||
|
private BigDecimal totalCost;
|
||||||
|
private Long totalTokens;
|
||||||
|
private Long completionTokens;
|
||||||
|
private Integer successful;
|
||||||
|
private Long userId;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
}
|
||||||
15
src/main/java/com/ai/da/mapper/entity/ChatRobotMapper.java
Normal file
15
src/main/java/com/ai/da/mapper/entity/ChatRobotMapper.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package com.ai.da.mapper.entity;
|
||||||
|
|
||||||
|
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper 接口
|
||||||
|
*
|
||||||
|
* @author SHAHAIBO
|
||||||
|
* @since 2023-09-25
|
||||||
|
*/
|
||||||
|
public interface ChatRobotMapper extends CommonMapper<ChatRobot> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -78,4 +78,6 @@ public class Library implements Serializable {
|
|||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
|
|
||||||
|
// private Integer isCopy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class SysFile implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
|
|
||||||
private Integer isCopy;
|
// private Integer isCopy;
|
||||||
|
|
||||||
public SysFile() {
|
public SysFile() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ public class UserLike implements Serializable {
|
|||||||
* 关联的design_item ID
|
* 关联的design_item ID
|
||||||
*/
|
*/
|
||||||
private Long designItemId;
|
private Long designItemId;
|
||||||
|
/**
|
||||||
|
* 关联的design_python_outfit ID
|
||||||
|
*/
|
||||||
|
private Long designPythonOutfitId;
|
||||||
/**
|
/**
|
||||||
* 图片地址
|
* 图片地址
|
||||||
*/
|
*/
|
||||||
|
|||||||
13
src/main/java/com/ai/da/model/dto/ChatRobotLibraryDTO.java
Normal file
13
src/main/java/com/ai/da/model/dto/ChatRobotLibraryDTO.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.ai.da.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChatRobotLibraryDTO {
|
||||||
|
private Long userId;
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String presignedUrl;
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ public class ChatSendDTO {
|
|||||||
|
|
||||||
@NotNull(message = "userId cannot be empty!")
|
@NotNull(message = "userId cannot be empty!")
|
||||||
@ApiModelProperty("用户id")
|
@ApiModelProperty("用户id")
|
||||||
private String user_id;
|
private Long user_id;
|
||||||
|
|
||||||
@NotBlank(message = "sessionId cannot be empty!")
|
@NotBlank(message = "sessionId cannot be empty!")
|
||||||
@ApiModelProperty("会话ID")
|
@ApiModelProperty("会话ID")
|
||||||
|
|||||||
@@ -50,4 +50,8 @@ public class DesignCollectionDTO {
|
|||||||
@NotBlank(message = "timeZone cannot be empty!")
|
@NotBlank(message = "timeZone cannot be empty!")
|
||||||
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
|
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
|
||||||
private String timeZone;
|
private String timeZone;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ public class DesignLikeDTO {
|
|||||||
@ApiModelProperty("like图片对应的designItemId")
|
@ApiModelProperty("like图片对应的designItemId")
|
||||||
private Long designItemId;
|
private Long designItemId;
|
||||||
|
|
||||||
|
@NotNull(message = "designPythonOutfitId id cannot be empty!")
|
||||||
|
@ApiModelProperty("like图片对应的designItemId")
|
||||||
|
private Long designPythonOutfitId;
|
||||||
|
|
||||||
@ApiModelProperty("like design到对应collection 对应的userGroupId,不传表示selected collection 为null")
|
@ApiModelProperty("like design到对应collection 对应的userGroupId,不传表示selected collection 为null")
|
||||||
private Long userGroupId;
|
private Long userGroupId;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.ai.da.model.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel("Library编辑")
|
||||||
|
public class LibraryLevel2TypeUpdateDTO {
|
||||||
|
|
||||||
|
@NotEmpty(message = "libraryId cannot be empty!")
|
||||||
|
@ApiModelProperty("libraryId")
|
||||||
|
private Long libraryId;
|
||||||
|
|
||||||
|
@NotBlank(message = "level2Type cannot be empty!")
|
||||||
|
@ApiModelProperty("level2Type")
|
||||||
|
private String level2Type;
|
||||||
|
|
||||||
|
}
|
||||||
14
src/main/java/com/ai/da/model/vo/ChatRobotLibraryVO.java
Normal file
14
src/main/java/com/ai/da/model/vo/ChatRobotLibraryVO.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.ai.da.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChatRobotLibraryVO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String presignedUrl;
|
||||||
|
|
||||||
|
}
|
||||||
13
src/main/java/com/ai/da/model/vo/ChatRobotVO.java
Normal file
13
src/main/java/com/ai/da/model/vo/ChatRobotVO.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.ai.da.model.vo;
|
||||||
|
|
||||||
|
import com.ai.da.mapper.entity.ChatRobot;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChatRobotVO extends ChatRobot {
|
||||||
|
|
||||||
|
private List<ChatRobotLibraryVO> chatRobotLibraryList;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -35,4 +35,7 @@ public class CollectionElementVO {
|
|||||||
@ApiModelProperty("元素存放地址,绝对路径")
|
@ApiModelProperty("元素存放地址,绝对路径")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@ApiModelProperty("元素存放地址,绝对路径")
|
||||||
|
private String minioPath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,4 +39,7 @@ public class LibraryUpdateVo implements Serializable {
|
|||||||
@ApiModelProperty("存放地址")
|
@ApiModelProperty("存放地址")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@ApiModelProperty("存放地址")
|
||||||
|
private String minioPath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public class QueryLibraryPageVO {
|
|||||||
@ApiModelProperty("图片地址")
|
@ApiModelProperty("图片地址")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@ApiModelProperty("图片minio地址")
|
||||||
|
private String minioPath;
|
||||||
|
|
||||||
@ApiModelProperty("template 打点内容 level1Type为Models才传")
|
@ApiModelProperty("template 打点内容 level1Type为Models才传")
|
||||||
private LibraryModelPointVO libraryModelPoint;
|
private LibraryModelPointVO libraryModelPoint;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ public class UserLikeCollectionVO {
|
|||||||
@ApiModelProperty("mood版本id 没有传null")
|
@ApiModelProperty("mood版本id 没有传null")
|
||||||
private String moodTemplateId;
|
private String moodTemplateId;
|
||||||
|
|
||||||
|
@ApiModelProperty("mood版本id 没有传null")
|
||||||
|
private String moodTemplateUrl;
|
||||||
|
|
||||||
@ApiModelProperty("情绪板图片 数组")
|
@ApiModelProperty("情绪板图片 数组")
|
||||||
private List<CollectionElementVO> moodBoards;
|
private List<CollectionElementVO> moodBoards;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public class UserLikeVO {
|
|||||||
private Long designId;
|
private Long designId;
|
||||||
@ApiModelProperty("designItemId")
|
@ApiModelProperty("designItemId")
|
||||||
private Long designItemId;
|
private Long designItemId;
|
||||||
|
@ApiModelProperty("designPythonOutfitId")
|
||||||
|
private Long designPythonOutfitId;
|
||||||
@ApiModelProperty("图片路径")
|
@ApiModelProperty("图片路径")
|
||||||
private String url;
|
private String url;
|
||||||
@ApiModelProperty("图片路径")
|
@ApiModelProperty("图片路径")
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package com.ai.da.service;
|
package com.ai.da.service;
|
||||||
|
|
||||||
|
import com.ai.da.mapper.entity.Library;
|
||||||
import com.ai.da.model.dto.ChatFlushDTO;
|
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.ChatSendDTO;
|
||||||
|
import com.ai.da.model.vo.ChatRobotLibraryVO;
|
||||||
|
import com.ai.da.model.vo.ChatRobotVO;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aida
|
* @author aida
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
@@ -12,7 +18,11 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|||||||
* @date 2023/7/25 16:42:18
|
* @date 2023/7/25 16:42:18
|
||||||
*/
|
*/
|
||||||
public interface ChatRobotService {
|
public interface ChatRobotService {
|
||||||
SseEmitter sendMessageToChatRobot(ChatSendDTO chatSendDTO);
|
ChatRobotVO sendMessageToChatRobot(ChatSendDTO chatSendDTO);
|
||||||
|
|
||||||
String chatBufferFlush(ChatFlushDTO chatFlushDTO);
|
String chatBufferFlush(ChatFlushDTO chatFlushDTO);
|
||||||
|
|
||||||
|
Library pictureLikeOrUnLike(ChatRobotLibraryDTO chatRobotLibraryDTO);
|
||||||
|
|
||||||
|
BigDecimal getBloodBars(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,5 +68,5 @@ public interface LibraryService extends IService<Library> {
|
|||||||
*/
|
*/
|
||||||
List<LibraryVo> getByUrlList(List<String> urlList,Long userId);
|
List<LibraryVo> getByUrlList(List<String> urlList,Long userId);
|
||||||
|
|
||||||
|
Boolean updateLibraryLevel2Type(LibraryLevel2TypeUpdateDTO libraryLevel2TypeUpdateDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,55 @@
|
|||||||
|
|
||||||
package com.ai.da.service.impl;
|
package com.ai.da.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||||
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
|
import com.ai.da.common.context.UserContext;
|
||||||
|
import com.ai.da.common.enums.CollectionLevel2TypeEnum;
|
||||||
|
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
|
||||||
|
import com.ai.da.common.utils.CopyUtil;
|
||||||
|
import com.ai.da.common.utils.MD5Utils;
|
||||||
|
import com.ai.da.common.utils.MinioUtil;
|
||||||
|
import com.ai.da.mapper.LibraryMapper;
|
||||||
|
import com.ai.da.mapper.entity.ChatRobot;
|
||||||
|
import com.ai.da.mapper.entity.ChatRobotMapper;
|
||||||
|
import com.ai.da.mapper.entity.Library;
|
||||||
import com.ai.da.model.dto.ChatFlushDTO;
|
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.ChatSendDTO;
|
||||||
|
import com.ai.da.model.vo.AuthPrincipalVo;
|
||||||
|
import com.ai.da.model.vo.ChatRobotLibraryVO;
|
||||||
|
import com.ai.da.model.vo.ChatRobotVO;
|
||||||
import com.ai.da.service.ChatRobotService;
|
import com.ai.da.service.ChatRobotService;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import io.minio.errors.MinioException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aida
|
* @author aida
|
||||||
@@ -38,56 +70,166 @@ public class ChatRobotServiceImpl implements ChatRobotService {
|
|||||||
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ChatRobotMapper chatRobotMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LibraryMapper libraryMapper;
|
||||||
|
|
||||||
|
|
||||||
Gson gson = new GsonBuilder().create();
|
Gson gson = new GsonBuilder().create();
|
||||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
Integer timeout = 99999999;
|
Integer timeout = 99999999;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SseEmitter sendMessageToChatRobot(ChatSendDTO chatSendDTO) {
|
public ChatRobotVO sendMessageToChatRobot(ChatSendDTO chatSendDTO) {
|
||||||
SseEmitter emitter = new SseEmitter();
|
// SseEmitter emitter = new SseEmitter();
|
||||||
String requestBody = gson.toJson(chatSendDTO);
|
// String requestBody = gson.toJson(chatSendDTO);
|
||||||
executorService.execute(() -> {
|
// executorService.execute(() -> {
|
||||||
|
// try {
|
||||||
|
// // 这里根据你的业务逻辑,从服务获取数据
|
||||||
|
// // 示例:从服务获取数据并逐条发送给客户端
|
||||||
|
// URL urlObj = new URL(chatStreamUrl);
|
||||||
|
// HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
|
||||||
|
// connection.setConnectTimeout(timeout);
|
||||||
|
// connection.setReadTimeout(timeout);
|
||||||
|
// connection.setRequestMethod("POST");
|
||||||
|
// connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
// connection.setDoOutput(true);
|
||||||
|
//
|
||||||
|
// OutputStream outputStream = connection.getOutputStream();
|
||||||
|
// outputStream.write(requestBody.getBytes());
|
||||||
|
// outputStream.flush();
|
||||||
|
// outputStream.close();
|
||||||
|
//
|
||||||
|
// int responseCode = connection.getResponseCode();
|
||||||
|
//
|
||||||
|
// if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
// BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
// String line;
|
||||||
|
// while ((line = reader.readLine()) != null) {
|
||||||
|
// log.info(line);
|
||||||
|
//
|
||||||
|
// emitter.send(line);
|
||||||
|
//// Thread.sleep(1000);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// reader.close();
|
||||||
|
// } else {
|
||||||
|
// System.out.println("Request failed with status code: " + responseCode);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// connection.disconnect();
|
||||||
|
// emitter.complete();
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// emitter.completeWithError(e);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// return emitter;
|
||||||
|
|
||||||
|
// AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||||
|
// chatSendDTO.setUser_id(userInfo.getId());
|
||||||
|
// chatSendDTO.setUser_id(chatSendDTO.getUser_id());
|
||||||
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
|
.connectTimeout(30, TimeUnit.SECONDS)
|
||||||
|
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||||
|
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||||
|
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||||
|
.build();
|
||||||
|
MediaType mediaType = MediaType.parse("application/json");
|
||||||
|
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||||
|
String param = JSON.toJSONString(chatSendDTO, SerializerFeature.DisableCircularReferenceDetect);
|
||||||
|
log.info("chatRobot请求python 参数:####{}", param);
|
||||||
|
RequestBody body = RequestBody.create(mediaType, param);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url("http://18.167.251.121:9991/api/chat_stream_test")
|
||||||
|
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||||
|
.method("POST", body)
|
||||||
|
.addHeader("Content-Type", "application/json")
|
||||||
|
.build();
|
||||||
|
Response response = null;
|
||||||
try {
|
try {
|
||||||
// 这里根据你的业务逻辑,从服务获取数据
|
response = client.newCall(request).execute();
|
||||||
// 示例:从服务获取数据并逐条发送给客户端
|
} catch (IOException ioException) {
|
||||||
URL urlObj = new URL(chatStreamUrl);
|
log.error("PythonService##chatRobot异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||||
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
|
|
||||||
connection.setConnectTimeout(timeout);
|
|
||||||
connection.setReadTimeout(timeout);
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
|
|
||||||
OutputStream outputStream = connection.getOutputStream();
|
|
||||||
outputStream.write(requestBody.getBytes());
|
|
||||||
outputStream.flush();
|
|
||||||
outputStream.close();
|
|
||||||
|
|
||||||
int responseCode = connection.getResponseCode();
|
|
||||||
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
log.info(line);
|
|
||||||
|
|
||||||
emitter.send(line);
|
|
||||||
// Thread.sleep(1000);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
reader.close();
|
if (Objects.isNull(response)) {
|
||||||
} else {
|
log.error("PythonService##chatRobot异常###{}", "response is empty!");
|
||||||
System.out.println("Request failed with status code: " + responseCode);
|
throw new BusinessException("system error!");
|
||||||
}
|
}
|
||||||
|
if (response.isSuccessful()) {
|
||||||
connection.disconnect();
|
try {
|
||||||
emitter.complete();
|
String responseBody = response.body().string();
|
||||||
} catch (Exception e) {
|
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||||
emitter.completeWithError(e);
|
JSONObject data = responseObject.getJSONObject("data");
|
||||||
|
if (null != data) {
|
||||||
|
ChatRobot chatRobot = new ChatRobot();
|
||||||
|
chatRobot.setResponseType(data.getString("response_type"));
|
||||||
|
chatRobot.setCompletionTokens(data.getLong("completion_tokens"));
|
||||||
|
chatRobot.setInput(data.getString("input"));
|
||||||
|
String output = data.getString("output");
|
||||||
|
chatRobot.setOutput(output);
|
||||||
|
chatRobot.setPromptTokens(data.getLong("prompt_tokens"));
|
||||||
|
chatRobot.setSessionId(data.getString("session_id"));
|
||||||
|
BigDecimal totalCost = data.getBigDecimal("total_cost");
|
||||||
|
chatRobot.setTotalCost(totalCost);
|
||||||
|
chatRobot.setTotalTokens(data.getLong("total_tokens"));
|
||||||
|
chatRobot.setUserId(chatSendDTO.getUser_id());
|
||||||
|
chatRobot.setCreateTime(LocalDateTime.now());
|
||||||
|
ChatRobotVO chatRobotVO = CopyUtil.copyObject(chatRobot, ChatRobotVO.class);
|
||||||
|
if (null != chatRobotVO.getResponseType() && "image".equals(chatRobotVO.getResponseType())) {
|
||||||
|
List<ChatRobotLibraryVO> chatRobotLibraryVOList = new ArrayList<>();
|
||||||
|
if (output.startsWith("[")) {
|
||||||
|
JSONArray array = JSONArray.parseArray(output);
|
||||||
|
if (array.size() == 0) {
|
||||||
|
chatRobot.setSuccessful(0);
|
||||||
|
chatRobotMapper.insert(chatRobot);
|
||||||
|
chatRobotVO.setOutput("I'm sorry, but I can't process your current request. Please rephrase it differently.");
|
||||||
|
}else {
|
||||||
|
chatRobot.setSuccessful(1);
|
||||||
|
chatRobotMapper.insert(chatRobot);
|
||||||
|
for (int i = 0; i < array.size(); i++) {
|
||||||
|
if (i >= 3) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
});
|
ChatRobotLibraryVO chatRobotLibraryVO = new ChatRobotLibraryVO();
|
||||||
return emitter;
|
String bucketName = "aida-sys-image";
|
||||||
|
String path = "images/" + array.getString(i);
|
||||||
|
QueryWrapper<Library> qw = new QueryWrapper<>();
|
||||||
|
qw.lambda().eq(Library::getUrl, bucketName + "/" + path);
|
||||||
|
qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id());
|
||||||
|
qw.lambda().last("limit 1");
|
||||||
|
List<Library> libraryList = libraryMapper.selectList(qw);
|
||||||
|
if (!CollectionUtils.isEmpty(libraryList)) {
|
||||||
|
chatRobotLibraryVO.setId(libraryList.get(0).getId());
|
||||||
|
}
|
||||||
|
String aidaSysImage = minioUtil.getPresignedUrl("aida-sys-image", "images/" + array.getString(i), 10);
|
||||||
|
chatRobotLibraryVO.setUrl(bucketName + "/" + path);
|
||||||
|
chatRobotLibraryVO.setPresignedUrl(aidaSysImage);
|
||||||
|
chatRobotLibraryVOList.add(chatRobotLibraryVO);
|
||||||
|
}
|
||||||
|
chatRobotVO.setChatRobotLibraryList(chatRobotLibraryVOList);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
chatRobot.setSuccessful(0);
|
||||||
|
chatRobotMapper.insert(chatRobot);
|
||||||
|
chatRobotVO.setOutput("I'm sorry, but I can't process your current request. Please rephrase it differently.");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
chatRobot.setSuccessful(1);
|
||||||
|
chatRobotMapper.insert(chatRobot);
|
||||||
|
}
|
||||||
|
return chatRobotVO;
|
||||||
|
}
|
||||||
|
throw new BusinessException("ChatRobot response data is null!");
|
||||||
|
}catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new BusinessException("ChatRobot exception!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,4 +238,63 @@ public class ChatRobotServiceImpl implements ChatRobotService {
|
|||||||
return String.valueOf(restTemplate.postForEntity(chatBufferFlushUrl, chatFlushDTO, String.class));
|
return String.valueOf(restTemplate.postForEntity(chatBufferFlushUrl, chatFlushDTO, String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Library pictureLikeOrUnLike(ChatRobotLibraryDTO chatRobotLibraryDTO) {
|
||||||
|
if (chatRobotLibraryDTO.getId() == null) {
|
||||||
|
Library library = new Library();
|
||||||
|
library.setAccountId(chatRobotLibraryDTO.getUserId());
|
||||||
|
library.setUrl(chatRobotLibraryDTO.getUrl());
|
||||||
|
library.setLevel1Type(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName());
|
||||||
|
String[] split = chatRobotLibraryDTO.getUrl().split("/");
|
||||||
|
if (split.length == 4) {
|
||||||
|
String level2Type = split[2];
|
||||||
|
if (level2Type != null && !level2Type.isEmpty()) {
|
||||||
|
library.setLevel2Type(Character.toUpperCase(level2Type.charAt(0)) + level2Type.substring(1));
|
||||||
|
}
|
||||||
|
String name = split[3];
|
||||||
|
if (name.contains(".")) {
|
||||||
|
library.setName(name.split("\\.")[0]);
|
||||||
|
}else {
|
||||||
|
library.setName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
library.setMd5(MD5Utils.encryptFile(minioUtil.download(library.getUrl())));
|
||||||
|
} catch (MinioException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
library.setCreateDate(new Date());
|
||||||
|
libraryMapper.insert(library);
|
||||||
|
return library;
|
||||||
|
}else {
|
||||||
|
libraryMapper.deleteById(chatRobotLibraryDTO.getId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigDecimal getBloodBars(Long userId) {
|
||||||
|
// QueryWrapper<ChatRobot> queryWrapper = new QueryWrapper<>();
|
||||||
|
// queryWrapper.select("user_id as userId", "SUM(total_cost) as totalCost");
|
||||||
|
// queryWrapper.lambda().eq(ChatRobot::getTotalCost, userId);
|
||||||
|
// queryWrapper.lambda().eq(ChatRobot::getSuccessful, 1);
|
||||||
|
// queryWrapper.lambda().ge(ChatRobot::getCreateTime, LocalDateTime.now().withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0));
|
||||||
|
QueryWrapper<ChatRobot> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("user_id", userId);
|
||||||
|
queryWrapper.ge("create_time", LocalDateTime.now().withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0));
|
||||||
|
queryWrapper.select("user_id", "SUM(total_cost) as total_cost");
|
||||||
|
queryWrapper.groupBy("user_id");
|
||||||
|
List<ChatRobot> chatRobots = chatRobotMapper.selectList(queryWrapper);
|
||||||
|
if(CollectionUtils.isEmpty(chatRobots)) {
|
||||||
|
return BigDecimal.ONE;
|
||||||
|
}else {
|
||||||
|
BigDecimal totalCost = BigDecimal.valueOf(5).subtract(chatRobots.get(0).getTotalCost());
|
||||||
|
BigDecimal result = totalCost.divide(BigDecimal.valueOf(5), 4, RoundingMode.HALF_UP);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import com.ai.da.common.config.exception.BusinessException;
|
|||||||
import com.ai.da.common.context.UserContext;
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.enums.*;
|
import com.ai.da.common.enums.*;
|
||||||
import com.ai.da.common.response.PageBaseResponse;
|
import com.ai.da.common.response.PageBaseResponse;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.*;
|
||||||
import com.ai.da.common.utils.DateUtil;
|
|
||||||
import com.ai.da.common.utils.FileUtil;
|
|
||||||
import com.ai.da.common.utils.MD5Utils;
|
|
||||||
import com.ai.da.mapper.CollectionElementMapper;
|
import com.ai.da.mapper.CollectionElementMapper;
|
||||||
import com.ai.da.mapper.entity.*;
|
import com.ai.da.mapper.entity.*;
|
||||||
import com.ai.da.mapper.entity.Collection;
|
import com.ai.da.mapper.entity.Collection;
|
||||||
@@ -69,6 +66,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
private LibraryModelPointService libraryModelPointService;
|
private LibraryModelPointService libraryModelPointService;
|
||||||
@Resource
|
@Resource
|
||||||
private TCollectionElementRelationService tCollectionElementRelationService;
|
private TCollectionElementRelationService tCollectionElementRelationService;
|
||||||
|
@Resource
|
||||||
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
@@ -78,12 +77,16 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(uploadDTO.getLevel1Type());
|
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(uploadDTO.getLevel1Type());
|
||||||
Assert.notNull(level1TypeEnum, "unknown parameter level1Type!");
|
Assert.notNull(level1TypeEnum, "unknown parameter level1Type!");
|
||||||
|
|
||||||
String path = calculateFileUrl(level1TypeEnum, userInfo.getId());
|
// String path = calculateFileUrl(level1TypeEnum, userInfo.getId());aida-collection-element
|
||||||
File file = FileUtil.upload(uploadDTO.getFile(), path);
|
String objectName = userInfo.getId() + "/" + level1TypeEnum.getRealName();
|
||||||
|
String path = minioUtil.upload("aida-collection-element", objectName, uploadDTO.getFile());
|
||||||
|
// File file = FileUtil.upload(uploadDTO.getFile(), path);
|
||||||
//保存element元素
|
//保存element元素
|
||||||
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, file);
|
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, path);
|
||||||
saveOne(collectionElement);
|
saveOne(collectionElement);
|
||||||
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
|
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
|
||||||
|
collectionElementVO.setMinioPath(collectionElementVO.getUrl());
|
||||||
|
collectionElementVO.setUrl(minioUtil.getPresignedUrl(collectionElementVO.getUrl(), 480));
|
||||||
collectionElementVO.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
collectionElementVO.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
return collectionElementVO;
|
return collectionElementVO;
|
||||||
}
|
}
|
||||||
@@ -91,8 +94,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
private String calculateFileUrl(CollectionLevel1TypeEnum level1TypeEnum, Long userId) {
|
private String calculateFileUrl(CollectionLevel1TypeEnum level1TypeEnum, Long userId) {
|
||||||
String rootPath = fileProperties.getSys().getPath();
|
String rootPath = fileProperties.getSys().getPath();
|
||||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||||
return rootPath + day + File.separator + "userFile" + File.separator + "collection"
|
return rootPath + day + "/" + "userFile" + "/collection"
|
||||||
+ File.separator + level1TypeEnum.getRealName() + File.separator + userId + File.separator+UUID.randomUUID().toString();
|
+ "/" + level1TypeEnum.getRealName() + "/" + userId + "/" + UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollectionElement resolveData(CollectionElementUploadDTO uploadDTO, AuthPrincipalVo userInfo, File file) {
|
private CollectionElement resolveData(CollectionElementUploadDTO uploadDTO, AuthPrincipalVo userInfo, File file) {
|
||||||
@@ -118,6 +121,29 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CollectionElement resolveData(CollectionElementUploadDTO uploadDTO, AuthPrincipalVo userInfo, String path) {
|
||||||
|
CollectionElement element = CopyUtil.copyObject(uploadDTO, CollectionElement.class);
|
||||||
|
element.setAccountId(userInfo.getId());
|
||||||
|
element.setCollectionId(0L);
|
||||||
|
element.setHasPin((byte) 0);
|
||||||
|
// String pictureCollectonName = fileName;
|
||||||
|
// //获取图片后缀
|
||||||
|
// String suffix = pictureCollectonName.substring(pictureCollectonName.lastIndexOf("."));
|
||||||
|
// //获取图片前缀
|
||||||
|
// String prefix = pictureCollectonName.substring(0,pictureCollectonName.lastIndexOf("."));
|
||||||
|
element.setName(DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD));
|
||||||
|
element.setUrl(path);
|
||||||
|
//按时区计算
|
||||||
|
element.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
|
||||||
|
// String linuxDomain = fileProperties.getLinuxDomain();
|
||||||
|
// if (!StringUtils.isEmpty(linuxDomain)) {
|
||||||
|
// //linux 系统
|
||||||
|
// String oldPath = fileProperties.getSys().getPath();
|
||||||
|
// element.setUrl(file.getAbsolutePath().replace(oldPath, linuxDomain));
|
||||||
|
// }
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
CollectionElement collectionElement = selectById(id);
|
CollectionElement collectionElement = selectById(id);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
|||||||
import com.ai.da.common.enums.DesignTypeEnum;
|
import com.ai.da.common.enums.DesignTypeEnum;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.CopyUtil;
|
||||||
import com.ai.da.common.utils.DateUtil;
|
import com.ai.da.common.utils.DateUtil;
|
||||||
|
import com.ai.da.common.utils.MinioUtil;
|
||||||
import com.ai.da.mapper.CollectionMapper;
|
import com.ai.da.mapper.CollectionMapper;
|
||||||
import com.ai.da.mapper.entity.Collection;
|
import com.ai.da.mapper.entity.Collection;
|
||||||
import com.ai.da.mapper.entity.CollectionElement;
|
import com.ai.da.mapper.entity.CollectionElement;
|
||||||
@@ -42,6 +43,8 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
|||||||
private CollectionMapper collectionMapper;
|
private CollectionMapper collectionMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private CollectionElementService collectionElementService;
|
private CollectionElementService collectionElementService;
|
||||||
|
@Resource
|
||||||
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
@@ -72,7 +75,7 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
|||||||
Assert.notEmpty(collectionElements,"collection element does not exist!");
|
Assert.notEmpty(collectionElements,"collection element does not exist!");
|
||||||
response.setCollectionId(id);
|
response.setCollectionId(id);
|
||||||
response.setMoodTemplateId(collection.getMoodTemplateId());
|
response.setMoodTemplateId(collection.getMoodTemplateId());
|
||||||
|
response.setMoodTemplateUrl(minioUtil.getPresignedUrl(collectionElementService.getById(response.getMoodTemplateId()).getUrl(), 10));
|
||||||
Map<String,List<CollectionElement>> maps = collectionElements
|
Map<String,List<CollectionElement>> maps = collectionElements
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
||||||
@@ -83,18 +86,21 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
|||||||
case MOOD_BOARD:
|
case MOOD_BOARD:
|
||||||
response.setMoodBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
response.setMoodBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
|
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case PRINT_BOARD:
|
case PRINT_BOARD:
|
||||||
response.setPrintBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
response.setPrintBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||||
d.setIsPin(o.getHasPin());
|
d.setIsPin(o.getHasPin());
|
||||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
|
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case SKETCH_BOARD:
|
case SKETCH_BOARD:
|
||||||
response.setSketchBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d) ->{
|
response.setSketchBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d) ->{
|
||||||
d.setIsPin(o.getHasPin());
|
d.setIsPin(o.getHasPin());
|
||||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
|
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case COLOR_BOARD:
|
case COLOR_BOARD:
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -687,7 +687,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
throw new BusinessException("DesignItemId not found elements for ax elements to like! ["+designLikeDTO.getDesignItemId());
|
throw new BusinessException("DesignItemId not found elements for ax elements to like! ["+designLikeDTO.getDesignItemId());
|
||||||
}
|
}
|
||||||
UserLike userLike = resolveUserLike(designLikeDTO.getUserGroupId(), designItem.getDesignId(),
|
UserLike userLike = resolveUserLike(designLikeDTO.getUserGroupId(), designItem.getDesignId(),
|
||||||
designLikeDTO.getDesignItemId(), tDesignPythonOutfits.get(0).getDesignUrl(), designLikeDTO.getTimeZone());
|
designLikeDTO.getDesignItemId(), designLikeDTO.getDesignPythonOutfitId(), tDesignPythonOutfits.get(0).getDesignUrl(), designLikeDTO.getTimeZone());
|
||||||
userLikeService.save(userLike);
|
userLikeService.save(userLike);
|
||||||
groupDetailId = userLike.getId();
|
groupDetailId = userLike.getId();
|
||||||
} else {
|
} else {
|
||||||
@@ -700,7 +700,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
throw new BusinessException("DesignItemId not found elements for ax elements to like! ["+designLikeDTO.getDesignItemId());
|
throw new BusinessException("DesignItemId not found elements for ax elements to like! ["+designLikeDTO.getDesignItemId());
|
||||||
}
|
}
|
||||||
UserLike userLike = resolveUserLike(userGroupId,
|
UserLike userLike = resolveUserLike(userGroupId,
|
||||||
designItem.getDesignId(), designLikeDTO.getDesignItemId(), tDesignPythonOutfits.get(0).getDesignUrl(), designLikeDTO.getTimeZone());
|
designItem.getDesignId(), designLikeDTO.getDesignItemId(), designLikeDTO.getDesignPythonOutfitId(), tDesignPythonOutfits.get(0).getDesignUrl(), designLikeDTO.getTimeZone());
|
||||||
userLikeService.save(userLike);
|
userLikeService.save(userLike);
|
||||||
groupDetailId = userLike.getId();
|
groupDetailId = userLike.getId();
|
||||||
}
|
}
|
||||||
@@ -748,12 +748,13 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
return num + thisElement.size();
|
return num + thisElement.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserLike resolveUserLike(Long userGroupId, Long designId, Long designItemId, String designUrl, String timeZone) {
|
private UserLike resolveUserLike(Long userGroupId, Long designId, Long designItemId, Long designPythonOutfitId, String designUrl, String timeZone) {
|
||||||
UserLike userLike = new UserLike();
|
UserLike userLike = new UserLike();
|
||||||
userLike.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
userLike.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||||
userLike.setDesignId(designId);
|
userLike.setDesignId(designId);
|
||||||
userLike.setUserLikeGroupId(userGroupId);
|
userLike.setUserLikeGroupId(userGroupId);
|
||||||
userLike.setDesignItemId(designItemId);
|
userLike.setDesignItemId(designItemId);
|
||||||
|
userLike.setDesignPythonOutfitId(designPythonOutfitId);
|
||||||
userLike.setUrl(designUrl);
|
userLike.setUrl(designUrl);
|
||||||
return userLike;
|
return userLike;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,13 @@ import com.ai.da.service.GenerateService;
|
|||||||
import com.ai.da.service.LibraryService;
|
import com.ai.da.service.LibraryService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import io.minio.errors.MinioException;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -196,7 +198,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper,Generate> im
|
|||||||
library.setLevel2Type(StringUtil.isNullOrEmpty(generateLikeDTO.getLevel2Type()) ? null : generateLikeDTO.getLevel2Type());
|
library.setLevel2Type(StringUtil.isNullOrEmpty(generateLikeDTO.getLevel2Type()) ? null : generateLikeDTO.getLevel2Type());
|
||||||
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
|
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
|
||||||
library.setUrl(imageUrl);
|
library.setUrl(imageUrl);
|
||||||
library.setMd5(MD5Utils.encryptFile(minioUtil.splitThenGetPreviewUrl(imageUrl,5),Boolean.FALSE));
|
try {
|
||||||
|
library.setMd5(MD5Utils.encryptFile(minioUtil.download(imageUrl)));
|
||||||
|
} catch (MinioException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
library.setCreateDate(DateUtil.getByTimeZone(generateLikeDTO.getTimeZone()));
|
library.setCreateDate(DateUtil.getByTimeZone(generateLikeDTO.getTimeZone()));
|
||||||
return library;
|
return library;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
private LibraryModelPointService libraryModelPointService;
|
private LibraryModelPointService libraryModelPointService;
|
||||||
@Resource
|
@Resource
|
||||||
private MinioUtil minioUtil;
|
private MinioUtil minioUtil;
|
||||||
@Value("minio.bucketName.mannequins")
|
@Value("${minio.bucketName.mannequins}")
|
||||||
private String mannequins;
|
private String mannequins;
|
||||||
@Value("minio.bucketName.users")
|
@Value("${minio.bucketName.users}")
|
||||||
private String users;
|
private String users;
|
||||||
|
|
||||||
private static List<String> top = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(),
|
private static List<String> top = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(),
|
||||||
@@ -124,9 +124,8 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
IPage<QueryLibraryPageVO> convert = page.convert((Function<Library, QueryLibraryPageVO>) library -> {
|
IPage<QueryLibraryPageVO> convert = page.convert((Function<Library, QueryLibraryPageVO>) library -> {
|
||||||
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library,QueryLibraryPageVO.class);
|
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library,QueryLibraryPageVO.class);
|
||||||
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
|
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
|
||||||
if (library.getUrl().startsWith("aida")){
|
libraryPageVO.setMinioPath(library.getUrl());
|
||||||
libraryPageVO.setUrl(minioUtil.splitThenGetPreviewUrl(library.getUrl(),480));
|
libraryPageVO.setUrl(minioUtil.getPresignedUrl(library.getUrl(),480));
|
||||||
}
|
|
||||||
if(finalMap != null && finalMap.containsKey(library.getId())){
|
if(finalMap != null && finalMap.containsKey(library.getId())){
|
||||||
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
|
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
|
||||||
}
|
}
|
||||||
@@ -151,8 +150,6 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
String bucketName = null;
|
String bucketName = null;
|
||||||
switch (level1TypeEnum) {
|
switch (level1TypeEnum) {
|
||||||
case MODELS:
|
case MODELS:
|
||||||
bucketName = mannequins;
|
|
||||||
break;
|
|
||||||
case MOOD_BOARD:
|
case MOOD_BOARD:
|
||||||
case PRINT_BOARD:
|
case PRINT_BOARD:
|
||||||
case SKETCH_BOARD:
|
case SKETCH_BOARD:
|
||||||
@@ -165,15 +162,18 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
}
|
}
|
||||||
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
|
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
|
||||||
//保存element元素
|
//保存element元素
|
||||||
Library library = resolveData(libraryUploadDTO, userInfo, filePath, bucketName);
|
Library library = resolveData(libraryUploadDTO, userInfo, filePath);
|
||||||
return CopyUtil.copyObject(library,LibraryUpdateVo.class);
|
LibraryUpdateVo libraryUpdateVo = CopyUtil.copyObject(library, LibraryUpdateVo.class);
|
||||||
|
libraryUpdateVo.setMinioPath(libraryUpdateVo.getUrl());
|
||||||
|
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(filePath, 480));
|
||||||
|
return libraryUpdateVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Library resolveData(LibraryUploadDTO uploadDTO, AuthPrincipalVo userInfo, String filePath, String bucketName) {
|
private Library resolveData(LibraryUploadDTO uploadDTO, AuthPrincipalVo userInfo, String filePath) {
|
||||||
Library library = CopyUtil.copyObject(uploadDTO, Library.class);
|
Library library = CopyUtil.copyObject(uploadDTO, Library.class);
|
||||||
library.setAccountId(userInfo.getId());
|
library.setAccountId(userInfo.getId());
|
||||||
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
|
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
|
||||||
library.setUrl(bucketName + File.separator + filePath);
|
library.setUrl(filePath);
|
||||||
//按时区计算
|
//按时区计算
|
||||||
library.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
|
library.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
|
||||||
// String linuxDomain = fileProperties.getLinuxDomain();
|
// String linuxDomain = fileProperties.getLinuxDomain();
|
||||||
@@ -189,7 +189,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
private String calculateFileUrl(LibraryLevel1TypeEnum level1TypeEnum, String level2Type, Long userId) {
|
private String calculateFileUrl(LibraryLevel1TypeEnum level1TypeEnum, String level2Type, Long userId) {
|
||||||
// String rootPath = fileProperties.getSys().getPath();
|
// String rootPath = fileProperties.getSys().getPath();
|
||||||
// String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
// String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||||
return StringUtils.isEmpty(level2Type) ? userId + File.separator + level1TypeEnum.getRealName() : userId + File.separator + level1TypeEnum.getRealName() + File.separator + level2Type;
|
return StringUtils.isEmpty(level2Type) ? userId + "/" + level1TypeEnum.getRealName().toLowerCase() : userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + level2Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -226,6 +226,16 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
|||||||
return CopyUtil.copyList(libraryMapper.selectList(queryWrapper),LibraryVo.class);
|
return CopyUtil.copyList(libraryMapper.selectList(queryWrapper),LibraryVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateLibraryLevel2Type(LibraryLevel2TypeUpdateDTO libraryLevel2TypeUpdateDTO) {
|
||||||
|
Library library = new Library();
|
||||||
|
library.setId(libraryLevel2TypeUpdateDTO.getLibraryId());
|
||||||
|
library.setLevel2Type(libraryLevel2TypeUpdateDTO.getLevel2Type());
|
||||||
|
QueryWrapper<Library> qw = new QueryWrapper<>();
|
||||||
|
qw.lambda().eq(Library::getId, libraryLevel2TypeUpdateDTO.getLibraryId());
|
||||||
|
return libraryMapper.update(library, qw) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
private Library selectById(Long id) {
|
private Library selectById(Long id) {
|
||||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("id", id);
|
queryWrapper.eq("id", id);
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.ai.da.service.impl;
|
package com.ai.da.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.ai.da.common.context.UserContext;
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.CopyUtil;
|
||||||
import com.ai.da.common.utils.DateUtil;
|
import com.ai.da.common.utils.DateUtil;
|
||||||
import com.ai.da.common.utils.MinioUtil;
|
import com.ai.da.common.utils.MinioUtil;
|
||||||
|
import com.ai.da.mapper.TDesignPythonOutfitMapper;
|
||||||
import com.ai.da.mapper.UserLikeGroupMapper;
|
import com.ai.da.mapper.UserLikeGroupMapper;
|
||||||
import com.ai.da.mapper.entity.Account;
|
import com.ai.da.mapper.entity.Account;
|
||||||
|
import com.ai.da.mapper.entity.TDesignPythonOutfit;
|
||||||
import com.ai.da.mapper.entity.UserLikeGroup;
|
import com.ai.da.mapper.entity.UserLikeGroup;
|
||||||
import com.ai.da.model.vo.*;
|
import com.ai.da.model.vo.*;
|
||||||
import com.ai.da.service.AccountService;
|
import com.ai.da.service.AccountService;
|
||||||
@@ -44,6 +47,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
@Resource
|
@Resource
|
||||||
private MinioUtil minioUtil;
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TDesignPythonOutfitMapper designPythonOutfitMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteUserGroup(Long userGroupId) {
|
public void deleteUserGroup(Long userGroupId) {
|
||||||
UserLikeGroup group = getById(userGroupId);
|
UserLikeGroup group = getById(userGroupId);
|
||||||
@@ -101,8 +107,13 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|||||||
Assert.notNull(group,"History does not exist!");
|
Assert.notNull(group,"History does not exist!");
|
||||||
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userGroupId);
|
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userGroupId);
|
||||||
userLikeVOS.forEach(o -> {
|
userLikeVOS.forEach(o -> {
|
||||||
if (o.getUrl().startsWith("aida-")) {
|
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||||
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 5));
|
QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
|
||||||
|
qw.lambda().eq(TDesignPythonOutfit::getDesignItemId, o.getDesignItemId());
|
||||||
|
List<TDesignPythonOutfit> tDesignPythonOutfits = designPythonOutfitMapper.selectList(qw);
|
||||||
|
if (CollectionUtil.isNotEmpty(tDesignPythonOutfits)) {
|
||||||
|
TDesignPythonOutfit tDesignPythonOutfit = tDesignPythonOutfits.get(0);
|
||||||
|
o.setDesignPythonOutfitId(tDesignPythonOutfit.getId());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
UserLikeCollectionVO userLikeCollection = collectionService.chooseCollection(group.getCollectionId());
|
UserLikeCollectionVO userLikeCollection = collectionService.chooseCollection(group.getCollectionId());
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import com.ai.da.common.utils.FileUtil;
|
|||||||
import com.ai.da.common.utils.MinioUtil;
|
import com.ai.da.common.utils.MinioUtil;
|
||||||
import com.ai.da.mapper.LibraryMapper;
|
import com.ai.da.mapper.LibraryMapper;
|
||||||
import com.ai.da.mapper.SysFileMapper;
|
import com.ai.da.mapper.SysFileMapper;
|
||||||
|
import com.ai.da.mapper.UserLikeMapper;
|
||||||
import com.ai.da.mapper.WorkspaceMapper;
|
import com.ai.da.mapper.WorkspaceMapper;
|
||||||
import com.ai.da.mapper.entity.Library;
|
import com.ai.da.mapper.entity.Library;
|
||||||
import com.ai.da.mapper.entity.SysFile;
|
import com.ai.da.mapper.entity.SysFile;
|
||||||
|
import com.ai.da.mapper.entity.UserLike;
|
||||||
import com.ai.da.mapper.entity.Workspace;
|
import com.ai.da.mapper.entity.Workspace;
|
||||||
import com.ai.da.model.dto.WorkspaceDTO;
|
import com.ai.da.model.dto.WorkspaceDTO;
|
||||||
import com.ai.da.model.enums.*;
|
import com.ai.da.model.enums.*;
|
||||||
@@ -20,8 +22,6 @@ import com.ai.da.model.vo.AuthPrincipalVo;
|
|||||||
import com.ai.da.model.vo.ModelVO;
|
import com.ai.da.model.vo.ModelVO;
|
||||||
import com.ai.da.model.vo.ModelsVO;
|
import com.ai.da.model.vo.ModelsVO;
|
||||||
import com.ai.da.model.vo.WorkspaceVO;
|
import com.ai.da.model.vo.WorkspaceVO;
|
||||||
import com.ai.da.service.LibraryService;
|
|
||||||
import com.ai.da.service.SysFileService;
|
|
||||||
import com.ai.da.service.WorkspaceService;
|
import com.ai.da.service.WorkspaceService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@@ -32,6 +32,7 @@ import org.apache.commons.fileupload.FileItemFactory;
|
|||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||||
|
|
||||||
@@ -40,8 +41,10 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +68,10 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
@Resource
|
@Resource
|
||||||
private MinioUtil minioUtil;
|
private MinioUtil minioUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserLikeMapper userLikeMapper;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<WorkspaceVO> selectWorkspacePage(IPage<WorkspaceVO> page, WorkspaceVO workspace) {
|
public IPage<WorkspaceVO> selectWorkspacePage(IPage<WorkspaceVO> page, WorkspaceVO workspace) {
|
||||||
return page.setRecords(baseMapper.selectWorkspacePage(page, workspace));
|
return page.setRecords(baseMapper.selectWorkspacePage(page, workspace));
|
||||||
@@ -124,7 +131,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
page.getRecords().forEach(o -> {
|
page.getRecords().forEach(o -> {
|
||||||
String url = o.getMannequinUrl();
|
String url = o.getMannequinUrl();
|
||||||
if (url.startsWith("aida-")) {
|
if (url.startsWith("aida-")) {
|
||||||
o.setMannequinUrl(minioUtil.getPresignedUrl(o.getMannequinUrl(), 10));
|
o.setMannequinUrl(minioUtil.getPresignedUrl(o.getMannequinUrl(), 60*24));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
vo.setPage(PageBaseResponse.success(page));
|
vo.setPage(PageBaseResponse.success(page));
|
||||||
@@ -230,22 +237,72 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
@Override
|
@Override
|
||||||
public void systemFileCopy() {
|
public void systemFileCopy() {
|
||||||
QueryWrapper<SysFile> sysFileQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysFile> sysFileQueryWrapper = new QueryWrapper<>();
|
||||||
|
// 迁移系统表图片
|
||||||
List<SysFile> sysFiles = sysFileMapper.selectList(sysFileQueryWrapper);
|
List<SysFile> sysFiles = sysFileMapper.selectList(sysFileQueryWrapper);
|
||||||
sysFiles.forEach(o -> {
|
for (SysFile sysFile : sysFiles) {
|
||||||
String url = o.getUrl();
|
String url = sysFile.getUrl();
|
||||||
|
if (url.contains("/download/")) {
|
||||||
String[] downloads = url.split("/download/");
|
String[] downloads = url.split("/download/");
|
||||||
if (downloads.length == 2) {
|
if (downloads.length == 2) {
|
||||||
String path = "/workspace/home/aida/file/" + downloads[1];
|
String linux = downloads[1];
|
||||||
File file = FileUtil.getFile("");
|
String windows = linux.replaceAll("/", "\\\\");
|
||||||
|
String path = "C:\\workspace\\fileData\\file\\" + windows;
|
||||||
|
File file = FileUtil.getFile(path);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
String uploadMinioPath = o.getLevel1Type().toLowerCase() + "/" + o.getLevel2Type().toLowerCase() + "/" + file.getName();
|
String uploadMinioPath = sysFile.getLevel1Type().toLowerCase() + "/" + sysFile.getLevel2Type().toLowerCase() + "/" + file.getName();
|
||||||
String bucketName = "aida-sys-image";
|
String bucketName = "aida-sys-image";
|
||||||
FileItem a = getMultipartFile(file, "A");
|
// boolean b = minioUtil.doesObjectExist(bucketName, uploadMinioPath);
|
||||||
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
// if (!b) {
|
||||||
minioUtil.upload(bucketName, uploadMinioPath, multipartFile);
|
// FileItem a = getMultipartFile(file, file.getName());
|
||||||
|
// MultipartFile multipartFile = new CommonsMultipartFile(a);
|
||||||
|
// minioUtil.upload(bucketName, uploadMinioPath, multipartFile, "");
|
||||||
|
// }
|
||||||
|
sysFile.setUrl(bucketName + "/" + uploadMinioPath);
|
||||||
|
sysFileMapper.updateById(sysFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
// 迁移用户上传library图片
|
||||||
|
QueryWrapper<Library> libraryQueryWrapper = new QueryWrapper<>();
|
||||||
|
List<Library> libraryList = libraryMapper.selectList(libraryQueryWrapper);
|
||||||
|
for (Library o : libraryList) {
|
||||||
|
String url = o.getUrl();
|
||||||
|
if (url.contains("/download/")) {
|
||||||
|
String[] downloads = url.split("/download/");
|
||||||
|
if (downloads.length == 2) {
|
||||||
|
String linux = downloads[1];
|
||||||
|
String windows = linux.replaceAll("/", "\\\\");
|
||||||
|
String path = "C:\\workspace\\fileData\\file\\" + windows;
|
||||||
|
File file = FileUtil.getFile(path);
|
||||||
|
if (file != null) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (StringUtils.isEmpty(o.getLevel2Type())) {
|
||||||
|
sb.append(o.getAccountId() + "/").append(o.getLevel1Type().toLowerCase() + "/").append(file.getName());
|
||||||
|
} else {
|
||||||
|
sb.append(o.getAccountId() + "/").append(o.getLevel1Type().toLowerCase() + "/").append(o.getLevel2Type().toLowerCase() + "/").append(file.getName());
|
||||||
|
}
|
||||||
|
String bucketName = "aida-users";
|
||||||
|
// boolean b = minioUtil.doesObjectExist(bucketName, sb.toString());
|
||||||
|
// if (!b) {
|
||||||
|
// FileItem a = getMultipartFile(file, file.getName());
|
||||||
|
// MultipartFile multipartFile = new CommonsMultipartFile(a);
|
||||||
|
// minioUtil.upload(bucketName, sb.toString(), multipartFile, "");
|
||||||
|
// }
|
||||||
|
o.setUrl(bucketName + "/" + sb);
|
||||||
|
libraryMapper.updateById(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 迁移like相关数据
|
||||||
|
// QueryWrapper<UserLike> userLikeQueryWrapper = new QueryWrapper<>();
|
||||||
|
// List<UserLike> userLikeList = userLikeMapper.selectList(userLikeQueryWrapper);
|
||||||
|
// if (!CollectionUtils.isEmpty(userLikeList)) {
|
||||||
|
// userLikeList.forEach(o -> {
|
||||||
|
// Long userLikeId = o.getId();
|
||||||
|
// });
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileItem getMultipartFile(File file, String fieldName){
|
private FileItem getMultipartFile(File file, String fieldName){
|
||||||
@@ -253,7 +310,8 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
||||||
|
|
||||||
// 使用 FileItemFactory 创建一个 FileItem 对象
|
// 使用 FileItemFactory 创建一个 FileItem 对象
|
||||||
FileItem item = factory.createItem(fieldName, "text/plain", true, file.getName());
|
String mimeType = getMimeType(file);
|
||||||
|
FileItem item = factory.createItem(fieldName, mimeType, true, file.getName());
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
@@ -271,6 +329,15 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getMimeType(File file) {
|
||||||
|
try {
|
||||||
|
return Files.probeContentType(file.toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<BizJson> getEnumValues(Class clazz) {
|
private List<BizJson> getEnumValues(Class clazz) {
|
||||||
List<BizJson> kvs = new ArrayList<BizJson>();
|
List<BizJson> kvs = new ArrayList<BizJson>();
|
||||||
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
|
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
|
||||||
|
|||||||
21
src/main/resources/mapper/ChatRobotMapper.xml
Normal file
21
src/main/resources/mapper/ChatRobotMapper.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ai.da.mapper.entity.ChatRobotMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="BaseResultMap" type="com.ai.da.mapper.entity.ChatRobot">
|
||||||
|
<id column="id" property="id" />
|
||||||
|
<result column="session_id" property="sessionId" />
|
||||||
|
<result column="input" property="input" />
|
||||||
|
<result column="response_type" property="responseType" />
|
||||||
|
<result column="output" property="output" />
|
||||||
|
<result column="prompt_tokens" property="promptTokens" />
|
||||||
|
<result column="total_cost" property="totalCost" />
|
||||||
|
<result column="total_tokens" property="totalTokens" />
|
||||||
|
<result column="completion_tokens" property="completionTokens" />
|
||||||
|
<result column="user_id" property="userId" />
|
||||||
|
<result column="create_time" property="createTime" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user