|
|
@ -3,6 +3,7 @@ package com.gaotao.modules.base.controller; |
|
|
import com.gaotao.common.utils.R; |
|
|
import com.gaotao.common.utils.R; |
|
|
import com.gaotao.modules.base.entity.Chooselist; |
|
|
import com.gaotao.modules.base.entity.Chooselist; |
|
|
import com.gaotao.modules.base.service.ChooselistService; |
|
|
import com.gaotao.modules.base.service.ChooselistService; |
|
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
@ -34,8 +35,10 @@ public class ChooselistController { |
|
|
* @return |
|
|
* @return |
|
|
**/ |
|
|
**/ |
|
|
@GetMapping("getChooselist/{tagNo}") |
|
|
@GetMapping("getChooselist/{tagNo}") |
|
|
public R getChooselist(@PathVariable("tagNo") String tagNo) { |
|
|
|
|
|
|
|
|
public R getChooselist(@PathVariable("tagNo") String tagNo, |
|
|
|
|
|
@RequestHeader(value = "Accept-Language", required = false) String acceptLanguage) { |
|
|
Chooselist chooselist = chooselistService.getChooselist(tagNo); |
|
|
Chooselist chooselist = chooselistService.getChooselist(tagNo); |
|
|
|
|
|
applyLocaleValue(chooselist, acceptLanguage); |
|
|
return R.ok().put("data", chooselist); |
|
|
return R.ok().put("data", chooselist); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -72,4 +75,30 @@ public class ChooselistController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void applyLocaleValue(Chooselist chooselist, String acceptLanguage) { |
|
|
|
|
|
if (chooselist == null || !isEnglishLanguage(acceptLanguage)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
chooselist.setDescription(localizedValue(chooselist.getDescriptionEn(), chooselist.getDescription())); |
|
|
|
|
|
chooselist.setCaption1(localizedValue(chooselist.getCaption1En(), chooselist.getCaption1())); |
|
|
|
|
|
chooselist.setCaption2(localizedValue(chooselist.getCaption2En(), chooselist.getCaption2())); |
|
|
|
|
|
chooselist.setCaption3(localizedValue(chooselist.getCaption3En(), chooselist.getCaption3())); |
|
|
|
|
|
chooselist.setCaption4(localizedValue(chooselist.getCaption4En(), chooselist.getCaption4())); |
|
|
|
|
|
chooselist.setCaption5(localizedValue(chooselist.getCaption5En(), chooselist.getCaption5())); |
|
|
|
|
|
chooselist.setCaption6(localizedValue(chooselist.getCaption6En(), chooselist.getCaption6())); |
|
|
|
|
|
chooselist.setCaption7(localizedValue(chooselist.getCaption7En(), chooselist.getCaption7())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String localizedValue(String languageValue, String defaultValue) { |
|
|
|
|
|
return StringUtils.isBlank(languageValue) ? defaultValue : languageValue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isEnglishLanguage(String acceptLanguage) { |
|
|
|
|
|
if (StringUtils.isBlank(acceptLanguage)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
String normalized = acceptLanguage.trim().toLowerCase(); |
|
|
|
|
|
return normalized.startsWith("en"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |