|
|
@ -11,11 +11,14 @@ import com.sztzjy.fund_investment.entity.PerformanceScoreExample;
|
|
|
|
import com.sztzjy.fund_investment.entity.User;
|
|
|
|
import com.sztzjy.fund_investment.entity.User;
|
|
|
|
import com.sztzjy.fund_investment.mapper.FlowMapper;
|
|
|
|
import com.sztzjy.fund_investment.mapper.FlowMapper;
|
|
|
|
import com.sztzjy.fund_investment.mapper.PerformanceScoreMapper;
|
|
|
|
import com.sztzjy.fund_investment.mapper.PerformanceScoreMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.fund_investment.mapper.UserMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.fund_investment.service.IIlabService;
|
|
|
|
import com.sztzjy.fund_investment.service.IUserService;
|
|
|
|
import com.sztzjy.fund_investment.service.IUserService;
|
|
|
|
import com.sztzjy.fund_investment.util.ResultEntity;
|
|
|
|
import com.sztzjy.fund_investment.util.ResultEntity;
|
|
|
|
import com.sztzjy.fund_investment.util.RsaUtil;
|
|
|
|
import com.sztzjy.fund_investment.util.RsaUtil;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
@ -29,77 +32,142 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "用户管理")
|
|
|
|
@Api(tags = "用户管理")
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("api/user")
|
|
|
|
@RequestMapping("api/user")
|
|
|
|
public class UserController {
|
|
|
|
public class UserController {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IUserService userService;
|
|
|
|
private IUserService userService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private UserMapper userMapper;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
|
|
private AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private FlowMapper flowMapper;
|
|
|
|
private FlowMapper flowMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private PerformanceScoreMapper performanceScoreMapper;
|
|
|
|
private PerformanceScoreMapper performanceScoreMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private IIlabService iIlabService;
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "用户登录", httpMethod = "POST")
|
|
|
|
@ApiOperation(value = "用户登录", httpMethod = "POST")
|
|
|
|
@OperateLog(recordParameters = false)
|
|
|
|
@OperateLog(recordParameters = false)
|
|
|
|
@PostMapping("login")
|
|
|
|
@PostMapping("login")
|
|
|
|
@AnonymousAccess
|
|
|
|
@AnonymousAccess
|
|
|
|
public ResultEntity login(@RequestParam String username, @RequestParam String passwordEncode) {
|
|
|
|
public ResultEntity login(@RequestParam(required = false) String username,
|
|
|
|
String password;
|
|
|
|
@RequestParam(required = false) String passwordEncode,
|
|
|
|
try {
|
|
|
|
@RequestParam(required = false) String ticket) {
|
|
|
|
password = RsaUtil.decryptByPrivateKey(passwordEncode);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (ticket==null) {
|
|
|
|
return new ResultEntity(HttpStatus.BAD_REQUEST, "密码错误");
|
|
|
|
String password;
|
|
|
|
|
|
|
|
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 = (JwtUser) authentication.getPrincipal();
|
|
|
|
|
|
|
|
String token = TokenProvider.createToken(jwtUser);
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("token", token);
|
|
|
|
|
|
|
|
map.put("name", jwtUser.getName());
|
|
|
|
|
|
|
|
User user = userService.findById(jwtUser.getUserId());
|
|
|
|
|
|
|
|
map.put("username", user.getUsername());
|
|
|
|
|
|
|
|
map.put("roleId", user.getRoleId());
|
|
|
|
|
|
|
|
map.put("phone", user.getPhone());
|
|
|
|
|
|
|
|
map.put("schoolId", "999999999");
|
|
|
|
|
|
|
|
map.put("userId", user.getUserid());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Flow flow = flowMapper.selectByPrimaryKey(jwtUser.getUserId());
|
|
|
|
|
|
|
|
if (flow == null) {
|
|
|
|
|
|
|
|
String uuid = String.valueOf(UUID.randomUUID());
|
|
|
|
|
|
|
|
Flow flow1 = new Flow();
|
|
|
|
|
|
|
|
flow1.setUserid(jwtUser.getUserId());
|
|
|
|
|
|
|
|
flow1.setFlowId(uuid);
|
|
|
|
|
|
|
|
flowMapper.insert(flow1);
|
|
|
|
|
|
|
|
map.put("flowId", uuid);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
map.put("flowId", flow.getFlowId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, map);
|
|
|
|
|
|
|
|
} else { //平台跳转登录
|
|
|
|
|
|
|
|
//判断用户是否存在
|
|
|
|
|
|
|
|
Map<String, String> accessToken = iIlabService.getAccessToken(ticket);
|
|
|
|
|
|
|
|
String access_token = accessToken.get("access_token");
|
|
|
|
|
|
|
|
if (access_token==null){
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.BAD_REQUEST,"登录过期,请重试!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String un = accessToken.get("un");
|
|
|
|
|
|
|
|
String dis = accessToken.get("dis");
|
|
|
|
|
|
|
|
User user = userMapper.selectByUn(un);
|
|
|
|
|
|
|
|
String newUUID = IdUtil.simpleUUID();
|
|
|
|
|
|
|
|
String flowId = IdUtil.simpleUUID();
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
|
|
Map<String, Object> map = getStringObjectMap(access_token, un, dis, newUUID, flowId);
|
|
|
|
|
|
|
|
user.setAccessToken(access_token);
|
|
|
|
|
|
|
|
userMapper.updateByPrimaryKey(user);
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, map);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
User newUser = new User();
|
|
|
|
|
|
|
|
newUser.setUserid(IdUtil.simpleUUID());
|
|
|
|
|
|
|
|
newUser.setRoleId(4);
|
|
|
|
|
|
|
|
newUser.setLoginType(0);
|
|
|
|
|
|
|
|
newUser.setAccessToken(access_token);
|
|
|
|
|
|
|
|
newUser.setDis(dis);
|
|
|
|
|
|
|
|
newUser.setName(dis);
|
|
|
|
|
|
|
|
newUser.setUn(un);
|
|
|
|
|
|
|
|
newUser.setUsername(un);
|
|
|
|
|
|
|
|
newUser.setCreateTime(new Date());
|
|
|
|
|
|
|
|
newUser.setSchoolId("999999999");
|
|
|
|
|
|
|
|
newUser.setClassId("999999999");
|
|
|
|
|
|
|
|
newUser.setClassName("国家虚拟仿真训练班");
|
|
|
|
|
|
|
|
Map<String, Object> map = getStringObjectMap(access_token, un, dis, newUUID, flowId);
|
|
|
|
|
|
|
|
userMapper.insert(newUser);
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 封装MAP并生成flow表数据
|
|
|
|
|
|
|
|
* @author xcj
|
|
|
|
|
|
|
|
* @Date 2024/1/3
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Map<String, Object> getStringObjectMap(String access_token, String un, String dis, String newUUID, String flowId) {
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken("tzs001", "123qwe");
|
|
|
|
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
|
|
|
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
|
JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
|
|
|
|
JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
|
|
|
|
String token = TokenProvider.createToken(jwtUser);
|
|
|
|
String token = TokenProvider.createToken(jwtUser);
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("token", token);
|
|
|
|
map.put("token", token);
|
|
|
|
map.put("name", jwtUser.getName());
|
|
|
|
map.put("access_token", access_token);
|
|
|
|
User user = userService.findById(jwtUser.getUserId());
|
|
|
|
map.put("un", un);
|
|
|
|
map.put("username", user.getUsername());
|
|
|
|
map.put("username", un);
|
|
|
|
map.put("roleId", user.getRoleId());
|
|
|
|
map.put("dis", dis);
|
|
|
|
map.put("phone", user.getPhone());
|
|
|
|
map.put("name", dis);
|
|
|
|
map.put("schoolId", user.getSchoolId());
|
|
|
|
map.put("roleId", 4);
|
|
|
|
map.put("userId", user.getUserid());
|
|
|
|
map.put("schoolId", "999999999");
|
|
|
|
|
|
|
|
map.put("classId", "999999999");
|
|
|
|
Flow flow = flowMapper.selectByPrimaryKey(jwtUser.getUserId());
|
|
|
|
Flow flow = new Flow();
|
|
|
|
if (flow == null) {
|
|
|
|
flow.setUserid(newUUID);
|
|
|
|
String uuid = String.valueOf(UUID.randomUUID());
|
|
|
|
flow.setFlowId(flowId);
|
|
|
|
Flow flow1 = new Flow();
|
|
|
|
flowMapper.insert(flow);
|
|
|
|
flow1.setUserid(jwtUser.getUserId());
|
|
|
|
map.put("flowId", flowId);
|
|
|
|
flow1.setFlowId(uuid);
|
|
|
|
return map;
|
|
|
|
flowMapper.insert(flow1);
|
|
|
|
|
|
|
|
map.put("flowId", uuid);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
map.put("flowId", flow.getFlowId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, map);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
// public static void main(String[] args) throws Exception {
|
|
|
|
String password = "123qwe";
|
|
|
|
// String password = "123qwe";
|
|
|
|
password = RsaUtil.encryptByPublicKey(password);
|
|
|
|
// password = RsaUtil.encryptByPublicKey(password);
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
password = RsaUtil.decryptByPrivateKey(password);
|
|
|
|
// password = RsaUtil.decryptByPrivateKey(password);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// } catch (Exception e) {
|
|
|
|
throw new IllegalArgumentException("密文不正确,请检查");
|
|
|
|
// throw new IllegalArgumentException("密文不正确,请检查");
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
System.out.println(new BCryptPasswordEncoder().encode(password));
|
|
|
|
// System.out.println(new BCryptPasswordEncoder().encode(password));
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "重新实训", httpMethod = "POST")
|
|
|
|
@ApiOperation(value = "重新实训", httpMethod = "POST")
|
|
|
|
@PostMapping("reTraining")
|
|
|
|
@PostMapping("reTraining")
|
|
|
@ -118,4 +186,6 @@ public class UserController {
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, "已重新实训!");
|
|
|
|
return new ResultEntity(HttpStatus.OK, "已重新实训!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|