ソースを参照

IM咨询相关修改,上传语音添加修改

8 年 前
コミット
0269258553

+ 9 - 6
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -1440,8 +1440,9 @@ public class ConsultTeamService extends ConsultService {
     * @param ct
     * @param uid
     * @param oldConsultCode
     * @param isSend 是否转发患者咨询内容
     */
    public void addSeekHelpTeam(ConsultTeam ct, String uid,String oldConsultCode){
    public void addSeekHelpTeam(ConsultTeam ct, String uid,String oldConsultCode,int isSend){
        ct.setPatient(uid);
        //推送给IM文字消息
        JSONObject participants = new JSONObject();
@ -1454,8 +1455,9 @@ public class ConsultTeamService extends ConsultService {
        }
        JSONObject session = sessionJson.getJSONObject("data");
        if(StringUtils.isNotEmpty(oldConsultCode)){
            ct.setTeam(oldConsultCode);
            ConsultTeam oldConsult =  consultTeamDao.findByConsult(oldConsultCode);
            if(oldConsult!=null){
            if(oldConsult!=null&&isSend==1){
                ImUtill.sendImMsg(ct.getPatient(), ct.getDoctor(), session.getString("id"),"1","居民问题:" +oldConsult.getSymptoms());
                //推送给IM图片
                if (StringUtils.isNotEmpty(oldConsult.getImages())) {
@ -1486,7 +1488,7 @@ public class ConsultTeamService extends ConsultService {
     * @param uid
     * @param oldConsultCode
     */
    public void addSeekHelpOtherTeam(ConsultTeam ct, String uid,String oldConsultCode) throws Exception{
    public void addSeekHelpOtherTeam(ConsultTeam ct, String uid,String oldConsultCode,int isSend) throws Exception{
        // 设置患者信息
        ct.setPatient(uid);
        Doctor doctorTemp = doctorDao.findByCode(uid);
@ -1531,12 +1533,13 @@ public class ConsultTeamService extends ConsultService {
        //转发咨询问题
        if(StringUtils.isNotBlank(oldConsultCode)){
            Consult oldConsult = consultDao.findByCode(oldConsultCode);
            if(oldConsult!=null){
                ImUtill.sendImMsg(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"6",content);
            ct.setTeam(oldConsultCode);
            if(oldConsult!=null&&isSend==1){
                ImUtill.sendTopicIM(doctorTemp.getCode(),doctorTemp.getName(),consult.getCode(),"6",oldConsult.getSymptoms());
                if(StringUtils.isNotBlank(oldConsult.getImages())){
                    String imgs[] = oldConsult.getImages().split(",");
                    for(String url :imgs)
                        ImUtill.sendImMsg(doctorTemp.getCode(),doctorTemp.getName(),String.valueOf(jsonObject.hashCode()),"2",url);
                        ImUtill.sendTopicIM(doctorTemp.getCode(),doctorTemp.getName(),consult.getCode(),"2",url);
                }
            }
        }

+ 15 - 20
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/CommonUtil.java

@ -171,30 +171,25 @@ public class CommonUtil {
     * @return
     * @throws IOException
     */
    public static String copyTempVoice(String voices) throws IOException {
    public static String copyTempVoice(String voices) throws  Exception {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        // 语音保存路径
        String voicePath = SystemConf.getInstance().getVoicePath() + File.separator;
        String[] tempVoices = voices.split(",");
        String temp = "";
        for (String voice : tempVoices) {
            File file = new File(tempPath + voice);
            if (file.exists()) {
                // 目标文件
                File targetFile = new File(voicePath + voice);
                // 拷贝到指定路径
                FileUtils.copyFile(file, targetFile);
                // 删除临时文件
                FileUtils.forceDelete(file);
                if (temp.length() == 0) {
                    temp = SystemConf.getInstance().getVoiceServer() + voice;
                } else {
                    temp += "," + SystemConf.getInstance().getVoiceServer() + voice;
                }
        String serverUrl = SystemConf.getInstance().getSystemProperties().getProperty("fastdfs_file_url");
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileUrls = "";
        File f = new File(tempPath + voices);
        if (f.exists()) {
            String fileName = f.getName();
            InputStream in = new FileInputStream(f);
            ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
            in.close();
            if (result != null) {
                fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + serverUrl
                        + result.get("groupName").toString().replaceAll("\"", "") + "/"
                        + result.get("remoteFileName").toString().replaceAll("\"", "");
            }
        }
        return temp;
        return fileUrls;
    }
    /**

+ 3 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/ImUtill.java

@ -118,7 +118,7 @@ public class ImUtill {
    public static JSONObject createSession(JSONObject participants,String sessionType,String sessionName,String sessionId) {
        String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions";
        JSONObject params = new JSONObject();
        params.put("participants", participants);
        params.put("participants", participants.toString());
        params.put("session_name", sessionName);
        params.put("session_type", sessionType);
        params.put("session_id", sessionId);
@ -151,7 +151,7 @@ public class ImUtill {
        return messages;
    }
    public static JSONArray getTopicMessage(String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
    public static JSONObject getTopicMessage(String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
        String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
                + "api/v2/sessions/topic/"+topicId+"/messages?topic_id="+topicId+"&end="+startMsgId
                +"&start="+(endMsgId==null?"":endMsgId)+"&page="+page+"&pagesize="+pagesize+"&user="+uid;
@ -161,7 +161,7 @@ public class ImUtill {
            if(obj.getInt("status")==-1){
                throw new RuntimeException(obj.getString("message"));
            }else{
                return  obj.getJSONArray("data");
                return  obj.getJSONObject("data");
            }
        }catch (Exception e){
            return null;

+ 1 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/WeixinBaseController.java

@ -328,9 +328,6 @@ public class WeixinBaseController extends BaseController {
			while ((len = inputStream.read(data)) != -1) {
				fileOutputStream.write(data, 0, len);
			}
			// 生成缩略图
			//ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
			// 返回保存路径
			return datePath + newFileName;
		} catch (IOException e) {
			e.printStackTrace();
@ -427,7 +424,7 @@ public class WeixinBaseController extends BaseController {
		// 拼接年月日路径
		String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
		// 重命名文件
		String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".amr";
		String newFileName = DateUtil.dateToStr(new Date(), DateUtil.YYYYMMDDHHMMSS) + "_" + new Random().nextInt(1000) + ".wav";
		// 保存路径
		File uploadFile = new File(tempPath + datePath + newFileName);

+ 4 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -943,7 +943,8 @@ public class DoctorConsultController extends WeixinBaseController {
            @RequestParam(required = true) String symptoms,
            @RequestParam(required = false) String oldConsultCode,
            @RequestParam(required = false) String doctorCode,
            @RequestParam(required = false) String images){
            @RequestParam(required = false) String images,
            @RequestParam(required = true) Integer isSend){
        try {
                if (StringUtils.isEmpty(images)) {
                    images = fetchWxImages();
@ -963,9 +964,9 @@ public class DoctorConsultController extends WeixinBaseController {
                consult.setDoctor(doctorCode);//设置专科医生
                // 保存到数据库
                if(consultTeamService.isCommonTeam(doctorCode, getUID())){
                    consultTeamService.addSeekHelpTeam(consult, getUID(), oldConsultCode);
                    consultTeamService.addSeekHelpTeam(consult, getUID(), oldConsultCode,isSend);
                }else{
                    consultTeamService.addSeekHelpOtherTeam(consult, getUID(), oldConsultCode);
                    consultTeamService.addSeekHelpOtherTeam(consult, getUID(), oldConsultCode,isSend);
                }
                return success("提交成功");
            } catch (Exception ex) {

+ 22 - 7
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -591,7 +591,7 @@ public class ConsultController extends WeixinBaseController {
     */
    @RequestMapping(value = "append")
    @ResponseBody
    public String append(@RequestParam String consult, @RequestParam String content, @RequestParam int type) {
    public String append(@RequestParam String consult, @RequestParam String content, @RequestParam int type,@RequestParam(required = false,defaultValue = "0") Integer times) {
        try {
            List<ConsultTeamLog> logs = new ArrayList<ConsultTeamLog>();
            ConsultTeam consultModel = consultTeamService.findByCode(consult);
@ -605,8 +605,24 @@ public class ConsultController extends WeixinBaseController {
            }
            String[] arr = null;
            if (type == 2) {
            if(type==3){
               String path =  fetchWxVoices();
               JSONObject obj = new JSONObject();
                // 将临时语音拷贝到正式存储路径下
                if (StringUtils.isNotEmpty(path)) {
                    content = CommonUtil.copyTempVoice(path);
                    obj.put("path",content);
                    obj.put("times",times);
                    content = obj.toString();
                }
                ConsultTeamLog log = new ConsultTeamLog();
                log.setConsult(consult);
                log.setContent(content);
                log.setDel("1");
                log.setChatType(type);
                log.setType(3);
                logs.add(log);
            }else if (type == 2) {
                // 图片消息
                if (StringUtils.isEmpty(content)) {
                    String images = request.getParameter("mediaIds");
@ -614,7 +630,6 @@ public class ConsultController extends WeixinBaseController {
                    if (!StringUtils.isEmpty(images)) {
                        arr = images.split(",");
                    }
                    content = fetchWxImages();
                } else {
                    arr = content.split(",");
                }
@ -658,7 +673,7 @@ public class ConsultController extends WeixinBaseController {
                    if(resObj.getInt("status")==-1){
                        return invalidUserException(new RuntimeException(resObj.getString("message")), -1, "追问失败!"+resObj.getString("message"));
                    }
                    failed.add(response);
                    failed.add(String.valueOf(resObj.get("data")));
                }
            }
            return write(200, "追问成功!", "data", failed);
@ -684,8 +699,8 @@ public class ConsultController extends WeixinBaseController {
            if (consultModel == null) {
                return error(-1, "咨询记录不存在!");
            }
           JSONArray array =  ImUtill.getTopicMessage(consultModel.getConsult(),consultModel.getStartMsgId(),consultModel.getEndMsgId(),page,pagesize,getUID());
            return write(200, "查询成功", "list", array);
            JSONObject messageObj =  ImUtill.getTopicMessage(consultModel.getConsult(),consultModel.getStartMsgId(),consultModel.getEndMsgId(),page,pagesize,getUID());
            return write(200, "查询成功", "list", messageObj);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");