用户相关

master
yz 7 months ago
parent 9ee8caedf5
commit fe30f5c5c1

@ -0,0 +1,47 @@
package com.sztzjy.money_management.controller;
import com.sztzjy.money_management.annotation.AnonymousAccess;
import com.sztzjy.money_management.mapper.ChapterMapper;
import com.sztzjy.money_management.service.ChapterService;
import com.sztzjy.money_management.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@Api(tags = "章节相关相关")
@RequestMapping("api/ChapterController")
public class ChapterController {
@Autowired
ChapterMapper chapterMapper;
@Autowired
ChapterService chapterService;
//章节添加
// @AnonymousAccess
// @ApiOperation("章节查询")
// @PostMapping("chapterAdd")
// public ResultEntity<String> chapterAdd(@RequestParam String chapterName,
// @ApiParam("来源学校ID/内置)") @RequestParam String source) {
// if(StringUtils.isBlank(source)){
//
// }
//
// }
// //章节查询
// @AnonymousAccess
// @ApiOperation("章节查询")
// @PostMapping("chapterSelect")
// public ResultEntity<String> chapterSelect() {
//
// }
//章节删除
}

@ -0,0 +1,12 @@
package com.sztzjy.money_management.controller;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Api(tags = "知识概要相关")
@RequestMapping("api/KnowledgeNoteController")
public class KnowledgeNoteController {
}

@ -0,0 +1,147 @@
package com.sztzjy.money_management.controller.common;
import cn.hutool.core.util.IdUtil;
import com.sztzjy.money_management.annotation.AnonymousAccess;
import com.sztzjy.money_management.config.exception.UnAuthorizedException;
import com.sztzjy.money_management.config.security.JwtUser;
import com.sztzjy.money_management.config.security.LoginResult;
import com.sztzjy.money_management.config.security.TokenProvider;
import com.sztzjy.money_management.entity.UserInfo;
import com.sztzjy.money_management.entity.UserInfoExample;
import com.sztzjy.money_management.entity.zy.ZYUserInfo;
import com.sztzjy.money_management.mapper.UserInfoMapper;
import com.sztzjy.money_management.util.ResultEntity;
import com.sztzjy.money_management.util.RsaUtil;
import com.sztzjy.money_management.util.TzApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@RestController
@RequestMapping("/api/user")
@Api(tags = "用户登录、账号相关")
public class UserController {
@Resource
private AuthenticationManagerBuilder authenticationManagerBuilder;
@Autowired
UserInfoMapper userInfoMapper;
@PostMapping("/login")
@ApiOperation("登录接口")
@AnonymousAccess
public ResultEntity login(@RequestParam(required = false) String passwordEncode,
@RequestParam(required = false) String userName,
HttpServletRequest request,
@RequestParam(required = false) String TOKEN) {
JwtUser jwtUser;
String passWord;
if (StringUtils.isBlank(TOKEN)) {
try {
passWord = RsaUtil.decryptByPrivateKey(passwordEncode);
} catch (Exception e) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "密码错误");
}
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userName, passWord);
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
jwtUser = (JwtUser) authentication.getPrincipal();
String token = TokenProvider.createToken(jwtUser);
// 1、子系统直接登录
UserInfoExample stuUserExample = new UserInfoExample();
stuUserExample.createCriteria().andUsernameEqualTo(userName).andPasswordEqualTo(passWord);
List<UserInfo> stuUsers = userInfoMapper.selectByExample(stuUserExample);
//不存在返回错误,正确放行
if (stuUsers.isEmpty()) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "密码错误");
}
// 保存用户的登录信息
Map<String, Object> map = new HashMap<>();
UserInfo user = stuUsers.get(0);
map.put("name", user.getName());
map.put("username", user.getUsername());
map.put("roleId", user.getRoleId());
map.put("schoolId", user.getSchoolId());
map.put("classId", user.getClassId());
map.put("userId", user.getUserid());
map.put("token", token);
return new ResultEntity(HttpStatus.OK, map);
} else { // 2、智云单点登录
jwtUser = TokenProvider.getJWTUserByZhiYun(TOKEN);
jwtUser = TzApi.foreignExchangeTradingLogin(jwtUser.getUsername(), jwtUser.getPassword());
if (jwtUser == null) {
throw new UnAuthorizedException("用户名或密码错误");
}
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
String token = TokenProvider.createToken(jwtUser);
LoginResult loginResult = LoginResult.create(jwtUser, token);
Map<String, Object> map = new HashMap<>();
map.put("name", loginResult.getName());
map.put("username", loginResult.getUsername());
map.put("roleId", loginResult.getRoleId());
map.put("schoolId", loginResult.getSchoolId());
if (StringUtils.isNotBlank(loginResult.getUserId())) {
map.put("classId", loginResult.getClassId());
}
map.put("userId", loginResult.getUserId());
map.put("token", token);
return new ResultEntity(HttpStatus.OK, map); //todo 从智云登录后将用户添加到本地用户表
}
}
@ApiOperation("根据用户Code查询该用户是否存在个人赛用户数据存在则返回不存在则新增后返回用于智云3.0创建用户后调用该接口创建用户个人赛")
@PostMapping("/checkOrCreateForexSimulationUser")
@AnonymousAccess
public String checkOrCreateForexSimulationUser(@RequestBody List<ZYUserInfo> zyUserInfoList,
@RequestParam String systemOwner) {
System.out.println(systemOwner);
List<UserInfo> users = new ArrayList<>();
for (int i = 0; i < zyUserInfoList.size(); i++) {
ZYUserInfo zyUserInfo = zyUserInfoList.get(i);
Integer zyUserId = zyUserInfo.getUserId();
String username = zyUserInfo.getUsername(); // studentid
String name = zyUserInfo.getName();
String password = zyUserInfo.getPassword();
Integer roleId = zyUserInfo.getRoleId(); //3教师 4学生
UserInfo userInfo = userInfoMapper.selectByPrimaryKey(String.valueOf(zyUserId));
if (userInfo!=null) {
continue;
}
UserInfo stuUser = new UserInfo();
stuUser.setUserid(IdUtil.randomUUID());
stuUser.setStudentId(zyUserInfo.getUsername());
stuUser.setName(name);
stuUser.setUsername(username);
stuUser.setClassId(zyUserInfo.getClassId().toString());
stuUser.setPassword(password);
stuUser.setPhone(zyUserInfo.getPhone());
stuUser.setMajor(zyUserInfo.getMajorName());
stuUser.setRoleId(roleId);
stuUser.setSchoolId(zyUserInfo.getSchoolId().toString());
stuUser.setSchoolName(zyUserInfo.getSchoolName());
stuUser.setCreateTime(new Date());
users.add(stuUser);
}
if (users.isEmpty()) {
return "账号已全部存在";
}
userInfoMapper.batchInsertUserInfo(users);
return "ok";
}
}

