【优化】教程分类以及教程

This commit is contained in:
2025-11-03 18:41:15 +08:00
parent 3dbfff5f41
commit 2b92f29a17
8 changed files with 44 additions and 13 deletions

View File

@@ -75,5 +75,8 @@ public class Tutorial implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private Long categoryId; private Long categoryId;
@TableField(exist = false)
private String categoryName;
} }

View File

@@ -13,5 +13,7 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface TutorialMapper extends BaseMapper<Tutorial> { public interface TutorialMapper extends BaseMapper<Tutorial> {
Page<Tutorial> pageList(Page<Tutorial> page, @Param("categoryId") int categoryId, @Param("tutorialTitle") String tutorialTitle, @Param("lang") String lang); Page<Tutorial> pageList(Page<Tutorial> page, @Param("categoryId") Long categoryId, @Param("tutorialTitle") String tutorialTitle, @Param("lang") String lang);
Page<Tutorial> page(Page<Tutorial> page, @Param("tutorial") Tutorial tutorial);
} }

View File

@@ -96,11 +96,11 @@ public class AppTutorialController {
public Result<IPage<Tutorial>> getPageList( public Result<IPage<Tutorial>> getPageList(
@RequestParam(defaultValue = "1") Long current, @RequestParam(defaultValue = "1") Long current,
@RequestParam(defaultValue = "10") Long size, @RequestParam(defaultValue = "10") Long size,
@RequestParam(required = false, defaultValue = "0") Integer categoryId, @RequestParam(required = false, defaultValue = "0") Long categoryId,
@RequestParam(required = false) String tutorialTitle) { @RequestParam(required = false) String tutorialTitle) {
try { try {
Page<Tutorial> page = new Page<>(current, size); Page<Tutorial> page = new Page<>(current, size);
IPage<Tutorial> pageResult = tutorialService.pageList(page, categoryId, tutorialTitle, I18nUtil.getCurrentLocale().getLanguage()); Page<Tutorial> pageResult = tutorialService.pageList(page, categoryId, tutorialTitle, 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

@@ -7,7 +7,7 @@ import com.corewing.app.entity.Tutorial;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
public interface TutorialService extends IService<Tutorial> { public interface TutorialService extends IService<Tutorial> {
IPage<Tutorial> pageList(Page<Tutorial> page, int categoryId, String tutorialTitle, String lang); Page<Tutorial> pageList(Page<Tutorial> page, Long categoryId, String tutorialTitle, String lang);
Page<Tutorial> page(Tutorial tutorial); Page<Tutorial> page(Tutorial tutorial);

View File

@@ -26,16 +26,14 @@ public class TutorialServiceImpl extends ServiceImpl<TutorialMapper, Tutorial> i
private TutorialCategoryRelationService tutorialCategoryRelationService; private TutorialCategoryRelationService tutorialCategoryRelationService;
@Override @Override
public IPage<Tutorial> pageList(Page<Tutorial> page, int categoryId, String tutorialTitle, String lang) { public Page<Tutorial> pageList(Page<Tutorial> page, Long categoryId, String tutorialTitle, String lang) {
return tutorialMapper.pageList(page, categoryId, tutorialTitle, lang); return tutorialMapper.pageList(page, categoryId, tutorialTitle, lang);
} }
@Override @Override
public Page<Tutorial> page(Tutorial tutorial) { public Page<Tutorial> page(Tutorial tutorial) {
Page<Tutorial> page = PageContext.getPage(Tutorial.class); Page<Tutorial> page = PageContext.getPage(Tutorial.class);
LambdaQueryWrapper<Tutorial> queryWrapper = new LambdaQueryWrapper<>(); return tutorialMapper.page(page, tutorial);
queryWrapper.like(StringUtils.hasText(tutorial.getTutorialTitle()), Tutorial::getTutorialTitle, tutorial.getTutorialTitle());
return page(page, queryWrapper);
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)

View File

@@ -55,4 +55,8 @@ public class TutorialVO {
*/ */
private String categoryTitle; private String categoryTitle;
private String lang;
private Long categoryId;
} }

View File

@@ -11,14 +11,16 @@
<result column="view_count" property="viewCount"/> <result column="view_count" property="viewCount"/>
<result column="recommend_status" property="recommendStatus"/> <result column="recommend_status" property="recommendStatus"/>
<result column="status" property="status"/> <result column="status" property="status"/>
<result column="lang" property="lang"/>
<result column="category_title" property="categoryTitle"/> <result column="category_title" property="categoryTitle"/>
<result column="category_id" property="categoryId"/>
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/> <result column="update_time" property="updateTime"/>
</resultMap> </resultMap>
<!-- 基础查询SQL片段 --> <!-- 基础查询SQL片段 -->
<sql id="selectVOSql"> <sql id="selectVOSql">
select c.*, cc.category_title select c.*, cc.category_title, cc.id as category_id
from app_tutorial c from app_tutorial c
left join app_tutorial_category_relation ccr on c.id = ccr.tutorial_id left join app_tutorial_category_relation ccr on c.id = ccr.tutorial_id
left join app_tutorial_category cc on cc.id = ccr.category_id left join app_tutorial_category cc on cc.id = ccr.category_id
@@ -36,9 +38,28 @@
<if test="tutorialTitle != null and tutorialTitle != ''"> <if test="tutorialTitle != null and tutorialTitle != ''">
AND c.tutorial_title like CONCAT('%', #{tutorialTitle}, '%') AND c.tutorial_title like CONCAT('%', #{tutorialTitle}, '%')
</if> </if>
</where> </where>
ORDER BY c.recommend_status,c.create_time asc ORDER BY c.recommend_status,c.create_time asc
</select> </select>
<!-- 分页查询 -->
<select id="page" resultMap="VOResultMap">
<include refid="selectVOSql"/>
<where>
<if test="tutorial.categoryId != null and tutorial.categoryId != 0">
AND cc.id = #{tutorial.categoryId}
</if>
<if test="tutorial.tutorialTitle != null and tutorial.tutorialTitle != ''">
AND c.tutorial_title like CONCAT('%', #{tutorial.tutorialTitle}, '%')
</if>
<if test="tutorial.lang != null and tutorial.lang != ''">
AND c.lang = #{tutorial.lang}
</if>
<if test="tutorial.status != null">
AND c.status = #{tutorial.status}
</if>
</where>
</select>
</mapper> </mapper>

View File

@@ -514,6 +514,7 @@
status: 1, status: 1,
recommendStatus: 1, recommendStatus: 1,
lang: 'zh', lang: 'zh',
categoryId: 0,
}, },
// 教程分类 // 教程分类
categoryTableData: [], // 表格数据源 categoryTableData: [], // 表格数据源
@@ -624,7 +625,8 @@
} }
}); });
}, },
categoryQueryData() { categoryQueryData(item) {
this.searchParams.categoryId = item.id;
this.fetchData(); this.fetchData();
}, },
// 打开新增模态框 // 打开新增模态框
@@ -705,8 +707,8 @@
// 重置搜索 // 重置搜索
resetSearch() { resetSearch() {
this.searchParams = { this.searchParams = {
firmwareName: '', tutorialTitle: '',
firmwareType: '', status: '',
}; };
this.pageNum = 1; this.pageNum = 1;
this.fetchData(); this.fetchData();
@@ -734,6 +736,7 @@
openAddModal() { openAddModal() {
this.addOrEditTitle = '新增'; this.addOrEditTitle = '新增';
this.clearForm(); this.clearForm();
this.addOrEditDto.categoryId = this.categoryTableData[0]?.id;
this.modalInstances['addOrEditModel'].show(); this.modalInstances['addOrEditModel'].show();
}, },