diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/cardmanagement/mapper/InfectiousAuditMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/cardmanagement/mapper/InfectiousAuditMapper.java index b3c873c9..153d67f2 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/cardmanagement/mapper/InfectiousAuditMapper.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/cardmanagement/mapper/InfectiousAuditMapper.java @@ -20,12 +20,12 @@ public interface InfectiousAuditMapper extends BaseMapper { /** * 根据报卡编号查询审核记录 */ - @Select("SELECT * FROM infectious_audit WHERE card_id = #{cardId} ORDER BY audit_time DESC") + @Select("SELECT * FROM infectious_audit WHERE card_id::text = #{cardId} ORDER BY audit_time DESC") List selectByCardId(@Param("cardId") String cardId); /** * 获取下一个审核序号 */ - @Select("SELECT COALESCE(MAX(audit_seq), 0) + 1 FROM infectious_audit WHERE card_id = #{cardId}") + @Select("SELECT COALESCE(MAX(audit_seq), 0) + 1 FROM infectious_audit WHERE card_id::text = #{cardId}") Integer getNextAuditSeq(@Param("cardId") String cardId); } diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/IInfectiousCardAppService.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/IInfectiousCardAppService.java index 8c7956f1..0226706f 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/IInfectiousCardAppService.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/IInfectiousCardAppService.java @@ -104,4 +104,12 @@ public interface IInfectiousCardAppService { R revokeAudit(String cardNo, String status); R getDeptTree(); + /** + * 查询报卡审核记录(留痕追溯) + * + * @param cardNo 报卡编号 + * @return 审核记录列表 + */ + R getAuditRecords(String cardNo); + } \ No newline at end of file diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/impl/InfectiousCardAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/impl/InfectiousCardAppServiceImpl.java index 5c8f1c74..f8fcdf32 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/impl/InfectiousCardAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/appservice/impl/InfectiousCardAppServiceImpl.java @@ -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 { - InfectiousCardDto dto = reportManageCardMapper.selectCardByCardNo(cardNo); + String safeCardNo = cardNo == null ? null : cardNo.trim(); + InfectiousCardDto dto = reportManageCardMapper.selectCardByCardNo(safeCardNo); if (dto == null) { return R.fail("报卡不存在"); } - int rows = reportManageCardMapper.auditCard(cardNo, Integer.parseInt(status)); + Integer fromStatus = dto.getStatus(); + 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 { - InfectiousCardDto dto = reportManageCardMapper.selectCardByCardNo(cardNo); + String safeCardNo = cardNo == null ? null : cardNo.trim(); + InfectiousCardDto dto = reportManageCardMapper.selectCardByCardNo(safeCardNo); if (dto == null) { return R.fail("报卡不存在"); } - int rows = reportManageCardMapper.returnCard(cardNo, Integer.parseInt(status), returnReason); + Integer fromStatus = 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 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 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(cardNo, Integer.parseInt(status)); + int rows = reportManageCardMapper.revokeAuditCard(safeCardNo, 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 records = infectiousAuditMapper.selectByCardId(cardNo); + return R.ok(records); + } catch (Exception e) { + log.error("查询审核记录失败, cardNo={}", cardNo, e); + return R.fail("查询审核记录失败:" + e.getMessage()); + } + } + /** * 构建树形结构 */ diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/controller/reportManagementController.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/controller/reportManagementController.java index 9ee78a40..6ccea53a 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/controller/reportManagementController.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/reportManagement/controller/reportManagementController.java @@ -55,6 +55,14 @@ public class reportManagementController { return infectiousCardAppService.getByCardNo(cardNo); } + /** + * 查询报卡审核记录(留痕追溯) + */ + @GetMapping("/auditRecords/{cardNo}") + public R getAuditRecords(@PathVariable String cardNo) { + return infectiousCardAppService.getAuditRecords(cardNo); + } + /** * 审核传染病报卡 */ diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/reportManagement/InfectiousCardMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/reportManagement/InfectiousCardMapper.xml index efe57634..260e5760 100644 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/reportManagement/InfectiousCardMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/reportManagement/InfectiousCardMapper.xml @@ -150,6 +150,7 @@ WHERE t1.delete_flag = '0' AND t1.card_no = #{cardNo} + UPDATE infectious_card diff --git a/openhis-ui-vue3/src/views/diseaseReportManagement/ReportManagement/index.vue b/openhis-ui-vue3/src/views/diseaseReportManagement/ReportManagement/index.vue index a8eb9d3c..510cb70b 100644 --- a/openhis-ui-vue3/src/views/diseaseReportManagement/ReportManagement/index.vue +++ b/openhis-ui-vue3/src/views/diseaseReportManagement/ReportManagement/index.vue @@ -518,13 +518,16 @@ @close="handleDrawerClose" >