From f1a8fafb7208f13057e09b8a6b3ddcda672d2d68 Mon Sep 17 00:00:00 2001 From: chenqi Date: Wed, 17 Jun 2026 14:46:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(mrhomepage):=20=E7=97=85=E6=A1=88=E7=A4=BA?= =?UTF-8?q?=E8=B8=AA=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appservice/IMrTrackingAppService.java | 15 +++ .../impl/MrTrackingAppServiceImpl.java | 105 ++++++++++++++++++ .../controller/MrTrackingController.java | 43 +++++++ 3 files changed, 163 insertions(+) create mode 100644 healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/IMrTrackingAppService.java create mode 100644 healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/impl/MrTrackingAppServiceImpl.java create mode 100644 healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/controller/MrTrackingController.java diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/IMrTrackingAppService.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/IMrTrackingAppService.java new file mode 100644 index 000000000..f7ece352a --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/IMrTrackingAppService.java @@ -0,0 +1,15 @@ +package com.healthlink.his.web.mrhomepage.appservice; + +import com.healthlink.his.mrhomepage.domain.MrBorrowing; +import com.healthlink.his.mrhomepage.domain.MrTracking; + +import java.util.Map; + +public interface IMrTrackingAppService { + + Map trackStatus(Long homepageId); + + MrBorrowing borrowRecord(MrBorrowing borrowing); + + void returnRecord(Long borrowingId); +} diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/impl/MrTrackingAppServiceImpl.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/impl/MrTrackingAppServiceImpl.java new file mode 100644 index 000000000..ba4194772 --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/appservice/impl/MrTrackingAppServiceImpl.java @@ -0,0 +1,105 @@ +package com.healthlink.his.web.mrhomepage.appservice.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.healthlink.his.mrhomepage.domain.MrBorrowing; +import com.healthlink.his.mrhomepage.domain.MrTracking; +import com.healthlink.his.mrhomepage.service.IMrBorrowingService; +import com.healthlink.his.mrhomepage.service.IMrTrackingService; +import com.healthlink.his.web.mrhomepage.appservice.IMrTrackingAppService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class MrTrackingAppServiceImpl implements IMrTrackingAppService { + + @Resource + private IMrTrackingService trackingService; + + @Resource + private IMrBorrowingService borrowingService; + + @Override + public Map trackStatus(Long homepageId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MrTracking::getMedicalRecordId, homepageId) + .orderByDesc(MrTracking::getMoveTime); + List records = trackingService.list(wrapper); + + Map result = new HashMap<>(); + result.put("records", records); + + long inShelf = records.stream().filter(r -> "IN_SHELF".equals(r.getStatus())).count(); + long borrowed = records.stream().filter(r -> "BORROWED".equals(r.getStatus())).count(); + long archived = records.stream().filter(r -> "ARCHIVED".equals(r.getStatus())).count(); + long lost = records.stream().filter(r -> "LOST".equals(r.getStatus())).count(); + + Map stats = new HashMap<>(); + stats.put("inShelf", inShelf); + stats.put("borrowed", borrowed); + stats.put("archived", archived); + stats.put("lost", lost); + result.put("stats", stats); + + MrTracking current = records.isEmpty() ? null : records.get(0); + result.put("currentStatus", current != null ? current.getStatus() : "UNKNOWN"); + result.put("currentLocation", current != null ? current.getLocation() : null); + + return result; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public MrBorrowing borrowRecord(MrBorrowing borrowing) { + borrowing.setStatus(0); + borrowing.setBorrowDate(new Date()); + borrowing.setCreateTime(new Date()); + borrowingService.save(borrowing); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MrTracking::getMedicalRecordId, borrowing.getMedicalRecordId()) + .eq(MrTracking::getStatus, "IN_SHELF"); + MrTracking track = trackingService.getOne(wrapper); + if (track != null) { + track.setStatus("BORROWED"); + track.setLocation(borrowing.getBorrowerDept() != null ? borrowing.getBorrowerDept() : "借出"); + track.setLocationType("BORROWED"); + track.setMovedBy(borrowing.getBorrowerName()); + track.setMoveTime(new Date()); + trackingService.updateById(track); + } + + return borrowing; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void returnRecord(Long borrowingId) { + MrBorrowing borrowing = borrowingService.getById(borrowingId); + if (borrowing == null) { + throw new RuntimeException("借阅记录不存在"); + } + borrowing.setActualReturnDate(new Date()); + borrowing.setStatus(3); + borrowing.setUpdateTime(new Date()); + borrowingService.updateById(borrowing); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MrTracking::getMedicalRecordId, borrowing.getMedicalRecordId()) + .eq(MrTracking::getStatus, "BORROWED"); + MrTracking track = trackingService.getOne(wrapper); + if (track != null) { + track.setStatus("IN_SHELF"); + track.setLocation("病案室"); + track.setLocationType("STORAGE"); + track.setMovedBy("系统自动归还"); + track.setMoveTime(new Date()); + trackingService.updateById(track); + } + } +} diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/controller/MrTrackingController.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/controller/MrTrackingController.java new file mode 100644 index 000000000..82bdbf6d1 --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/mrhomepage/controller/MrTrackingController.java @@ -0,0 +1,43 @@ +package com.healthlink.his.web.mrhomepage.controller; + +import com.core.common.core.domain.R; +import com.healthlink.his.mrhomepage.domain.MrBorrowing; +import com.healthlink.his.web.mrhomepage.appservice.IMrTrackingAppService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequestMapping("/api/v1/mr-homepage/tracking") +@Tag(name = "病案示踪管理") +public class MrTrackingController { + + @Resource + private IMrTrackingAppService mrTrackingAppService; + + @GetMapping("/{homepageId}") + @PreAuthorize("hasAuthority('inpatient:mrhomepage:list')") + @Operation(summary = "查询病案示踪状态") + public R> trackStatus(@PathVariable Long homepageId) { + return R.ok(mrTrackingAppService.trackStatus(homepageId)); + } + + @PostMapping("/borrow") + @PreAuthorize("hasAuthority('inpatient:mrhomepage:edit')") + @Operation(summary = "病案借阅") + public R borrowRecord(@RequestBody MrBorrowing borrowing) { + return R.ok(mrTrackingAppService.borrowRecord(borrowing)); + } + + @PostMapping("/return") + @PreAuthorize("hasAuthority('inpatient:mrhomepage:edit')") + @Operation(summary = "病案归还") + public R returnRecord(@RequestParam Long borrowingId) { + mrTrackingAppService.returnRecord(borrowingId); + return R.ok(); + } +}