| 
					
				 | 
			
			
				@ -1,8 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.wlyy.web.third.gateway.controller.doctor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.doctor.profile.Doctor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.Patient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.wechat.WechatTemplateData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.doctor.DoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.SMSService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.common.account.PatientService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -13,18 +11,22 @@ import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.ApiOperation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.ApiParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.http.MediaType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Controller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.bind.annotation.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.ResponseBody; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.ExecutionException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by chenweida on 2017/8/17. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -108,67 +110,39 @@ public class GcMessageController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 客服系统发送消息接口 居民没有有openID只发手机短信 有openID发微信模板消息、手机短信 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 客服系统发送消息接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctorCodes 医生code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param openIds      微信openid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param content     消息内容限制字数70 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/sendMessage", method = RequestMethod.POST) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ApiOperation("客服系统发送消息接口") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/sendWechatMessage", method = RequestMethod.POST) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ApiOperation("客服系统发送微信模板消息接口") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ResultBatchModel sendMessage( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @ApiParam(name = "doctorCodes", value = "医生code(批量逗号分割)", required = true) @RequestParam(value = "doctorCodes", required = true) String doctorCodes, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @ApiParam(name = "openIds", value = "微信openid", required = true) @RequestParam(value = "openIds", required = true) String openIds, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            @ApiParam(name = "content", value = "消息内容", required = true) @RequestParam(value = "content", required = true) String content) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer success = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer error = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<String> errorLiust = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String templateId = "OqQXrb-e43_TJpq_70_K_y6vYJgY5mpjFYY4c5RWFP4"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String templateId = "OqQXrb-e43_TJpq_70_K_y6vYJgY5mpjFYY4c5RWFP4"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            String templateId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String url = "www.baidu.com";//要带基本地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String[] codeArr = doctorCodes.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String code : codeArr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Doctor doctor = doctorDao.findByCode(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String openId = doctor.getOpenid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String name = doctor.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String mobile = doctor.getMobile(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String url = "www.baidu.com";//要带基本地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String[] codeArr = openIds.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (String openId : codeArr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                String name = "吴家莲"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                String mobile = "13611153674"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isEmpty(openId) && StringUtils.isNotEmpty(mobile)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        smsService.sendMsg(mobile, content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        success++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        logger.error("mobile " + mobile + " send message error:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        error++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        errorLiust.add(mobile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else if (StringUtils.isNotEmpty(openId) && StringUtils.isNotEmpty(mobile)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        smsService.sendMsg(mobile, content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        success++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        logger.error("mobile " + mobile + " send message error:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        error++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        errorLiust.add(mobile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        JSONObject sendJson = packageTemplate("消息头","备注","续方提醒","2017年9月16日 18:00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        weiXinTempMsgSendUtils.sendTemplateMessage(templateId, openId, url, sendJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        success++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        logger.error("code " + code + " send Template error:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        error++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        errorLiust.add(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject sendJson = packageTemplate("消息头", "备注", "续方提醒", "2017年9月16日 18:00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                weiXinTempMsgSendUtils.sendTemplateMessage(templateId, openId, url, sendJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                success++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.error("openids " + openIds + " send Template error:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                error++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                errorLiust.add(openIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return new ResultBatchModel(success, error, errorLiust); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return new ResultBatchModel(-1, "找不到该医生!", success, error, errorLiust); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return new ResultBatchModel(success, error, errorLiust); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 |