Fix Bug #561: fallback修复
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.openhis.web.outpatient.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* 诊疗目录(Catalog)相关数据库操作 Mapper
|
||||
*
|
||||
* 该 Mapper 仅提供获取默认计量单位的查询,用于医嘱录入时的单位兜底。
|
||||
*/
|
||||
@Mapper
|
||||
public interface CatalogMapper {
|
||||
|
||||
/**
|
||||
* 根据诊疗目录 ID 查询其默认的计量单位(total_unit)。
|
||||
*
|
||||
* @param catalogId 诊疗目录主键 ID
|
||||
* @return 配置的计量单位字符串,若未配置则返回 null
|
||||
*/
|
||||
@Select("SELECT total_unit FROM adm_catalog WHERE id = #{catalogId}")
|
||||
String selectDefaultUnitByCatalogId(@Param("catalogId") Long catalogId);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.openhis.web.outpatient.service;
|
||||
|
||||
import com.openhis.web.outpatient.dto.OrderCreateParam;
|
||||
import com.openhis.web.outpatient.entity.OrderMain;
|
||||
import com.openhis.web.outpatient.mapper.OrderMainMapper;
|
||||
import com.openhis.web.outpatient.mapper.CatalogMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 门诊医嘱主表业务实现
|
||||
*/
|
||||
@Service
|
||||
public class OrderMainServiceImpl implements OrderMainService {
|
||||
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
private final CatalogMapper catalogMapper; // 新增:用于获取诊疗目录配置的默认计量单位
|
||||
|
||||
public OrderMainServiceImpl(OrderMainMapper orderMainMapper,
|
||||
CatalogMapper catalogMapper) {
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.catalogMapper = catalogMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建医嘱主记录
|
||||
*
|
||||
* @param param 前端提交的医嘱创建参数
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean createOrder(OrderCreateParam param) {
|
||||
OrderMain order = new OrderMain();
|
||||
order.setPatientId(param.getPatientId());
|
||||
order.setDoctorId(param.getDoctorId());
|
||||
order.setDeptId(param.getDeptId());
|
||||
order.setCatalogId(param.getCatalogId());
|
||||
order.setQuantity(param.getQuantity());
|
||||
order.setCreateTime(LocalDateTime.now());
|
||||
|
||||
// ---------- 修复点 ----------
|
||||
// 之前在保存医嘱时直接使用前端传入的 totalUnit,若前端未传或传入 null,
|
||||
// 页面会显示 “null”。这里改为在数据库层面兜底:如果前端未提供 totalUnit,
|
||||
// 则从诊疗目录(catalog)表中读取配置的默认计量单位并填充。
|
||||
// 这样即使前端忘记传值,也能保证页面展示正确的单位。
|
||||
// ----------
|
||||
String totalUnit = param.getTotalUnit();
|
||||
if (totalUnit == null || totalUnit.trim().isEmpty()) {
|
||||
// 通过 catalogId 查询诊疗目录的默认计量单位
|
||||
totalUnit = catalogMapper.selectDefaultUnitByCatalogId(param.getCatalogId());
|
||||
}
|
||||
order.setTotalUnit(totalUnit);
|
||||
|
||||
// 其余字段保持不变
|
||||
int affected = orderMainMapper.insert(order);
|
||||
return affected == 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user