parent
ce2cd85e24
commit
6ac99e9dec
@ -0,0 +1,60 @@
|
||||
package com.tz.platform.common.core.api;
|
||||
|
||||
import com.tz.platform.common.core.tools.HttpUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ZhiYunApi {
|
||||
String baseUrl = "http://139.159.242.249:8890";
|
||||
Map<String,String> headers = null;
|
||||
public ZhiYunApi(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String findAllGrade(Integer schoolId){
|
||||
String content = HttpUtil.get(baseUrl+"/api/classes/findAllBySchoolId?schoolId="+schoolId,headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findAllSchool(){
|
||||
String content = HttpUtil.get(baseUrl+"/api/school/findAll",headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findAllStudent(Integer schoolId){
|
||||
String content = HttpUtil.get(baseUrl+"/api/student/findAllBySchoolId?schoolId="+schoolId,headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findTeacherBySchoolId(Integer schoolId){
|
||||
String content = HttpUtil.get(baseUrl+"/api/teacher/findAllBySchoolId?schoolId="+schoolId,headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findClassesBySchoolId(Integer schoolId){
|
||||
String content = HttpUtil.get(baseUrl+"/api/classes/findAllBySchoolId?schoolId="+schoolId,headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findAllCource(){
|
||||
String content = HttpUtil.get(baseUrl+"/api/course/findAll",headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
public String findCourceBySchool(Integer schoolId){
|
||||
String content = HttpUtil.get(baseUrl+"/api/course/findAllBySchoolId?schoolId="+schoolId,headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findAllQuestion(){
|
||||
String content = HttpUtil.get(baseUrl+"/api/question/findAll",headers);
|
||||
return content;
|
||||
}
|
||||
|
||||
public String findQuestionByCourseId(Integer courseId,Integer pageIndex,Integer pageSize){
|
||||
String content = HttpUtil.get(baseUrl+"/api/question/findByCourseId?courseId="+courseId+"&pageSize="+pageSize+"&pageIndex="+pageIndex,headers);
|
||||
return content;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
build.artifact=competition
|
||||
build.group=com.tz
|
||||
build.name=competition
|
||||
build.time=2022-06-16T05\:40\:57.634Z
|
||||
build.time=2022-08-25T14\:09\:03.001Z
|
||||
build.version=1.0-SNAPSHOT
|
||||
|
@ -1,5 +1,5 @@
|
||||
build.artifact=gateway
|
||||
build.group=com.tz
|
||||
build.name=gateway
|
||||
build.time=2022-06-16T05\:40\:57.634Z
|
||||
build.time=2022-08-25T14\:09\:03.001Z
|
||||
build.version=1.0-SNAPSHOT
|
||||
|
@ -1,5 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Thu Jun 16 13:41:15 CST 2022
|
||||
#Thu Aug 25 22:09:13 CST 2022
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=com.tz
|
||||
artifactId=gateway
|
||||
|
Binary file not shown.
@ -0,0 +1,20 @@
|
||||
package com.tz.platform.feign;
|
||||
|
||||
import com.tz.platform.feign.vo.GradeVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FeignClient(value = "tz-system-service")
|
||||
public interface IFeignGrade {
|
||||
@RequestMapping(value = "/feign/system/grade/getByOuterId")
|
||||
GradeVo getByOuterId(@RequestBody Integer outerId);
|
||||
|
||||
@RequestMapping(value = "/feign/system/grade/save")
|
||||
GradeVo saveGrade(@RequestBody GradeVo vo);
|
||||
|
||||
@RequestMapping(value = "/feign/system/grade/saveAll")
|
||||
void saveAllGrade(@RequestBody List<GradeVo> gradeVoList);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.tz.platform.feign;
|
||||
|
||||
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 java.util.List;
|
||||
|
||||
|
||||
@FeignClient(value = "tz-system-service")
|
||||
public interface IFeignSchool {
|
||||
@RequestMapping(value = "/feign/system/school/getByOuterId")
|
||||
SchoolVo getByOuterId(@RequestBody Integer outerId);
|
||||
|
||||
@RequestMapping(value = "/feign/system/school/list")
|
||||
List<SchoolVo> list();
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.tz.platform.feign.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class GradeVo {
|
||||
private String classNo;
|
||||
private String name;
|
||||
private Date createTime;
|
||||
private Long userNo;
|
||||
private Integer schoolId;
|
||||
private Integer outerId;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.tz.platform.feign.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class SchoolVo {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer provinceId;
|
||||
private String province;
|
||||
private Integer levelId;
|
||||
private String level;
|
||||
private Date createTime;
|
||||
private Integer outerId;
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.tz.platform.system.feign;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.tz.platform.common.core.tools.BeanUtils;
|
||||
import com.tz.platform.entity.Grade;
|
||||
import com.tz.platform.feign.IFeignGrade;
|
||||
import com.tz.platform.feign.vo.GradeVo;
|
||||
import com.tz.platform.repository.GradeDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class FeigGradeController implements IFeignGrade {
|
||||
|
||||
@Autowired
|
||||
private GradeDao gradeDao;
|
||||
|
||||
@Override
|
||||
public GradeVo getByOuterId(Integer outerId) {
|
||||
Grade grade = gradeDao.getByOuterId(outerId);
|
||||
return BeanUtils.copyProperties(grade,GradeVo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GradeVo saveGrade(GradeVo vo) {
|
||||
Grade grade = BeanUtils.copyProperties(vo,Grade.class);
|
||||
grade = gradeDao.save(grade);
|
||||
return BeanUtils.copyProperties(grade,GradeVo.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllGrade(List<GradeVo> gradeVoList) {
|
||||
List<Grade> gradeList = BeanUtils.copyProperties(gradeVoList,Grade.class);
|
||||
gradeList.forEach(grade -> {
|
||||
if(StringUtils.isEmpty(grade.getClassNo())){
|
||||
grade.setClassNo(UUID.fastUUID().toString(true));
|
||||
}
|
||||
});
|
||||
gradeDao.saveAll(gradeList);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.tz.platform.system.feign;
|
||||
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
public class FeignSchoolController implements IFeignSchool {
|
||||
|
||||
@Autowired
|
||||
private SchoolDao schoolDao ;
|
||||
@Override
|
||||
public SchoolVo getByOuterId(Integer outerId) {
|
||||
School school = schoolDao.getByOuterId(outerId);
|
||||
SchoolVo schoolVo = BeanUtils.copyProperties(school,SchoolVo.class);
|
||||
return schoolVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchoolVo> list() {
|
||||
List<School> schoolList = schoolDao.findAll();
|
||||
List<SchoolVo> vo = BeanUtils.copyProperties(schoolList,SchoolVo.class);
|
||||
return vo;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.tz.platform.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
|
||||
@Configuration
|
||||
@EnableResourceServer
|
||||
public class MyResourceServerConfigurer extends ResourceServerConfigurerAdapter {
|
||||
@Override
|
||||
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
|
||||
super.configure(resources);
|
||||
}
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception{
|
||||
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests().antMatchers("/api/auth/**").authenticated();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.tz.platform.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
|
||||
|
||||
@Configuration
|
||||
@EnableAuthorizationServer
|
||||
public class MyauthorizationServerConfigurer extends AuthorizationServerConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
@Override
|
||||
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception{
|
||||
security.allowFormAuthenticationForClients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(ClientDetailsServiceConfigurer clients) throws Exception{
|
||||
clients.inMemory()
|
||||
.withClient("zhiyun")
|
||||
.authorizedGrantTypes("client_credentials")
|
||||
.scopes("all")
|
||||
.secret("zhiyun2022");
|
||||
}
|
||||
|
||||
|
||||
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
|
||||
endpoints.authenticationManager(authenticationManager);
|
||||
super.configure(endpoints);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.tz.platform.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder(){
|
||||
return new PasswordEncoder() {
|
||||
@Override
|
||||
public String encode(CharSequence charSequence) {
|
||||
return charSequence.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CharSequence charSequence, String s) {
|
||||
return s.equals(charSequence.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
@Bean
|
||||
public AuthenticationManager authenticationManager() throws Exception{
|
||||
return super.authenticationManager();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.tz.platform.user.api;
|
||||
|
||||
import com.tz.platform.common.core.base.Result;
|
||||
import com.tz.platform.common.core.enmus.UserTypeEnum;
|
||||
import com.tz.platform.common.core.tools.JWTUtil;
|
||||
import com.tz.platform.entity.User;
|
||||
import com.tz.platform.repository.UserDao;
|
||||
import com.tz.platform.user.api.biz.ApiUserLoginBiz;
|
||||
import com.tz.platform.user.api.dto.OauthDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/auth")
|
||||
public class OauthController {
|
||||
|
||||
@Autowired
|
||||
private ApiUserLoginBiz userLoginBiz;
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
|
||||
@PostMapping("login")
|
||||
public Result<OauthDTO> login(String uname, Integer uid){
|
||||
OauthDTO oauthDTO = new OauthDTO();
|
||||
User user = userDao.getByUsername(uname);
|
||||
if(user == null){
|
||||
return Result.error("用户不存在");
|
||||
}
|
||||
String token =JWTUtil.create(user.getId(),user.getUserType(), JWTUtil.DATE);
|
||||
oauthDTO.setToken(token);
|
||||
String baseUrl = "https://zqtzdss.sztzjy.com/index?token=";
|
||||
if(user.getUserType() > UserTypeEnum.USER.getCode()){
|
||||
baseUrl = "http://zqtzdst.sztzjy.com/#/login?token=";
|
||||
}
|
||||
oauthDTO.setUrl(baseUrl+token);
|
||||
return Result.success(oauthDTO);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.tz.platform.user.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class OauthDTO implements Serializable {
|
||||
private String url;
|
||||
private String token;
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
package com.tz.platform.zhiyun.biz;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.tz.platform.common.core.api.ZhiYunApi;
|
||||
import com.tz.platform.common.core.config.SystemUtil;
|
||||
import com.tz.platform.common.core.enmus.UserTypeEnum;
|
||||
import com.tz.platform.common.core.tools.StrUtil;
|
||||
import com.tz.platform.entity.User;
|
||||
import com.tz.platform.feign.IFeignGrade;
|
||||
import com.tz.platform.feign.IFeignSchool;
|
||||
import com.tz.platform.feign.vo.GradeVo;
|
||||
import com.tz.platform.feign.vo.SchoolVo;
|
||||
import com.tz.platform.repository.UserDao;
|
||||
import org.apache.commons.collections4.list.GrowthList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ZhiyunAccountBiz {
|
||||
private ZhiYunApi zhiYunApi =new ZhiYunApi();
|
||||
|
||||
@Autowired
|
||||
private IFeignSchool feignSchool ;
|
||||
|
||||
@Autowired
|
||||
private IFeignGrade feignGrade ;
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
public void synAccountJob(){
|
||||
List<SchoolVo> schoolVoList = feignSchool.list();
|
||||
schoolVoList.forEach(schoolVo -> {
|
||||
String studentContent = zhiYunApi.findAllStudent(schoolVo.getOuterId());
|
||||
dealStudent(studentContent,schoolVo);
|
||||
String teacherCountent = zhiYunApi.findTeacherBySchoolId(schoolVo.getOuterId());
|
||||
dealTeacher(teacherCountent,schoolVo);
|
||||
});
|
||||
}
|
||||
|
||||
public void synGrade(){
|
||||
List<SchoolVo> schoolVoList = feignSchool.list();
|
||||
schoolVoList.forEach(schoolVo -> {
|
||||
String gradeContent = zhiYunApi.findAllGrade(schoolVo.getOuterId());
|
||||
dealGrade(gradeContent,schoolVo);
|
||||
});
|
||||
}
|
||||
|
||||
public void synQuestion(){
|
||||
List<SchoolVo> schoolVoList = feignSchool.list();
|
||||
schoolVoList.forEach(schoolVo -> {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void dealGrade(String content,SchoolVo school){
|
||||
JSONObject jsonObject = JSONUtil.parseObj(content);
|
||||
Integer code = jsonObject.getInt("code");
|
||||
if(code == 200 ){
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
||||
List<GradeVo> gradeVoList = new ArrayList<>();
|
||||
jsonArray.forEach(jo->{
|
||||
JSONObject studentOb = (JSONObject)jo;
|
||||
Integer outerId = studentOb.getInt("id");
|
||||
String name = studentOb.getStr("name");
|
||||
GradeVo vo = feignGrade.getByOuterId(outerId);
|
||||
if(vo == null){
|
||||
vo = new GradeVo();
|
||||
vo.setCreateTime(new Date());
|
||||
}
|
||||
vo.setName(name);
|
||||
vo.setOuterId(outerId);
|
||||
vo.setUserNo(0L);
|
||||
vo.setSchoolId(school.getId());
|
||||
gradeVoList.add(vo);
|
||||
});
|
||||
feignGrade.saveAllGrade(gradeVoList);
|
||||
}
|
||||
}
|
||||
|
||||
private void dealStudent(String content,SchoolVo school){
|
||||
JSONObject jsonObject = JSONUtil.parseObj(content);
|
||||
Integer code = jsonObject.getInt("code");
|
||||
if(code == 200 ){
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
||||
List<User> userList = new ArrayList<>();
|
||||
jsonArray.forEach(jo->{
|
||||
JSONObject studentOb = (JSONObject)jo;
|
||||
Integer classId = studentOb.getInt("classId");
|
||||
String studentNo = studentOb.getStr("studentNo");
|
||||
String name = studentOb.getStr("name");
|
||||
User user = dealUser(studentNo,name,classId,school,UserTypeEnum.USER.getCode());
|
||||
userList.add(user);
|
||||
});
|
||||
userDao.saveAll(userList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private User dealUser(String studentNo,String name,int classId,SchoolVo school,Integer userType){
|
||||
User user =userDao.getByUsername(studentNo);
|
||||
if(user == null){
|
||||
user = new User();
|
||||
user.setMobileSalt(StrUtil.get32UUID());
|
||||
user.setMobilePsw(DigestUtil.sha1Hex(user.getMobileSalt() + SystemUtil.INIT_PASSWORD));
|
||||
}
|
||||
user.setSchoolId(school.getId());
|
||||
user.setOuterId(0);
|
||||
user.setSchool(school.getName());
|
||||
|
||||
|
||||
//需要设置值
|
||||
user.setClassName("");
|
||||
user.setClassId(0);
|
||||
GradeVo gradeVo = feignGrade.getByOuterId(classId);
|
||||
if(gradeVo !=null){
|
||||
user.setClassName(gradeVo.getName());
|
||||
user.setClassId(gradeVo.getOuterId());
|
||||
}
|
||||
user.setLevelId(school.getLevelId());
|
||||
user.setName(name);
|
||||
user.setUsername(studentNo);
|
||||
user.setStatusId(1);
|
||||
user.setUserType(userType);
|
||||
user.setStudentNo(studentNo);
|
||||
return user;
|
||||
}
|
||||
|
||||
private void dealTeacher(String content,SchoolVo school){
|
||||
JSONObject jsonObject = JSONUtil.parseObj(content);
|
||||
Integer code = jsonObject.getInt("code");
|
||||
if(code == 200 ){
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
||||
List<User> userList = new ArrayList<>();
|
||||
jsonArray.forEach(jo->{
|
||||
JSONObject studentOb = (JSONObject)jo;
|
||||
String studentNo = studentOb.getStr("teacherNo");
|
||||
String name = studentOb.getStr("name");
|
||||
User user = dealUser(studentNo,name,0,school,UserTypeEnum.TEACHER.getCode());
|
||||
userList.add(user);
|
||||
});
|
||||
userDao.saveAll(userList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue