lrf 8 months ago
parent
commit
8861e7fb4c

+ 10 - 6
src/main/java/com/free/controller/HistoryController.java

@@ -7,6 +7,7 @@ import java.util.Map;
 import javax.validation.Valid;
 import javax.validation.Valid;
 
 
 import com.free.service.HistoryService;
 import com.free.service.HistoryService;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -35,6 +36,7 @@ import io.swagger.annotations.ApiOperation;
 public class HistoryController {
 public class HistoryController {
   @Autowired
   @Autowired
   private HistoryService service;
   private HistoryService service;
+  
 
 
   @PassToken
   @PassToken
   /** 创建数据 */
   /** 创建数据 */
@@ -61,10 +63,10 @@ public class HistoryController {
     }
     }
   }
   }
 
 
-  /** 修改数据 */
+  /** 修改数据, 接口不需要 */
   @PassToken
   @PassToken
   @ApiOperation("修改数据")
   @ApiOperation("修改数据")
-  @PostMapping("/{id}")
+  // @PostMapping("/{id}")
   public Object update(@PathVariable long id, @RequestBody History data) {
   public Object update(@PathVariable long id, @RequestBody History data) {
     QueryWrapper qw = new QueryWrapper<>();
     QueryWrapper qw = new QueryWrapper<>();
     qw.eq("id", id);
     qw.eq("id", id);
@@ -108,13 +110,15 @@ public class HistoryController {
     if (null != skip && null != limit) {
     if (null != skip && null != limit) {
       IPage page = new Page<>(skip, limit);
       IPage page = new Page<>(skip, limit);
       IPage pageResult = service.page(page, qw);
       IPage pageResult = service.page(page, qw);
-      List data = pageResult.getRecords();
+      List<History> data = pageResult.getRecords();
+      List<Map> newData = service.getQuestionsName(data);
       long total = pageResult.getTotal();
       long total = pageResult.getTotal();
-      map.put("data", data);
+      map.put("data", newData);
       map.put("total", total);
       map.put("total", total);
     } else {
     } else {
-      List list = service.list(qw);
-      map.put("data", list);
+      List<History> list = service.list(qw);
+      List<Map> newData = service.getQuestionsName(list);
+      map.put("data", newData);
     }
     }
     return ResponseFormat.success(map);
     return ResponseFormat.success(map);
   }
   }

+ 28 - 0
src/main/java/com/free/service/HistoryService.java

@@ -2,9 +2,37 @@ package com.free.service;
 
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.free.entity.History;
 import com.free.entity.History;
+import com.free.entity.Question;
 import com.free.mapper.HistoryMapper;
 import com.free.mapper.HistoryMapper;
+import com.free.utils.Utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 @Service
 @Service
 public class HistoryService extends ServiceImpl<HistoryMapper, History> {
 public class HistoryService extends ServiceImpl<HistoryMapper, History> {
+  @Autowired
+  private QuestionService questionService;
+  /**
+   * 根据question_id取出question的title
+   * @param list
+   * @return
+   */
+  public List<Map> getQuestionsName(List<History> list) {
+    List<Map> returnData = new ArrayList<>();
+    for (History i : list) {
+      Question q = questionService.getById(i.getId());
+      if (null == q) {
+        continue;
+      }
+      Map map = Utils.objectToMap(i);
+      map.put("question_name", q.getTitle());
+      returnData.add(map);
+    }
+    return returnData;
+  }
 }
 }