@ -0,0 +1,22 @@
package com.sztzjy.money_management.entity.zy;
import lombok.Data;
@Data
public class ZYUserInfo {
private String username;
private String password;
private String name;
private Integer userId;
private Integer roleId;
private Integer schoolId;
private String schoolName;
private Integer classId;
private String className;
private String phone;
private Long collegeId;
private String collegeName;
private Long majorId;
private String majorName;
}

@ -29,4 +29,6 @@ public interface UserInfoMapper {
int updateByPrimaryKeySelective(UserInfo record);
int updateByPrimaryKey(UserInfo record);
void batchInsertUserInfo(List<UserInfo> users);
}

@ -0,0 +1,7 @@
package com.sztzjy.money_management.service;
import org.springframework.stereotype.Service;
@Service
public interface ChapterService {
}

@ -0,0 +1,6 @@
package com.sztzjy.money_management.service.impl;
import com.sztzjy.money_management.service.ChapterService;
public class ChapterServiceImpl implements ChapterService {
}

@ -350,4 +350,15 @@
school_name = #{schoolName,jdbcType=VARCHAR}
where userid = #{userid,jdbcType=VARCHAR}
</update>
<insert id="batchInsertStudents" parameterType="java.util.List">
INSERT INTO stu_userinfo (userid, name, student_id, class_id,class_name, username, password, phone,
email,major,
role_id,create_time,school_id,school_name) VALUES
<foreach collection="list" item="student" separator=",">
(#{student.userid}, #{student.name}, #{student.studentId}, #{student.classId},#{student.className}, #{student.username},
#{student.password}, #{student.phone}, #{student.email},#{student.major},#{student.roleId},
#{student.createTime},#{student.schoolId},#{student.schoolName})
</foreach>
</insert>
</mapper>
Loading…
Cancel
Save