Bläddra i källkod

手动写的sql 英文

wanglang 5 dagar sedan
förälder
incheckning
e95332ed34

+ 48 - 0
trade-common/src/main/java/com/trade/common/core/service/BaseI18nService.java

@@ -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);
+        }
+    }
 }

+ 6 - 1
trade-service/src/main/java/com/trade/service/trade/salescontract/service/impl/SalesCommodityServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.trade.common.core.service.BaseI18nService;
 import com.trade.service.enterprise.customer.domain.Enterprise;
 import com.trade.service.enterprise.customer.service.EnterpriseBaseService;
 import com.trade.service.trade.salescontract.domain.SalesCommodity;
@@ -49,10 +50,14 @@ public class SalesCommodityServiceImpl extends ServiceImpl<SalesCommodityMapper,
     private EnterpriseBaseService enterpriseBaseService;
     @Resource
     private SuperviseCertificateCodeService superviseCertificateCodeService;
+    @Resource
+    private BaseI18nService baseI18nService;
 
     @Override
     public List<SalesCommodity> queryBySalesContractId(Long salesContractId) {
-        return this.baseMapper.selectBySalesContractId(salesContractId);
+        List<SalesCommodity> salesCommodities = this.baseMapper.selectBySalesContractId(salesContractId);
+        baseI18nService.setBaseI18nMap(salesCommodities, SalesCommodity.class);
+        return salesCommodities;
     }
 
     @Override