Commit 935baa11 authored by Mindfaker's avatar Mindfaker

补充controller层代码

parent 007a8317
......@@ -203,6 +203,33 @@ public interface SpecialSqlMapper {
)
Map selectUnfinishLessonCount(@Param("userId") Integer userId);
/**
* 打卡评分
* @param
* @return
*/
@Select("<script> " +
"SELECT t1.*, t2.class_name FROM " +
"(SELECT * FROM " +
"(SELECT id, student_unique_id, `name`, class_id FROM student_info WHERE deleted = FALSE " +
"<if test = 'studentName != null'> AND `name` like '%${studentName}%' </if>" +
"<if test = 'studentUniqueId != null'> AND student_unique_id like '%${studentUniqueId}%' </if>" +
"<if test = 'classId != null'> AND class_id = ${classId} </if>" +
") target_stu INNER JOIN (" +
"SELECT student_id, record_time, point FROM student_point_info WHERE deleted = FALSE " +
"<if test = 'startTime != null'> AND record_time &gt;= '${startTime}' </if>" +
"<if test = 'endTime != null'> AND '${endTime} ' &gt;= record_time </if>" +
" ) point_info ON target_stu.id = point_info.student_id) t1 " +
" LEFT JOIN (SELECT id, class_name FROM class_info WHERE deleted = FALSE ) t2 ON t1.class_id = t2.id"+
"ORDER by ${sort} ${order} " +
"LIMIT ${(page - 1) * size}, ${page * size} " +
"</script>"
)
List<Map> selectPoint(@Param("studentName") String studentName, @Param("studentUniqueId") String studentUniqueId,
@Param("classId") Integer classId, @Param("startTime") String startTime, @Param("endTime") String endTime,
@Param("page") Integer page, @Param("limit") Integer limit, @Param("sort") String sort, @Param("order") String order);
/**
* 随机选择一个的学生
* @param classId
......
package cn.exploring.engine.server.db.domain;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -66,6 +68,7 @@ public class StudentPointInfo {
*
* @mbg.generated
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime recordTime;
/**
......@@ -552,4 +555,4 @@ public class StudentPointInfo {
}
}
}
}
\ No newline at end of file
}
......@@ -3,12 +3,16 @@ package cn.exploring.engine.server.db.service;
import cn.exploring.engine.server.db.dao.ClassInfoMapper;
import cn.exploring.engine.server.db.domain.ClassInfo;
import cn.exploring.engine.server.db.domain.ClassInfoExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ClassService {
......@@ -16,16 +20,18 @@ public class ClassService {
@Resource
ClassInfoMapper classInfoMapper;
public List<ClassInfo> selectClass(String className) {
public List<ClassInfo> selectClass(String className, List<Integer> idList) {
ClassInfoExample example = new ClassInfoExample();
ClassInfoExample.Criteria criteria = example.createCriteria();
if (idList != null && idList.size() > 0) {
criteria.andIdIn(idList);
}
criteria.andDeletedEqualTo(false);
criteria.andClassNameEqualTo(className);
criteria.andDeletedEqualTo(false).andClassNameEqualTo(className);
return classInfoMapper.selectByExample(example);
}
public List<ClassInfo> webSelectClass(String className, List<Integer> idList) {
public Map webSelectClass(String className, Integer page, Integer limit, String sort, String order) {
ClassInfoExample example = new ClassInfoExample();
ClassInfoExample.Criteria criteria = example.createCriteria();
......@@ -33,11 +39,15 @@ public class ClassService {
if (!StringUtils.isEmpty(className)) {
criteria.andClassNameLike("%" + className + "%");
}
if (idList != null && idList.size() > 0) {
criteria.andIdIn(idList);
}
PageHelper.startPage(page, limit);
example.setOrderByClause(sort + " " + order);
criteria.andClassNameEqualTo(className);
return classInfoMapper.selectByExample(example);
List<ClassInfo> dataList = classInfoMapper.selectByExample(example);
Long total = PageInfo.of(dataList).getTotal();
return new HashMap(){{
put("total", total);
put("items", dataList);
}};
}
/**
......@@ -46,7 +56,7 @@ public class ClassService {
* @return
*/
public String addClassInfo(String className) {
List<ClassInfo> classInfoList = selectClass(className);
List<ClassInfo> classInfoList = selectClass(className, null);
if (classInfoList != null && classInfoList.size() != 0) {
return "fail 当前已存在该班级";
}
......@@ -67,7 +77,7 @@ public class ClassService {
}
public Object batchDeletedData(List<Integer> idList) {
List<ClassInfo> classInfoList = webSelectClass(null, idList);
List<ClassInfo> classInfoList = selectClass(null, idList);
classInfoList.forEach(x -> {
x.setDeleted(null);
updateClassInfo(x);
......
......@@ -4,11 +4,14 @@ import cn.exploring.engine.server.db.dao.SpecialSqlMapper;
import cn.exploring.engine.server.db.dao.StudentInfoMapper;
import cn.exploring.engine.server.db.domain.StudentInfo;
import cn.exploring.engine.server.db.domain.StudentInfoExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -21,17 +24,19 @@ public class StudentInfoService {
@Resource
SpecialSqlMapper specialSqlMapper;
/**
* 添加
* @param studentInfo
* @return
*/
public Object addStudentInfo(StudentInfo studentInfo) {
public String addStudentInfo(StudentInfo studentInfo) {
LocalDateTime now = LocalDateTime.now();
studentInfo.setAddTime(now);
studentInfo.setUpdateTime(now);
studentInfoMapper.insertSelective(studentInfo);
return "添加成功";
return "OK 添加成功";
}
/**
......@@ -51,7 +56,7 @@ public class StudentInfoService {
public Object updateStudentInfo(StudentInfo studentInfo) {
studentInfo.setUpdateTime(LocalDateTime.now());
studentInfoMapper.updateByPrimaryKey(studentInfo);
return "修改成功";
return "OK 修改成功";
}
/**
......@@ -90,6 +95,38 @@ public class StudentInfoService {
return studentInfoMapper.selectByExample(example);
}
/**
* 检索学生相关的信息
* @param studentName
* @param studentId
* @return
*/
public Map selectStudentInfoByWeb(String studentName, String studentId, List<Integer> idList, Integer classId, Integer page, Integer limit, String sort, String order) {
StudentInfoExample example = new StudentInfoExample();
StudentInfoExample.Criteria criteria = example.createCriteria();
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(studentName)) {
criteria.andNameLike("%" + studentName + "%");
}
if (!StringUtils.isEmpty(studentId)) {
criteria.andStudentUniqueIdLike("%" + studentId + "%");
}
if (idList != null && idList.size() > 0) {
criteria.andIdIn(idList);
}
if (classId != null) {
criteria.andClassIdEqualTo(classId);
}
PageHelper.startPage(page, limit);
example.setOrderByClause(sort + " " + order);
List<StudentInfo> studentInfoList = studentInfoMapper.selectByExample(example);
Long total = PageInfo.of(studentInfoList).getTotal();
return new HashMap(){{
put("total", total);
put("items", studentInfoList);
}};
}
}
package cn.exploring.engine.server.db.service;
import cn.exploring.engine.server.db.dao.SpecialSqlMapper;
import cn.exploring.engine.server.db.dao.StudentPointInfoMapper;
import cn.exploring.engine.server.db.domain.StudentPointInfo;
import cn.exploring.engine.server.db.domain.StudentPointInfoExample;
......@@ -8,6 +9,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@Service
public class StudentPointService {
......@@ -15,6 +17,13 @@ public class StudentPointService {
@Resource
StudentPointInfoMapper studentPointInfoMapper;
@Resource
SpecialSqlMapper specialSqlMapper;
public List<Map> selectPointByWeb( String studentName, String studentUniqueId, Integer classId, String startTime, String endTime, Integer page, Integer limit, String sort, String order) {
return specialSqlMapper.selectPoint(studentName, studentUniqueId, classId, startTime, endTime, page, limit, sort, order);
}
/**
* id 检索
* @param idList
......@@ -31,7 +40,7 @@ public class StudentPointService {
}
public Object addPoint(StudentPointInfo studentPoint) {
public String addPoint(StudentPointInfo studentPoint) {
LocalDateTime now = LocalDateTime.now();
studentPoint.setRecordTime(now);
studentPoint.setUpdateTime(now);
......
......@@ -3,12 +3,11 @@ package cn.exploring.engine.server.wx.web;
import cn.exploring.engine.server.core.util.ResponseUtil;
import cn.exploring.engine.server.db.domain.ClassInfo;
import cn.exploring.engine.server.db.service.ClassService;
import cn.exploring.engine.server.db.service.StudentPointService;
import cn.exploring.engine.server.wx.annotation.LoginUser;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/wx/class")
......@@ -18,12 +17,32 @@ public class ClassController {
@Resource
ClassService classService;
@GetMapping("selectClass")
public Object selectClass(@RequestParam String className, @RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit,
@RequestParam(required = false, defaultValue = "add_time") String sort, @RequestParam(required = false, defaultValue = "desc") String order) {
return ResponseUtil.ok(classService.webSelectClass(className, page, limit, sort, order));
}
@GetMapping("addClass")
public Object commitUserLessonRecord(@RequestParam String className) {
public Object addClass(@RequestParam String className) {
String status = classService.addClassInfo(className);
return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status);
}
@PostMapping("updateClass")
public Object updateClass(@RequestBody ClassInfo classInfo) {
classService.updateClassInfo(classInfo);
return ResponseUtil.ok("OK");
}
@PostMapping("batchDeleted")
public Object batchDeleted(@RequestBody List<Integer> idList) {
return ResponseUtil.ok(classService.batchDeletedData(idList));
}
}
package cn.exploring.engine.server.wx.web;
import cn.exploring.engine.server.core.util.ResponseUtil;
import cn.exploring.engine.server.db.service.ClassService;
import cn.exploring.engine.server.db.domain.StudentPointInfo;
import cn.exploring.engine.server.db.service.StudentPointService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/wx/point")
......@@ -19,7 +17,35 @@ public class PointController {
@Resource
StudentPointService pointService;
@GetMapping("selectPoint")
public Object selectPoint(@RequestParam String studentName, @RequestParam String studentUniqueId,@RequestParam Integer classId,@RequestParam String startTime,@RequestParam String endTime,
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit,
@RequestParam(required = false, defaultValue = "add_time") String sort, @RequestParam(required = false, defaultValue = "desc") String order) {
return ResponseUtil.ok(pointService.selectPointByWeb(studentName, studentUniqueId, classId, startTime, endTime, page, limit, sort, order));
}
@GetMapping("add")
public Object add(@RequestBody StudentPointInfo pointInfo) {
String status = pointService.addPoint(pointInfo);
return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status);
}
@PostMapping("update")
public Object update(@RequestBody StudentPointInfo pointInfo) {
pointService.updatePoint(pointInfo);
return ResponseUtil.ok("OK");
}
@PostMapping("batchDeleted")
public Object batchDeleted(@RequestBody List<Integer> idList) {
return ResponseUtil.ok(pointService.batchDeleted(idList));
}
}
package cn.exploring.engine.server.wx.web;
import cn.exploring.engine.server.core.util.ResponseUtil;
import cn.exploring.engine.server.db.domain.StudentInfo;
import cn.exploring.engine.server.db.service.StudentInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/wx/student")
@Validated
public class StudentController {
@Resource
StudentInfoService studentInfoService;
@GetMapping("selectStudent")
public Object selectClass(@RequestParam String studentName, @RequestParam String studentId, @RequestParam Integer classId,
@RequestParam(required = false, defaultValue = "1") Integer page, @RequestParam(required = false, defaultValue = "10") Integer limit,
@RequestParam(required = false, defaultValue = "add_time") String sort, @RequestParam(required = false, defaultValue = "desc") String order) {
return ResponseUtil.ok(studentInfoService.selectStudentInfoByWeb(studentName, studentId, null, classId, page, limit, sort, order));
}
@GetMapping("randomSelect")
public Object randomSelect(@RequestParam Integer classId) {
return ResponseUtil.ok(studentInfoService.selectStudentInfo(classId));
}
@GetMapping("add")
public Object add(@RequestBody StudentInfo studentInfo) {
String status = studentInfoService.addStudentInfo(studentInfo);
return status.contains("OK") ? ResponseUtil.ok(status) : ResponseUtil.fail(502, status);
}
@PostMapping("update")
public Object update(@RequestBody StudentInfo studentInfo) {
studentInfoService.updateStudentInfo(studentInfo);
return ResponseUtil.ok("OK");
}
@PostMapping("batchDeleted")
public Object batchDeleted(@RequestBody List<Integer> idList) {
return ResponseUtil.ok(studentInfoService.batchDeleted(idList));
}
}
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