登录信息中添加电话字段

This commit is contained in:
wenc000 2019-08-11 20:11:51 +08:00
parent c972006c51
commit 99441e06be
14 changed files with 521 additions and 0 deletions

View File

@ -44,6 +44,7 @@ public class SecurityComponent {
UserBO userBO = (UserBO) user;
userInfoBO.setUserId(userBO.getUserId());
userInfoBO.setUserUsername(userBO.getUsername());
userInfoBO.setUserPhone(userBO.getUserPhone());
}
if (user instanceof UserInfoBO) {
userInfoBO = (UserInfoBO) user;

View File

@ -58,6 +58,7 @@ public class UserAuthConverter implements UserAuthenticationConverter {
userInfoBO.setUserId(userBO.getUserId());
userInfoBO.setUserUsername(userBO.getUsername());
userInfoBO.setUserName(userBO.getUserName());
userInfoBO.setUserPhone(userBO.getUserPhone());
principal = userInfoBO;
} else {
// 包含用户信息则直接抽取其中的用户信息
@ -67,6 +68,7 @@ public class UserAuthConverter implements UserAuthenticationConverter {
userInfoBO.setUserId(userInfo.get("userId").toString());
userInfoBO.setUserUsername(userInfo.get("username").toString());
userInfoBO.setUserName(userInfo.get("userName").toString());
userInfoBO.setUserPhone(userInfo.get("userPhone") == null ? "" : userInfo.get("userPhone").toString());
principal = userInfoBO;
}
}

View File

@ -0,0 +1,44 @@
package com.cm.common.pojo.bos;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: PositionBO
* @Description: 职位
* @Author: WangGeng
* @Date: 2019-08-10 13:27
* @Version: 1.0
**/
public class PositionBO {
private String positionId;
private String positionName;
public String getPositionId() {
return positionId == null ? "" : positionId.trim();
}
public void setPositionId(String positionId) {
this.positionId = positionId;
}
public String getPositionName() {
return positionName == null ? "" : positionName.trim();
}
public void setPositionName(String positionName) {
this.positionName = positionName;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"positionId\":")
.append("\"").append(positionId).append("\"");
sb.append(",\"positionName\":")
.append("\"").append(positionName).append("\"");
sb.append('}');
return sb.toString();
}
}

View File

