|
@@ -2,6 +2,9 @@ package com.cyksj.service.translations.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.mapper.BackInfoTranslationsMapper;
|
|
import com.cyksj.mapper.BackInfoTranslationsMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
@@ -13,6 +16,7 @@ import com.cyksj.model.manage.views.GoodsDonViewer;
|
|
|
import com.cyksj.model.views.*;
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.service.translations.BackInfoTranslationsFrontService;
|
|
import com.cyksj.service.translations.BackInfoTranslationsFrontService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
@@ -29,6 +33,7 @@ import java.util.Map;
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
public class BackInfoTranslationsFrontServiceImpl implements BackInfoTranslationsFrontService {
|
|
public class BackInfoTranslationsFrontServiceImpl implements BackInfoTranslationsFrontService {
|
|
|
private final BackInfoTranslationsMapper backInfoTranslationsMapper;
|
|
private final BackInfoTranslationsMapper backInfoTranslationsMapper;
|
|
|
|
|
|
|
@@ -101,7 +106,11 @@ public class BackInfoTranslationsFrontServiceImpl implements BackInfoTranslation
|
|
|
//sku
|
|
//sku
|
|
|
setFieldLanguage(goodsDonViewer.getClass(), goodsDonViewer, BackInfoTranslations.Type.goods.ordinal(), goodsDonViewer.getId(), lang);
|
|
setFieldLanguage(goodsDonViewer.getClass(), goodsDonViewer, BackInfoTranslations.Type.goods.ordinal(), goodsDonViewer.getId(), lang);
|
|
|
//spec
|
|
//spec
|
|
|
|
|
+ //特殊处理specJson
|
|
|
|
|
+ String specsJson = goodsDonViewer.getSpecsJson();
|
|
|
setFieldLanguage(goodsDonViewer.getClass(), goodsDonViewer, BackInfoTranslations.Type.spec.ordinal(), goodsDonViewer.getSpecId(), lang);
|
|
setFieldLanguage(goodsDonViewer.getClass(), goodsDonViewer, BackInfoTranslations.Type.spec.ordinal(), goodsDonViewer.getSpecId(), lang);
|
|
|
|
|
+ String specsJsonLang = goodsDonViewer.getSpecsJson();
|
|
|
|
|
+ goodsDonViewer.setSpecsJson(replaceSpecValues(specsJson, specsJsonLang));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -258,4 +267,50 @@ public class BackInfoTranslationsFrontServiceImpl implements BackInfoTranslation
|
|
|
homeManagementFrontViews.forEach(rg -> setFieldLanguage(rg.getClass(), rg, BackInfoTranslations.Type.home_config.ordinal(), rg.getHomeManageConfigId(), lang));
|
|
homeManagementFrontViews.forEach(rg -> setFieldLanguage(rg.getClass(), rg, BackInfoTranslations.Type.home_config.ordinal(), rg.getHomeManageConfigId(), lang));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 多语言特殊处理specJson
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String replaceSpecValues(String specJsons, String specJsons2) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONArray specArray = JSONUtil.parseArray(specJsons);
|
|
|
|
|
+ JSONArray specArray2 = JSONUtil.parseArray(specJsons2);
|
|
|
|
|
+
|
|
|
|
|
+ Map<Integer, String> replacementMap = new HashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (Object obj2 : specArray2) {
|
|
|
|
|
+ JSONObject spec2 = (JSONObject) obj2;
|
|
|
|
|
+ JSONArray values2 = spec2.getJSONArray("values");
|
|
|
|
|
+ if (values2 != null) {
|
|
|
|
|
+ for (Object value2Obj : values2) {
|
|
|
|
|
+ JSONObject value2 = (JSONObject) value2Obj;
|
|
|
|
|
+ Integer id = value2.getInt("id");
|
|
|
|
|
+ String valueStr = value2.getStr("value");
|
|
|
|
|
+ if (id != null && valueStr != null) {
|
|
|
|
|
+ replacementMap.put(id, valueStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (Object obj : specArray) {
|
|
|
|
|
+ JSONObject spec = (JSONObject) obj;
|
|
|
|
|
+ JSONArray values = spec.getJSONArray("values");
|
|
|
|
|
+ if (values != null) {
|
|
|
|
|
+ for (Object valueObj : values) {
|
|
|
|
|
+ JSONObject value = (JSONObject) valueObj;
|
|
|
|
|
+ Integer id = value.getInt("id");
|
|
|
|
|
+ if (id != null && replacementMap.containsKey(id)) {
|
|
|
|
|
+ value.set("value", replacementMap.get(id));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return JSONUtil.toJsonStr(specArray);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理JSON时发生错误: " + e.getMessage());
|
|
|
|
|
+ return specJsons;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|