Procházet zdrojové kódy

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

# Conflicts:
#	business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java
wangzhinan před 5 roky
rodič
revize
d275d92af6

+ 17 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/consult/dao/WlyyConsultAdviceDao.java

@ -0,0 +1,17 @@
package com.yihu.jw.hospital.consult.dao;
import com.yihu.jw.entity.hospital.prescription.WlyyConsultAdvice;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 咨询建议Dao
 * @author huangwenjie
 * @date 2020/5/27 17:29
 */
public interface WlyyConsultAdviceDao  extends PagingAndSortingRepository<WlyyConsultAdvice, String>, JpaSpecificationExecutor<WlyyConsultAdvice> {
	
	List<WlyyConsultAdvice> getByConsult(String consult);
}

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/dao/PrescriptionDao.java

@ -34,6 +34,8 @@ public interface PrescriptionDao extends PagingAndSortingRepository<WlyyPrescrip
    List<WlyyPrescriptionDO> findById(String id);
    WlyyPrescriptionDO findByRealOrder(String realOrder);
    
    WlyyPrescriptionDO findByAdmNoAndRealOrder(String admno,String realOrder);
    List<WlyyPrescriptionDO> findByDoctorAndCreateTimeAndRemark(String doctor,Date createTime,String remark);

+ 16 - 2
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionExpressageService.java

@ -1,5 +1,6 @@
package com.yihu.jw.hospital.prescription.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
@ -206,7 +207,7 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(sfexpress_obj.getOutpatientId());
        BaseOrgDO hospital = baseOrgDao.findByCode(outpatientDO.getHospital());
        BasePatientDO basePatientDO = basePatientDao.findById(outpatientDO.getPatient());
    
        JSONObject params = SFUtils.postSFOrderServiceV2(sfexpress_obj,hospital,basePatientDO);
        String re = this.SFExpressPostV2(params);
        //xml验证
@ -214,10 +215,23 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
        verificationResponV2(re);
        JSONObject respone = JSONObject.parseObject(re);
//        String re = "{\"success\":true,\"message\":null,\"code\":\"SUCCESS\",\"result\":{\"successResult\":[{\"mailNo\":\"SF1023527844982\",\"bspOrderNo\":\"2c9081aa724b941501724eb3d0e40036\"}]}}";
//        JSONObject respone = JSONObject.parseObject(re);
        String mailno = "";//顺丰运单号
        
        JSONArray successResult =  respone.getJSONObject("result").getJSONArray("successResult");
        
        if(!successResult.isEmpty()){
            JSONObject object = successResult.getJSONObject(0);
            mailno = object.getString("mailNo");
        }
    
        logger.info("顺丰快递下订单:mailno"+mailno);
    
        mailno = respone.getJSONObject("result").getJSONArray("successResult").getJSONObject(0).getString("mailNo");
        
//        mailno = respone.getJSONObject("result").getJSONArray("successResult").getJSONObject(0).getString("mailNo");
        
        sfexpress_obj.setMailno(mailno);
        return sfexpress_obj;
    }

