You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					175 lines
				
				7.4 KiB
			
		
		
			
		
	
	
					175 lines
				
				7.4 KiB
			| 
											3 years ago
										 | package com.ynxbd.ali.helper;
 | ||
|  | 
 | ||
|  | import com.alibaba.fastjson.JSONArray;
 | ||
|  | import com.alibaba.fastjson.JSONObject;
 | ||
|  | import com.alipay.api.AlipayClient;
 | ||
|  | import com.alipay.api.request.AlipayCommerceMedicalIndustrydataDepartmentUploadRequest;
 | ||
|  | import com.alipay.api.request.AlipayCommerceMedicalIndustrydataHospitalUploadRequest;
 | ||
|  | import com.alipay.api.response.AlipayCommerceMedicalIndustrydataDepartmentUploadResponse;
 | ||
|  | import com.alipay.api.response.AlipayCommerceMedicalIndustrydataHospitalUploadResponse;
 | ||
|  | import com.ynxbd.ali.config.AliConfig;
 | ||
|  | import com.ynxbd.common.bean.Dept;
 | ||
|  | import com.ynxbd.common.helper.common.ErrorHelper;
 | ||
|  | import com.ynxbd.common.helper.common.JsonHelper;
 | ||
|  | import com.ynxbd.wx.config.WeChatConfig;
 | ||
|  | import lombok.extern.slf4j.Slf4j;
 | ||
|  | 
 | ||
|  | import java.net.URLEncoder;
 | ||
|  | import java.util.List;
 | ||
|  | import java.util.UUID;
 | ||
|  | 
 | ||
|  | @Slf4j
 | ||
