Ver código fonte

中英文切换代码提交

kouchengxing 5 anos atrás
pai
commit
8de505f7c6
19 arquivos alterados com 325 adições e 39 exclusões
  1. 17 14
      dgtly-apiframework/src/main/java/com/dgtly/apiframework/interceptor/SwitchEnSqlInterceptor.java
  2. 51 16
      dgtly-common/src/main/java/com/dgtly/common/utils/TranslateUtil.java
  3. 8 0
      dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/info/add.html
  4. 8 0
      dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/info/edit.html
  5. 17 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsAttribute.java
  6. 9 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsColor.java
  7. 52 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsInfo.java
  8. 8 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsSize.java
  9. 8 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsType.java
  10. 9 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsTypeAttribute.java
  11. 1 1
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/mapper/GoodsInfoMapper.java
  12. 76 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsInfoServiceImpl.java
  13. 30 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsTypeServiceImpl.java
  14. 3 2
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsAttributeMapper.xml
  15. 3 2
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsColorMapper.xml
  16. 17 0
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsInfoMapper.xml
  17. 3 2
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsSizeMapper.xml
  18. 2 2
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsTypeAttributeMapper.xml
  19. 3 0
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsTypeMapper.xml

+ 17 - 14
dgtly-apiframework/src/main/java/com/dgtly/apiframework/interceptor/SwitchEnSqlInterceptor.java

