瀏覽代碼

增加卡号变更消息推送

hurugang 5 年之前
父節點
當前提交
f94fe124a0

+ 5 - 0
pom.xml

@@ -97,6 +97,11 @@
             <artifactId>poi-ooxml</artifactId>
             <version>RELEASE</version>
         </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 162 - 0
src/main/java/cn/hnthyy/thmz/Utils/HttpUtil.java

@@ -0,0 +1,162 @@
+package cn.hnthyy.thmz.Utils;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpStatus;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * http 请求工具类
+ */
+@Slf4j
+public class HttpUtil {
+    /**
+     * get请求传输数据
+     *
+     * @param url
+     * @param encoding
+     * @return
+     * @throws ClientProtocolException
+     * @throws IOException
+     */
+    public static String sendHttpGet(String url, String encoding) throws ClientProtocolException, IOException {
+        String result = "";
+        // 创建httpclient对象
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        // 创建get方式请求对象
+        HttpGet httpGet = new HttpGet(url);
+        httpGet.addHeader("Content-type", "application/json");
+        // 通过请求对象获取响应对象
+        CloseableHttpResponse response = httpClient.execute(httpGet);
+        // 获取结果实体
+        // 判断网络连接状态码是否正常(0--200都数正常)
+        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+            result = EntityUtils.toString(response.getEntity(), "utf-8");
+        }
+        // 释放链接
+        response.close();
+        return result;
+    }
+
+    /**
+     * POST 请求
+     * @param url
+     * @param JSONBody
+     * @return
+     * @throws Exception
+     */
+    public static String sendHttpPost(String url, String JSONBody) throws Exception {
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        HttpPost httpPost = new HttpPost(url);
+        httpPost.addHeader("Content-Type", "application/json");
+        httpPost.setEntity(new StringEntity(JSONBody));
+        CloseableHttpResponse response = httpClient.execute(httpPost);
+//		System.out.println(response.getStatusLine().getStatusCode() + "\n");
+        HttpEntity entity = response.getEntity();
+        String responseContent = EntityUtils.toString(entity, "UTF-8");
+//		System.out.println(responseContent);
+        response.close();
+        httpClient.close();
+        return responseContent;
+    }
+
+    /**
+     * POST 请求 非JSON 数据
+     * @param url
+     * @param requestParams
+     * @return
+     * @throws Exception
+     */
+    public static String requestOCRForHttp(String url, Map<String, String> requestParams) throws Exception {
+        String result = null;
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        /** HttpPost */
+        HttpPost httpPost = new HttpPost(url);
+        List<NameValuePair> params = new ArrayList<>();
+        Iterator<Map.Entry<String, String>> it = requestParams.entrySet().iterator();
+//		System.out.println(params.toString());
+        while (it.hasNext()) {
+            Map.Entry<String, String> en = it.next();
+            String key = en.getKey();
+            String value = en.getValue();
+            if (value != null) {
+                params.add(new BasicNameValuePair(key, value));
+            }
+        }
+        httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
+        /** HttpResponse */
+        CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
+        try {
+            HttpEntity httpEntity = httpResponse.getEntity();
+            result = EntityUtils.toString(httpEntity, "utf-8");
+            EntityUtils.consume(httpEntity);
+        } finally {
+            try {
+                if (httpResponse != null) {
+                    httpResponse.close();
+                }
+            } catch (IOException e) {
+                log.info("## release resouce error ##" + e);
+            }
+        }
+        return result;
+    }
+
+
+    /**
+     * post请求,发送字符串参数
+     * @param url
+     * @param param
+     * @param contentType
+     * @return
+     */
+    public static String httpPost(String url, String param, String contentType) {
+        try {
+            HttpClient client = new HttpClient();
+            PostMethod post = new PostMethod(url);
+            RequestEntity entity = new StringRequestEntity(param, contentType, "UTF-8");
+            post.setRequestEntity(entity);
+            post.setRequestHeader("Content-Type", contentType);
+            post.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
+            post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 5000);
+            client.executeMethod(post);
+            InputStream in = post.getResponseBodyAsStream();
+            BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
+            StringBuilder sb = new StringBuilder();
+            String temp;
+            while ((temp = reader.readLine()) != null)
+                sb.append(temp);
+            reader.close();
+            return sb.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 30 - 0
src/main/java/cn/hnthyy/thmz/Utils/SignUtil.java

@@ -0,0 +1,30 @@
+package cn.hnthyy.thmz.Utils;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.util.StringUtils;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class SignUtil {
+
+    public static String getSignValue(Map<String, String> map, String key) throws Exception {
+        List<String> list = new ArrayList<>();
+        for (Map.Entry<String, String> entry : map.entrySet())
+            if (null != entry.getValue() && !StringUtils.isEmpty(entry.getValue() + ""))
+                list.add(entry.getKey() + "=" + entry.getValue() + "&");
+        int size = list.size();
+        String[] arrayToSort = list.toArray(new String[size]);
+        Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < size; i++)
+            sb.append(arrayToSort[i]);
+        if (!StringUtils.isEmpty(key))
+            sb.append(key);
+        byte[] target = sb.toString().getBytes(StandardCharsets.UTF_8);
+        return DigestUtils.md5Hex(target).toUpperCase();
+    }
+}

