微信后端代码
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.

395 lines
16 KiB

package com.ynxbd.common.action;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.enums.MerchantEnum;
import com.ynxbd.common.bean.pay.PayCasebook;
import com.ynxbd.common.bean.xbd.MRHistory;
import com.ynxbd.common.bean.xbd.MedicalRecord;
import com.ynxbd.common.config.interceptor.AesDecode;
import com.ynxbd.common.helper.common.Base64Helper;
import com.ynxbd.common.helper.common.JsonHelper;
import com.ynxbd.common.helper.xbd.XBDEnum;
import com.ynxbd.common.helper.xbd.XBDHelper;
import com.ynxbd.common.helper.xbd.XBDHttpHelper;
import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.result.ServiceException;
import com.ynxbd.common.service.CasebookService;
import com.ynxbd.common.service.PEISService;
import com.ynxbd.common.service.XBDService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import java.math.BigDecimal;
import java.util.List;
/**
* @author 李进才
* @ClassName XBDAction
* @Description description
* @date 2023/3/30 16:50
*/
@Slf4j
@Namespace("/xbd")
public class XBDAction extends BaseAction {
@Action("test03")
public Result test03(String a) throws ServiceException {
System.out.println("测试");
return Result.success();
}
/**
* 获取智能云胶片的地址
*
* @param info patientId
* @return 路径
*/
@Action("cloudFilm")
public Result cloudFilm(String info) {
try {
log.info("[云胶片]info={}", info);
String path = XBDHelper.outTeamDao.getCloudFilmPath(info);
return Result.success(path);
} catch (Exception e) {
log.error("[云胶片]{}", e.getMessage());
return Result.error("请求异常");
}
}
/**
* 获取云胶片的授权地址
*
* @param patientId 患者id
*/
@Action("pacsAuth")
public Result pacsAuth(Integer version, @AesDecode String patientId, @AesDecode String treatNum, String treatType) {
try {
String url = new XBDService().getPacsAuthUrl(version, patientId, treatNum, treatType);
return Result.success(url);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* 获取该病人已归档可以翻拍的病历[红河]
*
* @param patientId 病人id
* @return 可以翻拍的病历列表
*/
@Action("getMedicalRecordList")
public Result getMedicalRecordList(@AesDecode String patientId, Integer flagSh) {
try {
log.info("[病历]获取该病人已归档可以翻拍的病历 patientId={}", patientId);
if (patientId == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String resp = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_GetBA.NAME, params -> {
params.put("patientID", patientId);
params.put("flagFP", 0);
params.put("flagSH", flagSh);
});
if (ObjectUtils.isEmpty(resp)) {
return Result.error(ResultEnum.INTERFACE_INVOKE_ERROR);
}
return Result.success(JsonHelper.parseArray(resp, MedicalRecord.class));
} catch (Exception e) {
return Result.error(e);
}
}
/**
* [病历复印]获取该病人需要翻拍病历干啥的列表(用途)->直接绑定翻拍的病历类型
*
* @return 用途列表
*/
@Action("getMRTemplateList")
public Result getMRTemplateList() {
try {
String respJson = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_GetTemplate.NAME, null);
return Result.success(JsonHelper.parseArray(respJson));
} catch (Exception e) {
return Result.error(e);
}
}
/**
* [病历复印]新增预约信息
*
* @param openId openId
* @param patientId patientId
* @param zyNum 住院号
* @param applyName 申请人姓名
* @param useToNo 模版ID
* @param useToName 模版名称
* @param getWay 获取方式:1自提 2邮寄 3电子版
* @param address 地址
* @param phone 联系电话
* @param ptImg1 身份证正面
* @param ptImg2 身份证反面
* @param ptImg3 手持身份证
* @param relationship 申请人与病人关系
* @param applyPtImg1 申请人身份证正面照片
* @param applyPtImg2 申请人身份证反面照片
* @param applicationImg 申请书图片
* @return 成功行数
*/
@Action("addMRReserve")
public Result addMRReserve(String openId, @AesDecode String patientId, String zyNum, String applyName, String relationship, String useToNo, String useToName, int getWay, String address, String phone, String ptImg1, String ptImg2, String ptImg3, String ptImg4, String ptImg5, String ptImg6, String applyPtImg1, String applyPtImg2, String applicationImg) {
try {
log.info("[病历复印]新增预约信息 patientId={}, treatNum={}, applyName={}, useToNo={}, useToName={}, getWay={}, address={}, phone={}", patientId, zyNum, applyName, useToNo, useToName, getWay, address, phone);
if (ObjectUtils.isEmpty(openId) || ObjectUtils.isEmpty(patientId)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
CasebookService service = new CasebookService();
List<PayCasebook> dbDataList = service.queryListByTreat(patientId, zyNum);
if (dbDataList.size() > 5) {
log.info("[病历复印]今日预约申请次数超过限制 patientId={}, treatNum={}, getWay={}, useToNo={}, useToName={}", patientId, zyNum, getWay, useToNo, useToName);
throw new ServiceException("[病历复印]每日可预约申请最多5次,请明日再试!");
}
String respJson = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_SetAppointment.NAME, params -> {
params.put("ZYNum", zyNum);
params.put("ApplyName", applyName);
params.put("UseToNo", useToNo);
params.put("UseToName", useToName);
params.put("GetWay", getWay);
params.put("Address", address);
params.put("Relationship", relationship);
params.put("Phone", phone);
params.put("ptImg1", ptImg1);
params.put("ptImg2", ptImg2);
params.put("ptImg3", ptImg3);
params.put("ptImg4", ptImg4);
if (ptImg5 != null) {
params.put("ptImg5", ptImg5);
}
if (ptImg6 != null) {
params.put("ptImg6", ptImg6);
}
params.put("applyPtImg1", applyPtImg1);
params.put("applyPtImg2", applyPtImg2);
params.put("ApplicationImg", applicationImg);
});
log.info("[病历复印]HIS预约申请返回 resp={}", respJson);
if (ObjectUtils.isEmpty(respJson)) {
return Result.error(ResultEnum.INTERFACE_HIS_INVOKE_ERROR);
}
JSONObject respJsonObj = JsonHelper.parseJsonObjByBracket(respJson);
if (respJsonObj == null) {
return Result.error(ResultEnum.INTERFACE_HIS_DATA_ERROR);
}
String applyId = respJsonObj.getString("Ba_Borrow_No");
if (ObjectUtils.isEmpty(applyId)) {
return Result.error(ResultEnum.INTERFACE_HIS_DATA_ERROR);
}
PayCasebook addInfo = new PayCasebook();
addInfo.setTreatNum(zyNum);
addInfo.setPatientName(applyName);
addInfo.setUseToNo(useToNo);
addInfo.setUseToName(useToName);
addInfo.setGetWay(getWay);
addInfo.setAddress(address);
addInfo.setPhone(phone);
addInfo.setApplyId(applyId);
addInfo.setPayStatus(-2); // 预约标识
if (!service.addResApply(addInfo, openId, patientId)) {
log.info("[病历复印]预约申请信息存储失败 patientId={}, openId={}, applyId={}", patientId, openId, applyId);
return Result.error(ResultEnum.SPECIFIED_QUESTIONED_USER_NOT_EXIST);
}
return Result.success(respJsonObj);
} catch (Exception e) {
log.error("[病历复印]HIS预约申请失败 error:{}", e.toString());
return Result.error(e);
}
}
/**
* [查询]患者的病历翻拍历史
*
* @param patientId 病人Id
* @return 历史记录
*/
@Action("getMRHistory")
public Result getMRHistory(@AesDecode String patientId) {
try {
log.info("[查询]患者的病历翻拍历史 patientId={}", patientId);
String jsonString = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_GetHistoryAppointment.NAME, params -> {
params.put("patientID", patientId);
params.put("BorrowNo", -1);
});
return Result.success(JsonHelper.parseArray(jsonString, MRHistory.class));
} catch (Exception e) {
return Result.error(e);
}
}
/**
* 病历复印唤起支付
*
* @param payCode wx微信
* @param openid 患者openId
* @param patientId 患者patientId
* @param treatNum 住院号
* @param totalFee 总费用
* @param applyId 申请单Id
* @return 支付回调参数
*/
@Action("caseBookPay")
public Result caseBookPay(String payCode, String openid, @AesDecode String patientId, String patientName, String treatNum, BigDecimal totalFee, String applyId, Integer getWay, String useToNo, String useToName, String address, String phone) {
try {
log.info("[病历复印]下单 payCode={}, openid={}, patientId={}, patientName={}, treatNum={}, totalFee={}, useToName={}", payCode, openid, patientId, patientName, treatNum, totalFee, useToName);
MerchantEnum merchantEnum = MerchantEnum.findEnumByCode(payCode);
if (merchantEnum == null) { // 支付方式异常
return Result.error(ResultEnum.PAY_TYPE_ERROR);
}
String ip = request.getRemoteAddr();
return new CasebookService().placeOrder(merchantEnum, ip, openid, patientId, patientName, treatNum, totalFee, applyId, getWay, useToNo, useToName, address, phone);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* 生成token // 德宏体检看pacs报告
*/
@Action("getCloudToken")
public Result getCloudToken(String treatNum) {
log.info("[生成token] treatNum={}", treatNum);
if (ObjectUtils.isEmpty(treatNum)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String token = new XBDService().getCloudToken(treatNum);
return Result.success(token);
}
/**
* 生成token // 德宏体检看pacs报告
*/
@Action("getPeisByCardNo")
public Result getPeisByCardNo(@AesDecode String cardNo, String begDate, String endDate) {
log.info("[查询体检记录] cardNo={}, begDate={}, endDate={}", cardNo, begDate, endDate);
if (ObjectUtils.isEmpty(cardNo) || ObjectUtils.isEmpty(begDate) || ObjectUtils.isEmpty(endDate)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String encode = Base64Helper.encode(cardNo);
if (ObjectUtils.isEmpty(encode)) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
try {
JSONArray dataList = new PEISService().queryPEISRecordByCardNo(encode, begDate, endDate);
for (int i = 0; i < dataList.size(); i++) {
JSONObject dataItem = dataList.getJSONObject(i);
String eid = dataItem.getString("eid");
if (!ObjectUtils.isEmpty(eid)) {
dataItem.put("token", new XBDService().getCloudToken(eid));
}
dataItem.put("treatNum", eid);
}
return Result.success(dataList);
} catch (Exception e) {
return Result.error(e);
}
}
/**
* 图片测试
*
* @param patientId patientId
* @return 成功行数
*/
@Action("testImportImage")
public Result testImportImage(@AesDecode String patientId, String img1, String img2, String img3) {
try {
log.info("[图片测试]patientId={}, img1={}", patientId, img1);
if (ObjectUtils.isEmpty(patientId)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
String jsonString = XBDHttpHelper.ExecMethodPost(XBDEnum.Test_ImportImage.NAME, params -> {
params.put("Img1", img1);
params.put("Img2", img2);
params.put("ImageType", 1);
});
return Result.success(jsonString);
} catch (Exception e) {
log.error("[图片测试] error-{}", e.toString());
return Result.error(ResultEnum.ERROR);
}
}
// /**
// * 病人修改病历的地址
// * @param id 申请单号
// * @param getWay 收货方式(0.自提 1.邮寄 2.电子版)
// * @param address 地址
// * @return 是否修改成功
// */
// @Action("changeMRAddress")
// public Result changeMRAddress(Integer id,String getWay,String address) {
// String jsonString = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_ChangeAddress.Name,params-> {
// params.put("Id",id);
// params.put("getWay",getWay);
// params.put("address",address);
// });
// return Result.success(JsonHelper.parseObject(jsonString));
// }
//
// /**
// * 停止未通过审核的病历预约
// * @param id 申请单号
// * @param delNote 删除理由
// * @return 是否成功
// */
// @Action("stopMRReserve")
// public Result stopMRReserve(Integer id,String delNote){
// String jsonString = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_StopAppointment.Name,params-> {
// params.put("Id",id);
// params.put("delNote",delNote);
// });
// return Result.success(JsonHelper.parseObject(jsonString));
// }
// /**
// * 获取该病人已归档可以翻拍的病历[红河]
// *
// * @param patientId 病人id
// * @return 可以翻拍的病历列表
// */
// @Action("getMedicalRecordList2")
// public Result getMedicalRecordList2(String patientId, Integer flagSh) {
// String realPatientId = getDecodeString(patientId);
// log.info("[病历]获取该病人已归档可以翻拍的病历 patientId={}", realPatientId);
// if (ObjectUtils.isEmpty(realPatientId)) {
// return Result.error(ResultEnum.PARAM_IS_DEFECT);
// }
// String resp = XBDHttpHelper.ExecMethodPost(XBDEnum.BLSM_Appointment_GetBA.Name, params -> {
// params.put("patientID", realPatientId);
// params.put("flagFP", 0);
// params.put("flagSH", flagSh);
// });
// if (ObjectUtils.isEmpty(resp)) {
// return Result.error(ResultEnum.INTERFACE_INVOKE_ERROR);
// }
// return Result.success(JsonHelper.parseArray(resp, MedicalRecord.class));
// }
}