Quellcode durchsuchen

医生助手模板消息

wujunjie vor 7 Jahren
Ursprung
Commit
df773bfc14

+ 24 - 26
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorFeldsherTemplateService.java

@ -238,40 +238,38 @@ public class DoctorFeldsherTemplateService extends BaseService {
    }
    /**
     * 拼装医生助手 医生类模板消息 并发送到IM
     * @param templateId 微信模板Id
     * @param receiver 接收者openid
     * @param url 模板跳转链接
     * @param first 头消息
     * @param remark 备注消息
     * @param keywords 消息体
     *  拼装医生助手 医生类模板消息并发送
     * @param doctorCode 医生code
     * @param sessionId 会话Id
     * @param sessionType 会话类型
     * @param businessType 消息类型
     * @param from 发送者
     * @param content 消息内容
     * @return
     */
    public Boolean sendDoctorTemplate(String templateId,String receiver,String url,String first,String remark,String ... keywords) {
        try{
    public Boolean sendDoctorTemplate(String doctorCode, String sessionId, String sessionType, String businessType, String from, String content) {
        try {
            String remark = "请进入手机APP查看,如尚未安装APP请点击详情下载安装";
            String url = "www.baidu.com";
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
            JSONObject sendJson = new JSONObject();
            for (int i=0;i<keywords.length;i++) {
                sendJson.put("keyword"+i, keywords[i]);
            }
            Doctor doctor = doctorDao.findByCode(doctorCode);
            String doctorName = doctor.getName();
            String doctorOpenId = doctor.getOpenid();
            String first = businessType;
            sendJson.put("keyword1", content);
            sendJson.put("keyword2", dateFormat.format(new Date()));
            sendJson.put("first", first);
            sendJson.put("remark", remark);
            sendJson.put("url", url);//带参数的模板跳转链接
            sendJson.put("templateId", templateId);//微信模板Id
            JSONObject participants = new JSONObject();
            participants.put("system",0);
            participants.put(receiver,0);
            JSONObject sessionObj  = imUtill.createSession(participants,ImUtill.SESSION_TYPE_SYSTEM,"系统消息","");
            if(sessionObj.getInt("status")==-1){
                throw  new RuntimeException(sessionObj.getString("message"));
            }
            JSONObject session = sessionObj.getJSONObject("data");
//            imUtill.sendImMsg("system","系统",session.getString("id"),"1", msg,businessType);
            imUtill.sendImMsg("system","系统",session.getString("id"),"1", sendJson.toString(),"1");
            pushMsgTask.putWxMsg(weiXinAccessTokenUtils.getAccessToken(), 11, doctorOpenId, doctorName, sendJson);
            logger.info("sendJson: " + sendJson);
            return true;
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }
}

+ 69 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/template/DoctorFeldsherTemplateController.java

@ -0,0 +1,69 @@
package com.yihu.wlyy.web.doctor.template;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.template.DoctorGuidanceTemp;
import com.yihu.wlyy.repository.template.DoctorGuidanceTempDao;
import com.yihu.wlyy.service.template.DoctorFeldsherTemplateService;
import com.yihu.wlyy.service.template.DoctorGuidanceTempService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
 * 医生健康指导模板
 * <p>
 * Created by Reece on 2017/9/14.
 */
@RestController
@RequestMapping(value = "/doctor/feldsher")
@Api(description = "医生健康指导模板")
public class DoctorFeldsherTemplateController extends BaseController {
    @Autowired
    private DoctorFeldsherTemplateService feldsherTemplateService;
    @Autowired
    DoctorGuidanceTempDao guidanceTempDao;
    /**
     * @param doctorCode   医生code
     * @param sessionId    会话Id
     * @param sessionType  会话类型
     * @param businessType 消息类型
     * @param from         发送者
     * @param content      消息内容
     * @return
     */
    @RequestMapping(value = "/sendDoctorTemplate", method = RequestMethod.GET)
    @ApiOperation(value = "医生助手给医生发送模板消息")
    public String sendDoctorTemplate(@RequestParam @ApiParam(value = "医生code") String doctorCode,
                                     @RequestParam @ApiParam(value = "会话Id", required = false) String sessionId,
                                     @RequestParam @ApiParam(value = "会话类型", required = false) String sessionType,
                                     @RequestParam @ApiParam(value = "消息类型") String businessType,
                                     @RequestParam @ApiParam(value = "发送者", required = false) String from,
                                     @RequestParam @ApiParam(value = "消息内容") String content) {
        try {
            Boolean flag = feldsherTemplateService.sendDoctorTemplate(doctorCode, sessionId, sessionType, businessType, from, content);
            if (flag){
                return write(200, "发送成功!");
            }else {
                return write( -1, "发送失败!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return invalidUserException(e, -1, "发送失败!");
        }
    }
}