wangwei 5 years ago
parent
commit
a3bd99b928

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

@@ -459,6 +459,28 @@ public class StudentController extends ControllerSupport {
 		}
 	}
 
+	@ApiOperation(value = "重置机构下所有学生密码", notes = "重置机构下所有学生密码")
+	@PutMapping("resetPasswordByOrgId/{orgId}")
+	@Transactional
+	public void resetPasswordByOrgId(@PathVariable Long orgId) {
+		OrgEntity org = GlobalHelper.getPresentEntity(orgRepo, orgId, OrgEntity.class);
+
+		validateRootOrgIsolation(org.getRootId());
+
+		List<StudentEntity> stuentList = studentRepo.findByOrgId(org.getId());
+		for (StudentEntity s : stuentList) {
+			String identityNumber = s.getIdentityNumber();
+			if (StringUtils.isNotEmpty(identityNumber)
+					&& identityNumber.matches("[0-9a-zA-Z]{6,}")) {
+				s.setPassword(StringUtils.substring(identityNumber, -6, identityNumber.length()));
+			} else {
+				s.setPassword(BasicConsts.DEFAULT_PASSWORD);
+			}
+			s.setUpdateTime(new Date());
+			studentRepo.save(s);
+		}
+	}
+
 	/**
 	 * 方法注释
 	 *

+ 4 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/StudentRepo.java

@@ -1,5 +1,7 @@
 package cn.com.qmth.examcloud.core.basic.dao;
 
+import java.util.List;
+
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
@@ -25,4 +27,6 @@ public interface StudentRepo
 
 	int countByRootOrgId(Long rootOrgId);
 
+	List<StudentEntity> findByOrgId(Long orgId);
+
 }