+ 31 - 5
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -28,6 +28,7 @@ import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
import com.yihu.jw.file_upload.FileUploadService;
import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
import com.yihu.jw.hospital.consult.dao.WlyyConsultAdviceDao;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.doctor.dao.DoctorWorkTimeDao;
@ -185,6 +186,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    @Autowired
    private PrescriptionEmrDao prescriptionEmrDao;
    @Autowired
    private WlyyConsultAdviceDao wlyyConsultAdviceDao;
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
@ -4294,13 +4297,15 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    public Object getSFExpressInfo(String admNo,String realOrder,String wxId)throws Exception {
    
        //根据门诊唯一号取就诊记录
        List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByAdmNo(admNo);
//        List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByAdmNo(admNo);
        WlyyPrescriptionDO wlyyPrescriptionDOS = prescriptionDao.findByAdmNoAndRealOrder(admNo,realOrder);
        
        Object result = "";
    
        System.out.println("获取顺丰物流面单信息:wlyyOutpatientDOs.isEmpty()="+wlyyOutpatientDOs.isEmpty());
        if(!wlyyOutpatientDOs.isEmpty() && wlyyOutpatientDOs.size()>0){
            List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpatientId",wlyyOutpatientDOs.get(0).getId());
        System.out.println("获取顺丰物流面单信息:wlyyPrescriptionDOS != null="+wlyyPrescriptionDOS != null);
        if(wlyyPrescriptionDOS != null){
            List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpatientId",wlyyPrescriptionDOS.getOutpatientId());
            WlyyPrescriptionExpressageDO sfexpress_obj = null;
            System.out.println("获取顺丰物流面单信息:CollectionUtils.isEmpty(expressageDOList)="+CollectionUtils.isEmpty(expressageDOList));
            if(CollectionUtils.isEmpty(expressageDOList)){
@ -4309,7 +4314,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                System.out.println("获取顺丰物流面单信息:1");
                sfexpress_obj = expressageDOList.get(0);
                System.out.println("获取顺丰物流面单信息:2");
                BasePatientDO basePatientDO = basePatientDao.findById(wlyyOutpatientDOs.get(0).getPatient());
                BasePatientDO basePatientDO = basePatientDao.findById(wlyyPrescriptionDOS.getPatientCode());
                //如果该处方的快递单号已生成,则说明已经下单成功,不需要重复下单,直接返回面单信息
                System.out.println("获取顺丰物流面单信息:3");
                if(org.apache.commons.lang.StringUtils.isNotBlank(sfexpress_obj.getMailno())){
@ -5727,6 +5732,27 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    }
    /**
     * 保存排班规则
     * @param workRoleJsons
     * @return
     */
    public Boolean sendOutPatientSuggest(String advicesJson){
        List<WlyyConsultAdvice> advices = (List<WlyyConsultAdvice>) com.alibaba.fastjson.JSONArray.parseArray(advicesJson, WlyyConsultAdvice.class);
        wlyyConsultAdviceDao.save(advices);
        return true;
    }
    /**
     * 获取咨询建议
     * @param consultcode
     * @return
     */
    public List<WlyyConsultAdvice> getConsultSuggest(String consultcode) {
        return wlyyConsultAdviceDao.getByConsult(consultcode);
    }
    public String readOutPatient(String registerSn) throws Exception {
        String url = "";

+ 38 - 0
business/im-service/src/main/java/com/yihu/jw/im/service/ImService.java

@ -1659,6 +1659,10 @@ public class ImService {
		
		//获取药品
		List<WlyyPrescriptionInfoVO> infoVOs = wlyyPrescriptionVO.getInfoVOs();
		JSONObject object = new JSONObject();
		object.put("info",infoVOs);
		object.put("outpatientid",wlyyPrescriptionVO.getOutpatientId());
		object.put("prescriptionid",wlyyPrescriptionVO.getId());
		if(!infoVOs.isEmpty()){
			String response = imUtil.sendImMsg(wlyyPrescriptionVO.getDoctor(), wlyyPrescriptionVO.getDoctorName(), wlyyPrescriptionVO.getPatientCode()+"_"+wlyyPrescriptionVO.getOutpatientId()+"_9", "27", JSON.toJSONString(infoVOs),"1");
		}
@ -1690,6 +1694,20 @@ public class ImService {
		}
	}
	
	/**
	 * 发送咨询建议
	 * @param jsonObject
	 * @param doctor
	 * @param doctorName
	 * @param outpatientId
	 * @param patient
	 * @return
	 * @throws Exception
	 */
	public String sendOutPatientSuggestMsg(String msg,String doctor,String doctorName,String sessionid) throws Exception {
		return imUtil.sendImMsg(doctor, doctorName, sessionid, "34",msg,"1");
	}
	
	
	/**
	 * 发送处方驳回消息
@ -1711,6 +1729,26 @@ public class ImService {
		}
	}
	
	/**
	 * 发送处方支付消息
	 * @param jsonObject
	 * @param doctor
	 * @param doctorName
	 * @param outpatientId
	 * @param patient
	 * @return
	 * @throws Exception
	 */
	public String sendOutPatientPayMsg(com.alibaba.fastjson.JSONObject jsonObject,String doctor,String doctorName,String outpatientId,String patient,String outpatientType) throws Exception {
		if("1".equals(outpatientType)){
			return imUtil.sendImMsg(doctor, doctorName, patient+"_"+outpatientId+"_9", "35",jsonObject.toString(),"1");
		}else if("2".equals(outpatientType)){
			return imUtil.sendImMsg(doctor, doctorName, patient+"_"+outpatientId+"_12", "35",jsonObject.toString(),"1");
		}else{
			return null;
		}
	}
	
	/**
	 * 查询医生所有的咨询记录
	 * @param doctor 医生标识

+ 57 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/prescription/WlyyConsultAdvice.java

@ -0,0 +1,57 @@
package com.yihu.jw.entity.hospital.prescription;
import com.yihu.jw.entity.UuidIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 咨询建议
 * @author huangwenjie
 * @date 2020/5/27 17:23
 */
@Entity
@Table(name = "wlyy_consult_advice")
public class WlyyConsultAdvice extends UuidIdentityEntity {
	
	private String adviceKey;
	private String adviceValue;
	private String adviceType;
	private String consult;
	
	
	@Column(name = "advice_key")
	public String getAdviceKey() {
		return adviceKey;
	}
	
	public void setAdviceKey(String adviceKey) {
		this.adviceKey = adviceKey;
	}
	
	@Column(name = "advice_value")
	public String getAdviceValue() {
		return adviceValue;
	}
	
	public void setAdviceValue(String adviceValue) {
		this.adviceValue = adviceValue;
	}
	@Column(name = "advice_type")
	public String getAdviceType() {
		return adviceType;
	}
	
	public void setAdviceType(String adviceType) {
		this.adviceType = adviceType;
	}
	
	public String getConsult() {
		return consult;
	}
	
	public void setConsult(String consult) {
		this.consult = consult;
	}
}

+ 6 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/hospital/BaseHospitalRequestMapping.java

@ -932,6 +932,12 @@ public class BaseHospitalRequestMapping {
    
        //医生端:发起/断开 会话小程序视频邀请
        public static final String videoInviteMiniProgram="videoInviteMiniProgram";
    
        //医生端:发送咨询建议
        public static final String sendOutPatientSuggest = "sendOutPatientSuggest";
        
        //医生端:获取咨询建议
        public static final String getConsultSuggest = "getConsultSuggest";
    }

+ 449 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/service/channel/UnSettledHISPrescriptionService.java

@ -0,0 +1,449 @@
package com.yihu.jw.service.channel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.*;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.service.PrescriptionLogService;
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.im.service.ImService;
import com.yihu.jw.oauth.OauthSsoService;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.order.dao.ConsultOrderDao;
import com.yihu.jw.order.dao.ConsultTeamOrderDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import com.yihu.jw.utils.RSAEncrypt;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
import com.yihu.jw.wechat.dao.WxPushLogDao;
import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
import com.yihu.jw.wechat.dao.WxTemplateDao;
import com.yihu.jw.wechat.service.WxAccessTokenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.net.URLEncoder;
import java.util.*;
/**
 * Created by Administrator on 2017/5/19 0019.
 */
@Service
public class UnSettledHISPrescriptionService {
    private Logger logger= LoggerFactory.getLogger(UnSettledHISPrescriptionService.class);
    @Autowired
    private WxTemplateConfigDao wxTemplateConfigDao;
    @Autowired
    private WxTemplateDao wxTemplateDao;
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    @Autowired
    private WeixinMessagePushUtils weixinMessagePushUtils;
    @Value("${wechat.id}")
    private String wechatId;
    
    @Autowired
    private BasePatientDao basePatientDao;
    
    @Autowired
    private BasePatientWechatDao basePatientWechatDao;
    
    @Autowired
    private OauthSsoService oauthSsoService;
    
    @Autowired
    private XzzxEntranceService xzzxEntranceService;
    @Autowired
    private YkyyEntranceService ykyyEntranceService;
    @Autowired
    private WxPushLogDao wxPushLogDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private ConsultOrderDao consultOrderDao;
    @Autowired
    private BusinessOrderDao businessOrderDao;
    @Autowired
    private ConsultTeamOrderDao consultTeamOrderDao;
    @Autowired
    private OutpatientDao outpatientDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private PrescriptionLogService prescriptionLogService;
    @Autowired
    private ImService imService;
    @Autowired
    private PrescriptionDao prescriptionDao;
    
    
    /**
     * 发送微信模版消息-小程序视频
     * @param sender_id 发送者ID
     * @param sender_name 发送者姓名
     * @param reciver_id 接收者ID
     * @param reciver_name 接收者姓名
     * @param session_id 会话ID
     */
    public String sendWeTempMesMiniProgram(String sender_id, String sender_name, String reciver_id, String reciver_name,String session_id)throws Exception {
        BasePatientDO basePatientDO = basePatientDao.findById(reciver_id);
        if(basePatientDO!=null){
            List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,reciver_id);
            if(ps.isEmpty()){
                logger.info("该用户"+reciver_name+"没有openid,无法推送模版消息,用户ID:"+reciver_id+"wechatId:"+wechatId);
            }else{
                for (BasePatientWechatDo basePatientWechatDo:ps){
                    if("xm_xzzx_wx".equals(wechatId)){
                        String getAuthCode = oauthSsoService.getSsoPublic(wechatId,basePatientDO.getId());
    
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("name",basePatientDO.getName());
                        jsonObject.put("idcard",basePatientDO.getIdcard());
                        jsonObject.put("mobile",basePatientDO.getMobile());
                        jsonObject.put("openid",basePatientWechatDo.getOpenid());
                        String authCode = jsonObject.toJSONString();
                        String jm = URLEncoder.encode(RSAEncrypt.encrypt(authCode,getAuthCode),"utf-8");
                        String miniprogramUrl = "pages/room/room?patientCode="+reciver_id+"&doctorName="+sender_name+"&role=patient&roomID="+session_id+"&template=1v1&debugMode=false&cloudenv=PRO&authCode="+jm+"&code="+wechatId+"&appId="+basePatientDO.getId();
                        //心脏中心模版消息推送接口
                        logger.info("心脏中心小程序跳转URL:"+miniprogramUrl);
                        xzzxEntranceService.sendXCXMes(wechatId,
                                basePatientDO.getId(),
                                basePatientDO.getIdcard(),
                                sender_name+"主任医生已向您发起视频通话邀请,请点击详情进入视频诊室。",
                                "点击消息进入视频诊室接听视频通话,开始视频咨询",
                                "",miniprogramUrl,"wx53f6bb4ac081d840");
                    }else{
                        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_consult_notice","spthtx",1);
                        config.setFirst(config.getFirst().replace("key1",sender_name));
                        config.setPagepath(config.getPagepath()+""+reciver_id+"&doctorName="+sender_name+"&role=patient&roomID="+session_id+"&template=1v1&debugMode=false&cloudenv=PRO");
                        weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),basePatientWechatDo.getOpenid(),config);
                    }
                }
            }
        }else{
            throw new Exception("接收者ID错误,无法找到该账号");
        }
        return "success";
    }
    /**
     * 查询HIS的01表中的审方状态,如果已审方,且未结算,则推送一条模板消息给居民,让居民进行支付结算。
     */
    public void unSettledHISPrescription() throws Exception{
        if("xm_ykyy_wx".equals(wechatId)){
            //获取审核失败
            JSONArray jsonArray = ykyyEntranceService.getNoUnsettledPrescription();
            if(jsonArray!=null&&jsonArray.size()>0) {
                for (int i = 0; i<jsonArray.size(); i++){
                    JSONObject json = jsonArray.getJSONObject(i);
                    String cfsb = json.getString("CFSB");
                    //查找对应的处方
                    String sql = "SELECT w.OUTPATIENT_ID,w.ID,w.DOCTOR_NAME from WLYY_PRESCRIPTION w WHERE REAL_ORDER = '"+cfsb+"' ORDER BY w.CREATE_TIME desc";
                    List<Map<String, Object>> pre = hibenateUtils.createSQLQuery(sql);
                    if(pre!=null && pre.size()>0){
                        String prescriptionId = pre.get(0).get("ID").toString();
                        //修改处方状态
                        String updateSql = "update WLYY_PRESCRIPTION set status = 11 where id = '"+prescriptionId+"'";
                        hibenateUtils.updateBySql(updateSql);
                    }
                }
            }
            //获取已审核未结算的处方
            JSONArray array = ykyyEntranceService.getUnsettledPrescription();
            //发送模板
            if(array!=null&&array.size()>0) {
                for (int i = 0; i<array.size(); i++){
                    JSONObject json = array.getJSONObject(i);
                    String brid = json.getString("BRID");
                    String cfsb = json.getString("CFSB");
                    //查找居民信息
                    BasePatientDO patientDO = ykyyEntranceService.findPatientByMapingCode(brid);
                    if(patientDO!=null){
                        //查找对应的处方
                        String sql = "SELECT w.OUTPATIENT_ID,w.ID,w.DOCTOR_NAME from WLYY_PRESCRIPTION w WHERE REAL_ORDER = '"+cfsb+"' ORDER BY w.CREATE_TIME desc";
                        List<Map<String, Object>> pre = hibenateUtils.createSQLQuery(sql);
                        if(pre!=null && pre.size()>0){
                            String outpatientId = pre.get(0).get("OUTPATIENT_ID").toString();
                            String prescriptionId = pre.get(0).get("ID").toString();
                            String doctorName = pre.get(0).get("DOCTOR_NAME").toString();
                            WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
                            JSONObject object = (JSONObject) JSONObject.toJSON(wlyyPrescriptionDO);
                            logger.info("11111参数入参"+object.toJSONString());
                            WlyyPrescriptionVO prescriptionVO = JSONObject.toJavaObject(object,WlyyPrescriptionVO.class);
                            imService.pushPrescriptionImMessage(prescriptionVO);
                            //判断是否发送过
                            String countSql = "SELECT id from WX_PUSH_LOG w WHERE w.RECEIVER = '"+patientDO.getId()
                                    +"' and w.OPENID = '"+prescriptionId+"' and w.scene = 'djsxxtz' and w.WECHAT_ID='"+wechatId+"'";
                            List<Map<String, Object>> count = hibenateUtils.createSQLQuery(countSql);
                            if(count==null || count.size() == 0){
                                List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,patientDO.getId());
                                if(ps.isEmpty()){
                                    logger.info("该用户"+patientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+patientDO.getId()+"wechatId:"+wechatId);
                                }else{
                                    //修改处方状态
                                    String updateSql = "update WLYY_PRESCRIPTION set status = 20 where id = '"+prescriptionId+"' and status = 10";
                                    hibenateUtils.updateBySql(updateSql);
                                    prescriptionLogService.addPrescriptionLog(prescriptionId,20,2,"system","system","",new Date());
                                    ps.stream().forEach(one->{
                                        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_unsettled_notice","djsxxtz",1);
                                        WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
                                        BeanUtils.copyProperties(config,newConfig);
                                        newConfig.setFirst(config.getFirst().replace("key1",patientDO.getName()));
                                        newConfig.setUrl(config.getUrl()+""+outpatientId);
                                        newConfig.setKeyword3(doctorName);
                                        WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
                                        logger.info("=======setUrl========"+newConfig.getUrl());
                                        weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(),one.getOpenid(),newConfig);
                                    });
                                    //保存发送模板记录,
                                    WxPushLogDO wxPushLogDO = new WxPushLogDO();
                                    wxPushLogDO.setCreateTime(new Date());
                                    wxPushLogDO.setOpenid(prescriptionId);
                                    wxPushLogDO.setReceiver(patientDO.getId());
                                    wxPushLogDO.setWechatId(wechatId);
                                    wxPushLogDO.setReceiverName(patientDO.getName());
                                    wxPushLogDO.setScene("djsxxtz");
                                    wxPushLogDao.save(wxPushLogDO);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public void updateStatusByPayTime() throws Exception{
        if("xm_ykyy_wx".equals(wechatId)){
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("PAY_TIME");
            if (wlyyHospitalSysDictDO!=null){
                String remind = wlyyHospitalSysDictDO.getDictValue();
                String close = wlyyHospitalSysDictDO.getDictCode();
                List<BusinessOrderDO> businessOrderDOS = businessOrderDao.selectByStatus(0);
                //关闭处理
                for (BusinessOrderDO businessOrderDO:businessOrderDOS){
                    Calendar cal= Calendar.getInstance();
                    cal.setTime(businessOrderDO.getCreateTime());
                    cal.add(Calendar.MINUTE,Integer.parseInt(close));
                    Long now = new Date().getTime();
                    Long min = cal.getTime().getTime();
                    logger.info("关闭处理cal="+cal);
                    if (min==now){
                        String orderCategory = businessOrderDO.getOrderCategory();
                        String relationCode = businessOrderDO.getRelationCode();
                        if (orderCategory.equalsIgnoreCase("1")){
                            ConsultTeamDo consultTeamDo = consultTeamOrderDao.findByConsult(relationCode);
                            consultTeamDo.setStatus(-1);
                            consultTeamOrderDao.save(consultTeamDo);
                        }else if (orderCategory.equalsIgnoreCase("2")){
                            WlyyOutpatientDO outpatientDO = outpatientDao.findById(relationCode);
                            outpatientDO.setStatus("-1");
                            outpatientDao.save(outpatientDO);
                        }
                    }
                }
                //提醒处理
                for (BusinessOrderDO businessOrderDO:businessOrderDOS){
                    String orderCategory = businessOrderDO.getOrderCategory();
                    String relationCode = businessOrderDO.getRelationCode();
                    String orderType =businessOrderDO.getOrderType()+"";
                    String doctor = businessOrderDO.getDoctor();
                    String patient= businessOrderDO.getPatient();
                    Calendar cal= Calendar.getInstance();
                    cal.setTime(businessOrderDO.getCreateTime());
                    cal.add(Calendar.MINUTE,Integer.parseInt(remind));
                    Long now = new Date().getTime();
                    Long min = cal.getTime().getTime();
                    logger.info("提醒处理cal="+cal);
                    if (min==now){
                        //判断是否发送过
                        String countSql = "SELECT id from WX_PUSH_LOG w WHERE w.RECEIVER = '"+patient
                                +"' and w.OPENID = '"+relationCode+"' and w.scene = 'zxzfts' and w.WECHAT_ID='"+wechatId+"'";
                        List<Map<String, Object>> count = hibenateUtils.createSQLQuery(countSql);
                        if(count==null || count.size() == 0){
                            BasePatientDO patientDO = basePatientDao.findById(patient);
                            BaseDoctorDO doctorDO = doctorDao.findById(doctor);
                            List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,patient);
                            if(ps.isEmpty()){
                                logger.info("该用户"+patientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+patientDO.getId()+"wechatId:"+wechatId);
                            }else{
                                ps.stream().forEach(one->{
                                    WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_unsettled_notice","zxzfts",1);
                                    WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
                                    BeanUtils.copyProperties(config,newConfig);
                                    String name = "";
                                    String condition="";
                                    if (orderCategory.equalsIgnoreCase("1")){
                                        if (orderType.equalsIgnoreCase("1")){
                                            name="图文咨询";
                                        }else if (orderType.equalsIgnoreCase("3")){
                                            name="视频咨询";
                                        }
                                        condition = "&consultCode="+relationCode;
                                    }else if (orderCategory.equalsIgnoreCase("2")){
                                        if (orderType.equalsIgnoreCase("1")){
                                            name="图文咨询";
                                        }else if (orderType.equalsIgnoreCase("3")){
                                            name="视频咨询";
                                        }
                                        condition = "&outpatientId="+relationCode;
                                    }
                                    newConfig.setFirst(config.getFirst().replace("key1",patientDO.getName()).replace("key2",name));
                                    newConfig.setUrl(config.getUrl()+""+condition);
                                    newConfig.setKeyword3(doctorDO.getName());
                                    newConfig.setKeyword1(name);
                                    WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
                                    logger.info("=======setUrl========"+newConfig.getUrl());
                                    weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(),one.getOpenid(),newConfig);
                                });
                                //保存发送模板记录,
                                WxPushLogDO wxPushLogDO = new WxPushLogDO();
                                wxPushLogDO.setCreateTime(new Date());
                                wxPushLogDO.setOpenid(relationCode);
                                wxPushLogDO.setReceiver(patientDO.getId());
                                wxPushLogDO.setWechatId(wechatId);
                                wxPushLogDO.setReceiverName(patientDO.getName());
                                wxPushLogDO.setScene("zxzfts");
                                wxPushLogDao.save(wxPushLogDO);
                            }
                        }
                    }
                }
            }
        }
    }
    
    public String sendWeTempMesTest(String wechatId,String openid)throws Exception{
        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_survey","test",1);
        config.setFirst(config.getFirst().replace("key1","小明"));
        config.setKeyword2("2018-08-21");
        weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),openid,config);
        return "success";
    }
    
    public Envelop getAllTemp(String wechatId){
        String url ="https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token="+wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken();
        String result = HttpUtil.sendGet(url);
        JSONObject tempJsons = JSON.parseObject(result);
        //获取所有本地模板
        List<String> localTemps = findAllTempDos(wechatId);
        //解析公众号模板
        JSONArray temps = tempJsons.getJSONArray("template_list");
        List<WxTemplateDO> savelist = new ArrayList<>();
        if(temps!=null&&!temps.isEmpty()){
            for(int i=0;i<temps.size();i++){
                JSONObject tp = (JSONObject) temps.get(i);
                String tpid = tp.getString("template_id");
                if(!localTemps.contains(tpid)){
                    WxTemplateDO wxTemplateDO = new WxTemplateDO();
                    wxTemplateDO.setWechatId(wechatId);
                    wxTemplateDO.setTemplateId(tpid);
                    wxTemplateDO.setTitle(tp.getString("title"));
                    wxTemplateDO.setContent(tp.getString("content"));
                    wxTemplateDO.setStatus(1);
                    wxTemplateDO.setCreateTime(new Date());
                    savelist.add(wxTemplateDO);
                }
            }
            wxTemplateDao.save(savelist);
        }
        return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
    }
    public List<String> findAllTempDos(String wechatId){
        List<WxTemplateDO> list =  wxTemplateDao.findByWxId(wechatId);
        List<String> rs = new ArrayList<>();
        if(list!=null&&list.size()>0){
            for(WxTemplateDO wxTemplateDO:list){
                rs.add(wxTemplateDO.getTemplateId());
            }
        }
        return rs;
    }
    
    /**
     * 发送微信模版消息
     * @param userName
     * @param senderName
     * @param idCard
     * @param phone
     * @param title
     * @param content
     * @param contentString
     * @param url
     */
    public String sendWxTemple(String userName, String senderName,
                             String idCard, String phone, String title,
                             String content, String contentString,
                             String url) throws Exception{
        BasePatientDO basePatientDO = basePatientDao.findByIdcard(idCard);
        if(basePatientDO!=null){
            List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,basePatientDO.getId());
            if(ps.isEmpty()){
                logger.info("该用户"+basePatientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+basePatientDO.getId()+"wechatId:"+wechatId);
            }else{
                for (BasePatientWechatDo basePatientWechatDo:ps){
                        WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_im_notice","zxtx",1);
                        config.setFirst(config.getFirst().replace("key1",userName));
                        config.setKeyword1(contentString);
                        config.setKeyword2(DateUtil.dateToStrLong(new Date()));
                        config.setUrl(url);
                        weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),basePatientWechatDo.getOpenid(),config);
                }
            }
        }else{
            throw new Exception("接收者ID错误,无法找到该账号");
        }
        return "success";
    }
}

+ 33 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/consult/DoctorConsultEndpoint.java

@ -10,6 +10,7 @@ import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.hospital.prescription.service.XzyyPrescriptionService;
@ -716,5 +717,37 @@ public class DoctorConsultEndpoint extends EnvelopRestEndpoint {
		wxTemplateService.sendWeTempMesMiniProgram(sender_id,sender_name,reciver_id,reciver_name,session_id);
		return success("操作成功");
	}
	
	@PostMapping(value = BaseHospitalRequestMapping.DodtorIM.sendOutPatientSuggest)
	@ApiOperation(value = "医生端:发送咨询建议消息", notes = "医生端:发送咨询建议消息")
	public Envelop sendOutPatientSuggest(@ApiParam(name = "adviceJson", value = "咨询建议JSON")
	                                     @RequestParam(value = "adviceJson", required = true)String adviceJson,
	                                     @ApiParam(name = "session_id", value = "咨询sessionid")
	                                     @RequestParam(value = "session_id", required = true)String session_id,
	                                     @ApiParam(name = "doctor", value = "医生CODE")
	                                         @RequestParam(value = "doctor", required = true)String doctor,
	                                     @ApiParam(name = "doctorName", value = "")
	                                         @RequestParam(value = "doctorName", required = true)String doctorName
                                      
	)throws Exception  {
		try {
			prescriptionService.sendOutPatientSuggest(adviceJson);
			String immsg = imService.sendOutPatientSuggestMsg(adviceJson,doctor,doctorName,session_id);
			System.out.println("发送咨询建议消息成功:"+immsg);
		}catch (Exception e){
			System.out.println("发送咨询建议消息失败:"+e.getMessage());
//            e.printStackTrace();
		}
		return success("操作成功");
	}
	
	@PostMapping(value = BaseHospitalRequestMapping.DodtorIM.getConsultSuggest)
	@ApiOperation(value = "医生端:发送咨询建议消息", notes = "医生端:发送咨询建议消息")
	public Envelop getConsultSuggest(@ApiParam(name = "consultcode", value = "咨询CODE")
	                                     @RequestParam(value = "consultcode", required = true)String consultcode
	
	)throws Exception  {
		return success("操作成功",prescriptionService.getConsultSuggest(consultcode));
	}
}

