|
|
@@ -17,6 +17,7 @@ import com.inspur.device.mapper.SmsbDeviceChatKeyMapper;
|
|
|
import com.inspur.device.mapper.SmsbDeviceChatRecordMapper;
|
|
|
import com.inspur.device.service.ISmsbDeviceChatRecordService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
@@ -37,6 +38,7 @@ import java.util.List;
|
|
|
*/
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordService {
|
|
|
|
|
|
private final SmsbDeviceChatRecordMapper baseMapper;
|
|
|
@@ -91,6 +93,7 @@ public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordSer
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getName()), SmsbDeviceChatRecord::getName, bo.getName());
|
|
|
lqw.eq(bo.getDeviceId() != null, SmsbDeviceChatRecord::getDeviceId, bo.getDeviceId());
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), SmsbDeviceChatRecord::getDeviceName, bo.getDeviceName());
|
|
|
+ lqw.orderByDesc(SmsbDeviceChatRecord::getId);
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
|
@@ -149,6 +152,7 @@ public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordSer
|
|
|
@Override
|
|
|
public Boolean syncRecordFromDify() {
|
|
|
// 1、查询出本地保存的所有工作流 即API KEY
|
|
|
+ log.info("begin syncRecordFromDify do ... ");
|
|
|
List<SmsbDeviceChatKeyVo> chatKeyVOList = smsbDeviceChatKeyMapper.selectVoWithDevice();
|
|
|
if (CollectionUtils.isEmpty(chatKeyVOList)) {
|
|
|
return true;
|
|
|
@@ -158,6 +162,7 @@ public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordSer
|
|
|
for (SmsbDeviceChatKeyVo chatKey : chatKeyVOList) {
|
|
|
String requestUrl = difyBaseUrl + SYNC_CHAT_RECORD_URL + "?user=role&limit=20";
|
|
|
String apiKey = chatKey.getApiKey();
|
|
|
+ String tenantId = chatKey.getTenantId();
|
|
|
// 2、调用接口 获取数据
|
|
|
JSONObject difyResponse = getRecordFromDify(requestUrl,apiKey);
|
|
|
if (null == difyResponse) {
|
|
|
@@ -180,7 +185,7 @@ public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordSer
|
|
|
}
|
|
|
// 不存在 插入数据库
|
|
|
SmsbDeviceChatRecord addRecord = new SmsbDeviceChatRecord();
|
|
|
- createNewAddRecord(addRecord,rspData,chatKey);
|
|
|
+ createNewAddRecord(addRecord,rspData,chatKey,tenantId);
|
|
|
addRecordList.add(addRecord);
|
|
|
// 6、再获取对话内容
|
|
|
String requestDetailUrl = difyBaseUrl + SYNC_CHAT_DETAIL_URL + "?user=role&limit=100&conversation_id=" + difyId;
|
|
|
@@ -195,13 +200,14 @@ public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordSer
|
|
|
// 7 组装详情数据
|
|
|
for (DifyChatDetailRspData detailRspData : rspDetailDataList) {
|
|
|
SmsbDeviceChatDetail addDetail = new SmsbDeviceChatDetail();
|
|
|
- createNewAddDetail(addDetail,detailRspData);
|
|
|
+ createNewAddDetail(addDetail,detailRspData,tenantId);
|
|
|
addDetailList.add(addDetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
baseMapper.insertBatch(addRecordList);
|
|
|
smsbDeviceChatDetailMapper.insertBatch(addDetailList);
|
|
|
+ log.info("begin syncRecordFromDify,addRecordList.size = " + addRecordList.size() + ",addDetailList.size = " + addDetailList.size());
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -212,22 +218,24 @@ public class SmsbDeviceChatRecordServiceImpl implements ISmsbDeviceChatRecordSer
|
|
|
.orderByDesc(SmsbDeviceChatDetail::getId));
|
|
|
}
|
|
|
|
|
|
- private void createNewAddDetail(SmsbDeviceChatDetail addDetail, DifyChatDetailRspData detailRspData) {
|
|
|
+ private void createNewAddDetail(SmsbDeviceChatDetail addDetail, DifyChatDetailRspData detailRspData,String tenantId) {
|
|
|
addDetail.setConversationId(detailRspData.getConversation_id());
|
|
|
addDetail.setDifyId(detailRspData.getId());
|
|
|
addDetail.setQuery(detailRspData.getQuery());
|
|
|
addDetail.setAnswer(detailRspData.getAnswer());
|
|
|
addDetail.setCreatedAt(detailRspData.getCreated_at());
|
|
|
+ addDetail.setTenantId(tenantId);
|
|
|
addDetail.setCreateTime(DateUtil.date(detailRspData.getCreated_at() * 1000));
|
|
|
}
|
|
|
|
|
|
- private void createNewAddRecord(SmsbDeviceChatRecord addRecord, DifyChatRecordRspData rspData, SmsbDeviceChatKeyVo chatKey) {
|
|
|
+ private void createNewAddRecord(SmsbDeviceChatRecord addRecord, DifyChatRecordRspData rspData, SmsbDeviceChatKeyVo chatKey,String tenantId) {
|
|
|
addRecord.setDeviceId(chatKey.getDeviceId());
|
|
|
addRecord.setDeviceName(chatKey.getDeviceName());
|
|
|
addRecord.setCreatedAt(rspData.getCreated_at());
|
|
|
addRecord.setUpdatedAt(rspData.getUpdated_at());
|
|
|
addRecord.setDifyId(rspData.getId());
|
|
|
addRecord.setName(rspData.getName());
|
|
|
+ addRecord.setTenantId(tenantId);
|
|
|
addRecord.setCreateTime(DateUtil.date(rspData.getCreated_at() * 1000));
|
|
|
}
|
|
|
|