feat(menu): 优化菜单服务性能并新增医生排班功能

- 添加菜单缓存注解以提升查询性能
- 实现菜单完整路径计算优化,解决 N+1 查询问题
- 新增 selectAllMenus 方法供路径计算使用
- 添加今日医生排班查询功能
- 重构前端图标显示逻辑,使用 SVG 图标替代 Element 图标
- 添加前端菜单数据本地缓存机制
- 更新菜单管理界面的表单组件绑定方式
- 新增预约管理、门诊管理和药房管理路由配置
This commit is contained in:
2026-02-02 08:46:33 +08:00
parent 669d669422
commit 5534a71c7d
20 changed files with 1156 additions and 228 deletions

View File

@@ -140,4 +140,11 @@ public interface SysMenuMapper {
* @return 结果
*/
public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId);
/**
* 查询所有菜单信息
*
* @return 菜单列表
*/
public List<SysMenu> selectAllMenus();
}

View File

@@ -59,6 +59,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return 菜单列表
*/
@Override
@org.springframework.cache.annotation.Cacheable(value = "menu", key = "'menuList:' + #userId + ':' + (#menu == null ? 'all' : #menu.menuName)")
public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
List<SysMenu> menuList = null;
// 管理员显示所有菜单信息
@@ -224,23 +225,133 @@ public class SysMenuServiceImpl implements ISysMenuService {
@Override
public List<SysMenu> buildMenuTreeWithFullPath(List<SysMenu> menus) {
List<SysMenu> menuTree = buildMenuTree(menus);
// 为每个菜单项添加完整路径
addFullPathToMenuTree(menuTree);
// 一次性获取所有菜单信息避免N+1查询问题
List<SysMenu> allMenus = menuMapper.selectAllMenus();
Map<Long, SysMenu> menuMap = allMenus.stream()
.collect(Collectors.toMap(SysMenu::getMenuId, menu -> menu));
// 为每个菜单项添加完整路径优化版本避免N+1查询问题
addFullPathsToMenuTreeOptimized(menuTree, menuMap);
return menuTree;
}
/**
* 为菜单树添加完整路径
* 为菜单树添加完整路径(优化版本)
*
* @param menus 菜单树
* @param menuMap 菜单映射
*/
private void addFullPathToMenuTree(List<SysMenu> menus) {
private void addFullPathsToMenuTreeOptimized(List<SysMenu> menus, Map<Long, SysMenu> menuMap) {
for (SysMenu menu : menus) {
// 计算当前菜单的完整路径
menu.setFullPath(getMenuFullPath(menu.getMenuId()));
// 使用优化的路径计算方法
menu.setFullPath(computeMenuFullPathOptimized(menu, menuMap));
// 递归处理子菜单
if (menu.getChildren() != null && !menu.getChildren().isEmpty()) {
addFullPathToMenuTree(menu.getChildren());
addFullPathsToMenuTreeOptimized(menu.getChildren(), menuMap);
}
}
}
/**
* 优化的计算菜单完整路径方法
*
* @param menu 菜单
* @param menuMap 菜单映射
* @return 完整路径
*/
private String computeMenuFullPathOptimized(SysMenu menu, Map<Long, SysMenu> menuMap) {
if (menu == null || menu.getMenuId() == null) {
return "";
}
StringBuilder fullPath = new StringBuilder();
buildMenuPathOptimized(menu, fullPath, menuMap);
return normalizePath(fullPath.toString());
}
/**
* 优化的递归构建菜单路径
*
* @param menu 菜单信息
* @param path 路径构建器
* @param menuMap 菜单映射
*/
private void buildMenuPathOptimized(SysMenu menu, StringBuilder path, Map<Long, SysMenu> menuMap) {
if (menu == null || menu.getMenuId() == null) {
return;
}
// 如果不是根节点,则递归查找父节点
if (menu.getParentId() != null && menu.getParentId() > 0) {
SysMenu parentMenu = menuMap.get(menu.getParentId());
if (parentMenu != null) {
buildMenuPathOptimized(parentMenu, path, menuMap);
}
}
// 添加当前菜单的路径,避免双斜杠
String currentPath = normalizePathSegment(menu.getPath());
if (currentPath != null && !currentPath.isEmpty()) {
if (path.length() > 0) {
// 确保路径之间只有一个斜杠分隔符
if (path.charAt(path.length() - 1) != '/') {
path.append("/").append(currentPath);
} else {
path.append(currentPath);
}
} else {
// 对于第一个路径,直接追加
path.append(currentPath);
}
}
}
/**
* 递归收集菜单树中的所有菜单ID
*
* @param menus 菜单树
* @return 菜单ID列表
*/
private List<Long> collectMenuIds(List<SysMenu> menus) {
List<Long> menuIds = new ArrayList<>();
for (SysMenu menu : menus) {
menuIds.add(menu.getMenuId());
if (menu.getChildren() != null && !menu.getChildren().isEmpty()) {
menuIds.addAll(collectMenuIds(menu.getChildren()));
}
}
return menuIds;
}
/**
* 批量获取菜单完整路径
*
* @param menuIds 菜单ID列表
* @return 菜单ID到完整路径的映射
*/
private Map<Long, String> batchGetMenuFullPaths(List<Long> menuIds) {
Map<Long, String> fullPathMap = new HashMap<>();
for (Long menuId : menuIds) {
// 使用缓存的getMenuFullPath方法
fullPathMap.put(menuId, getMenuFullPath(menuId));
}
return fullPathMap;
}
/**
* 为菜单树设置完整路径
*
* @param menus 菜单树
* @param fullPathMap 完整路径映射
*/
private void setFullPathsToMenuTree(List<SysMenu> menus, Map<Long, String> fullPathMap) {
for (SysMenu menu : menus) {
// 设置当前菜单的完整路径
menu.setFullPath(fullPathMap.get(menu.getMenuId()));
// 递归处理子菜单
if (menu.getChildren() != null && !menu.getChildren().isEmpty()) {
setFullPathsToMenuTree(menu.getChildren(), fullPathMap);
}
}
}
@@ -299,6 +410,9 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return 结果
*/
@Override
@org.springframework.cache.annotation.Caching(evict = {
@org.springframework.cache.annotation.CacheEvict(value = "menu", allEntries = true)
})
public int insertMenu(SysMenu menu) {
//路径Path唯一性判断
SysMenu sysMenu = menuMapper.selectMenuByPath(menu.getPath());
@@ -315,13 +429,17 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return 结果
*/
@Override
@org.springframework.cache.annotation.Caching(evict = {
@org.springframework.cache.annotation.CacheEvict(value = "menu", allEntries = true),
@org.springframework.cache.annotation.CacheEvict(value = "menu", key = "'fullPath:' + #menu.menuId")
})
public int updateMenu(SysMenu menu) {
//路径Path唯一性判断排除当前菜单本身
String path = menu.getPath();
if (StringUtils.isNotBlank(path)) {
SysMenu sysMenu = menuMapper.selectMenuByPathExcludeId(menu.getPath(), menu.getMenuId());
if (sysMenu != null) {
log.warn("路由地址已存在 - menuId: {}, path: {}, 存在的menuId: {}",
log.warn("路由地址已存在 - menuId: {}, path: {}, 存在的menuId: {}",
menu.getMenuId(), menu.getPath(), sysMenu.getMenuId());
return -1; // 路由地址已存在
}
@@ -337,6 +455,10 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return 结果
*/
@Override
@org.springframework.cache.annotation.Caching(evict = {
@org.springframework.cache.annotation.CacheEvict(value = "menu", allEntries = true),
@org.springframework.cache.annotation.CacheEvict(value = "menu", key = "'fullPath:' + #menuId")
})
public int deleteMenuById(Long menuId) {
return menuMapper.deleteMenuById(menuId);
}
@@ -533,6 +655,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @return 完整路径
*/
@Override
@org.springframework.cache.annotation.Cacheable(value = "menu", key = "'fullPath:' + #menuId", unless = "#result == null || #result.isEmpty()")
public String getMenuFullPath(Long menuId) {
SysMenu menu = menuMapper.selectMenuById(menuId);
if (menu == null) {

View File

@@ -274,4 +274,27 @@
where menu_id = #{menuId}
</delete>
<select id="selectAllMenus" resultMap="SysMenuResult">
select menu_id,
parent_id,
menu_name,
path,
component,
"query",
route_name,
is_frame,
is_cache,
menu_type,
visible,
status,
perms,
icon,
order_num,
create_time,
update_time,
remark
from sys_menu
order by parent_id, order_num
</select>
</mapper>

View File

@@ -7,6 +7,8 @@ public interface IDoctorScheduleAppService {
R<?> getDoctorScheduleList();
R<?> getTodayDoctorScheduleList();
R<?> addDoctorSchedule(DoctorSchedule doctorSchedule);
R<?> removeDoctorSchedule(Integer doctorScheduleId);

View File

@@ -1,6 +1,7 @@
package com.openhis.web.appointmentmanage.appservice.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.core.common.core.domain.R;
import com.openhis.appointmentmanage.domain.DoctorSchedule;
import com.openhis.appointmentmanage.mapper.DoctorScheduleMapper;
@@ -9,6 +10,8 @@ import com.openhis.web.appointmentmanage.appservice.IDoctorScheduleAppService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;
@Service
@@ -26,6 +29,50 @@ public class DoctorScheduleAppServiceImpl implements IDoctorScheduleAppService {
return R.ok(list);
}
@Override
public R<?> getTodayDoctorScheduleList() {
// 获取今天的日期
LocalDate today = LocalDate.now();
DayOfWeek dayOfWeek = today.getDayOfWeek();
// 将 Java 的 DayOfWeek 转换为字符串表示
String weekdayStr = convertDayOfWeekToString(dayOfWeek);
// 查询今天排班的医生
LambdaQueryWrapper<DoctorSchedule> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DoctorSchedule::getWeekday, weekdayStr) // 根据星期几查询
.eq(DoctorSchedule::getIsStopped, false); // 只查询未停止的排班
List<DoctorSchedule> list = doctorScheduleService.list(queryWrapper);
return R.ok(list);
}
/**
* 将 DayOfWeek 转换为字符串表示
* @param dayOfWeek DayOfWeek枚举
* @return 对应的字符串表示
*/
private String convertDayOfWeekToString(DayOfWeek dayOfWeek) {
switch (dayOfWeek) {
case MONDAY:
return "1"; // 或者 "星期一" 或 "Monday",取决于数据库中的实际存储格式
case TUESDAY:
return "2";
case WEDNESDAY:
return "3";
case THURSDAY:
return "4";
case FRIDAY:
return "5";
case SATURDAY:
return "6";
case SUNDAY:
return "7";
default:
return "1"; // 默认为星期一
}
}
@Override
public R<?> addDoctorSchedule(DoctorSchedule doctorSchedule) {
if (ObjectUtil.isEmpty(doctorSchedule)) {

View File

@@ -40,4 +40,13 @@ public class DoctorScheduleController {
return R.ok(doctorScheduleAppService.removeDoctorSchedule(doctorScheduleId));
}
/*
* 获取今日医生排班List
*
* */
@GetMapping("/today")
public R<?> getTodayDoctorScheduleList() {
return R.ok(doctorScheduleAppService.getTodayDoctorScheduleList());
}
}

View File

@@ -0,0 +1,88 @@
package com.openhis.web.medicationmanagement.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.core.page.TableDataInfo;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.openhis.domain.DayEndSettlement;
import com.openhis.service.IDayEndSettlementService;
import com.core.common.core.page.PageDomain;
import com.core.common.utils.StringUtils;
import com.github.pagehelper.PageHelper;
/**
* 日结结算单Controller
*
* @author openhis
* @date 2025-02-01
*/
@RestController
@RequestMapping("/medication/dayEndSettlement")
public class DayEndSettlementController extends BaseController {
@Autowired
private IDayEndSettlementService dayEndSettlementService;
/**
* 查询日结结算单列表
*/
@GetMapping("/list")
public TableDataInfo list(DayEndSettlement dayEndSettlement, PageDomain pageDomain) {
// 使用PageHelper进行分页
PageHelper.startPage(pageDomain.getPageNum(), pageDomain.getPageSize());
List<DayEndSettlement> list = dayEndSettlementService.lambdaQuery()
.like(StringUtils.isNotBlank(dayEndSettlement.getSettlementNo()), DayEndSettlement::getSettlementNo, dayEndSettlement.getSettlementNo())
.eq(StringUtils.isNotBlank(dayEndSettlement.getSettlementType()), DayEndSettlement::getSettlementType, dayEndSettlement.getSettlementType())
.eq(dayEndSettlement.getSettlementDate() != null, DayEndSettlement::getSettlementDate, dayEndSettlement.getSettlementDate())
.orderByDesc(DayEndSettlement::getId)
.list();
return getDataTable(list);
}
/**
* 获取日结结算单详细信息
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(dayEndSettlementService.getById(id));
}
/**
* 新增日结结算单
*/
@Log(title = "日结结算单", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody DayEndSettlement dayEndSettlement) {
return toAjax(dayEndSettlementService.save(dayEndSettlement));
}
/**
* 修改日结结算单
*/
@Log(title = "日结结算单", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody DayEndSettlement dayEndSettlement) {
return toAjax(dayEndSettlementService.updateById(dayEndSettlement));
}
/**
* 删除日结结算单
*/
@Log(title = "日结结算单", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(dayEndSettlementService.removeByIds(List.of(ids)));
}
}

View File

@@ -0,0 +1,60 @@
package com.openhis.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.core.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* 日结结算单对象 medication_day_end_settlement
*
* @author openhis
* @date 2025-02-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("medication_day_end_settlement")
public class DayEndSettlement extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 结算单号
*/
private String settlementNo;
/**
* 结算日期
*/
private LocalDate settlementDate;
/**
* 结算类型 (daily, weekly, monthly)
*/
private String settlementType;
/**
* 总金额
*/
private BigDecimal totalAmount;
/**
* 状态 (0正常 1停用)
*/
private String status;
/**
* 备注
*/
private String remark;
}

View File

@@ -0,0 +1,14 @@
package com.openhis.mapper;
import com.openhis.domain.DayEndSettlement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* 日结结算单Mapper接口
*
* @author openhis
* @date 2025-02-01
*/
public interface DayEndSettlementMapper extends BaseMapper<DayEndSettlement> {
}

View File

@@ -0,0 +1,14 @@
package com.openhis.service;
import com.openhis.domain.DayEndSettlement;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* 日结结算单Service接口
*
* @author openhis
* @date 2025-02-01
*/
public interface IDayEndSettlementService extends IService<DayEndSettlement> {
}

View File

@@ -0,0 +1,18 @@
package com.openhis.service.impl;
import com.openhis.domain.DayEndSettlement;
import com.openhis.mapper.DayEndSettlementMapper;
import com.openhis.service.IDayEndSettlementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* 日结结算单Service业务层处理
*
* @author openhis
* @date 2025-02-01
*/
@Service
public class DayEndSettlementServiceImpl extends ServiceImpl<DayEndSettlementMapper, DayEndSettlement> implements IDayEndSettlementService {
}

View File

@@ -0,0 +1,52 @@
-- 创建日结结算单表
CREATE TABLE IF NOT EXISTS medication_day_end_settlement (
id BIGSERIAL PRIMARY KEY,
settlement_no VARCHAR(64) NOT NULL,
settlement_date DATE NOT NULL,
settlement_type VARCHAR(20) DEFAULT 'daily',
total_amount DECIMAL(15,2) DEFAULT 0.00,
status CHAR(1) DEFAULT '0',
remark VARCHAR(500),
create_by VARCHAR(64) DEFAULT '',
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_by VARCHAR(64) DEFAULT '',
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 添加注释
COMMENT ON TABLE medication_day_end_settlement IS '日结结算单表';
COMMENT ON COLUMN medication_day_end_settlement.settlement_no IS '结算单号';
COMMENT ON COLUMN medication_day_end_settlement.settlement_date IS '结算日期';
COMMENT ON COLUMN medication_day_end_settlement.settlement_type IS '结算类型 (daily, weekly, monthly)';
COMMENT ON COLUMN medication_day_end_settlement.total_amount IS '总金额';
COMMENT ON COLUMN medication_day_end_settlement.status IS '状态 (0正常 1停用)';
COMMENT ON COLUMN medication_day_end_settlement.remark IS '备注';
COMMENT ON COLUMN medication_day_end_settlement.create_by IS '创建者';
COMMENT ON COLUMN medication_day_end_settlement.create_time IS '创建时间';
COMMENT ON COLUMN medication_day_end_settlement.update_by IS '更新者';
COMMENT ON COLUMN medication_day_end_settlement.update_time IS '更新时间';
-- 添加索引
CREATE INDEX IF NOT EXISTS idx_settlement_date ON medication_day_end_settlement(settlement_date);
CREATE INDEX IF NOT EXISTS idx_settlement_no ON medication_day_end_settlement(settlement_no);
-- 创建更新时间触发器函数
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.update_time = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ language 'plpgsql';
-- 创建更新时间触发器
DROP TRIGGER IF EXISTS update_medication_day_end_settlement_modtime ON medication_day_end_settlement;
CREATE TRIGGER update_medication_day_end_settlement_modtime
BEFORE UPDATE ON medication_day_end_settlement
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();
-- 插入初始数据
INSERT INTO medication_day_end_settlement (settlement_no, settlement_date, settlement_type, total_amount, status, remark, create_by) VALUES
('DS20250201001', '2025-02-01', 'daily', 15000.00, '0', '2025年2月1日日结', 'admin'),
('DS20250201002', '2025-02-01', 'daily', 8500.50, '0', '药房日结', 'admin');

View File

@@ -0,0 +1,38 @@
CREATE TABLE IF NOT EXISTS sys_user_config (
config_id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
config_key VARCHAR(100) NOT NULL,
config_value TEXT,
remark VARCHAR(500),
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 添加注释
COMMENT ON TABLE sys_user_config IS '用户配置表';
COMMENT ON COLUMN sys_user_config.config_id IS '配置ID';
COMMENT ON COLUMN sys_user_config.user_id IS '用户ID';
COMMENT ON COLUMN sys_user_config.config_key IS '配置键名';
COMMENT ON COLUMN sys_user_config.config_value IS '配置值';
COMMENT ON COLUMN sys_user_config.remark IS '备注';
COMMENT ON COLUMN sys_user_config.create_time IS '创建时间';
COMMENT ON COLUMN sys_user_config.update_time IS '更新时间';
-- 创建唯一索引
CREATE UNIQUE INDEX IF NOT EXISTS uk_user_config ON sys_user_config (user_id, config_key);
CREATE INDEX IF NOT EXISTS idx_user_id ON sys_user_config (user_id);
-- 创建更新时间触发器函数
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.update_time = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ language 'plpgsql';
-- 创建触发器
CREATE TRIGGER update_sys_user_config_updated_at
BEFORE UPDATE ON sys_user_config
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();