|
@ -1,9 +1,33 @@
|
|
|
package com.yihu.wlyy.web.gateway.controller;
|
|
|
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.service.common.SMSService;
|
|
|
import com.yihu.wlyy.service.common.account.PatientService;
|
|
|
import com.yihu.wlyy.util.NetworkUtil;
|
|
|
import com.yihu.wlyy.web.gateway.vo.DoctorModel;
|
|
|
import com.yihu.wlyy.web.gateway.vo.PatientModel;
|
|
|
import com.yihu.wlyy.web.gateway.vo.base.BaseResultModel;
|
|
|
import com.yihu.wlyy.web.gateway.vo.base.ResultBatchModel;
|
|
|
import com.yihu.wlyy.web.gateway.vo.base.ResultOneModel;
|
|
|
import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
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 javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by chenweida on 2017/8/17.
|
|
|
*/
|
|
@ -12,4 +36,70 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RequestMapping("/wlyygc/message")
|
|
|
@Api(description = "消息相关服务,包括短信,微信模板")
|
|
|
public class GcMessageController {
|
|
|
|
|
|
private Logger logger= LoggerFactory.getLogger(GcMessageController.class);
|
|
|
@Autowired
|
|
|
private WeiXinTempMsgSendUtils weiXinTempMsgSendUtils;
|
|
|
@Autowired
|
|
|
private PatientService patientService;
|
|
|
@Autowired
|
|
|
private SMSService smsService;
|
|
|
|
|
|
@RequestMapping(value = "/sendWXTemplate", method = RequestMethod.POST)
|
|
|
@ApiOperation("给患者发送微信模板消息")
|
|
|
public ResultBatchModel sendWXTemplate(
|
|
|
@ApiParam(name = "codes", value = "患者code(多个逗号分割)", required = true) @RequestParam(value = "codes", required = true) String codes,
|
|
|
@ApiParam(name = "templateId", value = "微信模板Id", required = true) @RequestParam(value = "templateId", required = true) String templateId,
|
|
|
@ApiParam(name = "teampolateJson", value = "微信模板内容json格式", required = true) @RequestParam(value = "teampolateJson", required = true) String teampolateJson,
|
|
|
@ApiParam(name = "url", value = "模板跳转的url", required = true) @RequestParam(value = "url", required = true) String url
|
|
|
) {
|
|
|
Integer success = 0;
|
|
|
Integer error = 0;
|
|
|
List<String> errorLiust = new ArrayList<>();
|
|
|
String[] codeArr = codes.split(",");
|
|
|
for (String code : codeArr) {
|
|
|
try {
|
|
|
Patient patient = patientService.findByCode(code);
|
|
|
weiXinTempMsgSendUtils.sendTemplateMessage(templateId, patient.getOpenid(), url, new JSONObject(teampolateJson));
|
|
|
success++;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("code "+code+"send Template error:"+e.getMessage());
|
|
|
error++;
|
|
|
errorLiust.add(code);
|
|
|
}
|
|
|
}
|
|
|
return new ResultBatchModel(success, error, errorLiust);
|
|
|
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/sendMobileMessage", method = RequestMethod.POST)
|
|
|
@ApiOperation("给手机号码发送短信消息")
|
|
|
public ResultBatchModel sendMobileMessage(
|
|
|
@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,
|
|
|
HttpServletRequest request
|
|
|
) {
|
|
|
// 获取ip地址
|
|
|
Integer success = 0;
|
|
|
Integer error = 0;
|
|
|
List<String> errorLiust = new ArrayList<>();
|
|
|
try {
|
|
|
String ip = NetworkUtil.getIpAddress(request);
|
|
|
|
|
|
String[] mobileArr = mobiles.split(",");
|
|
|
for (String mobile : mobileArr) {
|
|
|
try {
|
|
|
smsService.sendWithContent(mobile, ip, 11, content);
|
|
|
success++;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("mobile "+mobile+"send message error:"+e.getMessage());
|
|
|
error++;
|
|
|
errorLiust.add(mobile);
|
|
|
}
|
|
|
}
|
|
|
return new ResultBatchModel(success, error, errorLiust);
|
|
|
} catch (Exception e) {
|
|
|
return new ResultBatchModel(BaseResultModel.codeEm.error_no_ip.getCode(), "获取IP失败", success, error, errorLiust);
|
|
|
}
|
|
|
}
|
|
|
}
|