Location的tree

This commit is contained in:
anxin
2025-03-06 10:58:43 +08:00
parent c6b93680b3
commit 57d1f08fb3
9 changed files with 187 additions and 122 deletions

View File

@@ -0,0 +1,13 @@
package com.openhis.web.basedatamanage.appservice;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.openhis.web.basedatamanage.dto.LocationQueryDto;
/**
* Location 应该服务类
*/
public interface ILocationAppService {
// 查询位置树
Page<LocationQueryDto> getLocationTree(Integer formKey, Integer pageNo, Integer pageSize);
}

View File

@@ -0,0 +1,92 @@
package com.openhis.web.basedatamanage.appservice.impl;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.openhis.administration.domain.Location;
import com.openhis.administration.service.ILocationService;
import com.openhis.common.enums.LocationForm;
import com.openhis.common.utils.EnumUtils;
import com.openhis.web.basedatamanage.appservice.ILocationAppService;
import com.openhis.web.basedatamanage.dto.LocationQueryDto;
@Service
public class ILocationAppServiceImpl implements ILocationAppService {
@Resource
ILocationService locationService;
@Override
public Page<LocationQueryDto> getLocationTree(Integer formKey, Integer pageNo, Integer pageSize) {
QueryWrapper<Location> queryWrapper = new QueryWrapper<>();
if (formKey != null) {
queryWrapper.eq("form_enum", formKey);
}
// 查询位置列表
Page<Location> page = locationService.page(new Page<>(pageNo, pageSize), queryWrapper);
List<Location> locationList = page.getRecords();
// 将位置列表转为树结构
List<LocationQueryDto> locationTree = buildTree(locationList);
Page<LocationQueryDto> locationQueryDtoPage = new Page<>(pageNo, pageSize, page.getTotal());
locationQueryDtoPage.setRecords(locationTree);
locationQueryDtoPage.getRecords().forEach(e -> {
// 物理形式枚举回显赋值
e.setFormEnum_enumText(EnumUtils.getInfoByValue(LocationForm.class, e.getFormEnum()));
});
return locationQueryDtoPage;
}
/**
* 将位置列表转换为树结构
*
* @param records 位置列表
* @return tree
*/
private List<LocationQueryDto> buildTree(List<Location> records) {
// 按b_no的层级排序确保父节点先处理
List<Location> sortedRecords = records.stream()
.sorted(Comparator.comparingInt(r -> r.getBusNo().split("\\.").length)).collect(Collectors.toList());
Map<String, LocationQueryDto> nodeMap = new HashMap<>();
List<LocationQueryDto> tree = new ArrayList<>();
for (Location record : sortedRecords) {
String bNo = record.getBusNo();
String[] parts = bNo.split("\\.");
LocationQueryDto node = new LocationQueryDto();
BeanUtils.copyProperties(record, node);
// 将当前节点加入映射
nodeMap.put(bNo, node);
if (parts.length == 1) {
// 根节点
tree.add(node);
} else {
// 获取父节点的b_no去掉最后一部分
String parentBNo = String.join(".", Arrays.copyOf(parts, parts.length - 1));
LocationQueryDto parent = nodeMap.get(parentBNo);
if (parent != null) {
parent.getChildren().add(node);
} else {
// 处理父节点不存在的情况(例如数据缺失)
// 可根据需求调整为将节点加入根或抛出异常
tree.add(node);
}
}
}
return tree;
}
}

View File

