mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 18:46:36 +08:00
commit:同步1.3版本
This commit is contained in:
@@ -83,12 +83,12 @@
|
||||
<orderEntry type="library" name="Maven: tk.mybatis:mapper-spring:1.1.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: tk.mybatis:mapper-extra:1.1.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: tk.mybatis:mapper-spring-boot-autoconfigure:2.1.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.2.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.2.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.1.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-starter:1.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper-spring-boot-autoconfigure:1.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:3.2" level="project" />
|
||||
<orderEntry type="module" module-name="common-swagger" />
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-micro-spring-boot-starter:2.0.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.xiaoymin:knife4j-spring-boot-autoconfigure:2.0.5" level="project" />
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.orange.demo.courseclassservice.controller;
|
||||
import io.swagger.annotations.Api;
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.core.base.service.IBaseDictService;
|
||||
import com.orange.demo.common.core.util.MyModelUtil;
|
||||
import com.orange.demo.common.core.object.*;
|
||||
import com.orange.demo.courseclassinterface.vo.AreaCodeVo;
|
||||
@@ -30,7 +30,7 @@ public class AreaCodeController extends BaseController<AreaCode, AreaCodeVo, Lon
|
||||
private AreaCodeService areaCodeService;
|
||||
|
||||
@Override
|
||||
protected BaseService<AreaCode, Long> service() {
|
||||
protected IBaseDictService<AreaCode, Long> service() {
|
||||
return areaCodeService;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,13 @@ import com.orange.demo.common.core.object.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.constant.*;
|
||||
import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
import com.orange.demo.common.core.annotation.MyRequestBody;
|
||||
import com.orange.demo.common.core.validator.UpdateGroup;
|
||||
import com.orange.demo.common.redis.cache.SessionCacheHelper;
|
||||
import com.orange.demo.courseclassservice.config.ApplicationConfig;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -54,7 +53,7 @@ public class CourseController extends BaseController<Course, CourseVo, Long> {
|
||||
private UpDownloaderFactory upDownloaderFactory;
|
||||
|
||||
@Override
|
||||
protected BaseService<Course, Long> service() {
|
||||
protected IBaseService<Course, Long> service() {
|
||||
return courseService;
|
||||
}
|
||||
|
||||
@@ -298,7 +297,7 @@ public class CourseController extends BaseController<Course, CourseVo, Long> {
|
||||
*/
|
||||
@GetMapping("/listDict")
|
||||
public ResponseResult<List<Map<String, Object>>> listDict(Course filter) {
|
||||
List<Course> resultList = courseService.getListByFilter(filter, null);
|
||||
List<Course> resultList = courseService.getListByFilter(filter);
|
||||
return ResponseResult.success(
|
||||
BeanQuery.select("courseId as id", "courseName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.orange.demo.courseclassservice.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import cn.jimmyshi.beanquery.BeanQuery;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseDictService;
|
||||
import com.orange.demo.common.core.base.service.IBaseDictService;
|
||||
import com.orange.demo.common.core.constant.ErrorCodeEnum;
|
||||
import com.orange.demo.common.core.object.*;
|
||||
import com.orange.demo.common.core.util.MyModelUtil;
|
||||
@@ -39,7 +40,7 @@ public class GradeController extends BaseController<Grade, GradeVo, Integer> {
|
||||
private GradeService gradeService;
|
||||
|
||||
@Override
|
||||
protected BaseDictService<Grade, Integer> service() {
|
||||
protected IBaseDictService<Grade, Integer> service() {
|
||||
return gradeService;
|
||||
}
|
||||
|
||||
@@ -121,18 +122,34 @@ public class GradeController extends BaseController<Grade, GradeVo, Integer> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 以字典形式返回全部年级数据集合。
|
||||
* 白名单接口,登录用户均可访问。
|
||||
* 白名单接口,登录用户均可访问。以字典形式返回全部年级数据集合。
|
||||
* 所有数据全部取自于缓存,对于数据库中存在,但是缓存中不存在的数据,不会返回。
|
||||
*
|
||||
* @return 应答结果对象,包含字典形式的数据集合。
|
||||
*/
|
||||
@GetMapping("/listDict")
|
||||
public ResponseResult<List<Map<String, Object>>> listDict() {
|
||||
List<Grade> resultList = gradeService.getAllList();
|
||||
List<Grade> resultList = gradeService.getAllListFromCache();
|
||||
return ResponseResult.success(BeanQuery.select(
|
||||
"gradeId as id", "gradeName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 白名单接口,登录用户均可访问。以字典形式返回全部年级数据集合。
|
||||
* fullResultList中的字典列表全部取自于数据库,而cachedResultList全部取自于缓存,前端负责比对。
|
||||
*
|
||||
* @return 应答结果对象,包含字典形式的数据集合。
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
public ResponseResult<JSONObject> listAll() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("fullResultList", BeanQuery.select(
|
||||
"gradeId as id", "gradeName as name").executeFrom(gradeService.getAllList()));
|
||||
jsonObject.put("cachedResultList", BeanQuery.select(
|
||||
"gradeId as id", "gradeName as name").executeFrom(gradeService.getAllListFromCache()));
|
||||
return ResponseResult.success(jsonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键Id集合,获取数据对象集合。仅限于微服务间远程接口调用。
|
||||
*
|
||||
|
||||
@@ -10,12 +10,11 @@ import com.orange.demo.common.core.object.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.constant.*;
|
||||
import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
import com.orange.demo.common.core.annotation.MyRequestBody;
|
||||
import com.orange.demo.common.core.validator.UpdateGroup;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -39,7 +38,7 @@ public class SchoolInfoController extends BaseController<SchoolInfo, SchoolInfoV
|
||||
private SchoolInfoService schoolInfoService;
|
||||
|
||||
@Override
|
||||
protected BaseService<SchoolInfo, Long> service() {
|
||||
protected IBaseService<SchoolInfo, Long> service() {
|
||||
return schoolInfoService;
|
||||
}
|
||||
|
||||
@@ -49,7 +48,7 @@ public class SchoolInfoController extends BaseController<SchoolInfo, SchoolInfoV
|
||||
* @param schoolInfoDto 新增对象。
|
||||
* @return 应答结果对象,包含新增对象主键Id。
|
||||
*/
|
||||
@ApiOperationSupport(ignoreParameters = {"schoolInfo.userId"})
|
||||
@ApiOperationSupport(ignoreParameters = {"schoolInfo.schoolId"})
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<Long> add(@MyRequestBody("schoolInfo") SchoolInfoDto schoolInfoDto) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(schoolInfoDto);
|
||||
@@ -176,7 +175,7 @@ public class SchoolInfoController extends BaseController<SchoolInfo, SchoolInfoV
|
||||
*/
|
||||
@GetMapping("/listDict")
|
||||
public ResponseResult<List<Map<String, Object>>> listDict(SchoolInfo filter) {
|
||||
List<SchoolInfo> resultList = schoolInfoService.getListByFilter(filter, null);
|
||||
List<SchoolInfo> resultList = schoolInfoService.getListByFilter(filter);
|
||||
return ResponseResult.success(
|
||||
BeanQuery.select("schoolId as id", "schoolName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
@@ -9,12 +9,11 @@ import com.orange.demo.common.core.object.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.constant.*;
|
||||
import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
import com.orange.demo.common.core.annotation.MyRequestBody;
|
||||
import com.orange.demo.common.core.validator.UpdateGroup;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -43,7 +42,7 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
private StudentService studentService;
|
||||
|
||||
@Override
|
||||
protected BaseService<StudentClass, Long> service() {
|
||||
protected IBaseService<StudentClass, Long> service() {
|
||||
return studentClassService;
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
* @param studentClassDto 新增对象。
|
||||
* @return 应答结果对象,包含新增对象主键Id。
|
||||
*/
|
||||
@ApiOperationSupport(ignoreParameters = {"studentClass.userId"})
|
||||
@ApiOperationSupport(ignoreParameters = {"studentClass.classId"})
|
||||
@PostMapping("/add")
|
||||
public ResponseResult<Long> add(@MyRequestBody("studentClass") StudentClassDto studentClassDto) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(studentClassDto);
|
||||
@@ -187,11 +186,9 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
@MyRequestBody("courseFilter") CourseDto courseDtoFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (MyCommonUtil.existBlankArgument(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!studentClassService.existId(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
ResponseResult<Void> verifyResult = this.doClassCourseVerify(classId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
@@ -218,11 +215,9 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
@MyRequestBody("courseFilter") CourseDto courseDtoFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (MyCommonUtil.existBlankArgument(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!studentClassService.existId(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
ResponseResult<Void> verifyResult = this.doClassCourseVerify(classId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
@@ -234,6 +229,16 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(courseList, Course.INSTANCE));
|
||||
}
|
||||
|
||||
private ResponseResult<Void> doClassCourseVerify(Long classId) {
|
||||
if (MyCommonUtil.existBlankArgument(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!studentClassService.existId(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加班级数据和 [课程数据] 对象的多对多关联关系数据。
|
||||
*
|
||||
@@ -342,11 +347,9 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
@MyRequestBody("studentFilter") StudentDto studentDtoFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (MyCommonUtil.existBlankArgument(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!studentClassService.existId(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
ResponseResult<Void> verifyResult = this.doClassStudentVerify(classId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
@@ -373,11 +376,9 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
@MyRequestBody("studentFilter") StudentDto studentDtoFilter,
|
||||
@MyRequestBody MyOrderParam orderParam,
|
||||
@MyRequestBody MyPageParam pageParam) {
|
||||
if (MyCommonUtil.existBlankArgument(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!studentClassService.existId(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
ResponseResult<Void> verifyResult = this.doClassStudentVerify(classId);
|
||||
if (!verifyResult.isSuccess()) {
|
||||
return ResponseResult.errorFrom(verifyResult);
|
||||
}
|
||||
if (pageParam != null) {
|
||||
PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
@@ -389,6 +390,16 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
return ResponseResult.success(MyPageUtil.makeResponseData(studentList, Student.INSTANCE));
|
||||
}
|
||||
|
||||
private ResponseResult<Void> doClassStudentVerify(Long classId) {
|
||||
if (MyCommonUtil.existBlankArgument(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
if (!studentClassService.existId(classId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加班级数据和 [学生数据] 对象的多对多关联关系数据。
|
||||
*
|
||||
|
||||
@@ -10,12 +10,11 @@ import com.orange.demo.common.core.object.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.constant.*;
|
||||
import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
import com.orange.demo.common.core.annotation.MyRequestBody;
|
||||
import com.orange.demo.common.core.validator.UpdateGroup;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -39,7 +38,7 @@ public class StudentController extends BaseController<Student, StudentVo, Long>
|
||||
private StudentService studentService;
|
||||
|
||||
@Override
|
||||
protected BaseService<Student, Long> service() {
|
||||
protected IBaseService<Student, Long> service() {
|
||||
return studentService;
|
||||
}
|
||||
|
||||
@@ -188,7 +187,7 @@ public class StudentController extends BaseController<Student, StudentVo, Long>
|
||||
*/
|
||||
@GetMapping("/listDict")
|
||||
public ResponseResult<List<Map<String, Object>>> listDict(Student filter) {
|
||||
List<Student> resultList = studentService.getListByFilter(filter, null);
|
||||
List<Student> resultList = studentService.getListByFilter(filter);
|
||||
return ResponseResult.success(
|
||||
BeanQuery.select("studentId as id", "studentName as name").executeFrom(resultList));
|
||||
}
|
||||
|
||||
@@ -38,4 +38,4 @@ public class AreaCode {
|
||||
*/
|
||||
@Column(name = "parent_id")
|
||||
private Long parentId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.orange.demo.courseclassservice.model;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* ClassCourse实体对象。
|
||||
@@ -17,7 +16,6 @@ public class ClassCourse {
|
||||
/**
|
||||
* 班级Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,班级Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "class_id")
|
||||
private Long classId;
|
||||
@@ -25,7 +23,6 @@ public class ClassCourse {
|
||||
/**
|
||||
* 课程Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,课程Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "course_id")
|
||||
private Long courseId;
|
||||
@@ -33,7 +30,6 @@ public class ClassCourse {
|
||||
/**
|
||||
* 课程顺序(数值越小越靠前)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,课程顺序(数值越小越靠前)不能为空!")
|
||||
@Column(name = "course_order")
|
||||
private Integer courseOrder;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.orange.demo.courseclassservice.model;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* ClassStudent实体对象。
|
||||
@@ -17,7 +16,6 @@ public class ClassStudent {
|
||||
/**
|
||||
* 班级Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,班级Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "class_id")
|
||||
private Long classId;
|
||||
@@ -25,7 +23,6 @@ public class ClassStudent {
|
||||
/**
|
||||
* 学生Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,学生Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "student_id")
|
||||
private Long studentId;
|
||||
|
||||
@@ -7,13 +7,11 @@ import com.orange.demo.common.core.annotation.UploadFlagColumn;
|
||||
import com.orange.demo.common.core.annotation.RelationDict;
|
||||
import com.orange.demo.common.core.annotation.RelationConstDict;
|
||||
import com.orange.demo.common.core.base.mapper.BaseModelMapper;
|
||||
import com.orange.demo.common.core.validator.ConstDictRef;
|
||||
import com.orange.demo.courseclassinterface.vo.CourseVo;
|
||||
import lombok.Data;
|
||||
import org.mapstruct.*;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
@@ -32,7 +30,6 @@ public class Course {
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,主键Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "course_id")
|
||||
private Long courseId;
|
||||
@@ -40,14 +37,12 @@ public class Course {
|
||||
/**
|
||||
* 课程名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,课程名称不能为空!")
|
||||
@Column(name = "course_name")
|
||||
private String courseName;
|
||||
|
||||
/**
|
||||
* 课程价格。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,课程价格不能为空!")
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
@@ -58,29 +53,23 @@ public class Course {
|
||||
/**
|
||||
* 课程难度(0: 容易 1: 普通 2: 很难)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,课程难度不能为空!")
|
||||
@ConstDictRef(constDictClass = CourseDifficult.class, message = "数据验证失败,课程难度为无效值!")
|
||||
private Integer difficulty;
|
||||
|
||||
/**
|
||||
* 年级Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所属年级不能为空!")
|
||||
@Column(name = "grade_id")
|
||||
private Integer gradeId;
|
||||
|
||||
/**
|
||||
* 学科Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所属学科不能为空!")
|
||||
@ConstDictRef(constDictClass = Subject.class, message = "数据验证失败,所属学科为无效值!")
|
||||
@Column(name = "subject_id")
|
||||
private Integer subjectId;
|
||||
|
||||
/**
|
||||
* 课时数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,课时数量不能为空!")
|
||||
@Column(name = "class_hour")
|
||||
private Integer classHour;
|
||||
|
||||
@@ -88,7 +77,6 @@ public class Course {
|
||||
* 多张课程图片地址。
|
||||
*/
|
||||
@UploadFlagColumn(storeType = UploadStoreTypeEnum.LOCAL_SYSTEM)
|
||||
@NotBlank(message = "数据验证失败,课程图片不能为空!")
|
||||
@Column(name = "picture_url")
|
||||
private String pictureUrl;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.demo.common.core.annotation.DeletedFlagColumn;
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* Grade实体对象。
|
||||
@@ -19,7 +18,6 @@ public class Grade {
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,主键Id不能为空!")
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "grade_id")
|
||||
@@ -28,7 +26,6 @@ public class Grade {
|
||||
/**
|
||||
* 年级名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,年级名称不能为空!")
|
||||
@Column(name = "grade_name")
|
||||
private String gradeName;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.orange.demo.courseclassservice.model;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* MaterialEdition实体对象。
|
||||
@@ -17,7 +16,6 @@ public class MaterialEdition {
|
||||
/**
|
||||
* 主键Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,主键Id不能为空!")
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "edition_id")
|
||||
@@ -26,13 +24,11 @@ public class MaterialEdition {
|
||||
/**
|
||||
* 教材版本名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,教材版本名称不能为空!")
|
||||
@Column(name = "edition_name")
|
||||
private String editionName;
|
||||
|
||||
/**
|
||||
* 是否正在使用(0:不是,1:是)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,是否正在使用(0:不是,1:是)不能为空!")
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import lombok.Data;
|
||||
import org.mapstruct.*;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -24,7 +23,6 @@ public class SchoolInfo {
|
||||
/**
|
||||
* 学校Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,学校Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "school_id")
|
||||
private Long schoolId;
|
||||
@@ -32,21 +30,18 @@ public class SchoolInfo {
|
||||
/**
|
||||
* 学校名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,学校名称不能为空!")
|
||||
@Column(name = "school_name")
|
||||
private String schoolName;
|
||||
|
||||
/**
|
||||
* 所在省Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所在省份不能为空!")
|
||||
@Column(name = "province_id")
|
||||
private Long provinceId;
|
||||
|
||||
/**
|
||||
* 所在城市Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所在城市不能为空!")
|
||||
@Column(name = "city_id")
|
||||
private Long cityId;
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@ import com.orange.demo.application.common.constant.StudentStatus;
|
||||
import com.orange.demo.common.core.annotation.RelationDict;
|
||||
import com.orange.demo.common.core.annotation.RelationConstDict;
|
||||
import com.orange.demo.common.core.base.mapper.BaseModelMapper;
|
||||
import com.orange.demo.common.core.validator.ConstDictRef;
|
||||
import com.orange.demo.common.core.util.MyCommonUtil;
|
||||
import com.orange.demo.courseclassinterface.vo.StudentVo;
|
||||
import lombok.Data;
|
||||
import org.mapstruct.*;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
@@ -30,7 +29,6 @@ public class Student {
|
||||
/**
|
||||
* 学生Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,学生Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "student_id")
|
||||
private Long studentId;
|
||||
@@ -38,84 +36,70 @@ public class Student {
|
||||
/**
|
||||
* 登录手机。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,手机号码不能为空!")
|
||||
@Column(name = "login_mobile")
|
||||
private String loginMobile;
|
||||
|
||||
/**
|
||||
* 学生姓名。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,姓名不能为空!")
|
||||
@Column(name = "student_name")
|
||||
private String studentName;
|
||||
|
||||
/**
|
||||
* 所在省份Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所在省份不能为空!")
|
||||
@Column(name = "province_id")
|
||||
private Long provinceId;
|
||||
|
||||
/**
|
||||
* 所在城市Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所在城市不能为空!")
|
||||
@Column(name = "city_id")
|
||||
private Long cityId;
|
||||
|
||||
/**
|
||||
* 区县Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所在区县不能为空!")
|
||||
@Column(name = "district_id")
|
||||
private Long districtId;
|
||||
|
||||
/**
|
||||
* 学生性别 (0: 女生 1: 男生)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,性别不能为空!")
|
||||
@ConstDictRef(constDictClass = Gender.class, message = "数据验证失败,性别为无效值!")
|
||||
private Integer gender;
|
||||
|
||||
/**
|
||||
* 生日。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,生日不能为空!")
|
||||
private Date birthday;
|
||||
|
||||
/**
|
||||
* 经验等级 (0: 初级 1: 中级 2: 高级 3: 资深)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,经验等级不能为空!")
|
||||
@ConstDictRef(constDictClass = ExpLevel.class, message = "数据验证失败,经验等级为无效值!")
|
||||
@Column(name = "experience_level")
|
||||
private Integer experienceLevel;
|
||||
|
||||
/**
|
||||
* 总共充值学币数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,充值学币不能为空!")
|
||||
@Column(name = "total_coin")
|
||||
private Integer totalCoin;
|
||||
|
||||
/**
|
||||
* 可用学币数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,剩余学币不能为空!")
|
||||
@Column(name = "left_coin")
|
||||
private Integer leftCoin;
|
||||
|
||||
/**
|
||||
* 年级Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,年级不能为空!")
|
||||
@Column(name = "grade_id")
|
||||
private Integer gradeId;
|
||||
|
||||
/**
|
||||
* 校区Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所属校区不能为空!")
|
||||
@Column(name = "school_id")
|
||||
private Long schoolId;
|
||||
|
||||
@@ -128,8 +112,6 @@ public class Student {
|
||||
/**
|
||||
* 学生状态 (0: 正常 1: 锁定 2: 注销)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,状态 不能为空!")
|
||||
@ConstDictRef(constDictClass = StudentStatus.class, message = "数据验证失败,状态 为无效值!")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
@@ -162,6 +144,10 @@ public class Student {
|
||||
@Transient
|
||||
private String searchString;
|
||||
|
||||
public void setSearchString(String searchString) {
|
||||
this.searchString = MyCommonUtil.replaceSqlWildcard(searchString);
|
||||
}
|
||||
|
||||
@RelationDict(
|
||||
masterIdField = "provinceId",
|
||||
slaveServiceName = "areaCodeService",
|
||||
|
||||
@@ -6,13 +6,11 @@ import com.orange.demo.common.core.annotation.RelationDict;
|
||||
import com.orange.demo.common.core.annotation.RelationConstDict;
|
||||
import com.orange.demo.common.core.base.mapper.BaseModelMapper;
|
||||
import com.orange.demo.common.core.annotation.DeletedFlagColumn;
|
||||
import com.orange.demo.common.core.validator.ConstDictRef;
|
||||
import com.orange.demo.courseclassinterface.vo.StudentClassVo;
|
||||
import lombok.Data;
|
||||
import org.mapstruct.*;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
@@ -30,7 +28,6 @@ public class StudentClass {
|
||||
/**
|
||||
* 班级Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,班级Id不能为空!")
|
||||
@Id
|
||||
@Column(name = "class_id")
|
||||
private Long classId;
|
||||
@@ -38,36 +35,30 @@ public class StudentClass {
|
||||
/**
|
||||
* 班级名称。
|
||||
*/
|
||||
@NotBlank(message = "数据验证失败,班级名称不能为空!")
|
||||
@Column(name = "class_name")
|
||||
private String className;
|
||||
|
||||
/**
|
||||
* 学校Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,所属校区不能为空!")
|
||||
@Column(name = "school_id")
|
||||
private Long schoolId;
|
||||
|
||||
/**
|
||||
* 学生班长Id。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,班长不能为空!")
|
||||
@Column(name = "leader_id")
|
||||
private Long leaderId;
|
||||
|
||||
/**
|
||||
* 已完成课时数量。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,已完成课时不能为空!")
|
||||
@Column(name = "finish_class_hour")
|
||||
private Integer finishClassHour;
|
||||
|
||||
/**
|
||||
* 班级级别(0: 初级班 1: 培优班 2: 冲刺提分班 3: 竞赛班)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,班级级别不能为空!")
|
||||
@ConstDictRef(constDictClass = ClassLevel.class, message = "数据验证失败,班级级别为无效值!")
|
||||
@Column(name = "class_level")
|
||||
private Integer classLevel;
|
||||
|
||||
|
||||
@@ -1,49 +1,17 @@
|
||||
package com.orange.demo.courseclassservice.service;
|
||||
|
||||
import com.orange.demo.courseclassservice.dao.AreaCodeMapper;
|
||||
import com.orange.demo.courseclassservice.model.AreaCode;
|
||||
import com.orange.demo.common.core.cache.MapTreeDictionaryCache;
|
||||
import com.orange.demo.common.core.base.service.BaseDictService;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
import com.orange.demo.common.core.base.service.IBaseDictService;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区划的Service类。
|
||||
* 行政区划的Service接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service
|
||||
public class AreaCodeService extends BaseDictService<AreaCode, Long> {
|
||||
|
||||
@Autowired
|
||||
private AreaCodeMapper areaCodeMapper;
|
||||
|
||||
public AreaCodeService() {
|
||||
super();
|
||||
this.dictionaryCache = MapTreeDictionaryCache.create(AreaCode::getAreaId, AreaCode::getParentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseDaoMapper<AreaCode> mapper() {
|
||||
return areaCodeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载数据库数据到内存缓存。
|
||||
*/
|
||||
@Override
|
||||
public void loadCachedData() {
|
||||
Example e = new Example(AreaCode.class);
|
||||
e.orderBy("areaLevel");
|
||||
List<AreaCode> areaCodeList = areaCodeMapper.selectByExample(e);
|
||||
dictionaryCache.putAll(areaCodeList);
|
||||
}
|
||||
public interface AreaCodeService extends IBaseDictService<AreaCode, Long> {
|
||||
|
||||
/**
|
||||
* 根据上级行政区划Id,获取其下级行政区划列表。
|
||||
@@ -51,7 +19,5 @@ public class AreaCodeService extends BaseDictService<AreaCode, Long> {
|
||||
* @param parentId 上级行政区划Id。
|
||||
* @return 下级行政区划列表。
|
||||
*/
|
||||
public Collection<AreaCode> getListByParentId(Long parentId) {
|
||||
return ((MapTreeDictionaryCache<Long, AreaCode>) dictionaryCache).getListByParentId(parentId);
|
||||
}
|
||||
Collection<AreaCode> getListByParentId(Long parentId);
|
||||
}
|
||||
|
||||
@@ -1,48 +1,18 @@
|
||||
package com.orange.demo.courseclassservice.service;
|
||||
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import com.orange.demo.common.core.object.MyWhereCriteria;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 课程数据数据操作服务类。
|
||||
* 课程数据数据操作服务接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service
|
||||
public class CourseService extends BaseService<Course, Long> {
|
||||
|
||||
@Autowired
|
||||
private CourseMapper courseMapper;
|
||||
@Autowired
|
||||
private ClassCourseMapper classCourseMapper;
|
||||
@Autowired
|
||||
private GradeService gradeService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Course> mapper() {
|
||||
return courseMapper;
|
||||
}
|
||||
public interface CourseService extends IBaseService<Course, Long> {
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
@@ -50,17 +20,7 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param course 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Course saveNew(Course course) {
|
||||
course.setCourseId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
course.setCreateUserId(tokenData.getUserId());
|
||||
Date now = new Date();
|
||||
course.setCreateTime(now);
|
||||
course.setUpdateTime(now);
|
||||
courseMapper.insert(course);
|
||||
return course;
|
||||
}
|
||||
Course saveNew(Course course);
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
@@ -69,14 +29,7 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param originalCourse 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(Course course, Course originalCourse) {
|
||||
course.setCreateUserId(originalCourse.getCreateUserId());
|
||||
course.setCreateTime(originalCourse.getCreateTime());
|
||||
course.setUpdateTime(new Date());
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return courseMapper.updateByPrimaryKey(course) == 1;
|
||||
}
|
||||
boolean update(Course course, Course originalCourse);
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
@@ -84,19 +37,7 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param courseId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long courseId) {
|
||||
// 这里先删除主数据
|
||||
if (courseMapper.deleteByPrimaryKey(courseId) == 0) {
|
||||
return false;
|
||||
}
|
||||
// 这里可继续删除关联数据。
|
||||
// 开始删除与本地多对多父表的关联
|
||||
ClassCourse classCourse = new ClassCourse();
|
||||
classCourse.setCourseId(courseId);
|
||||
classCourseMapper.delete(classCourse);
|
||||
return true;
|
||||
}
|
||||
boolean remove(Long courseId);
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
@@ -106,9 +47,7 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Course> getCourseList(Course filter, String orderBy) {
|
||||
return courseMapper.getCourseList(null, null, filter, orderBy);
|
||||
}
|
||||
List<Course> getCourseList(Course filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -121,11 +60,7 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<Course> getCourseList(
|
||||
String inFilterField, Set<M> inFilterValues, Course filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, Course.class);
|
||||
return courseMapper.getCourseList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
<M> List<Course> getCourseList(String inFilterField, Set<M> inFilterValues, Course filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
@@ -135,12 +70,7 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Course> getCourseListWithRelation(Course filter, String orderBy) {
|
||||
List<Course> resultList = courseMapper.getCourseList(null, null, filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
List<Course> getCourseListWithRelation(Course filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -153,13 +83,8 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<Course> getCourseListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, Course filter, String orderBy) {
|
||||
List<Course> resultList =
|
||||
courseMapper.getCourseList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
<M> List<Course> getCourseListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, Course filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回不与指定主表主键Id存在对多对关系的列表。
|
||||
@@ -169,13 +94,8 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Course> getNotInCourseListByClassId(
|
||||
Long classId, Course filter, String orderBy) {
|
||||
List<Course> resultList =
|
||||
courseMapper.getNotInCourseListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
List<Course> getNotInCourseListByClassId(
|
||||
Long classId, Course filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回与指定主表主键Id存在对多对关系的列表。
|
||||
@@ -185,13 +105,8 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Course> getCourseListByClassId(
|
||||
Long classId, Course filter, String orderBy) {
|
||||
List<Course> resultList =
|
||||
courseMapper.getCourseListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
List<Course> getCourseListByClassId(
|
||||
Long classId, Course filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
@@ -200,12 +115,5 @@ public class CourseService extends BaseService<Course, Long> {
|
||||
* @param originalCourse 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
public CallResult verifyRelatedData(Course course, Course originalCourse) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(course, originalCourse, Course::getGradeId)
|
||||
&& !gradeService.existId(course.getGradeId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属年级"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
CallResult verifyRelatedData(Course course, Course originalCourse);
|
||||
}
|
||||
|
||||
@@ -1,98 +1,13 @@
|
||||
package com.orange.demo.courseclassservice.service;
|
||||
|
||||
import com.orange.demo.common.redis.cache.RedisDictionaryCache;
|
||||
import com.orange.demo.common.core.base.service.BaseDictService;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.demo.courseclassservice.dao.GradeMapper;
|
||||
import com.orange.demo.common.core.base.service.IBaseDictService;
|
||||
import com.orange.demo.courseclassservice.model.Grade;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 年级数据操作服务类。
|
||||
* 年级字典数据操作服务接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service
|
||||
public class GradeService extends BaseDictService<Grade, Integer> {
|
||||
|
||||
@Autowired
|
||||
private GradeMapper gradeMapper;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public GradeService() {
|
||||
super();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.dictionaryCache = RedisDictionaryCache.create(
|
||||
redissonClient, "Grade", Grade.class, Grade::getGradeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Grade> mapper() {
|
||||
return gradeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
*
|
||||
* @param grade 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Grade saveNew(Grade grade) {
|
||||
grade.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
gradeMapper.insert(grade);
|
||||
dictionaryCache.put(grade.getGradeId(), grade);
|
||||
return grade;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
*
|
||||
* @param grade 更新的对象。
|
||||
* @param originalGrade 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(Grade grade, Grade originalGrade) {
|
||||
grade.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
if (gradeMapper.updateByPrimaryKey(grade) != 1) {
|
||||
return false;
|
||||
}
|
||||
dictionaryCache.put(grade.getGradeId(), grade);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param gradeId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Integer gradeId) {
|
||||
Grade deletedObject = new Grade();
|
||||
deletedObject.setGradeId(gradeId);
|
||||
deletedObject.setStatus(GlobalDeletedFlag.DELETED);
|
||||
if (gradeMapper.updateByPrimaryKeySelective(deletedObject) != 1) {
|
||||
return false;
|
||||
}
|
||||
dictionaryCache.invalidate(gradeId);
|
||||
return true;
|
||||
}
|
||||
public interface GradeService extends IBaseDictService<Grade, Integer> {
|
||||
}
|
||||
|
||||
@@ -1,45 +1,18 @@
|
||||
package com.orange.demo.courseclassservice.service;
|
||||
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.object.MyWhereCriteria;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 校区数据数据操作服务类。
|
||||
* 校区数据数据操作服务接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service
|
||||
public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
|
||||
@Autowired
|
||||
private SchoolInfoMapper schoolInfoMapper;
|
||||
@Autowired
|
||||
private AreaCodeService areaCodeService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SchoolInfo> mapper() {
|
||||
return schoolInfoMapper;
|
||||
}
|
||||
public interface SchoolInfoService extends IBaseService<SchoolInfo, Long> {
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
@@ -47,12 +20,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param schoolInfo 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SchoolInfo saveNew(SchoolInfo schoolInfo) {
|
||||
schoolInfo.setSchoolId(idGenerator.nextLongId());
|
||||
schoolInfoMapper.insert(schoolInfo);
|
||||
return schoolInfo;
|
||||
}
|
||||
SchoolInfo saveNew(SchoolInfo schoolInfo);
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
@@ -61,11 +29,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param originalSchoolInfo 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo) {
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return schoolInfoMapper.updateByPrimaryKey(schoolInfo) == 1;
|
||||
}
|
||||
boolean update(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo);
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
@@ -73,10 +37,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param schoolId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long schoolId) {
|
||||
return schoolInfoMapper.deleteByPrimaryKey(schoolId) != 0;
|
||||
}
|
||||
boolean remove(Long schoolId);
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
@@ -86,9 +47,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<SchoolInfo> getSchoolInfoList(SchoolInfo filter, String orderBy) {
|
||||
return schoolInfoMapper.getSchoolInfoList(null, null, filter, orderBy);
|
||||
}
|
||||
List<SchoolInfo> getSchoolInfoList(SchoolInfo filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -101,11 +60,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<SchoolInfo> getSchoolInfoList(
|
||||
String inFilterField, Set<M> inFilterValues, SchoolInfo filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, SchoolInfo.class);
|
||||
return schoolInfoMapper.getSchoolInfoList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
<M> List<SchoolInfo> getSchoolInfoList(String inFilterField, Set<M> inFilterValues, SchoolInfo filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
@@ -115,12 +70,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<SchoolInfo> getSchoolInfoListWithRelation(SchoolInfo filter, String orderBy) {
|
||||
List<SchoolInfo> resultList = schoolInfoMapper.getSchoolInfoList(null, null, filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
List<SchoolInfo> getSchoolInfoListWithRelation(SchoolInfo filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -133,13 +83,8 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<SchoolInfo> getSchoolInfoListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, SchoolInfo filter, String orderBy) {
|
||||
List<SchoolInfo> resultList =
|
||||
schoolInfoMapper.getSchoolInfoList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
<M> List<SchoolInfo> getSchoolInfoListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, SchoolInfo filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
@@ -148,16 +93,5 @@ public class SchoolInfoService extends BaseService<SchoolInfo, Long> {
|
||||
* @param originalSchoolInfo 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
public CallResult verifyRelatedData(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(schoolInfo, originalSchoolInfo, SchoolInfo::getProvinceId)
|
||||
&& !areaCodeService.existId(schoolInfo.getProvinceId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在省份"));
|
||||
}
|
||||
if (this.needToVerify(schoolInfo, originalSchoolInfo, SchoolInfo::getCityId)
|
||||
&& !areaCodeService.existId(schoolInfo.getCityId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在城市"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
CallResult verifyRelatedData(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo);
|
||||
}
|
||||
|
||||
@@ -1,54 +1,18 @@
|
||||
package com.orange.demo.courseclassservice.service;
|
||||
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import com.orange.demo.common.core.object.MyWhereCriteria;
|
||||
import com.orange.demo.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 班级数据数据操作服务类。
|
||||
* 班级数据数据操作服务接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service
|
||||
public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
|
||||
@Autowired
|
||||
private StudentClassMapper studentClassMapper;
|
||||
@Autowired
|
||||
private ClassCourseMapper classCourseMapper;
|
||||
@Autowired
|
||||
private ClassStudentMapper classStudentMapper;
|
||||
@Autowired
|
||||
private SchoolInfoService schoolInfoService;
|
||||
@Autowired
|
||||
private StudentService studentService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<StudentClass> mapper() {
|
||||
return studentClassMapper;
|
||||
}
|
||||
public interface StudentClassService extends IBaseService<StudentClass, Long> {
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
@@ -56,16 +20,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param studentClass 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public StudentClass saveNew(StudentClass studentClass) {
|
||||
studentClass.setClassId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
studentClass.setCreateUserId(tokenData.getUserId());
|
||||
studentClass.setCreateTime(new Date());
|
||||
studentClass.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
studentClassMapper.insert(studentClass);
|
||||
return studentClass;
|
||||
}
|
||||
StudentClass saveNew(StudentClass studentClass);
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
@@ -74,14 +29,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param originalStudentClass 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(StudentClass studentClass, StudentClass originalStudentClass) {
|
||||
studentClass.setCreateUserId(originalStudentClass.getCreateUserId());
|
||||
studentClass.setCreateTime(originalStudentClass.getCreateTime());
|
||||
studentClass.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return studentClassMapper.updateByPrimaryKey(studentClass) == 1;
|
||||
}
|
||||
boolean update(StudentClass studentClass, StudentClass originalStudentClass);
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
@@ -89,27 +37,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param classId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long classId) {
|
||||
Example studentClassExample = new Example(StudentClass.class);
|
||||
Example.Criteria c = studentClassExample.createCriteria();
|
||||
c.andEqualTo(super.idFieldName, classId);
|
||||
c.andEqualTo(super.deletedFlagFieldName, GlobalDeletedFlag.NORMAL);
|
||||
// 这里先删除主数据
|
||||
StudentClass deletedObject = new StudentClass();
|
||||
deletedObject.setStatus(GlobalDeletedFlag.DELETED);
|
||||
if (studentClassMapper.updateByExampleSelective(deletedObject, studentClassExample) == 0) {
|
||||
return false;
|
||||
}
|
||||
// 开始删除多对多中间表的关联
|
||||
ClassCourse classCourse = new ClassCourse();
|
||||
classCourse.setClassId(classId);
|
||||
classCourseMapper.delete(classCourse);
|
||||
ClassStudent classStudent = new ClassStudent();
|
||||
classStudent.setClassId(classId);
|
||||
classStudentMapper.delete(classStudent);
|
||||
return true;
|
||||
}
|
||||
boolean remove(Long classId);
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
@@ -119,9 +47,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<StudentClass> getStudentClassList(StudentClass filter, String orderBy) {
|
||||
return studentClassMapper.getStudentClassList(null, null, filter, orderBy);
|
||||
}
|
||||
List<StudentClass> getStudentClassList(StudentClass filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -134,11 +60,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<StudentClass> getStudentClassList(
|
||||
String inFilterField, Set<M> inFilterValues, StudentClass filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, StudentClass.class);
|
||||
return studentClassMapper.getStudentClassList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
<M> List<StudentClass> getStudentClassList(String inFilterField, Set<M> inFilterValues, StudentClass filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
@@ -148,12 +70,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<StudentClass> getStudentClassListWithRelation(StudentClass filter, String orderBy) {
|
||||
List<StudentClass> resultList = studentClassMapper.getStudentClassList(null, null, filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
List<StudentClass> getStudentClassListWithRelation(StudentClass filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -166,13 +83,8 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<StudentClass> getStudentClassListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, StudentClass filter, String orderBy) {
|
||||
List<StudentClass> resultList =
|
||||
studentClassMapper.getStudentClassList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
<M> List<StudentClass> getStudentClassListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, StudentClass filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 批量添加多对多关联关系。
|
||||
@@ -180,16 +92,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param classCourseList 多对多关联表对象集合。
|
||||
* @param classId 主表Id。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addClassCourseList(List<ClassCourse> classCourseList, Long classId) {
|
||||
for (ClassCourse classCourse : classCourseList) {
|
||||
classCourse.setClassId(classId);
|
||||
if (classCourse.getCourseOrder() == null) {
|
||||
classCourse.setCourseOrder(0);
|
||||
}
|
||||
}
|
||||
classCourseMapper.insertList(classCourseList);
|
||||
}
|
||||
void addClassCourseList(List<ClassCourse> classCourseList, Long classId);
|
||||
|
||||
/**
|
||||
* 更新中间表数据。
|
||||
@@ -197,14 +100,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param classCourse 中间表对象。
|
||||
* @return 更新成功与否。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateClassCourse(ClassCourse classCourse) {
|
||||
Example e = new Example(ClassCourse.class);
|
||||
e.createCriteria()
|
||||
.andEqualTo("classId", classCourse.getClassId())
|
||||
.andEqualTo("courseId", classCourse.getCourseId());
|
||||
return classCourseMapper.updateByExample(classCourse, e) > 0;
|
||||
}
|
||||
boolean updateClassCourse(ClassCourse classCourse);
|
||||
|
||||
/**
|
||||
* 获取中间表数据。
|
||||
@@ -213,13 +109,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param courseId 从表Id。
|
||||
* @return 中间表对象。
|
||||
*/
|
||||
public ClassCourse getClassCourse(Long classId, Long courseId) {
|
||||
Example e = new Example(ClassCourse.class);
|
||||
e.createCriteria()
|
||||
.andEqualTo("classId", classId)
|
||||
.andEqualTo("courseId", courseId);
|
||||
return classCourseMapper.selectOneByExample(e);
|
||||
}
|
||||
ClassCourse getClassCourse(Long classId, Long courseId);
|
||||
|
||||
/**
|
||||
* 移除单条多对多关系。
|
||||
@@ -228,13 +118,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param courseId 从表Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean removeClassCourse(Long classId, Long courseId) {
|
||||
ClassCourse classCourse = new ClassCourse();
|
||||
classCourse.setClassId(classId);
|
||||
classCourse.setCourseId(courseId);
|
||||
return classCourseMapper.delete(classCourse) > 0;
|
||||
}
|
||||
boolean removeClassCourse(Long classId, Long courseId);
|
||||
|
||||
/**
|
||||
* 批量添加多对多关联关系。
|
||||
@@ -242,13 +126,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param classStudentList 多对多关联表对象集合。
|
||||
* @param classId 主表Id。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addClassStudentList(List<ClassStudent> classStudentList, Long classId) {
|
||||
for (ClassStudent classStudent : classStudentList) {
|
||||
classStudent.setClassId(classId);
|
||||
}
|
||||
classStudentMapper.insertList(classStudentList);
|
||||
}
|
||||
void addClassStudentList(List<ClassStudent> classStudentList, Long classId);
|
||||
|
||||
/**
|
||||
* 移除单条多对多关系。
|
||||
@@ -257,13 +135,7 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param studentId 从表Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean removeClassStudent(Long classId, Long studentId) {
|
||||
ClassStudent classStudent = new ClassStudent();
|
||||
classStudent.setClassId(classId);
|
||||
classStudent.setStudentId(studentId);
|
||||
return classStudentMapper.delete(classStudent) > 0;
|
||||
}
|
||||
boolean removeClassStudent(Long classId, Long studentId);
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
@@ -272,16 +144,5 @@ public class StudentClassService extends BaseService<StudentClass, Long> {
|
||||
* @param originalStudentClass 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
public CallResult verifyRelatedData(StudentClass studentClass, StudentClass originalStudentClass) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(studentClass, originalStudentClass, StudentClass::getSchoolId)
|
||||
&& !schoolInfoService.existId(studentClass.getSchoolId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属校区"));
|
||||
}
|
||||
if (this.needToVerify(studentClass, originalStudentClass, StudentClass::getLeaderId)
|
||||
&& !studentService.existId(studentClass.getLeaderId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "班长"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
CallResult verifyRelatedData(StudentClass studentClass, StudentClass originalStudentClass);
|
||||
}
|
||||
|
||||
@@ -1,52 +1,18 @@
|
||||
package com.orange.demo.courseclassservice.service;
|
||||
|
||||
import com.orange.demo.application.common.constant.StudentStatus;
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.object.MyWhereCriteria;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.orange.demo.common.core.base.service.IBaseService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 学生数据数据操作服务类。
|
||||
* 学生数据数据操作服务接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service
|
||||
public class StudentService extends BaseService<Student, Long> {
|
||||
|
||||
@Autowired
|
||||
private StudentMapper studentMapper;
|
||||
@Autowired
|
||||
private ClassStudentMapper classStudentMapper;
|
||||
@Autowired
|
||||
private SchoolInfoService schoolInfoService;
|
||||
@Autowired
|
||||
private AreaCodeService areaCodeService;
|
||||
@Autowired
|
||||
private GradeService gradeService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Student> mapper() {
|
||||
return studentMapper;
|
||||
}
|
||||
public interface StudentService extends IBaseService<Student, Long> {
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
@@ -54,22 +20,7 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param student 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Student saveNew(Student student) {
|
||||
student.setStudentId(idGenerator.nextLongId());
|
||||
student.setRegisterTime(new Date());
|
||||
if (student.getTotalCoin() == null) {
|
||||
student.setTotalCoin(0);
|
||||
}
|
||||
if (student.getLeftCoin() == null) {
|
||||
student.setLeftCoin(0);
|
||||
}
|
||||
if (student.getStatus() == null) {
|
||||
student.setStatus(StudentStatus.NORMAL);
|
||||
}
|
||||
studentMapper.insert(student);
|
||||
return student;
|
||||
}
|
||||
Student saveNew(Student student);
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
@@ -78,12 +29,7 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param originalStudent 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(Student student, Student originalStudent) {
|
||||
student.setRegisterTime(originalStudent.getRegisterTime());
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return studentMapper.updateByPrimaryKey(student) == 1;
|
||||
}
|
||||
boolean update(Student student, Student originalStudent);
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
@@ -91,19 +37,7 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param studentId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Long studentId) {
|
||||
// 这里先删除主数据
|
||||
if (studentMapper.deleteByPrimaryKey(studentId) == 0) {
|
||||
return false;
|
||||
}
|
||||
// 这里可继续删除关联数据。
|
||||
// 开始删除与本地多对多父表的关联
|
||||
ClassStudent classStudent = new ClassStudent();
|
||||
classStudent.setStudentId(studentId);
|
||||
classStudentMapper.delete(classStudent);
|
||||
return true;
|
||||
}
|
||||
boolean remove(Long studentId);
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
@@ -113,9 +47,7 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Student> getStudentList(Student filter, String orderBy) {
|
||||
return studentMapper.getStudentList(null, null, filter, orderBy);
|
||||
}
|
||||
List<Student> getStudentList(Student filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -128,11 +60,7 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<Student> getStudentList(
|
||||
String inFilterField, Set<M> inFilterValues, Student filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, Student.class);
|
||||
return studentMapper.getStudentList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
<M> List<Student> getStudentList(String inFilterField, Set<M> inFilterValues, Student filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
@@ -142,12 +70,7 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Student> getStudentListWithRelation(Student filter, String orderBy) {
|
||||
List<Student> resultList = studentMapper.getStudentList(null, null, filter, orderBy);
|
||||
Map<String, List<MyWhereCriteria>> criteriaMap = buildAggregationAdditionalWhereCriteria();
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal(), criteriaMap);
|
||||
return resultList;
|
||||
}
|
||||
List<Student> getStudentListWithRelation(Student filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
@@ -160,13 +83,8 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public <M> List<Student> getStudentListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, Student filter, String orderBy) {
|
||||
List<Student> resultList =
|
||||
studentMapper.getStudentList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
<M> List<Student> getStudentListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, Student filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回不与指定主表主键Id存在对多对关系的列表。
|
||||
@@ -176,13 +94,8 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Student> getNotInStudentListByClassId(
|
||||
Long classId, Student filter, String orderBy) {
|
||||
List<Student> resultList =
|
||||
studentMapper.getNotInStudentListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
List<Student> getNotInStudentListByClassId(
|
||||
Long classId, Student filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回与指定主表主键Id存在对多对关系的列表。
|
||||
@@ -192,13 +105,8 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
public List<Student> getStudentListByClassId(
|
||||
Long classId, Student filter, String orderBy) {
|
||||
List<Student> resultList =
|
||||
studentMapper.getStudentListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly(), null);
|
||||
return resultList;
|
||||
}
|
||||
List<Student> getStudentListByClassId(
|
||||
Long classId, Student filter, String orderBy);
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
@@ -207,28 +115,5 @@ public class StudentService extends BaseService<Student, Long> {
|
||||
* @param originalStudent 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
public CallResult verifyRelatedData(Student student, Student originalStudent) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(student, originalStudent, Student::getProvinceId)
|
||||
&& !areaCodeService.existId(student.getProvinceId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在省份"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getCityId)
|
||||
&& !areaCodeService.existId(student.getCityId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在城市"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getDistrictId)
|
||||
&& !areaCodeService.existId(student.getDistrictId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在区县"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getGradeId)
|
||||
&& !gradeService.existId(student.getGradeId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "年级"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getSchoolId)
|
||||
&& !schoolInfoService.existId(student.getSchoolId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属校区"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
CallResult verifyRelatedData(Student student, Student originalStudent);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.orange.demo.courseclassservice.service.impl;
|
||||
|
||||
import com.orange.demo.courseclassservice.service.AreaCodeService;
|
||||
import com.orange.demo.courseclassservice.dao.AreaCodeMapper;
|
||||
import com.orange.demo.courseclassservice.model.AreaCode;
|
||||
import com.orange.demo.common.core.cache.MapTreeDictionaryCache;
|
||||
import com.orange.demo.common.core.base.service.BaseDictService;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区划的Service类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service("areaCodeService")
|
||||
public class AreaCodeServiceImpl extends BaseDictService<AreaCode, Long> implements AreaCodeService {
|
||||
|
||||
@Autowired
|
||||
private AreaCodeMapper areaCodeMapper;
|
||||
|
||||
public AreaCodeServiceImpl() {
|
||||
super();
|
||||
this.dictionaryCache = MapTreeDictionaryCache.create(AreaCode::getAreaId, AreaCode::getParentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BaseDaoMapper<AreaCode> mapper() {
|
||||
return areaCodeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载数据库数据到内存缓存。
|
||||
*/
|
||||
@Override
|
||||
public void loadCachedData() {
|
||||
Example e = new Example(AreaCode.class);
|
||||
e.orderBy("areaLevel");
|
||||
List<AreaCode> areaCodeList = areaCodeMapper.selectByExample(e);
|
||||
dictionaryCache.putAll(areaCodeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据上级行政区划Id,获取其下级行政区划列表。
|
||||
*
|
||||
* @param parentId 上级行政区划Id。
|
||||
* @return 下级行政区划列表。
|
||||
*/
|
||||
@Override
|
||||
public Collection<AreaCode> getListByParentId(Long parentId) {
|
||||
return ((MapTreeDictionaryCache<Long, AreaCode>) dictionaryCache).getListByParentId(parentId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package com.orange.demo.courseclassservice.service.impl;
|
||||
|
||||
import com.orange.demo.courseclassservice.service.*;
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 课程数据数据操作服务类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service("courseService")
|
||||
public class CourseServiceImpl extends BaseService<Course, Long> implements CourseService {
|
||||
|
||||
@Autowired
|
||||
private CourseMapper courseMapper;
|
||||
@Autowired
|
||||
private ClassCourseMapper classCourseMapper;
|
||||
@Autowired
|
||||
private GradeService gradeService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Course> mapper() {
|
||||
return courseMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
*
|
||||
* @param course 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Course saveNew(Course course) {
|
||||
course.setCourseId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
course.setCreateUserId(tokenData.getUserId());
|
||||
Date now = new Date();
|
||||
course.setCreateTime(now);
|
||||
course.setUpdateTime(now);
|
||||
courseMapper.insert(course);
|
||||
return course;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
*
|
||||
* @param course 更新的对象。
|
||||
* @param originalCourse 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean update(Course course, Course originalCourse) {
|
||||
course.setCreateUserId(originalCourse.getCreateUserId());
|
||||
course.setCreateTime(originalCourse.getCreateTime());
|
||||
course.setUpdateTime(new Date());
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return courseMapper.updateByPrimaryKey(course) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param courseId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean remove(Long courseId) {
|
||||
// 这里先删除主数据
|
||||
if (!this.removeById(courseId)) {
|
||||
return false;
|
||||
}
|
||||
// 开始删除与本地多对多父表的关联
|
||||
ClassCourse classCourse = new ClassCourse();
|
||||
classCourse.setCourseId(courseId);
|
||||
classCourseMapper.delete(classCourse);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getCourseListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Course> getCourseList(Course filter, String orderBy) {
|
||||
return courseMapper.getCourseList(null, null, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getCourseListWithRelation)方法。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<Course> getCourseList(
|
||||
String inFilterField, Set<M> inFilterValues, Course filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, Course.class);
|
||||
return courseMapper.getCourseList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 该查询会涉及到一对一从表的关联过滤,或一对多从表的嵌套关联过滤,因此性能不如单表过滤。
|
||||
* 如果仅仅需要获取主表数据,请移步(getCourseList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Course> getCourseListWithRelation(Course filter, String orderBy) {
|
||||
List<Course> resultList = courseMapper.getCourseList(null, null, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 同时还包含主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getCourseList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<Course> getCourseListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, Course filter, String orderBy) {
|
||||
List<Course> resultList =
|
||||
courseMapper.getCourseList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回不与指定主表主键Id存在对多对关系的列表。
|
||||
*
|
||||
* @param classId 主表的关联键Id。
|
||||
* @param filter 从表的过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Course> getNotInCourseListByClassId(
|
||||
Long classId, Course filter, String orderBy) {
|
||||
List<Course> resultList =
|
||||
courseMapper.getNotInCourseListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回与指定主表主键Id存在对多对关系的列表。
|
||||
*
|
||||
* @param classId 主表的关联键Id。
|
||||
* @param filter 从表的过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Course> getCourseListByClassId(
|
||||
Long classId, Course filter, String orderBy) {
|
||||
List<Course> resultList =
|
||||
courseMapper.getCourseListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
*
|
||||
* @param course 最新数据对象。
|
||||
* @param originalCourse 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
@Override
|
||||
public CallResult verifyRelatedData(Course course, Course originalCourse) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(course, originalCourse, Course::getGradeId)
|
||||
&& !gradeService.existId(course.getGradeId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属年级"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.orange.demo.courseclassservice.service.impl;
|
||||
|
||||
import com.orange.demo.common.redis.cache.RedisDictionaryCache;
|
||||
import com.orange.demo.common.core.base.service.BaseDictService;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.courseclassservice.service.GradeService;
|
||||
import com.orange.demo.courseclassservice.dao.GradeMapper;
|
||||
import com.orange.demo.courseclassservice.model.Grade;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 年级字典数据操作服务类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service("gradeService")
|
||||
public class GradeServiceImpl extends BaseDictService<Grade, Integer> implements GradeService {
|
||||
|
||||
@Autowired
|
||||
private GradeMapper gradeMapper;
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
public GradeServiceImpl() {
|
||||
super();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.dictionaryCache = RedisDictionaryCache.create(
|
||||
redissonClient, "Grade", Grade.class, Grade::getGradeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Grade> mapper() {
|
||||
return gradeMapper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package com.orange.demo.courseclassservice.service.impl;
|
||||
|
||||
import com.orange.demo.courseclassservice.service.*;
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 校区数据数据操作服务类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service("schoolInfoService")
|
||||
public class SchoolInfoServiceImpl extends BaseService<SchoolInfo, Long> implements SchoolInfoService {
|
||||
|
||||
@Autowired
|
||||
private SchoolInfoMapper schoolInfoMapper;
|
||||
@Autowired
|
||||
private AreaCodeService areaCodeService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<SchoolInfo> mapper() {
|
||||
return schoolInfoMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
*
|
||||
* @param schoolInfo 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public SchoolInfo saveNew(SchoolInfo schoolInfo) {
|
||||
schoolInfo.setSchoolId(idGenerator.nextLongId());
|
||||
schoolInfoMapper.insert(schoolInfo);
|
||||
return schoolInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
*
|
||||
* @param schoolInfo 更新的对象。
|
||||
* @param originalSchoolInfo 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean update(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo) {
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return schoolInfoMapper.updateByPrimaryKey(schoolInfo) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param schoolId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean remove(Long schoolId) {
|
||||
// 这里先删除主数据
|
||||
return this.removeById(schoolId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getSchoolInfoListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<SchoolInfo> getSchoolInfoList(SchoolInfo filter, String orderBy) {
|
||||
return schoolInfoMapper.getSchoolInfoList(null, null, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getSchoolInfoListWithRelation)方法。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<SchoolInfo> getSchoolInfoList(
|
||||
String inFilterField, Set<M> inFilterValues, SchoolInfo filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, SchoolInfo.class);
|
||||
return schoolInfoMapper.getSchoolInfoList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 该查询会涉及到一对一从表的关联过滤,或一对多从表的嵌套关联过滤,因此性能不如单表过滤。
|
||||
* 如果仅仅需要获取主表数据,请移步(getSchoolInfoList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<SchoolInfo> getSchoolInfoListWithRelation(SchoolInfo filter, String orderBy) {
|
||||
List<SchoolInfo> resultList = schoolInfoMapper.getSchoolInfoList(null, null, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 同时还包含主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getSchoolInfoList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<SchoolInfo> getSchoolInfoListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, SchoolInfo filter, String orderBy) {
|
||||
List<SchoolInfo> resultList =
|
||||
schoolInfoMapper.getSchoolInfoList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
*
|
||||
* @param schoolInfo 最新数据对象。
|
||||
* @param originalSchoolInfo 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
@Override
|
||||
public CallResult verifyRelatedData(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(schoolInfo, originalSchoolInfo, SchoolInfo::getProvinceId)
|
||||
&& !areaCodeService.existId(schoolInfo.getProvinceId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在省份"));
|
||||
}
|
||||
if (this.needToVerify(schoolInfo, originalSchoolInfo, SchoolInfo::getCityId)
|
||||
&& !areaCodeService.existId(schoolInfo.getCityId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在城市"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
package com.orange.demo.courseclassservice.service.impl;
|
||||
|
||||
import com.orange.demo.courseclassservice.service.*;
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.object.TokenData;
|
||||
import com.orange.demo.common.core.constant.GlobalDeletedFlag;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 班级数据数据操作服务类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service("studentClassService")
|
||||
public class StudentClassServiceImpl extends BaseService<StudentClass, Long> implements StudentClassService {
|
||||
|
||||
@Autowired
|
||||
private StudentClassMapper studentClassMapper;
|
||||
@Autowired
|
||||
private ClassCourseMapper classCourseMapper;
|
||||
@Autowired
|
||||
private ClassStudentMapper classStudentMapper;
|
||||
@Autowired
|
||||
private SchoolInfoService schoolInfoService;
|
||||
@Autowired
|
||||
private StudentService studentService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<StudentClass> mapper() {
|
||||
return studentClassMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
*
|
||||
* @param studentClass 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public StudentClass saveNew(StudentClass studentClass) {
|
||||
studentClass.setClassId(idGenerator.nextLongId());
|
||||
TokenData tokenData = TokenData.takeFromRequest();
|
||||
studentClass.setCreateUserId(tokenData.getUserId());
|
||||
studentClass.setCreateTime(new Date());
|
||||
studentClass.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
studentClassMapper.insert(studentClass);
|
||||
return studentClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
*
|
||||
* @param studentClass 更新的对象。
|
||||
* @param originalStudentClass 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean update(StudentClass studentClass, StudentClass originalStudentClass) {
|
||||
studentClass.setCreateUserId(originalStudentClass.getCreateUserId());
|
||||
studentClass.setCreateTime(originalStudentClass.getCreateTime());
|
||||
studentClass.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return studentClassMapper.updateByPrimaryKey(studentClass) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param classId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean remove(Long classId) {
|
||||
// 这里先删除主数据
|
||||
if (!this.removeById(classId)) {
|
||||
return false;
|
||||
}
|
||||
// 开始删除多对多中间表的关联
|
||||
ClassCourse classCourse = new ClassCourse();
|
||||
classCourse.setClassId(classId);
|
||||
classCourseMapper.delete(classCourse);
|
||||
ClassStudent classStudent = new ClassStudent();
|
||||
classStudent.setClassId(classId);
|
||||
classStudentMapper.delete(classStudent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getStudentClassListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<StudentClass> getStudentClassList(StudentClass filter, String orderBy) {
|
||||
return studentClassMapper.getStudentClassList(null, null, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getStudentClassListWithRelation)方法。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<StudentClass> getStudentClassList(
|
||||
String inFilterField, Set<M> inFilterValues, StudentClass filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, StudentClass.class);
|
||||
return studentClassMapper.getStudentClassList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 该查询会涉及到一对一从表的关联过滤,或一对多从表的嵌套关联过滤,因此性能不如单表过滤。
|
||||
* 如果仅仅需要获取主表数据,请移步(getStudentClassList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<StudentClass> getStudentClassListWithRelation(StudentClass filter, String orderBy) {
|
||||
List<StudentClass> resultList = studentClassMapper.getStudentClassList(null, null, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 同时还包含主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getStudentClassList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<StudentClass> getStudentClassListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, StudentClass filter, String orderBy) {
|
||||
List<StudentClass> resultList =
|
||||
studentClassMapper.getStudentClassList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加多对多关联关系。
|
||||
*
|
||||
* @param classCourseList 多对多关联表对象集合。
|
||||
* @param classId 主表Id。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void addClassCourseList(List<ClassCourse> classCourseList, Long classId) {
|
||||
for (ClassCourse classCourse : classCourseList) {
|
||||
classCourse.setClassId(classId);
|
||||
MyModelUtil.setDefaultValue(classCourse, "courseOrder", 0);
|
||||
}
|
||||
classCourseMapper.insertList(classCourseList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新中间表数据。
|
||||
*
|
||||
* @param classCourse 中间表对象。
|
||||
* @return 更新成功与否。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean updateClassCourse(ClassCourse classCourse) {
|
||||
Example e = new Example(ClassCourse.class);
|
||||
e.createCriteria()
|
||||
.andEqualTo("classId", classCourse.getClassId())
|
||||
.andEqualTo("courseId", classCourse.getCourseId());
|
||||
return classCourseMapper.updateByExample(classCourse, e) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中间表数据。
|
||||
*
|
||||
* @param classId 主表Id。
|
||||
* @param courseId 从表Id。
|
||||
* @return 中间表对象。
|
||||
*/
|
||||
@Override
|
||||
public ClassCourse getClassCourse(Long classId, Long courseId) {
|
||||
Example e = new Example(ClassCourse.class);
|
||||
e.createCriteria()
|
||||
.andEqualTo("classId", classId)
|
||||
.andEqualTo("courseId", courseId);
|
||||
return classCourseMapper.selectOneByExample(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除单条多对多关系。
|
||||
*
|
||||
* @param classId 主表Id。
|
||||
* @param courseId 从表Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean removeClassCourse(Long classId, Long courseId) {
|
||||
ClassCourse filter = new ClassCourse();
|
||||
filter.setClassId(classId);
|
||||
filter.setCourseId(courseId);
|
||||
return classCourseMapper.delete(filter) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加多对多关联关系。
|
||||
*
|
||||
* @param classStudentList 多对多关联表对象集合。
|
||||
* @param classId 主表Id。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void addClassStudentList(List<ClassStudent> classStudentList, Long classId) {
|
||||
for (ClassStudent classStudent : classStudentList) {
|
||||
classStudent.setClassId(classId);
|
||||
}
|
||||
classStudentMapper.insertList(classStudentList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除单条多对多关系。
|
||||
*
|
||||
* @param classId 主表Id。
|
||||
* @param studentId 从表Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean removeClassStudent(Long classId, Long studentId) {
|
||||
ClassStudent filter = new ClassStudent();
|
||||
filter.setClassId(classId);
|
||||
filter.setStudentId(studentId);
|
||||
return classStudentMapper.delete(filter) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
*
|
||||
* @param studentClass 最新数据对象。
|
||||
* @param originalStudentClass 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
@Override
|
||||
public CallResult verifyRelatedData(StudentClass studentClass, StudentClass originalStudentClass) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(studentClass, originalStudentClass, StudentClass::getSchoolId)
|
||||
&& !schoolInfoService.existId(studentClass.getSchoolId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属校区"));
|
||||
}
|
||||
if (this.needToVerify(studentClass, originalStudentClass, StudentClass::getLeaderId)
|
||||
&& !studentService.existId(studentClass.getLeaderId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "班长"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.orange.demo.courseclassservice.service.impl;
|
||||
|
||||
import com.orange.demo.application.common.constant.StudentStatus;
|
||||
import com.orange.demo.courseclassservice.service.*;
|
||||
import com.orange.demo.courseclassservice.dao.*;
|
||||
import com.orange.demo.courseclassservice.model.*;
|
||||
import com.orange.demo.common.core.util.*;
|
||||
import com.orange.demo.common.core.object.MyRelationParam;
|
||||
import com.orange.demo.common.core.object.CallResult;
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
import com.orange.demo.common.sequence.wrapper.IdGeneratorWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 学生数据数据操作服务类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2020-08-08
|
||||
*/
|
||||
@Service("studentService")
|
||||
public class StudentServiceImpl extends BaseService<Student, Long> implements StudentService {
|
||||
|
||||
@Autowired
|
||||
private StudentMapper studentMapper;
|
||||
@Autowired
|
||||
private ClassStudentMapper classStudentMapper;
|
||||
@Autowired
|
||||
private SchoolInfoService schoolInfoService;
|
||||
@Autowired
|
||||
private AreaCodeService areaCodeService;
|
||||
@Autowired
|
||||
private GradeService gradeService;
|
||||
@Autowired
|
||||
private IdGeneratorWrapper idGenerator;
|
||||
|
||||
/**
|
||||
* 返回当前Service的主表Mapper对象。
|
||||
*
|
||||
* @return 主表Mapper对象。
|
||||
*/
|
||||
@Override
|
||||
protected BaseDaoMapper<Student> mapper() {
|
||||
return studentMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新增对象。
|
||||
*
|
||||
* @param student 新增对象。
|
||||
* @return 返回新增对象。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Student saveNew(Student student) {
|
||||
student.setStudentId(idGenerator.nextLongId());
|
||||
student.setRegisterTime(new Date());
|
||||
MyModelUtil.setDefaultValue(student, "totalCoin", 0);
|
||||
MyModelUtil.setDefaultValue(student, "leftCoin", 0);
|
||||
MyModelUtil.setDefaultValue(student, "status", StudentStatus.NORMAL);
|
||||
studentMapper.insert(student);
|
||||
return student;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据对象。
|
||||
*
|
||||
* @param student 更新的对象。
|
||||
* @param originalStudent 原有数据对象。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean update(Student student, Student originalStudent) {
|
||||
student.setRegisterTime(originalStudent.getRegisterTime());
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return studentMapper.updateByPrimaryKey(student) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定数据。
|
||||
*
|
||||
* @param studentId 主键Id。
|
||||
* @return 成功返回true,否则false。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public boolean remove(Long studentId) {
|
||||
// 这里先删除主数据
|
||||
if (!this.removeById(studentId)) {
|
||||
return false;
|
||||
}
|
||||
// 开始删除与本地多对多父表的关联
|
||||
ClassStudent classStudent = new ClassStudent();
|
||||
classStudent.setStudentId(studentId);
|
||||
classStudentMapper.delete(classStudent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单表查询结果。由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getStudentListWithRelation)方法。
|
||||
*
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Student> getStudentList(Student filter, String orderBy) {
|
||||
return studentMapper.getStudentList(null, null, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 由于没有关联数据查询,因此在仅仅获取单表数据的场景下,效率更高。
|
||||
* 如果需要同时获取关联数据,请移步(getStudentListWithRelation)方法。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<Student> getStudentList(
|
||||
String inFilterField, Set<M> inFilterValues, Student filter, String orderBy) {
|
||||
String inFilterColumn = MyModelUtil.mapToColumnName(inFilterField, Student.class);
|
||||
return studentMapper.getStudentList(inFilterColumn, inFilterValues, filter, orderBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,以及主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 该查询会涉及到一对一从表的关联过滤,或一对多从表的嵌套关联过滤,因此性能不如单表过滤。
|
||||
* 如果仅仅需要获取主表数据,请移步(getStudentList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Student> getStudentListWithRelation(Student filter, String orderBy) {
|
||||
List<Student> resultList = studentMapper.getStudentList(null, null, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.normal());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主表的查询结果,查询条件中包括主表过滤对象和指定字段的(in list)过滤。
|
||||
* 同时还包含主表关联的字典数据和一对一从表数据,以及一对一从表的字典数据。
|
||||
* 如果仅仅需要获取主表数据,请移步(getStudentList),以便获取更好的查询性能。
|
||||
*
|
||||
* @param inFilterField (In-list)指定的字段(Java成员字段,而非数据列名)。
|
||||
* @param inFilterValues inFilterField指定字段的(In-list)数据列表。
|
||||
* @param filter 主表过滤对象。
|
||||
* @param orderBy 排序对象。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public <M> List<Student> getStudentListWithRelation(
|
||||
String inFilterField, Set<M> inFilterValues, Student filter, String orderBy) {
|
||||
List<Student> resultList =
|
||||
studentMapper.getStudentList(inFilterField, inFilterValues, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回不与指定主表主键Id存在对多对关系的列表。
|
||||
*
|
||||
* @param classId 主表的关联键Id。
|
||||
* @param filter 从表的过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Student> getNotInStudentListByClassId(
|
||||
Long classId, Student filter, String orderBy) {
|
||||
List<Student> resultList =
|
||||
studentMapper.getNotInStudentListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在多对多关系中,当前Service的数据表为从表,返回与指定主表主键Id存在对多对关系的列表。
|
||||
*
|
||||
* @param classId 主表的关联键Id。
|
||||
* @param filter 从表的过滤对象。
|
||||
* @param orderBy 排序参数。
|
||||
* @return 查询结果集。
|
||||
*/
|
||||
@Override
|
||||
public List<Student> getStudentListByClassId(
|
||||
Long classId, Student filter, String orderBy) {
|
||||
List<Student> resultList =
|
||||
studentMapper.getStudentListByClassId(classId, filter, orderBy);
|
||||
this.buildRelationForDataList(resultList, MyRelationParam.dictOnly());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据最新对象和原有对象的数据对比,判断关联的字典数据和多对一主表数据是否都是合法数据。
|
||||
*
|
||||
* @param student 最新数据对象。
|
||||
* @param originalStudent 原有数据对象。
|
||||
* @return 数据全部正确返回true,否则false,同时返回具体的错误信息。
|
||||
*/
|
||||
@Override
|
||||
public CallResult verifyRelatedData(Student student, Student originalStudent) {
|
||||
String errorMessageFormat = "数据验证失败,关联的%s并不存在,请刷新后重试!";
|
||||
if (this.needToVerify(student, originalStudent, Student::getProvinceId)
|
||||
&& !areaCodeService.existId(student.getProvinceId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在省份"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getCityId)
|
||||
&& !areaCodeService.existId(student.getCityId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在城市"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getDistrictId)
|
||||
&& !areaCodeService.existId(student.getDistrictId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所在区县"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getGradeId)
|
||||
&& !gradeService.existId(student.getGradeId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "年级"));
|
||||
}
|
||||
if (this.needToVerify(student, originalStudent, Student::getSchoolId)
|
||||
&& !schoolInfoService.existId(student.getSchoolId())) {
|
||||
return CallResult.error(String.format(errorMessageFormat, "所属校区"));
|
||||
}
|
||||
return CallResult.ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user