init version for new gitea

This commit is contained in:
terry.wang
2025-11-13 13:56:50 +08:00
commit c47b86edbe
389 changed files with 42329 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package com.saye.hrs.service;
/**
* @description: 排队叫号业务接口
* @author: Mr.zs
* @create: 2024-04-15 16:57
**/
public interface CallNumbersService {
String getCallNumberByIdentity(String identity,String sfzh);
}

View File

@@ -0,0 +1,25 @@
package com.saye.hrs.service;
import com.saye.hrs.vo.DeptListVo;
import com.saye.hrs.vo.DeptVo;
import java.util.List;
/**
* @description: his视图业务接口
* @author: Mr.zs
* @create: 2024-04-15 17:03
**/
public interface HisViewSearchService {
String getHistoricalVisits(String patientName, String idcard);
List<DeptListVo> getHisDeptList();
List<DeptVo> getHisDept(String deptId);
List<DeptVo> getHisDeptAdd();
}

View File

@@ -0,0 +1,18 @@
package com.saye.hrs.service;
import java.util.HashMap;
/**
* @description: 导诊业务接口
* @author: Mr.zs
* @create: 2024-04-15 12:08
**/
public interface IntelligentGuidanceCategoryService {
String getSymptom(String bodyAreaType);
String getQuestionsByChildId(String childId);
String getAllBodyArea(HashMap<String,Object> reqMap);
}

View File

@@ -0,0 +1,10 @@
package com.saye.hrs.service;
/**
* @description: 医嘱查询业务接口
* @author: Mr.zs
* @create: 2024-04-15 18:01
**/
public interface MedicalAdviceEnquiryService {
}

View File

@@ -0,0 +1,31 @@
package com.saye.hrs.service;
import com.saye.hrs.commons.wxpay.pojo.WxResult;
import com.saye.hrs.dto.PayQuery;
import com.saye.hrs.dto.WxAppletPayRequest;
import com.saye.hrs.dto.WxybAppletReuqest;
import com.saye.hrs.model.WxybResult;
import java.util.HashMap;
import java.util.Map;
/***
* @title PayService
* @description TODO 请填写注释
* @author thuang
* @create 2023/8/14 8:46
**/
public interface PayService {
Map wxAppletPay(WxAppletPayRequest reqDTO) throws Exception;
void wxPayNofify(WxResult wxResult);
Map ybAppletPay(WxybAppletReuqest reqDTO);
Map findWxPayResult(PayQuery reqDTO) throws Exception;
void wxybPayNofify(WxybResult wxybResult);
Map findWxybPayResult(PayQuery reqDTO) throws Exception;
}

View File

@@ -0,0 +1,9 @@
package com.saye.hrs.service;
/**
* @description: 系统参数获取接口
* @author: Mr.zs
* @create: 2024-04-16 16:23
**/
public interface ServiceParamService {
}

View File

@@ -0,0 +1,40 @@
package com.saye.hrs.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.saye.hrs.service.CallNumbersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @description: 排队叫号业务接口实现类
* @author: Mr.zs
* @create: 2024-04-15 16:57
**/
@Service
@Slf4j
public class CallNumbersServiceImpl implements CallNumbersService {
private static final String DATA_GET_URL = "http://12.0.2.1:8081/dataManager";
// private static final String DATA_GET_URL = "http://218.84.202.146:58080/datamsg";
@Override
public String getCallNumberByIdentity(String identity, String sfzh) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("identity", identity);
paramMap.put("sfzh", sfzh);
String result = HttpUtil.get(DATA_GET_URL + "/callNumbers/getCallNumberByIdentity", paramMap);
log.info("result is :" + result);
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {//响应成功
Object resData = resultJson.get("data");
return JSONUtil.toJsonStr(resData);
}
return null;
}
}

View File

