mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-18 11:06:36 +08:00
commit:添加多对多关联中间表更新支持,功能位于 班级管理 -> 课程 -> 编辑课程顺序
This commit is contained in:
@@ -8,8 +8,8 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
/**
|
||||
* course-class服务启动类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@SpringCloudApplication
|
||||
@EnableFeignClients(basePackages = "com.orange.demo")
|
||||
|
||||
@@ -13,8 +13,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
* uploadFileBaseDir: /user/xxx/fileRoot/
|
||||
* defaultSomething: defaultValue
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@RefreshScope
|
||||
|
||||
@@ -13,8 +13,8 @@ import javax.sql.DataSource;
|
||||
/**
|
||||
* 数据源配置Bean对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
|
||||
@@ -18,8 +18,8 @@ import java.util.*;
|
||||
/**
|
||||
* 行政区划数据访问接口类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/areaCode")
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.orange.demo.common.core.base.controller.BaseController;
|
||||
import com.orange.demo.common.core.base.service.BaseService;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,8 +30,8 @@ import java.util.*;
|
||||
/**
|
||||
* 课程数据操作控制器类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -41,6 +42,8 @@ public class CourseController extends BaseController<Course, CourseDto, Long> {
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private ApplicationConfig appConfig;
|
||||
@Autowired
|
||||
private SessionCacheHelper cacheHelper;
|
||||
|
||||
@Override
|
||||
protected BaseService<Course, CourseDto, Long> service() {
|
||||
@@ -191,31 +194,39 @@ public class CourseController extends BaseController<Course, CourseDto, Long> {
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void download(
|
||||
@RequestParam Long courseId,
|
||||
@RequestParam(required = false) Long courseId,
|
||||
@RequestParam String fieldName,
|
||||
@RequestParam String filename,
|
||||
@RequestParam Boolean asImage,
|
||||
HttpServletResponse response) {
|
||||
if (MyCommonUtil.existBlankArgument(courseId, fieldName, filename, asImage)) {
|
||||
if (MyCommonUtil.existBlankArgument(fieldName, filename, asImage)) {
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
// 使用try来捕获异常,是为了保证一旦出现异常可以返回500的错误状态,便于调试。
|
||||
// 否则有可能给前端返回的是200的错误码。
|
||||
try {
|
||||
Course course = courseService.getById(courseId);
|
||||
if (course == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
String fieldJsonData = (String) ReflectUtil.getFieldValue(course, fieldName);
|
||||
if (fieldJsonData == null) {
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
if (!UpDownloadUtil.containFile(fieldJsonData, filename)) {
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
return;
|
||||
// 如果请求参数中没有包含主键Id,就判断该文件是否为当前session上传的。
|
||||
if (courseId == null) {
|
||||
if (!cacheHelper.existSessionUploadFile(filename)) {
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Course course = courseService.getById(courseId);
|
||||
if (course == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
String fieldJsonData = (String) ReflectUtil.getFieldValue(course, fieldName);
|
||||
if (fieldJsonData == null) {
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
if (!UpDownloadUtil.containFile(fieldJsonData, filename)) {
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
return;
|
||||
}
|
||||
}
|
||||
UpDownloadUtil.doDownload(appConfig.getUploadFileBaseDir(),
|
||||
Course.class.getSimpleName(), fieldName, filename, asImage, response);
|
||||
@@ -240,8 +251,11 @@ public class CourseController extends BaseController<Course, CourseDto, Long> {
|
||||
@RequestParam Boolean asImage,
|
||||
@RequestParam("uploadFile") MultipartFile uploadFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
UpDownloadUtil.doUpload(appConfig.getUploadFileBaseDir(), appConfig.getServiceContextPath(),
|
||||
String filename = UpDownloadUtil.doUpload(appConfig.getUploadFileBaseDir(), appConfig.getServiceContextPath(),
|
||||
Course.class.getSimpleName(), fieldName, asImage, uploadFile, response);
|
||||
if (filename != null) {
|
||||
cacheHelper.putSessionUploadFile(filename);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.*;
|
||||
/**
|
||||
* 年级操作控制器类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.*;
|
||||
/**
|
||||
* 校区数据操作控制器类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* 班级数据操作控制器类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -245,37 +245,75 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
* 批量添加班级数据和 [课程数据] 对象的多对多关联关系数据。
|
||||
*
|
||||
* @param classId 主表主键Id。
|
||||
* @param classCourseList 关联对象列表。
|
||||
* @param classCourseDtoList 关联对象列表。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/addClassCourse")
|
||||
public ResponseResult<Void> addClassCourse(
|
||||
@MyRequestBody Long classId,
|
||||
@MyRequestBody(elementType = ClassCourse.class) List<ClassCourse> classCourseList) {
|
||||
if (MyCommonUtil.existBlankArgument(classId, classCourseList)) {
|
||||
@MyRequestBody(value = "classCourseList", elementType = ClassCourseDto.class) List<ClassCourseDto> classCourseDtoList) {
|
||||
if (MyCommonUtil.existBlankArgument(classId, classCourseDtoList)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
for (ClassCourse classCourse : classCourseList) {
|
||||
// NOTE: 如果中间表 [ClassCourse] 除了两个关联主键之外还包括其他NotNull或NotBlank字段,
|
||||
// 请在执行下面验证之前手动赋值缺省值。如果没有此种情况,请忽略并删除该TODO注释。
|
||||
// 如:classCourse.setCourseOrder(0) 或 classCourse.setStarCourse(false)等。
|
||||
classCourse.setClassId(classId);
|
||||
classCourse.setCourseOrder(0);
|
||||
for (ClassCourseDto classCourse : classCourseDtoList) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(classCourse);
|
||||
if (errorMessage != null) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
}
|
||||
Set<Long> courseIdSet =
|
||||
classCourseList.stream().map(ClassCourse::getCourseId).collect(Collectors.toSet());
|
||||
classCourseDtoList.stream().map(ClassCourseDto::getCourseId).collect(Collectors.toSet());
|
||||
if (!studentClassService.existId(classId)
|
||||
|| !courseService.existUniqueKeyList("courseId", courseIdSet)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
studentClassService.addClassCourseList(classCourseList);
|
||||
List<ClassCourse> classCourseList =
|
||||
MyModelUtil.copyCollectionTo(classCourseDtoList, ClassCourse.class);
|
||||
studentClassService.addClassCourseList(classCourseList, classId);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定班级数据和指定 [课程数据] 的多对多关联数据。
|
||||
*
|
||||
* @param classCourseDto 对多对中间表对象。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/updateClassCourse")
|
||||
public ResponseResult<Void> updateClassCourse(
|
||||
@MyRequestBody("classCourse") ClassCourseDto classCourseDto) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(classCourseDto);
|
||||
if (errorMessage != null) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
ClassCourse classCourse = MyModelUtil.copyTo(classCourseDto, ClassCourse.class);
|
||||
if (!studentClassService.updateClassCourse(classCourse)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示班级数据和指定 [课程数据] 的多对多关联详情数据。
|
||||
*
|
||||
* @param classId 主表主键Id。
|
||||
* @param courseId 从表主键Id。
|
||||
* @return 应答结果对象,包括中间表详情。
|
||||
*/
|
||||
@GetMapping("/viewClassCourse")
|
||||
public ResponseResult<ClassCourseDto> viewClassCourse(
|
||||
@RequestParam Long classId, @RequestParam Long courseId) {
|
||||
if (MyCommonUtil.existBlankArgument(classId, courseId)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
ClassCourse classCourse = studentClassService.getClassCourse(classId, courseId);
|
||||
if (classCourse == null) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
||||
}
|
||||
ClassCourseDto classCourseDto = MyModelUtil.copyTo(classCourse, ClassCourseDto.class);
|
||||
return ResponseResult.success(classCourseDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定班级数据和指定 [课程数据] 的多对多关联关系。
|
||||
*
|
||||
@@ -364,33 +402,31 @@ public class StudentClassController extends BaseController<StudentClass, Student
|
||||
* 批量添加班级数据和 [学生数据] 对象的多对多关联关系数据。
|
||||
*
|
||||
* @param classId 主表主键Id。
|
||||
* @param classStudentList 关联对象列表。
|
||||
* @param classStudentDtoList 关联对象列表。
|
||||
* @return 应答结果对象。
|
||||
*/
|
||||
@PostMapping("/addClassStudent")
|
||||
public ResponseResult<Void> addClassStudent(
|
||||
@MyRequestBody Long classId,
|
||||
@MyRequestBody(elementType = ClassStudent.class) List<ClassStudent> classStudentList) {
|
||||
if (MyCommonUtil.existBlankArgument(classId, classStudentList)) {
|
||||
@MyRequestBody(value = "classStudentList", elementType = ClassStudentDto.class) List<ClassStudentDto> classStudentDtoList) {
|
||||
if (MyCommonUtil.existBlankArgument(classId, classStudentDtoList)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
||||
}
|
||||
for (ClassStudent classStudent : classStudentList) {
|
||||
// NOTE: 如果中间表 [ClassCourse] 除了两个关联主键之外还包括其他NotNull或NotBlank字段,
|
||||
// 请在执行下面验证之前手动赋值缺省值。如果没有此种情况,请忽略并删除该TODO注释。
|
||||
// 如:classCourse.setCourseOrder(0) 或 classCourse.setStarCourse(false)等。
|
||||
classStudent.setClassId(classId);
|
||||
for (ClassStudentDto classStudent : classStudentDtoList) {
|
||||
String errorMessage = MyCommonUtil.getModelValidationError(classStudent);
|
||||
if (errorMessage != null) {
|
||||
return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATAED_FAILED, errorMessage);
|
||||
}
|
||||
}
|
||||
Set<Long> studentIdSet =
|
||||
classStudentList.stream().map(ClassStudent::getStudentId).collect(Collectors.toSet());
|
||||
classStudentDtoList.stream().map(ClassStudentDto::getStudentId).collect(Collectors.toSet());
|
||||
if (!studentClassService.existId(classId)
|
||||
|| !studentService.existUniqueKeyList("studentId", studentIdSet)) {
|
||||
return ResponseResult.error(ErrorCodeEnum.INVALID_RELATED_RECORD_ID);
|
||||
}
|
||||
studentClassService.addClassStudentList(classStudentList);
|
||||
List<ClassStudent> classStudentList =
|
||||
MyModelUtil.copyCollectionTo(classStudentDtoList, ClassStudent.class);
|
||||
studentClassService.addClassStudentList(classStudentList, classId);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.*;
|
||||
/**
|
||||
* 学生数据操作控制器类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.orange.demo.courseclassservice.model.AreaCode;
|
||||
/**
|
||||
* 行政区划数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface AreaCodeMapper extends BaseDaoMapper<AreaCode> {
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import com.orange.demo.courseclassservice.model.ClassCourse;
|
||||
/**
|
||||
* 数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface ClassCourseMapper extends BaseDaoMapper<ClassCourse> {
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.orange.demo.courseclassservice.model.ClassStudent;
|
||||
/**
|
||||
* 数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface ClassStudentMapper extends BaseDaoMapper<ClassStudent> {
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.util.*;
|
||||
/**
|
||||
* 课程数据数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface CourseMapper extends BaseDaoMapper<Course> {
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.orange.demo.courseclassservice.model.Grade;
|
||||
/**
|
||||
* 年级数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface GradeMapper extends BaseDaoMapper<Grade> {
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.orange.demo.courseclassservice.model.MaterialEdition;
|
||||
/**
|
||||
* 数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface MaterialEditionMapper extends BaseDaoMapper<MaterialEdition> {
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.util.*;
|
||||
/**
|
||||
* 校区数据数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface SchoolInfoMapper extends BaseDaoMapper<SchoolInfo> {
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.orange.demo.courseclassservice.dao;
|
||||
|
||||
import com.orange.demo.common.core.base.dao.BaseDaoMapper;
|
||||
import com.orange.demo.courseclassservice.model.StudentClass;
|
||||
import com.orange.demo.courseclassservice.model.ClassCourse;
|
||||
import com.orange.demo.courseclassservice.model.ClassStudent;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.*;
|
||||
@@ -11,8 +9,8 @@ import java.util.*;
|
||||
/**
|
||||
* 班级数据数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface StudentClassMapper extends BaseDaoMapper<StudentClass> {
|
||||
|
||||
@@ -43,18 +41,4 @@ public interface StudentClassMapper extends BaseDaoMapper<StudentClass> {
|
||||
@Param("inFilterColumn") String inFilterColumn,
|
||||
@Param("inFilterValues") Set<M> inFilterValues,
|
||||
@Param("studentClassFilter") StudentClass studentClassFilter);
|
||||
|
||||
/**
|
||||
* 插入一组关联关系数据。
|
||||
*
|
||||
* @param classCourseList 关联关系数据项列表。
|
||||
*/
|
||||
void addClassCourseList(List<ClassCourse> classCourseList);
|
||||
|
||||
/**
|
||||
* 插入一组关联关系数据。
|
||||
*
|
||||
* @param classStudentList 关联关系数据项列表。
|
||||
*/
|
||||
void addClassStudentList(List<ClassStudent> classStudentList);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.util.*;
|
||||
/**
|
||||
* 学生数据数据操作访问接口。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
public interface StudentMapper extends BaseDaoMapper<Student> {
|
||||
|
||||
|
||||
@@ -56,18 +56,4 @@
|
||||
<include refid="filterRef"/>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="addClassCourseList">
|
||||
REPLACE INTO zz_class_course(class_id, course_id) VALUES
|
||||
<foreach collection="list" index="index" item="item" separator=",">
|
||||
(#{item.classId}, #{item.courseId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="addClassStudentList">
|
||||
REPLACE INTO zz_class_student(class_id, student_id) VALUES
|
||||
<foreach collection="list" index="index" item="item" separator=",">
|
||||
(#{item.classId}, #{item.studentId})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
||||
@@ -7,8 +7,8 @@ import javax.persistence.*;
|
||||
/**
|
||||
* 行政区划实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_area_code")
|
||||
|
||||
@@ -7,8 +7,8 @@ import javax.validation.constraints.*;
|
||||
/**
|
||||
* ClassCourse实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_class_course")
|
||||
@@ -33,7 +33,6 @@ public class ClassCourse {
|
||||
/**
|
||||
* 课程顺序(数值越小越靠前)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,课程顺序(数值越小越靠前)不能为空!")
|
||||
@Column(name = "course_order")
|
||||
private Integer courseOrder;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import javax.validation.constraints.*;
|
||||
/**
|
||||
* ClassStudent实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_class_student")
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Map;
|
||||
/**
|
||||
* Course实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_course")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orange.demo.courseclassservice.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.orange.demo.common.core.annotation.DeletedFlagColumn;
|
||||
import lombok.Data;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
@@ -7,8 +9,8 @@ import javax.validation.constraints.*;
|
||||
/**
|
||||
* Grade实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_grade")
|
||||
@@ -31,8 +33,9 @@ public class Grade {
|
||||
private String gradeName;
|
||||
|
||||
/**
|
||||
* 是否正在使用(0:不是,1:是)。
|
||||
* 逻辑删除标记字段(1: 正常 -1: 已删除)。
|
||||
*/
|
||||
@NotNull(message = "数据验证失败,是否正在使用(0:不是,1:是)不能为空!")
|
||||
@JSONField(serialize = false)
|
||||
@DeletedFlagColumn
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import javax.validation.constraints.*;
|
||||
/**
|
||||
* MaterialEdition实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_material_edition")
|
||||
|
||||
@@ -14,8 +14,8 @@ import java.util.Map;
|
||||
/**
|
||||
* SchoolInfo实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_school_info")
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Map;
|
||||
/**
|
||||
* Student实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_student")
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Map;
|
||||
/**
|
||||
* StudentClass实体对象。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "zz_class")
|
||||
|
||||
@@ -16,8 +16,8 @@ import java.util.List;
|
||||
/**
|
||||
* 行政区划的Service类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Service
|
||||
public class AreaCodeService extends BaseDictService<AreaCode, AreaCodeDto, Long> {
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.*;
|
||||
/**
|
||||
* 课程数据数据操作服务类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Service
|
||||
public class CourseService extends BaseService<Course, CourseDto, Long> {
|
||||
@@ -75,6 +75,7 @@ public class CourseService extends BaseService<Course, CourseDto, Long> {
|
||||
course.setCreateUserId(originalCourse.getCreateUserId());
|
||||
course.setCreateTime(originalCourse.getCreateTime());
|
||||
course.setUpdateTime(new Date());
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return courseMapper.updateByPrimaryKey(course) == 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.courseclassservice.model.Grade;
|
||||
import com.orange.demo.courseclassinterface.dto.GradeDto;
|
||||
@@ -16,8 +17,8 @@ import javax.annotation.PostConstruct;
|
||||
/**
|
||||
* 年级数据操作服务类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Service
|
||||
public class GradeService extends BaseDictService<Grade, GradeDto, Integer> {
|
||||
@@ -55,6 +56,7 @@ public class GradeService extends BaseDictService<Grade, GradeDto, Integer> {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Grade saveNew(Grade grade) {
|
||||
grade.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
gradeMapper.insert(grade);
|
||||
dictionaryCache.put(grade.getGradeId(), grade);
|
||||
return grade;
|
||||
@@ -69,6 +71,7 @@ public class GradeService extends BaseDictService<Grade, GradeDto, Integer> {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(Grade grade, Grade originalGrade) {
|
||||
grade.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
if (gradeMapper.updateByPrimaryKey(grade) != 1) {
|
||||
return false;
|
||||
}
|
||||
@@ -84,7 +87,10 @@ public class GradeService extends BaseDictService<Grade, GradeDto, Integer> {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean remove(Integer gradeId) {
|
||||
if (gradeMapper.deleteByPrimaryKey(gradeId) != 1) {
|
||||
Grade deletedObject = new Grade();
|
||||
deletedObject.setGradeId(gradeId);
|
||||
deletedObject.setStatus(GlobalDeletedFlag.DELETED);
|
||||
if (gradeMapper.updateByPrimaryKeySelective(deletedObject) != 1) {
|
||||
return false;
|
||||
}
|
||||
dictionaryCache.invalidate(gradeId);
|
||||
|
||||
@@ -19,8 +19,8 @@ import java.util.*;
|
||||
/**
|
||||
* 校区数据数据操作服务类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Service
|
||||
public class SchoolInfoService extends BaseService<SchoolInfo, SchoolInfoDto, Long> {
|
||||
@@ -64,6 +64,7 @@ public class SchoolInfoService extends BaseService<SchoolInfo, SchoolInfoDto, Lo
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SchoolInfo schoolInfo, SchoolInfo originalSchoolInfo) {
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return schoolInfoMapper.updateByPrimaryKey(schoolInfo) == 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.*;
|
||||
/**
|
||||
* 班级数据数据操作服务类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Service
|
||||
public class StudentClassService extends BaseService<StudentClass, StudentClassDto, Long> {
|
||||
@@ -80,6 +80,7 @@ public class StudentClassService extends BaseService<StudentClass, StudentClassD
|
||||
studentClass.setCreateUserId(originalStudentClass.getCreateUserId());
|
||||
studentClass.setCreateTime(originalStudentClass.getCreateTime());
|
||||
studentClass.setStatus(GlobalDeletedFlag.NORMAL);
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return studentClassMapper.updateByPrimaryKey(studentClass) == 1;
|
||||
}
|
||||
|
||||
@@ -179,10 +180,47 @@ public class StudentClassService extends BaseService<StudentClass, StudentClassD
|
||||
* 批量添加多对多关联关系。
|
||||
*
|
||||
* @param classCourseList 多对多关联表对象集合。
|
||||
* @param classId 主表Id。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addClassCourseList(List<ClassCourse> classCourseList) {
|
||||
studentClassMapper.addClassCourseList(classCourseList);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新中间表数据。
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中间表数据。
|
||||
*
|
||||
* @param classId 主表Id。
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,10 +242,14 @@ public class StudentClassService extends BaseService<StudentClass, StudentClassD
|
||||
* 批量添加多对多关联关系。
|
||||
*
|
||||
* @param classStudentList 多对多关联表对象集合。
|
||||
* @param classId 主表Id。
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addClassStudentList(List<ClassStudent> classStudentList) {
|
||||
studentClassMapper.addClassStudentList(classStudentList);
|
||||
public void addClassStudentList(List<ClassStudent> classStudentList, Long classId) {
|
||||
for (ClassStudent classStudent : classStudentList) {
|
||||
classStudent.setClassId(classId);
|
||||
}
|
||||
classStudentMapper.insertList(classStudentList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.courseclassinterface.dto.*;
|
||||
@@ -19,8 +20,8 @@ import java.util.*;
|
||||
/**
|
||||
* 学生数据数据操作服务类。
|
||||
*
|
||||
* @author Orange Team
|
||||
* @date 2020-08-08
|
||||
* @author Jerry
|
||||
* @date 2020-09-27
|
||||
*/
|
||||
@Service
|
||||
public class StudentService extends BaseService<Student, StudentDto, Long> {
|
||||
@@ -58,6 +59,15 @@ public class StudentService extends BaseService<Student, StudentDto, Long> {
|
||||
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;
|
||||
}
|
||||
@@ -72,6 +82,7 @@ public class StudentService extends BaseService<Student, StudentDto, Long> {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(Student student, Student originalStudent) {
|
||||
student.setRegisterTime(originalStudent.getRegisterTime());
|
||||
// 这里重点提示,在执行主表数据更新之前,如果有哪些字段不支持修改操作,请用原有数据对象字段替换当前数据字段。
|
||||
return studentMapper.updateByPrimaryKey(student) == 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user