@@ -41,22 +41,25 @@ public class SwitchEnSqlInterceptor  implements Interceptor {
         String oldsql = boundSql.getSql();
         //oldsql = oldsql.replaceAll("gi.name","gi.name_en name");
 
-        //@TODO 获取前端标识是否切换获取中英文切换
+        //获取前端标识是否切换获取中英文切换
         HttpServletRequest request = ServletUtils.getRequest();
+        String language = request.getHeader("language");
 
-        // 方法中含有获取注解
-        Class<?> classType = Class.forName(mappedStatement.getId().substring(0,mappedStatement.getId().lastIndexOf(".")));
-        String mName  = mappedStatement.getId().substring(mappedStatement.getId().lastIndexOf(".") + 1 ,mappedStatement.getId().length());
-        for(Method method : classType.getDeclaredMethods()){
-            if(method!=null && mName.equals(method.getName()))
-            {
-                SwitchEn switchEn = method.getAnnotation(SwitchEn.class);
-                String[] oldfiles = switchEn.oldfiles();
-                String[] newfiles = switchEn.newfiles();
-                //旧字段和替换字段长度相同
-                if(newfiles.length==oldfiles.length){
-                    for(int i = 0;i<oldfiles.length;i++){
-                        oldsql = oldsql.replaceAll(oldfiles[i],newfiles[i]);
+        if(StringUtils.isNotEmpty(language) && "en".equalsIgnoreCase(language)){
+            // 方法中含有获取注解
+            Class<?> classType = Class.forName(mappedStatement.getId().substring(0,mappedStatement.getId().lastIndexOf(".")));
+            String mName  = mappedStatement.getId().substring(mappedStatement.getId().lastIndexOf(".") + 1 ,mappedStatement.getId().length());
+            for(Method method : classType.getDeclaredMethods()){
+                if(method!=null && mName.equals(method.getName()) && method.isAnnotationPresent(SwitchEn.class))
+                {
+                    SwitchEn switchEn = method.getAnnotation(SwitchEn.class);
+                    String[] oldfiles = switchEn.oldfiles();
+                    String[] newfiles = switchEn.newfiles();
+                    //旧字段和替换字段长度相同
+                    if(newfiles.length==oldfiles.length){
+                        for(int i = 0;i<oldfiles.length;i++){
+                            oldsql = oldsql.replaceAll(oldfiles[i],newfiles[i]);
+                        }
                     }
                 }
             }

+ 51 - 16
dgtly-common/src/main/java/com/dgtly/common/utils/TranslateUtil.java

@@ -6,6 +6,9 @@ import net.sf.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
 /**
  * @author koucx
  * @version 1.0
@@ -19,7 +22,8 @@ public class TranslateUtil {
 
     private static final Logger log = LoggerFactory.getLogger(TranslateUtil.class);
 
-    private static final String TRANSLATE_URL = "http://fanyi.youdao.com/translate";
+    private static final String TRANSLATE_URL_OLD = "http://fanyi.youdao.com/translate";
+    private static final String TRANSLATE_URL = "http://fanyi.youdao.com/openapi.do";
 
     /**
      * @Description: 调用有道翻译接口中文翻译成英文
@@ -28,9 +32,10 @@ public class TranslateUtil {
      * @Author: koucx
      * @Date: 2020-03-24
     **/
-    public static String getEnTranslateInfo(String msg){
+    @Deprecated
+    public static String getEnTranslateInfoOld(String msg){
         String params = "doctype=json&type=AUTO&i="+msg;
-        String enInfo = HttpUtils.sendGet(TRANSLATE_URL, params);
+        String enInfo = HttpUtils.sendGet(TRANSLATE_URL_OLD, params);
         /**
          * {
          *     "type": "ZH_CN2EN",
@@ -49,18 +54,20 @@ public class TranslateUtil {
          * 根据以上json串获取相应英文翻译
          *
          */
-        JSONObject object = JSONObject.fromObject(enInfo);
-        if(object!=null){
-            JSONArray array = object.getJSONArray("translateResult");
-            if(array!=null && array.size()>0){
-                for (Object obj:array) {
-                    JSONArray arr = JSONArray.fromObject(obj);
-                    for (Object o:arr) {
-                        JSONObject json = JSONObject.fromObject(o);
-                        if(json!=null && json.containsKey("tgt")){
-                            String tgt = json.getString("tgt");
-                            log.info("'"+json.getString("src")+"'翻译后'"+tgt+"'");
-                            return tgt;
+        if(enInfo.startsWith("{") && enInfo.endsWith("}")){
+            JSONObject object = JSONObject.fromObject(enInfo);
+            if(object!=null){
+                JSONArray array = object.getJSONArray("translateResult");
+                if(array!=null && array.size()>0){
+                    for (Object obj:array) {
+                        JSONArray arr = JSONArray.fromObject(obj);
+                        for (Object o:arr) {
+                            JSONObject json = JSONObject.fromObject(o);
+                            if(json!=null && json.containsKey("tgt")){
+                                String tgt = json.getString("tgt");
+                                log.info("'"+json.getString("src")+"'翻译后'"+tgt+"'");
+                                return tgt;
+                            }
                         }
                     }
                 }
@@ -69,9 +76,37 @@ public class TranslateUtil {
         return "";
     }
 
+    /**
+     * @Description: 调用有道翻译接口中文翻译成英文
+     * @Param: [msg]
+     * @Verision:2.0
+     * @Return: java.lang.String
+     * @Author: koucx
+     * @Date: 2020-03-24
+     **/
+    public static String getEnTranslateInfo(String msg){
+
+        try{
+            String params = "keyfrom=pdblog&key=993123434&type=data&doctype=json&version=1.1&q="+ URLEncoder.encode(msg,"utf-8");
+            String enInfo = HttpUtils.sendGet(TRANSLATE_URL, params);
+            JSONObject jsonObject = JSONObject.fromObject(enInfo);
+            if(jsonObject!=null){
+                Object obj = jsonObject.get("translation");
+                JSONArray jsonArray = JSONArray.fromObject(obj);
+                if(jsonArray!=null && jsonArray.size()>0){
+                    return jsonArray.get(0)==null?"":jsonArray.get(0).toString();
+                }
+            }
+        }catch (Exception e){
+            log.info("翻译出错");
+        }
+        return "";
+    }
+
 
     public static void main(String[] args) {
-        System.out.println(getEnTranslateInfo("60厘米")); ;
+        System.out.println(getEnTranslateInfo("<p><a>学习</a></p>"));
+
     }
 
 }

+ 8 - 0
dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/info/add.html

@@ -156,6 +156,14 @@
                         </div>
                     </div>
                 </div>
+                <div class="col-sm-6">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label"><span style="color: red; ">*</span>商品材质:</label>
+                        <div class="col-sm-8">
+                            <input name="material" class="form-control" type="text" required>
+                        </div>
+                    </div>
+                </div>
             </div>
             <!--规格和颜色-->
             <div class="row">

+ 8 - 0
dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/info/edit.html

@@ -163,6 +163,14 @@
                     </div>
                 </div>
             </div>
+            <div class="col-sm-6">
+                <div class="form-group">
+                    <label class="col-sm-2 control-label"><span style="color: red; ">*</span>商品材质:</label>
+                    <div class="col-sm-8">
+                        <input name="material" class="form-control" type="text" required>
+                    </div>
+                </div>
+            </div>
         </div>
         <!--规格和颜色-->
         <div class="row">

+ 17 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsAttribute.java

@@ -29,11 +29,13 @@ public class GoodsAttribute
     /** 取值 */
     @Excel(name = "取值")
     private String value;
+    private String valueEn;
 
 
     /** 属性名称 */
     @Excel(name = "取值")
     private String attributeName;
+    private String attributeNameEn;
 
     /**排序值*/
     private String Sort;
@@ -92,6 +94,21 @@ public class GoodsAttribute
         Sort = sort;
     }
 
+    public String getValueEn() {
+        return valueEn;
+    }
+
+    public void setValueEn(String valueEn) {
+        this.valueEn = valueEn;
+    }
+
+    public String getAttributeNameEn() {
+        return attributeNameEn;
+    }
+
+    public void setAttributeNameEn(String attributeNameEn) {
+        this.attributeNameEn = attributeNameEn;
+    }
 
     @Override
     public String toString() {

+ 9 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsColor.java

@@ -25,6 +25,7 @@ public class GoodsColor
     /** 颜色 */
     @Excel(name = "颜色")
     private String color;
+    private String colorEn;
 
 
     public void setId(Long id) 
@@ -55,6 +56,14 @@ public class GoodsColor
         return color;
     }
 
+    public String getColorEn() {
+        return colorEn;
+    }
+
+    public void setColorEn(String colorEn) {
+        this.colorEn = colorEn;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 52 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsInfo.java

@@ -24,6 +24,7 @@ public class GoodsInfo extends BaseEntity
     /** 商品名称 */
     @Excel(name = "商品名称")
     private String name;
+    private String nameEn;
 
     /** 所属公司id */
     @Excel(name = "所属公司id")
@@ -48,10 +49,12 @@ public class GoodsInfo extends BaseEntity
     /** 编辑器生成的详细描述html */
     @Excel(name = "编辑器生成的详细描述html")
     private String des;
+    private String desEn;
 
     /** 配送方式 */
     @Excel(name = "配送方式")
     private String delivery;
+    private String deliveryEn;
 
     /** 生产日期 */
     @Excel(name = "生产日期", width = 30, dateFormat = "yyyy-MM-dd")
@@ -60,10 +63,12 @@ public class GoodsInfo extends BaseEntity
     /** 生产地点 */
     @Excel(name = "生产地点")
     private String producedAddress;
+    private String producedAddressEn;
 
     /** 供货仓库地址 */
     @Excel(name = "供货仓库地址")
     private String warehouseAddress;
+    private String warehouseAddressEn;
 
     /** 单重 */
     @Excel(name = "单重")
@@ -72,6 +77,7 @@ public class GoodsInfo extends BaseEntity
     /** 商品材质 */
     @Excel(name = "商品材质")
     private String material;
+    private String materialEn;
 
     /** 排序 */
     @Excel(name = "排序")
@@ -309,7 +315,53 @@ public class GoodsInfo extends BaseEntity
         this.sort = sort;
     }
 
+    public String getNameEn() {
+        return nameEn;
+    }
+
+    public void setNameEn(String nameEn) {
+        this.nameEn = nameEn;
+    }
+
+    public String getDeliveryEn() {
+        return deliveryEn;
+    }
+
+    public void setDeliveryEn(String deliveryEn) {
+        this.deliveryEn = deliveryEn;
+    }
+
+    public String getProducedAddressEn() {
+        return producedAddressEn;
+    }
+
+    public void setProducedAddressEn(String producedAddressEn) {
+        this.producedAddressEn = producedAddressEn;
+    }
 
+    public String getWarehouseAddressEn() {
+        return warehouseAddressEn;
+    }
+
+    public void setWarehouseAddressEn(String warehouseAddressEn) {
+        this.warehouseAddressEn = warehouseAddressEn;
+    }
+
+    public String getDesEn() {
+        return desEn;
+    }
+
+    public void setDesEn(String desEn) {
+        this.desEn = desEn;
+    }
+
+    public String getMaterialEn() {
+        return materialEn;
+    }
+
+    public void setMaterialEn(String materialEn) {
+        this.materialEn = materialEn;
+    }
 
     @Override
     public String toString() {

+ 8 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsSize.java

@@ -25,6 +25,7 @@ public class GoodsSize
     /** 规格 */
     @Excel(name = "规格")
     private String size;
+    private String sizeEn;
 
 
     public void setId(Long id) 
@@ -55,6 +56,13 @@ public class GoodsSize
         return size;
     }
 
+    public String getSizeEn() {
+        return sizeEn;
+    }
+
+    public void setSizeEn(String sizeEn) {
+        this.sizeEn = sizeEn;
+    }
 
     @Override
     public String toString() {

+ 8 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsType.java

@@ -23,6 +23,7 @@ public class GoodsType extends BaseEntity
     /** 类型名称 */
     @Excel(name = "类型名称")
     private String name;
+    private String nameEn;
     /** 图片*/
     private String img;
 
@@ -113,6 +114,13 @@ public class GoodsType extends BaseEntity
         this.delFlag = delFlag;
     }
 
+    public String getNameEn() {
+        return nameEn;
+    }
+
+    public void setNameEn(String nameEn) {
+        this.nameEn = nameEn;
+    }
 
     @Override
     public String toString() {

+ 9 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/domain/GoodsTypeAttribute.java

@@ -25,6 +25,7 @@ public class GoodsTypeAttribute extends BaseEntity
     /** 属性名 */
     @Excel(name = "属性名")
     private String attributeName;
+    private String attributeNameEn;
 
     /** 字段排序(999最大排最前) */
     @Excel(name = "字段排序", readConverterExp = "9=99最大排最前")
@@ -53,6 +54,14 @@ public class GoodsTypeAttribute extends BaseEntity
         this.attributeName = attributeName;
     }
 
+    public String getAttributeNameEn() {
+        return attributeNameEn;
+    }
+
+    public void setAttributeNameEn(String attributeNameEn) {
+        this.attributeNameEn = attributeNameEn;
+    }
+
     public String getAttributeName()
     {
         return attributeName;

+ 1 - 1
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/mapper/GoodsInfoMapper.java

@@ -20,7 +20,7 @@ public interface GoodsInfoMapper
      * @param id 商品基础详情ID
      * @return 商品基础详情
      */
-    @SwitchEn
+    @SwitchEn(oldfiles ={"gi.name"},newfiles = {"gi.name_en name"})
     public GoodsInfo selectGoodsInfoById(Long id);
 
     /**

+ 76 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsInfoServiceImpl.java

@@ -4,6 +4,8 @@ import java.util.List;
 
 import com.dgtly.common.annotation.DataScope;
 import com.dgtly.common.utils.DateUtils;
+import com.dgtly.common.utils.StringUtils;
+import com.dgtly.common.utils.TranslateUtil;
 import com.dgtly.goods.domain.GoodsAttribute;
 import com.dgtly.goods.domain.GoodsColor;
 import com.dgtly.goods.domain.GoodsSize;
@@ -85,6 +87,8 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
     public int insertGoodsInfo(GoodsInfo goodsInfo)
     {
         goodsInfo.setCreateTime(DateUtils.getNowDate());
+        //翻译字段
+        translateField(goodsInfo);
         int num = goodsInfoMapper.insertGoodsInfo(goodsInfo);
         /*处理 属性 颜色 规格等数据*/
         handleAttributeSizeColor(goodsInfo);
@@ -102,6 +106,8 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
     public int updateGoodsInfo(GoodsInfo goodsInfo)
     {
         goodsInfo.setUpdateTime(DateUtils.getNowDate());
+        //翻译字段
+        translateField(goodsInfo);
         /*处理 属性 颜色 规格等数据*/
         handleAttributeSizeColor(goodsInfo);
 
@@ -197,6 +203,16 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
         if(goodsInfo.getGoodsAttributes()!=null&&goodsInfo.getGoodsAttributes().size()>0)
         {
             List<GoodsAttribute> goodsAttributeList = goodsInfo.getGoodsAttributes();
+            for (GoodsAttribute goodsAttribute:goodsAttributeList) {
+                String value = goodsAttribute.getValue();
+                if(StringUtils.isNotEmpty(value)){
+                    goodsAttribute.setValueEn(TranslateUtil.getEnTranslateInfo(value));
+                }
+                String attributeName = goodsAttribute.getAttributeName();
+                if(StringUtils.isNotEmpty(attributeName)){
+                    goodsAttribute.setAttributeNameEn(TranslateUtil.getEnTranslateInfo(attributeName));
+                }
+            }
             int i = goodsAttributeMapper.insertGoodsAttributeList(goodsAttributeList,goodsInfo.getId());
             if (i!=goodsAttributeList.size()){
                 throw  new RuntimeException("插入商品属性数量不符");
@@ -207,6 +223,13 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
         if(goodsInfo.getGoodsColors()!=null&&goodsInfo.getGoodsColors().size()>0)
         {
             List<GoodsColor> goodsColorList = goodsInfo.getGoodsColors();
+            for (GoodsColor goodsColor:goodsColorList) {
+                String color = goodsColor.getColor();
+                if(StringUtils.isNotEmpty(color)){
+                    //翻译英文
+                    goodsColor.setColorEn(TranslateUtil.getEnTranslateInfo(color));
+                }
+            }
             int i = goodsColorMapper.insertGoodsColorList(goodsColorList,goodsInfo.getId());
             if (i!=goodsColorList.size()){
                 throw  new RuntimeException("插入商品颜色数量不符");
@@ -217,6 +240,13 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
         if(goodsInfo.getGoodsSizes()!=null&&goodsInfo.getGoodsSizes().size()>0)
         {
             List<GoodsSize> goodsSizeList = goodsInfo.getGoodsSizes();
+            for (GoodsSize goodsSize:goodsSizeList) {
+                String size = goodsSize.getSize();
+                if(StringUtils.isNotEmpty(size)){
+                    //翻译英文
+                    goodsSize.setSizeEn(TranslateUtil.getEnTranslateInfo(size));
+                }
+            }
             int i = goodsSizeMapper.insertGoodsSizeList(goodsSizeList,goodsInfo.getId());
             if (i!=goodsSizeList.size()){
                 throw  new RuntimeException("插入商品规格数量不符");
@@ -228,4 +258,50 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
     public int countGoodsInfo() {
         return goodsInfoMapper.countGoodsInfo();
     }
+
+    /**
+     * @Description: 转换需要翻译的字段
+     * @Param: [goodsInfo]
+     * @Return: com.dgtly.goods.domain.GoodsInfo
+     * @Author: koucx
+     * @Date: 2020-03-24
+    **/
+    public GoodsInfo translateField(GoodsInfo goodsInfo){
+        //商品名称
+        String name = goodsInfo.getName();
+        if(StringUtils.isNotEmpty(name)){
+            goodsInfo.setNameEn(TranslateUtil.getEnTranslateInfo(name));
+        }
+        //配送方式
+        String delivery = goodsInfo.getDelivery();
+        if(StringUtils.isNotEmpty(delivery)){
+            goodsInfo.setDeliveryEn(TranslateUtil.getEnTranslateInfo(delivery));
+        }
+        //生产地点
+        String producedAddress = goodsInfo.getProducedAddress();
+        if(StringUtils.isNotEmpty(producedAddress)){
+            goodsInfo.setProducedAddressEn(TranslateUtil.getEnTranslateInfo(producedAddress));
+        }
+        //供货仓库地址
+        String warehouseAddress = goodsInfo.getWarehouseAddress();
+        if(StringUtils.isNotEmpty(warehouseAddress)){
+            goodsInfo.setWarehouseAddressEn(TranslateUtil.getEnTranslateInfo(warehouseAddress));
+        }
+
+        //商品材质
+        String material = goodsInfo.getMaterial();
+        if(StringUtils.isNotEmpty(material)){
+            goodsInfo.setMaterialEn(TranslateUtil.getEnTranslateInfo(material));
+        }
+
+
+        //描述文本编辑
+        String desc = goodsInfo.getDes();
+        if(StringUtils.isNotEmpty(desc)){
+            goodsInfo.setDes(TranslateUtil.getEnTranslateInfo(desc));
+        }
+        return goodsInfo;
+    }
+
+
 }

+ 30 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsTypeServiceImpl.java

@@ -7,6 +7,9 @@ import com.dgtly.common.constant.UserConstants;
 import com.dgtly.common.core.domain.Ztree;
 import com.dgtly.common.exception.BusinessException;
 import com.dgtly.common.utils.DateUtils;
+import com.dgtly.common.utils.StringUtils;
+import com.dgtly.common.utils.TranslateUtil;
+import com.dgtly.goods.domain.GoodsInfo;
 import com.dgtly.goods.domain.GoodsTypeAttribute;
 import com.dgtly.goods.mapper.GoodsTypeAttributeMapper;
 import com.dgtly.goods.service.IGoodsInfoService;
@@ -75,6 +78,8 @@ public class GoodsTypeServiceImpl implements IGoodsTypeService
     public int insertGoodsType(GoodsType goodsType)
     {
         goodsType.setCreateTime(DateUtils.getNowDate());
+        //翻译中文字段
+        translateField(goodsType);
         int i = goodsTypeMapper.insertGoodsType(goodsType);
         GoodsType type = goodsTypeMapper.selectGoodsTypeById(goodsType.getParentId());
         GoodsType upType = new GoodsType();
@@ -92,6 +97,13 @@ public class GoodsTypeServiceImpl implements IGoodsTypeService
             throw new RuntimeException("新增类型失败");
         }
         if(goodsType.getGoodsTypeAttributes()!=null&&goodsType.getGoodsTypeAttributes().size()>0){
+            List<GoodsTypeAttribute> goodsTypeAttributes = goodsType.getGoodsTypeAttributes();
+            for (GoodsTypeAttribute goodsTypeAttribute:goodsTypeAttributes) {
+                String attributeName = goodsTypeAttribute.getAttributeName();
+                if(StringUtils.isNotEmpty(attributeName)){
+                    goodsTypeAttribute.setAttributeNameEn(TranslateUtil.getEnTranslateInfo(attributeName));
+                }
+            }
             int num =goodsTypeAttributeMapper.batchAttribute(goodsType.getGoodsTypeAttributes(),goodsType.getId());
             if(num<goodsType.getGoodsTypeAttributes().size()){
                 throw new RuntimeException("新增类型失败");
@@ -111,6 +123,8 @@ public class GoodsTypeServiceImpl implements IGoodsTypeService
     public int updateGoodsType(GoodsType goodsType)
     {
         goodsType.setUpdateTime(DateUtils.getNowDate());
+        //翻译中文字段
+        translateField(goodsType);
         int i = goodsInfoService.selectGoodsInfoCountByTypeId(goodsType.getId());
 
         if(i>0&&goodsType.getGoodsTypeAttributes()!=null){
@@ -237,4 +251,20 @@ public class GoodsTypeServiceImpl implements IGoodsTypeService
         }
         return ztrees;
     }
+
+    /**
+     * @Description: 转换需要翻译的字段
+     * @Param: [goodsType]
+     * @Return: com.dgtly.goods.domain.GoodsType
+     * @Author: koucx
+     * @Date: 2020-03-25
+    **/
+    public GoodsType translateField(GoodsType goodsType){
+        //商品类型名称
+        String name = goodsType.getName();
+        if(StringUtils.isNotEmpty(name)){
+            goodsType.setNameEn(TranslateUtil.getEnTranslateInfo(name));
+        }
+        return goodsType;
+    }
 }

+ 3 - 2
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsAttributeMapper.xml

@@ -42,13 +42,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </insert>
 
     <insert id="insertGoodsAttributeList" >
-        insert into goods_attribute (goods_id,attribute_id,value) values
+        insert into goods_attribute (goods_id,attribute_id,value,value_en) values
         <foreach collection="list" item="item" index="index"
                  separator=",">
             (
             #{goodsId},
             #{item.attributeId},
-            #{item.value}
+            #{item.value},
+            #{item.valueEn}
             )
         </foreach>
     </insert>

+ 3 - 2
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsColorMapper.xml

@@ -42,12 +42,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </insert>
 
     <insert id="insertGoodsColorList" >
-        insert into goods_color (goods_id,color) values
+        insert into goods_color (goods_id,color,color_en) values
         <foreach collection="list" item="item" index="index"
                  separator=",">
             (
             #{goodsId},
-            #{item.color}
+            #{item.color},
+            #{item.colorEn}
             )
         </foreach>
     </insert>

+ 17 - 0
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsInfoMapper.xml

@@ -142,18 +142,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         insert into goods_info
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="name != null  and name != ''">name,</if>
+            <if test="nameEn != null  and nameEn != ''">name_en,</if>
             <if test="companyId != null ">company_id,</if>
             <if test="typeId != null ">type_id,</if>
             <if test="price != null ">price,</if>
             <if test="cover != null  and cover != ''">cover,</if>
             <if test="slideshow != null  and slideshow != ''">slideshow,</if>
             <if test="des != null  and des != ''">des,</if>
+            <if test="desEn != null  and desEn != ''">des_en,</if>
             <if test="delivery != null  and delivery != ''">delivery,</if>
+            <if test="deliveryEn != null  and deliveryEn != ''">delivery_en,</if>
             <if test="producedTime != null ">produced_time,</if>
             <if test="producedAddress != null  and producedAddress != ''">produced_address,</if>
+            <if test="producedAddressEn != null  and producedAddressEn != ''">produced_address_en,</if>
             <if test="warehouseAddress != null  and warehouseAddress != ''">warehouse_address,</if>
+            <if test="warehouseAddressEn != null  and warehouseAddressEn != ''">warehouse_address_en,</if>
             <if test="weight != null  and weight != ''">weight,</if>
             <if test="material != null  and material != ''">material,</if>
+            <if test="materialEn != null  and materialEn != ''">material_en,</if>
             <if test="putawayFlag != null  and putawayFlag != ''">putaway_flag,</if>
             <if test="delFlag != null  and delFlag != ''">del_flag,</if>
             <if test="createTime != null ">create_time,</if>
@@ -165,18 +171,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="name != null  and name != ''">#{name},</if>
+            <if test="nameEn != null  and nameEn != ''">#{nameEn},</if>
             <if test="companyId != null ">#{companyId},</if>
             <if test="typeId != null ">#{typeId},</if>
             <if test="price != null ">#{price},</if>
             <if test="cover != null  and cover != ''">#{cover},</if>
             <if test="slideshow != null  and slideshow != ''">#{slideshow},</if>
             <if test="des != null  and des != ''">#{des},</if>
+            <if test="desEn != null  and desEn != ''">#{desEn},</if>
             <if test="delivery != null  and delivery != ''">#{delivery},</if>
+            <if test="deliveryEn != null  and deliveryEn != ''">#{deliveryEn},</if>
             <if test="producedTime != null ">#{producedTime},</if>
             <if test="producedAddress != null  and producedAddress != ''">#{producedAddress},</if>
+            <if test="producedAddressEn != null  and producedAddressEn != ''">#{producedAddressEn},</if>
             <if test="warehouseAddress != null  and warehouseAddress != ''">#{warehouseAddress},</if>
+            <if test="warehouseAddressEn != null  and warehouseAddressEn != ''">#{warehouseAddressEn},</if>
             <if test="weight != null  and weight != ''">#{weight},</if>
             <if test="material != null  and material != ''">#{material},</if>
+            <if test="materialEn != null  and materialEn != ''">#{materialEn},</if>
             <if test="putawayFlag != null  and putawayFlag != ''">#{putawayFlag},</if>
             <if test="delFlag != null  and delFlag != ''">#{delFlag},</if>
             <if test="createTime != null ">#{createTime},</if>
@@ -192,6 +204,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update goods_info
         <trim prefix="SET" suffixOverrides=",">
             <if test="name != null  and name != ''">name = #{name},</if>
+            <if test="nameEn != null  and nameEn != ''">name_en = #{nameEn},</if>
             <if test="companyId != null ">company_id = #{companyId},</if>
             <if test="typeId != null ">type_id = #{typeId},</if>
             <if test="price != null ">price = #{price},</if>
@@ -199,11 +212,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="slideshow != null  and slideshow != ''">slideshow = #{slideshow},</if>
             <if test="des != null  and des != ''">des = #{des},</if>
             <if test="delivery != null  and delivery != ''">delivery = #{delivery},</if>
+            <if test="deliveryEn != null  and deliveryEn != ''">delivery_en = #{deliveryEn},</if>
             <if test="producedTime != null ">produced_time = #{producedTime},</if>
             <if test="producedAddress != null  and producedAddress != ''">produced_address = #{producedAddress},</if>
+            <if test="producedAddressEn != null  and producedAddressEn != ''">produced_address_en = #{producedAddressEn},</if>
             <if test="warehouseAddress != null  and warehouseAddress != ''">warehouse_address = #{warehouseAddress},</if>
+            <if test="warehouseAddressEn != null  and warehouseAddressEn != ''">warehouse_address_en = #{warehouseAddressEn},</if>
             <if test="weight != null  and weight != ''">weight = #{weight},</if>
             <if test="material != null  and material != ''">material = #{material},</if>
+            <if test="materialEn != null  and materialEn != ''">material_en = #{materialEn},</if>
             <if test="putawayFlag != null  and putawayFlag != ''">putaway_flag = #{putawayFlag},</if>
             <if test="delFlag != null  and delFlag != ''">del_flag = #{delFlag},</if>
             <if test="createTime != null ">create_time = #{createTime},</if>

+ 3 - 2
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsSizeMapper.xml

@@ -30,12 +30,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </insert>
 
     <insert id="insertGoodsSizeList" >
-        insert into goods_size (goods_id,size) values
+        insert into goods_size (goods_id,size,size_en) values
         <foreach collection="list" item="item" index="index"
                  separator=",">
             (
             #{goodsId},
-            #{item.size}
+            #{item.size},
+            #{item.sizeEn}
             )
 
         </foreach>

+ 2 - 2
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsTypeAttributeMapper.xml

@@ -67,9 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <insert id="batchAttribute" parameterType="GoodsTypeAttribute">
-        insert into goods_type_attribute (attribute_name,type_id,sort) values
+        insert into goods_type_attribute (attribute_name,attribute_name_en,type_id,sort) values
         <foreach item="item" index="index" collection="list" separator=",">
-            (#{item.attributeName},#{typeId},#{item.sort})
+            (#{item.attributeName},#{item.attributeNameEn},#{typeId},#{item.sort})
         </foreach>
 
     </insert>

+ 3 - 0
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsTypeMapper.xml

@@ -56,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         insert into goods_type
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="name != null  and name != ''">name,</if>
+            <if test="nameEn != null  and nameEn != ''">name_en,</if>
             <if test="img != null  and img != ''">img,</if>
             <if test="parentId != null ">parent_id,</if>
             <if test="ancestors != null  and ancestors != ''">ancestors,</if>
@@ -67,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="name != null  and name != ''">#{name},</if>
+            <if test="nameEn != null  and nameEn != ''">#{nameEn},</if>
             <if test="img != null  and img != ''">#{img},</if>
             <if test="parentId != null ">#{parentId},</if>
             <if test="ancestors != null  and ancestors != ''">#{ancestors},</if>
@@ -82,6 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update goods_type
         <trim prefix="SET" suffixOverrides=",">
             <if test="name != null  and name != ''">name = #{name},</if>
+            <if test="nameEn != null  and nameEn != ''">name_en = #{nameEn},</if>
             <if test="parentId != null ">parent_id = #{parentId},</if>
             <if test="ancestors != null  and ancestors != ''">ancestors = #{ancestors},</if>
             <if test="img != null  and img != ''">img = #{img},</if>