@@ -4,20 +4,25 @@ import com.alibaba.fastjson2.JSONObject;
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.utils.SecurityUtils ;
import com.openhis.administration.domain.Organization ;
import com.openhis.administration.service.IOrganizationService ;
import com.openhis.infectious.domain.InfectiousAudit ;
import com.openhis.web.reportManagement.appservice.IInfectiousCardAppService ;
import com.openhis.web.reportManagement.dto.InfectiousCardDto ;
import com.openhis.web.reportManagement.dto.InfectiousCardParam ;
import com.openhis.web.cardmanagement.mapper.InfectiousAuditMapper ;
import com.openhis.web.reportManagement.mapper.ReportManageCardMapper ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import javax.servlet.http.HttpServletResponse ;
import java.io.PrintWriter ;
import java.util.ArrayList ;
import java.util.List ;
import java.time.LocalDateTime ;
/**
* 传染病报卡 AppService 实现
@@ -35,6 +40,41 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
@Autowired
private IOrganizationService organizationService ;
@Autowired
private InfectiousAuditMapper infectiousAuditMapper ;
private void createAuditRecord ( String cardNo , Integer statusFrom , Integer statusTo , String auditType ,
String auditOpinion , String reasonForReturn , boolean isBatch , Integer batchSize ) {
String safeCardNo = cardNo = = null ? null : cardNo . trim ( ) ;
Integer nextSeq = infectiousAuditMapper . getNextAuditSeq ( safeCardNo ) ;
InfectiousAudit audit = new InfectiousAudit ( ) ;
// infectious_audit.card_id 设计上应存报卡 card_no( 字符串)
audit . setCardId ( safeCardNo ) ;
audit . setAuditSeq ( nextSeq ) ;
audit . setAuditType ( auditType ) ;
audit . setAuditStatusFrom ( statusFrom = = null ? null : String . valueOf ( statusFrom ) ) ;
audit . setAuditStatusTo ( statusTo = = null ? null : String . valueOf ( statusTo ) ) ;
audit . setAuditTime ( LocalDateTime . now ( ) ) ;
audit . setAuditorId ( SecurityUtils . getUserId ( ) ! = null ? SecurityUtils . getUserId ( ) . toString ( ) : null ) ;
audit . setAuditorName ( SecurityUtils . getUsername ( ) ) ;
audit . setAuditOpinion ( auditOpinion ) ;
audit . setReasonForReturn ( reasonForReturn ) ;
audit . setIsBatch ( isBatch ) ;
audit . setBatchSize ( batchSize ) ;
// 通用审计字段(数据库字段建议为 create_time/update_time, 与 HisBaseEntity 保持一致)
audit . setCreateBy ( SecurityUtils . getUsernameSafe ( ) ) ;
audit . setUpdateBy ( SecurityUtils . getUsernameSafe ( ) ) ;
audit . setCreateTime ( new java . util . Date ( ) ) ;
audit . setUpdateTime ( new java . util . Date ( ) ) ;
audit . setTenantId ( SecurityUtils . getLoginUser ( ) . getTenantId ( ) ) ;
audit . setDeleteFlag ( " 0 " ) ;
int inserted = infectiousAuditMapper . insert ( audit ) ;
if ( inserted < = 0 ) {
throw new RuntimeException ( " 写入审核记录失败 " ) ;
}
}
/**
* 分页查询传染病报卡列表
* @param param 查询参数
@@ -106,15 +146,21 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
* @return 审核结果
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public R < ? > audit ( String cardNo , String auditOpinion , String status ) {
try {
Infectious CardDt o dt o = reportManageCardMapper . selectCardByCardNo ( cardNo ) ;
String safe CardN o = cardN o = = null ? null : cardNo . trim ( ) ;
InfectiousCardDto dto = reportManageCardMapper . selectCardByCardNo ( safeCardNo ) ;
if ( dto = = null ) {
return R . fail ( " 报卡不存在 " ) ;
}
int row s = reportManageCardMapper . auditCard ( cardNo , Integer . parseInt ( s tatus) ) ;
Integer f romStatu s = dto . getS tatus( ) ;
Integer toStatus = Integer . parseInt ( status ) ;
int rows = reportManageCardMapper . auditCard ( safeCardNo , Integer . parseInt ( status ) ) ;
if ( rows > 0 ) {
// 单审核通过: auditType=2
createAuditRecord ( safeCardNo , fromStatus , toStatus , " 2 " , auditOpinion , null , false , 1 ) ;
return R . ok ( " 审核成功 " ) ;
} else {
return R . fail ( " 审核失败:未更新任何记录 " ) ;
@@ -133,15 +179,21 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
* @return 退回结果
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public R < ? > returnCard ( String cardNo , String returnReason , String status ) {
try {
Infectious CardDt o dt o = reportManageCardMapper . selectCardByCardNo ( cardNo ) ;
String safe CardN o = cardN o = = null ? null : cardNo . trim ( ) ;
InfectiousCardDto dto = reportManageCardMapper . selectCardByCardNo ( safeCardNo ) ;
if ( dto = = null ) {
return R . fail ( " 报卡不存在 " ) ;
}
int row s = reportManageCardMapper . returnCard ( cardNo , Integer . parseInt ( status ) , returnReason ) ;
Integer f romStatu s = dto . getStatus ( ) ;
Integer toStatus = Integer . parseInt ( status ) ;
int rows = reportManageCardMapper . returnCard ( safeCardNo , Integer . parseInt ( status ) , returnReason ) ;
if ( rows > 0 ) {
// 单退回: auditType=4
createAuditRecord ( safeCardNo , fromStatus , toStatus , " 4 " , null , returnReason , false , 1 ) ;
return R . ok ( " 退回成功 " ) ;
} else {
return R . fail ( " 退回失败:未更新任何记录 " ) ;
@@ -160,14 +212,27 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
* @return 批量审核结果
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public R < ? > batchAudit ( List < String > cardNos , String auditOpinion , String status ) {
try {
int successCount = 0 ;
int failCount = 0 ;
for ( String cardNo : cardNos ) {
try {
InfectiousCardDto dto = reportManageCardMapper . selectCardByCardNo ( cardNo ) ;
int rows = reportManageCardMapper . auditCard ( cardNo , Integer . parseInt ( status ) ) ;
if ( rows > 0 ) {
// 批量审核: auditType=1
createAuditRecord (
cardNo ,
dto ! = null ? dto . getStatus ( ) : null ,
Integer . parseInt ( status ) ,
" 1 " ,
auditOpinion ,
null ,
true ,
cardNos . size ( )
) ;
successCount + + ;
} else {
failCount + + ;
@@ -192,14 +257,27 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
* @return 批量退回结果
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public R < ? > batchReturn ( List < String > cardNos , String returnReason , String status ) {
try {
int successCount = 0 ;
int failCount = 0 ;
for ( String cardNo : cardNos ) {
try {
InfectiousCardDto dto = reportManageCardMapper . selectCardByCardNo ( cardNo ) ;
int rows = reportManageCardMapper . returnCard ( cardNo , Integer . parseInt ( status ) , returnReason ) ;
if ( rows > 0 ) {
// 批量退回: auditType=3
createAuditRecord (
cardNo ,
dto ! = null ? dto . getStatus ( ) : null ,
Integer . parseInt ( status ) ,
" 3 " ,
null ,
returnReason ,
true ,
cardNos . size ( )
) ;
successCount + + ;
} else {
failCount + + ;
@@ -284,20 +362,28 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
* @return 结果
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public R < ? > revokeAudit ( String cardNo , String status ) {
try {
// 验证参数
if ( cardNo = = null | | cardNo . trim ( ) . isEmpty ( ) ) {
return R . fail ( " 报卡编号不能为空 " ) ;
}
String safeCardNo = cardNo . trim ( ) ;
if ( status = = null | | status . trim ( ) . isEmpty ( ) ) {
return R . fail ( " 撤销后的状态不能为空 " ) ;
}
InfectiousCardDto dto = reportManageCardMapper . selectCardByCardNo ( safeCardNo ) ;
Integer fromStatus = dto ! = null ? dto . getStatus ( ) : null ;
Integer toStatus = Integer . parseInt ( status ) ;
// 执行撤销审核操作
int rows = reportManageCardMapper . revokeAuditCard ( c ardNo, Integer . parseInt ( status ) ) ;
int rows = reportManageCardMapper . revokeAuditCard ( safeC ardNo, Integer . parseInt ( status ) ) ;
if ( rows > 0 ) {
// 撤销审核: auditType=5(其他)
createAuditRecord ( safeCardNo , fromStatus , toStatus , " 5 " , " 撤销审核 " , null , false , 1 ) ;
return R . ok ( " 撤销审核成功 " ) ;
} else {
return R . fail ( " 撤销审核失败:未找到对应的报卡 " ) ;
@@ -411,6 +497,20 @@ public class InfectiousCardAppServiceImpl implements IInfectiousCardAppService {
}
}
@Override
public R < ? > getAuditRecords ( String cardNo ) {
try {
if ( cardNo = = null | | cardNo . trim ( ) . isEmpty ( ) ) {
return R . fail ( " 报卡编号不能为空 " ) ;
}
List < InfectiousAudit > records = infectiousAuditMapper . selectByCardId ( cardNo ) ;
return R . ok ( records ) ;
} catch ( Exception e ) {
log . error ( " 查询审核记录失败, cardNo={} " , cardNo , e ) ;
return R . fail ( " 查询审核记录失败: " + e . getMessage ( ) ) ;
}
}
/**
* 构建树形结构
*/