|  | @ -4,7 +4,6 @@ package com.yihu.jw.hospital.prescription.service;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.sun.org.apache.regexp.internal.RE;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
 | 
	
	
		
			
				|  | @ -15,34 +14,25 @@ import com.yihu.jw.entity.order.BusinessOrderDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.BaseNatAppointmentDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.BusinessOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.doctor.PersonInfoVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.http.HttpClientUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.WebserviceUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.BasePatientWechatDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
 | 
	
		
			
				|  |  | import com.yihu.utils.date.DateUtil;
 | 
	
		
			
				|  |  | import net.sf.json.xml.XMLSerializer;
 | 
	
		
			
				|  |  | import nu.xom.Builder;
 | 
	
		
			
				|  |  | import nu.xom.Document;
 | 
	
		
			
				|  |  | import nu.xom.Element;
 | 
	
		
			
				|  |  | import nu.xom.Elements;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.math.NumberUtils;
 | 
	
		
			
				|  |  | import org.apache.http.NameValuePair;
 | 
	
		
			
				|  |  | import org.apache.http.message.BasicNameValuePair;
 | 
	
		
			
				|  |  | import org.checkerframework.checker.units.qual.A;
 | 
	
		
			
				|  |  | 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;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.io.StringReader;
 | 
	
		
			
				|  |  | import java.net.URLEncoder;
 | 
	
		
			
				|  |  | import java.math.BigDecimal;
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | @Service
 | 
	
	
		
			
				|  | @ -75,6 +65,13 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         String url = list.get(0).getDictCode();
 | 
	
		
			
				|  |  |         return url;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public String gethsQueryDataWS(){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<WlyyHospitalSysDictDO> list =  wlyyHospitalSysDictDao.findByDictName("hdrQueryDataWSUrl");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String url = list.get(0).getDictCode();
 | 
	
		
			
				|  |  |         return url;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public String getTaszWebServiceInfo(String api, Map<String,String> params, String url)throws Exception{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         logger.info("url"+url);
 | 
	
	
		
			
				|  | @ -88,6 +85,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         return WebserviceUtil.post(url,xzzxNamespace,api,params);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 线上注册
 | 
	
		
			
				|  |  |      * @return
 | 
	
	
		
			
				|  | @ -551,9 +549,9 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |             key.put("first",first);
 | 
	
		
			
				|  |  |             key.put("keyword1",key1);
 | 
	
		
			
				|  |  |             key.put("keyword2",key2);
 | 
	
		
			
				|  |  |             key.put("key3",key3);
 | 
	
		
			
				|  |  |             key.put("key4",key4);
 | 
	
		
			
				|  |  |             key.put("key5",key5);
 | 
	
		
			
				|  |  |             key.put("keyword3",key3);
 | 
	
		
			
				|  |  |             key.put("keyword4",key4);
 | 
	
		
			
				|  |  |             key.put("keyword5",key5);
 | 
	
		
			
				|  |  |             key.put("remark",remark);
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("template_id",wxTemplateConfigDO1.getTemplateId());//
 | 
	
	
		
			
				|  | @ -582,16 +580,16 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |             key3.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key4.put("value",baseNatAppointmentD0.getDoctorName());
 | 
	
		
			
				|  |  |             key4.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key5.put("value",baseNatAppointmentD0.getCreateTime());
 | 
	
		
			
				|  |  |             key5.put("value", DateUtil.formatDate(baseNatAppointmentD0.getCreateTime(),"yyyy-MM-dd hh:mm:ss"));
 | 
	
		
			
				|  |  |             key5.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             remark.put("value",wxTemplateConfigDO1.getRemark());
 | 
	
		
			
				|  |  |             remark.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key.put("first",first);
 | 
	
		
			
				|  |  |             key.put("keyword1",key1);
 | 
	
		
			
				|  |  |             key.put("keyword2",key2);
 | 
	
		
			
				|  |  |             key.put("key3",key3);
 | 
	
		
			
				|  |  |             key.put("key4",key4);
 | 
	
		
			
				|  |  |             key.put("key5",key5);
 | 
	
		
			
				|  |  |             key.put("keyword3",key3);
 | 
	
		
			
				|  |  |             key.put("keyword4",key4);
 | 
	
		
			
				|  |  |             key.put("keyword5",key5);
 | 
	
		
			
				|  |  |             key.put("remark",remark);
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("template_id",wxTemplateConfigDO1.getTemplateId());//
 | 
	
	
		
			
				|  | @ -616,7 +614,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |             key1.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key2.put("value",baseNatAppointmentD0.getInspectionName());
 | 
	
		
			
				|  |  |             key2.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key3.put("value",baseNatAppointmentD0.getAppointmentTime());
 | 
	
		
			
				|  |  |             key3.put("value",DateUtil.formatDate(baseNatAppointmentD0.getAppointmentTime(),"yyyy-MM-dd hh:mm:ss"));
 | 
	
		
			
				|  |  |             key3.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key4.put("value",wxTemplateConfigDO1.getKeyword4());
 | 
	
		
			
				|  |  |             key4.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
	
		
			
				|  | @ -625,8 +623,8 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |             key.put("first",first);
 | 
	
		
			
				|  |  |             key.put("keyword1",key1);
 | 
	
		
			
				|  |  |             key.put("keyword2",key2);
 | 
	
		
			
				|  |  |             key.put("key3",key3);
 | 
	
		
			
				|  |  |             key.put("key4",key4);
 | 
	
		
			
				|  |  |             key.put("keyword3",key3);
 | 
	
		
			
				|  |  |             key.put("keyword4",key4);
 | 
	
		
			
				|  |  |             key.put("remark",remark);
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("template_id",wxTemplateConfigDO1.getTemplateId());//
 | 
	
	
		
			
				|  | @ -827,7 +825,98 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |             if (businessOrderDO!=null&&businessOrderDO.getStatus()==1){
 | 
	
		
			
				|  |  |                 throw new Exception("订单已支付");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             String openId="";
 | 
	
		
			
				|  |  |             List<BasePatientWechatDo> wechatList=basePatientWechatDao.findByWechatIdAndPatientId("xm_tasy_wx",baseNatAppointmentDO.getConsumer());
 | 
	
		
			
				|  |  |             if (wechatList!=null&&wechatList.size()>0){
 | 
	
		
			
				|  |  |                 openId=wechatList.get(0).getOpenid();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             businessOrderDO.setOrderNo("HLWYY"+System.currentTimeMillis()+(int)(Math.random()*900)+100);
 | 
	
		
			
				|  |  |             com.alibaba.fastjson.JSONObject orderObj= new com.alibaba.fastjson.JSONObject();
 | 
	
		
			
				|  |  |             orderObj.put("payType",1);
 | 
	
		
			
				|  |  |             orderObj.put("tradeNo",businessOrderDO.getOrderNo());
 | 
	
		
			
				|  |  |             orderObj.put("openId",openId);
 | 
	
		
			
				|  |  |             orderObj.put("name",baseNatAppointmentDO.getName());
 | 
	
		
			
				|  |  |             orderObj.put("idNo",baseNatAppointmentDO.getCardNo());
 | 
	
		
			
				|  |  |             BigDecimal b = new BigDecimal(baseNatAppointmentDO.getChargeAmount());
 | 
	
		
			
				|  |  |             b=b.setScale(2, BigDecimal.ROUND_DOWN);
 | 
	
		
			
				|  |  |             System.out.println("amount"+b);
 | 
	
		
			
				|  |  |             orderObj.put("amount",b);
 | 
	
		
			
				|  |  |             //重新下单
 | 
	
		
			
				|  |  |             String orderRes=placeOrder(orderObj);
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(orderRes)){
 | 
	
		
			
				|  |  |                 com.alibaba.fastjson.JSONObject jsonObject= JSON.parseObject(orderRes);
 | 
	
		
			
				|  |  |                 if (jsonObject!=null){
 | 
	
		
			
				|  |  |                     if("0".equalsIgnoreCase(jsonObject.getString("code"))){
 | 
	
		
			
				|  |  |                         com.alibaba.fastjson.JSONObject dataObj= com.alibaba.fastjson.JSONObject.parseObject(jsonObject.getString("data"));
 | 
	
		
			
				|  |  |                         businessOrderDO.setTraceNo(dataObj.getString("orderNo"));
 | 
	
		
			
				|  |  |                         businessOrderDO.setRematk(dataObj.toJSONString());
 | 
	
		
			
				|  |  |                         businessOrderDO=businessOrderDao.save(businessOrderDO);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return businessOrderDO.getRematk();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public String getNatResult(String patientId) throws Exception{
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findById(patientId);
 | 
	
		
			
				|  |  |         Calendar c = Calendar.getInstance();
 | 
	
		
			
				|  |  |         c.add(Calendar.MONTH, -6);
 | 
	
		
			
				|  |  |         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 | 
	
		
			
				|  |  |         String dateStr = sdf.format(c.getTime());
 | 
	
		
			
				|  |  |         String idcard="";
 | 
	
		
			
				|  |  |         String hospitalOid="";
 | 
	
		
			
				|  |  |         String wsCode="";
 | 
	
		
			
				|  |  |         if (basePatientDO!=null){
 | 
	
		
			
				|  |  |             idcard=basePatientDO.getIdcard();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         List<WlyyHospitalSysDictDO> list = wlyyHospitalSysDictDao.findByDictName("hdrQueryDataParam");
 | 
	
		
			
				|  |  |         for (WlyyHospitalSysDictDO wlyyHospitalSysDictDO:list){
 | 
	
		
			
				|  |  |             if ("hospitalOid".equalsIgnoreCase(wlyyHospitalSysDictDO.getDictCode())){
 | 
	
		
			
				|  |  |                 hospitalOid=wlyyHospitalSysDictDO.getDictValue();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if ("wsCode".equalsIgnoreCase(wlyyHospitalSysDictDO.getDictCode())){
 | 
	
		
			
				|  |  |                 wsCode=wlyyHospitalSysDictDO.getDictValue();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String res=hdrQueryDataWS(idcard,wsCode,hospitalOid,dateStr);
 | 
	
		
			
				|  |  |         return res;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //病人单据状态查询
 | 
	
		
			
				|  |  |     public String hdrQueryDataWS(String idcard,String wsCode,String oid,String time) throws Exception{
 | 
	
		
			
				|  |  |         /*String api = "hdrQueryDataWS";*/
 | 
	
		
			
				|  |  |         /*String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
 | 
	
		
			
				|  |  |                 "<root> " +
 | 
	
		
			
				|  |  |                 "   <serverName>"+api+"</serverName>  " +
 | 
	
		
			
				|  |  |                 "   <format>xml</format>" +
 | 
	
		
			
				|  |  |                 "   <callOperator>"+operator+"</callOperator> " +
 | 
	
		
			
				|  |  |                 "   <certificate>"+key+"</certificate> " +
 | 
	
		
			
				|  |  |                 "</root>";*/
 | 
	
		
			
				|  |  |         String msg="<HOSPITAL_OID>"+oid+"</HOSPITAL_OID>";
 | 
	
		
			
				|  |  |         if (StringUtils.isNoneBlank()){
 | 
	
		
			
				|  |  |             msg+="<ID_CARD>"+idcard+"</ID_CARD>";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNoneBlank(wsCode)){
 | 
	
		
			
				|  |  |             msg+="<WS_CODE>"+wsCode+"</WS_CODE>";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String condition ="";
 | 
	
		
			
				|  |  |         if (StringUtils.isNoneBlank(time)){
 | 
	
		
			
				|  |  |             condition+="<CONDITION><ELEM NAME=\"LAB_ITEM_NAME\" VALUE=\"核酸\" OPERATOR=\"like\"></ELEM>" +
 | 
	
		
			
				|  |  |                     "<ELEM NAME=\"REPORT_TIME\" VALUE=\""+time+"\" OPERATOR=\">=\"></ELEM></CONDITION>";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String msgBody ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
 | 
	
		
			
				|  |  |                 "<MSG>"+msg+condition+"</MSG>";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String,String> params = new HashedMap();
 | 
	
		
			
				|  |  |         params.put("msg",msgBody);
 | 
	
		
			
				|  |  |         logger.info("hdrQueryDataWS params:"+params.toString());
 | 
	
		
			
				|  |  |         String xml = getTaszWebServiceInfo("hdrQueryDataWS",params,gethsQueryDataWS());
 | 
	
		
			
				|  |  |         xml=xml.substring(xml.indexOf("<ArrayList>"),xml.lastIndexOf("]]"));
 | 
	
		
			
				|  |  |         XMLSerializer xmlSerializer = new XMLSerializer();
 | 
	
		
			
				|  |  |         String json = xmlSerializer.read(xml).toString();
 | 
	
		
			
				|  |  |         logger.info("hdrQueryDataWS json:"+json);
 | 
	
		
			
				|  |  |         return json;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |