Sfoglia il codice sorgente

Merge branch 'dev' of wujunjie/patient-co-management into dev

yeshijie 7 anni fa
parent
commit
6322b3ef1a

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -29,6 +29,11 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query("update SignFamily a set a.mobile = ?2 where a.patient = ?1")
    int updatePatientMobile(String patient, String mobile);
    //更新有效签约患者手机号
    @Modifying
    @Query("update SignFamily a set a.mobile = ?2 where a.patient = ?1 and a.status > 0 ")
    int updateSignMobile(String patient, String mobile);
    @Query("select a from SignFamily a where a.idcard = ?1 and status = ?2 and a.type = 2")
    SignFamily findByPatientStatus(String idcard, int status);

+ 19 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java

@ -128,6 +128,25 @@ public class PatientInfoService extends BaseService {
        return 1;
    }
    /**
     * 患者更换手机号
     *
     * @param patient 患者code
     * @param mobile  新手机号
     * @return
     */
    public int updateMobile(String patient, String mobile) throws Exception {
        Patient p = patientDao.findByCode(patient);
        if (p == null) {
            return -1;
        }
        p.setMobile(mobile);
        patientDao.save(p);
        signFamilyDao.updateSignMobile(patient, mobile);
        return 1;
    }
    /**
     * 手机号是否注册
     *

+ 117 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/message/SendMessageService.java

@ -0,0 +1,117 @@
package com.yihu.wlyy.service.message;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.task.PushMsgTask;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * 消息类发送(系统消息、模板消息、短信消息)
 * <p>
 * Created by Reece on 2017/11/27/007.
 */