@@ -3,29 +3,23 @@
*/
package com.openhis.web.basedatamanage.controller;
import java.util.Arrays;
import java.util.HashSet;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.common.core.domain.R;
import com.core.common.utils.MessageUtils;
import com.core.common.utils.bean.BeanUtils;
import com.openhis.administration.domain.Location;
import com.openhis.administration.mapper.LocationMapper;
import com.openhis.administration.service.ILocationService;
import com.openhis.common.constant.PromptMsgConstant;
import com.openhis.common.enums.LocationBedStatus;
import com.openhis.common.enums.LocationForm;
import com.openhis.common.utils.HisPageUtils;
import com.openhis.common.utils.HisQueryUtils;
import com.openhis.common.enums.LocationMode;
import com.openhis.common.enums.LocationStatus;
import com.openhis.web.basedatamanage.appservice.ILocationAppService;
import com.openhis.web.basedatamanage.dto.LocationQueryDto;
import com.openhis.web.basedatamanage.dto.LocationQueryParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -43,6 +37,7 @@ import lombok.extern.slf4j.Slf4j;
public class CabinetLocationController {
private final ILocationService locationService;
private final ILocationAppService iLocationAppService;
@Autowired
private LocationMapper locationMapper;
@@ -50,32 +45,18 @@ public class CabinetLocationController {
/**
* 位置分页列表
*
* @param locationQueryParam 查询字段
* @param searchKey 模糊查询关键字
* @param pageNo 当前页码
* @param pageSize 查询条数
* @param request 请求数据
* @return 位置分页列表
*/
@GetMapping(value = "/cabinet-location")
public R<?> getLocationPage(LocationQueryParam locationQueryParam,
@RequestParam(value = "searchKey", defaultValue = "") String searchKey,
public R<?> getLocationPage(@RequestParam(required = false, value = "formKey", defaultValue = "") Integer formKey,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
// 构建查询条件
QueryWrapper<Location> queryWrapper = HisQueryUtils.buildQueryWrapper(locationQueryParam, searchKey,
new HashSet<>(Arrays.asList("name", "py_str", "wb_str")), request);
Page<LocationQueryDto> locationTree = iLocationAppService.getLocationTree(formKey, pageNo, pageSize);
return R.ok(locationTree, MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"机构信息"}));
// 设置排序
queryWrapper.orderByDesc("create_time");
// 执行分页查询并转换为 locationQueryDtoPage
Page<LocationQueryDto> locationQueryDtoPage =
HisPageUtils.selectPage(locationMapper, queryWrapper, pageNo, pageSize, LocationQueryDto.class);
return R.ok(locationQueryDtoPage,
MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"位置信息"}));
}
/**
@@ -88,12 +69,15 @@ public class CabinetLocationController {
// 设置为库房
// LocationQueryDto locationQuery = new LocationQueryDto(LocationForm.CABINET);
Location location = new Location();
locationQueryDto.setFormEnum(LocationForm.CABINET);
BeanUtils.copyProperties(locationQueryDto, location);
// locationQueryDto.setFormEnum(LocationForm.CABINET);
// BeanUtils.copyProperties(locationQueryDto, location);
Location location = new Location(locationQueryDto.getId(), locationQueryDto.getBusNo(),
locationQueryDto.getName(), LocationStatus.ACTIVE, LocationBedStatus.U, LocationMode.INSTANCE,
locationQueryDto.getTypeCode(), locationQueryDto.getTypeJson(), locationQueryDto.getPyStr(),
locationQueryDto.getWbStr(), LocationForm.CABINET.getValue(), locationQueryDto.getOrganizationId(),
locationQueryDto.getDisplayOrder());
boolean saveLocationSuccess = locationService.save(location);
return saveLocationSuccess
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00001, new Object[] {"位置信息"}))
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00003, new Object[] {"位置信息"}));
@@ -114,13 +98,18 @@ public class CabinetLocationController {
/**
* 编辑库房位置信息
*
* @param location 库房位置信息
* @param locationQueryDto 库房位置信息
*/
@PutMapping("/cabinet-location")
public R<?> editLocation(@Validated @RequestBody Location location) {
public R<?> editLocation(@Validated @RequestBody LocationQueryDto locationQueryDto) {
Location location = new Location(locationQueryDto.getId(), locationQueryDto.getBusNo(),
locationQueryDto.getName(), LocationStatus.ACTIVE, LocationBedStatus.U, LocationMode.INSTANCE,
locationQueryDto.getTypeCode(), locationQueryDto.getTypeJson(), locationQueryDto.getPyStr(),
locationQueryDto.getWbStr(), LocationForm.CABINET.getValue(), locationQueryDto.getOrganizationId(),
locationQueryDto.getDisplayOrder());
boolean updateLocationSuccess = locationService.updateById(location);
return updateLocationSuccess
? R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"位置信息"}))
: R.fail(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00007, new Object[] {"位置信息"}));

