fix:添加问题

上级 ab106e39
......@@ -12,10 +12,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableScheduling
@EnableBatchProcessing
@SpringBootApplication
public class SpringBootKwanApplication {
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootKwanApplication.class, args);
SpringApplication.run(AppApplication.class, args);
System.out.println("------------------SpringBootKwan应用启动成功--------------------");
}
}
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.InterviewQuestion;
import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.service.InterviewQuestionService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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;
import java.io.Serializable;
import java.util.List;
/**
* 面试题(InterviewQuestion)表控制层
*
* @author makejava
* @since 2023-09-08 16:31:51
*/
@RestController
@RequestMapping("interviewQuestion")
public class InterviewQuestionController {
/**
* 服务对象
*/
@Resource
private InterviewQuestionService interviewQuestionService;
/**
* 导入问题
*
* @return 所有数据
*/
@GetMapping("/upload")
public Result uploadFile(@RequestParam String path) {
return Result.ok(this.interviewQuestionService.uploadFile(path));
}
/**
* 分页查询所有数据
*
* @param page 分页对象
* @param interviewQuestion 查询实体
* @return 所有数据
*/
@GetMapping
public Result selectAll(Page<InterviewQuestion> page, InterviewQuestion interviewQuestion) {
return Result.ok(this.interviewQuestionService.page(page, new QueryWrapper<>(interviewQuestion)));
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("{id}")
public Result selectOne(@PathVariable Serializable id) {
return Result.ok(this.interviewQuestionService.getById(id));
}
/**
* 新增数据
*
* @param interviewQuestion 实体对象
* @return 新增结果
*/
@PostMapping
public Result insert(@RequestBody InterviewQuestion interviewQuestion) {
return Result.ok(this.interviewQuestionService.save(interviewQuestion));
}
/**
* 修改数据
*
* @param interviewQuestion 实体对象
* @return 修改结果
*/
@PutMapping
public Result update(@RequestBody InterviewQuestion interviewQuestion) {
return Result.ok(this.interviewQuestionService.updateById(interviewQuestion));
}
/**
* 删除数据
*
* @param idList 主键结合
* @return 删除结果
*/
@DeleteMapping
public Result delete(@RequestParam("idList") List<Long> idList) {
return Result.ok(this.interviewQuestionService.removeByIds(idList));
}
}
package com.kwan.springbootkwan.entity;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import java.util.Date;
/**
* 面试题(InterviewQuestion)表实体类
*
* @author makejava
* @since 2023-09-08 16:31:53
*/
@Data
@SuppressWarnings("serial")
public class InterviewQuestion extends Model<InterviewQuestion> {
//主键id
private Integer id;
//面试问题
private String question;
//问题回答
private String response;
//知识类型,先默认0,后面再区分
private Integer type;
//创建时间
private Date createTime;
//逻辑删除,0未删除,1已删除
private Integer isDelete;
}
package com.kwan.springbootkwan.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kwan.springbootkwan.entity.InterviewQuestion;
/**
* 面试题(InterviewQuestion)表数据库访问层
*
* @author makejava
* @since 2023-09-08 16:31:51
*/
public interface InterviewQuestionMapper extends BaseMapper<InterviewQuestion> {
}
package com.kwan.springbootkwan.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kwan.springbootkwan.entity.InterviewQuestion;
/**
* 面试题(InterviewQuestion)表服务接口
*
* @author makejava
* @since 2023-09-08 16:31:53
*/
public interface InterviewQuestionService extends IService<InterviewQuestion> {
boolean uploadFile(String path);
}
package com.kwan.springbootkwan.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwan.springbootkwan.entity.InterviewQuestion;
import com.kwan.springbootkwan.mapper.InterviewQuestionMapper;
import com.kwan.springbootkwan.service.InterviewQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
/**
* 面试题(InterviewQuestion)表服务实现类
*
* @author makejava
* @since 2023-09-08 16:31:53
*/
@Slf4j
@Service("interviewQuestionService")
public class InterviewQuestionServiceImpl extends ServiceImpl<InterviewQuestionMapper, InterviewQuestion> implements InterviewQuestionService {
@Resource
private InterviewQuestionMapper interviewQuestionMapper;
@Override
public boolean uploadFile(String path) {
log.info("uploadFile() called with: path= {}", path);
// 定义文件路径
Path filePath = Paths.get(path);
try {
// 读取文件的所有行到List对象
List<String> lines = Files.readAllLines(filePath);
// 遍历List对象并输出每一行
for (String line : lines) {
QueryWrapper<InterviewQuestion> wrapper = new QueryWrapper<>();
wrapper.eq("question", line);// 按照 age 字段降序排列
final InterviewQuestion one = this.getOne(wrapper);
if (one == null) {
log.info("uploadFile() called with: question= {}", line);
InterviewQuestion interviewQuestion = new InterviewQuestion();
interviewQuestion.setQuestion(line);
interviewQuestion.setResponse("");
this.save(interviewQuestion);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = SpringBootKwanApplication.class)
@ContextConfiguration(classes = AppApplication.class)
public class SensitiveTest {
@Autowired
......
package com.kwan.springbootkwan.controller;
import com.kwan.springbootkwan.SpringBootKwanApplication;
import com.kwan.springbootkwan.AppApplication;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -10,7 +10,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = SpringBootKwanApplication.class)
@ContextConfiguration(classes = AppApplication.class)
class ChatbotControllerTest {
@Test
......
package com.kwan.springbootkwan.utils;
import com.kwan.springbootkwan.SpringBootKwanApplication;
import com.kwan.springbootkwan.AppApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -9,7 +9,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = SpringBootKwanApplication.class)
@ContextConfiguration(classes = AppApplication.class)
public class PinyinUtilTest {
@Test
......
package com.kwan.springbootkwan.utils;
import com.kwan.springbootkwan.SpringBootKwanApplication;
import com.kwan.springbootkwan.AppApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -8,7 +8,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = SpringBootKwanApplication.class)
@ContextConfiguration(classes = AppApplication.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SnowflakeUtilTest {
@Test
......
package com.kwan.springbootkwan.utils;
import com.kwan.springbootkwan.SpringBootKwanApplication;
import com.kwan.springbootkwan.AppApplication;
import org.jasypt.encryption.StringEncryptor;
import org.junit.Assert;
import org.junit.Test;
......@@ -20,7 +20,7 @@ import org.springframework.test.context.junit4.SpringRunner;
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = SpringBootKwanApplication.class)
@ContextConfiguration(classes = AppApplication.class)
public class StringEncryptorUtil {
@Autowired
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册