Browse Source
Merge branch 'milestone-20251125-多语言' of http://39.101.133.168:8807/huangqizhen/gold-java into lijianlin/feature-20251104110749-现金管理二期
Merge branch 'milestone-20251125-多语言' of http://39.101.133.168:8807/huangqizhen/gold-java into lijianlin/feature-20251104110749-现金管理二期
# Conflicts: # src/main/java/com/example/demo/controller/coin/RefundController.javamilestone-20251125-多语言
29 changed files with 1420 additions and 179 deletions
-
104src/main/java/com/example/demo/Util/LanguageTranslationUtil.java
-
70src/main/java/com/example/demo/controller/coin/AdminController.java
-
103src/main/java/com/example/demo/controller/coin/AuditController.java
-
45src/main/java/com/example/demo/controller/coin/ConsumeController.java
-
77src/main/java/com/example/demo/controller/coin/GeneralController.java
-
85src/main/java/com/example/demo/controller/coin/GoldDetailController.java
-
43src/main/java/com/example/demo/controller/coin/MarketController.java
-
28src/main/java/com/example/demo/controller/coin/MenuController.java
-
54src/main/java/com/example/demo/controller/coin/RateController.java
-
64src/main/java/com/example/demo/controller/coin/RechargeController.java
-
125src/main/java/com/example/demo/controller/coin/RefundController.java
-
153src/main/java/com/example/demo/controller/coin/TranslationController.java
-
27src/main/java/com/example/demo/controller/coin/UserController.java
-
113src/main/java/com/example/demo/controller/coin/WorkbenchController.java
-
11src/main/java/com/example/demo/domain/DTO/TranslationQueryRequest.java
-
25src/main/java/com/example/demo/domain/entity/Translation.java
-
1src/main/java/com/example/demo/domain/vo/coin/ConsumeUser.java
-
1src/main/java/com/example/demo/domain/vo/coin/GoldDetail.java
-
1src/main/java/com/example/demo/domain/vo/coin/RefundAudit.java
-
1src/main/java/com/example/demo/domain/vo/coin/RefundUser.java
-
42src/main/java/com/example/demo/mapper/coin/TranslationMapper.java
-
5src/main/java/com/example/demo/service/coin/AdminService.java
-
7src/main/java/com/example/demo/service/coin/RefundService.java
-
36src/main/java/com/example/demo/service/coin/TranslationService.java
-
45src/main/java/com/example/demo/serviceImpl/coin/AdminServiceImpl.java
-
4src/main/java/com/example/demo/serviceImpl/coin/ExportExcelServiceImpl.java
-
64src/main/java/com/example/demo/serviceImpl/coin/RefundServiceImpl.java
-
97src/main/java/com/example/demo/serviceImpl/coin/TranslationServiceImpl.java
-
106src/main/resources/mapper/TranslationMapper.xml
@ -0,0 +1,104 @@ |
|||||
|
package com.example.demo.Util; |
||||
|
|
||||
|
import com.example.demo.domain.entity.Translation; |
||||
|
import com.example.demo.service.coin.TranslationService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||
|
|
||||
|
/** |
||||
|
* 多语言转换工具类 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class LanguageTranslationUtil { |
||||
|
|
||||
|
@Autowired |
||||
|
private TranslationService translationService; |
||||
|
|
||||
|
// 缓存翻译数据,提高性能 |
||||
|
private final Map<String, Translation> translationCache = new ConcurrentHashMap<>(); |
||||
|
|
||||
|
/** |
||||
|
* 根据中文简体获取指定语言的翻译 |
||||
|
* |
||||
|
* @param chineseSimplified 中文简体内容 |
||||
|
* @param language 目标语言 (en/th/zh_TW/ms/vi) |
||||
|
* @return 对应语言的翻译内容 |
||||
|
*/ |
||||
|
public String translate(String chineseSimplified, String language) { |
||||
|
System.out.println("Translate request - Text: " + chineseSimplified + ", Language: " + language); |
||||
|
|
||||
|
Translation translation = findTranslationByChinese(chineseSimplified); |
||||
|
if (translation == null) { |
||||
|
System.out.println("No translation found for: " + chineseSimplified); |
||||
|
return chineseSimplified; |
||||
|
} |
||||
|
|
||||
|
String result; |
||||
|
switch (language.toLowerCase()) { |
||||
|
case "en": |
||||
|
result = translation.getEnglish() != null ? translation.getEnglish() : chineseSimplified; |
||||
|
break; |
||||
|
case "th": |
||||
|
result = translation.getThai() != null ? translation.getThai() : chineseSimplified; |
||||
|
break; |
||||
|
case "zh_tw": |
||||
|
result = translation.getChineseTraditional() != null ? translation.getChineseTraditional() : chineseSimplified; |
||||
|
break; |
||||
|
case "ms": |
||||
|
result = translation.getMalay() != null ? translation.getMalay() : chineseSimplified; |
||||
|
break; |
||||
|
case "vi": |
||||
|
result = translation.getVietnamese() != null ? translation.getVietnamese() : chineseSimplified; |
||||
|
break; |
||||
|
default: |
||||
|
result = chineseSimplified; |
||||
|
} |
||||
|
|
||||
|
System.out.println("Translation result: " + result); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 根据中文简体查找翻译对象 |
||||
|
* |
||||
|
* @param chineseSimplified 中文简体内容 |
||||
|
* @return 翻译对象 |
||||
|
*/ |
||||
|
private Translation findTranslationByChinese(String chineseSimplified) { |
||||
|
// 先从缓存中查找 |
||||
|
if (translationCache.containsKey(chineseSimplified)) { |
||||
|
return translationCache.get(chineseSimplified); |
||||
|
} |
||||
|
|
||||
|
// 从数据库中精确查找 |
||||
|
Translation translation = translationService.findByChineseSimplified(chineseSimplified); |
||||
|
|
||||
|
if (translation != null) { |
||||
|
translationCache.put(chineseSimplified, translation); |
||||
|
return translation; |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 刷新整个缓存(当翻译数据有更新时调用) |
||||
|
*/ |
||||
|
public void refreshAllCache() { |
||||
|
translationCache.clear(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 从缓存中移除指定的翻译条目 |
||||
|
* @param chineseSimplified 简体中文原文 |
||||
|
*/ |
||||
|
public void removeFromCache(String chineseSimplified) { |
||||
|
if (chineseSimplified != null) { |
||||
|
translationCache.remove(chineseSimplified); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,153 @@ |
|||||
|
package com.example.demo.controller.coin; |
||||
|
|
||||
|
import com.example.demo.config.interfac.Log; |
||||
|
import com.example.demo.domain.DTO.TranslationQueryRequest; |
||||
|
import com.example.demo.domain.entity.Translation; |
||||
|
import com.example.demo.domain.vo.coin.Result; |
||||
|
import com.example.demo.service.coin.TranslationService; |
||||
|
import com.example.demo.Util.LanguageTranslationUtil; |
||||
|
import com.github.pagehelper.PageHelper; |
||||
|
import com.github.pagehelper.PageInfo; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/language") |
||||
|
@RequiredArgsConstructor |
||||
|
@Slf4j |
||||
|
@CrossOrigin |
||||
|
public class TranslationController { |
||||
|
|
||||
|
private final TranslationService translationService; |
||||
|
private final LanguageTranslationUtil languageTranslationUtil; |
||||
|
|
||||
|
// 查询所有翻译记录(可加条件) |
||||
|
@PostMapping("/getTranslation") |
||||
|
public Result getTranslations(@RequestBody TranslationQueryRequest request) { |
||||
|
try { |
||||
|
// 设置分页参数 |
||||
|
PageHelper.startPage(request.getPageNum(), request.getPageSize()); |
||||
|
|
||||
|
String chineseSimplified = request.getChineseSimplified(); |
||||
|
String languageStatus = request.getLanguageStatus(); |
||||
|
|
||||
|
List<Translation> translations; |
||||
|
|
||||
|
if (chineseSimplified != null && !chineseSimplified.isEmpty() && |
||||
|
languageStatus != null && !languageStatus.isEmpty()) { |
||||
|
// 同时存在模糊查询和语言状态查询 |
||||
|
String[] parts = languageStatus.split("/"); |
||||
|
if (parts.length != 2) { |
||||
|
return Result.error("languageStatus 参数格式错误,应为 'language/isTranslated'"); |
||||
|
} |
||||
|
String language = parts[0]; |
||||
|
boolean isTranslated = Boolean.parseBoolean(parts[1]); |
||||
|
translations = translationService.findByChineseSimplifiedAndLanguageStatus( |
||||
|
chineseSimplified, language, isTranslated); |
||||
|
} else if (chineseSimplified != null && !chineseSimplified.isEmpty()) { |
||||
|
// 只进行模糊查询 |
||||
|
translations = translationService.findByChineseSimplifiedLike(chineseSimplified); |
||||
|
} else if (languageStatus != null && !languageStatus.isEmpty()) { |
||||
|
// 只进行语言状态查询 |
||||
|
String[] parts = languageStatus.split("/"); |
||||
|
if (parts.length != 2) { |
||||
|
return Result.error("languageStatus 参数格式错误,应为 'language/isTranslated'"); |
||||
|
} |
||||
|
String language = parts[0]; |
||||
|
boolean isTranslated = Boolean.parseBoolean(parts[1]); |
||||
|
translations = translationService.findByLanguageAndTranslationStatus(language, isTranslated); |
||||
|
} else { |
||||
|
// 查询所有 |
||||
|
translations = translationService.findAll(); |
||||
|
} |
||||
|
|
||||
|
// 使用 PageInfo 封装分页结果 |
||||
|
PageInfo<Translation> pageInfo = new PageInfo<>(translations); |
||||
|
|
||||
|
// 构造返回数据 |
||||
|
Map<String, Object> resultData = new HashMap<>(); |
||||
|
resultData.put("list", pageInfo.getList()); |
||||
|
resultData.put("total", pageInfo.getTotal()); |
||||
|
resultData.put("pageNum", pageInfo.getPageNum()); |
||||
|
resultData.put("pageSize", pageInfo.getPageSize()); |
||||
|
|
||||
|
return Result.success(resultData); |
||||
|
} catch (IllegalArgumentException e) { |
||||
|
return Result.error("参数错误:" + e.getMessage()); |
||||
|
} catch (Exception e) { |
||||
|
log.error("查询翻译记录失败", e); |
||||
|
return Result.error("查询翻译记录失败"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 添加新的翻译记录 |
||||
|
@Log("添加翻译记录") |
||||
|
@PostMapping("/addTranslation") |
||||
|
public Result addTranslation(@RequestBody Translation translation) { |
||||
|
try { |
||||
|
boolean result = translationService.add(translation); |
||||
|
if (result) { |
||||
|
return Result.success("添加翻译记录成功"); |
||||
|
} else { |
||||
|
return Result.error("添加翻译记录失败"); |
||||
|
} |
||||
|
} catch (RuntimeException e) { |
||||
|
// 捕获重复插入异常 |
||||
|
if ("简体中文已存在".equals(e.getMessage())) { |
||||
|
return Result.error("添加翻译记录失败:简体中文已存在"); |
||||
|
} else { |
||||
|
log.error("添加翻译记录失败", e); |
||||
|
return Result.error("添加翻译记录失败"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 更新翻译记录 |
||||
|
@Log("更新翻译记录") |
||||
|
@PostMapping("/updateTranslation") |
||||
|
public Result updateTranslation(@RequestBody Translation translation) { |
||||
|
try { |
||||
|
boolean result = translationService.update(translation); |
||||
|
if (result) { |
||||
|
// 更新成功后刷新缓存 |
||||
|
languageTranslationUtil.refreshAllCache(); |
||||
|
return Result.success("更新翻译记录成功"); |
||||
|
} else { |
||||
|
return Result.error("更新翻译记录失败"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("更新翻译记录失败", e); |
||||
|
return Result.error("更新翻译记录失败"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 删除翻译记录 |
||||
|
@Log("删除翻译记录") |
||||
|
@PostMapping("/deleteTranslation") |
||||
|
public Result deleteTranslation(@RequestBody Translation request) { |
||||
|
try { |
||||
|
// 先获取要删除的记录,用于后续清理缓存 |
||||
|
Translation translationToDelete = translationService.findById(request.getId()); |
||||
|
|
||||
|
boolean result = translationService.deleteById(request.getId()); |
||||
|
if (result) { |
||||
|
// 删除成功后清理相关缓存 |
||||
|
if (translationToDelete != null) { |
||||
|
languageTranslationUtil.removeFromCache(translationToDelete.getChineseSimplified()); |
||||
|
} |
||||
|
return Result.success("删除翻译记录成功"); |
||||
|
} else { |
||||
|
return Result.error("删除翻译记录失败"); |
||||
|
} |
||||
|
} catch (Exception e) { |
||||
|
log.error("删除翻译记录失败", e); |
||||
|
return Result.error("删除翻译记录失败"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
package com.example.demo.domain.DTO; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class TranslationQueryRequest { |
||||
|
private int pageNum = 1; |
||||
|
private int pageSize = 10; |
||||
|
private String chineseSimplified; |
||||
|
private String languageStatus; // format: "language/isTranslated" e.g. "en/true" |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
package com.example.demo.domain.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 多语言配置实体类 |
||||
|
*/ |
||||
|
@Data |
||||
|
@NoArgsConstructor |
||||
|
public class Translation implements Serializable { |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
private Integer id; |
||||
|
private String chineseSimplified; // 中文(简体原文) |
||||
|
private String english; // 英语 |
||||
|
private String thai; // 泰语 |
||||
|
private String chineseTraditional; // 中文(繁体) |
||||
|
private String malay; // 马来语 |
||||
|
private String vietnamese; // 越南语 |
||||
|
private Date configTime; // 更新时间 |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
package com.example.demo.mapper.coin; |
||||
|
|
||||
|
import com.example.demo.domain.entity.Translation; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface TranslationMapper { |
||||
|
// 查询所有翻译记录 |
||||
|
List<Translation> findAll(); |
||||
|
|
||||
|
// 插入新的翻译记录 |
||||
|
int insert(Translation translation); |
||||
|
|
||||
|
// 更新翻译记录 |
||||
|
int update(Translation translation); |
||||
|
|
||||
|
// 删除翻译记录 |
||||
|
int deleteById(Integer id); |
||||
|
|
||||
|
// 根据部分中文简体内容模糊查询翻译记录 |
||||
|
List<Translation> findByChineseSimplifiedLike(@Param("chineseSimplified") String chineseSimplified); |
||||
|
|
||||
|
// 根据中文简体内容精确查询翻译记录 |
||||
|
Translation findByChineseSimplified(@Param("chineseSimplified") String chineseSimplified); |
||||
|
|
||||
|
// 根据语言和翻译状态查询翻译记录 |
||||
|
List<Translation> findByLanguageAndTranslationStatus( |
||||
|
@Param("languageColumn") String languageColumn, |
||||
|
@Param("isTranslated") boolean isTranslated |
||||
|
); |
||||
|
|
||||
|
List<Translation> findByChineseSimplifiedAndLanguageStatus( |
||||
|
@Param("chineseSimplified") String chineseSimplified, |
||||
|
@Param("languageColumn") String languageColumn, |
||||
|
@Param("isTranslated") boolean isTranslated |
||||
|
); |
||||
|
|
||||
|
Translation findById(Integer id); |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
package com.example.demo.service.coin; |
||||
|
|
||||
|
import com.example.demo.domain.entity.Translation; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface TranslationService { |
||||
|
// 查询所有翻译记录 |
||||
|
List<Translation> findAll(); |
||||
|
|
||||
|
// 添加新的翻译记录 |
||||
|
boolean add(Translation translation); |
||||
|
|
||||
|
// 更新翻译记录 |
||||
|
boolean update(Translation translation); |
||||
|
|
||||
|
// 删除翻译记录 |
||||
|
boolean deleteById(Integer id); |
||||
|
|
||||
|
// 根据部分中文简体内容模糊查询翻译记录 |
||||
|
List<Translation> findByChineseSimplifiedLike(String chineseSimplified); |
||||
|
|
||||
|
// 根据中文简体内容精确查询翻译记录 |
||||
|
Translation findByChineseSimplified(String chineseSimplified); |
||||
|
|
||||
|
// 根据语言和翻译状态查询翻译记录 |
||||
|
List<Translation> findByLanguageAndTranslationStatus(String language, boolean isTranslated); |
||||
|
|
||||
|
List<Translation> findByChineseSimplifiedAndLanguageStatus( |
||||
|
String chineseSimplified, |
||||
|
String language, |
||||
|
boolean isTranslated |
||||
|
); |
||||
|
|
||||
|
Translation findById(Integer id); |
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
package com.example.demo.serviceImpl.coin; |
||||
|
|
||||
|
import com.example.demo.domain.entity.Translation; |
||||
|
import com.example.demo.mapper.coin.TranslationMapper; |
||||
|
import com.example.demo.service.coin.TranslationService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Service |
||||
|
public class TranslationServiceImpl implements TranslationService { |
||||
|
|
||||
|
@Autowired |
||||
|
private TranslationMapper translationMapper; |
||||
|
|
||||
|
@Override |
||||
|
public List<Translation> findAll() { |
||||
|
return translationMapper.findAll(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean add(Translation translation) { |
||||
|
// 使用精确匹配检查是否存在相同的 chineseSimplified |
||||
|
Translation existingTranslation = translationMapper.findByChineseSimplified(translation.getChineseSimplified()); |
||||
|
if (existingTranslation != null) { |
||||
|
throw new RuntimeException("简体中文已存在"); |
||||
|
} |
||||
|
return translationMapper.insert(translation) > 0; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean update(Translation translation) { |
||||
|
return translationMapper.update(translation) > 0; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean deleteById(Integer id) { |
||||
|
return translationMapper.deleteById(id) > 0; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Translation> findByChineseSimplifiedLike(String chineseSimplified) { |
||||
|
return translationMapper.findByChineseSimplifiedLike(chineseSimplified); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Translation findByChineseSimplified(String chineseSimplified) { |
||||
|
return translationMapper.findByChineseSimplified(chineseSimplified); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Translation> findByLanguageAndTranslationStatus(String language, boolean isTranslated) { |
||||
|
// 语言字段映射关系 |
||||
|
Map<String, String> languageColumnMap = new HashMap<>(); |
||||
|
languageColumnMap.put("en", "english"); // 英语 |
||||
|
languageColumnMap.put("th", "thai"); // 泰语 |
||||
|
languageColumnMap.put("zh_TW", "chinese_traditional"); // 繁体中文 |
||||
|
languageColumnMap.put("ms", "malay"); // 马来语 |
||||
|
languageColumnMap.put("vi", "vietnamese"); // 越南语 |
||||
|
|
||||
|
String columnName = languageColumnMap.get(language.toLowerCase()); |
||||
|
if (columnName == null) { |
||||
|
throw new IllegalArgumentException("不支持的语言类型: " + language); |
||||
|
} |
||||
|
|
||||
|
return translationMapper.findByLanguageAndTranslationStatus(columnName, isTranslated); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Translation> findByChineseSimplifiedAndLanguageStatus( |
||||
|
String chineseSimplified, |
||||
|
String language, |
||||
|
boolean isTranslated) { |
||||
|
// 语言字段映射关系 |
||||
|
Map<String, String> languageColumnMap = new HashMap<>(); |
||||
|
languageColumnMap.put("en", "english"); // 英语 |
||||
|
languageColumnMap.put("th", "thai"); // 泰语 |
||||
|
languageColumnMap.put("zh_TW", "chinese_traditional"); // 繁体中文 |
||||
|
languageColumnMap.put("ms", "malay"); // 马来语 |
||||
|
languageColumnMap.put("vi", "vietnamese"); // 越南语 |
||||
|
|
||||
|
String columnName = languageColumnMap.get(language.toLowerCase()); |
||||
|
if (columnName == null) { |
||||
|
throw new IllegalArgumentException("不支持的语言类型: " + language); |
||||
|
} |
||||
|
return translationMapper.findByChineseSimplifiedAndLanguageStatus( |
||||
|
chineseSimplified, columnName, isTranslated); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Translation findById(Integer id) { |
||||
|
return translationMapper.findById(id); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,106 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.example.demo.mapper.coin.TranslationMapper"> |
||||
|
|
||||
|
<resultMap id="TranslationMap" type="com.example.demo.domain.entity.Translation"> |
||||
|
<id property="id" column="id"/> |
||||
|
<result property="chineseSimplified" column="chinese_simplified"/> |
||||
|
<result property="english" column="english"/> |
||||
|
<result property="thai" column="thai"/> |
||||
|
<result property="chineseTraditional" column="chinese_traditional"/> |
||||
|
<result property="malay" column="malay"/> |
||||
|
<result property="vietnamese" column="vietnamese"/> |
||||
|
<result property="configTime" column="config_time"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<!-- 查询所有翻译记录 --> |
||||
|
<select id="findAll" resultMap="TranslationMap"> |
||||
|
SELECT * FROM translation ORDER BY config_time DESC |
||||
|
</select> |
||||
|
|
||||
|
<!-- 插入新的翻译记录 --> |
||||
|
<insert id="insert" parameterType="com.example.demo.domain.entity.Translation"> |
||||
|
INSERT INTO translation ( |
||||
|
chinese_simplified, |
||||
|
english, |
||||
|
thai, |
||||
|
chinese_traditional, |
||||
|
malay, |
||||
|
vietnamese, |
||||
|
config_time |
||||
|
) VALUES ( |
||||
|
#{chineseSimplified}, |
||||
|
#{english}, |
||||
|
#{thai}, |
||||
|
#{chineseTraditional}, |
||||
|
#{malay}, |
||||
|
#{vietnamese}, |
||||
|
NOW() |
||||
|
) |
||||
|
</insert> |
||||
|
|
||||
|
<!-- 更新翻译记录 --> |
||||
|
<update id="update" parameterType="com.example.demo.domain.entity.Translation"> |
||||
|
UPDATE translation |
||||
|
<set> |
||||
|
<if test="chineseSimplified != null">chinese_simplified = #{chineseSimplified},</if> |
||||
|
<if test="english != null">english = #{english},</if> |
||||
|
<if test="thai != null">thai = #{thai},</if> |
||||
|
<if test="chineseTraditional != null">chinese_traditional = #{chineseTraditional},</if> |
||||
|
<if test="malay != null">malay = #{malay},</if> |
||||
|
<if test="vietnamese != null">vietnamese = #{vietnamese},</if> |
||||
|
config_time = NOW() |
||||
|
</set> |
||||
|
WHERE id = #{id} |
||||
|
</update> |
||||
|
|
||||
|
<!-- 删除翻译记录 --> |
||||
|
<delete id="deleteById"> |
||||
|
DELETE FROM translation WHERE id = #{id} |
||||
|
</delete> |
||||
|
|
||||
|
<!-- 根据部分中文简体内容模糊查询翻译记录 --> |
||||
|
<select id="findByChineseSimplifiedLike" resultMap="TranslationMap"> |
||||
|
SELECT * FROM translation |
||||
|
WHERE chinese_simplified LIKE CONCAT('%', #{chineseSimplified}, '%') |
||||
|
ORDER BY config_time DESC |
||||
|
</select> |
||||
|
|
||||
|
<select id="findByChineseSimplified" parameterType="string" resultType="com.example.demo.domain.entity.Translation"> |
||||
|
SELECT * FROM translation WHERE chinese_simplified = #{chineseSimplified} |
||||
|
ORDER BY config_time DESC |
||||
|
</select> |
||||
|
|
||||
|
<select id="findByLanguageAndTranslationStatus" resultMap="TranslationMap"> |
||||
|
SELECT * FROM translation |
||||
|
<where> |
||||
|
<choose> |
||||
|
<when test="isTranslated == true"> |
||||
|
${languageColumn} IS NOT NULL AND ${languageColumn} != '' |
||||
|
</when> |
||||
|
<otherwise> |
||||
|
${languageColumn} IS NULL OR ${languageColumn} = '' |
||||
|
</otherwise> |
||||
|
</choose> |
||||
|
</where> |
||||
|
ORDER BY config_time DESC |
||||
|
</select> |
||||
|
|
||||
|
<select id="findByChineseSimplifiedAndLanguageStatus" resultMap="TranslationMap"> |
||||
|
SELECT * FROM translation |
||||
|
WHERE chinese_simplified LIKE CONCAT('%', #{chineseSimplified}, '%') |
||||
|
<choose> |
||||
|
<when test="isTranslated == true"> |
||||
|
AND ${languageColumn} IS NOT NULL AND ${languageColumn} != '' |
||||
|
</when> |
||||
|
<otherwise> |
||||
|
AND (${languageColumn} IS NULL OR ${languageColumn} = '') |
||||
|
</otherwise> |
||||
|
</choose> |
||||
|
ORDER BY config_time DESC |
||||
|
</select> |
||||
|
|
||||
|
<select id="findById" parameterType="int" resultType="com.example.demo.domain.entity.Translation"> |
||||
|
SELECT * FROM translation WHERE id = #{id} |
||||
|
</select> |
||||
|
</mapper> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue