|
|
@@ -1,19 +1,34 @@
|
|
|
package com.fs.handwrite.service.impl;
|
|
|
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.fastgptApi.param.ChatImgParam;
|
|
|
+import com.fs.fastgptApi.result.ChatDetailTStreamFResult;
|
|
|
+import com.fs.fastgptApi.service.ChatService;
|
|
|
import com.fs.handwrite.domain.HandwriteCollection;
|
|
|
import com.fs.handwrite.mapper.HandwriteCollectionMapper;
|
|
|
import com.fs.handwrite.service.IHandwriteCollectionService;
|
|
|
+import com.fs.his.domain.FsOrcAiRecord;
|
|
|
+import com.fs.his.param.CollectionOrcParam;
|
|
|
+import com.fs.his.service.IFsOrcAiRecordService;
|
|
|
+import com.fs.his.vo.CollectionOrcVO;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
+import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.logging.log4j.core.util.UuidUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 手写信息采集表Service业务层处理
|
|
|
@@ -31,6 +46,12 @@ public class HandwriteCollectionServiceImpl implements IHandwriteCollectionServi
|
|
|
@Autowired
|
|
|
private FsStoreOrderScrmMapper storeOrderScrmMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ChatService chatService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsOrcAiRecordService orcAiRecordService;
|
|
|
+
|
|
|
@Override
|
|
|
public HandwriteCollection selectHandwriteCollectionById(Integer id)
|
|
|
{
|
|
|
@@ -97,4 +118,60 @@ public class HandwriteCollectionServiceImpl implements IHandwriteCollectionServi
|
|
|
}
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public CollectionOrcVO imageProcess(CollectionOrcParam collectionOrcParam) {
|
|
|
+ if (StringUtils.isEmpty(collectionOrcParam.getImgUrl())) {
|
|
|
+ log.error("图片地址不能为空!");
|
|
|
+ throw new CustomException("图片地址不能为空!");
|
|
|
+ }
|
|
|
+ ChatImgParam param=new ChatImgParam();
|
|
|
+ param.setChatId(UuidUtil.getTimeBasedUuid().toString());
|
|
|
+ param.setStream(false);
|
|
|
+ param.setDetail(true);
|
|
|
+ List<ChatImgParam.Message> messageList=new ArrayList<ChatImgParam.Message>();
|
|
|
+ ChatImgParam.Message message = new ChatImgParam.Message();
|
|
|
+ message.setRole("user");
|
|
|
+ List<ChatImgParam.Message.content> contents = new ArrayList<>();
|
|
|
+
|
|
|
+ ChatImgParam.Message.content content = new ChatImgParam.Message.content();
|
|
|
+ content.setType("text");
|
|
|
+ content.setText("请根据提示词识别图片内容");
|
|
|
+ contents.add(content);
|
|
|
+
|
|
|
+ //设置上传的图片
|
|
|
+ ChatImgParam.Message.content contentImg = new ChatImgParam.Message.content();
|
|
|
+ contentImg.setType("image_url");
|
|
|
+ ChatImgParam.Message.ImageUrl imageUrl = new ChatImgParam.Message.ImageUrl();
|
|
|
+ imageUrl.setUrl(collectionOrcParam.getImgUrl());
|
|
|
+ contentImg.setImage_url(imageUrl);
|
|
|
+ contents.add(contentImg);
|
|
|
+
|
|
|
+ message.setContent(contents);
|
|
|
+ messageList.add(message);
|
|
|
+ param.setMessages(messageList);
|
|
|
+
|
|
|
+ R r = chatService.initiatingTakeChatNew(param, "http://129.28.170.206:3000/api", "fastgpt-vHaXxiy4g5pfQyFFwUsAAtqDHDpztftrVzXyh5hgMtcUjaE6dFupgKz");
|
|
|
+ if(!r.get("code").equals(200)){
|
|
|
+ CollectionOrcVO vo = new CollectionOrcVO();
|
|
|
+ vo.setIsParse(0);
|
|
|
+ }
|
|
|
+ ChatDetailTStreamFResult result=(ChatDetailTStreamFResult)r.get("data");
|
|
|
+
|
|
|
+ String contentKh = result.getChoices().get(0).getMessage().getContent();
|
|
|
+ System.out.println("模型解析图片结果:"+contentKh);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ CollectionOrcVO fromJson = gson.fromJson(contentKh, CollectionOrcVO.class);
|
|
|
+
|
|
|
+ //解析记录
|
|
|
+ FsOrcAiRecord record = new FsOrcAiRecord();
|
|
|
+ record.setCollectionId(collectionOrcParam.getCollectionId());
|
|
|
+ record.setCompanyUserId(collectionOrcParam.getCompanyUserId());
|
|
|
+ record.setImgUrl(collectionOrcParam.getImgUrl());
|
|
|
+ record.setCreateTime(new Date());
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ orcAiRecordService.insertFsOrcAiRecord(record);
|
|
|
+ return fromJson;
|
|
|
+ }
|
|
|
}
|