From 340333a4a0c466a81210288a5ee49adbbd39ecba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Mon, 9 Oct 2023 11:24:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=AF=97=E8=AF=8D=E7=9A=84=E5=90=8E?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AphorismPoetryController.java | 145 ++++++++++++++++++ .../springbootkwan/entity/AphorismPoetry.java | 34 ++++ .../entity/dto/AphorismPoetryDTO.java | 65 ++++++++ .../entity/query/AphorismPoetryQuery.java | 10 ++ .../mapper/AphorismPoetryMapper.java | 15 ++ .../service/AphorismPoetryService.java | 15 ++ .../impl/AphorismPoetryServiceImpl.java | 19 +++ .../resources/mapper/AphorismPoetryMapper.xml | 4 + 8 files changed, 307 insertions(+) create mode 100644 src/main/java/com/kwan/springbootkwan/controller/AphorismPoetryController.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/AphorismPoetry.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/dto/AphorismPoetryDTO.java create mode 100644 src/main/java/com/kwan/springbootkwan/entity/query/AphorismPoetryQuery.java create mode 100644 src/main/java/com/kwan/springbootkwan/mapper/AphorismPoetryMapper.java create mode 100644 src/main/java/com/kwan/springbootkwan/service/AphorismPoetryService.java create mode 100644 src/main/java/com/kwan/springbootkwan/service/impl/AphorismPoetryServiceImpl.java create mode 100644 src/main/resources/mapper/AphorismPoetryMapper.xml diff --git a/src/main/java/com/kwan/springbootkwan/controller/AphorismPoetryController.java b/src/main/java/com/kwan/springbootkwan/controller/AphorismPoetryController.java new file mode 100644 index 0000000..b9fff96 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/controller/AphorismPoetryController.java @@ -0,0 +1,145 @@ +package com.kwan.springbootkwan.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.kwan.springbootkwan.entity.AphorismPoetry; +import com.kwan.springbootkwan.entity.Result; +import com.kwan.springbootkwan.entity.dto.AphorismPoetryDTO; +import com.kwan.springbootkwan.entity.query.AphorismPoetryQuery; +import com.kwan.springbootkwan.service.AphorismPoetryService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 名言警句(AphorismPoetry)表控制层 + * + * @author makejava + * @since 2023-10-09 11:13:12 + */ +@RestController +@RequestMapping("aphorismPoetry") +public class AphorismPoetryController { + /** + * 服务对象 + */ + @Resource + private AphorismPoetryService aphorismPoetryService; + + /** + * 分页查询所有数据 + * + * @return 所有数据 + */ + @GetMapping("/page") + public Result selectAll(@RequestParam Integer page + , @RequestParam Integer pageSize + , @RequestParam String poetryText) { + Page pageParm = new Page<>(); + pageParm.setCurrent(page); + pageParm.setSize(pageSize); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.orderByDesc("id"); + wrapper.eq("is_delete", 0); + if (StringUtils.isNotEmpty(poetryText)) { + wrapper.like("poetry_text", poetryText); + } + return Result.ok(AphorismPoetryDTO.Converter.INSTANCE.from(this.aphorismPoetryService.page(pageParm, wrapper))); + } + + /** + * 随机一题 + */ + @GetMapping("/random") + public Result random() { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("is_delete", 0); + wrapper.orderByAsc("rand()").last("limit 1"); + return Result.ok(AphorismPoetryDTO.Converter.INSTANCE.from(this.aphorismPoetryService.getOne(wrapper))); + } + + /** + * 新增问题 + * + * @return 所有数据 + */ + @PostMapping("/add") + public Result add(@RequestBody AphorismPoetryQuery poetryQuery) { + final Integer addType = poetryQuery.getAddType(); + final String poetryText = poetryQuery.getPoetryText(); + if (StringUtils.isEmpty(poetryText)) { + return Result.error("内容不能为空"); + } + //批量添加 + if (addType == 1) { + final String[] split = poetryText.split("\n"); + for (String str : split) { + str = str.trim().replace("- ", ""); + if (StringUtils.isEmpty(str)) { + continue; + } + AphorismPoetry algorithmicProblem = new AphorismPoetry(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("poetry_text", str); + wrapper.eq("is_delete", 0); + final AphorismPoetry one = this.aphorismPoetryService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(poetryQuery, algorithmicProblem); + algorithmicProblem.setPoetryText(str); + this.aphorismPoetryService.save(algorithmicProblem); + } + } + } else { + AphorismPoetry aphorismPoetry = new AphorismPoetry(); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("poetry_text", poetryText); + wrapper.eq("is_delete", 0); + final AphorismPoetry one = this.aphorismPoetryService.getOne(wrapper); + if (one == null) { + BeanUtils.copyProperties(poetryQuery, aphorismPoetry); + this.aphorismPoetryService.save(aphorismPoetry); + return Result.ok(); + } else { + return Result.error("该诗词已存在"); + } + } + return Result.ok(); + } + + /** + * 更新面试题 + * + * @param query + * @return + */ + @PostMapping("/update") + public Result update(@RequestBody AphorismPoetryQuery query) { + AphorismPoetry aphorismPoetry = new AphorismPoetry(); + BeanUtils.copyProperties(query, aphorismPoetry); + return Result.ok(this.aphorismPoetryService.updateById(aphorismPoetry)); + } + + /** + * 删除面试题 + * + * @param id + * @return + */ + @GetMapping("/delete") + public Result delete(@RequestParam("id") Integer id) { + AphorismPoetry aphorismPoetry = new AphorismPoetry(); + aphorismPoetry.setIsDelete(1); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("id", id); + return Result.ok(this.aphorismPoetryService.update(aphorismPoetry, wrapper)); + } +} + diff --git a/src/main/java/com/kwan/springbootkwan/entity/AphorismPoetry.java b/src/main/java/com/kwan/springbootkwan/entity/AphorismPoetry.java new file mode 100644 index 0000000..d1a4f11 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/AphorismPoetry.java @@ -0,0 +1,34 @@ +package com.kwan.springbootkwan.entity; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; + +import java.util.Date; + +/** + * 名言警句(AphorismPoetry)表实体类 + * + * @author makejava + * @since 2023-10-09 11:13:13 + */ +@SuppressWarnings("serial") +@Data +public class AphorismPoetry extends Model { + /** + * 主键id + */ + private Integer id; + /** + * 诗词内容 + */ + private String poetryText; + /** + * 创建时间 + */ + private Date createTime; + /** + * 逻辑删除,0未删除,1已删除 + */ + private Integer isDelete; +} + diff --git a/src/main/java/com/kwan/springbootkwan/entity/dto/AphorismPoetryDTO.java b/src/main/java/com/kwan/springbootkwan/entity/dto/AphorismPoetryDTO.java new file mode 100644 index 0000000..512e3ab --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/dto/AphorismPoetryDTO.java @@ -0,0 +1,65 @@ +package com.kwan.springbootkwan.entity.dto; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import com.kwan.springbootkwan.entity.AphorismPoetry; +import com.kwan.springbootkwan.mapstruct.FromConverter; +import lombok.Data; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +import java.util.Date; + + +/** + * 诗词实体类 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/10/9 11:19 + */ +@Data +@SuppressWarnings("serial") +public class AphorismPoetryDTO extends Model { + /** + * 主键id + */ + private Integer id; + /** + * 面试问题 + */ + private String questionName; + /** + * 类型 + */ + private Integer questionType; + /** + * 1~10的分值 + */ + private Integer degreeOfImportance; + /** + * 1:简单;2:中等;3:困难 + */ + private Integer degreeOfDifficulty; + /** + * 困难指数 + */ + private Integer difficultyOfScore; + /** + * 力扣的问题号 + */ + private Integer leetcodeNumber; + /** + * 力扣的问题链接 + */ + private String leetcodeLink; + /** + * 创建时间 + */ + private Date createTime; + + @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) + public interface Converter extends FromConverter { + AphorismPoetryDTO.Converter INSTANCE = Mappers.getMapper(AphorismPoetryDTO.Converter.class); + } +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/entity/query/AphorismPoetryQuery.java b/src/main/java/com/kwan/springbootkwan/entity/query/AphorismPoetryQuery.java new file mode 100644 index 0000000..b9e01f8 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/entity/query/AphorismPoetryQuery.java @@ -0,0 +1,10 @@ +package com.kwan.springbootkwan.entity.query; + +import lombok.Data; + +@Data +public class AphorismPoetryQuery { + private Integer id; + private String poetryText; + private Integer addType; +} \ No newline at end of file diff --git a/src/main/java/com/kwan/springbootkwan/mapper/AphorismPoetryMapper.java b/src/main/java/com/kwan/springbootkwan/mapper/AphorismPoetryMapper.java new file mode 100644 index 0000000..6fc01d7 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/mapper/AphorismPoetryMapper.java @@ -0,0 +1,15 @@ +package com.kwan.springbootkwan.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.kwan.springbootkwan.entity.AphorismPoetry; + +/** + * 名言警句(AphorismPoetry)表数据库访问层 + * + * @author makejava + * @since 2023-10-09 11:13:12 + */ +public interface AphorismPoetryMapper extends BaseMapper { + +} + diff --git a/src/main/java/com/kwan/springbootkwan/service/AphorismPoetryService.java b/src/main/java/com/kwan/springbootkwan/service/AphorismPoetryService.java new file mode 100644 index 0000000..3c04fe3 --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/service/AphorismPoetryService.java @@ -0,0 +1,15 @@ +package com.kwan.springbootkwan.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.kwan.springbootkwan.entity.AphorismPoetry; + +/** + * 名言警句(AphorismPoetry)表服务接口 + * + * @author makejava + * @since 2023-10-09 11:13:13 + */ +public interface AphorismPoetryService extends IService { + +} + diff --git a/src/main/java/com/kwan/springbootkwan/service/impl/AphorismPoetryServiceImpl.java b/src/main/java/com/kwan/springbootkwan/service/impl/AphorismPoetryServiceImpl.java new file mode 100644 index 0000000..44d52db --- /dev/null +++ b/src/main/java/com/kwan/springbootkwan/service/impl/AphorismPoetryServiceImpl.java @@ -0,0 +1,19 @@ +package com.kwan.springbootkwan.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kwan.springbootkwan.mapper.AphorismPoetryMapper; +import com.kwan.springbootkwan.entity.AphorismPoetry; +import com.kwan.springbootkwan.service.AphorismPoetryService; +import org.springframework.stereotype.Service; + +/** + * 名言警句(AphorismPoetry)表服务实现类 + * + * @author makejava + * @since 2023-10-09 11:13:13 + */ +@Service("aphorismPoetryService") +public class AphorismPoetryServiceImpl extends ServiceImpl implements AphorismPoetryService { + +} + diff --git a/src/main/resources/mapper/AphorismPoetryMapper.xml b/src/main/resources/mapper/AphorismPoetryMapper.xml new file mode 100644 index 0000000..70f7fbc --- /dev/null +++ b/src/main/resources/mapper/AphorismPoetryMapper.xml @@ -0,0 +1,4 @@ + + + + -- GitLab