From 1d42ec0fd777d38a2e2d6c14dfcfe4fc9025acc5 Mon Sep 17 00:00:00 2001 From: tianea Date: Thu, 1 Sep 2022 10:42:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/common/core/api/ZhiYunApi.java | 5 ++++ .../src/main/resources/system.properties | 2 +- .../com/tz/platform/feign/IFeignSchool.java | 4 +++ .../system/feign/FeignSchoolController.java | 26 +++++++++++++++++++ .../com/tz/platform/zhiyun/ZhiyunJob.java | 5 ++++ .../platform/zhiyun/biz/ZhiyunAccountBiz.java | 14 +++++++++- 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/api/ZhiYunApi.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/api/ZhiYunApi.java index 0228dd5..828363a 100644 --- a/tz/common/common-core/src/main/java/com/tz/platform/common/core/api/ZhiYunApi.java +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/api/ZhiYunApi.java @@ -57,4 +57,9 @@ public class ZhiYunApi { String content = HttpUtil.get(baseUrl+"/api/question/findByCourseId?courseId="+courseId+"&pageSize="+pageSize+"&pageIndex="+pageIndex,headers); return content; } + + public String findAuthSchool(){ + String content = HttpUtil.get(baseUrl+"/api/school/findByAuthorization",headers); + return content; + } } diff --git a/tz/common/common-core/src/main/resources/system.properties b/tz/common/common-core/src/main/resources/system.properties index 2406bd6..de82ee3 100644 --- a/tz/common/common-core/src/main/resources/system.properties +++ b/tz/common/common-core/src/main/resources/system.properties @@ -1,3 +1,3 @@ pic_path=/users/root/www/pic/ pic_recourse_url=/pic/ -initPwd=123456 \ No newline at end of file +initPwd=123qwe \ No newline at end of file diff --git a/tz/system/system-feign/src/main/java/com/tz/platform/feign/IFeignSchool.java b/tz/system/system-feign/src/main/java/com/tz/platform/feign/IFeignSchool.java index 6b12e63..dd91c5e 100644 --- a/tz/system/system-feign/src/main/java/com/tz/platform/feign/IFeignSchool.java +++ b/tz/system/system-feign/src/main/java/com/tz/platform/feign/IFeignSchool.java @@ -4,6 +4,7 @@ import com.tz.platform.feign.vo.SchoolVo; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -15,4 +16,7 @@ public interface IFeignSchool { @RequestMapping(value = "/feign/system/school/list") List list(); + + @RequestMapping(value = "/feign/system/school/add") + void addSchool(@RequestBody String json); } diff --git a/tz/system/system-service/src/main/java/com/tz/platform/system/feign/FeignSchoolController.java b/tz/system/system-service/src/main/java/com/tz/platform/system/feign/FeignSchoolController.java index 5bd837a..c3f2a2f 100644 --- a/tz/system/system-service/src/main/java/com/tz/platform/system/feign/FeignSchoolController.java +++ b/tz/system/system-service/src/main/java/com/tz/platform/system/feign/FeignSchoolController.java @@ -1,10 +1,14 @@ package com.tz.platform.system.feign; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import com.tz.platform.common.core.tools.BeanUtils; import com.tz.platform.entity.School; import com.tz.platform.feign.IFeignSchool; import com.tz.platform.feign.vo.SchoolVo; import com.tz.platform.repository.SchoolDao; +import com.tz.platform.system.pc.biz.SchoolBiz; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -16,6 +20,9 @@ public class FeignSchoolController implements IFeignSchool { @Autowired private SchoolDao schoolDao ; + + @Autowired + private SchoolBiz schoolBiz; @Override public SchoolVo getByOuterId(Integer outerId) { School school = schoolDao.getByOuterId(outerId); @@ -29,4 +36,23 @@ public class FeignSchoolController implements IFeignSchool { List vo = BeanUtils.copyProperties(schoolList,SchoolVo.class); return vo; } + + @Override + public void addSchool(String json) { + JSONObject content = JSONUtil.parseObj(json); + int code = content.getInt("code"); + if(code == 200){ + JSONArray jsonArray = content.getJSONArray("data"); + jsonArray.forEach(object -> { + JSONObject schoolInfo = (JSONObject) object; + int id = schoolInfo.getInt("id"); + String name = schoolInfo.getStr("name"); + int level = schoolInfo.getInt("level"); + if(name.isEmpty() ==false){ + schoolBiz.save(id,name,level); + } + + }); + } + } } diff --git a/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/ZhiyunJob.java b/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/ZhiyunJob.java index 33e3420..cacd661 100644 --- a/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/ZhiyunJob.java +++ b/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/ZhiyunJob.java @@ -37,9 +37,11 @@ public class ZhiyunJob { boolean lr = lock(jobName,ms); if(lr){ try { + zhiyunAccountBiz.synSchool(); zhiyunAccountBiz.synGrade(); zhiyunAccountBiz.synAccountJob(); }catch (Exception ex){ + ex.printStackTrace(); log.error("大赛状态更新任务失败: {}",ex.getMessage()); }finally { unLock(jobName); @@ -47,6 +49,9 @@ public class ZhiyunJob { } } + + + /** * 获取一个redis分布锁 * diff --git a/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/biz/ZhiyunAccountBiz.java b/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/biz/ZhiyunAccountBiz.java index 6279b03..271bc52 100644 --- a/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/biz/ZhiyunAccountBiz.java +++ b/tz/user/user-service/src/main/java/com/tz/platform/zhiyun/biz/ZhiyunAccountBiz.java @@ -38,6 +38,7 @@ public class ZhiyunAccountBiz { public void synAccountJob(){ List schoolVoList = feignSchool.list(); schoolVoList.forEach(schoolVo -> { + String studentContent = zhiYunApi.findAllStudent(schoolVo.getOuterId()); dealStudent(studentContent,schoolVo); String teacherCountent = zhiYunApi.findTeacherBySchoolId(schoolVo.getOuterId()); @@ -53,6 +54,14 @@ public class ZhiyunAccountBiz { }); } + public void synSchool(){ + String content = zhiYunApi.findAuthSchool(); + if(!content.isEmpty()){ + feignSchool.addSchool(content); + } + + } + public void synQuestion(){ List schoolVoList = feignSchool.list(); schoolVoList.forEach(schoolVo -> { @@ -96,6 +105,9 @@ public class ZhiyunAccountBiz { JSONObject studentOb = (JSONObject)jo; Integer classId = studentOb.getInt("classId"); String studentNo = studentOb.getStr("studentNo"); + if(userList.stream().filter(user -> user.getStudentNo().equals(studentNo)).count()>0) { + return ; + } String name = studentOb.getStr("name"); User user = dealUser(studentNo,name,classId,school,UserTypeEnum.USER.getCode()); userList.add(user); @@ -106,7 +118,7 @@ public class ZhiyunAccountBiz { } private User dealUser(String studentNo,String name,int classId,SchoolVo school,Integer userType){ - User user =userDao.getByUsername(studentNo); + User user =userDao.getByStudentNo(studentNo); if(user == null){ user = new User(); user.setMobileSalt(StrUtil.get32UUID());