diff --git a/cloud-common/src/main/java/com/cm/common/component/SecurityComponent.java b/cloud-common/src/main/java/com/cm/common/component/SecurityComponent.java index 05d511e..070e64a 100644 --- a/cloud-common/src/main/java/com/cm/common/component/SecurityComponent.java +++ b/cloud-common/src/main/java/com/cm/common/component/SecurityComponent.java @@ -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; diff --git a/cloud-common/src/main/java/com/cm/common/converter/UserAuthConverter.java b/cloud-common/src/main/java/com/cm/common/converter/UserAuthConverter.java index 68de225..f638655 100644 --- a/cloud-common/src/main/java/com/cm/common/converter/UserAuthConverter.java +++ b/cloud-common/src/main/java/com/cm/common/converter/UserAuthConverter.java @@ -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; } } diff --git a/cloud-common/src/main/java/com/cm/common/pojo/bos/PositionBO.java b/cloud-common/src/main/java/com/cm/common/pojo/bos/PositionBO.java new file mode 100644 index 0000000..da6d5ff --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/pojo/bos/PositionBO.java @@ -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(); + } +} diff --git a/cloud-common/src/main/java/com/cm/common/pojo/bos/UserBO.java b/cloud-common/src/main/java/com/cm/common/pojo/bos/UserBO.java index 519beb8..69f6788 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/bos/UserBO.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/bos/UserBO.java @@ -17,6 +17,7 @@ public class UserBO extends User { private String userId; private String userName; + private String userPhone; private List roles; private List groups; private List 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 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\":") diff --git a/cloud-common/src/main/java/com/cm/common/pojo/bos/UserInfoBO.java b/cloud-common/src/main/java/com/cm/common/pojo/bos/UserInfoBO.java index 09ea1f9..fa15ef8 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/bos/UserInfoBO.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/bos/UserInfoBO.java @@ -14,6 +14,7 @@ public class UserInfoBO { private String userId; private String userUsername; private String userName; + private String userPhone; private List 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 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('}'); diff --git a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java index 35545c6..c3e1b8a 100644 --- a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java +++ b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java @@ -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 listCurrentUsers() { + List users = new ArrayList<>(); + for (Map.Entry kvs : tokens.entrySet()) { + AppToken appToken = kvs.getValue(); + users.add(appToken.getAppTokenUser()); + } + return users; + } + + /** + * 清空超时Token + */ + public synchronized void clearTimeoutToken() { + long currentTime = System.currentTimeMillis(); + List clearTokenKeys = new ArrayList<>(0); + for (Map.Entry 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(); } diff --git a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenTask.java b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenTask.java new file mode 100644 index 0000000..691852a --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenTask.java @@ -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(); + } + +} diff --git a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUser.java b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUser.java index 66d015f..f60168a 100644 --- a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUser.java +++ b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUser.java @@ -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 appTokenUserRoles; + private List appTokenUserPositions; + private List appTokenUserDepartments; public String getId() { return id == null ? "" : id.trim(); @@ -67,6 +72,30 @@ public class AppTokenUser { this.email = email; } + public List getAppTokenUserRoles() { + return appTokenUserRoles; + } + + public void setAppTokenUserRoles(List appTokenUserRoles) { + this.appTokenUserRoles = appTokenUserRoles; + } + + public List getAppTokenUserPositions() { + return appTokenUserPositions; + } + + public void setAppTokenUserPositions(List appTokenUserPositions) { + this.appTokenUserPositions = appTokenUserPositions; + } + + public List getAppTokenUserDepartments() { + return appTokenUserDepartments; + } + + public void setAppTokenUserDepartments(List 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(); } diff --git a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserDepartment.java b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserDepartment.java new file mode 100644 index 0000000..c4a7803 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserDepartment.java @@ -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(); + } +} diff --git a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserPosition.java b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserPosition.java new file mode 100644 index 0000000..d7ee86e --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserPosition.java @@ -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(); + } +} diff --git a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserRole.java b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserRole.java new file mode 100644 index 0000000..faf8545 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppTokenUserRole.java @@ -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(); + } +} diff --git a/cloud-common/src/main/java/com/cm/common/utils/point/Circle.java b/cloud-common/src/main/java/com/cm/common/utils/point/Circle.java new file mode 100644 index 0000000..5659108 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/utils/point/Circle.java @@ -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; + } + +} diff --git a/cloud-common/src/main/java/com/cm/common/utils/point/Point.java b/cloud-common/src/main/java/com/cm/common/utils/point/Point.java new file mode 100644 index 0000000..dc576fe --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/utils/point/Point.java @@ -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; + } +} diff --git a/cloud-common/src/main/java/com/cm/common/utils/point/PointUtil.java b/cloud-common/src/main/java/com/cm/common/utils/point/PointUtil.java new file mode 100644 index 0000000..60cfc6a --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/utils/point/PointUtil.java @@ -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 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; + } + } + + /** + * 判断是否在圆形内 + *

+ * 判断点与圆心之间的距离和圆半径的关系 + * + * @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 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)); + + } + +}