feat: 根据语言对应的时区返回时间
This commit is contained in:
parent
5f9543d097
commit
148ff6dbb0
|
|
@ -7,7 +7,7 @@ import com.nflg.mobilebroken.common.pojo.PageData;
|
|||
import com.nflg.mobilebroken.common.pojo.request.*;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.*;
|
||||
import com.nflg.mobilebroken.common.util.AppUserUtil;
|
||||
import com.nflg.mobilebroken.common.util.LanguageUtil;
|
||||
import com.nflg.mobilebroken.common.util.MultilingualUtil;
|
||||
import com.nflg.mobilebroken.repository.entity.AppUser;
|
||||
import com.nflg.mobilebroken.repository.entity.Ticket;
|
||||
import com.nflg.mobilebroken.repository.entity.TicketChat;
|
||||
|
|
@ -188,7 +188,7 @@ public class TiketController extends ControllerBase {
|
|||
**/
|
||||
@GetMapping("getTicketEvaluateSelect")
|
||||
public ApiResult<TicketEvaluateVO> getTicketEvaluateSelect() {
|
||||
String language = LanguageUtil.getLanguage();
|
||||
String language = MultilingualUtil.getLanguage();
|
||||
return ApiResult.success(dictionaryItemTranslateService.getTicketEvaluateSelect(language));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package com.nflg.mobilebroken.cfs.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.nflg.mobilebroken.common.util.MultilingualUtil;
|
||||
import com.nflg.mobilebroken.repository.entity.Language;
|
||||
import com.nflg.mobilebroken.repository.service.ILanguageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class InitZoneMap implements CommandLineRunner {
|
||||
|
||||
@Resource
|
||||
private ILanguageService languageService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
log.info("初始化语言区域映射");
|
||||
List<Language> languages = languageService.getLanguages();
|
||||
if (CollectionUtil.isNotEmpty(languages)) {
|
||||
Map<String, String> map = languages.stream()
|
||||
.collect(Collectors.toMap(Language::getCode, Language::getZone));
|
||||
MultilingualUtil.setZoneMap(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import org.ttzero.excel.annotation.IgnoreExport;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class AdminTicketVO {
|
||||
|
|
@ -137,6 +138,9 @@ public class AdminTicketVO {
|
|||
}
|
||||
|
||||
public String getUrgencyDesc() {
|
||||
if (Objects.isNull(urgency)) {
|
||||
return "";
|
||||
}
|
||||
return TicketUrgency.findByValue(urgency).getDescription();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
package com.nflg.mobilebroken.common.util;
|
||||
|
||||
public class LanguageUtil {
|
||||
|
||||
private static final ThreadLocal<String> threadLocal = new ThreadLocal<>();
|
||||
|
||||
public static String getLanguage() {
|
||||
String language = threadLocal.get();
|
||||
if (language == null) {
|
||||
language = "cn";
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
public static void setLanguage(String language) {
|
||||
threadLocal.set(language);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.nflg.mobilebroken.common.util;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MultilingualUtil {
|
||||
|
||||
private static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<>();
|
||||
|
||||
private static final Map<String, String> ZONE_MAP = MapUtil.newHashMap();
|
||||
|
||||
public static String getLanguage() {
|
||||
String language = THREAD_LOCAL.get();
|
||||
if (language == null) {
|
||||
language = "cn";
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
public static void setLanguage(String language) {
|
||||
THREAD_LOCAL.set(language);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static void setZoneMap(Map<String, String> map) {
|
||||
ZONE_MAP.putAll(map);
|
||||
}
|
||||
|
||||
public static String getZone(String language) {
|
||||
return ZONE_MAP.get(language);
|
||||
}
|
||||
|
||||
public static String getZone() {
|
||||
return ZONE_MAP.get(getLanguage());
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,12 @@ package com.nflg.mobilebroken.repository.entity;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 字典
|
||||
|
|
@ -45,6 +46,11 @@ public class Language implements Serializable {
|
|||
*/
|
||||
private String ico;
|
||||
|
||||
/**
|
||||
* 时区
|
||||
*/
|
||||
private String zone;
|
||||
|
||||
/**
|
||||
* 排序,从大到小
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ public class LoggingAspect {
|
|||
StackTraceElement[] stackTraceElements = ex.getStackTrace();
|
||||
logRecord.setRequestResult(false);
|
||||
logDetail.setRequestErrMsg(stackTraceElements.length > 0 ? ex.getMessage() + ":" + stackTraceElements[0].toString() : "");
|
||||
// logger.error("未捕获的异常",ex);
|
||||
return ApiResult.error(STATE.Error,"操作出现错误"+ex.getMessage());
|
||||
}
|
||||
finally {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.nflg.mobilebroken.starter.handler;
|
||||
|
||||
import com.nflg.mobilebroken.common.util.MultilingualUtil;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
|
@ -31,7 +32,7 @@ public class UTCLocalDateTimeTypeHandler extends BaseTypeHandler<LocalDateTime>
|
|||
public LocalDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
LocalDateTime utcTime = rs.getObject(columnName, LocalDateTime.class);
|
||||
// 将 UTC 时间转换为本地时间
|
||||
return utcTime != null ? utcTime.atZone(ZoneId.of("UTC"))
|
||||
return utcTime != null ? utcTime.atZone(ZoneId.of(MultilingualUtil.getZone()))
|
||||
.withZoneSameInstant(ZoneId.systemDefault())
|
||||
.toLocalDateTime() : null;
|
||||
}
|
||||
|
|
@ -40,7 +41,7 @@ public class UTCLocalDateTimeTypeHandler extends BaseTypeHandler<LocalDateTime>
|
|||
public LocalDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
LocalDateTime utcTime = rs.getObject(columnIndex, LocalDateTime.class);
|
||||
// 将 UTC 时间转换为本地时间
|
||||
return utcTime != null ? utcTime.atZone(ZoneId.of("UTC"))
|
||||
return utcTime != null ? utcTime.atZone(ZoneId.of(MultilingualUtil.getZone()))
|
||||
.withZoneSameInstant(ZoneId.systemDefault())
|
||||
.toLocalDateTime() : null;
|
||||
}
|
||||
|
|
@ -49,7 +50,7 @@ public class UTCLocalDateTimeTypeHandler extends BaseTypeHandler<LocalDateTime>
|
|||
public LocalDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
LocalDateTime utcTime = cs.getObject(columnIndex, LocalDateTime.class);
|
||||
// 将 UTC 时间转换为本地时间
|
||||
return utcTime != null ? utcTime.atZone(ZoneId.of("UTC"))
|
||||
return utcTime != null ? utcTime.atZone(ZoneId.of(MultilingualUtil.getZone()))
|
||||
.withZoneSameInstant(ZoneId.systemDefault())
|
||||
.toLocalDateTime() : null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue