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 0000000000000000000000000000000000000000..b9fff96895aec412a5c5aa0cb4f9b84225020ebf --- /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 0000000000000000000000000000000000000000..d1a4f11517af650dc8888758037134dd3b996ebf --- /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 0000000000000000000000000000000000000000..512e3ab7f91e276149f2942ccec8064e37146320 --- /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 0000000000000000000000000000000000000000..b9e01f80566fd0a01f6790c12bd6936cdd025199 --- /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 0000000000000000000000000000000000000000..6fc01d785e813faa262810343ac805efa2c78f6d --- /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 0000000000000000000000000000000000000000..3c04fe3514a2bdc157b686f31eafaabc28ba7b14 --- /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 0000000000000000000000000000000000000000..44d52dbcd786b61308fa8f1037994ca4db23860a --- /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 0000000000000000000000000000000000000000..70f7fbc812d408e938121170705b688c18dff315 --- /dev/null +++ b/src/main/resources/mapper/AphorismPoetryMapper.xml @@ -0,0 +1,4 @@ + + + +