|
@ -1,6 +1,7 @@
|
|
|
package com.yihu.wlyy.web.third.gateway.controller.doctor;
|
|
|
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
import com.yihu.wlyy.service.common.account.PatientService;
|
|
|
import com.yihu.wlyy.util.NetworkUtil;
|
|
@ -14,12 +15,15 @@ import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
@ -40,6 +44,13 @@ public class GcMessageController {
|
|
|
private PatientService patientService;
|
|
|
@Autowired
|
|
|
private SMSService smsService;
|
|
|
@Autowired
|
|
|
private PatientDao patientDao;
|
|
|
|
|
|
@Value("${wechat.message.template_consult_notice}")
|
|
|
private String templateId;
|
|
|
@Value("${server.server_url}")
|
|
|
private String server_url;
|
|
|
|
|
|
@RequestMapping(value = "/sendWXTemplate", method = RequestMethod.POST)
|
|
|
@ApiOperation("给患者发送微信模板消息")
|
|
@ -102,10 +113,93 @@ public class GcMessageController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/sendEduArticle", method = RequestMethod.POST)
|
|
|
@ApiOperation("给手机号码发送短信消息")
|
|
|
public ResultBatchModel sendEduArticle(){
|
|
|
/**
|
|
|
* 健康宣教微信模板消息通知
|
|
|
*
|
|
|
* @param title 指导标题
|
|
|
* @param hospitalName 指导机构名称
|
|
|
* @param doctorName 指导医生姓名
|
|
|
* @param patients 发送居民对象 多个以逗号分隔
|
|
|
* @param content 指导内容
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/sendWechatMessage", method = RequestMethod.POST)
|
|
|
@ApiOperation("健康宣教微信模板消息通知")
|
|
|
public ResultBatchModel sendWechatMessage(
|
|
|
@ApiParam(name = "title", value = "消息标题", required = true) @RequestParam(value = "title", required = true) String title,
|
|
|
@ApiParam(name = "hospitalName", value = "指导机构名称", required = true) @RequestParam(value = "hospitalName", required = true) String hospitalName,
|
|
|
@ApiParam(name = "doctorName", value = "指导医生姓名", required = true) @RequestParam(value = "doctorName", required = true) String doctorName,
|
|
|
@ApiParam(name = "patients", value = "指导对象", required = true) @RequestParam(value = "patients", required = true) String patients,
|
|
|
@ApiParam(name = "content", value = "指导内容", required = true) @RequestParam(value = "content", required = true) String content) {
|
|
|
Integer success = 0;
|
|
|
Integer error = 0;
|
|
|
String remark = "为了您和家人更健康,请仔细阅读健康指导内容,谢谢。";
|
|
|
List<String> errorLiust = new ArrayList<>();
|
|
|
try {
|
|
|
String url = server_url + "wx_doctor/html/home/html/jumpApp.html";
|
|
|
String[] codeArr = patients.split(",");
|
|
|
for (String people : codeArr) {
|
|
|
try {
|
|
|
Patient patient = patientDao.findByCode(people);
|
|
|
String openId = patient.getOpenid();
|
|
|
String name = patient.getName();
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
|
|
|
JSONObject sendJson = weiXinTempMsgSendUtils.packageTemplate(title, remark, dateFormat.format(new Date()),hospitalName,doctorName,name,content );
|
|
|
Boolean flag = weiXinTempMsgSendUtils.sendTemplateMessage(templateId, openId, url, sendJson);
|
|
|
logger.info("send wechat message param : title "+title+" hospitalName "+hospitalName+" doctorName "+doctorName+" patients "+patients+" content "+content);
|
|
|
logger.info("send wechat message retuen : " + flag + " =======> " + flag);
|
|
|
success++;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error("patient " + people + " send Template error:" + e.getMessage());
|
|
|
error++;
|
|
|
errorLiust.add(people);
|
|
|
}
|
|
|
}
|
|
|
return new ResultBatchModel(success, error, errorLiust);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return new ResultBatchModel(-1, "发送失败!", success, error, errorLiust);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
/**
|
|
|
* 健康宣教短信消息通知
|
|
|
*
|
|
|
* @param mobiles 手机号.多个用逗号分隔
|
|
|
* @param content
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/sendEduArticle", method = RequestMethod.POST)
|
|
|
@ApiOperation("健康宣教微信短信消息通知")
|
|
|
public ResultBatchModel sendEduArticle(
|
|
|
@ApiParam(name = "mobiles", value = "手机号(批量逗号分割)", required = true) @RequestParam(value = "mobiles", required = true) String mobiles,
|
|
|
@ApiParam(name = "content", value = "消息内容", required = true) @RequestParam(value = "content", required = true) String content) {
|
|
|
Integer success = 0;
|
|
|
Integer error = 0;
|
|
|
List<String> errorLiust = new ArrayList<>();
|
|
|
content = "【健康之路】" +content+
|
|
|
"社区的医生,给您发送了发送了健康教育文章,请点击以下网址查看www.yihu.com.xxxxx.xxx,关注【小薇社区】公众号,获取更多健康资讯。";
|
|
|
try {
|
|
|
String[] codeArr = mobiles.split(",");
|
|
|
for (String mobile : codeArr) {
|
|
|
try {
|
|
|
JSONObject result = smsService.sendMsg(mobile, content);
|
|
|
logger.info("send mobile message param : " + mobile + " ====> " + content);
|
|
|
logger.info("send mobile message return : " + result);
|
|
|
success++;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error("mobile " + mobile + " send message error:" + e.getMessage());
|
|
|
error++;
|
|
|
errorLiust.add(mobile);
|
|
|
}
|
|
|
}
|
|
|
return new ResultBatchModel(success, error, errorLiust);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return new ResultBatchModel(-1, "发送失败!", success, error, errorLiust);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|