Commit a556a2b1 authored by Mindfaker's avatar Mindfaker

fix

parent 244590fd
...@@ -20,6 +20,21 @@ public class ClassService { ...@@ -20,6 +20,21 @@ public class ClassService {
@Resource @Resource
ClassInfoMapper classInfoMapper; ClassInfoMapper classInfoMapper;
public Map<Integer, String> getClassNameMap() {
ClassInfoExample example = new ClassInfoExample();
ClassInfoExample.Criteria criteria = example.createCriteria();
criteria.andDeletedEqualTo(false);
List<ClassInfo> dataList = classInfoMapper.selectByExample(example);
return dataList.stream().map(x -> {
Map oneData = new HashMap();
oneData.put(x.getId(), x.getClassName());
return oneData;
}).reduce(new HashMap(), (x, y) -> {
x.putAll(y);
return x;
});
}
public List<ClassInfo> selectClass(String className, List<Integer> idList) { public List<ClassInfo> selectClass(String className, List<Integer> idList) {
ClassInfoExample example = new ClassInfoExample(); ClassInfoExample example = new ClassInfoExample();
ClassInfoExample.Criteria criteria = example.createCriteria(); ClassInfoExample.Criteria criteria = example.createCriteria();
......
...@@ -4,6 +4,7 @@ import cn.exploring.engine.server.db.dao.SpecialSqlMapper; ...@@ -4,6 +4,7 @@ import cn.exploring.engine.server.db.dao.SpecialSqlMapper;
import cn.exploring.engine.server.db.dao.StudentInfoMapper; import cn.exploring.engine.server.db.dao.StudentInfoMapper;
import cn.exploring.engine.server.db.domain.StudentInfo; import cn.exploring.engine.server.db.domain.StudentInfo;
import cn.exploring.engine.server.db.domain.StudentInfoExample; import cn.exploring.engine.server.db.domain.StudentInfoExample;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -14,6 +15,7 @@ import java.time.LocalDateTime; ...@@ -14,6 +15,7 @@ import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
public class StudentInfoService { public class StudentInfoService {
...@@ -21,6 +23,9 @@ public class StudentInfoService { ...@@ -21,6 +23,9 @@ public class StudentInfoService {
@Resource @Resource
StudentInfoMapper studentInfoMapper; StudentInfoMapper studentInfoMapper;
@Resource
ClassService classService;
@Resource @Resource
SpecialSqlMapper specialSqlMapper; SpecialSqlMapper specialSqlMapper;
...@@ -120,10 +125,16 @@ public class StudentInfoService { ...@@ -120,10 +125,16 @@ public class StudentInfoService {
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
example.setOrderByClause(sort + " " + order); example.setOrderByClause(sort + " " + order);
List<StudentInfo> studentInfoList = studentInfoMapper.selectByExample(example); List<StudentInfo> studentInfoList = studentInfoMapper.selectByExample(example);
Map<Integer, String> classMap = classService.getClassNameMap();
List<Map> dataList = studentInfoList.stream().map(x -> {
Map oneData = JSON.parseObject(JSON.toJSONString(x), Map.class);
oneData.put("className", classMap.get(classId));
return oneData;
}).collect(Collectors.toList());
Long total = PageInfo.of(studentInfoList).getTotal(); Long total = PageInfo.of(studentInfoList).getTotal();
return new HashMap(){{ return new HashMap(){{
put("total", total); put("total", total);
put("items", studentInfoList); put("items", dataList);
}}; }};
} }
......
...@@ -30,7 +30,7 @@ public class StudentController { ...@@ -30,7 +30,7 @@ public class StudentController {
return ResponseUtil.ok(studentInfoService.selectStudentInfo(classId)); return ResponseUtil.ok(studentInfoService.selectStudentInfo(classId));
} }
@GetMapping("add") @PostMapping("add")
public Object add(@RequestBody StudentInfo studentInfo) { public Object add(@RequestBody StudentInfo studentInfo) {
String status = studentInfoService.addStudentInfo(studentInfo); String status = studentInfoService.addStudentInfo(studentInfo);
return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status); return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment