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

381 lines
16 KiB

package com.ynxbd.common.action;
import com.ynxbd.common.action.base.BaseAction;
import com.ynxbd.common.bean.HisRecipe;
import com.ynxbd.common.bean.NatRecord;
import com.ynxbd.common.bean.Patient;
import com.ynxbd.common.bean.enums.MerchantEnum;
import com.ynxbd.common.bean.pay.Recipe;
import com.ynxbd.common.dao.NatRecordDao;
import com.ynxbd.common.dao.PatientDao;
import com.ynxbd.common.dao.his.HisRecipeDao;
import com.ynxbd.common.dao.peis.PeisDao;
import com.ynxbd.common.helper.common.DateHelper;
import com.ynxbd.common.helper.his.HisEnum;
import com.ynxbd.common.helper.his.HisHelper;
import com.ynxbd.common.result.JsonResult;
import com.ynxbd.common.result.Result;
import com.ynxbd.common.result.ResultEnum;
import com.ynxbd.common.service.RecipeService;
import com.ynxbd.wx.config.WeChatConfig;
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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 处方
*
* @Author wsq
* @Date 2020/11/6 9:45
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
*/
@Slf4j
@Namespace("/recipe")
public class RecipeAction extends BaseAction {
/**
* 获取已缴费项目
*/
@Action("getPayedList")
public Result getPayedList(String patientId, String personNo, String begDate, String endDate) {
log.info("[处方]已缴费项目查询 patientId={}, begDate={}, endDate={}, personNo-{}", patientId, begDate, endDate, personNo);
patientId = getDecodeString(patientId);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
List<HisRecipe> recipeList = new HisRecipeDao().getPaidRecipeList(patientId, begDate, endDate, personNo);
return Result.success(recipeList);
}
/**
* 查询已缴费项目
*/
@Action("getRxPaidList")
public Result getRxPaidList(String patientId, String personNo, String begDate, String endDate) {
log.info("[处方]查询已缴费项目 patientId={}, begDate={}, endDate={}, personNo-{}", patientId, begDate, endDate, personNo);
patientId = getDecodeString(patientId);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
if (!ObjectUtils.isEmpty(personNo)) {
personNo = getDecodeString(personNo);
if (personNo == null) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
}
List<HisRecipe> hisRecipeList = new HisRecipeDao().getPaidRecipeList(patientId, begDate, endDate, personNo);
List<HisRecipe> dataList = new ArrayList<>();
HisRecipe treatItem;
List<HisRecipe> groupList;
for (HisRecipe item : hisRecipeList) {
String treatNum = item.getMzNum();
if (ObjectUtils.isEmpty(treatNum)) {
continue;
}
String execDate = item.getExecDate();
item.setTreatNum(treatNum);
HisRecipe findTreat = dataList.stream().filter(o -> o.getTreatNum().equals(treatNum)).findFirst().orElse(null);
if (findTreat == null) {
treatItem = new HisRecipe();
treatItem.setTreatNum(treatNum);
treatItem.setDate(execDate);
groupList = new ArrayList<>();
groupList.add(item);
treatItem.setGroupList(groupList);
dataList.add(treatItem);
} else {
if (findTreat.getGroupList() == null) {
findTreat.setGroupList(new ArrayList<>());
}
Boolean isGreaterThan = DateHelper.leftGreaterThanRight(execDate, findTreat.getDate(), null);
if (isGreaterThan != null && isGreaterThan) {
findTreat.setDate(execDate);
}
findTreat.getGroupList().add(item);
}
}
return Result.success(dataList);
}
/**
* 获取未缴费项目
*/
@Action("getRxUnPayList")
public Result getRxUnPayList(String patientId, String personNo, String begDate, String endDate) {
log.info("[处方]未缴费项目查询 patientId={}, personNo={}, begDate={}, endDate={}", patientId, personNo, begDate, endDate);
patientId = getDecodeString(patientId);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
if (!ObjectUtils.isEmpty(personNo)) {
personNo = getDecodeString(personNo);
if (personNo == null) {
return Result.error(ResultEnum.PARAM_IS_INVALID);
}
}
int days = DateHelper.intervalDays(begDate, endDate, true);
List<HisRecipe> hisRecipes = new HisRecipeDao().getUnPayRecipe(patientId, personNo, days);
List<HisRecipe> resultList = new ArrayList<>();
for (HisRecipe hisRecipe : hisRecipes) {
hisRecipe.setTreatNum(hisRecipe.getMzNum());
if (hisRecipe.getDate() != null && DateHelper.inDateRange(begDate, endDate, hisRecipe.getDate(), DateHelper.DateEnum.yyyy_MM_dd)
&& !"1".equals(hisRecipe.getSTDFlag()) && (!"1".equals(hisRecipe.getInternetHospFlag()) || "1".equals(hisRecipe.getYJSAuditFlag()))) {
resultList.add(hisRecipe);
}
}
return Result.success(resultList);
}
/**
* 获取未缴费项目(旧)
*/
@Action("getUnPayList")
public Result getUnPayList(String patientId, String personNo, String begDate, String endDate) {
log.info("[处方]未缴费项目查询 patientId={}, personNo={}, begDate={}, endDate={}", patientId, personNo, begDate, endDate);
patientId = getDecodeString(patientId);
if (patientId == null || begDate == null || endDate == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
int days = DateHelper.intervalDays(begDate, endDate, true);
List<HisRecipe> hisRecipes = new HisRecipeDao().getUnPayRecipe(patientId, personNo, days);
List<HisRecipe> resultList = new ArrayList<>();
for (HisRecipe hisRecipe : hisRecipes) {
if (hisRecipe.getDate() != null && DateHelper.inDateRange(begDate, endDate, hisRecipe.getDate(), DateHelper.DateEnum.yyyy_MM_dd) && !"1".equals(hisRecipe.getSTDFlag()) && (!"1".equals(hisRecipe.getInternetHospFlag()) || "1".equals(hisRecipe.getYJSAuditFlag()))) {
resultList.add(hisRecipe);
}
}
return Result.success(resultList);
}
/**
* 获取所以未缴费订单 包括互联网医院未审核,医保双通道订单
*
* @param patientId patientId
* @param begDate 开始时间
* @param endDate 结束时间
*/
@Action("getMedicalRecipe")
public Result getMedicalRecipe(String patientId, String begDate, String endDate) {
log.info("[处方]未缴费项目查询 patientId={}", patientId);
patientId = getDecodeString(patientId);
if (patientId == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
int days = DateHelper.intervalDays(begDate, endDate, true);
List<HisRecipe> hisRecipes = new HisRecipeDao().getUnPayRecipe(patientId, "", days);
List<HisRecipe> resultList = new ArrayList<>();
for (HisRecipe hisRecipe : hisRecipes) {
if (hisRecipe.getDate() != null && DateHelper.inDateRange(begDate, endDate, hisRecipe.getDate(), DateHelper.DateEnum.yyyy_MM_dd)) {
resultList.add(hisRecipe);
}
}
return Result.success(resultList);
}
/**
* 将订单上传到医保双通道
*
* @param treatNum 门诊号
* @param personID 身份证
* @param recipes 处方号合集,中间用英文逗号隔开
*/
@Action("uploadMedicalRecipe")
public Result uploadMedicalRecipe(String treatNum, String personID, String recipes) {
log.info("[互联网医院]处方医保双通道流转 treatNum={},personNo-{}, recipes={}", treatNum, personID, recipes);
if (treatNum == null || personID == null || recipes == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
return new HisRecipeDao().uploadMedicalRecipe(treatNum, personID, recipes);
}
// /**
// * 获取未缴费项目
// */
// @Action("getDevUnPayList")
// public Result getDevUnPayList(String patientId, String begDate, String endDate ) {
// log.info("[处方]未缴费项目查询 patientId={}, begDate={}, endDate={}", patientId, begDate, endDate);
// if (patientId == null || begDate == null || endDate == null) {
// return Result.error(ResultEnum.PARAM_IS_DEFECT);
// }
//
// int days = DateHelper.intervalDays(begDate, endDate, true);
// List<HisRecipe> hisRecipes = new DevHisRecipeDao().getDevUnPayRecipe(patientId, days);
//
// List<HisRecipe> resultList = new ArrayList<>();
// for (HisRecipe hisRecipe : hisRecipes) {
// if (hisRecipe.getDate() != null && DateHelper.inDateRange(begDate, endDate, hisRecipe.getDate(), DateHelper.DateEnum.yyyy_MM_dd)) {
// resultList.add(hisRecipe);
// }
// }
// return Result.success(resultList);
// }
/**
* 预约体检his缴费
*
* @param treatNum 体检号
* @param payMoney 缴费金额
* @param payDate 缴费日期
* @param payTime 缴费时间
* @param bankTransNo bankTransNo
* @param outTranNo outTranNo
*/
@Action("peisHisPay")
public Result peisHisPay(String treatNum, String payMoney, String payDate, String payTime, String bankTransNo, String outTranNo) {
log.info("[体检预约请求his计费]treatNum-{},payMoney-{},payDate-{},payTime-{},bankTransNo-{},outTranNo-{}", treatNum, payMoney, payDate, payTime, bankTransNo, outTranNo);
if ("".equals(treatNum) || "".equals(outTranNo)) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
Recipe recipe = new PeisDao().selectByOutTradeNo(outTranNo);
if (recipe == null) {
return Result.error(ResultEnum.DATA_NOT_FOUND);
}
if (!recipe.getBankTransNo().equals(bankTransNo)) {
log.info("[体检预约请求his计费]体检系统跟微信支付系统两笔订单不一致,体检系统:bankTransNo-{},微信系统:bankTransNo-{}", bankTransNo, recipe.getBankTransNo());
return Result.error(ResultEnum.DATA_IS_WRONG);
}
Map<String, Object> params = new HashMap<>();
params.put("MZNum", "0");
params.put("PatientID", "0");
params.put("TJBH", treatNum);
params.put("GroupFlag", "1");
params.put("PayMoney", payMoney);
params.put("PayDate", payDate);
params.put("PayTime", payTime);
params.put("TransNo", recipe.getTradeNo());
params.put("PayDeviceID", "app");
params.put("PayWay", MerchantEnum.WX.HIS_PAY_WAY);
params.put("BankTransNo", bankTransNo); // 商户订单号
params.put("OpenId", recipe.getOpenid());
params.put("Token", WeChatConfig.TOKEN);
JsonResult result = HisHelper.getJsonResult(HisEnum.AP_Pay_Invoice, params, MerchantEnum.WX);
return result.success() ? Result.success(result) : Result.error(result.getMessage());
}
/**
* 标准物价查询
*
* @param pageNum 页码
* @param pageSize 每页数量
* @param pyCode 拼音码
* @param type 类型 {1:检查治疗; 2:药品材料; 99:全部}
* @param groupFlag 组套标识 { 0:不含组套; 1:包含组套 }
* @return 结果
*/
@Action("getStandardPrice")
public Result getStandardPrice(Integer pageNum, Integer pageSize, String pyCode, String type, String groupFlag) {
return new RecipeService().getStandardPrice(pageNum, pageSize, pyCode, type, groupFlag);
}
/**
* 添加核酸检测记录(德宏)
*/
@Action("addNatRecord")
public Result addNatRecord() {
String openid = getString("openid");
String patientId = getString("patientId");
if (patientId == null || openid == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
Boolean isRepeat = getBoolean("isRepeat"); // 开启重复填写检查
if (isRepeat == null) isRepeat = false;
NatRecordDao natRecordDao = new NatRecordDao();
if (isRepeat && natRecordDao.hasRecord(patientId, DateHelper.getCurDate())) {
return Result.success();
}
String temperature = getString("temperature"); // 体温
String country = getString("country"); // 国籍
String greenCode = getString("greenCode"); // 绿码情况
String tripCode = getString("tripCode"); // 行程码情况
String symptom = getString("symptom"); // 症状
String info = getString("info");
log.info("[核酸检测]记录 country={}, temperature={}, greenCode={}, tripCode={}, symptom={}", country, temperature, greenCode, tripCode, symptom);
if (temperature == null || greenCode == null || tripCode == null) {
return Result.error(ResultEnum.PARAM_IS_DEFECT);
}
Patient patient = new PatientDao().selectByOpenidAndPatientId(openid, patientId);
if (patient == null) {
return Result.error(ResultEnum.PATIENT_NOT_FOUND);
}
NatRecord natRecord = new NatRecord();
natRecord.setOperateUser("蓝旗");
natRecord.setPatientId(patientId);
natRecord.setIdCardNo(patient.getIdCardNo());
natRecord.setName(patient.getName());
natRecord.setTel(patient.getTel());
natRecord.setSex(patient.getSex());
//
natRecord.setCountry(country);
natRecord.setTemperature(temperature);
natRecord.setGreenCode(greenCode);
natRecord.setTripCode(tripCode);
natRecord.setSymptom(symptom);
//
natRecord.setInfo(info);
boolean isInsert = natRecordDao.insert(natRecord);
if (!isInsert) {
log.info("[核酸检测] 记录信息失败 patientId={}, openid={}", patientId, openid);
return Result.error();
}
return Result.success();
}
// /**
// * 核酸检测支付
// */
// @Action("payNat")
// public Result payNat() {
// String patientId = getString("patientId");
// Boolean isDoubleCollect = getBoolean("isDoubleCollect"); // 是否双采
// if (StringUtils.isEmpty(patientId)) {
// return Result.error(ResultEnum.PARAM_IS_DEFECT);
// }
//
// // 开申请单
// JsonResult JsonResult = new HisRecipeDao().payNat(patientId, isDoubleCollect);
// if (JsonResult.isTimeout()) { // 请求超时
// return Result.error(JsonResult.getMessage());
// }
//
// String mzNum = JsonResult.getDataMapString("MZNum");
// String recipeId = JsonResult.getDataMapString("RecipeId");
// if (ObjectUtils.isEmpty(recipeId) || ObjectUtils.isEmpty(mzNum)) {
// return Result.error(JsonResult.getMessage());
// }
//
// if (!JsonResult.success()) {
// return Result.error(ResultEnum.RECIPE_REPEAT_BILL, null, JsonResult.getMessage());
// }
//
// try {
// Map<String, Object> resultData = new HashMap<>();
// resultData.put("recipeId", Long.toString(Long.parseLong(recipeId) + 1000000000L));
// resultData.put("treatNum", mzNum);
// return Result.success(resultData);
// } catch (Exception e) {
// ErrorHelper.println(e);
// }
// return Result.error();
// }
}