WANG 5 жил өмнө
parent
commit
936bf24e61

+ 18 - 19
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/StudentController.java

@@ -20,7 +20,6 @@ import org.springframework.data.domain.Sort;
 import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -48,6 +47,7 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.StudentCodeEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
 import cn.com.qmth.examcloud.core.basic.service.StudentService;
 import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
+import cn.com.qmth.examcloud.core.basic.service.cache.StudentCache;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.config.SystemConfig;
@@ -84,6 +84,9 @@ public class StudentController extends ControllerSupport {
 	@Autowired
 	DataSyncCloudService dataSyncCloudService;
 
+	@Autowired
+	StudentCache studentCache;
+
 	private static final String[] EXCEL_HEADER = new String[]{"ID", "姓名", "学号", "身份证", "学习中心代码",
 			"学习中心名称"};
 
@@ -305,24 +308,6 @@ public class StudentController extends ControllerSupport {
 		FileUtils.deleteQuietly(file);
 	}
 
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param id
-	 * @return
-	 */
-	@ApiOperation(value = "按ID删除学生", notes = "删除")
-	@DeleteMapping("{id}")
-	public Long deleteStudent(@PathVariable Long id) {
-		StudentEntity s = GlobalHelper.getEntity(studentRepo, id, StudentEntity.class);
-		if (null != s) {
-			validateRootOrgIsolation(s.getRootOrgId());
-		}
-		studentRepo.deleteById(id);
-		return id;
-	}
-
 	/**
 	 * 方法注释
 	 *
@@ -342,6 +327,9 @@ public class StudentController extends ControllerSupport {
 			studentRepo.save(s);
 			ret.add(s.getId() + ":" + s.getName());
 		}
+		for (Long cur : studentIds) {
+			studentCache.remove(cur);
+		}
 		return ret;
 	}
 
@@ -364,6 +352,9 @@ public class StudentController extends ControllerSupport {
 			studentRepo.save(s);
 			ret.add(s.getId() + ":" + s.getName());
 		}
+		for (Long cur : studentIds) {
+			studentCache.remove(cur);
+		}
 		return ret;
 	}
 
@@ -507,6 +498,10 @@ public class StudentController extends ControllerSupport {
 		List<Long> studentIdList = studentService.unbindStudentCode(rootOrgId, studentCode,
 				identityNumber);
 
+		for (Long cur : studentIdList) {
+			studentCache.remove(cur);
+		}
+
 		return studentIdList;
 	}
 
@@ -527,6 +522,10 @@ public class StudentController extends ControllerSupport {
 			studentService.unbindSecurityPhone(cur);
 		}
 
+		for (Long cur : studentIds) {
+			studentCache.remove(cur);
+		}
+
 	}
 
 }

+ 13 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/StudentCloudServiceProvider.java

@@ -30,6 +30,7 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
 import cn.com.qmth.examcloud.core.basic.service.StudentService;
 import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
+import cn.com.qmth.examcloud.core.basic.service.cache.StudentCache;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
@@ -60,6 +61,9 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 	@Autowired
 	StudentRepo studentRepo;
 
+	@Autowired
+	StudentCache studentCache;
+
 	@ApiOperation(value = "保存学生")
 	@PostMapping("saveStudent")
 	@Override
@@ -93,6 +97,8 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 			resp.setOrgName(org.getName());
 		}
 
+		studentCache.remove(student.getId());
+
 		return resp;
 	}
 
@@ -155,6 +161,10 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 		UnbindStudentCodeResp resp = new UnbindStudentCodeResp();
 		resp.setStudentIdList(studentIdList);
 
+		for (Long cur : studentIdList) {
+			studentCache.remove(cur);
+		}
+
 		return resp;
 	}
 
@@ -216,7 +226,9 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 		}
 
 		entity.setEnable(enable);
-		studentRepo.save(entity);
+		StudentEntity saved = studentRepo.save(entity);
+
+		studentCache.remove(saved.getId());
 
 		UpdateStudentStatusResp resp = new UpdateStudentStatusResp();
 		return resp;

+ 51 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/cache/StudentCache.java

@@ -0,0 +1,51 @@
+package cn.com.qmth.examcloud.core.basic.service.cache;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
+import cn.com.qmth.examcloud.support.cache.bean.StudentCacheBean;
+import cn.com.qmth.examcloud.web.cache.RandomObjectRedisCache;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+
+@Service
+public class StudentCache extends RandomObjectRedisCache<StudentCacheBean> {
+
+	@Autowired
+	StudentRepo studentRepo;
+
+	@Override
+	public StudentCacheBean loadFromResource(Object... keys) {
+		Long studentId = (Long) keys[0];
+
+		StudentEntity s = GlobalHelper.getPresentEntity(studentRepo, studentId,
+				StudentEntity.class);
+
+		StudentCacheBean b = new StudentCacheBean();
+		b.setId(s.getId());
+		b.setEnable(s.getEnable());
+		b.setIdentityNumber(s.getIdentityNumber());
+		b.setName(s.getName());
+		b.setOrgId(s.getOrgId());
+		b.setPhoneNumber(s.getPhoneNumber());
+		b.setPhotoPath(s.getPhotoPath());
+		b.setRemark(s.getRemark());
+		b.setRootOrgId(s.getRootOrgId());
+		b.setSecurityPhone(s.getSecurityPhone());
+
+		return b;
+	}
+
+	@Override
+	protected String getKeyPrefix() {
+		return "B_STUDENT:";
+	}
+
+	@Override
+	protected int getTimeout() {
+		// 5分钟
+		return 60 * 5;
+	}
+
+}

+ 12 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

@@ -27,6 +27,7 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
 import cn.com.qmth.examcloud.core.basic.service.StudentService;
 import cn.com.qmth.examcloud.core.basic.service.UserService;
 import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
+import cn.com.qmth.examcloud.core.basic.service.cache.StudentCache;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncStudentReq;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
@@ -59,6 +60,9 @@ public class StudentServiceImpl implements StudentService {
 	@Autowired
 	DataSyncCloudService dataSyncCloudService;
 
+	@Autowired
+	StudentCache studentCache;
+
 	/*
 	 * 实现
 	 *
@@ -224,6 +228,8 @@ public class StudentServiceImpl implements StudentService {
 			dataSyncCloudService.syncStudent(req);
 		}
 
+		studentCache.remove(saved.getId());
+
 		return saved;
 	}
 
@@ -405,6 +411,10 @@ public class StudentServiceImpl implements StudentService {
 			dataSyncCloudService.syncStudent(req);
 		}
 
+		for (Long cur : studentIdList) {
+			studentCache.remove(cur);
+		}
+
 		return studentIdList;
 	}
 
@@ -445,6 +455,8 @@ public class StudentServiceImpl implements StudentService {
 		req.setSyncType("update");
 
 		dataSyncCloudService.syncStudent(req);
+
+		studentCache.remove(studentId);
 	}
 
 	@Override