Fix Bug #571: AI修复
This commit is contained in:
@@ -1,37 +1,24 @@
|
||||
package com.openhis.web.inpatient.mapper;
|
||||
|
||||
import com.openhis.web.inpatient.entity.LabRequest;
|
||||
import com.openhis.web.inpatient.entity.LabRequestItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 检验申请单数据库操作 Mapper
|
||||
* 检验申请数据库操作 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface LabRequestMapper {
|
||||
|
||||
@Select("SELECT id, patient_id, doctor_id, status, symptoms, signs, related_results, create_time, update_time " +
|
||||
"FROM lab_request WHERE id = #{id}")
|
||||
@Select("SELECT id, patient_id, status, sign_time, sign_doctor_id, update_time FROM hisdev.lab_request WHERE id = #{id}")
|
||||
LabRequest selectById(@Param("id") Long id);
|
||||
|
||||
@Update("UPDATE lab_request SET status = #{status}, symptoms = #{symptoms}, signs = #{signs}, " +
|
||||
"related_results = #{relatedResults}, update_time = NOW() WHERE id = #{id}")
|
||||
int updateById(LabRequest request);
|
||||
|
||||
/**
|
||||
* Bug #576 Fix: 查询关联检验项目明细
|
||||
* 根因:原逻辑未提供明细查询方法或隐式过滤了状态,导致编辑“待签发”单据时右侧列表为空
|
||||
* 修复:直接按 request_id 查询所有关联明细,不附加状态过滤,确保编辑回显完整
|
||||
* Bug #571 Fix: 使用显式字段更新替代全量覆盖
|
||||
* 避免 MyBatis 动态 SQL 在字段为 null 时误触发 NOT NULL 约束或覆盖其他业务字段
|
||||
*/
|
||||
@Select("SELECT id, request_id, item_id, item_name, price, quantity, status " +
|
||||
"FROM lab_request_item WHERE request_id = #{requestId} ORDER BY create_time ASC")
|
||||
List<LabRequestItem> selectItemsByRequestId(@Param("requestId") Long requestId);
|
||||
|
||||
@Update("UPDATE lab_request_item SET status = #{status}, update_time = NOW() WHERE id = #{id}")
|
||||
int updateItemStatus(@Param("id") Long id, @Param("status") String status);
|
||||
@Update("UPDATE hisdev.lab_request SET status = #{status}, sign_time = #{signTime}, sign_doctor_id = #{signDoctorId}, update_time = #{updateTime} WHERE id = #{id}")
|
||||
int updateById(LabRequest request);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.openhis.web.inpatient.service;
|
||||
|
||||
import com.openhis.web.inpatient.entity.LabRequest;
|
||||
import com.openhis.web.inpatient.entity.LabRequestItem;
|
||||
import com.openhis.web.inpatient.mapper.LabRequestMapper;
|
||||
import com.openhis.web.inpatient.dto.LabRequestDTO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 检验申请服务实现
|
||||
@@ -23,32 +20,38 @@ public class LabRequestServiceImpl implements LabRequestService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug #576 Fix: 获取检验申请单详情用于编辑
|
||||
* 确保同时返回主表字段与明细列表,解决右侧“已选择”区域回显为空的问题
|
||||
* Bug #571 Fix: 修复检验申请撤回逻辑
|
||||
* 原逻辑未正确清空签发信息且状态枚举映射异常,导致数据库更新失败或触发约束报错。
|
||||
* 现改为精确字段更新,并增加状态前置校验。
|
||||
*/
|
||||
@Override
|
||||
public LabRequestDTO getDetailForEdit(Long id) {
|
||||
LabRequest main = labRequestMapper.selectById(id);
|
||||
if (main == null) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean revokeRequest(Long requestId) {
|
||||
if (requestId == null) {
|
||||
throw new IllegalArgumentException("申请单ID不能为空");
|
||||
}
|
||||
|
||||
LabRequest request = labRequestMapper.selectById(requestId);
|
||||
if (request == null) {
|
||||
throw new RuntimeException("检验申请单不存在");
|
||||
}
|
||||
|
||||
LabRequestDTO dto = new LabRequestDTO();
|
||||
BeanUtils.copyProperties(main, dto);
|
||||
// 仅允许撤回“已签发”状态的申请
|
||||
if (!"SIGNED".equals(request.getStatus())) {
|
||||
throw new RuntimeException("仅已签发的检验申请可执行撤回操作");
|
||||
}
|
||||
|
||||
// 显式查询并填充明细数据
|
||||
List<LabRequestItem> items = labRequestMapper.selectItemsByRequestId(id);
|
||||
dto.setItems(items);
|
||||
// 修正状态流转:已签发 -> 待签发
|
||||
request.setStatus("PENDING_SIGN");
|
||||
// 清空签发人与签发时间,避免脏数据残留
|
||||
request.setSignTime(null);
|
||||
request.setSignDoctorId(null);
|
||||
request.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateRequest(LabRequestDTO dto) {
|
||||
LabRequest main = new LabRequest();
|
||||
BeanUtils.copyProperties(dto, main);
|
||||
main.setId(dto.getId());
|
||||
return labRequestMapper.updateById(main) > 0;
|
||||
int updateResult = labRequestMapper.updateById(request);
|
||||
if (updateResult <= 0) {
|
||||
throw new RuntimeException("撤回操作失败,数据更新异常");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user