Commit 940f6df3 by zhangxingmin

Merge remote-tracking branch 'origin/dev_zxm' into test

# Conflicts:
#	yd-common/src/main/java/com/yd/common/enums/CommonEnum.java
parents 033cdc4c cc6dc680
...@@ -39,4 +39,14 @@ public class ServerNameConstants { ...@@ -39,4 +39,14 @@ public class ServerNameConstants {
* yd-csf-api 香港保险服务接口模块服务名称 * yd-csf-api 香港保险服务接口模块服务名称
*/ */
public static String ydCsfApi="yd-csf-api"; public static String ydCsfApi="yd-csf-api";
/**
* yd-question-api 问题基础微服务
*/
public static String ydQuestionApi="yd-question-api";
/**
* yd-email-api 邮件微服务
*/
public static String ydEmailApi="yd-email-api";
} }
...@@ -30,6 +30,10 @@ public enum CommonEnum { ...@@ -30,6 +30,10 @@ public enum CommonEnum {
UID_TYPE_POLICY("policy","CSF保单表"), UID_TYPE_POLICY("policy","CSF保单表"),
UID_TYPE_COMMISSION("commission","CSF来佣表"), UID_TYPE_COMMISSION("commission","CSF来佣表"),
UID_TYPE_FORTUNE("fortune","CSF发佣表"), UID_TYPE_FORTUNE("fortune","CSF发佣表"),
UID_TYPE_EMAIL_SENDER_CONFIG("email_sender_config","邮箱发件人配置表"),
UID_TYPE_EMAIL_CONTACT("email_contact","邮箱联系人(收件人)表"),
UID_TYPE_EMAIL_PROVIDER_CONFIG("email_provider_config","SMTP邮箱服务商配置表"),
UID_TYPE_EMAIL_VARIABLE("email_variable","邮箱变量表"),
//作用域枚举 //作用域枚举
SCOPE_SYS("1","系统级(全局)"), SCOPE_SYS("1","系统级(全局)"),
......
package com.yd.common.enums;
import java.util.Arrays;
/**
* 是否枚举
*/
public enum NoYesEnum {
//是否枚举
NO("否","0"),
YES("是","1"),
;
//字典项标签(名称)
private String itemLabel;
//字典项值
private String itemValue;
//构造函数
NoYesEnum(String itemLabel, String itemValue) {
this.itemLabel = itemLabel;
this.itemValue = itemValue;
}
public String getItemLabel() {
return itemLabel;
}
public String getItemValue() {
return itemValue;
}
/**
* 根据itemValue获取对应的itemLabel
* @param itemValue 字典值
* @return 对应的字典标签,如果未找到则返回空字符串
*/
public static String getLabelByValue(String itemValue) {
return Arrays.stream(values())
.filter(noYesEnum -> noYesEnum.itemValue.equals(itemValue))
.findFirst()
.map(NoYesEnum::getItemLabel)
.orElse("");
}
}
...@@ -19,6 +19,7 @@ public enum ResultCode { ...@@ -19,6 +19,7 @@ public enum ResultCode {
PRODUCT_NAME_EXISTS(207,"保险产品名称已存在","") , PRODUCT_NAME_EXISTS(207,"保险产品名称已存在","") ,
PLAN_NAME_EXISTS(208,"保险产品计划名称已存在","") , PLAN_NAME_EXISTS(208,"保险产品计划名称已存在","") ,
ADDITIONAL_PRODUCT_NAME_EXISTS(209,"保险附加产品名称已存在","") , ADDITIONAL_PRODUCT_NAME_EXISTS(209,"保险附加产品名称已存在","") ,
EMAIL_EXISTS(210,"邮箱地址已存在","") ,
USER_NOT_EXISTS(300,"用户不存在","") , USER_NOT_EXISTS(300,"用户不存在","") ,
PARAM_CHECK_ERROR(4001,"参数校验异常",""), PARAM_CHECK_ERROR(4001,"参数校验异常",""),
PARAMS_ERROR(40000, "请求参数错误",""), PARAMS_ERROR(40000, "请求参数错误",""),
......
package com.yd.common.utils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 对象转换工具类
* 提供将Java对象转换为Map的功能
*/
public class BeanMapUtils {
/**
* 将任意对象转换为Map<String, Object>
* 包含对象的所有字段(包括私有字段)
*
* @param <T> 对象类型
* @param obj 要转换的对象
* @return 包含对象字段名和值的Map
* @throws IllegalAccessException 如果无法访问字段
*/
public static <T> Map<String, Object> convertToMap(T obj) throws IllegalAccessException {
Map<String, Object> map = new HashMap<>();
if (obj == null) {
return map;
}
Class<?> clazz = obj.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true); // 允许访问私有字段
Object value = field.get(obj);
map.put(field.getName(), value);
}
return map;
}
/**
* 将任意对象转换为Map<String, Object>
* 包含对象的所有字段,包括继承的字段
*
* @param <T> 对象类型
* @param obj 要转换的对象
* @return 包含对象字段名和值的Map
* @throws IllegalAccessException 如果无法访问字段
*/
public static <T> Map<String, Object> convertToMapIncludingInherited(T obj) throws IllegalAccessException {
Map<String, Object> map = new HashMap<>();
if (obj == null) {
return map;
}
Class<?> clazz = obj.getClass();
while (clazz != null && clazz != Object.class) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object value = field.get(obj);
map.put(field.getName(), value);
}
clazz = clazz.getSuperclass(); // 处理父类的字段
}
return map;
}
/**
* 安全地将对象转换为Map,遇到异常时返回空Map
*
* @param <T> 对象类型
* @param obj 要转换的对象
* @return 包含对象字段名和值的Map,转换失败时返回空Map
*/
public static <T> Map<String, Object> convertToMapSafely(T obj) {
try {
return convertToMap(obj);
} catch (IllegalAccessException e) {
// 记录日志或处理异常
return new HashMap<>();
}
}
/**
* 将对象列表转换为Map列表
*
* @param <T> 对象类型
* @param objList 要转换的对象列表
* @return 包含对象字段名和值的Map列表
* @throws IllegalAccessException 如果无法访问字段
*/
public static <T> List<Map<String, Object>> convertListToMapList(List<T> objList) throws IllegalAccessException {
List<Map<String, Object>> resultList = new ArrayList<>();
if (objList == null) {
return resultList;
}
for (T obj : objList) {
Map<String, Object> map = convertToMap(obj);
resultList.add(map);
}
return resultList;
}
/**
* 将对象列表转换为Map列表(包含继承字段)
*
* @param <T> 对象类型
* @param objList 要转换的对象列表
* @return 包含对象字段名和值的Map列表
* @throws IllegalAccessException 如果无法访问字段
*/
public static <T> List<Map<String, Object>> convertListToMapListIncludingInherited(List<T> objList)
throws IllegalAccessException {
List<Map<String, Object>> resultList = new ArrayList<>();
if (objList == null) {
return resultList;
}
for (T obj : objList) {
Map<String, Object> map = convertToMapIncludingInherited(obj);
resultList.add(map);
}
return resultList;
}
/**
* 安全地将对象列表转换为Map列表,遇到异常时跳过有问题的对象
*
* @param <T> 对象类型
* @param objList 要转换的对象列表
* @return 包含对象字段名和值的Map列表
*/
public static <T> List<Map<String, Object>> convertListToMapListSafely(List<T> objList) {
List<Map<String, Object>> resultList = new ArrayList<>();
if (objList == null) {
return resultList;
}
for (T obj : objList) {
try {
Map<String, Object> map = convertToMap(obj);
resultList.add(map);
} catch (IllegalAccessException e) {
// 记录日志或处理异常,跳过有问题的对象
// 可以选择添加空Map或跳过
}
}
return resultList;
}
/**
* 安全地将对象列表转换为Map列表,遇到异常时添加空Map
*
* @param <T> 对象类型
* @param objList 要转换的对象列表
* @return 包含对象字段名和值的Map列表
*/
public static <T> List<Map<String, Object>> convertListToMapListSafelyWithEmpty(List<T> objList) {
List<Map<String, Object>> resultList = new ArrayList<>();
if (objList == null) {
return resultList;
}
for (T obj : objList) {
Map<String, Object> map = convertToMapSafely(obj);
resultList.add(map);
}
return resultList;
}
}
package com.yd.common.utils;
public class CommonUtil {
public static String formatPercentage(Object percentage) {
if (percentage == null) return "0%";
try {
double value = Double.parseDouble(percentage.toString());
return String.format("%.0f%%", value);
} catch (NumberFormatException e) {
return percentage.toString();
}
}
}
package com.yd.common.utils;
import org.apache.commons.lang3.StringUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;
public class DateUtil {
public static String formatDate(Object date) {
if (date == null) return "";
if (date instanceof Date) {
return new SimpleDateFormat("yyyy/MM/dd").format((Date) date);
}
return date.toString();
}
public static Date parseDate(String dateStr) {
try {
return new SimpleDateFormat("yyyy/MM/dd").parse(dateStr);
} catch (ParseException e) {
return new Date();
}
}
/**
* localDateTime转成年/月/日这种格式
* @param localDateTime
* @return
*/
public static String getyyyyMMdd(LocalDateTime localDateTime) {
if (Objects.isNull(localDateTime)) {
return "";
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
return localDateTime.format(formatter);
}
/**
* localDateTime转成时分这种格式
* @param localDateTime
* @return
*/
public static String getHHmm(LocalDateTime localDateTime) {
if (Objects.isNull(localDateTime)) {
return "";
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
return localDateTime.format(formatter);
}
/**
* localDateTime转成年-月-日 时:分这种格式
* @param localDateTime
* @return
*/
public static String getyyyyMMddHHmm(LocalDateTime localDateTime) {
if (Objects.isNull(localDateTime)) {
return "";
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return localDateTime.format(formatter);
}
/**
* yyyy/MM/dd HH:mm转成LocalDateTime
* @param timeStr
* @return
*/
public static LocalDateTime getLocalDateTime(String timeStr) {
if (StringUtils.isBlank(timeStr)) {
return null;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
// 解析字符串为LocalDateTime
LocalDateTime localDateTime = LocalDateTime.parse(timeStr, formatter);
return localDateTime;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment