|  | @ -1,20 +1,28 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.hospital.prescription.service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | 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 net.sf.json.xml.XMLSerializer;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | 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;
 | 
	
	
		
			
				|  | @ -22,6 +30,7 @@ import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.ArrayList;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -29,13 +38,20 @@ import java.util.Map;
 | 
	
		
			
				|  |  | @Transactional
 | 
	
		
			
				|  |  | public class TasyNatService {
 | 
	
		
			
				|  |  |     private static Logger logger = LoggerFactory.getLogger(TasyNatService.class);
 | 
	
		
			
				|  |  |     private static String key="bvvsf3JA0mUXMU+mVnMaOQ==";
 | 
	
		
			
				|  |  |     private static String operator="健康之路";
 | 
	
		
			
				|  |  |     private static String key="1";
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao basePatientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HttpClientUtil httpClientUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WlyyHttpLogDao wlyyHttpLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientWechatDao basePatientWechatDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WxTemplateConfigDao wxTemplateConfigDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public String getOperateUrl(){
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -63,13 +79,13 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String registerPatient(JSONObject jsonObject)throws Exception{
 | 
	
		
			
				|  |  |         String api = "SickNocardRegister";
 | 
	
		
			
				|  |  |         /*String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
 | 
	
		
			
				|  |  |         String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
 | 
	
		
			
				|  |  |                 "<root> " +
 | 
	
		
			
				|  |  |                 "   <serverName>"+api+"</serverName>  " +
 | 
	
		
			
				|  |  |                 "   <format>xml</format>" +
 | 
	
		
			
				|  |  |                 "   <callOperator></callOperator> " +
 | 
	
		
			
				|  |  |                 "   <callOperator>"+operator+"</callOperator> " +
 | 
	
		
			
				|  |  |                 "   <certificate>"+key+"</certificate> " +
 | 
	
		
			
				|  |  |                 "</root>";*/
 | 
	
		
			
				|  |  |                 "</root>";
 | 
	
		
			
				|  |  |         String condition ="";
 | 
	
		
			
				|  |  |         if (StringUtils.isNoneBlank(jsonObject.getString("IdType"))){
 | 
	
		
			
				|  |  |             condition += "<IdType>"+jsonObject.getString("IdType")+"</IdType>";
 | 
	
	
		
			
				|  | @ -139,7 +155,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |                 "<root>"+condition+"</root>";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String,String> params = new HashedMap();
 | 
	
		
			
				|  |  |         //params.put("msgHeader",msgHeader);
 | 
	
		
			
				|  |  |         params.put("msgHeader",msgHeader);
 | 
	
		
			
				|  |  |         params.put("msgBody",msgBody);
 | 
	
		
			
				|  |  |         logger.info("registerPatient params:"+params.toString());
 | 
	
		
			
				|  |  |         String xml = getTaszWebServiceInfo("CallInterface",params,getOperateUrl());
 | 
	
	
		
			
				|  | @ -158,7 +174,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |                 "<root> " +
 | 
	
		
			
				|  |  |                 "   <serverName>"+api+"</serverName>  " +
 | 
	
		
			
				|  |  |                 "   <format>xml</format>" +
 | 
	
		
			
				|  |  |                 "   <callOperator></callOperator> " +
 | 
	
		
			
				|  |  |                 "   <callOperator>"+operator+"</callOperator> " +
 | 
	
		
			
				|  |  |                 "   <certificate>"+key+"</certificate> " +
 | 
	
		
			
				|  |  |                 "</root>";
 | 
	
		
			
				|  |  |         String condition ="";
 | 
	
	
		
			
				|  | @ -195,7 +211,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(itemObject.getString("itemPrice"))){
 | 
	
		
			
				|  |  |                 itemCoditon += "<itemPrice>"+itemCoditon+"</itemPrice>";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             condition += "<itemList><item>"+jsonObject.getString("clinicFee")+"</item></itemList>";
 | 
	
		
			
				|  |  |             condition += "<itemList><item>"+itemCoditon+"</item></itemList>";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String msgBody ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
 | 
	
		
			
				|  |  |                 "<root>"+condition+"</root>";
 | 
	
	
		
			
				|  | @ -220,7 +236,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |                 "<root> " +
 | 
	
		
			
				|  |  |                 "   <serverName>"+api+"</serverName>  " +
 | 
	
		
			
				|  |  |                 "   <format>xml</format>" +
 | 
	
		
			
				|  |  |                 "   <callOperator></callOperator> " +
 | 
	
		
			
				|  |  |                 "   <callOperator>"+operator+"</callOperator> " +
 | 
	
		
			
				|  |  |                 "   <certificate>"+key+"</certificate> " +
 | 
	
		
			
				|  |  |                 "</root>";
 | 
	
		
			
				|  |  |         String condition ="";
 | 
	
	
		
			
				|  | @ -257,7 +273,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |                 "<root> " +
 | 
	
		
			
				|  |  |                 "   <serverName>"+api+"</serverName>  " +
 | 
	
		
			
				|  |  |                 "   <format>xml</format>" +
 | 
	
		
			
				|  |  |                 "   <callOperator></callOperator> " +
 | 
	
		
			
				|  |  |                 "   <callOperator>"+operator+"</callOperator> " +
 | 
	
		
			
				|  |  |                 "   <certificate>"+key+"</certificate> " +
 | 
	
		
			
				|  |  |                 "</root>";
 | 
	
		
			
				|  |  |         String condition ="";
 | 
	
	
		
			
				|  | @ -334,6 +350,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         String res="";
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             res = insertNucleicBill(jsonObject);
 | 
	
		
			
				|  |  |             saveHttpLog("insertNucleicBill",jsonObject.toString(),res,"insertNucleicBill");
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(res)){
 | 
	
		
			
				|  |  |                 return res;
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -352,6 +369,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         String res="";
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             res = cancelNucleicBill(jsonObject);
 | 
	
		
			
				|  |  |             saveHttpLog("cancelNat",jsonObject.toString(),res,"cancelNat");
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(res)){
 | 
	
		
			
				|  |  |                 return res;
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -370,6 +388,7 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         String res="";
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             res = ChargenucleicBill(jsonObject);
 | 
	
		
			
				|  |  |             saveHttpLog("chargeBill",jsonObject.toString(),res,"chargeBill");
 | 
	
		
			
				|  |  |             if (StringUtils.isNoneBlank(res)){
 | 
	
		
			
				|  |  |                 return res;
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -391,9 +410,18 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         if (wlyyHospitalSysDictDO!=null){
 | 
	
		
			
				|  |  |             url=wlyyHospitalSysDictDO.getDictValue();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         System.out.println(url);
 | 
	
		
			
				|  |  |         List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("placeOrder", jsonObject.toJSONString()));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("payType", jsonObject.getString("payType")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("tradeNo", jsonObject.getString("tradeNo")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("openId", jsonObject.getString("openId")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("name", jsonObject.getString("name")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("idNo", jsonObject.getString("idNo")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("amount", jsonObject.getString("amount")));
 | 
	
		
			
				|  |  |         System.out.println(params.toString());
 | 
	
		
			
				|  |  |         String response = httpClientUtil.post(url,params ,"UTF-8");
 | 
	
		
			
				|  |  |         System.out.println("res"+response);
 | 
	
		
			
				|  |  |         saveHttpLog("placeOrder",params.toString(),response,url);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -403,9 +431,13 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         if (wlyyHospitalSysDictDO!=null){
 | 
	
		
			
				|  |  |             url=wlyyHospitalSysDictDO.getDictValue();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         System.out.println(url);
 | 
	
		
			
				|  |  |         List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("orderStatus", jsonObject.toJSONString()));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("orderNo", jsonObject.getString("orderNo")));
 | 
	
		
			
				|  |  |         System.out.println(params.toString());
 | 
	
		
			
				|  |  |         String response = httpClientUtil.post(url,params ,"UTF-8");
 | 
	
		
			
				|  |  |         System.out.println("res"+response);
 | 
	
		
			
				|  |  |         saveHttpLog("orderStatus",params.toString(),response,url);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -415,10 +447,86 @@ public class TasyNatService {
 | 
	
		
			
				|  |  |         if (wlyyHospitalSysDictDO!=null){
 | 
	
		
			
				|  |  |             url=wlyyHospitalSysDictDO.getDictValue();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         System.out.println(url);
 | 
	
		
			
				|  |  |         List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("orderStatus", jsonObject.toJSONString()));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("tempateId", jsonObject.getString("tempateId")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("url", jsonObject.getString("url")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("openId", jsonObject.getString("openId")));
 | 
	
		
			
				|  |  |         params.add(new BasicNameValuePair("data", jsonObject.getJSONObject("data").toString()));
 | 
	
		
			
				|  |  |         System.out.println(params.toString());
 | 
	
		
			
				|  |  |         String response = httpClientUtil.post(url,params ,"UTF-8");
 | 
	
		
			
				|  |  |         System.out.println("res"+response);
 | 
	
		
			
				|  |  |         saveHttpLog("tmpPush",params.toString(),response,url);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public void  saveHttpLog(String name,String req,String res,String code){
 | 
	
		
			
				|  |  |         WlyyHttpLogDO wlyyHttpLogDO = new WlyyHttpLogDO();
 | 
	
		
			
				|  |  |         wlyyHttpLogDO.setRequest(req);
 | 
	
		
			
				|  |  |         wlyyHttpLogDO.setName(name);
 | 
	
		
			
				|  |  |         wlyyHttpLogDO.setCode(code);
 | 
	
		
			
				|  |  |         wlyyHttpLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         wlyyHttpLogDO.setResponse(res);
 | 
	
		
			
				|  |  |         wlyyHttpLogDao.save(wlyyHttpLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     public String sendWxtemplateMessaeg(String patient,String name,String scene){
 | 
	
		
			
				|  |  |         String url="";
 | 
	
		
			
				|  |  |         String openId="";
 | 
	
		
			
				|  |  |         JSONObject key=new JSONObject();
 | 
	
		
			
				|  |  |         JSONObject key1=new JSONObject();
 | 
	
		
			
				|  |  |         JSONObject key2=new JSONObject();
 | 
	
		
			
				|  |  |         List<BasePatientWechatDo> basePatientWechatDo = basePatientWechatDao.findByWechatIdAndPatientId("xm_tasy_wx",patient);
 | 
	
		
			
				|  |  |         if (basePatientWechatDo!=null&&basePatientWechatDo.size()>0){
 | 
	
		
			
				|  |  |             openId=basePatientWechatDo.get(0).getOpenid();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if ("hszfcg".equalsIgnoreCase(scene)){
 | 
	
		
			
				|  |  |             //开始发送模板消息
 | 
	
		
			
				|  |  |             logger.info("开始发送模板消息");
 | 
	
		
			
				|  |  |             List<WxTemplateConfigDO> wxTemplateConfigDO = wxTemplateConfigDao.findByWechatIdAndScene("xm_tasy_wx",scene);
 | 
	
		
			
				|  |  |             WxTemplateConfigDO wxTemplateConfigDO1 = new WxTemplateConfigDO();
 | 
	
		
			
				|  |  |             if (wxTemplateConfigDO!=null&&wxTemplateConfigDO.size()>0){
 | 
	
		
			
				|  |  |                 wxTemplateConfigDO1 = wxTemplateConfigDO.get(0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             url=wxTemplateConfigDO1.getUrl();
 | 
	
		
			
				|  |  |             key1.put("value",wxTemplateConfigDO1.getKeyword1().replace("key1",name));
 | 
	
		
			
				|  |  |             key1.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key2.put("value",wxTemplateConfigDO1.getKeyword1().replace("key1",name));
 | 
	
		
			
				|  |  |             key2.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key.put("keyword1",key1);
 | 
	
		
			
				|  |  |             key.put("keyword2",key2);
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("tempateId",wxTemplateConfigDO1.getTemplateId());//
 | 
	
		
			
				|  |  |             jsonObject.put("data",key);
 | 
	
		
			
				|  |  |             jsonObject.put("openId",openId);
 | 
	
		
			
				|  |  |             jsonObject.put("url",wxTemplateConfigDO1.getUrl());
 | 
	
		
			
				|  |  |             logger.info("核酸检测支付成功模板消息推送param"+jsonObject.toString());
 | 
	
		
			
				|  |  |             String tmResilt= tmpPush(jsonObject);
 | 
	
		
			
				|  |  |             return tmResilt;
 | 
	
		
			
				|  |  |         } else if ("hszftx".equalsIgnoreCase(scene)) {
 | 
	
		
			
				|  |  |             //开始发送模板消息
 | 
	
		
			
				|  |  |             logger.info("开始发送模板消息");
 | 
	
		
			
				|  |  |             List<WxTemplateConfigDO> wxTemplateConfigDO = wxTemplateConfigDao.findByWechatIdAndScene("xm_tasy_wx",scene);
 | 
	
		
			
				|  |  |             WxTemplateConfigDO wxTemplateConfigDO1 = new WxTemplateConfigDO();
 | 
	
		
			
				|  |  |             if (wxTemplateConfigDO!=null&&wxTemplateConfigDO.size()>0){
 | 
	
		
			
				|  |  |                 wxTemplateConfigDO1 = wxTemplateConfigDO.get(0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             url=wxTemplateConfigDO1.getUrl();
 | 
	
		
			
				|  |  |             key1.put("value",wxTemplateConfigDO1.getKeyword1().replace("key1",name));
 | 
	
		
			
				|  |  |             key1.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key2.put("value",wxTemplateConfigDO1.getKeyword1().replace("key1",name));
 | 
	
		
			
				|  |  |             key2.put("color",wxTemplateConfigDO1.getKeyword6());
 | 
	
		
			
				|  |  |             key.put("keyword1",key1);
 | 
	
		
			
				|  |  |             key.put("keyword2",key2);
 | 
	
		
			
				|  |  |             JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |             jsonObject.put("tempateId",wxTemplateConfigDO1.getTemplateId());//
 | 
	
		
			
				|  |  |             jsonObject.put("data",key);
 | 
	
		
			
				|  |  |             jsonObject.put("openId",openId);
 | 
	
		
			
				|  |  |             jsonObject.put("url",wxTemplateConfigDO1.getUrl());
 | 
	
		
			
				|  |  |             logger.info("核酸检测支付提醒模板消息推送param"+jsonObject.toString());
 | 
	
		
			
				|  |  |             String tmResilt= tmpPush(jsonObject);
 | 
	
		
			
				|  |  |             return tmResilt;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |