【新增】数据国际化支持

This commit is contained in:
2025-10-28 14:40:22 +08:00
parent e264cb15b9
commit 577b37b768
7 changed files with 21 additions and 7 deletions

View File

@@ -8,6 +8,8 @@ import com.corewing.app.entity.Course;
import com.corewing.app.entity.CourseCategory; import com.corewing.app.entity.CourseCategory;
import com.corewing.app.service.CourseCategoryService; import com.corewing.app.service.CourseCategoryService;
import com.corewing.app.service.CourseService; import com.corewing.app.service.CourseService;
import com.corewing.app.util.I18nUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@@ -20,6 +22,7 @@ import java.util.List;
*/ */
@RequestMapping("/course") @RequestMapping("/course")
@RestController @RestController
@Slf4j
public class CourseController { public class CourseController {
private final CourseService courseService; private final CourseService courseService;
@@ -40,8 +43,10 @@ public class CourseController {
public Result<List<CourseCategory>> category( public Result<List<CourseCategory>> category(
@RequestParam(required = false, defaultValue = "0") Integer firstStatus @RequestParam(required = false, defaultValue = "0") Integer firstStatus
) { ) {
log.info("当前语言环境:{}", I18nUtil.getCurrentLocale().getLanguage());
LambdaQueryWrapper<CourseCategory> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<CourseCategory> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(firstStatus != 0, CourseCategory::getFirstStatus, firstStatus); wrapper.eq(firstStatus != 0, CourseCategory::getFirstStatus, firstStatus);
wrapper.eq(CourseCategory::getLang, I18nUtil.getCurrentLocale().getLanguage());
List<CourseCategory> list = courseCategoryService.list(wrapper); List<CourseCategory> list = courseCategoryService.list(wrapper);
return Result.success(list); return Result.success(list);
} }
@@ -63,7 +68,7 @@ public class CourseController {
@RequestParam(required = false) String courseTitle) { @RequestParam(required = false) String courseTitle) {
try { try {
Page<Course> page = new Page<>(current, size); Page<Course> page = new Page<>(current, size);
IPage<Course> pageResult = courseService.pageList(page, categoryId, courseTitle); IPage<Course> pageResult = courseService.pageList(page, categoryId, courseTitle, I18nUtil.getCurrentLocale().getLanguage());
return Result.success(pageResult); return Result.success(pageResult);
} catch (Exception e) { } catch (Exception e) {
return Result.error(e.getMessage()); return Result.error(e.getMessage());

View File

@@ -53,6 +53,11 @@ public class Course implements Serializable {
*/ */
private Integer status; private Integer status;
/**
* 语言中文zh英文en
*/
private String lang;
/** /**
* 创建时间 * 创建时间
*/ */

View File

@@ -51,6 +51,11 @@ public class CourseCategory implements Serializable {
*/ */
private Integer status; private Integer status;
/**
* 语言中文zh英文en
*/
private String lang;
/** /**
* 创建时间 * 创建时间
*/ */

View File

@@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface CourseMapper extends BaseMapper<Course> { public interface CourseMapper extends BaseMapper<Course> {
Page<Course> pageList(Page<Course> page, @Param("categoryId") int categoryId, @Param("courseTitle") String courseTitle); Page<Course> pageList(Page<Course> page, @Param("categoryId") int categoryId, @Param("courseTitle") String courseTitle, @Param("lang") String lang);
} }

View File

@@ -6,5 +6,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.corewing.app.entity.Course; import com.corewing.app.entity.Course;
public interface CourseService extends IService<Course> { public interface CourseService extends IService<Course> {
IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle); IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle, String lang);
} }

View File

@@ -18,7 +18,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
} }
@Override @Override
public IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle) { public IPage<Course> pageList(Page<Course> page, int categoryId, String courseTitle, String lang) {
return courseMapper.pageList(page, categoryId, courseTitle); return courseMapper.pageList(page, categoryId, courseTitle, lang);
} }
} }

View File

@@ -24,13 +24,12 @@
left join app_course_category cc on cc.id = ccr.category_id left join app_course_category cc on cc.id = ccr.category_id
</sql> </sql>
<!-- 分页查询 --> <!-- 分页查询 -->
<select id="pageList" resultMap="VOResultMap"> <select id="pageList" resultMap="VOResultMap">
<include refid="selectVOSql"/> <include refid="selectVOSql"/>
<where> <where>
c.status = 1 c.status = 1
and c.lang = #{lang}
<if test="categoryId != null and categoryId != 0"> <if test="categoryId != null and categoryId != 0">
AND cc.id = #{categoryId} AND cc.id = #{categoryId}
</if> </if>