package com.ruoyi.common.utils.civilAviation;
|
|
|
import com.alibaba.fastjson2.JSON;
|
import com.ruoyi.common.core.domain.entity.ServiceOrderAppVo;
|
import com.ruoyi.common.core.domain.entity.ServiceOrderAppResultVo;
|
import com.ruoyi.common.core.domain.entity.ServiceOrderDelVo;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
import java.io.IOException;
|
import java.io.UnsupportedEncodingException;
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.net.URLEncoder;
|
import java.nio.charset.StandardCharsets;
|
import java.util.Calendar;
|
|
/**
|
* 民航医疗接口处理
|
*/
|
@Component
|
public class ServiceOrderUtil {
|
private static final Logger log = LoggerFactory.getLogger(ServiceOrderUtil.class);
|
private static String addServiceOrederAPI;
|
|
@Value("${min.apiUrl}")
|
public void setAddServiceOrederAPI(String apiUrl) {
|
ServiceOrderUtil.addServiceOrederAPI = apiUrl;
|
}
|
|
public static String getAddServiceOrederAPI() {
|
return addServiceOrederAPI;
|
}
|
|
/**
|
* 创建服务单
|
*
|
* @param model 服务单应用值对象
|
* @return 服务单接口调用结果
|
*/
|
public static ServiceOrderAppResultVo CreateServiceOrder(ServiceOrderAppVo model,String appSecret) {
|
if (addServiceOrederAPI.isEmpty()) {
|
// log.info("AddServiceOrederAPI 未设置,请先设置接口地址。");
|
return null;
|
}
|
|
log.info("接口地址:"+addServiceOrederAPI);
|
|
//计算时间戳和签名
|
long unixTime = System.currentTimeMillis() / 1000; // 获取当前时间戳(秒) Long.valueOf("1746444543") ;//
|
model.setUnixTime(unixTime); // 设置时间戳到模型中
|
|
// 将 model 转换为 Map<String, String>
|
Map<String, String> params = new HashMap<>();
|
java.lang.reflect.Field[] fields = model.getClass().getDeclaredFields();
|
for (java.lang.reflect.Field field : fields) {
|
field.setAccessible(true);
|
try {
|
Object value = field.get(model);
|
if (value != null) {
|
params.put(field.getName(),URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
|
}
|
} catch (IllegalAccessException e) {
|
// log.error("获取对象属性值时出错", e);
|
} catch (UnsupportedEncodingException e) {
|
throw new RuntimeException(e);
|
}
|
}
|
|
model.setSign(ServiceOrderSign.generateSign(params,appSecret)); // 生成签名并设置到模型中
|
|
log.info("Sign值="+model.getSign());
|
|
// 替换为
|
StringBuilder formData = new StringBuilder();
|
java.lang.reflect.Field[] fieldsQuest = model.getClass().getDeclaredFields();
|
for (java.lang.reflect.Field field : fieldsQuest) {
|
field.setAccessible(true);
|
try {
|
Object value = field.get(model);
|
if (value != null) {
|
if (formData.length() > 0) {
|
formData.append("&");
|
}
|
// 将字段名首字母大写
|
String fieldName = field.getName();
|
String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
|
|
formData.append(capitalizedFieldName)
|
.append("=")
|
.append(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
|
}
|
} catch (Exception e) {
|
// log.error("拼接表单数据时出错", e);
|
}
|
}
|
|
log.info("请求参数="+formData.toString());
|
|
String responseData = HttpUtils.sendPost(addServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded");
|
|
|
if (responseData != null && !responseData.isEmpty()) {
|
// log.info("接口响应: " + responseData);
|
try {
|
// 使用 FastJSON 将响应数据转换为 ServiceOrderAppResultVo 对象
|
return JSON.parseObject(responseData, ServiceOrderAppResultVo.class);
|
} catch (Exception e) {
|
// log.info("解析接口响应数据失败: " + e.getMessage());
|
}
|
} else {
|
// log.info("接口调用失败,未获取到有效响应数据");
|
}
|
|
return null;
|
}
|
|
|
/**
|
* 取消服务单
|
*
|
* @param model 服务订单删除请求值对象
|
* @return 服务订单删除接口调用结果
|
*/
|
public static ServiceOrderAppResultVo CancelServiceOrder(ServiceOrderDelVo model,String appSecret) {
|
if (addServiceOrederAPI.isEmpty()) {
|
// log.info("AddServiceOrederAPI 未设置,请先设置接口地址。");
|
return null;
|
}
|
|
// 计算时间戳和签名
|
long unixTime = System.currentTimeMillis() / 1000;
|
model.setUnixTime(unixTime);
|
|
// 将 model 转换为 Map<String, String>
|
Map<String, String> params = new HashMap<>();
|
java.lang.reflect.Field[] fields = model.getClass().getDeclaredFields();
|
for (java.lang.reflect.Field field : fields) {
|
field.setAccessible(true);
|
try {
|
Object value = field.get(model);
|
if (value != null) {
|
params.put(field.getName(), value.toString());
|
}
|
} catch (IllegalAccessException e) {
|
// log.error("获取对象属性值时出错", e);
|
}
|
}
|
|
model.setSign(ServiceOrderSign.generateSign(params,appSecret));
|
|
// 构建表单数据
|
StringBuilder formData = new StringBuilder();
|
java.lang.reflect.Field[] fieldsQuest = model.getClass().getDeclaredFields();
|
for (java.lang.reflect.Field field : fieldsQuest) {
|
field.setAccessible(true);
|
try {
|
Object value = field.get(model);
|
if (value != null) {
|
if (formData.length() > 0) {
|
formData.append("&");
|
}
|
// 将字段名首字母大写
|
String fieldName = field.getName();
|
formData.append(fieldName)
|
.append("=")
|
.append(URLEncoder.encode(value.toString(), StandardCharsets.UTF_8.toString()));
|
}
|
} catch (Exception e) {
|
// log.error("拼接表单数据时出错", e);
|
}
|
}
|
|
String responseData = HttpUtils.sendPost(addServiceOrederAPI, formData.toString(), "application/x-www-form-urlencoded");
|
|
if (responseData != null && !responseData.isEmpty()) {
|
// log.info("接口响应: " + responseData);
|
try {
|
return JSON.parseObject(responseData, ServiceOrderAppResultVo.class);
|
} catch (Exception e) {
|
// log.info("解析接口响应数据失败: " + e.getMessage());
|
}
|
} else {
|
// log.info("接口调用失败,未获取到有效响应数据");
|
}
|
|
return null;
|
}
|
|
|
public static void main(String[] args) {
|
// 创建服务单应用值对象并设置相关模拟属性
|
test();
|
|
// testCancelServiceOrder();
|
}
|
|
//测试取消服务单
|
public static void testCancelServiceOrder() {
|
// 创建服务单应用值对象并设置相关模拟属性
|
ServiceOrderDelVo model = new ServiceOrderDelVo();
|
model.setMethod("ServiceOrder_DEL"); // 设置接口名称
|
model.setAPPID("GDS-000001"); // 设置商户 APPID
|
model.setServiceOrdID("1016302854"); // 设置服务单ID
|
model.setDELRemarks("测试");
|
|
// 调用 CancelServiceOrder 方法取消服务单
|
// ServiceOrderAppResultVo result = CancelServiceOrder(model);
|
// System.out.println("1");
|
}
|
|
public static void test()
|
{
|
ServiceOrderAppVo model = new ServiceOrderAppVo();
|
model.setMethod("ServiceOrder_APP"); // 设置接口名称
|
model.setAppId("GDS-000001"); // 设置商户 APPID
|
model.setOrdType(2);
|
model.setCoPhone("13" + (int) (Math.random() * 900000000 + 100000000)); // 随机生成客户联系电话
|
model.setCoName("客户" + (int) (Math.random() * 100)); // 随机生成客户姓名
|
model.setCoTies("家属"); // 随机设置客户联系人与患者关系
|
// 设置预约时间为一天后
|
Calendar calendar = Calendar.getInstance();
|
calendar.add(Calendar.DAY_OF_MONTH, 1); // 增加一天
|
|
String testTime = "2025-05-03%2021:33";
|
model.setApptDate(testTime); // 设置预约运送时间为明天
|
model.setPtName("患者姓名" + (int) (Math.random() * 100)); // 随机生成患者姓名
|
model.setPtAge((int) (Math.random() * 100) + "岁"); // 随机生成患者年龄
|
model.setPtSex(Math.random() > 0.5 ? "男" : "女"); // 随机生成患者性别
|
model.setPtNat("中国"); // 随机设置患者国籍
|
model.setOutHosp("广州天河"); // 随机设置转出医院
|
model.setInHosp("广州海珠"); // 随机设置转入医院
|
model.setPtServices("科室" + (int) (Math.random() * 10)); // 随机设置患者所在科室
|
model.setPtDiagnosis("随机诊断信息"); // 随机设置诊断信息
|
model.setCondition("随机备注信息"); // 随机设置备注信息
|
model.setDoctor("医生" + (int) (Math.random() * 10)); // 随机设置患者医生
|
model.setDoctorPhone("13" + (int) (Math.random() * 900000000 + 100000000)); // 随机生成患者医生电话
|
model.setOfferPrice(Math.random() * 1000); // 随机生成报价
|
model.setReferrals("推介人" + (int) (Math.random() * 10)); // 随机设置推介人信息
|
model.setUnitRemarks("商户随机备注信息"); // 随机设置商户备注
|
model.setPayQRcodeURL("https://example.com/qrcode/" + (int) (Math.random() * 100)); // 随机生成外部支付二维码链接
|
|
// 调用 CreateServiceOrder 方法创建服务单
|
// ServiceOrderAppResultVo result = CreateServiceOrder(model);
|
}
|
|
}
|