@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.core.common.core.domain.R ;
import com.core.common.core.domain.model.LoginUser ;
import com.core.common.utils.SecurityUtils ;
import com.core.common.core.domain.model.LoginUser ;
import com.openhis.infectious.domain.InfectiousAudit ;
@@ -39,7 +40,7 @@ import java.util.Map;
import java.util.stream.Collectors ;
/**
* 报卡管理 Service实现
* 报卡管理 Service 实现
*
* @author system
* @date 2026-03-05
@@ -102,7 +103,7 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
IPage < InfectiousCard > result = infectiousCardMapper . selectPage ( page , wrapper ) ;
// 转换为DTO
// 转换为 DTO
List < InfectiousCardDto > list = result . getRecords ( ) . stream ( ) . map ( this : : convertToDto ) . collect ( Collectors . toList ( ) ) ;
Map < String , Object > resultMap = new HashMap < > ( ) ;
@@ -177,7 +178,7 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( card = = null ) continue ;
if ( " 2 " . equals ( card . getStatus ( ) ) | | " 3 " . equals ( card . getStatus ( ) ) ) continue ;
// 更新状态为退回(审核失败)
// 更新状态为退回 (审核失败)
String oldStatus = card . getStatus ( ) ;
card . setStatus ( " 5 " ) ;
card . setReturnReason ( batchReturnDto . getReturnReason ( ) ) ;
@@ -316,12 +317,12 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
@Override
public DoctorCardStatisticsDto getDoctorCardStatistics ( ) {
Long doctorId = SecurityUtils . getUserId ( ) ;
DoctorCardStatisticsDto dto = new DoctorCardStatisticsDto ( ) ;
Integer totalCount = infectiousCardMapper . countByDoctorId ( doctorId ) ;
Integer pendingFailedCount = infectiousCardMapper . countPendingFailedByDoctorId ( doctorId ) ;
Integer reportedCount = infectiousCardMapper . countReportedByDoctorId ( doctorId ) ;
dto . setTotalCount ( totalCount ! = null ? totalCount : 0 ) ;
dto . setPendingFailedCount ( pendingFailedCount ! = null ? pendingFailedCount : 0 ) ;
dto . setReportedCount ( reportedCount ! = null ? reportedCount : 0 ) ;
@@ -331,18 +332,18 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
@Override
public R < ? > getDoctorCardPage ( DoctorCardQueryDto queryParams ) {
Long doctorId = SecurityUtils . getUserId ( ) ;
Page < InfectiousCard > page = new Page < > ( queryParams . getPageNo ( ) , queryParams . getPageSize ( ) ) ;
LambdaQueryWrapper < InfectiousCard > wrapper = new LambdaQueryWrapper < > ( ) ;
// 只查询当前医生的报卡
wrapper . eq ( InfectiousCard : : getDoctorId , doctorId ) ;
// 状态筛选
if ( StringUtils . hasText ( queryParams . getStatus ( ) ) ) {
wrapper . eq ( InfectiousCard : : getStatus , queryParams . getStatus ( ) ) ;
}
// 时间范围筛选
if ( StringUtils . hasText ( queryParams . getStartDate ( ) ) ) {
LocalDateTime startDateTime = LocalDateTime . parse ( queryParams . getStartDate ( ) + " T00:00:00 " ) ;
@@ -352,7 +353,7 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
LocalDateTime endDateTime = LocalDateTime . parse ( queryParams . getEndDate ( ) + " T23:59:59 " ) ;
wrapper . le ( InfectiousCard : : getCreateTime , endDateTime ) ;
}
// 关键词搜索(患者姓名或报卡名称)
if ( StringUtils . hasText ( queryParams . getKeyword ( ) ) ) {
wrapper . and ( w - > w
@@ -361,17 +362,17 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
. like ( InfectiousCard : : getDiseaseName , queryParams . getKeyword ( ) )
) ;
}
// 按创建时间倒序
wrapper . orderByDesc ( InfectiousCard : : getCreateTime ) ;
IPage < InfectiousCard > result = infectiousCardMapper . selectPage ( page , wrapper ) ;
// 转换为DTO
// 转换为 DTO
List < DoctorCardListDto > list = result . getRecords ( ) . stream ( )
. map ( this : : convertToDoctorCardListDto )
. collect ( Collectors . toList ( ) ) ;
Map < String , Object > resultMap = new HashMap < > ( ) ;
resultMap . put ( " list " , list ) ;
resultMap . put ( " total " , result . getTotal ( ) ) ;
@@ -385,22 +386,22 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( card = = null ) {
return R . fail ( " 报卡不存在 " ) ;
}
// 验证权限:只能提交自己的报卡
if ( ! card . getDoctorId ( ) . equals ( SecurityUtils . getUserId ( ) ) ) {
return R . fail ( " 无权操作此报卡 " ) ;
}
// 验证状态:只有暂存状态可以提交
if ( ! " 0 " . equals ( card . getStatus ( ) ) ) {
return R . fail ( " 只能提交暂存状态的报卡 " ) ;
}
// 更新状态为已提交
card . setStatus ( " 1 " ) ;
card . setUpdateTime ( new Date ( ) ) ;
infectiousCardMapper . updateById ( card ) ;
return R . ok ( " 提交成功 " ) ;
}
@@ -411,22 +412,22 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( card = = null ) {
return R . fail ( " 报卡不存在 " ) ;
}
// 验证权限:只能撤回自己的报卡
if ( ! card . getDoctorId ( ) . equals ( SecurityUtils . getUserId ( ) ) ) {
return R . fail ( " 无权操作此报卡 " ) ;
}
// 验证状态:只有已提交状态可以撤回
if ( ! " 1 " . equals ( card . getStatus ( ) ) ) {
return R . fail ( " 只能撤回已提交状态的报卡 " ) ;
}
// 更新状态为暂存
card . setStatus ( " 0 " ) ;
card . setUpdateTime ( new Date ( ) ) ;
infectiousCardMapper . updateById ( card ) ;
return R . ok ( " 撤回成功 " ) ;
}
@@ -437,22 +438,22 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( card = = null ) {
return R . fail ( " 报卡不存在 " ) ;
}
// 验证权限:只能删除自己的报卡
if ( ! card . getDoctorId ( ) . equals ( SecurityUtils . getUserId ( ) ) ) {
return R . fail ( " 无权操作此报卡 " ) ;
}
// 验证状态:只有暂存状态可以删除
if ( ! " 0 " . equals ( card . getStatus ( ) ) ) {
return R . fail ( " 只能删除暂存状态的报卡 " ) ;
}
// 更新状态为作废
card . setStatus ( " 6 " ) ;
card . setUpdateTime ( new Date ( ) ) ;
infectiousCardMapper . updateById ( card ) ;
return R . ok ( " 删除成功 " ) ;
}
@@ -462,31 +463,31 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( cardNos = = null | | cardNos . isEmpty ( ) ) {
return R . fail ( " 请选择要提交的报卡 " ) ;
}
Long doctorId = SecurityUtils . getUserId ( ) ;
int successCount = 0 ;
for ( String cardNo : cardNos ) {
InfectiousCard card = infectiousCardMapper . selectByCardNo ( cardNo ) ;
if ( card = = null ) continue ;
// 验证权限:只能提交自己的报卡
if ( ! card . getDoctorId ( ) . equals ( doctorId ) ) continue ;
// 验证状态:只有暂存状态可以提交
if ( ! " 0 " . equals ( card . getStatus ( ) ) ) continue ;
// 更新状态为已提交
card . setStatus ( " 1 " ) ;
card . setUpdateTime ( new Date ( ) ) ;
infectiousCardMapper . updateById ( card ) ;
successCount + + ;
}
if ( successCount = = 0 ) {
return R . fail ( " 没有可提交的报卡,只能提交暂存状态的报卡 " ) ;
}
return R . ok ( " 批量提交成功,共提交 " + successCount + " 条 " ) ;
}
@@ -496,31 +497,31 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( cardNos = = null | | cardNos . isEmpty ( ) ) {
return R . fail ( " 请选择要删除的报卡 " ) ;
}
Long doctorId = SecurityUtils . getUserId ( ) ;
int successCount = 0 ;
for ( String cardNo : cardNos ) {
InfectiousCard card = infectiousCardMapper . selectByCardNo ( cardNo ) ;
if ( card = = null ) continue ;
// 验证权限:只能删除自己的报卡
if ( ! card . getDoctorId ( ) . equals ( doctorId ) ) continue ;
// 验证状态:只有暂存状态可以删除
if ( ! " 0 " . equals ( card . getStatus ( ) ) ) continue ;
// 更新状态为作废
card . setStatus ( " 6 " ) ;
card . setUpdateTime ( new Date ( ) ) ;
infectiousCardMapper . updateById ( card ) ;
successCount + + ;
}
if ( successCount = = 0 ) {
return R . fail ( " 没有可删除的报卡,只能删除暂存状态的报卡 " ) ;
}
return R . ok ( " 批量删除成功,共删除 " + successCount + " 条 " ) ;
}
@@ -529,35 +530,44 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
// 获取当前登录用户信息
LoginUser loginUser = SecurityUtils . getLoginUser ( ) ;
Long currentUserId = loginUser . getUserId ( ) ;
// 查询报卡
InfectiousCard card = infectiousCardMapper . selectByCardNo ( updateDto . getCardNo ( ) ) ;
if ( card = = null ) {
return R . fail ( " 报卡不存在 " ) ;
}
// 验证是否当前医生的报卡 - 根据doctorId字段验证
// 验证是否当前医生的报卡 - 根据 doctorId 字段验证
if ( ! currentUserId . equals ( card . getDoctorId ( ) ) ) {
return R . fail ( " 只能修改自己的报卡 " ) ;
}
// 验证状态是否允许修改(只能修改暂存状态的报卡)
if ( ! " 0 " . equals ( card . getStatus ( ) ) ) {
return R . fail ( " 只能修改暂存状态的报卡 " ) ;
}
// 更新字段
card . setPhone ( updateDto . getPhone ( ) ) ;
card . setOnsetDate ( updateDto . getOnsetDate ( ) ) ;
card . setDiagDate ( updateDto . getDiagDate ( ) ) ;
card . setDiseaseType ( updateDto . getDiseaseType ( ) ) ; // 使用diseaseType字段
card . setDiseaseType ( updateDto . getDiseaseType ( ) ) ; // 使用 diseaseType 字段
card . setAddressProv ( updateDto . getAddressProv ( ) ) ;
card . setAddressCity ( updateDto . getAddressCity ( ) ) ;
card . setAddressCounty ( updateDto . getAddressCounty ( ) ) ;
card . setAddressHouse ( updateDto . getAddressHouse ( ) ) ;
card . setUpdateTime ( new Date ( ) ) ;
card . setUpdateBy ( loginUser . getUsername ( ) ) ; // 使用username作为更新者
card . setUpdateTime ( new Date ( ) ) ;
card . setUpdateBy ( loginUser . getUsername ( ) ) ; // 使用 username 作为更新者
card . setUpdateTime ( new Date ( ) ) ;
card . setUpdateBy ( loginUser . getUsername ( ) ) ; // 使用 username 作为更新者
card . setUpdateTime ( new Date ( ) ) ;
card . setUpdateBy ( loginUser . getUsername ( ) ) ; // 使用 username 作为更新者
int rows = infectiousCardMapper . updateById ( card ) ;
if ( rows > 0 ) {
return R . ok ( " 更新成功 " ) ;
@@ -571,25 +581,25 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
if ( card = = null ) {
return ;
}
// 验证权限:只能导出自己的报卡
if ( ! card . getDoctorId ( ) . equals ( SecurityUtils . getUserId ( ) ) ) {
return ;
}
// 验证状态:只有已上报状态可以导出
if ( ! " 3 " . equals ( card . getStatus ( ) ) ) {
return ;
}
try {
// TODO: 实现Word导出逻辑, 使用Apache POI或其他库
// TODO: 实现 Word 导出逻辑,使用 Apache POI 或其他库
// 这里简化为返回文本内容
response . setContentType ( " application/vnd.openxmlformats-officedocument.wordprocessingml.document " ) ;
response . setHeader ( " Content-Disposition " , " attachment;filename= " +
URLEncoder . encode ( " 传染病报告卡- " + cardNo + " .docx " , StandardCharsets . UTF_8 ) ) ;
// 实际应生成Word文档内容
// 实际应生成 Word 文档内容
response . getWriter ( ) . write ( " 报卡编号: " + cardNo ) ;
} catch ( IOException e ) {
log . error ( " 导出报卡失败 " , e ) ;
@@ -597,13 +607,13 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
}
/**
* 转换为医生报卡列表DTO
* 转换为医生报卡列表 DTO
*/
private DoctorCardListDto convertToDoctorCardListDto ( InfectiousCard card ) {
DoctorCardListDto dto = new DoctorCardListDto ( ) ;
BeanUtils . copyProperties ( card , dto ) ;
dto . setCardName ( getCardName ( card . getCardNameCode ( ) ) ) ;
dto . setSubmitTime ( card . getCreateTime ( ) ! = null ?
dto . setSubmitTime ( card . getCreateTime ( ) ! = null ?
new SimpleDateFormat ( " yyyy-MM-dd HH:mm " ) . format ( card . getCreateTime ( ) ) : null ) ;
return dto ;
}
@@ -623,7 +633,7 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
}
/**
* 转换审核记录为DTO
* 转换审核记录为 DTO
*/
private AuditRecordDto convertAuditToDto ( InfectiousAudit audit ) {
AuditRecordDto dto = new AuditRecordDto ( ) ;
@@ -633,7 +643,7 @@ public class CardManageAppServiceImpl implements ICardManageAppService {
}
/**
* 转换为报卡DTO
* 转换为报卡 DTO
*/
private InfectiousCardDto convertToDto ( InfectiousCard card ) {
InfectiousCardDto dto = new InfectiousCardDto ( ) ;