Преглед изворни кода

医生助手发送短信,发送微信消息接口开发

chenyongxing пре 7 година
родитељ
комит
bee48ddc54

+ 26 - 9
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/controller/common/account/CustomerController.java

@ -1,15 +1,14 @@
package com.yihu.wlyy.controller.common.account;
import com.yihu.wlyy.controller.BaseController;
import com.yihu.wlyy.entity.Doctor;
import com.yihu.wlyy.entity.Patient;
import com.yihu.wlyy.entity.User;
import com.yihu.wlyy.entity.WlyyCustomerLog;
import com.yihu.wlyy.repository.ManageDictDao;
import com.yihu.wlyy.repository.PatientDao;
import com.yihu.wlyy.service.manager.account.CustomerService;
import com.yihu.wlyy.service.manager.family.FamilyMemberService;
import com.yihu.wlyy.service.manager.hos.HosDoctorService;
import com.yihu.wlyy.service.manager.patient.AdminPatientService;
import com.yihu.wlyy.service.manager.sign.SignFamilyService;
import com.yihu.wlyy.service.manager.user.UserService;
import com.yihu.wlyy.service.manager.user.WlyyCustomerLogService;
import io.swagger.annotations.ApiParam;
@ -37,15 +36,9 @@ public class CustomerController extends BaseController {
    @Autowired
    private UserService userService;
    @Autowired
    private ManageDictDao manageDictDao;
    @Autowired
    private AdminPatientService patientService;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private FamilyMemberService familyMemberService;
    @Autowired
    private SignFamilyService signFamilyService;
    @Autowired
    private WlyyCustomerLogService wlyyCustomerLogService;
@ -53,6 +46,8 @@ public class CustomerController extends BaseController {
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private HosDoctorService doctorService;
    @RequestMapping(value = "/login",method = RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
@ -174,4 +169,26 @@ public class CustomerController extends BaseController {
        return write(200,"查询成功","data",respon);
    }
    /**
     * 客服给医生发送短信,微信提醒
     * (医生助手功能)
     * @param msg
     * @param doctorCode
     * @return
     */
    @RequestMapping(value = "/sendMsg",produces="application/json;charset=UTF-8")
    @ResponseBody
    public String sendMsg(@ApiParam(name="msg",value="消息内容")@RequestParam(name="msg")String msg,
                          @ApiParam(name="doctorCode",value="发送给某个医生code")@RequestParam(name="doctorCode")String doctorCode,
                          @ApiParam(name="type",value="发送类型  1发送短信   2发送微信   3短信微信都发送")@RequestParam(name="doctorCode",required = false)String type) throws Exception {
        //用于返回的resp
        Doctor doctor = doctorService.getDoctorByCode(doctorCode);
        if(StringUtils.isBlank(type)){
            type="3";
        }
        Map<String, Object> resp = customerService.sendMsg(doctor,msg,type);
        return write(200,"","data",resp);
    }
}

+ 11 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/Doctor.java

@ -99,6 +99,8 @@ public class Doctor extends IdEntity {
    private String adminTeamId;
    private String adminTeamName;
	private String openid; //医生微信openID
    @Column(name = "idcard")
    public String getIdCard() {
        return idCard;
@ -417,4 +419,13 @@ public class Doctor extends IdEntity {
    public void setAdminTeamName(String adminTeamName) {
        this.adminTeamName = adminTeamName;
    }
	@Column(name="openid")
	public String getOpenid() {
		return openid;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}
}

+ 51 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/account/CustomerService.java

@ -6,8 +6,13 @@ import com.yihu.wlyy.entity.SignFamily;
import com.yihu.wlyy.service.manager.family.FamilyMemberService;
import com.yihu.wlyy.service.manager.hos.HosDoctorService;
import com.yihu.wlyy.service.manager.sign.FamilyContractService;
import com.yihu.wlyy.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -25,6 +30,10 @@ public class CustomerService{
	@Autowired
	private HosDoctorService hosDoctorService;
	@Value(("${doctorAssistant.api}")+"/wlyygc/doctor/message")
	private String messageApi;
	public Map<String,Object> findServerInfo(Patient patient) throws Exception {
		Map<String, Object> resp = new HashMap<>();
@ -93,4 +102,46 @@ public class CustomerService{
		return resp;
	}
	/**
	 *
	 * @param doctor
	 * @param msg
	 * @param type  1发送短信   2发送微信   3短信微信都发送
	 * @return
	 */
	public Map<String, Object> sendMsg(Doctor doctor,String msg,String type) {
		Map<String, Object> resp = new HashMap<String, Object>();
		//发送短信消息啦
		String mobile = doctor.getMobile();
		//
		if(!StringUtils.isBlank(mobile)&&!"2".equals(type)){
			List<NameValuePair> par = new ArrayList<NameValuePair>();
			par.add(new BasicNameValuePair("mobiles", mobile));
			par.add(new BasicNameValuePair("content", msg));
			String result = HttpClientUtil.post(messageApi+"/sendMobileMessage",par,"UTF-8");
			JSONObject resultJson = new JSONObject(result);
			if(1!=resultJson.getInt("successNum")){
				resp.put("mobile","-1");//-1代表发送失败
			}
		}
		//发送微信消息啦
		String openId = doctor.getOpenid();
		if(!StringUtils.isBlank(openId)&&!"1".equals(type)){
			List<NameValuePair> par = new ArrayList<NameValuePair>();
			par.add(new BasicNameValuePair("openIds", openId));
			par.add(new BasicNameValuePair("content", msg));
			JSONObject params = new JSONObject();
			String result = HttpClientUtil.post(messageApi+"/sendWechatMessage", par,"UTF-8");
			JSONObject resultJson = new JSONObject(result);
			if(1!=resultJson.getInt("successNum")){
				resp.put("wechat","-1");//-1代表发送失败
			}
		}
		return resp;
	}
}

+ 2 - 0
patient-co-manage/wlyy-manage/src/main/resources/application.yml

@ -73,6 +73,8 @@ im-service:
  im_service_url: http://172.19.103.88:3000/api/v2
yueren:
  api: http://120.77.209.211:8080
doctorAssistant:
  api: http://127.0.0.1:8080
---
spring:

+ 26 - 52
patient-co/patient-co-doctor-assistant/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcMessageController.java

@ -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);
    }
    /**