@@ -0,0 +1,88 @@
package com.saye.hrs.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.saye.hrs.commons.JsonUtils;
import com.saye.hrs.service.HisViewSearchService;
import com.saye.hrs.vo.DeptListVo;
import com.saye.hrs.vo.DeptVo;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @description: his视图业务接口实现类
* @author: Mr.zs
* @create: 2024-04-15 17:03
**/
@Service
public class HisViewSearchServiceImpl implements HisViewSearchService {
private static final String DATA_GET_URL = "http://12.0.2.1:8081/dataManager";
// private static final String DATA_GET_URL = "http://218.84.202.146:58080/datamsg";
//addtional datamanger
private static final String DATA_GET_ADDURL = "http://12.0.2.1:8081/dataManagerAdd";
@Override
public String getHistoricalVisits(String patientName, String idcard) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("patient_name", patientName);
paramMap.put("idcard", idcard);
String result = HttpUtil.get(DATA_GET_URL + "/hisViewSearch/getHistoricalVisits", paramMap);
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object resData = resultJson.get("data");
return JSONUtil.toJsonStr(resData);
}
return null;
}
@Override
public List<DeptListVo> getHisDeptList() {
HashMap<String, Object> map = new HashMap<>();
List<DeptListVo> deptListVos= new ArrayList<>();
String result = HttpUtil.get(DATA_GET_URL + "/hisViewSearch/getHisDeptList");
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object data = resultJson.get("data");
deptListVos = JsonUtils.jsonToList(data.toString(), DeptListVo.class);
}
return deptListVos;
}
@Override
public List<DeptVo> getHisDept(String deptId) {
HashMap<String, Object> reqmap = new HashMap<>();
HashMap<String, Object> resMap = new HashMap<>();
List<DeptVo> deptVos= new ArrayList<>();
reqmap.put("deptId",deptId);
String result = HttpUtil.get(DATA_GET_URL + "/hisViewSearch/getHisDept", reqmap);
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object data = resultJson.get("data");
deptVos = JsonUtils.jsonToList(data.toString(), DeptVo.class);
}
return deptVos;
}
@Override
public List<DeptVo> getHisDeptAdd() {
HashMap<String, Object> reqmap = new HashMap<>();
HashMap<String, Object> resMap = new HashMap<>();
List<DeptVo> deptVos= new ArrayList<>();
String result = HttpUtil.get(DATA_GET_ADDURL + "/hisViewSearch/getHisDeptAdd");
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object data = resultJson.get("data");
deptVos = JsonUtils.jsonToList(data.toString(), DeptVo.class);
}
return deptVos;
}
}

View File

@@ -0,0 +1,65 @@
package com.saye.hrs.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.saye.hrs.service.IntelligentGuidanceCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @description: 导诊业务接口实现类
* @author: Mr.zs
* @create: 2024-04-15 12:08
**/
@Service
@Slf4j
public class IntelligentGuidanceCategoryServiceImpl implements IntelligentGuidanceCategoryService {
private static final String DATA_GET_URL = "http://12.0.2.1:8081/dataManager";
// private static final String DATA_GET_URL = "http://218.84.202.146:58080/datamsg";
@Override
public String getSymptom(String bodyAreaType) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("bodyAreaType", bodyAreaType);
String result = HttpUtil.get(DATA_GET_URL + "/IntelligentGuidance/getSymptom", paramMap);
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object resData = resultJson.get("data");
return JSONUtil.toJsonStr(resData);
}
return null;
}
@Override
public String getQuestionsByChildId(String childId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("childId", childId);
String result = HttpUtil.get(DATA_GET_URL + "/IntelligentGuidance/getQuestions", paramMap);
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object resData = resultJson.get("data");
return JSONUtil.toJsonStr(resData);
}
return null;
}
@Override
public String getAllBodyArea(HashMap<String, Object> reqMap) {
log.info("reqMap:{}", reqMap);
String result = HttpUtil.get(DATA_GET_URL + "/IntelligentGuidance/getAllBodyArea", reqMap);
JSONObject resultJson = JSONUtil.parseObj(result);
if (Convert.toInt(resultJson.get("status")) > 0) {// 响应成功
Object resData = resultJson.get("data");
return JSONUtil.toJsonStr(resData);
}
return null;
}
}

View File

@@ -0,0 +1,14 @@
package com.saye.hrs.service.impl;
import com.saye.hrs.service.MedicalAdviceEnquiryService;
import org.springframework.stereotype.Service;
/**
* @description: 医嘱查询业务接口实现类
* @author: Mr.zs
* @create: 2024-04-15 18:01
**/
@Service
public class MedicalAdviceEnquiryServiceImpl implements MedicalAdviceEnquiryService {
}

View File

