package com.goafanti.baiduAI.service.impl; import com.alibaba.fastjson.JSON; import com.goafanti.baiduAI.BaiduChatErrorEnums; import com.goafanti.baiduAI.bo.*; import com.goafanti.baiduAI.service.BaiduAiService; import com.goafanti.common.bo.SseEmitterUTF8; import com.goafanti.common.dao.ErnieBotCommonDao; import com.goafanti.common.error.BusinessException; import com.goafanti.common.model.ErnieBotCommon; import com.goafanti.common.utils.BaiduChatUtils; import com.goafanti.common.utils.HttpUtils; import com.goafanti.common.utils.LoggerUtils; import com.goafanti.common.utils.RedisUtil; import com.goafanti.core.shiro.cache.ShiroRedisCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; import javax.annotation.Resource; import java.io.IOException; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class BaiduAiServiceImpl implements BaiduAiService { @Autowired private ErnieBotCommonDao ernieBotCommonDao; @Autowired private BaiduChatUtils baiduChatUtils; @Override public SseEmitterUTF8 sendChat(InputSendChat in) { SseEmitterUTF8 sseEmitter = new SseEmitterUTF8(3600_000L); // if (clientId==null)clientId=UUID.randomUUID().toString(); SseMap.sseEmitterMap.put(in.getUserId(), new SseResult(in.getUserId(), System.currentTimeMillis(), sseEmitter)); try { // 先将数据返回,异步调用返回数据 baiduChatUtils.sendBaiduAiStream(in); } catch (IOException e) { e.printStackTrace(); throw new BusinessException("文言一心调用失败"+e.getLocalizedMessage()); } return sseEmitter; } @Override @Cacheable(value = "selectErnieBotCommonAll#300",key = "'page:'+'All'") public List selectErnieBotCommonAll(Integer count) { return ernieBotCommonDao.selectAll(count); } }