From fa6c51df4e981bf0e0041626317ca4a686f1a918 Mon Sep 17 00:00:00 2001 From: guyue <1721849008@qq.com> Date: 星期三, 09 七月 2025 10:19:47 +0800 Subject: [PATCH] 采集列表 --- src/main/java/com/linghu/controller/OrderController.java | 10 ++++ src/main/java/com/linghu/model/dto/OrderDto.java | 4 ++ src/main/java/com/linghu/service/OrderService.java | 8 +++ src/main/java/com/linghu/service/impl/OrderServiceImpl.java | 35 ++++++++++++++++- src/main/java/com/linghu/model/dto/KeywordDto.java | 10 ++++- 5 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/linghu/controller/OrderController.java b/src/main/java/com/linghu/controller/OrderController.java index 8ce2d69..926ec33 100644 --- a/src/main/java/com/linghu/controller/OrderController.java +++ b/src/main/java/com/linghu/controller/OrderController.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.util.BeanUtil; import com.linghu.model.common.ResponseResult; import com.linghu.model.entity.Orders; +import com.linghu.model.dto.KeywordDto; import com.linghu.model.dto.OrderDto; import com.linghu.service.OrderService; @@ -63,7 +64,7 @@ order.setCreate_time(LocalDateTime.now()); boolean save = orderService.save(order); // 保存关键词 - boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto,order.getOrder_id()); + boolean saveOrderWithKeywords = orderService.saveOrderWithKeywords(orderDto, order.getOrder_id()); if (!saveOrderWithKeywords) { return ResponseResult.error("添加关键词失败"); } @@ -168,4 +169,11 @@ List<Orders> list = orderService.list(queryWrapper); return ResponseResult.success(list); } + + @GetMapping("/{orderId}/keywordList") + @ApiOperation("获取订单关联的关键词及提问词") + public ResponseResult<List<KeywordDto>> getKeywordList(@PathVariable String orderId) { + List<KeywordDto> result = orderService.getKeywordListByOrderId(orderId); + return ResponseResult.success(result); + } } \ No newline at end of file diff --git a/src/main/java/com/linghu/model/dto/KeywordDto.java b/src/main/java/com/linghu/model/dto/KeywordDto.java index a06bdf9..634adc8 100644 --- a/src/main/java/com/linghu/model/dto/KeywordDto.java +++ b/src/main/java/com/linghu/model/dto/KeywordDto.java @@ -1,9 +1,13 @@ package com.linghu.model.dto; - + import lombok.Data; import lombok.EqualsAndHashCode; + +import java.util.List; + import com.linghu.model.entity.Keyword; - +import com.linghu.model.entity.Question; + @EqualsAndHashCode(callSuper = true) @Data public class KeywordDto extends Keyword { @@ -11,4 +15,6 @@ * 提问词列表,用换行符分隔 */ private String questions; + + private List<Question> questionList; } \ No newline at end of file diff --git a/src/main/java/com/linghu/model/dto/OrderDto.java b/src/main/java/com/linghu/model/dto/OrderDto.java index 7d0fc1a..368ca44 100644 --- a/src/main/java/com/linghu/model/dto/OrderDto.java +++ b/src/main/java/com/linghu/model/dto/OrderDto.java @@ -4,6 +4,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; +import java.util.List; + /** * 订单数据传输对象,扩展Order实体 */ @@ -14,4 +16,6 @@ * 关键词列表,用换行符分隔 */ private String keywords; + + private List<KeywordDto> keywordList; } \ No newline at end of file diff --git a/src/main/java/com/linghu/service/OrderService.java b/src/main/java/com/linghu/service/OrderService.java index b696d51..3f91ffd 100644 --- a/src/main/java/com/linghu/service/OrderService.java +++ b/src/main/java/com/linghu/service/OrderService.java @@ -1,7 +1,11 @@ package com.linghu.service; import com.linghu.model.entity.Orders; +import com.linghu.model.dto.KeywordDto; import com.linghu.model.dto.OrderDto; + +import java.util.List; + import com.baomidou.mybatisplus.extension.service.IService; /** @@ -18,5 +22,7 @@ * @param orderDto 订单数据传输对象 * @return 是否保存成功 */ - boolean saveOrderWithKeywords(OrderDto orderDto,String order_id); + boolean saveOrderWithKeywords(OrderDto orderDto, String order_id); + + List<KeywordDto> getKeywordListByOrderId(String order_id); } diff --git a/src/main/java/com/linghu/service/impl/OrderServiceImpl.java b/src/main/java/com/linghu/service/impl/OrderServiceImpl.java index c2b03b3..92e7030 100644 --- a/src/main/java/com/linghu/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/linghu/service/impl/OrderServiceImpl.java @@ -1,12 +1,20 @@ package com.linghu.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.linghu.model.dto.KeywordDto; import com.linghu.model.dto.OrderDto; import com.linghu.model.entity.Keyword; import com.linghu.model.entity.Orders; +import com.linghu.model.entity.Question; import com.linghu.service.KeywordService; import com.linghu.service.OrderService; import com.linghu.mapper.OrderMapper; + +import java.util.ArrayList; +import java.util.List; + +import com.linghu.service.QuestionService; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,11 +31,12 @@ @Autowired private KeywordService keywordService; + @Autowired + private QuestionService questionService; @Override @Transactional(rollbackFor = Exception.class) - public boolean saveOrderWithKeywords(OrderDto orderDto,String order_id) { - + public boolean saveOrderWithKeywords(OrderDto orderDto, String order_id) { // 如果有关键词,则保存关键词 if (StringUtils.hasText(orderDto.getKeywords())) { @@ -82,4 +91,26 @@ return true; } + + @Override + public List<KeywordDto> getKeywordListByOrderId(String orderId) { + List<Keyword> keywords = keywordService.lambdaQuery() + .eq(Keyword::getOrder_id, orderId) + .list(); + + // 遍历关键词,获取每个关键词对应的提问词 + List<KeywordDto> keywordDtos = new ArrayList<>(); + for (Keyword keyword : keywords) { + KeywordDto dto = new KeywordDto(); + BeanUtils.copyProperties(keyword, dto); + + // 查询该关键词下的所有提问词 + List<Question> questions = questionService.lambdaQuery() + .eq(Question::getKeyword_id, keyword.getKeyword_id()) + .list(); + dto.setQuestionList(questions); + keywordDtos.add(dto); + } + return keywordDtos; + } } -- Gitblit v1.7.1