格式化
This commit is contained in:
@@ -1,24 +1,21 @@
|
|||||||
package com.openhis.common.utils;
|
package com.openhis.common.utils;
|
||||||
|
|
||||||
import com.openhis.common.enums.HisEnumInterface;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.openhis.common.enums.HisEnumInterface;
|
||||||
|
|
||||||
public class EnumUtils {
|
public class EnumUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 value 获取枚举的 info
|
* 根据 value 获取枚举的 info
|
||||||
*
|
*
|
||||||
* @param enumClass 枚举类
|
* @param enumClass 枚举类
|
||||||
* @param value 枚举的 value
|
* @param value 枚举的 value
|
||||||
* @param <E> 枚举类型
|
* @param <E> 枚举类型
|
||||||
* @return 对应的 info,如果未找到则返回 null
|
* @return 对应的 info,如果未找到则返回 null
|
||||||
*/
|
*/
|
||||||
public static <E extends Enum<E> & HisEnumInterface> String getInfoByValue(Class<E> enumClass, Integer value) {
|
public static <E extends Enum<E> & HisEnumInterface> String getInfoByValue(Class<E> enumClass, Integer value) {
|
||||||
return Arrays.stream(enumClass.getEnumConstants())
|
return Arrays.stream(enumClass.getEnumConstants()).filter(e -> e.getValue().equals(value)).findFirst()
|
||||||
.filter(e -> e.getValue().equals(value))
|
.map(HisEnumInterface::getInfo).orElse(null);
|
||||||
.findFirst()
|
|
||||||
.map(HisEnumInterface::getInfo)
|
|
||||||
.orElse(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,30 @@
|
|||||||
package com.openhis.common.utils;
|
package com.openhis.common.utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class HisPageUtils {
|
public class HisPageUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行分页查询并转换为目标类型
|
* 执行分页查询并转换为目标类型
|
||||||
*
|
*
|
||||||
* @param mapper MyBatis Plus Mapper 接口
|
* @param mapper MyBatis Plus Mapper 接口
|
||||||
* @param queryWrapper 查询条件
|
* @param queryWrapper 查询条件
|
||||||
* @param pageNo 当前页
|
* @param pageNo 当前页
|
||||||
* @param pageSize 每页大小
|
* @param pageSize 每页大小
|
||||||
* @param targetClass 目标类(如 MedicationDto.class)
|
* @param targetClass 目标类(如 MedicationDto.class)
|
||||||
* @param <T> 源对象类型(数据库实体类)
|
* @param <T> 源对象类型(数据库实体类)
|
||||||
* @param <R> 目标对象类型(DTO 类)
|
* @param <R> 目标对象类型(DTO 类)
|
||||||
* @return 分页结果(目标类型)
|
* @return 分页结果(目标类型)
|
||||||
*/
|
*/
|
||||||
public static <T, R> Page<R> selectPage(BaseMapper<T> mapper, QueryWrapper<T> queryWrapper,
|
public static <T, R> Page<R> selectPage(BaseMapper<T> mapper, QueryWrapper<T> queryWrapper, int pageNo,
|
||||||
int pageNo, int pageSize, Class<R> targetClass) {
|
int pageSize, Class<R> targetClass) {
|
||||||
// 构建分页对象
|
// 构建分页对象
|
||||||
Page<T> page = new Page<>(pageNo, pageSize);
|
Page<T> page = new Page<>(pageNo, pageSize);
|
||||||
// 执行分页查询
|
// 执行分页查询
|
||||||
@@ -40,25 +41,23 @@ public class HisPageUtils {
|
|||||||
/**
|
/**
|
||||||
* 将源对象列表转换为目标对象列表
|
* 将源对象列表转换为目标对象列表
|
||||||
*
|
*
|
||||||
* @param sourceList 源对象列表
|
* @param sourceList 源对象列表
|
||||||
* @param targetClass 目标类
|
* @param targetClass 目标类
|
||||||
* @param <T> 源对象类型
|
* @param <T> 源对象类型
|
||||||
* @param <R> 目标对象类型
|
* @param <R> 目标对象类型
|
||||||
* @return 目标对象列表
|
* @return 目标对象列表
|
||||||
*/
|
*/
|
||||||
private static <T, R> List<R> convertToDtoList(List<T> sourceList, Class<R> targetClass) {
|
private static <T, R> List<R> convertToDtoList(List<T> sourceList, Class<R> targetClass) {
|
||||||
return sourceList.stream()
|
return sourceList.stream().map(source -> convertToDto(source, targetClass)).collect(Collectors.toList());
|
||||||
.map(source -> convertToDto(source, targetClass))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将源对象转换为目标对象
|
* 将源对象转换为目标对象
|
||||||
*
|
*
|
||||||
* @param source 源对象
|
* @param source 源对象
|
||||||
* @param targetClass 目标类
|
* @param targetClass 目标类
|
||||||
* @param <T> 源对象类型
|
* @param <T> 源对象类型
|
||||||
* @param <R> 目标对象类型
|
* @param <R> 目标对象类型
|
||||||
* @return 目标对象
|
* @return 目标对象
|
||||||
*/
|
*/
|
||||||
private static <T, R> R convertToDto(T source, Class<R> targetClass) {
|
private static <T, R> R convertToDto(T source, Class<R> targetClass) {
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ public class HisQueryUtils {
|
|||||||
/**
|
/**
|
||||||
* 条件查询构造器
|
* 条件查询构造器
|
||||||
*
|
*
|
||||||
* @param entity 传参实体
|
* @param entity 传参实体
|
||||||
* @param searchKey 模糊查询关键字
|
* @param searchKey 模糊查询关键字
|
||||||
* @param searchFields 支持模糊查询的字段集合 ; 不需要模糊查询传 null 即可
|
* @param searchFields 支持模糊查询的字段集合 ; 不需要模糊查询传 null 即可
|
||||||
* @param request 请求
|
* @param request 请求
|
||||||
* @return 构造条件
|
* @return 构造条件
|
||||||
*/
|
*/
|
||||||
public static <T> QueryWrapper<T> buildQueryWrapper(Object entity, String searchKey, HashSet<String> searchFields,
|
public static <T> QueryWrapper<T> buildQueryWrapper(Object entity, String searchKey, HashSet<String> searchFields,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||||
// 添加租户id查询条件
|
// 添加租户id查询条件
|
||||||
queryWrapper.eq(CommonConstants.Common.TENANT_ID, getCurrentTenantId());
|
queryWrapper.eq(CommonConstants.Common.TENANT_ID, getCurrentTenantId());
|
||||||
@@ -51,7 +51,7 @@ public class HisQueryUtils {
|
|||||||
String paramName = entry.getKey();
|
String paramName = entry.getKey();
|
||||||
// 检查参数名是否以 "STime" 或 "ETime" 结尾
|
// 检查参数名是否以 "STime" 或 "ETime" 结尾
|
||||||
if (paramName.endsWith(CommonConstants.Common.S_TIME)
|
if (paramName.endsWith(CommonConstants.Common.S_TIME)
|
||||||
|| paramName.endsWith(CommonConstants.Common.E_TIME)) {
|
|| paramName.endsWith(CommonConstants.Common.E_TIME)) {
|
||||||
// 提取字段名(去掉 "STime" 或 "ETime" 后缀)
|
// 提取字段名(去掉 "STime" 或 "ETime" 后缀)
|
||||||
String fieldName = paramName.substring(0, paramName.length() - 5);
|
String fieldName = paramName.substring(0, paramName.length() - 5);
|
||||||
// 驼峰转下划线
|
// 驼峰转下划线
|
||||||
|
|||||||
Reference in New Issue
Block a user