|  | public class AliUploadHelper {
 | ||
|  | 
 | ||
|  |     /**
 | ||
|  |      * 上传医院信息
 | ||
|  |      */
 | ||
|  |     public static void uploadHosp() {
 | ||
|  |         AlipayClient alipayClient = AliHelper.getAliClient();
 | ||
|  |         AlipayCommerceMedicalIndustrydataHospitalUploadRequest request = new AlipayCommerceMedicalIndustrydataHospitalUploadRequest();
 | ||
|  | 
 | ||
|  |         JSONObject reqJson = new JSONObject();
 | ||
|  |         reqJson.put("isv_pid", AliConfig.ISV_PARTNER_ID);
 | ||
|  |         reqJson.put("request_id", UUID.randomUUID().toString());
 | ||
|  | 
 | ||
|  |         JSONArray hospArr = new JSONArray();
 | ||
|  |         JSONObject hospInfoJson = new JSONObject();
 | ||
|  |         hospInfoJson.put("hospital_name", AliConfig.HOSP_NAME);
 | ||
|  |         hospInfoJson.put("hospital_id", AliConfig.HOSP_ID);
 | ||
|  |         hospInfoJson.put("hospital_alias", AliConfig.HOSP_ALIAS);
 | ||
|  |         hospInfoJson.put("hospital_province", AliConfig.HOSP_PROVINCE);
 | ||
|  |         hospInfoJson.put("hospital_city", AliConfig.HOSP_CITY);
 | ||
|  |         hospInfoJson.put("hospital_district", AliConfig.HOSP_DISTRICT);
 | ||
|  |         hospInfoJson.put("hospital_addr", AliConfig.HOSP_ADDR);
 | ||
|  |         hospInfoJson.put("hospital_lgt", AliConfig.HOSP_LGT);
 | ||
|  |         hospInfoJson.put("hospital_lat", AliConfig.HOSP_LAT);
 | ||
|  |         hospInfoJson.put("hospital_type", AliConfig.HOSP_TYPE);
 | ||
|  |         hospInfoJson.put("hospital_grade", AliConfig.HOSP_GRADE);
 | ||
|  |         hospInfoJson.put("hospital_logo", WeChatConfig.getHttpsBaseUrl() + "images/logo.png"); // logo
 | ||
|  | 
 | ||
|  |         hospArr.add(hospInfoJson);
 | ||
|  |         reqJson.put("hospital_list", hospArr);
 | ||
|  | 
 | ||
|  |         log.info("[支付宝-医院信息]上传req={}", JsonHelper.toJsonString(reqJson));
 | ||
|  |         request.setBizContent(JsonHelper.toJsonString(reqJson));
 | ||
|  |         try {
 | ||
|  |             AlipayCommerceMedicalIndustrydataHospitalUploadResponse response = alipayClient.execute(request);
 | ||
|  |             log.info("[支付宝-医院信息]上传resp={}", JsonHelper.toJsonString(response));
 | ||
|  | 
 | ||
|  |             if (!response.isSuccess()) {
 | ||
|  |                 log.error("[支付宝医院信息]上传失败 code={}, msg={}, subMsg={}", response.getCode(), response.getMsg(), response.getSubMsg());
 | ||
|  |             } else {
 | ||
|  |                 log.error("[支付宝医院信息]上传成功");
 | ||
|  |             }
 | ||
|  |         } catch (Exception e) {
 | ||
|  |             ErrorHelper.println(e);
 | ||
|  |         }
 | ||
|  |     }
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  |     public static void uploadDept(List<Dept> deptList, boolean isReserve) {
 | ||
|  |         if (deptList == null || deptList.size() == 0) {
 | ||
|  |             return;
 | ||
|  |         }
 | ||
|  |         if (!AliConfig.IS_PUSH_MSG) {
 | ||
|  |             return;
 | ||
|  |         }
 | ||
|  |         String regFlag = isReserve ? "1" : "0"; // 0:今日挂号;1:预约挂号
 | ||
|  | 
 | ||
|  |         JSONArray deptArr = new JSONArray();
 | ||
|  |         JSONObject deptInfoJson;
 | ||
|  |         String url;
 | ||
|  |         String deptCode, deptName;
 | ||
|  |         String subDeptCode, subDeptName;
 | ||
|  |         List<Dept> children;
 | ||
|  |         for (Dept dept : deptList) {
 | ||
|  |             deptCode = dept.getDeptCode();
 | ||
|  |             deptName = dept.getDeptName();
 | ||
|  |             if (deptCode == null || deptName == null) {
 | ||
|  |                 continue;
 | ||
|  |             }
 | ||
|  |             deptInfoJson = new JSONObject();
 | ||
|  |             url = "deptCode=" + deptCode + "&deptName=" + deptName + "®Flag=" + regFlag;
 | ||
|  |             try {
 | ||
|  |                 url = URLEncoder.encode(url, "UTF-8");
 | ||
|  |             } catch (Exception e) {
 | ||
|  |                 ErrorHelper.println(e);
 | ||
|  |             }
 | ||
|  |             deptInfoJson.put("department_id", deptCode);
 | ||
|  |             deptInfoJson.put("department_name", deptName);
 | ||
|  |             deptInfoJson.put("department_type", "一级科室");
 | ||
|  |             deptInfoJson.put("hospital_name", AliConfig.HOSP_NAME);
 | ||
|  |             deptInfoJson.put("department_url", AliHelper.getLink("pages/home/department/department?" + url, null)); // 科室挂号服务跳转
 | ||
|  |             deptArr.add(deptInfoJson);
 | ||
|  |             if (deptArr.size() > 90) {
 | ||
|  |                 uploadDept(deptArr);
 | ||
|  |                 deptArr.clear();
 | ||
|  |             }
 | ||
|  | 
 | ||
|  |             children = dept.getChildren();
 | ||
|  |             if (children == null || children.size() == 0) {
 | ||
|  |                 continue;
 | ||
|  |             }
 | ||
|  |             for (Dept childDept : children) {
 | ||
|  |                 deptInfoJson = new JSONObject();
 | ||
|  |                 subDeptCode = childDept.getDeptCode();
 | ||
|  |                 subDeptName = childDept.getDeptName();
 | ||
|  |                 if (subDeptCode == null || subDeptName == null) {
 | ||
|  |                     continue;
 | ||
|  |                 }
 | ||
|  | 
 | ||
|  |                 url = "deptCode=" + deptCode + "&subDeptCode=" + subDeptCode + "&deptName=" + deptName + "&subDeptName=" + subDeptName + "®Flag=" + regFlag;
 | ||
|  |                 try {
 | ||
|  |                     url = URLEncoder.encode(url, "UTF-8");
 | ||
|  |                 } catch (Exception e) {
 | ||
|  |                     ErrorHelper.println(e);
 | ||
|  |                 }
 | ||
|  |                 deptInfoJson.put("department_id", deptCode + subDeptCode);
 | ||
|  |                 deptInfoJson.put("department_name", subDeptName);
 | ||
|  |                 deptInfoJson.put("department_type", "二级科室");
 | ||
|  |                 deptInfoJson.put("hospital_name", AliConfig.HOSP_NAME);
 | ||
|  |                 deptInfoJson.put("department_url", AliHelper.getLink("pages/home/department/department?" + url, null)); // 科室挂号服务跳转
 | ||
|  |                 deptArr.add(deptInfoJson);
 | ||
|  |                 if (deptArr.size() > 90) {
 | ||
|  |                     uploadDept(deptArr);
 | ||
|  |                     deptArr.clear();
 | ||
|  |                 }
 | ||
|  |             }
 | ||
|  |         }
 | ||
|  |     }
 | ||
|  | 
 | ||
|  | 
 | ||
|  |     private static void uploadDept(JSONArray deptJson) {
 | ||
|  |         if (deptJson == null || deptJson.size() == 0) {
 | ||
|  |             return;
 | ||
|  |         }
 | ||
|  | 
 | ||
|  |         AlipayClient alipayClient = AliHelper.getAliClient();
 | ||
|  |         AlipayCommerceMedicalIndustrydataDepartmentUploadRequest request = new AlipayCommerceMedicalIndustrydataDepartmentUploadRequest();
 | ||
|  | 
 | ||
|  |         JSONObject reqJson = new JSONObject();
 | ||
|  |         reqJson.put("isv_pid", AliConfig.ISV_PARTNER_ID);
 | ||
|  |         reqJson.put("request_id", UUID.randomUUID().toString().replace("-", ""));
 | ||
|  | 
 | ||
|  |         reqJson.put("department_list", deptJson);
 | ||
|  | 
 | ||
|  |         if (AliConfig.IS_LOG) {
 | ||
|  |             log.info("[支付宝-科室信息]上传入参:{}", JsonHelper.toJsonString(reqJson));
 | ||
|  |         }
 | ||
|  | 
 | ||
|  |         request.setBizContent(JsonHelper.toJsonString(reqJson));
 | ||
|  |         try {
 | ||
|  |             AlipayCommerceMedicalIndustrydataDepartmentUploadResponse response = alipayClient.execute(request);
 | ||
|  |             if (!response.isSuccess()) {
 | ||
|  |                 log.error("[支付宝-科室信息]上传失败 code={}, msg={}, subMsg={}", response.getCode(), response.getMsg(), response.getSubMsg());
 | ||
|  |             } else {
 | ||
|  |                 log.info("[支付宝-科室信息]上传成功");
 | ||
|  |             }
 | ||
|  |         } catch (Exception e) {
 | ||
|  |             ErrorHelper.println(e);
 | ||
|  |         }
 | ||
|  |     }
 | ||
|  | 
 | ||
|  | }
 |