TASK:机器人、首页、history模块代码;
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
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.ChatRobotLibraryDTO;
|
||||
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 java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author aida
|
||||
* @version 1.0
|
||||
@@ -12,7 +18,11 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
* @date 2023/7/25 16:42:18
|
||||
*/
|
||||
public interface ChatRobotService {
|
||||
SseEmitter sendMessageToChatRobot(ChatSendDTO chatSendDTO);
|
||||
ChatRobotVO sendMessageToChatRobot(ChatSendDTO chatSendDTO);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Boolean updateLibraryLevel2Type(LibraryLevel2TypeUpdateDTO libraryLevel2TypeUpdateDTO);
|
||||
}
|
||||
|
||||
@@ -3,23 +3,55 @@
|
||||
|
||||
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.ChatRobotLibraryDTO;
|
||||
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.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.GsonBuilder;
|
||||
import io.minio.errors.MinioException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
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.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author aida
|
||||
@@ -38,56 +70,166 @@ public class ChatRobotServiceImpl implements ChatRobotService {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@Resource
|
||||
private ChatRobotMapper chatRobotMapper;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Resource
|
||||
private LibraryMapper libraryMapper;
|
||||
|
||||
|
||||
Gson gson = new GsonBuilder().create();
|
||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
Integer timeout = 99999999;
|
||||
|
||||
@Override
|
||||
public SseEmitter sendMessageToChatRobot(ChatSendDTO chatSendDTO) {
|
||||
SseEmitter emitter = new SseEmitter();
|
||||
String requestBody = gson.toJson(chatSendDTO);
|
||||
executorService.execute(() -> {
|
||||
public ChatRobotVO sendMessageToChatRobot(ChatSendDTO chatSendDTO) {
|
||||
// SseEmitter emitter = new SseEmitter();
|
||||
// String requestBody = gson.toJson(chatSendDTO);
|
||||
// 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 {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##chatRobot异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
}
|
||||
if (Objects.isNull(response)) {
|
||||
log.error("PythonService##chatRobot异常###{}", "response is empty!");
|
||||
throw new BusinessException("system error!");
|
||||
}
|
||||
if (response.isSuccessful()) {
|
||||
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);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
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();
|
||||
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);
|
||||
}
|
||||
reader.close();
|
||||
} else {
|
||||
System.out.println("Request failed with status code: " + responseCode);
|
||||
return chatRobotVO;
|
||||
}
|
||||
|
||||
connection.disconnect();
|
||||
emitter.complete();
|
||||
} catch (Exception e) {
|
||||
emitter.completeWithError(e);
|
||||
throw new BusinessException("ChatRobot response data is null!");
|
||||
}catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
return emitter;
|
||||
}
|
||||
throw new BusinessException("ChatRobot exception!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,4 +238,63 @@ public class ChatRobotServiceImpl implements ChatRobotService {
|
||||
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.enums.*;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
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.common.utils.*;
|
||||
import com.ai.da.mapper.CollectionElementMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
@@ -69,6 +66,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
private LibraryModelPointService libraryModelPointService;
|
||||
@Resource
|
||||
private TCollectionElementRelationService tCollectionElementRelationService;
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
@@ -78,12 +77,16 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(uploadDTO.getLevel1Type());
|
||||
Assert.notNull(level1TypeEnum, "unknown parameter level1Type!");
|
||||
|
||||
String path = calculateFileUrl(level1TypeEnum, userInfo.getId());
|
||||
File file = FileUtil.upload(uploadDTO.getFile(), path);
|
||||
// String path = calculateFileUrl(level1TypeEnum, userInfo.getId());aida-collection-element
|
||||
String objectName = userInfo.getId() + "/" + level1TypeEnum.getRealName();
|
||||
String path = minioUtil.upload("aida-collection-element", objectName, uploadDTO.getFile());
|
||||
// File file = FileUtil.upload(uploadDTO.getFile(), path);
|
||||
//保存element元素
|
||||
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, file);
|
||||
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, path);
|
||||
saveOne(collectionElement);
|
||||
CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class);
|
||||
collectionElementVO.setMinioPath(collectionElementVO.getUrl());
|
||||
collectionElementVO.setUrl(minioUtil.getPresignedUrl(collectionElementVO.getUrl(), 480));
|
||||
collectionElementVO.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
return collectionElementVO;
|
||||
}
|
||||
@@ -91,8 +94,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
private String calculateFileUrl(CollectionLevel1TypeEnum level1TypeEnum, Long userId) {
|
||||
String rootPath = fileProperties.getSys().getPath();
|
||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||
return rootPath + day + File.separator + "userFile" + File.separator + "collection"
|
||||
+ File.separator + level1TypeEnum.getRealName() + File.separator + userId + File.separator+UUID.randomUUID().toString();
|
||||
return rootPath + day + "/" + "userFile" + "/collection"
|
||||
+ "/" + level1TypeEnum.getRealName() + "/" + userId + "/" + UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private CollectionElement resolveData(CollectionElementUploadDTO uploadDTO, AuthPrincipalVo userInfo, File file) {
|
||||
@@ -118,6 +121,29 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
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
|
||||
public void delete(Long 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.utils.CopyUtil;
|
||||
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.entity.Collection;
|
||||
import com.ai.da.mapper.entity.CollectionElement;
|
||||
@@ -42,6 +43,8 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
||||
private CollectionMapper collectionMapper;
|
||||
@Resource
|
||||
private CollectionElementService collectionElementService;
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
@@ -72,7 +75,7 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
||||
Assert.notEmpty(collectionElements,"collection element does not exist!");
|
||||
response.setCollectionId(id);
|
||||
response.setMoodTemplateId(collection.getMoodTemplateId());
|
||||
|
||||
response.setMoodTemplateUrl(minioUtil.getPresignedUrl(collectionElementService.getById(response.getMoodTemplateId()).getUrl(), 10));
|
||||
Map<String,List<CollectionElement>> maps = collectionElements
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));
|
||||
@@ -83,18 +86,21 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
|
||||
case MOOD_BOARD:
|
||||
response.setMoodBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||
}));
|
||||
break;
|
||||
case PRINT_BOARD:
|
||||
response.setPrintBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d)->{
|
||||
d.setIsPin(o.getHasPin());
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||
}));
|
||||
break;
|
||||
case SKETCH_BOARD:
|
||||
response.setSketchBoards(CopyUtil.copyList(v,CollectionElementVO.class,(o,d) ->{
|
||||
d.setIsPin(o.getHasPin());
|
||||
d.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||
d.setUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||
}));
|
||||
break;
|
||||
case COLOR_BOARD:
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
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());
|
||||
}
|
||||
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);
|
||||
groupDetailId = userLike.getId();
|
||||
} 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());
|
||||
}
|
||||
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);
|
||||
groupDetailId = userLike.getId();
|
||||
}
|
||||
@@ -748,12 +748,13 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
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.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
userLike.setDesignId(designId);
|
||||
userLike.setUserLikeGroupId(userGroupId);
|
||||
userLike.setDesignItemId(designItemId);
|
||||
userLike.setDesignPythonOutfitId(designPythonOutfitId);
|
||||
userLike.setUrl(designUrl);
|
||||
return userLike;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,13 @@ import com.ai.da.service.GenerateService;
|
||||
import com.ai.da.service.LibraryService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import io.minio.errors.MinioException;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@@ -196,7 +198,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper,Generate> im
|
||||
library.setLevel2Type(StringUtil.isNullOrEmpty(generateLikeDTO.getLevel2Type()) ? null : generateLikeDTO.getLevel2Type());
|
||||
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
|
||||
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()));
|
||||
return library;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
private LibraryModelPointService libraryModelPointService;
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
@Value("minio.bucketName.mannequins")
|
||||
@Value("${minio.bucketName.mannequins}")
|
||||
private String mannequins;
|
||||
@Value("minio.bucketName.users")
|
||||
@Value("${minio.bucketName.users}")
|
||||
private String users;
|
||||
|
||||
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 -> {
|
||||
QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library,QueryLibraryPageVO.class);
|
||||
libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName());
|
||||
if (library.getUrl().startsWith("aida")){
|
||||
libraryPageVO.setUrl(minioUtil.splitThenGetPreviewUrl(library.getUrl(),480));
|
||||
}
|
||||
libraryPageVO.setMinioPath(library.getUrl());
|
||||
libraryPageVO.setUrl(minioUtil.getPresignedUrl(library.getUrl(),480));
|
||||
if(finalMap != null && finalMap.containsKey(library.getId())){
|
||||
libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId()));
|
||||
}
|
||||
@@ -151,8 +150,6 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
String bucketName = null;
|
||||
switch (level1TypeEnum) {
|
||||
case MODELS:
|
||||
bucketName = mannequins;
|
||||
break;
|
||||
case MOOD_BOARD:
|
||||
case PRINT_BOARD:
|
||||
case SKETCH_BOARD:
|
||||
@@ -165,15 +162,18 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
}
|
||||
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
|
||||
//保存element元素
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, filePath, bucketName);
|
||||
return CopyUtil.copyObject(library,LibraryUpdateVo.class);
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, filePath);
|
||||
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.setAccountId(userInfo.getId());
|
||||
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()));
|
||||
// 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) {
|
||||
// String rootPath = fileProperties.getSys().getPath();
|
||||
// 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
|
||||
@@ -226,6 +226,16 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
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) {
|
||||
QueryWrapper<Library> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", id);
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.TDesignPythonOutfitMapper;
|
||||
import com.ai.da.mapper.UserLikeGroupMapper;
|
||||
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.model.vo.*;
|
||||
import com.ai.da.service.AccountService;
|
||||
@@ -44,6 +47,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Resource
|
||||
private TDesignPythonOutfitMapper designPythonOutfitMapper;
|
||||
|
||||
@Override
|
||||
public void deleteUserGroup(Long userGroupId) {
|
||||
UserLikeGroup group = getById(userGroupId);
|
||||
@@ -101,8 +107,13 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
Assert.notNull(group,"History does not exist!");
|
||||
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userGroupId);
|
||||
userLikeVOS.forEach(o -> {
|
||||
if (o.getUrl().startsWith("aida-")) {
|
||||
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 5));
|
||||
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 10));
|
||||
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());
|
||||
|
||||
@@ -10,9 +10,11 @@ import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.LibraryMapper;
|
||||
import com.ai.da.mapper.SysFileMapper;
|
||||
import com.ai.da.mapper.UserLikeMapper;
|
||||
import com.ai.da.mapper.WorkspaceMapper;
|
||||
import com.ai.da.mapper.entity.Library;
|
||||
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.model.dto.WorkspaceDTO;
|
||||
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.ModelsVO;
|
||||
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
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.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
@@ -40,8 +41,10 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,6 +68,10 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Resource
|
||||
private UserLikeMapper userLikeMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<WorkspaceVO> selectWorkspacePage(IPage<WorkspaceVO> page, WorkspaceVO workspace) {
|
||||
return page.setRecords(baseMapper.selectWorkspacePage(page, workspace));
|
||||
@@ -124,7 +131,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
page.getRecords().forEach(o -> {
|
||||
String url = o.getMannequinUrl();
|
||||
if (url.startsWith("aida-")) {
|
||||
o.setMannequinUrl(minioUtil.getPresignedUrl(o.getMannequinUrl(), 10));
|
||||
o.setMannequinUrl(minioUtil.getPresignedUrl(o.getMannequinUrl(), 60*24));
|
||||
}
|
||||
});
|
||||
vo.setPage(PageBaseResponse.success(page));
|
||||
@@ -230,22 +237,72 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
@Override
|
||||
public void systemFileCopy() {
|
||||
QueryWrapper<SysFile> sysFileQueryWrapper = new QueryWrapper<>();
|
||||
// 迁移系统表图片
|
||||
List<SysFile> sysFiles = sysFileMapper.selectList(sysFileQueryWrapper);
|
||||
sysFiles.forEach(o -> {
|
||||
String url = o.getUrl();
|
||||
String[] downloads = url.split("/download/");
|
||||
if (downloads.length == 2) {
|
||||
String path = "/workspace/home/aida/file/" + downloads[1];
|
||||
File file = FileUtil.getFile("");
|
||||
if (file != null) {
|
||||
String uploadMinioPath = o.getLevel1Type().toLowerCase() + "/" + o.getLevel2Type().toLowerCase() + "/" + file.getName();
|
||||
String bucketName = "aida-sys-image";
|
||||
FileItem a = getMultipartFile(file, "A");
|
||||
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
||||
minioUtil.upload(bucketName, uploadMinioPath, multipartFile);
|
||||
for (SysFile sysFile : sysFiles) {
|
||||
String url = sysFile.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) {
|
||||
String uploadMinioPath = sysFile.getLevel1Type().toLowerCase() + "/" + sysFile.getLevel2Type().toLowerCase() + "/" + file.getName();
|
||||
String bucketName = "aida-sys-image";
|
||||
// boolean b = minioUtil.doesObjectExist(bucketName, uploadMinioPath);
|
||||
// if (!b) {
|
||||
// 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){
|
||||
@@ -253,7 +310,8 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
||||
|
||||
// 使用 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];
|
||||
int bytesRead;
|
||||
@@ -271,6 +329,15 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
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) {
|
||||
List<BizJson> kvs = new ArrayList<BizJson>();
|
||||
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
|
||||
|
||||
Reference in New Issue
Block a user