View File

@@ -3,10 +3,15 @@
*/
package com.openhis.web.basedatamanage.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.openhis.common.enums.LocationBedStatus;
import com.openhis.common.enums.LocationForm;
import com.openhis.common.enums.LocationMode;
import com.openhis.common.enums.LocationStatus;
@@ -20,30 +25,35 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class LocationQueryDto {
/** ID */
@TableId(type = IdType.ASSIGN_ID)
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
/** 编码 */
@NotBlank(message = "位置编码不能为空")
private String busNo;
/** 名称 */
@NotBlank(message = "位置名称不能为空")
private String name;
/** 状态编码 */
@NotNull(message = "状态编码不能为空")
private LocationStatus statusEnum;
/** 操作状态 */
@NotNull(message = "操作状态不能为空")
private LocationBedStatus operationalEnum;
/** 模式编码 */
@NotNull(message = "模式编码不能为空")
private LocationMode modeEnum;
/** 模式编码 */
private String typeCode;
/** 功能编码 */
@NotBlank(message = "功能编码不能为空")
private String typeJson;
/** 拼音码 */
@@ -53,18 +63,20 @@ public class LocationQueryDto {
private String wbStr;
/** 物理形式枚举 */
private LocationForm formEnum;
@NotNull(message = "物理形式枚举不能为空")
// private LocationForm formEnum;
private Integer formEnum;
private String formEnum_enumText;
/** 机构编码 */
@NotNull(message = "机构编码不能为空")
@JsonSerialize(using = ToStringSerializer.class)
private Long organizationId;
/** 显示顺序 */
private Integer displayOrder;
// public LocationQueryDto(LocationForm form, String busNo, LocationMode mode) {
// public LocationQueryDto(LocationForm form) {
// this.statusEnum = LocationStatus.ACTIVE;
// this.formEnum = form;
// this.modeEnum = mode;
// }
/** 子集合 */
private List<LocationQueryDto> children = new ArrayList<>();
}

View File

@@ -1,25 +0,0 @@
/*
* Copyright ©2023 CJB-CNIT Team. All rights reserved
*/
package com.openhis.web.basedatamanage.dto;
import java.io.Serializable;
import com.openhis.common.enums.LocationMode;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 科室分页查询条件
*
* @author
* @date 2025-02-21
*/
@Data
@Accessors(chain = true)
public class LocationQueryParam implements Serializable {
/** 模式编码 */
private LocationMode modeEnum;
}

View File

@@ -1,33 +0,0 @@
/*
* Copyright ©2023 CJB-CNIT Team. All rights reserved
*/
package com.openhis.web.basedatamanage.dto;
import java.io.Serializable;
import com.openhis.common.enums.OrganizationClass;
import com.openhis.common.enums.OrganizationType;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 科室分页查询条件
*
* @author
* @date 2025-02-21
*/
@Data
@Accessors(chain = true)
public class OrgQueryParam implements Serializable {
/** 活动标识 */
private Integer activeFlag;
/** 机构类型枚举 */
private OrganizationType typeEnum;
/** 机构分类枚举 */
private OrganizationClass classEnum;
}

View File

@@ -25,7 +25,6 @@ import lombok.experimental.Accessors;
public class OrganizationQueryDto {
/** ID */
@TableId(type = IdType.ASSIGN_ID)
@JsonSerialize(using = ToStringSerializer.class)
private Long id;

View File

@@ -1,35 +1,39 @@
package com.openhis.common.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum LocationForm {
public enum LocationForm implements HisEnumInterface {
SITE(1, "si", "集合点A collection of buildings or other locations such as a site or a campus."),
BUILDING(2, "bu", "建筑Any Building or structure. This may contain rooms, corridors, wings, etc. It might not have walls, or a roof, but is considered a defined/allocated space."),
BUILDING(2, "bu",
"建筑Any Building or structure. This may contain rooms, corridors, wings, etc. It might not have walls, or a roof, but is considered a defined/allocated space."),
WING(3, "wi", "连廊A Wing within a Building, this often contains levels, rooms and corridors."),
WARD(4, "wa", "病区A Ward is a section of a medical facility that may contain rooms and other types of location."),
LEVEL(5, "lvl", "楼层A Level in a multi-level Building/Structure."),
CORRIDOR(6, "co", "走廊Any corridor within a Building, that may connect rooms."),
ROOM(7, "ro", "诊室A space that is allocated as a room, it may have walls/roof etc., but does not require these."),
BED(8, "bd", "床A space that is allocated for sleeping/laying on. This is not the physical bed/trolley that may be moved about, but the space it may occupy."),
BED(8, "bd",
"床A space that is allocated for sleeping/laying on. This is not the physical bed/trolley that may be moved about, but the space it may occupy."),
VEHICLE(9, "ve", "运输工具A means of transportation."),
HOUSE(10, "ho", "病房A residential dwelling. Usually used to reference a location that a person/patient may reside."),
CABINET(11, "ca", "库房A container that can store goods, equipment, medications or other items."),
ROAD(12, "rd", "路A defined path to travel between 2 points that has a known name."),
AREA(13, "area", "区域A defined physical boundary of something, such as a flood risk zone, region, postcode"),
JURISDICTION(14, "jdn", "适用范围A wide scope that covers a conceptual domain, such as a Nation (Country wide community or Federal Government - e.g. Ministry of Health), Province or State (community or Government), Business (throughout the enterprise), Nation with a business scope of an agency (e.g. CDC, FDA etc.) or a Business segment (UK Pharmacy), not just an physical boundary"),
JURISDICTION(14, "jdn",
"适用范围A wide scope that covers a conceptual domain, such as a Nation (Country wide community or Federal Government - e.g. Ministry of Health), Province or State (community or Government), Business (throughout the enterprise), Nation with a business scope of an agency (e.g. CDC, FDA etc.) or a Business segment (UK Pharmacy), not just an physical boundary"),
VIRTUAL(15, "vi", "虚拟A location that is virtual in nature, such as a conference call or virtual meeting space");
// PHARMACY(16, "ph", "药房"),
// PHARMACY_WINDOW(17, "phw", "发药窗口"),
// PHARMACY_TABLE(18, "dt", "摆药台"),
// NURSE_STATION(19, "ns", "护士站"),
// PERSON_STORE(20, "ps", "个人储物柜"),
// DOCTOR_TABLE(21, "dt", "医生诊台");
// PHARMACY(16, "ph", "药房"),
// PHARMACY_WINDOW(17, "phw", "发药窗口"),
// PHARMACY_TABLE(18, "dt", "摆药台"),
// NURSE_STATION(19, "ns", "护士站"),
// PERSON_STORE(20, "ps", "个人储物柜"),
// DOCTOR_TABLE(21, "dt", "医生诊台");
@EnumValue
private final Integer value;
private final String code;

View File

@@ -1,17 +1,13 @@
package com.openhis.administration.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.core.common.core.domain.HisBaseEntity;
import com.openhis.common.enums.LocationBedStatus;
import com.openhis.common.enums.LocationForm;
import com.openhis.common.enums.LocationMode;
import com.openhis.common.enums.LocationStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@@ -60,7 +56,8 @@ public class Location extends HisBaseEntity {
private String wbStr;
/** 物理形式枚举 */
private LocationForm formEnum;
// private LocationForm formEnum;
private Integer formEnum;
/** 机构编码 */
private Long organizationId;
@@ -68,5 +65,22 @@ public class Location extends HisBaseEntity {
/** 显示顺序 */
private Integer displayOrder;
public Location(Long id, String busNo, String name, LocationStatus statusEnum, LocationBedStatus operationalEnum,
LocationMode modeEnum, String typeCode, String typeJson, String pyStr, String wbStr, Integer formEnum,
Long organizationId, Integer displayOrder) {
this.id = id;
this.busNo = busNo;
this.name = name;
this.statusEnum = statusEnum;
this.operationalEnum = operationalEnum;
this.modeEnum = modeEnum;
this.typeCode = typeCode;
this.typeJson = typeJson;
this.pyStr = pyStr;
this.wbStr = wbStr;
this.formEnum = formEnum;
this.organizationId = organizationId;
this.displayOrder = displayOrder;
}
}