@Service
@Transactional
public class SendMessageService extends BaseService {
    @Autowired
    private WeiXinTempMsgSendUtils tempMsgSendUtils;
    @Autowired
    private PushMsgTask pushMsgTask;
    @Autowired
    private SMSService smsService;
    @Autowired
    WeiXinOpenIdUtils weiXinOpenIdUtils;
    @Autowired
    WeiXinAccessTokenUtils weiXinAccessTokenUtils;
    @Autowired
    private PatientDao patientDao;
    private static final Logger logger = LoggerFactory.getLogger(SendMessageService.class);
    /**
     * 拼装参数并发送模板消息
     *
     * @param type     typeMsg对应参数
     * @param patient  居民code
     * @param url      带参数跳转链接
     * @param first
     * @param remark
     * @param keywords
     * @return
     */
    public Boolean sendTemplate(int type, String patient, String url, String first, String remark, String... keywords) {
        Boolean flag = false;
        try {
            Patient patient1 = patientDao.findByCode(patient);
            String openid = patient1.getOpenid();
            String name = patient1.getName();
            String accessToken = weiXinAccessTokenUtils.getAccessToken();
            JSONObject data = tempMsgSendUtils.getTemplateContent(first, remark, keywords);
            data.put("url", url+"&represented="+patient);
            if (StringUtils.isNotEmpty(openid)) {
                pushMsgTask.putWxMsg(accessToken, type, openid, name, data);
                flag = true;
            }else {
                //发送代理人
                JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(patient, openid);
                if (jsonArray != null && jsonArray.length() > 0) {
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject j = jsonArray.getJSONObject(i);
                        Patient member = (Patient) j.get("member");
                        JSONObject json = data;
                        data.remove("first");
                        data.remove("url");
                        data.put("url",url+"&represented="+member.getCode());
                        data.put("first", weiXinOpenIdUtils.getTitleMes(patient1, j.getInt("relation"), name) + first);
                        pushMsgTask.putWxMsg(accessToken, type, member.getOpenid(), name, data);
                        flag = true;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return flag;
    }
    /**
     * 拼装参数并发送短信消息
     *
     * @param mobile 发送手机号
     * @param msg    发送短信内容
     * @return
     */
    public String sendMessage(String mobile, String msg) {
        String response = null;
        try {
            //发送短信消息,调用总部发送信息的接口
            JSONObject resultJson = smsService.sendMsg(mobile, msg);
            if (resultJson != null && resultJson.getInt("result") != 0) {
                response = "短信提醒失败!(原因:" + resultJson.getString("description") + ")";
            }
            response = "短信发送成功!";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }
}

+ 1 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorFeldsherTemplateService.java

@ -108,8 +108,7 @@ public class DoctorFeldsherTemplateService extends BaseService {
            Doctor doctor = doctorDao.findByCode(doctorCode);
            String doctorName = doctor.getName();
//            String doctorOpenId = doctor.getOpenid();
            String doctorOpenId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
            String doctorOpenId = doctor.getOpenid();
            String first = businessType;
            sendJson.put("keyword1", content);

+ 67 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/PatientInfoController.java

@ -8,6 +8,7 @@ import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SocialSecurityInfoDao;
import com.yihu.wlyy.service.app.account.PatientInfoService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.message.SendMessageService;
import com.yihu.wlyy.util.IdcardValidator;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.RSAUtils;
@ -26,7 +27,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * 医生端:患者分组管理
@ -48,6 +53,9 @@ public class PatientInfoController extends BaseController {
    private SocialSecurityInfoDao socialSecurityInfoDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private SendMessageService sendMessageService;
    /**
     * 获取患者基本信息
     *
@ -360,4 +368,63 @@ public class PatientInfoController extends BaseController {
            return error(-1, "注册失败!");
        }
    }
    /**
     * 修改居民手机号码
     * @param patient 居民code
     * @param newMobile 新手机号
     * @param oldMobile 旧手机号
     * @return
     */
    @ObserverRequired
    @RequestMapping(value = "/updateMobile", method = RequestMethod.POST)
    @ResponseBody
    public String updatePatientMobile(@ApiParam(value = "居民code", name = "patient") @RequestParam(required = true) String patient,
                         @ApiParam(value = "新手机号", name = "newMobile") @RequestParam(required = true) String newMobile,
                         @ApiParam(value = "旧手机号", name = "oldMobile") @RequestParam(required = false) String oldMobile) {
        try {
            if (StringUtils.isEmpty(patient)) {
                return error(-1, "居民不允许为空!");
            }
            if (StringUtils.isEmpty(newMobile)) {
                return error(-1, "新手机号不允许为空!");
            }
            String keyword = "新手机号码"+newMobile;
            if (StringUtils.isNotEmpty(oldMobile)) {
                keyword = "原关联手机号码"+oldMobile+"变更为"+keyword;
            }
            String reg = "^1[34578][0-9]{9}$";
            Pattern pattern = Pattern.compile(reg);
            Matcher matcher = pattern.matcher(newMobile);
            Boolean flag = matcher.matches();
            if (!flag){
                return error(-1, "新手机号格式不正确!");
            }
            Patient patient1 = patientDao.findByCode(patient);
            String patientName = patient1.getName();
            String openid = patient1.getOpenid();
            int result = patientInfoService.updateMobile(patient, newMobile);
            if (result == -1) {
                return error(-1, "居民信息查找失败");
            } else if (result == 1) {
                String first = patientName+",您好!\n"+"您的家庭医生已将您账号关联的手机号码进行变更";
                String remark = "您可使用新手机号码登录i健康平台";
                String url = "/grzx/html/my-detail.html?openid=" + openid + "&toUser=" + patient + "&toName=" + patientName;
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                Boolean mark = sendMessageService.sendTemplate(10,patient,url,first,remark,patientName,format.format(new Date()),keyword);
                if (!mark){
                    String msg = patientName+",您好!您的家庭医生已将您账号关联的手机号码变更:"+keyword+".您可以使用新手机号码登录i健康平台.";
                    sendMessageService.sendMessage(newMobile,msg);
                }
                return write(200, "手机号更新成功");
            } else {
                return write(-1, "手机号更新失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "注册失败!");
        }
    }
}

+ 17 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/util/WeiXinTempMsgSendUtils.java

@ -97,4 +97,21 @@ public class WeiXinTempMsgSendUtils {
        return data;
    }
    /**
     * 构建微信模板内容消息体 加入队列发送无字体格式
     *
     * @param first    消息头
     * @param remark   备注
     * @param keywords 消息体
     * @return
     */
    public JSONObject getTemplateContent(String first, String remark, String... keywords) throws Exception{
        JSONObject data = new JSONObject();
        data.put("first", first);
        data.put("remark", remark);
        for (int i = 0; i < keywords.length; i++) {
            data.put("keyword" + (i + 1), keywords[i]);
        }
        return data;
    }
}