+ 7 - 3
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/controller/CreditsDetailController.java

@ -274,7 +274,7 @@ public class CreditsDetailController extends EnvelopRestEndpoint {
                                                                 @ApiParam(name = "doctorId",value = "医生code")
                                                                     @RequestParam(value = "doctorId",required = false)String doctorId){
        try {
            return service.doctorDescreaseIntegrate(ruleId,patientId,doctorId,hospital,hospitalName,integrate,reason,null);
            return service.doctorDescreaseIntegrate(ruleId,patientId,doctorId,hospital,hospitalName,integrate,reason,null,null,null);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
@ -309,9 +309,13 @@ public class CreditsDetailController extends EnvelopRestEndpoint {
                                                                 @ApiParam(name = "reason",value = "增加的原因")
                                                                 @RequestParam(value = "reason",required = false)String reason,
                                                                 @ApiParam(name = "doctorId",value = "医生code")
                                                                 @RequestParam(value = "doctorId",required = false)String doctorId){
                                                                 @RequestParam(value = "doctorId",required = false)String doctorId,
                                                                 @ApiParam(name = "name",value = "名字")
                                                                 @RequestParam(value = "name",required = false)String name,
                                                                 @ApiParam(name = "idcard",value = "身份证")
                                                                 @RequestParam(value = "idcard",required = false)String idcard){
        try {
            return service.doctorDescreaseIntegrate(ruleId,patientId,doctorId,hospital,hospitalName,integrate,reason,"add");
            return service.doctorDescreaseIntegrate(ruleId,patientId,doctorId,hospital,hospitalName,integrate,reason,"add",name,idcard);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());

+ 31 - 7
svr/svr-wlyy-health-bank/src/main/java/com/yihu/jw/service/CreditsDetailService.java

@ -988,13 +988,37 @@ public class CreditsDetailService extends BaseJpaService<CreditsDetailDO,Creditt
    }
    public MixEnvelop doctorDescreaseIntegrate(String ruleId,String patientId,String doctorId,String hospital,String hospitalName,Integer integrate,String reason,String type) throws Exception {
       MixEnvelop envelop = new MixEnvelop<>();
       envelop.setObj(true);
       TaskDO taskDO =  taskDao.selectByTaskRuleId(ruleId);
       String sql = "select * from wlyy_health_bank_account where status = 1 and patient_id = '"+patientId+"'";
       List<AccountDO> accountDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
       AccountDO accountDO = accountDOs.get(0);
    public MixEnvelop doctorDescreaseIntegrate(String ruleId,String patientId,String doctorId,String hospital,String hospitalName,Integer integrate,String reason,String type,String name,String idcard) throws Exception {
        MixEnvelop envelop = new MixEnvelop<>();
        envelop.setObj(true);
        TaskDO taskDO =  taskDao.selectByTaskRuleId(ruleId);
        String sql = "select * from wlyy_health_bank_account where status = 1 and patient_id = '"+patientId+"'";
        List<AccountDO> accountDOs = jdbcTemplate.query(sql,new BeanPropertyRowMapper(AccountDO.class));
        AccountDO accountDO = null;
        if("add".equals(type)&&(accountDOs==null||accountDOs.size()==0)){
            //新建账户
            accountDO = new AccountDO();
            accountDO.setTotal(0);
            accountDO.setId(getCode());
            accountDO.setPatientId(patientId);
            accountDO.setAccountName(name);
            accountDO.setHospital(hospital);
            accountDO.setHospitalName(hospitalName);
            if(idcard.length()>=4){// 判断是否长度大于等于4
                String cardNumber=idcard.substring(idcard.length()- 4,idcard.length());//截取两个数字之间的部分
                int random = (int)((Math.random()*9+1)*100000);
                accountDO.setCardNumber(cardNumber+Integer.toString(random));
            }
            accountDO.setPassword("123456");
            accountDO.setSaasId("dev");
            accountDO.setStatus(1);
            accountDO.setCreateTime(new Date());
            accountDO.setUpdateTime(new Date());
            accountDO = accountDao.save(accountDO);
        }else{
            accountDO = accountDOs.get(0);
        }
       if (taskDO == null){
           TaskRuleDO taskRuleDO =  taskRuleDao.findByCode(ruleId);
           TaskDO  taskDO1 = new TaskDO();