From f04385a306ef2d64fc39675adedf9e811a202e84 Mon Sep 17 00:00:00 2001 From: MichaelWin Date: Mon, 3 Nov 2025 18:18:37 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E6=95=99?= =?UTF-8?q?=E7=A8=8B=E6=8C=87=E5=8D=97=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tutorial/BatchTutorialDeleteRequest.java | 10 + .../tutorial/CategoryBatchDeleteRequest.java | 10 + .../com/corewing/app/entity/Tutorial.java | 12 +- .../corewing/app/entity/TutorialCategory.java | 14 +- .../admin/biz/BizTutorialController.java | 143 +++ .../admin/sys/SysFirmwareController.java | 19 - .../app/service/TutorialCategoryService.java | 4 + .../corewing/app/service/TutorialService.java | 9 + .../impl/TutorialCategoryServiceImpl.java | 13 + .../app/service/impl/TutorialServiceImpl.java | 53 +- .../templates/admin/biz/tutorial/index.html | 915 ++++++++++++++++++ 11 files changed, 1171 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/corewing/app/dto/biz/tutorial/BatchTutorialDeleteRequest.java create mode 100644 src/main/java/com/corewing/app/dto/biz/tutorial/CategoryBatchDeleteRequest.java create mode 100644 src/main/java/com/corewing/app/modules/admin/biz/BizTutorialController.java delete mode 100644 src/main/java/com/corewing/app/modules/admin/sys/SysFirmwareController.java create mode 100644 src/main/resources/templates/admin/biz/tutorial/index.html diff --git a/src/main/java/com/corewing/app/dto/biz/tutorial/BatchTutorialDeleteRequest.java b/src/main/java/com/corewing/app/dto/biz/tutorial/BatchTutorialDeleteRequest.java new file mode 100644 index 0000000..14be5eb --- /dev/null +++ b/src/main/java/com/corewing/app/dto/biz/tutorial/BatchTutorialDeleteRequest.java @@ -0,0 +1,10 @@ +package com.corewing.app.dto.biz.tutorial; + +import lombok.Data; + +import java.util.List; + +@Data +public class BatchTutorialDeleteRequest { + private List ids; +} diff --git a/src/main/java/com/corewing/app/dto/biz/tutorial/CategoryBatchDeleteRequest.java b/src/main/java/com/corewing/app/dto/biz/tutorial/CategoryBatchDeleteRequest.java new file mode 100644 index 0000000..01a66b9 --- /dev/null +++ b/src/main/java/com/corewing/app/dto/biz/tutorial/CategoryBatchDeleteRequest.java @@ -0,0 +1,10 @@ +package com.corewing.app.dto.biz.tutorial; + +import lombok.Data; + +import java.util.List; + +@Data +public class CategoryBatchDeleteRequest { + private List ids; +} diff --git a/src/main/java/com/corewing/app/entity/Tutorial.java b/src/main/java/com/corewing/app/entity/Tutorial.java index bb2d1ba..12bb76f 100644 --- a/src/main/java/com/corewing/app/entity/Tutorial.java +++ b/src/main/java/com/corewing/app/entity/Tutorial.java @@ -1,8 +1,6 @@ package com.corewing.app.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -62,12 +60,20 @@ public class Tutorial implements Serializable { /** * 创建时间 */ + @TableField(fill = FieldFill.INSERT) private Date createTime; /** * 更新时间 */ + @TableField(fill = FieldFill.UPDATE) private Date updateTime; + /** + * 教程分类id + */ + @TableField(exist = false) + private Long categoryId; + } diff --git a/src/main/java/com/corewing/app/entity/TutorialCategory.java b/src/main/java/com/corewing/app/entity/TutorialCategory.java index 21a078d..3c34982 100644 --- a/src/main/java/com/corewing/app/entity/TutorialCategory.java +++ b/src/main/java/com/corewing/app/entity/TutorialCategory.java @@ -1,12 +1,11 @@ package com.corewing.app.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; +import java.time.LocalDateTime; import java.util.Date; /** @@ -65,11 +64,16 @@ public class TutorialCategory implements Serializable { /** * 创建时间 */ - private Date createTime; + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createTime; /** * 更新时间 */ - private Date updateTime; + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime updateTime; + + public static final String typeCategory = "category"; + public static final String typeTag = "tag"; } diff --git a/src/main/java/com/corewing/app/modules/admin/biz/BizTutorialController.java b/src/main/java/com/corewing/app/modules/admin/biz/BizTutorialController.java new file mode 100644 index 0000000..cd1c4ea --- /dev/null +++ b/src/main/java/com/corewing/app/modules/admin/biz/BizTutorialController.java @@ -0,0 +1,143 @@ +package com.corewing.app.modules.admin.biz; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.corewing.app.common.Result; +import com.corewing.app.dto.biz.tutorial.CategoryBatchDeleteRequest; +import com.corewing.app.entity.Tutorial; +import com.corewing.app.entity.TutorialCategory; +import com.corewing.app.service.TutorialCategoryService; +import com.corewing.app.service.TutorialService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +/** + * 教程指南 + */ +@Controller +@RequestMapping("/biz/tutorial") +public class BizTutorialController { + + @Resource + private TutorialCategoryService tutorialCategoryService; + + @Resource + private TutorialService tutorialService; + + + /** + * 教程分页 + * @param tutorial + * @return + */ + @GetMapping("/page") + @ResponseBody + public Result> page(Tutorial tutorial) { + return Result.success(tutorialService.page(tutorial)); + } + + /** + * 新增教程 + * @param tutorial + * @return + */ + @PostMapping("/save") + @ResponseBody + public Result save(@RequestBody Tutorial tutorial) { + return Result.isBool(tutorialService.save(tutorial)); + } + + /** + * 更新教程 + * @param tutorial + * @return + */ + @PostMapping("/update") + @ResponseBody + public Result update(@RequestBody Tutorial tutorial) { + return Result.isBool(tutorialService.updateById(tutorial)); + } + + /** + * 删除教程 + * @param id + * @return + */ + @DeleteMapping("/delete") + @ResponseBody + public Result delete(Long id) { + return Result.isBool(tutorialService.remove(id)); + } + + + + /** + * 教程管理首页 + * @return + */ + @GetMapping("/index") + public String index() { + return "admin/biz/tutorial/index"; + } + + /** + * 教程分类分页 + * @param tutorialCategory + * @return + */ + @GetMapping("/category/page") + @ResponseBody + public Result> categoryPage(TutorialCategory tutorialCategory) { + return Result.success(tutorialCategoryService.page(tutorialCategory)); + } + + /** + * 新增教程分类 + * @param tutorialCategory + * @return + */ + @PostMapping("/category/save") + @ResponseBody + public Result saveCategory(@RequestBody TutorialCategory tutorialCategory) { + tutorialCategory.setType(TutorialCategory.typeCategory); + return Result.isBool(tutorialCategoryService.save(tutorialCategory)); + } + + /** + * 更新教程分类 + * @param tutorialCategory + * @return + */ + @PostMapping("/category/update") + @ResponseBody + public Result updateCategory(@RequestBody TutorialCategory tutorialCategory) { + return Result.isBool(tutorialCategoryService.updateById(tutorialCategory)); + } + + /** + * 删除教程分类 + * @param id + * @return + */ + @DeleteMapping("/category/delete") + @ResponseBody + public Result deleteCategory(Long id) { + return Result.isBool(tutorialCategoryService.removeById(id)); + } + + /** + * 批量删除教程分类 + * @param categoryBatchDeleteRequest + * @return + */ + @PostMapping("/category/batchDelete") + @ResponseBody + public Result batchDeleteCategory(@RequestBody CategoryBatchDeleteRequest categoryBatchDeleteRequest) { + return Result.isBool(tutorialCategoryService.removeBatchByIds(categoryBatchDeleteRequest.getIds())); + } + + + + +} diff --git a/src/main/java/com/corewing/app/modules/admin/sys/SysFirmwareController.java b/src/main/java/com/corewing/app/modules/admin/sys/SysFirmwareController.java deleted file mode 100644 index e08cf64..0000000 --- a/src/main/java/com/corewing/app/modules/admin/sys/SysFirmwareController.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.corewing.app.modules.admin.sys; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * 固件管理 - */ -@Controller -@RequestMapping("/sys/firmware") -public class SysFirmwareController { - - @GetMapping("/index") - public String index() { - return "admin/sys/firmware/index"; - } - -} diff --git a/src/main/java/com/corewing/app/service/TutorialCategoryService.java b/src/main/java/com/corewing/app/service/TutorialCategoryService.java index fc1b2f5..e154e22 100644 --- a/src/main/java/com/corewing/app/service/TutorialCategoryService.java +++ b/src/main/java/com/corewing/app/service/TutorialCategoryService.java @@ -1,7 +1,11 @@ package com.corewing.app.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.corewing.app.entity.TutorialCategory; public interface TutorialCategoryService extends IService { + + Page page(TutorialCategory tutorialCategory); + } diff --git a/src/main/java/com/corewing/app/service/TutorialService.java b/src/main/java/com/corewing/app/service/TutorialService.java index 2c74498..df8758c 100644 --- a/src/main/java/com/corewing/app/service/TutorialService.java +++ b/src/main/java/com/corewing/app/service/TutorialService.java @@ -4,7 +4,16 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.corewing.app.entity.Tutorial; +import org.springframework.web.bind.annotation.RequestBody; public interface TutorialService extends IService { IPage pageList(Page page, int categoryId, String tutorialTitle, String lang); + + Page page(Tutorial tutorial); + + boolean save(Tutorial tutorial); + + boolean update(Tutorial tutorial); + + boolean remove(Long id); } diff --git a/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java b/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java index 06bf878..ef19cb7 100644 --- a/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java +++ b/src/main/java/com/corewing/app/service/impl/TutorialCategoryServiceImpl.java @@ -1,11 +1,24 @@ package com.corewing.app.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.common.page.PageContext; import com.corewing.app.entity.TutorialCategory; import com.corewing.app.mapper.TutorialCategoryMapper; import com.corewing.app.service.TutorialCategoryService; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; @Service public class TutorialCategoryServiceImpl extends ServiceImpl implements TutorialCategoryService { + + public Page page(TutorialCategory tutorialCategory){ + Page page = PageContext.getPage(TutorialCategory.class); + + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.like(StringUtils.hasText(tutorialCategory.getCategoryTitle()), TutorialCategory::getCategoryTitle, tutorialCategory.getCategoryTitle()); + return page(page, queryWrapper); + } + } diff --git a/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java b/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java index a9e1827..fbc6cbe 100644 --- a/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java +++ b/src/main/java/com/corewing/app/service/impl/TutorialServiceImpl.java @@ -1,24 +1,69 @@ package com.corewing.app.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.common.page.PageContext; import com.corewing.app.entity.Tutorial; +import com.corewing.app.entity.TutorialCategoryRelation; import com.corewing.app.mapper.TutorialMapper; +import com.corewing.app.service.TutorialCategoryRelationService; import com.corewing.app.service.TutorialService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; @Service public class TutorialServiceImpl extends ServiceImpl implements TutorialService { - private final TutorialMapper tutorialMapper; + @Resource + private TutorialMapper tutorialMapper; - public TutorialServiceImpl(TutorialMapper tutorialMapper) { - this.tutorialMapper = tutorialMapper; - } + @Resource + private TutorialCategoryRelationService tutorialCategoryRelationService; @Override public IPage pageList(Page page, int categoryId, String tutorialTitle, String lang) { return tutorialMapper.pageList(page, categoryId, tutorialTitle, lang); } + + @Override + public Page page(Tutorial tutorial) { + Page page = PageContext.getPage(Tutorial.class); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.like(StringUtils.hasText(tutorial.getTutorialTitle()), Tutorial::getTutorialTitle, tutorial.getTutorialTitle()); + return page(page, queryWrapper); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean save(Tutorial tutorial) { + super.save(tutorial); + TutorialCategoryRelation tutorialCategoryRelation = new TutorialCategoryRelation(); + tutorialCategoryRelation.setTutorialId(tutorial.getId()); + tutorialCategoryRelation.setCategoryId(tutorial.getCategoryId()); + return tutorialCategoryRelationService.save(tutorialCategoryRelation); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean update(Tutorial tutorial) { + super.updateById(tutorial); + tutorialCategoryRelationService.remove(new LambdaQueryWrapper().eq(TutorialCategoryRelation::getCategoryId, tutorial.getCategoryId())); + TutorialCategoryRelation tutorialCategoryRelation = new TutorialCategoryRelation(); + tutorialCategoryRelation.setTutorialId(tutorial.getId()); + tutorialCategoryRelation.setCategoryId(tutorial.getCategoryId()); + return tutorialCategoryRelationService.save(tutorialCategoryRelation); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public boolean remove(Long id) { + Tutorial tutorial = getById(id); + removeById(id); + return tutorialCategoryRelationService.remove(new LambdaQueryWrapper().eq(TutorialCategoryRelation::getCategoryId, tutorial.getCategoryId())); + } } diff --git a/src/main/resources/templates/admin/biz/tutorial/index.html b/src/main/resources/templates/admin/biz/tutorial/index.html new file mode 100644 index 0000000..849c2a6 --- /dev/null +++ b/src/main/resources/templates/admin/biz/tutorial/index.html @@ -0,0 +1,915 @@ + + + + + + 教程管理 + + + + + + + + + + + + + + +
+
+
+

分类管理

+ + + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
名称颜色操作
+
+
+ Loading... +
+

加载中,请稍候...

+
+
+
+ +
暂无匹配数据
+

请尝试调整搜索条件或重置查询

+
+
{{ item.categoryTitle }} +
+
+
+ + + +
+
+
+ +
+
+
+ +
+
+
+
+
+

教程管理

+ + + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
名称描述推荐状态查看次数操作
+
+
+ Loading... +
+

加载中,请稍候...

+
+
+
+ +
暂无匹配数据
+

请尝试调整搜索条件或重置查询

+
+
{{ item.tutorialTitle }}{{ item.description }} + + {{ item.recommendStatus === 1 ? '推荐' : '不推荐' }} + + + + {{ item.status === 1 ? '启用' : '禁用' }} + + {{ item.viewCount }} +
+ + +
+
+
+ +
+
+ 共 {{ total }} 条数据,当前第 {{ pageNum }}/{{ totalPages }} 页 +
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file