Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
wangjian963
2026-02-03 15:16:03 +08:00
6 changed files with 479 additions and 97 deletions

View File

@@ -10,16 +10,21 @@ import com.core.common.utils.MessageUtils;
import com.core.common.utils.SecurityUtils;
import com.core.common.utils.StringUtils;
import com.core.common.utils.bean.BeanUtils;
import com.core.common.core.domain.entity.SysRole;
import com.core.common.core.domain.model.LoginUser;
import com.openhis.administration.domain.*;
import com.openhis.administration.mapper.PatientMapper;
import com.openhis.administration.service.*;
import com.openhis.common.constant.CommonConstants;
import com.openhis.common.constant.PromptMsgConstant;
import com.openhis.common.enums.*;
import com.openhis.common.enums.ybenums.YbPayment;
import com.openhis.common.utils.EnumUtils;
import com.openhis.common.utils.HisPageUtils;
import com.openhis.common.utils.HisQueryUtils;
import com.openhis.financial.domain.PaymentReconciliation;
import com.openhis.financial.domain.RefundLog;
import com.openhis.financial.service.IRefundLogService;
import com.openhis.web.basicservice.dto.HealthcareServiceDto;
import com.openhis.web.basicservice.mapper.HealthcareServiceBizMapper;
import com.openhis.web.chargemanage.appservice.IOutpatientRegistrationAppService;
@@ -40,10 +45,14 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* 门诊挂号 应用实现类
@@ -85,6 +94,9 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
@Resource
TriageCandidateExclusionService triageCandidateExclusionService;
@Resource
IRefundLogService iRefundLogService;
/**
* 门诊挂号 - 查询患者信息
*
@@ -260,7 +272,7 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
R<?> result = iPaymentRecService.cancelRegPayment(cancelPaymentDto);
PaymentReconciliation paymentRecon = null;
if (PaymentReconciliation.class.isAssignableFrom(result.getData().getClass())) {
if (result.getData() != null && PaymentReconciliation.class.isAssignableFrom(result.getData().getClass())) {
paymentRecon = (PaymentReconciliation)result.getData();
}
if (paymentRecon != null) {
@@ -275,6 +287,9 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
}
}
// 记录退号日志
recordRefundLog(cancelRegPaymentDto, byId, result, paymentRecon);
// 2025/05/05 该处保存费用项后,会通过统一收费处理进行收费
return R.ok(paymentRecon, MessageUtils.createMessage(PromptMsgConstant.Common.M00004, new Object[] {"退号"}));
}
@@ -394,4 +409,124 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra
return R.ok(null, "补打挂号成功");
}
/**
* 记录退号日志
*
* @param cancelRegPaymentDto 退号请求对象
* @param encounter 就诊信息
* @param result 退号结果
* @param paymentRecon 支付对账信息
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void recordRefundLog(CancelRegPaymentDto cancelRegPaymentDto,
Encounter encounter,
R<?> result,
PaymentReconciliation paymentRecon) {
RefundLog refundLog = new RefundLog();
try {
// 1. 订单ID唯一
String orderId = String.valueOf(cancelRegPaymentDto.getEncounterId());
refundLog.setOrderId(orderId);
// 已存在则不重复插入(防止唯一约束异常)
long exist = iRefundLogService.lambdaQuery()
.eq(RefundLog::getOrderId, orderId)
.count();
if (exist > 0) {
log.warn("退号日志已存在orderId={}", orderId);
return;
}
// 2. 患者信息
if (encounter != null) {
refundLog.setPatientId(String.valueOf(encounter.getPatientId()));
Patient patient = patientMapper.selectById(encounter.getPatientId());
refundLog.setPatientName(patient != null ? patient.getName() : "未知");
} else {
refundLog.setPatientId("0");
refundLog.setPatientName("未知");
}
// 3. 金额
// 优先使用paymentRecon中的displayAmount如果没有则尝试使用cancelRegPaymentDto中的displayAmount
BigDecimal refundAmount = BigDecimal.ZERO;
if (paymentRecon != null) {
// 使用退号后生成的paymentRecon的实际金额这个金额应该是负数
refundAmount = paymentRecon.getDisplayAmount() != null
? paymentRecon.getDisplayAmount().abs() // 取绝对值,因为退费金额通常显示为正数
: BigDecimal.ZERO;
} else if (cancelRegPaymentDto.getDisplayAmount() != null) {
refundAmount = cancelRegPaymentDto.getDisplayAmount();
}
refundLog.setRefundAmount(refundAmount);
// 4. 原因 & 类型
refundLog.setRefundReason(
StringUtils.isNotEmpty(cancelRegPaymentDto.getReason())
? cancelRegPaymentDto.getReason()
: "诊前退号-已缴费签到未就诊"
);
refundLog.setRefundType("FULL");
// 5. 退款方式
String refundMethod = "UNKNOWN";
if (cancelRegPaymentDto.getPaymentDetails() != null
&& !cancelRegPaymentDto.getPaymentDetails().isEmpty()) {
Integer payEnum = cancelRegPaymentDto.getPaymentDetails().get(0).getPayEnum();
if (payEnum != null) {
YbPayment ybPayment = YbPayment.getByValue(payEnum);
refundMethod = (ybPayment != null ? ybPayment.getInfo() : payEnum.toString());
}
}
refundLog.setRefundMethod(refundMethod);
// 6. 原交易号
refundLog.setOriginalTradeNo(
paymentRecon != null ? paymentRecon.getPaymentNo() : null
);
// 7. 时间
refundLog.setRefundTime(LocalDateTime.now());
// 8. 操作人
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null) {
refundLog.setOpUserId(String.valueOf(loginUser.getUserId()));
refundLog.setOpUserName(loginUser.getUsername());
List<SysRole> roles = loginUser.getRoleList();
refundLog.setOpRole(
roles != null && !roles.isEmpty() ? roles.get(0).getRoleName() : "SYSTEM"
);
} else {
refundLog.setOpUserId("0");
refundLog.setOpUserName("SYSTEM");
refundLog.setOpRole("SYSTEM");
}
// 9. 状态
if (result != null && result.getCode() == 200) {
refundLog.setState(1);
} else {
refundLog.setState(0);
refundLog.setFailReason(result != null ? result.getMsg() : "未知错误");
}
// 10. 创建时间
refundLog.setCreatedAt(LocalDateTime.now());
refundLog.setUpdatedAt(LocalDateTime.now());
// 11. 保存
boolean saved = iRefundLogService.save(refundLog);
if (!saved) {
throw new RuntimeException("退号日志保存失败");
}
log.info("退号日志入库成功, orderId={}", orderId);
} catch (Exception e) {
log.error("退号日志入库失败,数据={}", refundLog, e);
throw e; // 让事务感知(你也可以只记录不抛)
}
}
}

View File

@@ -0,0 +1,127 @@
package com.openhis.financial.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import lombok.Data;
/**
* 退号日志表
*/
@TableName(value = "refund_log")
@Data
public class RefundLog implements Serializable {
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 订单ID
*/
@TableField(value = "order_id")
private String orderId;
/**
* 患者ID
*/
@TableField(value = "patient_id")
private String patientId;
/**
* 患者姓名
*/
@TableField(value = "patient_name")
private String patientName;
/**
* 退款金额
*/
@TableField(value = "refund_amount")
private BigDecimal refundAmount;
/**
* 退款原因
*/
@TableField(value = "refund_reason")
private String refundReason;
/**
* 退款类型(FULL-全额退号PART-部分退号)
*/
@TableField(value = "refund_type")
private String refundType;
/**
* 退款方式
*/
@TableField(value = "refund_method")
private String refundMethod;
/**
* 原交易流水号
*/
@TableField(value = "original_trade_no")
private String originalTradeNo;
/**
* 退款交易流水号
*/
@TableField(value = "refund_trade_no")
private String refundTradeNo;
/**
* 退款时间
*/
@TableField(value = "refund_time")
private LocalDateTime refundTime;
/**
* 操作用户ID
*/
@TableField(value = "op_user_id")
private String opUserId;
/**
* 操作用户名
*/
@TableField(value = "op_user_name")
private String opUserName;
/**
* 操作角色
*/
@TableField(value = "op_role")
private String opRole;
/**
* 状态(0-失败1-成功2-处理中)
*/
@TableField(value = "state")
private Integer state;
/**
* 失败原因
*/
@TableField(value = "fail_reason")
private String failReason;
/**
* 创建时间
*/
@TableField(value = "created_at")
private LocalDateTime createdAt;
/**
* 更新时间
*/
@TableField(value = "updated_at")
private LocalDateTime updatedAt;
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,10 @@
package com.openhis.financial.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.openhis.financial.domain.RefundLog;
/**
* 退号日志 Mapper接口
*/
public interface RefundLogMapper extends BaseMapper<RefundLog> {
}

View File

@@ -0,0 +1,10 @@
package com.openhis.financial.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.openhis.financial.domain.RefundLog;
/**
* 退号日志 Service接口
*/
public interface IRefundLogService extends IService<RefundLog> {
}

View File

@@ -0,0 +1,14 @@
package com.openhis.financial.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.openhis.financial.domain.RefundLog;
import com.openhis.financial.mapper.RefundLogMapper;
import com.openhis.financial.service.IRefundLogService;
import org.springframework.stereotype.Service;
/**
* 退号日志 Service实现类
*/
@Service
public class RefundLogServiceImpl extends ServiceImpl<RefundLogMapper, RefundLog> implements IRefundLogService {
}

View File

@@ -10,58 +10,8 @@
<el-input v-model="form.name" clearable :disabled="isViewMode" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="性别" prop="genderEnum">
<el-radio-group v-model="form.genderEnum" :disabled="isViewMode">
<el-radio
v-for="item in administrativegenderList"
:key="item.value"
:label="item.value"
>
{{ item.info }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="活动标识" prop="tempFlag">
<el-radio-group v-model="form.tempFlag" :disabled="isViewMode">
<el-radio v-for="dict in patient_temp_flag" :key="dict.value" :label="dict.value">
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="联系方式" prop="phone">
<el-input v-model="form.phone" clearable :disabled="isViewMode" />
</el-form-item>
</el-col>
<!-- <el-col :span="8">
<el-form-item label="证件类型" prop="typeCode">
<el-select
v-model="form.typeCode"
placeholder="证件类型"
clearable
:disabled="isViewMode"
@change="typeChange"
>
<el-option
v-for="dict in sys_idtype"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-col> -->
<el-col :span="8">
<el-form-item label="身份证号码" prop="idCard">
<el-input v-model="form.idCard" clearable :disabled="isViewMode" @blur="onBlur" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="民族" prop="nationalityCode">
<el-col :span="6">
<el-form-item label="民族" prop="nationalityCode" label-width="80px">
<el-select v-model="form.nationalityCode" clearable filterable :disabled="isViewMode">
<el-option
v-for="item in nationality_code"
@@ -99,24 +49,84 @@
</el-row>
<!-- 第二行证件类别证件号码*年龄 -->
<el-row :gutter="10">
<el-col :span="8">
<el-form-item label="证件类别" prop="typeCode" label-width="80px">
<el-select
v-model="form.typeCode"
placeholder="就诊卡"
clearable
:disabled="isViewMode"
>
<el-option
v-for="dict in sys_idtype"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="证件号码" prop="idCard" label-width="80px">
<el-input v-model="form.idCard" clearable :disabled="isViewMode" @blur="onBlur" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="年龄" prop="age" label-width="80px">
<el-input
v-model="form.age"
:disabled="isViewMode"
@input="handleAgeInput"
placeholder="请输入年龄"
>
<template #suffix></template>
</el-input>
</el-form-item>
</el-col>
</el-row>
<!-- 第三行国籍*联系方式出生日期 -->
<el-row :gutter="10">
<el-col :span="8">
<el-form-item label="国籍" prop="countryCode" label-width="80px">
<el-select v-model="form.countryCode" placeholder="请选择国籍" clearable filterable :disabled="isViewMode">
<el-option
v-for="item in countryCodeList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="联系方式" prop="phone" label-width="80px">
<el-input v-model="form.phone" clearable :disabled="isViewMode" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="出生日期" prop="birthDate">
<el-date-picker
v-model="form.birthDate"
type="date"
placeholder="请选择出生日期"
format="YYYY年MM月DD日"
:disabled="isViewMode"
value-format="YYYY-MM-DD"
@change="handleBirthDateChange"
/>
</el-form-item>
</el-col>
</el-row>
<!-- 第四行就诊卡号职业邮政编码 -->
<el-row :gutter="10">
<el-col :span="8">
<el-form-item label="就诊卡号" prop="identifierNo">
<el-input v-model="form.identifierNo" clearable :disabled="isViewMode" />
</el-form-item>
</el-col>
<!-- <el-col :span="8">
<el-form-item label="国家编码" prop="countryCode">
<el-input v-model="form.countryCode" clearable :disabled="isViewMode" />
</el-form-item>
</el-col> -->
</el-row>
<!-- <el-col :span="6">
<el-form-item label="年龄" prop="age">
<el-input v-model="form.age" clearable :disabled="isViewMode"/>
</el-form-item>
</el-col> -->
<el-row>
<el-col :span="8">
<el-form-item label="职业" prop="prfsEnum">
<el-select v-model="form.prfsEnum" placeholder="职业" clearable :disabled="isViewMode">
@@ -135,7 +145,8 @@
</el-form-item>
</el-col>
</el-row>
<!-- 第四行工作单位 -->
<!-- 第五行工作单位 -->
<el-row>
<el-col :span="8">
<el-form-item label="工作单位" prop="workCompany">
@@ -262,7 +273,7 @@
</el-select>
</el-form-item>
</el-col>
<el-col :span="16">
<el-col :span="8">
<el-form-item label="死亡时间" prop="deceasedDate">
<el-date-picker
v-model="form.deceasedDate"
@@ -345,6 +356,7 @@ import {addPatient, getOutpatientRegistrationList, patientlLists} from './outpat
import {updatePatient} from '@/views/patientmanagement/patientmanagement/component/api';
import {getGenderAndAge, isValidCNidCardNumber, isValidCNPhoneNumber,} from '../../../../utils/validate';
import {ElMessage} from 'element-plus';
import {getConfigKey} from '@/api/system/config'; // 导入获取配置的方法
const router = useRouter();
const { proxy } = getCurrentInstance();
@@ -578,28 +590,39 @@ const validateIdCard = (rule, value, callback) => {
// 监护人信息条件验证函数
const validateGuardianInfo = (rule, value, callback) => {
// 只有当年龄小于规定年龄时才验证监护人信息
if (form.value.age) {
// 提取年龄数字部分
const ageMatch = form.value.age.toString().match(/\d+/);
if (ageMatch) {
const age = parseInt(ageMatch[0]);
const guardianAgeValue = parseInt(props.guardianAge) || 16;
// 如果年龄小于规定年龄,监护人信息必须填写
if (age < guardianAgeValue && !value) {
return callback(new Error(`年龄小于${guardianAgeValue}岁的患者必须填写监护人信息`));
// 从系统配置获取监护人规定年龄
getConfigKey('guardianAge').then(res => {
if (res.code === 200) {
const guardianAgeValue = parseInt(res.data) || 16; // 默认值为16
// 提取年龄数字部分
const ageMatch = form.value.age.toString().match(/\d+/);
if (ageMatch) {
const age = parseInt(ageMatch[0]);
// 如果年龄小于规定年龄,监护人信息必须填写
if (age < guardianAgeValue && !value) {
return callback(new Error(`年龄小于${guardianAgeValue}岁的患者必须填写监护人信息`));
}
}
}
}
callback();
callback(); // 如果获取不到配置或出现错误,仍然通过验证
}).catch(error => {
console.error('获取监护人规定年龄配置失败:', error);
callback(); // 获取配置失败时也通过验证
});
}
const data = reactive({
isViewMode: false,
form: {
typeCode: '01',
tempFlag: '1',
// genderEnum: 0,
typeCode: '08', // 证件类别,默认为'08'(就诊卡)
birthDate: undefined,
age: undefined,
hukouAddressSelect: undefined,
hukouAddress: undefined,
postalCode: undefined,
companyAddress: undefined,
patientDerived: undefined,
},
rules: {
name: [{ required: true, message: '姓名不能为空', trigger: 'change' },
@@ -616,7 +639,18 @@ const data = reactive({
genderEnum: [{ required: true, message: '请选择性别', trigger: 'change' }],
age: [{ required: true, message: '年龄不能为空', trigger: 'change' }],
phone: [{ required: true, message: '联系方式不能为空', trigger: 'change' }],
idCard: [{ required: true, message: '证件号不能为空', trigger: 'change' }],
identifierNo: [{ required: true, message: '就诊卡号不能为空', trigger: 'change' }],
idCard: [
{ required: false, message: '证件号码不能为空', trigger: 'change' },
{ validator: validateIdCard, trigger: 'blur' },
{ validator: validateUniquePatient, trigger: 'blur' }
],
birthDate: [{ required: false, message: '请选择出生日期', trigger: 'change' }],
// 监护人信息条件验证规则
guardianName: [{ validator: validateGuardianInfo, trigger: 'blur' }],
guardianRelation: [{ validator: validateGuardianInfo, trigger: 'blur' }],
guardianPhone: [{ validator: validateGuardianInfo, trigger: 'blur' }],
guardianIdNo: [{ validator: validateGuardianInfo, trigger: 'blur' }],
},
});
@@ -1271,22 +1305,74 @@ function cancel() {
visible.value = false;
reset();
}
// 身份证号失去焦点获取年龄和性别
const onBlur = () => {
if (form.value.typeCode === '01') {
const info = getGenderAndAge(form.value.idCard || '');
form.value.age = info.age;
form.value.genderEnum = info.gender;
// 处理出生日期变化,自动计算年龄
function handleBirthDateChange() {
if (form.value.birthDate) {
const birthDate = new Date(form.value.birthDate);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
// 计算精确年龄
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
form.value.age = age;
}
};
//切换证件类型
const typeChange = () => {
if (form.value.typeCode === '01') {
const info = getGenderAndAge(form.value.idCard || '');
form.value.age = info.age;
form.value.genderEnum = info.gender;
}
// 处理年龄输入,自动计算出生日期
function handleAgeInput() {
// 提取数字部分
const ageMatch = form.value.age.match(/\d+/);
if (ageMatch) {
const age = parseInt(ageMatch[0]);
// 移除非数字字符,保留数字和可能的单位
form.value.age = age ;
// 计算出生日期
const today = new Date();
const birthYear = today.getFullYear() - age;
const birthMonth = today.getMonth();
const birthDay = today.getDate();
const birthDate = new Date(birthYear, birthMonth, birthDay);
// 格式化为YYYY-MM-DD
const formattedBirthDate = birthDate.toISOString().split('T')[0];
form.value.birthDate = formattedBirthDate;
}
};
}
watch(
() => form.value.idCard,
(newIdCard) => {
if (newIdCard && newIdCard.length === 18) {
const birthYear = parseInt(newIdCard.substring(6, 10));
const birthMonth = parseInt(newIdCard.substring(10, 12));
const birthDay = parseInt(newIdCard.substring(12, 14));
// 设置出生日期
form.value.birthDate = `${birthYear}-${birthMonth.toString().padStart(2, '0')}-${birthDay.toString().padStart(2, '0')}`;
const today = new Date();
const currentYear = today.getFullYear();
const currentMonth = today.getMonth() + 1;
const currentDay = today.getDate();
let age = currentYear - birthYear;
// 如果当前月份小于出生月份或者月份相同但当前日期小于出生日期则年龄减1
if (
currentMonth < birthMonth ||
(currentMonth === birthMonth && currentDay < birthDay)
) {
age--;
}
form.value.age = age ;
}
}
);
// 设置查看模式
function setViewMode(isView) {
isViewMode.value = isView;