|
@@ -0,0 +1,68 @@
|
|
|
+package cn.com.qmth.examcloud.tool.service.reset_student_password;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.tool.config.SysProperty;
|
|
|
+import cn.com.qmth.examcloud.tool.entity.TaskEntity;
|
|
|
+import cn.com.qmth.examcloud.tool.service.CommonService;
|
|
|
+import cn.com.qmth.examcloud.tool.service.reset_student_password.vo.StudentVO;
|
|
|
+import cn.com.qmth.examcloud.tool.utils.HttpHelper;
|
|
|
+import cn.com.qmth.examcloud.tool.utils.JsonMapper;
|
|
|
+import cn.com.qmth.examcloud.tool.vo.PageInfo;
|
|
|
+import cn.com.qmth.examcloud.tool.vo.User;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class ResetStudentPasswordTask {
|
|
|
+
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(ResetStudentPasswordTask.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysProperty sysProperty;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
+ public void start(TaskEntity task) {
|
|
|
+ User user = new User();
|
|
|
+ user.setKey("U_C_0_9");
|
|
|
+ user.setToken("c7377229debb4c6594c071a57e9d983f");
|
|
|
+ this.execute(user, 0L);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void execute(User user, Long rootOrgId) {
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("key", user.getKey());
|
|
|
+ headers.put("token", user.getToken());
|
|
|
+
|
|
|
+ JsonMapper jsonMapper = new JsonMapper();
|
|
|
+ int sum = 0, pageNo = 0, pageSize = 100;
|
|
|
+
|
|
|
+ String url = sysProperty.getServerUrl() + "/api/ecs_core/student/studentPage/%s/%s?rootOrgId=%s&identityNumber=&studentCode=&name=";
|
|
|
+ while (true) {
|
|
|
+ String json = HttpHelper.get(String.format(url, pageNo, pageSize, rootOrgId), headers, null);
|
|
|
+
|
|
|
+ PageInfo<StudentVO> page = jsonMapper.parseJson(json, new TypeReference<PageInfo<StudentVO>>() {
|
|
|
+ });
|
|
|
+ if (page == null || CollectionUtils.isEmpty(page.getList())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (StudentVO student : page.getList()) {
|
|
|
+ HttpHelper.put(sysProperty.getServerUrl() + "/api/ecs_core/student/resetPass/" + student.getId(), headers, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ pageNo++;
|
|
|
+ sum += page.getList().size();
|
|
|
+ float rate = sum * 100f / page.getTotal();
|
|
|
+ log.info("rootOrgId:{} 已重置学生密码数:{} 进度:{}%", rootOrgId, sum, rate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|