Location的tree
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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[] {"位置信息"}));
|
||||
|
||||
@@ -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<>();
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import lombok.experimental.Accessors;
|
||||
public class OrganizationQueryDto {
|
||||
|
||||
/** ID */
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user