+ 2 - 0
src/main/java/cn/hnthyy/thmz/controller/api/MedicalViewApiController.java

@@ -773,6 +773,7 @@ public class MedicalViewApiController {
             e.printStackTrace();
             results.put("resultCode", -1);
             results.put("resultMessage", "门诊缴费订单支付状态查询失败,请联系管理员");
+            results.put("payStatus", "2");
             log.error("系统异常,错误信息{}", e.getMessage());
             return results;
         }
@@ -1324,6 +1325,7 @@ public class MedicalViewApiController {
             e.printStackTrace();
             results.put("resultCode", -1);
             results.put("resultMessage", "门诊挂号订单支付状态查询失败,请联系管理员");
+            results.put("payStatus", "2");
             log.error("系统异常,错误信息{}", e.getMessage());
             return results;
         }

+ 9 - 1
src/main/java/cn/hnthyy/thmz/service/impl/his/MzPatientMiServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hnthyy.thmz.entity.his.MzPatientMi;
 import cn.hnthyy.thmz.mapper.his.MzPatientMiMapper;
 import cn.hnthyy.thmz.service.his.MzPatientMiService;
 import cn.hnthyy.thmz.service.his.MzSerialNoService;
+import cn.hnthyy.thmz.service.thmz.HaiCiAdapterService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,6 +21,8 @@ public class MzPatientMiServiceImpl implements MzPatientMiService {
     private MzPatientMiMapper mzPatientMiMapper;
     @Autowired
     private MzSerialNoService mzSerialNoService;
+    @Autowired
+    private HaiCiAdapterService haiCiAdapterService;
     @Override
     public MzPatientMi queryByIcCardNo(String icCardNo) {
         return mzPatientMiMapper.selectByIcCardNo(icCardNo);
@@ -55,7 +58,12 @@ public class MzPatientMiServiceImpl implements MzPatientMiService {
         if(StringUtils.isBlank(mzPatientMi.getPatientId())){
             return 0;
         }
-        return mzPatientMiMapper.updateMzPatientMi(mzPatientMi);
+        MzPatientMi mzPatientMiDb= mzPatientMiMapper.selectByPatientId(mzPatientMi.getPatientId());
+        int num= mzPatientMiMapper.updateMzPatientMi(mzPatientMi);
+        if (num>0 && mzPatientMiDb!=null && !mzPatientMiDb.getIcCardNo().equals(mzPatientMi.getIcCardNo())){
+            haiCiAdapterService.cardChangeNotice(mzPatientMiDb.getIcCardNo(),mzPatientMi.getIcCardNo(),new Date());
+        }
+        return num;
     }
 
     @Override

+ 80 - 0
src/main/java/cn/hnthyy/thmz/service/impl/thmz/HaiCiAdapterServiceImpl.java

@@ -0,0 +1,80 @@
+package cn.hnthyy.thmz.service.impl.thmz;
+
+import cn.hnthyy.thmz.Utils.DateUtil;
+import cn.hnthyy.thmz.Utils.HttpUtil;
+import cn.hnthyy.thmz.Utils.SignUtil;
+import cn.hnthyy.thmz.service.thmz.HaiCiAdapterService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+@Slf4j
+@Service
+public class HaiCiAdapterServiceImpl implements HaiCiAdapterService {
+    private static final String th_pwd = "hnthyy2213";
+
+    @Value("${haiciServiceUrl}")
+    private String haiciServiceUrl;
+    //卡号变更通知开关
+    @Value("${sendNoticeToHaiCi}")
+    private boolean sendNoticeToHaiCi;
+
+    /**
+     * 更新病人卡号 消息通知
+     *
+     * @param oldCardNo 老卡号
+     * @param cardNo    新卡号
+     * @param timeStamp 变更时间
+     */
+    @Override
+    public void cardChangeNotice(String oldCardNo, String cardNo, Date timeStamp) {
+        if(!sendNoticeToHaiCi){
+            return;
+        }
+        try {
+            String timeStampStr= DateUtil.fomart(timeStamp, "yyyy-MM-dd HH:mm:ss");
+            Map<String, String> map = getMap(oldCardNo, cardNo, timeStampStr);
+            String result = HttpUtil.httpPost(haiciServiceUrl, getXMLString(oldCardNo,cardNo,timeStampStr),"application/xml");
+            log.info(map.toString());
+            System.out.println(result+"---------------");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 生成map以进行Sign加密
+     */
+    private Map<String, String> getMap(String oldCardNo, String cardNo, String timeStamp) throws Exception {
+        Map<String, String> map = new HashMap<>();
+        map.put("serviceCode", "CardChangeNotice");
+        map.put("partnerId", "hnthyy");
+        map.put("timeStamp", timeStamp);
+        map.put("actionType", "1");
+        map.put("cardType", "1");
+        map.put("oldCardNo", oldCardNo);
+        map.put("cardNo", cardNo);
+        return map;
+    }
+
+    /**
+     * 生成向海鹚发送请求的参数
+     * */
+    private String getXMLString(String oldCardNo,String cardNo,String timeStamp) throws Exception {
+        Map<String, String> map = getMap(oldCardNo,cardNo,timeStamp);
+        return "<?xml version='1.0' encoding='UTF-8'?>\n"
+                + "<Request>\n"
+                + "<serviceCode>CardChangeNotice</serviceCode>\n"
+                + "<partnerId>hnthyy</partnerId>\n"
+                + "<timeStamp>" + timeStamp + "</timeStamp>\n"
+                + "<password>" + SignUtil.getSignValue(map, th_pwd) + "</password>\n"
+                + "<actionType>1</actionType>\n"
+                + "<cardType>1</cardType>\n"
+                + "<cardNo>" + cardNo + "</cardNo>\n"
+                + "<oldCardNo>" + oldCardNo + "</oldCardNo>\n"
+                + "</Request>";
+    }
+}

+ 2 - 38
src/main/java/cn/hnthyy/thmz/service/impl/thmz/MessageServiceImpl.java

@@ -1,19 +1,11 @@
 package cn.hnthyy.thmz.service.impl.thmz;
 
+import cn.hnthyy.thmz.Utils.HttpUtil;
 import cn.hnthyy.thmz.service.thmz.MessageService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.http.HttpStatus;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-
-import java.io.IOException;
 @Slf4j
 @Service
 public class MessageServiceImpl implements MessageService {
@@ -29,7 +21,7 @@ public class MessageServiceImpl implements MessageService {
         }
         try {
             String url = serviceUrl+"?touser="+touser+"&content="+content;
-            sendGetData(url, "utf-8");
+            HttpUtil.sendHttpGet(url, "utf-8");
         } catch (Exception e) {
             e.printStackTrace();
             return 0;
@@ -37,32 +29,4 @@ public class MessageServiceImpl implements MessageService {
         return 1;
     }
 
-
-    /**
-     * get请求传输数据
-     *
-     * @param url
-     * @param encoding
-     * @return
-     * @throws ClientProtocolException
-     * @throws IOException
-     */
-    private String sendGetData(String url, String encoding) throws ClientProtocolException, IOException {
-        String result = "";
-        // 创建httpclient对象
-        CloseableHttpClient httpClient = HttpClients.createDefault();
-        // 创建get方式请求对象
-        HttpGet httpGet = new HttpGet(url);
-        httpGet.addHeader("Content-type", "application/json");
-        // 通过请求对象获取响应对象
-        CloseableHttpResponse response = httpClient.execute(httpGet);
-        // 获取结果实体
-        // 判断网络连接状态码是否正常(0--200都数正常)
-        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
-            result = EntityUtils.toString(response.getEntity(), "utf-8");
-        }
-        // 释放链接
-        response.close();
-        return result;
-    }
 }

+ 13 - 0
src/main/java/cn/hnthyy/thmz/service/thmz/HaiCiAdapterService.java

@@ -0,0 +1,13 @@
+package cn.hnthyy.thmz.service.thmz;
+
+import java.util.Date;
+
+public interface HaiCiAdapterService {
+    /**
+     * 更新病人卡号 消息通知
+     * @param oldCardNo 老卡号
+     * @param cardNo 新卡号
+     * @param timeStamp 变更时间
+     */
+    void cardChangeNotice(String oldCardNo,String cardNo,Date timeStamp);
+}

+ 11 - 2
src/main/resources/application.yml

@@ -39,7 +39,16 @@ mybatis:
 logging:
   level:
     cn.hnthyy.thmz.mapper: info
+
+
+#企业微信消息服务地址测试环境
+#serviceUrl: "http://172.16.30.21:8081/adverse.event/sendWxInfo"
 #企业微信消息服务地址生产环境
 serviceUrl: "http://172.16.32.160:8081/adverse.event/sendWxInfo"
-#企业微信消息服务地址测试环境
-#serviceUrl: "http://172.16.30.21:8081/adverse.event/sendWxInfo"
+
+#卡号变更通知开关
+sendNoticeToHaiCi: false
+#海慈开放服务地址测试环境
+haiciServiceUrl: "https://sapi.med.gzhc365.com/openapi/health"
+#海慈开放服务地址生产环境
+#haiciServiceUrl: "https://api.med.gzhc365.com/openapi/health"

+ 3 - 0
src/main/resources/static/js/registration.js

@@ -322,6 +322,9 @@ $(function () {
     });
     $("#editUserIdCard").change(function (e) {
         var editUserIdCard = $("#editUserIdCard").val();
+        if(editUserIdCard==null || editUserIdCard==""){
+            return;
+        }
         var birthday = editUserIdCard.substring(6, 14);
         birthday = birthday.substring(0, 4) + "-" + birthday.substring(4, 6) + "-" + birthday.substring(6);
         $("#editUserBirthDay").val(birthday);