@ -17,6 +17,7 @@ public class UserBO extends User {
private String userId;
private String userName;
private String userPhone;
private List<RoleBO> roles;
private List<GroupBO> groups;
private List<DepartmentBO> departments;
@ -49,6 +50,14 @@ public class UserBO extends User {
this.userName = userName;
}
public String getUserPhone() {
return userPhone == null ? "" : userPhone.trim();
}
public void setUserPhone(String userPhone) {
this.userPhone = userPhone;
}
public List<RoleBO> getRoles() {
return roles;
}
@ -80,6 +89,8 @@ public class UserBO extends User {
.append("\"").append(userId).append("\"");
sb.append(",\"userName\":")
.append("\"").append(userName).append("\"");
sb.append(",\"userPhone\":")
.append("\"").append(userPhone).append("\"");
sb.append(",\"roles\":")
.append(roles);
sb.append(",\"groups\":")

View File

@ -14,6 +14,7 @@ public class UserInfoBO {
private String userId;
private String userUsername;
private String userName;
private String userPhone;
private List<DepartmentBO> departments;
public String getUserId() {
@ -40,6 +41,14 @@ public class UserInfoBO {
this.userName = userName;
}
public String getUserPhone() {
return userPhone == null ? "" : userPhone.trim();
}
public void setUserPhone(String userPhone) {
this.userPhone = userPhone;
}
public List<DepartmentBO> getDepartments() {
return departments;
}
@ -57,6 +66,8 @@ public class UserInfoBO {
.append("\"").append(userUsername).append("\"");
sb.append(",\"userName\":")
.append("\"").append(userName).append("\"");
sb.append(",\"userPhone\":")
.append("\"").append(userPhone).append("\"");
sb.append(",\"departments\":")
.append(departments);
sb.append('}');

View File

@ -6,12 +6,15 @@ import com.cm.common.exception.TokenException;
import com.cm.common.token.app.entity.AppToken;
import com.cm.common.token.app.entity.AppTokenUser;
import com.cm.common.utils.AesUtil;
import com.cm.common.utils.DateUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -102,6 +105,39 @@ public class AppTokenManager {
return JSONObject.toJavaObject(userInfoObj, AppTokenUser.class);
}
/**
* 当前用户列表
*
* @return
*/
public List<AppTokenUser> listCurrentUsers() {
List<AppTokenUser> users = new ArrayList<>();
for (Map.Entry<String, AppToken> kvs : tokens.entrySet()) {
AppToken appToken = kvs.getValue();
users.add(appToken.getAppTokenUser());
}
return users;
}
/**
* 清空超时Token
*/
public synchronized void clearTimeoutToken() {
long currentTime = System.currentTimeMillis();
List<String> clearTokenKeys = new ArrayList<>(0);
for (Map.Entry<String, AppToken> kvs : tokens.entrySet()) {
AppToken appToken = kvs.getValue();
// 超过10分钟
if (currentTime - appToken.getLastTime() > 600000L) {
clearTokenKeys.add(kvs.getKey());
}
}
for (String tokenKey : clearTokenKeys) {
tokens.remove(tokenKey);
}
LOG.debug("本次共清理超时Token:{}个", clearTokenKeys.size());
}
private static class AppTokenManagerBuilder {
public static final AppTokenManager appTokenManager = new AppTokenManager();
}

View File

@ -0,0 +1,28 @@
package com.cm.common.token.app;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: AppTokenTask
* @Description: app token 定时任务
* @Author: WangGeng
* @Date: 2019-08-10 14:50
* @Version: 1.0
**/
@Component
@Configuration
@EnableScheduling
public class AppTokenTask {
@Scheduled(cron = "0 0/1 * * * ?")
public void clearAppTokenUser() {
AppTokenManager.getInstance().clearTimeoutToken();
}
}

View File

@ -1,5 +1,7 @@
package com.cm.common.token.app.entity;
import java.util.List;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
@ -18,6 +20,9 @@ public class AppTokenUser {
private String username;
private String phone;
private String email;
private List<AppTokenUserRole> appTokenUserRoles;
private List<AppTokenUserPosition> appTokenUserPositions;
private List<AppTokenUserDepartment> appTokenUserDepartments;
public String getId() {
return id == null ? "" : id.trim();
@ -67,6 +72,30 @@ public class AppTokenUser {
this.email = email;
}
public List<AppTokenUserRole> getAppTokenUserRoles() {
return appTokenUserRoles;
}
public void setAppTokenUserRoles(List<AppTokenUserRole> appTokenUserRoles) {
this.appTokenUserRoles = appTokenUserRoles;
}
public List<AppTokenUserPosition> getAppTokenUserPositions() {
return appTokenUserPositions;
}
public void setAppTokenUserPositions(List<AppTokenUserPosition> appTokenUserPositions) {
this.appTokenUserPositions = appTokenUserPositions;
}
public List<AppTokenUserDepartment> getAppTokenUserDepartments() {
return appTokenUserDepartments;
}
public void setAppTokenUserDepartments(List<AppTokenUserDepartment> appTokenUserDepartments) {
this.appTokenUserDepartments = appTokenUserDepartments;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
@ -82,6 +111,12 @@ public class AppTokenUser {
.append("\"").append(phone).append("\"");
sb.append(",\"email\":")
.append("\"").append(email).append("\"");
sb.append(",\"appTokenUserRoles\":")
.append(appTokenUserRoles);
sb.append(",\"appTokenUserPositions\":")
.append(appTokenUserPositions);
sb.append(",\"appTokenUserDepartments\":")
.append(appTokenUserDepartments);
sb.append('}');
return sb.toString();
}

View File

@ -0,0 +1,43 @@
package com.cm.common.token.app.entity;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: AppTokenUserDepartment
* @Description: 用户部门
* @Author: WangGeng
* @Date: 2019-08-10 14:21
* @Version: 1.0
**/
public class AppTokenUserDepartment {
private String departmentId;
private String departmentName;
public String getDepartmentId() {
return departmentId == null ? "" : departmentId.trim();
}
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName == null ? "" : departmentName.trim();
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"departmentId\":")
.append("\"").append(departmentId).append("\"");
sb.append(",\"departmentName\":")
.append("\"").append(departmentName).append("\"");
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,44 @@
package com.cm.common.token.app.entity;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: AppTokenUserPosition
* @Description: 用户职位
* @Author: WangGeng
* @Date: 2019-08-10 14:22
* @Version: 1.0
**/
public class AppTokenUserPosition {
private String positionId;
private String positionName;
public String getPositionId() {
return positionId == null ? "" : positionId.trim();
}
public void setPositionId(String positionId) {
this.positionId = positionId;
}
public String getPositionName() {
return positionName == null ? "" : positionName.trim();
}
public void setPositionName(String positionName) {
this.positionName = positionName;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"positionId\":")
.append("\"").append(positionId).append("\"");
sb.append(",\"positionName\":")
.append("\"").append(positionName).append("\"");
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,44 @@
package com.cm.common.token.app.entity;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: AppTokenUserRole
* @Description: 用户角色
* @Author: WangGeng
* @Date: 2019-08-10 12:25
* @Version: 1.0
**/
public class AppTokenUserRole {
private String roleId;
private String roleName;
public String getRoleId() {
return roleId == null ? "" : roleId.trim();
}
public void setRoleId(String roleId) {
this.roleId = roleId;
}
public String getRoleName() {
return roleName == null ? "" : roleName.trim();
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("{");
sb.append("\"roleId\":")
.append("\"").append(roleId).append("\"");
sb.append(",\"roleName\":")
.append("\"").append(roleName).append("\"");
sb.append('}');
return sb.toString();
}
}

View File

@ -0,0 +1,33 @@
package com.cm.common.utils.point;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: Circle
* @Description:
* @Author: WangGeng
* @Date: 2019-08-09 22:54
* @Version: 1.0
**/
public class Circle {
private double r;
private Point point;
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
}

View File

@ -0,0 +1,41 @@
package com.cm.common.utils.point;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: Point
* @Description:
* @Author: WangGeng
* @Date: 2019-08-09 22:44
* @Version: 1.0
**/
public class Point {
private double x;
private double y;
public Point() {
}
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}

View File

@ -0,0 +1,148 @@
package com.cm.common.utils.point;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: PointUtil
* @Description: 点工具类
* @Author: WangGeng
* @Date: 2019-08-09 22:43
* @Version: 1.0
**/
public class PointUtil {
/**
* 点在多边形内
*
* @param point
* @param points
* @return
*/
public static boolean isPointInPoly(Point point, List<Point> points) {
int N = points.size();
//如果点位于多边形的顶点或边上也算做点在多边形内直接返回true
boolean boundOrVertex = true;
//cross points count of x
int intersectCount = 0;
//浮点类型计算时候与0比较时候的容差
double precision = 2e-10;
//neighbour bound vertices
Point p1, p2;
//当前点
Point p = point;
//left vertex
p1 = points.get(0);
//check all rays
for (int i = 1; i <= N; ++i) {
if (p.equals(p1)) {
//p is an vertex
return boundOrVertex;
}
//right vertex
p2 = points.get(i % N);
//ray is outside of our interests
if (p.getX() < Math.min(p1.getX(), p2.getX()) || p.getX() > Math.max(p1.getX(), p2.getX())) {
p1 = p2;
continue;//next ray left point
}
//ray is crossing over by the algorithm (common part of)
if (p.getX() > Math.min(p1.getX(), p2.getX()) && p.getX() < Math.max(p1.getX(), p2.getX())) {
//x is before of ray
if (p.getY() <= Math.max(p1.getY(), p2.getY())) {
//overlies on a horizontal ray
if (p1.getX() == p2.getX() && p.getY() >= Math.min(p1.getY(), p2.getY())) {
return boundOrVertex;
}
//ray is vertical
if (p1.getY() == p2.getY()) {
//overlies on a vertical ray
if (p1.getY() == p.getY()) {
return boundOrVertex;
} else {
//before ray
++intersectCount;
}
} else {
//cross point on the left side
//cross point of y
double xinters = (p.getX() - p1.getX()) * (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()) + p1.getY();
//overlies on a ray
if (Math.abs(p.getY() - xinters) < precision) {
return boundOrVertex;
}
//before ray
if (p.getY() < xinters) {
++intersectCount;
}
}
}
} else {
//special case when ray is crossing through the vertex
//p crossing over p2
if (p.getX() == p2.getX() && p.getY() <= p2.getY()) {
//next vertex
Point p3 = points.get((i + 1) % N);
//p.x lies between p1.x & p3.x
if (p.getX() >= Math.min(p1.getX(), p3.getX()) && p.getX() <= Math.max(p1.getX(), p3.getX())) {
++intersectCount;
} else {
intersectCount += 2;
}
}
}
//next ray left point
p1 = p2;
}
if (intersectCount % 2 == 0) {
//偶数在多边形外
return false;
} else {
//奇数在多边形内
return true;
}
}
/**
* 判断是否在圆形内
* <p>
* 判断点与圆心之间的距离和圆半径的关系
*
* @param p
* @param c
* @return
*/
public static int distencePC(Point p, Circle c) {
int s;
double d2 = Math.hypot((p.getX() - c.getPoint().getX()), (p.getY() - c.getPoint().getY()));
double r = c.getR();
if (d2 > r) {
// 圆外
s = -1;
} else if (d2 < r) {
// 圆内
s = 1;
} else {
// 圆上
s = 0;
}
return s;
}
public static void main(String[] args) {
Point point = new Point(111.770495, 40.871839);
List<Point> points = new ArrayList<>();
points.add(new Point(111.76776160830235, 40.87164162798379));
points.add(new Point(111.76940775314925, 40.868854144474206));
points.add(new Point(111.77202968235643, 40.86936472871906));
points.add(new Point(111.77072713936697, 40.87228340534707));
System.out.println(PointUtil.isPointInPoly(point, points));
}
}