@@ -0,0 +1,746 @@
package com.saye.hrs.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayUtil;
import com.saye.hrs.commons.HttpUtil;
import com.saye.hrs.commons.IPUtil;
import com.saye.hrs.commons.JsonUtils;
import com.saye.hrs.commons.date.DateDUtil;
import com.saye.hrs.commons.exception.CustomException;
import com.saye.hrs.commons.idcard.Ic;
import com.saye.hrs.commons.log.LogUtil;
import com.saye.hrs.commons.qitahoutai.HoutaiService;
import com.saye.hrs.commons.string.StringDUtil;
import com.saye.hrs.commons.webservice.OtherWSUtil;
import com.saye.hrs.commons.wxpay.MyConfig;
import com.saye.hrs.commons.wxpay.WxPayDUtil;
import com.saye.hrs.commons.wxpay.pojo.PassbackParams;
import com.saye.hrs.commons.wxpay.pojo.WxPay;
import com.saye.hrs.commons.wxpay.pojo.WxResult;
import com.saye.hrs.dto.*;
import com.saye.hrs.enums.MedTradeStateEnum;
import com.saye.hrs.model.MessageVo;
import com.saye.hrs.model.StatusDefine;
import com.saye.hrs.model.WxybResult;
import com.saye.hrs.model.YbPassbackParams;
import com.saye.hrs.scheduler.RetrieveAccessToken;
import com.saye.hrs.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author zmc
* @description: 支付
*/
@Service
@Slf4j
public class PayServiceImpl implements PayService {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Object.class);
@Autowired
private RestTemplate restTemplate;
@Resource
private HoutaiService houtaiService;
@Value("${hospital_name}")
private String hospital_name;
@Value("${notifyUrl}")
private String notifyUrl;
@Value("${ybNotifyUrl}")
private String ybNotifyUrl;
@Autowired
private Environment environment;
private static Map<String, ReentrantLock> lockMap = new ConcurrentHashMap<>();
@Override
public Map wxAppletPay(WxAppletPayRequest reqDTO) throws Exception {
// 订单标题
String orderTitle = reqDTO.getOrderTitle();
if (orderTitle == null || "".equals(orderTitle)) {
orderTitle = "门诊付款";
}
// 添加上名称
orderTitle = hospital_name + "-" + orderTitle;
String openid = reqDTO.getOpenid();
String tradeNo = reqDTO.getTradeNo();
// String total_fee = reqDTO.getTotal_fee();
// 取应收金额,需要扣除预交金
String total_fee = reqDTO.getYsje();
WxPay wxPay = new WxPay();
wxPay.setAppid(StatusDefine.wxAppId);
wxPay.setSecret(StatusDefine.wxSecret);
wxPay.setMchid(StatusDefine.wxMchid);
wxPay.setWechartkey(StatusDefine.wxWechartkey);
wxPay.setPath(StatusDefine.wxCertPath); // 小程序证书文件路径
wxPay.setDomain("http://" + HttpUtil.getServerName()); // 接口域名
PassbackParams passbackParams = new PassbackParams();
// passbackParams.setTradeNo(tradeNo).setAppId(wxPay.getAppid()).setOpenId(openid);
passbackParams.setYsje(reqDTO.getYsje()).setZje(total_fee).setZfje(reqDTO.getZfje()).setSjh(reqDTO.getSjh()).setPatid(reqDTO.getPatid());
String attach = JsonUtils.beanToJson(passbackParams); // 可放回调接收的JSON参数
// 拼装参数
String nonceStr = WxPayDUtil.generateNonceStr();
Map<String, String> map = new HashMap<>();
map.put("appid", wxPay.getAppid());
map.put("mch_id", wxPay.getMchid());
map.put("nonce_str", nonceStr);
map.put("body", orderTitle);
map.put("openid", openid);
map.put("attach", attach);
map.put("out_trade_no", tradeNo);
// 将元转为分 微信接收分为单位的金额
int totalFeeInt = new BigDecimal(total_fee).multiply(BigDecimal.valueOf(100)).intValue();
String totalFeeStr = String.valueOf(totalFeeInt);
map.put("total_fee", totalFeeStr);
// 获取ip地址没有就用转发这个。
String spbill_create_ip = "";
String ip = reqDTO.getIp();
if (ip != null && !"".equals(ip)) {
spbill_create_ip = ip;
} else {
spbill_create_ip = IPUtil.getIp();
}
map.put("spbill_create_ip", spbill_create_ip); // 买家客户端IP
map.put("trade_type", "JSAPI");
map.put("notify_url", notifyUrl); // 支付结果回调地址
// 签名
map.put("sign", WxPayDUtil.generateSignature(map, wxPay.getWechartkey()));
logger.info("小程序统一下单参数" + JsonUtils.beanToJson(map) + ", " + JsonUtils.beanToJson(wxPay));
// 配置
WXPay pay = new WXPay(new MyConfig(wxPay));
Map tmap = pay.unifiedOrder(map);
logger.info("小程序统一下单结果" + JsonUtils.beanToJson(tmap));
String returnCode = tmap.get("return_code").toString();
String resultCode = tmap.get("result_code").toString();
// 发起支付成功
if ("SUCCESS".equals(returnCode) && "SUCCESS".equals(resultCode)) {
String prepayId = tmap.get("prepay_id").toString();
Map<String, String> resultMap = new HashMap<>();
resultMap.put("appId", wxPay.getAppid());
resultMap.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
resultMap.put("nonceStr", nonceStr);
resultMap.put("package", "prepay_id=" + prepayId);
resultMap.put("signType", "MD5");
String sign = WxPayDUtil.generateSignature(resultMap, wxPay.getWechartkey());
resultMap.put("paySign", sign);
// 保存参数
String jsonString1 = JSON.toJSONString(resultMap);
HashMap hashMap = JSON.parseObject(jsonString1, HashMap.class);
hashMap.put("patid", reqDTO.getPatid());
hashMap.put("hosp_out_trade_no", tradeNo);
String url2 = StatusDefine.IP_PORT + "/api/updateOrderInfoPay";
HttpHeaders headers2 = new HttpHeaders();
headers2.setContentType(MediaType.APPLICATION_JSON);
String body2 = JSON.toJSONString(hashMap);
HttpEntity<String> entity = new HttpEntity<String>(body2, headers2);
ResponseEntity<HashMap> resp = restTemplate.exchange(url2, HttpMethod.POST, entity, HashMap.class);
HashMap respMap = resp.getBody();
// 如果保存 返回错误信息
String errCode = StringDUtil.changeNullToEmpty(respMap.get("errCode"));
if (!"0".equals(errCode)) {
throw new CustomException("统一下单信息保存失败");
} else {
return resultMap;
}
}
return null;
}
@Override
public void wxPayNofify(WxResult wxResult) {
String id = wxResult.getTransaction_id();
ReentrantLock o = null;
do {
// 开始执行先unlock
if (o != null) {
o.unlock();
}
o = lockMap.computeIfAbsent(id, k -> new ReentrantLock());
// 加锁
o.lock();
// 新创建的被上一个线程remove掉了或者新创建的对象和lockMap中已有的不是同一个对象重试
} while (lockMap.get(id) == null || o != lockMap.get(id));
try {
PassbackParams callBackParam = JSONObject.parseObject(URLDecoder.decode(wxResult.getAttach(), "UTF-8"), PassbackParams.class);
if ("SUCCESS".equals(wxResult.getResult_code()) && "SUCCESS".equals(wxResult.getReturn_code())) {
// 更新订单状态为已完成 返回没用。。。已经异步了
HashMap<Object, Object> updateOrderInfoMap = new HashMap<>();
String updateUrl = StatusDefine.IP_PORT + "/api/updateOrderInfoComplete";
updateOrderInfoMap.put("hosp_out_trade_no", wxResult.getOut_trade_no());
HashMap<Object, Object> updateResultMap = houtaiService.PostInfoByParam(updateUrl, updateOrderInfoMap);
// 判断是否已经有这个消息了
String findUrl = StatusDefine.IP_PORT + "/api/findWxPayInfo";
HashMap<Object, Object> searchMap = new HashMap<>();
searchMap.put("transaction_id", wxResult.getTransaction_id());
HashMap<Object, Object> map = houtaiService.PostInfoByParam(findUrl, searchMap);
String errCode = StringDUtil.changeNullToEmpty(map.get("errCode"));
// 如果有 直接跳过 如果没有先发送信息进行结算 如果失败 将状态设置为0
boolean sendMsg = true;
if ("0".equals(errCode)) {
HashMap<Object, Object> map1 = (HashMap<Object, Object>) map.get("data");
if (map1 != null) {
String mzjsStatus = StringDUtil.changeNullToEmpty(map1.get("mzjsStatus"));
if ("1".equals(mzjsStatus)) {
LogUtil.info(this.getClass(), "回调后写入到his失败本地数据库内发现已有记录");
sendMsg = false;
}
}
}
if (sendMsg) {
// 查询后台错误 不知道有没有发过 先发了再说
SettlementDTO reqDTO = new SettlementDTO();
reqDTO.setPatid(callBackParam.getPatid());
reqDTO.setSjh(callBackParam.getSjh());
// reqDTO.setZje(callBackParam.getZje());
reqDTO.setZje(callBackParam.getZfje());
reqDTO.setYsje(callBackParam.getYsje());
// reqDTO.setPaymoney(callBackParam.getZfje());
reqDTO.setPaymoney(callBackParam.getYsje());
reqDTO.setPaytype("9");
reqDTO.setPaylsh(wxResult.getTransaction_id());
reqDTO.setZfjsbz("1");
HashMap<Object, Object> settlementResultMap = OtherWSUtil.Settlement(reqDTO);
String errCode1 = StringDUtil.changeNullToEmpty(settlementResultMap.get("errCode"));
if ("0".equals(errCode1)) {
wxResult.setMzjsStatus("1");
} else {
wxResult.setMzjsStatus("0");
LogUtil.error(this.getClass(), StringDUtil.changeNullToEmpty(settlementResultMap.get("errMsg")));
}
// 成功存储信息
String url = StatusDefine.IP_PORT + "/api/addWxPayInfo";
houtaiService.PostInfoByParam(url, wxResult);
}
} else {
// 没成功 ,输出日志
String jsonString = JSONObject.toJSONString(wxResult);
LogUtil.error(this.getClass(), "支付回调支付异常,内容:" + jsonString);
// 调用处方解锁
LogUtil.info(this.getClass(), "开始调用处方解锁接口(支付回调显示支付异常)");
//
CancelPreSettlementDTO reqDTO = new CancelPreSettlementDTO();
reqDTO.setJssjh(callBackParam.getSjh());
reqDTO.setZfjsbz("1");
OtherWSUtil.CancelPreSettlement(reqDTO);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public Map findWxPayResult(PayQuery reqDTO) throws Exception {
WxPay wxPay = new WxPay();
wxPay.setAppid(StatusDefine.wxAppId);
wxPay.setSecret(StatusDefine.wxSecret);
wxPay.setMchid(StatusDefine.wxMchid);
wxPay.setWechartkey(StatusDefine.wxWechartkey);
HashMap<String, String> map = new HashMap<>();
map.put("appid", StatusDefine.wxAppId);
map.put("mch_id", StatusDefine.wxMchid);
map.put("out_trade_no", reqDTO.getOut_trade_no());
String nonceStr = WxPayDUtil.generateNonceStr();
map.put("nonce_str", nonceStr);
String sign = WxPayDUtil.generateSignature(map, wxPay.getWechartkey());
map.put("sign", sign);
WXPay pay = new WXPay(new MyConfig(wxPay));
Map<String, String> tmap = pay.orderQuery(map);
logger.info("查询账单结果" + JsonUtils.beanToJson(tmap));
String returnCode = tmap.get("return_code");
String resultCode = tmap.get("result_code");
if ("SUCCESS".equals(returnCode) && "SUCCESS".equals(resultCode)) {
String tradeStateDesc = tmap.get("trade_state_desc");
String tradeState = tmap.get("trade_state");
String timeEnd = tmap.get("time_end");
String outTradeNo = tmap.get("out_trade_no");
String totalFee = tmap.get("total_fee");
String timeEndStr = "";
if (timeEnd != null) {
Date date = DateDUtil.strToDate(DateDUtil.yyyyMMddHHmmss, timeEnd);
timeEndStr = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd_HH_mm_ss, date);
}
Map resultMap = new HashMap();
// 单号
resultMap.put("outTradeNo", outTradeNo);
// 付款时间
resultMap.put("timeEnd", timeEndStr);
// 状态
resultMap.put("tradeState", tradeState);
resultMap.put("tradeStateDesc", tradeStateDesc);
// 写死医院和项目
resultMap.put("hospitalName", "库尔勒市妇幼保健院");
resultMap.put("body", "门诊缴费");
// 总金额
totalFee = new BigDecimal(totalFee).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString();
resultMap.put("totalFee", totalFee);
// 更新订单状态为已完成
if ("SUCCESS".equals(tradeState)) {
HashMap<Object, Object> updateOrderInfoMap = new HashMap<>();
String updateUrl = StatusDefine.IP_PORT + "/api/updateOrderInfoComplete";
updateOrderInfoMap.put("hosp_out_trade_no", outTradeNo);
HashMap<Object, Object> updateResultMap = houtaiService.PostInfoByParam(updateUrl, updateOrderInfoMap);
}
return resultMap;
} else {
String errCodeDes = tmap.get("err_code_des");
throw new RuntimeException(errCodeDes);
}
}
@Override
public Map ybAppletPay(WxybAppletReuqest reqDTO) {
String errMsg = "";
try {
// 先将参数值复制过来
WxybPay wxybPay = JSON.parseObject(JSON.toJSONString(reqDTO), WxybPay.class);
// 对金额进行处理 传过来的是元 转为分
String totalFee = wxybPay.getTotal_fee();
String cashFee = wxybPay.getCash_fee();
String zhzf = reqDTO.getZhzf();
String ybzf = reqDTO.getYbzf();
String yjjzf = reqDTO.getYjjzf();
long totalFeeL = new BigDecimal(totalFee).multiply(new BigDecimal(100)).longValue();
wxybPay.setTotal_fee(String.valueOf(totalFeeL));
long cashFeeL = new BigDecimal(cashFee).multiply(new BigDecimal(100)).longValue();
wxybPay.setCash_fee(String.valueOf(cashFeeL));
long insuranceFeeL = new BigDecimal(ybzf).add(new BigDecimal(zhzf)).multiply(new BigDecimal(100)).longValue();
wxybPay.setInsurance_fee(String.valueOf(insuranceFeeL));
long reducefee = new BigDecimal(yjjzf).multiply(new BigDecimal(100)).longValue();
wxybPay.setCash_reduced_fee(String.valueOf(reducefee));
wxybPay.setCash_reduced_wording("1");
// 将数据补全
wxybPay.setOrder_type("DiagPay"); // 固定为诊间支付
wxybPay.setAppid(StatusDefine.wxAppId);
wxybPay.setMch_id(StatusDefine.wxMchid);
wxybPay.setHospital_name(hospital_name);
// 身份证验证 如果15位转18位 并且用md5加密
String userCardNo = wxybPay.getUser_card_no();
if (userCardNo.length() == 15) {
userCardNo = Ic.get18Ic(userCardNo);
}
userCardNo = DigestUtils.md5DigestAsHex(userCardNo.toUpperCase().getBytes());
wxybPay.setUser_card_no(userCardNo);
// 随机字符串
String nonceStr = WxPayDUtil.generateNonceStr();
wxybPay.setNonce_str(nonceStr);
// 是否允许预结算费用发生变化 0 不允许
wxybPay.setAllow_fee_change("0");
// 获取ip地址没有就用转发这个。
String spbill_create_ip = "";
String ip = reqDTO.getIp();
if (ip != null && !"".equals(ip)) {
spbill_create_ip = ip;
} else {
spbill_create_ip = IPUtil.getIp();
}
wxybPay.setSpbill_create_ip(spbill_create_ip);
// 回调地址
wxybPay.setNotify_url(ybNotifyUrl);
wxybPay.setBody("门诊缴费");
wxybPay.setUser_card_type("1");
wxybPay.setIs_dept("4");
// 城市id 传固定的id 因为医保开通是地区
wxybPay.setCity_id(StatusDefine.cityId);
String orgCodg = environment.getProperty("orgCodg");
wxybPay.setOrg_no(orgCodg);// 医疗机构编码(医保局分配给机构)
YbPassbackParams passbackParams = new YbPassbackParams();
// 此处应收金额单位还是元未被改为分
passbackParams.setYsje(reqDTO.getYsje()).setPatid(reqDTO.getPatid()).setPayToken(reqDTO.getPayToken()).setPayOrdId(reqDTO.getPayOrdId());
String attach = JsonUtils.beanToJson(passbackParams);
wxybPay.setAttach(attach);
// 添加渠道号
wxybPay.setChannel_no(StatusDefine.channel);
HashMap<String, String> hashMap = JSON.parseObject(JSON.toJSONString(wxybPay), HashMap.class);
hashMap.remove("sign");
String sign = WxPayDUtil.generateSignature(hashMap, StatusDefine.wxybkey);
hashMap.put("sign", sign);
logger.info("小程序医保统一下单参数" + JsonUtils.beanToJson(hashMap));
// 调用统一下单接口
String tyxdUrl = "https://api.weixin.qq.com/payinsurance/unifiedorder?access_token=" + RetrieveAccessToken.getToken();
String xmlStr = WXPayUtil.mapToXml(hashMap);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_ATOM_XML);
List<HttpMessageConverter<?>> httpMessageConverters = restTemplate.getMessageConverters();
httpMessageConverters.forEach(httpMessageConverter -> {
if (httpMessageConverter instanceof StringHttpMessageConverter) {
StringHttpMessageConverter messageConverter = (StringHttpMessageConverter) httpMessageConverter;
// 设置编码为UTF-8
messageConverter.setDefaultCharset(StandardCharsets.UTF_8);
}
});
HttpEntity<String> entity = new HttpEntity<String>(xmlStr, headers);
ResponseEntity<String> resultXml = restTemplate.postForEntity(tyxdUrl, entity, String.class);
int statusCodeValue = resultXml.getStatusCodeValue();
if (statusCodeValue == 200) {
// 这里这个是微信支付的jar包里的类。里面地址有点不一样 这里就当转xml用的
WxPay wxPay = new WxPay();
wxPay.setAppid(StatusDefine.wxAppId);
wxPay.setSecret(StatusDefine.wxSecret);
wxPay.setMchid(StatusDefine.wxMchid);
wxPay.setWechartkey(StatusDefine.wxybkey);
WXPay wxPay2 = new WXPay(new MyConfig(wxPay));
Map<String, String> stringMap = wxPay2.processResponseXml(resultXml.getBody());
logger.info("小程序医保统一下单结果" + JsonUtils.beanToJson(stringMap));
String returnCode = stringMap.get("return_code");
String resultCode = stringMap.get("result_code");
if ("SUCCESS".equals(returnCode) && "SUCCESS".equals(resultCode)) {
String payAppid = stringMap.get("pay_appid");
String payUrl = stringMap.get("pay_url");
String medTransId = stringMap.get("med_trans_id");
Map<String, String> resultMap = new HashMap<>();
resultMap.put("pay_appid", payAppid);
resultMap.put("pay_url", payUrl);
resultMap.put("med_trans_id", medTransId);
// 保存参数
String jsonString1 = JSON.toJSONString(resultMap);
HashMap hashMap1 = JSON.parseObject(jsonString1, HashMap.class);
hashMap1.put("patid", reqDTO.getPatid());
hashMap1.put("hosp_out_trade_no", reqDTO.getHosp_out_trade_no());
String url2 = StatusDefine.IP_PORT + "/api/updateYBOrderInfoPay";
HttpHeaders headers2 = new HttpHeaders();
headers2.setContentType(MediaType.APPLICATION_JSON);
String body2 = JSON.toJSONString(hashMap1);
HttpEntity<String> entity2 = new HttpEntity<String>(body2, headers2);
ResponseEntity<HashMap> resp = restTemplate.exchange(url2, HttpMethod.POST, entity2, HashMap.class);
HashMap respMap = resp.getBody();
// 如果保存 返回错误信息
String errCode = StringDUtil.changeNullToEmpty(respMap.get("errCode"));
if (!"0".equals(errCode)) {
throw new CustomException("统一下单信息保存失败");
} else {
return resultMap;
}
} else {
errMsg = "小程序医保统一下单结果失败:" + stringMap;
logger.error("小程序医保统一下单结果失败:" + stringMap);
}
} else {
errMsg = "调用医保统一下单接口失败,网络错误编码:" + statusCodeValue;
logger.error("调用医保统一下单接口失败,网络错误编码:" + statusCodeValue);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("发起微信医保支付失败,原因" + e.getMessage());
errMsg = "发起微信医保支付失败,原因" + e.getMessage();
}
throw new RuntimeException(errMsg);
}
@Override
public void wxybPayNofify(WxybResult wxybResult) {
String id = wxybResult.getSerial_no();
ReentrantLock o = null;
do {
// 开始执行先unlock
if (o != null) {
o.unlock();
}
o = lockMap.computeIfAbsent(id, k -> new ReentrantLock());
// 加锁
o.lock();
// 新创建的被上一个线程remove掉了或者新创建的对象和lockMap中已有的不是同一个对象重试
} while (lockMap.get(id) == null || o != lockMap.get(id));
try {
YbPassbackParams callBackParam = JSONObject.parseObject(URLDecoder.decode(wxybResult.getAttach(), "UTF-8"), YbPassbackParams.class);
if ("SUCCESS".equals(wxybResult.getResult_code()) && "SUCCESS".equals(wxybResult.getReturn_code())) {
// 更新订单状态为已完成
HashMap<Object, Object> updateOrderInfoMap = new HashMap<>();
String updateUrl = StatusDefine.IP_PORT + "/api/updateOrderInfoComplete";
updateOrderInfoMap.put("hosp_out_trade_no", wxybResult.getHosp_out_trade_no());
HashMap<Object, Object> updateResultMap = houtaiService.PostInfoByParam(updateUrl, updateOrderInfoMap);
// 说是成功就不用干任何事了。 不知道是不是 这里先注释掉
// //判断是否已经有这个消息了
// String findUrl=StatusDefine.IP_PORT+"/api/findWxybPayInfo";
// HashMap<Object,Object> searchMap=new HashMap<>();
// searchMap.put("cash_order_id",wxybResult.getCash_order_id());
// HashMap<Object, Object> map = houtaiService.PostInfoByParam(findUrl, searchMap);
// String errCode = StringDUtil.changeNullToEmpty(map.get("errCode"));
//
// //如果有 直接跳过 如果没有先发送信息进行结算 如果失败 将状态设置为0
// boolean sendMsg=true;
// if ("0".equals(errCode)) {
// HashMap<Object, Object> map1 = (HashMap<Object, Object>) map.get("data");
// if (map1 != null) {
// String mzjsStatus = StringDUtil.changeNullToEmpty(map1.get("mzjsStatus"));
// if ("1".equals(mzjsStatus)){
// LogUtil.info(this.getClass(), "回调后写入到his失败本地数据库内发现已有记录");
// sendMsg=false;
// }
// }
// }
// if (sendMsg){
// //查询后台错误 不知道有没有发过 先发了再说
// SettlementDTO reqDTO = new SettlementDTO();
// reqDTO.setPatid(callBackParam.getPatid());
// reqDTO.setSjh(wxybResult.getSerial_no());
// reqDTO.setYsje(callBackParam.getYsje());
//
// //从微信返回的金额为分要改为元来传输给his
// Integer totalFee = wxybResult.getTotal_fee();
// Integer cashFee = wxybResult.getCash_fee();
// BigDecimal totalFeeBD = new BigDecimal(totalFee).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
// BigDecimal cashFeeBD = new BigDecimal(cashFee).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
//
// reqDTO.setZje(totalFeeBD.toString());
// reqDTO.setPaymoney(cashFeeBD.toString());
// reqDTO.setPaytype("9");
// reqDTO.setPaylsh(wxybResult.getCash_order_id());
// reqDTO.setZfjsbz("0");
// HashMap<Object, Object> settlementResultMap = OtherWSUtil.Settlement(reqDTO);
//
// String errCode1 = StringDUtil.changeNullToEmpty(settlementResultMap.get("errCode"));
//
// if ("0".equals(errCode1)) {
// wxybResult.setMzjsStatus("1");
// } else {
// wxybResult.setMzjsStatus("0");
// LogUtil.error(this.getClass(), StringDUtil.changeNullToEmpty(settlementResultMap.get("errMsg")));
// }
//
// //存储信息
// String url = StatusDefine.IP_PORT + "/api/addWxybPayInfo";
// houtaiService.PostInfoByParam(url, wxybResult);
// }
} else {
// 没成功 ,输出日志
String jsonString = JSONObject.toJSONString(wxybResult);
LogUtil.error(this.getClass(), "医保支付回调支付异常,内容:" + jsonString);
// 调用处方解锁
LogUtil.info(this.getClass(), "开始调用处方解锁接口(医保支付回调显示支付异常)");
//
CancelPreSettlementDTO reqDTO = new CancelPreSettlementDTO();
reqDTO.setJssjh(wxybResult.getSerial_no());
reqDTO.setZfjsbz("0");
reqDTO.setPayToken(callBackParam.getPayToken());
reqDTO.setPayOrdId(callBackParam.getPayOrdId());
OtherWSUtil.CancelPreSettlement(reqDTO);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
// 释放锁
lockMap.remove(id);
}
}
@Override
public Map findWxybPayResult(PayQuery reqDTO) throws Exception {
WxPay wxPay = new WxPay();
wxPay.setAppid(StatusDefine.wxAppId);
wxPay.setSecret(StatusDefine.wxSecret);
wxPay.setMchid(StatusDefine.wxMchid);
wxPay.setWechartkey(StatusDefine.wxybkey);
WXPay pay = new WXPay(new MyConfig(wxPay));
HashMap<String, String> map = new HashMap<>();
map.put("appid", StatusDefine.wxAppId);
map.put("mch_id", StatusDefine.wxMchid);
map.put("hosp_out_trade_no", reqDTO.getOut_trade_no());
String nonceStr = WxPayDUtil.generateNonceStr();
map.put("nonce_str", nonceStr);
String sign = WxPayDUtil.generateSignature(map, wxPay.getWechartkey());
map.put("sign", sign);
String url = "https://api.weixin.qq.com/payinsurance/queryorder?access_token=" + RetrieveAccessToken.getToken();
String xmlStr = WXPayUtil.mapToXml(map);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_ATOM_XML);
List<HttpMessageConverter<?>> httpMessageConverters = restTemplate.getMessageConverters();
httpMessageConverters.forEach(httpMessageConverter -> {
if (httpMessageConverter instanceof StringHttpMessageConverter) {
StringHttpMessageConverter messageConverter = (StringHttpMessageConverter) httpMessageConverter;
// 设置编码为UTF-8
messageConverter.setDefaultCharset(StandardCharsets.UTF_8);
}
});
HttpEntity<String> entity = new HttpEntity<String>(xmlStr, headers);
ResponseEntity<String> resultXml = restTemplate.postForEntity(url, entity, String.class);
int statusCodeValue = resultXml.getStatusCodeValue();
if (statusCodeValue == 200) {
Map<String, String> stringMap = pay.processResponseXml(resultXml.getBody());
logger.info("小程序医保订单查询结果" + JsonUtils.beanToJson(stringMap));
String returnCode = stringMap.get("return_code");
String resultCode = stringMap.get("result_code");
if ("SUCCESS".equals(returnCode) && "SUCCESS".equals(resultCode)) {
String medTradeState = stringMap.get("med_trade_state");
String cashTradeStatus = stringMap.get("cash_trade_status");
String insuranceTradeStatus = stringMap.get("insurance_trade_status");
String hospitalName = stringMap.get("hospital_name");
String body = stringMap.get("body");
String totalFee = stringMap.get("total_fee");
String gmtOutCreate = stringMap.get("gmt_out_create");
String hospOutTradeNo = stringMap.get("hosp_out_trade_no");
Date date = DateDUtil.strToDate(DateDUtil.yyyyMMddHHmmss, gmtOutCreate);
String gmtOutCreateStr = DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd_HH_mm_ss, date);
Map resultMap = new HashMap();
resultMap.put("cashTradeStatus", cashTradeStatus);
resultMap.put("insuranceTradeStatus", insuranceTradeStatus);
// 机构名称
resultMap.put("hospitalName", hospitalName);
// 项目
resultMap.put("body", body);
// 总金额
totalFee = new BigDecimal(totalFee).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString();
resultMap.put("totalFee", totalFee);
// 支付状态
resultMap.put("medTradeState", medTradeState);
resultMap.put("medTradeStateName", MedTradeStateEnum.getNameByValue(medTradeState));
// 订单号
resultMap.put("hospOutTradeNo", hospOutTradeNo);
// 创建时间
resultMap.put("gmtOutCreate", gmtOutCreateStr);
// 更新订单状态为已完成
if ("SUCCESS".equals(medTradeState)) {
HashMap<Object, Object> updateOrderInfoMap = new HashMap<>();
String updateUrl = StatusDefine.IP_PORT + "/api/updateOrderInfoComplete";
updateOrderInfoMap.put("hosp_out_trade_no", hospOutTradeNo);
HashMap<Object, Object> updateResultMap = houtaiService.PostInfoByParam(updateUrl, updateOrderInfoMap);
}
return resultMap;
} else {
String errCodeDes = stringMap.get("err_code_des");
throw new RuntimeException(errCodeDes);
}
}
return null;
}
// public static void main(String[] args) {
// String s = "{\"bz\":\"\",\"patid\":\"421322\",\"sjh\":\"20240418yypt120005\",\"ybzf\":\"\",\"yhje\":\"0.0000\",\"ysje\":\"5.0000\",\"zfje\":\"5.0000\",\"zhye\":\"\",\"zhzf\":\"\",\"zje\":\"5.0000\"}";
// JSONObject jsonObject = JSONObject.parseObject(s);
// System.out.println(jsonObject);
// System.out.println(jsonObject.get("zje"));
//
//
// }
}

View File

@@ -0,0 +1,13 @@
package com.saye.hrs.service.impl;
import com.saye.hrs.service.ServiceParamService;
import org.springframework.stereotype.Service;
/**
* @description: 系统参数获取接口
* @author: Mr.zs
* @create: 2024-04-16 16:23
**/
@Service
public class ServiceParamServiceImpl implements ServiceParamService {
}