|
@@ -3,6 +3,7 @@ package com.trade.common.core.service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
import com.trade.common.core.domain.BaseI18nEntity;
|
|
|
+import com.trade.common.core.domain.BizBaseI18nEntity;
|
|
|
import com.trade.common.exception.ServiceException;
|
|
|
import com.trade.common.utils.I18nUtil;
|
|
|
import org.slf4j.Logger;
|
|
@@ -42,6 +43,21 @@ public class BaseI18nService {
|
|
|
return entity;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新对象列表的i18n属性,以及需要国际化的字段
|
|
|
+ *
|
|
|
+ * @param entity 实体对象
|
|
|
+ * @param clazz 类信息
|
|
|
+ * @param <T> 继承BaseI18nDomain
|
|
|
+ */
|
|
|
+ public <T extends BizBaseI18nEntity> T setI18nMap(T entity, Class<T> clazz) {
|
|
|
+ if (entity == null || clazz == null) {
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+ setBaseI18nMap(Collections.singletonList(entity), clazz);
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新对象列表的i18n属性
|
|
|
*
|
|
@@ -55,6 +71,19 @@ public class BaseI18nService {
|
|
|
return entityList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新对象列表的i18n属性
|
|
|
+ *
|
|
|
+ * @param entityList 实体类集合
|
|
|
+ * @param clazz 类信息
|
|
|
+ * @param <T> BaseI18nEntity
|
|
|
+ */
|
|
|
+ public <T extends BizBaseI18nEntity> List<T> setBaseI18nMap(List<T> entityList, Class<T> clazz) {
|
|
|
+ exeBaseI18nQuery(entityList, clazz,
|
|
|
+ (tableInfo, connection) -> I18nUtil.setBaseI18nMap(entityList, clazz, tableInfo, connection));
|
|
|
+ return entityList;
|
|
|
+ }
|
|
|
+
|
|
|
private <T extends BaseI18nEntity> void exeI18nQuery(List<T> entityList, Class<T> clazz,
|
|
|
BiConsumer<TableInfo, Connection> biConsumer) {
|
|
|
if (CollectionUtils.isEmpty(entityList)) {
|
|
@@ -73,4 +102,23 @@ public class BaseI18nService {
|
|
|
DataSourceUtils.releaseConnection(connection, dataSource);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private <T extends BizBaseI18nEntity> void exeBaseI18nQuery(List<T> entityList, Class<T> clazz,
|
|
|
+ BiConsumer<TableInfo, Connection> biConsumer) {
|
|
|
+ if (CollectionUtils.isEmpty(entityList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
|
|
|
+ if (tableInfo == null) {
|
|
|
+ throw new ServiceException("无法获取表信息");
|
|
|
+ }
|
|
|
+ Connection connection = DataSourceUtils.getConnection(dataSource);
|
|
|
+ try {
|
|
|
+ biConsumer.accept(tableInfo, connection);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ } finally {
|
|
|
+ DataSourceUtils.releaseConnection(connection, dataSource);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|