Commit aac60bd1 sunke

架构调整

1 个父辈 da084776
正在显示 35 个修改的文件 包含 733 行增加402 行删除
package com.neotel.smfcore;
import com.neotel.smfcore.common.annotation.AnonymousGetMapping;
import com.neotel.smfcore.common.annotation.security.AnonymousGetMapping;
import com.neotel.smfcore.common.utils.SpringContextHolder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......
package com.neotel.smfcore.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface QueryCondition {
/**
* 查询字段
*/
String propName() default "";
Type type() default Type.EQ;
/**
* 多字段模糊搜索,仅支持String类型字段,多个用逗号隔开, 如@Query(blurry = "email,username")
*/
String blurry() default "";
enum Type {
/**
* 等于
*/
EQ,
/**
* 不等于
*/
NE,
/**
* 大于
*/
GT,
/**
* 大于等于
*/
GTE,
/**
* 小于
*/
LT,
/**
* 小于等于
*/
LTE,
// 包含
IN,
/**
* 不包含
*/
NIN,
/**
* between
*/
BETWEEN
// 不为空
,NOT
// 为空
,IS_NULL,
//存在
EXISTS
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.common.annotation;
package com.neotel.smfcore.common.annotation.security;
import java.lang.annotation.*;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.neotel.smfcore.common.annotation;
package com.neotel.smfcore.common.annotation.security;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.neotel.smfcore.common.annotation;
package com.neotel.smfcore.common.annotation.security;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.neotel.smfcore.common.annotation;
package com.neotel.smfcore.common.annotation.security;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.neotel.smfcore.common.annotation;
package com.neotel.smfcore.common.annotation.security;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.neotel.smfcore.common.annotation;
package com.neotel.smfcore.common.annotation.security;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
......
package com.neotel.smfcore.common.enums;
import com.google.common.collect.Lists;
import java.util.List;
/**
* Created by sunke on 2021/7/13.
*/
public enum DeviceType {
/**
* 料仓类型:0单台自动料仓,1手动料仓2流水线料仓
*/
/**
*0单台自动料仓
*/
AUTO("storage.type.auto"),
/**
* 1手动料仓
*/
MANUAL("storage.type.manual"),
/**
* 2流水线料仓
*/
LINE("storage.type.line"),
/**
* 3 虚拟料仓
*/
VIRTUAL("storage.type.virtual"),
/**
* 4 在线料仓(上下层两个 BOX)
*/
ONLINE("storage.type.online"),
/**
* 5批量上下料料仓
*/
BATCH("storage.type.batch"),
/**
* 6智能料架
*/
SHELF("storage.type.shelf"),
/**
* 7 料柜
*/
CABINET("storage.type.cabinet"),
/**
* 8 料架
*/
ACCSHELF("storage.type.accShelf"),
/**
* 9 新料架,支持合并库位确认
*/
NEWSHELF("storage.type.newShelf"),
/**
* 9 扫码料架
*/
CODESHELF("storage.type.codeShelf"),
/**
* 10 锡膏料仓
*/
SOLDERPASTE("storage.type.solderPaste"),
/**
* 11 垂直货柜
*/
VERTICALBOX("storage.type.smdVl"),
/**
* 12 SMD-XL(方仓)
*/
SMD_XL("storage.type.smdXl"),
/**
* 13 SMD-DUO(DUO料仓)
*/
SMD_DUO("storage.type.smdDuo")
;
private String key;
TYPE(String key) {
this.key = key;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getName(){
return name();
}
public static List<TYPE> availableTypeList(){
return Lists.newArrayList(AUTO,LINE,BATCH,ACCSHELF,CODESHELF,SOLDERPASTE,VERTICALBOX,SMD_XL,SMD_DUO);
}
}
///*
// * Copyright 2019-2020 Zheng Jie
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//package com.neotel.smfcore.common.utils;
//
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.collection.CollectionUtil;
//import cn.hutool.core.util.ObjectUtil;
//import lombok.extern.slf4j.Slf4j;
//import me.zhengjie.annotation.DataPermission;
//import me.zhengjie.annotation.Query;
//import org.springframework.data.mongodb.core.query.Criteria;
//import org.springframework.data.mongodb.core.query.Query;
//
//import javax.persistence.criteria.*;
//import java.lang.reflect.Field;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Collection;
//import java.util.List;
//
///**
// * @author Zheng Jie
// * @date 2019-6-4 14:59:48
// */
//@Slf4j
//@SuppressWarnings({"unchecked","all"})
//public class QueryHelp {
//
//
//
// public static <C> Query getQuery(C c){
// Criteria criteria = new Criteria();
// if(c == null){
// return new Query(criteria);
// }
// try {
// List<Field> fields = getAllFields(c.getClass(), new ArrayList<>());
// for (Field field : fields) {
// boolean accessible = field.isAccessible();
// // 设置对象的访问权限,保证对private的属性的访
// field.setAccessible(true);
// Query q = field.getAnnotation(Query.class);
// if (q != null) {
// String propName = q.propName();
// String joinName = q.joinName();
// String blurry = q.blurry();
// String attributeName = isBlank(propName) ? field.getName() : propName;
// Class<?> fieldType = field.getType();
// Object val = field.get(query);
// if (ObjectUtil.isNull(val) || "".equals(val)) {
// continue;
// }
// Join join = null;
// // 模糊多字段
// if (ObjectUtil.isNotEmpty(blurry)) {
// String[] blurrys = blurry.split(",");
// List<Predicate> orPredicate = new ArrayList<>();
// for (String s : blurrys) {
// orPredicate.add(cb.like(root.get(s)
// .as(String.class), "%" + val.toString() + "%"));
// }
// Predicate[] p = new Predicate[orPredicate.size()];
// list.add(cb.or(orPredicate.toArray(p)));
// continue;
// }
// if (ObjectUtil.isNotEmpty(joinName)) {
// String[] joinNames = joinName.split(">");
// for (String name : joinNames) {
// switch (q.join()) {
// case LEFT:
// if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
// join = join.join(name, JoinType.LEFT);
// } else {
// join = root.join(name, JoinType.LEFT);
// }
// break;
// case RIGHT:
// if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
// join = join.join(name, JoinType.RIGHT);
// } else {
// join = root.join(name, JoinType.RIGHT);
// }
// break;
// case INNER:
// if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
// join = join.join(name, JoinType.INNER);
// } else {
// join = root.join(name, JoinType.INNER);
// }
// break;
// default: break;
// }
// }
// }
// switch (q.type()) {
// case EQUAL:
// list.add(cb.equal(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType),val));
// break;
// case GREATER_THAN:
// list.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType), (Comparable) val));
// break;
// case LESS_THAN:
// list.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType), (Comparable) val));
// break;
// case LESS_THAN_NQ:
// list.add(cb.lessThan(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType), (Comparable) val));
// break;
// case INNER_LIKE:
// list.add(cb.like(getExpression(attributeName,join,root)
// .as(String.class), "%" + val.toString() + "%"));
// break;
// case LEFT_LIKE:
// list.add(cb.like(getExpression(attributeName,join,root)
// .as(String.class), "%" + val.toString()));
// break;
// case RIGHT_LIKE:
// list.add(cb.like(getExpression(attributeName,join,root)
// .as(String.class), val.toString() + "%"));
// break;
// case IN:
// if (CollUtil.isNotEmpty((Collection<Object>)val)) {
// list.add(getExpression(attributeName,join,root).in((Collection<Object>) val));
// }
// break;
// case NOT_IN:
// if (CollUtil.isNotEmpty((Collection<Object>)val)) {
// list.add(getExpression(attributeName,join,root).in((Collection<Object>) val).not());
// }
// break;
// case NOT_EQUAL:
// list.add(cb.notEqual(getExpression(attributeName,join,root), val));
// break;
// case NOT_NULL:
// list.add(cb.isNotNull(getExpression(attributeName,join,root)));
// break;
// case IS_NULL:
// list.add(cb.isNull(getExpression(attributeName,join,root)));
// break;
// case BETWEEN:
// List<Object> between = new ArrayList<>((List<Object>)val);
// list.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()),
// (Comparable) between.get(0), (Comparable) between.get(1)));
// break;
// default: break;
// }
// }
// field.setAccessible(accessible);
// }
// } catch (Exception e) {
// log.error(e.getMessage(), e);
// }
// int size = list.size();
// return cb.and(list.toArray(new Predicate[size]));
// }
//
// public static <R, Q> Predicate getPredicate(Root<R> root, Q query, CriteriaBuilder cb) {
// List<Predicate> list = new ArrayList<>();
// if(query == null){
// return cb.and(list.toArray(new Predicate[0]));
// }
// // 数据权限验证
// DataPermission permission = query.getClass().getAnnotation(DataPermission.class);
// if(permission != null){
// // 获取数据权限
// List<Long> dataScopes = SecurityUtils.getCurrentUserDataScope();
// if(CollectionUtil.isNotEmpty(dataScopes)){
// if(StringUtils.isNotBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) {
// Join join = root.join(permission.joinName(), JoinType.LEFT);
// list.add(getExpression(permission.fieldName(),join, root).in(dataScopes));
// } else if (StringUtils.isBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) {
// list.add(getExpression(permission.fieldName(),null, root).in(dataScopes));
// }
// }
// }
// try {
// List<Field> fields = getAllFields(query.getClass(), new ArrayList<>());
// for (Field field : fields) {
// boolean accessible = field.isAccessible();
// // 设置对象的访问权限,保证对private的属性的访
// field.setAccessible(true);
// Query q = field.getAnnotation(Query.class);
// if (q != null) {
// String propName = q.propName();
// String joinName = q.joinName();
// String blurry = q.blurry();
// String attributeName = isBlank(propName) ? field.getName() : propName;
// Class<?> fieldType = field.getType();
// Object val = field.get(query);
// if (ObjectUtil.isNull(val) || "".equals(val)) {
// continue;
// }
// Join join = null;
// // 模糊多字段
// if (ObjectUtil.isNotEmpty(blurry)) {
// String[] blurrys = blurry.split(",");
// List<Predicate> orPredicate = new ArrayList<>();
// for (String s : blurrys) {
// orPredicate.add(cb.like(root.get(s)
// .as(String.class), "%" + val.toString() + "%"));
// }
// Predicate[] p = new Predicate[orPredicate.size()];
// list.add(cb.or(orPredicate.toArray(p)));
// continue;
// }
// if (ObjectUtil.isNotEmpty(joinName)) {
// String[] joinNames = joinName.split(">");
// for (String name : joinNames) {
// switch (q.join()) {
// case LEFT:
// if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
// join = join.join(name, JoinType.LEFT);
// } else {
// join = root.join(name, JoinType.LEFT);
// }
// break;
// case RIGHT:
// if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
// join = join.join(name, JoinType.RIGHT);
// } else {
// join = root.join(name, JoinType.RIGHT);
// }
// break;
// case INNER:
// if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){
// join = join.join(name, JoinType.INNER);
// } else {
// join = root.join(name, JoinType.INNER);
// }
// break;
// default: break;
// }
// }
// }
// switch (q.type()) {
// case EQUAL:
// list.add(cb.equal(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType),val));
// break;
// case GREATER_THAN:
// list.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType), (Comparable) val));
// break;
// case LESS_THAN:
// list.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType), (Comparable) val));
// break;
// case LESS_THAN_NQ:
// list.add(cb.lessThan(getExpression(attributeName,join,root)
// .as((Class<? extends Comparable>) fieldType), (Comparable) val));
// break;
// case INNER_LIKE:
// list.add(cb.like(getExpression(attributeName,join,root)
// .as(String.class), "%" + val.toString() + "%"));
// break;
// case LEFT_LIKE:
// list.add(cb.like(getExpression(attributeName,join,root)
// .as(String.class), "%" + val.toString()));
// break;
// case RIGHT_LIKE:
// list.add(cb.like(getExpression(attributeName,join,root)
// .as(String.class), val.toString() + "%"));
// break;
// case IN:
// if (CollUtil.isNotEmpty((Collection<Object>)val)) {
// list.add(getExpression(attributeName,join,root).in((Collection<Object>) val));
// }
// break;
// case NOT_IN:
// if (CollUtil.isNotEmpty((Collection<Object>)val)) {
// list.add(getExpression(attributeName,join,root).in((Collection<Object>) val).not());
// }
// break;
// case NOT_EQUAL:
// list.add(cb.notEqual(getExpression(attributeName,join,root), val));
// break;
// case NOT_NULL:
// list.add(cb.isNotNull(getExpression(attributeName,join,root)));
// break;
// case IS_NULL:
// list.add(cb.isNull(getExpression(attributeName,join,root)));
// break;
// case BETWEEN:
// List<Object> between = new ArrayList<>((List<Object>)val);
// list.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()),
// (Comparable) between.get(0), (Comparable) between.get(1)));
// break;
// default: break;
// }
// }
// field.setAccessible(accessible);
// }
// } catch (Exception e) {
// log.error(e.getMessage(), e);
// }
// int size = list.size();
// return cb.and(list.toArray(new Predicate[size]));
// }
//
// @SuppressWarnings("unchecked")
// private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) {
// if (ObjectUtil.isNotEmpty(join)) {
// return join.get(attributeName);
// } else {
// return root.get(attributeName);
// }
// }
//
// private static boolean isBlank(final CharSequence cs) {
// int strLen;
// if (cs == null || (strLen = cs.length()) == 0) {
// return true;
// }
// for (int i = 0; i < strLen; i++) {
// if (!Character.isWhitespace(cs.charAt(i))) {
// return false;
// }
// }
// return true;
// }
//
// public static List<Field> getAllFields(Class clazz, List<Field> fields) {
// if (clazz != null) {
// fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
// getAllFields(clazz.getSuperclass(), fields);
// }
// return fields;
// }
//}
package com.neotel.smfcore.common.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.annotation.QueryCondition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;
@Slf4j
public class QueryHelp {
public static <C> Query getQuery(C c){
Criteria criteria = new Criteria();
if(c != null){
try {
List<Field> fields = getAllFields(c.getClass(), new ArrayList<>());
for (Field field : fields) {
boolean accessible = field.isAccessible();
// 设置对象的访问权限,保证对private的属性的访
field.setAccessible(true);
QueryCondition q = field.getAnnotation(QueryCondition.class);
if (q != null) {
String propName = q.propName();
String attributeName = isBlank(propName) ? field.getName() : propName;
Class<?> fieldType = field.getType();
Object val = field.get(c);
if (ObjectUtil.isNull(val) || "".equals(val)) {
continue;
}
// 如果是多字段
String blurry = q.blurry();
String[] blurrys = blurry.split(",");
if (ObjectUtil.isNotEmpty(blurry)) {
for (String s : blurrys) {
Pattern pattern = Pattern.compile(escapeExprSpecialWord(val.toString()), Pattern.CASE_INSENSITIVE);
criteria = criteria.and(s).regex(pattern);
}
continue;
}
switch (q.type()) {
case EQ:
criteria = criteria.and(propName).is(val);
break;
case GT:
criteria = criteria.and(propName).gt(val);
break;
case LT:
criteria = criteria.and(propName).lt(val);
break;
case LTE:
criteria = criteria.and(propName).lte(val);
break;
case IN:
if (CollUtil.isNotEmpty((Collection<Object>)val)) {
criteria = criteria.and(propName).in((Collection<Object>) val);
}
break;
case NIN:
if (CollUtil.isNotEmpty((Collection<Object>)val)) {
criteria = criteria.and(propName).nin((Collection<Object>) val);
}
break;
case NE:
criteria = criteria.and(propName).ne(val);
break;
case NOT:
criteria = criteria.and(propName).not();
break;
case IS_NULL:
criteria = criteria.and(propName).is(null);
break;
case EXISTS:
criteria = criteria.and(propName).exists(true);
break;
case BETWEEN:
List<Object> between = new ArrayList<>((List<Object>)val);
criteria = criteria.and(propName).gte(between.get(0)).lte(between.get(1));
break;
default: break;
}
}
field.setAccessible(accessible);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
return new Query(criteria);
}
private static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
private static List<Field> getAllFields(Class clazz, List<Field> fields) {
if (clazz != null) {
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
getAllFields(clazz.getSuperclass(), fields);
}
return fields;
}
private static String escapeExprSpecialWord(String keyword) {
if (ObjectUtil.isNotEmpty(keyword)) {
String[] fbsArr = { "\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };
for (String key : fbsArr) {
if (keyword.contains(key)) {
keyword = keyword.replace(key, "\\" + key);
}
}
}
return keyword;
}
}
package com.neotel.smfcore.core.device;
import com.neotel.smfcore.core.listener.IDeviceListener;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sunke on 2021/7/12.
*/
@Service
public class BaseDeviceHandler implements IDeviceHandler{
@Override
public String getDeviceType() {
return "";
}
}
package com.neotel.smfcore.core.device;
/**
* Created by sunke on 2021/7/13.
*/
public interface IDeviceHandler {
String getDeviceType();
}
package com.neotel.smfcore.core.device;
/**
* Created by sunke on 2021/7/12.
*/
public class SmdXlBoxHandler implements IDeviceHandler{
@Override
public String getDeviceType() {
return null;
}
}
package com.neotel.smfcore.core.listener;
import org.springframework.stereotype.Service;
/**
* Created by sunke on 2021/7/12.
*/
@Service
public class ApiListener implements IDeviceListener {
@Override
public String onScanCode(String codeStr) {
return "LiteOrderListener";
}
}
package com.neotel.smfcore.core.listener;
/**
* Created by sunke on 2021/7/12.
*/
public interface IDeviceListener {
String onScanCode(String codeStr);
}
package com.neotel.smfcore.core.listener;
import org.springframework.stereotype.Service;
/**
* Created by sunke on 2021/7/12.
*/
@Service
public class LiteOrderListener implements IDeviceListener {
@Override
public String onScanCode(String codeStr) {
return "LiteOrderListener";
}
}
package com.neotel.smfcore.core.rest;
import com.neotel.smfcore.core.device.IDeviceHandler;
import com.neotel.smfcore.core.listener.IDeviceListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by sunke on 2021/7/13.
*/
public class TaskService {
private List<IDeviceListener> listenerList = new ArrayList<>();
private Map<String, IDeviceHandler> handlerMap = new HashMap<>();
public TaskService(List<IDeviceHandler> deviceHandlerList, List<IDeviceListener> deviceListenerList){
for (IDeviceHandler deviceHandler : deviceHandlerList) {
}
for (IDeviceListener deviceListener: deviceListenerList) {
listenerList.add(deviceListener);
}
}
}
......@@ -19,7 +19,7 @@ import cn.hutool.core.util.StrUtil;
import com.neotel.smfcore.security.bean.SecurityProperties;
import com.neotel.smfcore.security.service.OnlineUserService;
import com.neotel.smfcore.security.service.UserCacheClean;
import com.neotel.smfcore.security.service.dto.OnlineUserDto;
import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
import io.jsonwebtoken.ExpiredJwtException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -15,7 +15,7 @@
*/
package com.neotel.smfcore.security.config;
import com.neotel.smfcore.common.annotation.AnonymousAccess;
import com.neotel.smfcore.common.annotation.security.AnonymousAccess;
import com.neotel.smfcore.common.enums.RequestMethodEnum;
import com.neotel.smfcore.security.JwtAccessDeniedHandler;
import com.neotel.smfcore.security.JwtAuthenticationEntryPoint;
......
......@@ -15,22 +15,26 @@
*/
package com.neotel.smfcore.security.rest;
import com.neotel.smfcore.common.annotation.AnonymousDeleteMapping;
import com.neotel.smfcore.common.annotation.AnonymousGetMapping;
import com.neotel.smfcore.common.annotation.AnonymousPostMapping;
import com.neotel.smfcore.common.annotation.security.AnonymousDeleteMapping;
import com.neotel.smfcore.common.annotation.security.AnonymousGetMapping;
import com.neotel.smfcore.common.annotation.security.AnonymousPostMapping;
import com.neotel.smfcore.common.utils.EncryptUtils;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.security.bean.RsaProperties;
import com.neotel.smfcore.security.TokenProvider;
import com.neotel.smfcore.security.bean.LoginProperties;
import com.neotel.smfcore.security.bean.SecurityProperties;
import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
import com.neotel.smfcore.security.service.OnlineUserService;
import com.neotel.smfcore.security.service.dto.AuthUserDto;
import com.neotel.smfcore.security.service.dto.JwtUserDto;
import com.neotel.smfcore.security.rest.bean.dto.AuthUserDto;
import com.neotel.smfcore.security.rest.bean.dto.JwtUserDto;
import com.neotel.smfcore.common.utils.RsaUtils;
import com.neotel.smfcore.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
......@@ -45,6 +49,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -56,9 +61,12 @@ import java.util.Map;
@Api(tags = "系统:系统授权接口")
public class AuthorizationController {
private final SecurityProperties properties;
// private final RedisUtils redisUtils;
private final OnlineUserService onlineUserService;
private final TokenProvider tokenProvider;
@Autowired
private OnlineUserService onlineUserService;
@Autowired
private TokenProvider tokenProvider;
private final AuthenticationManagerBuilder authenticationManagerBuilder;
@Resource
private LoginProperties loginProperties;
......@@ -89,7 +97,17 @@ public class AuthorizationController {
String token = tokenProvider.createToken(authentication);
final JwtUserDto jwtUserDto = (JwtUserDto) authentication.getPrincipal();
// 保存在线信息
onlineUserService.save(jwtUserDto, token, request);
String ip = StringUtils.getIp(request);
String browser = StringUtils.getBrowser(request);
String address = StringUtils.getCityInfo(ip);
OnlineUserDto onlineUserDto = null;
try {
long seconds = onlineUserService.properties.getTokenValidityInSeconds() / 1000;
onlineUserDto = new OnlineUserDto(jwtUserDto.getUsername(), browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
} catch (Exception e) {
log.error(e.getMessage(),e);
}
OnlineUserService.onlineUserMap.put(onlineUserService.properties.getOnlineKey() + token, onlineUserDto);
// 返回 token 与 用户信息
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
put("token", properties.getTokenStartWith() + token);
......
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.security.rest;
import cn.hutool.core.collection.CollectionUtil;
import com.neotel.smfcore.common.annotation.QueryCondition;
import com.neotel.smfcore.security.service.manager.IMenuManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Zheng Jie
* @date 2018-12-03
*/
@RestController
@RequiredArgsConstructor
@Api(tags = "系统:菜单管理")
@RequestMapping("/api/menus")
public class MenuController {
// @Autowired
// private final IMenuManager menuManager;
// private final MenuMapper menuMapper;
// private static final String ENTITY_NAME = "menu";
//
// @ApiOperation("导出菜单数据")
// @GetMapping(value = "/download")
// @PreAuthorize("@el.check('menu:list')")
// public void download(HttpServletResponse response, QueryCondition criteria) throws Exception {
// menuService.download(menuService.queryAll(criteria, false), response);
// }
//
// @GetMapping(value = "/build")
// @ApiOperation("获取前端所需菜单")
// public ResponseEntity<Object> buildMenus(){
// List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId());
// List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
// return new ResponseEntity<>(menuService.buildMenus(menuDtos), HttpStatus.OK);
// }
//
// @ApiOperation("返回全部的菜单")
// @GetMapping(value = "/lazy")
// @PreAuthorize("@el.check('menu:list','roles:list')")
// public ResponseEntity<Object> query(@RequestParam Long pid){
// return new ResponseEntity<>(menuService.getMenus(pid), HttpStatus.OK);
// }
//
// @ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
// @GetMapping(value = "/child")
// @PreAuthorize("@el.check('menu:list','roles:list')")
// public ResponseEntity<Object> child(@RequestParam Long id){
// Set<Menu> menuSet = new HashSet<>();
// List<MenuDto> menuList = menuService.getMenus(id);
// menuSet.add(menuService.findOne(id));
// menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
// Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());
// return new ResponseEntity<>(ids, HttpStatus.OK);
// }
//
// @GetMapping
// @ApiOperation("查询菜单")
// @PreAuthorize("@el.check('menu:list')")
// public ResponseEntity<Object> query(MenuQueryCriteria criteria) throws Exception {
// List<MenuDto> menuDtoList = menuService.queryAll(criteria, true);
// return new ResponseEntity<>(PageUtil.toPage(menuDtoList, menuDtoList.size()), HttpStatus.OK);
// }
//
// @ApiOperation("查询菜单:根据ID获取同级与上级数据")
// @PostMapping("/superior")
// @PreAuthorize("@el.check('menu:list')")
// public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
// Set<MenuDto> menuDtos = new LinkedHashSet<>();
// if(CollectionUtil.isNotEmpty(ids)){
// for (Long id : ids) {
// MenuDto menuDto = menuService.findById(id);
// menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>()));
// }
// return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menuDtos)), HttpStatus.OK);
// }
// return new ResponseEntity<>(menuService.getMenus(null), HttpStatus.OK);
// }
//
// @Log("新增菜单")
// @ApiOperation("新增菜单")
// @PostMapping
// @PreAuthorize("@el.check('menu:add')")
// public ResponseEntity<Object> create(@Validated @RequestBody Menu resources){
// if (resources.getId() != null) {
// throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
// }
// menuService.create(resources);
// return new ResponseEntity<>(HttpStatus.CREATED);
// }
//
// @Log("修改菜单")
// @ApiOperation("修改菜单")
// @PutMapping
// @PreAuthorize("@el.check('menu:edit')")
// public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody Menu resources){
// menuService.update(resources);
// return new ResponseEntity<>(HttpStatus.NO_CONTENT);
// }
//
// @Log("删除菜单")
// @ApiOperation("删除菜单")
// @DeleteMapping
// @PreAuthorize("@el.check('menu:del')")
// public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
// Set<Menu> menuSet = new HashSet<>();
// for (Long id : ids) {
// List<MenuDto> menuList = menuService.getMenus(id);
// menuSet.add(menuService.findOne(id));
// menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
// }
// menuService.delete(menuSet);
// return new ResponseEntity<>(HttpStatus.OK);
// }
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.security.service.dto;
package com.neotel.smfcore.security.rest.bean.dto;
import lombok.Getter;
import lombok.Setter;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.security.service.dto;
package com.neotel.smfcore.security.rest.bean.dto;
import lombok.Data;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.security.service.dto;
package com.neotel.smfcore.security.rest.bean.dto;
import com.alibaba.fastjson.annotation.JSONField;
import com.neotel.smfcore.security.service.po.User;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.security.service.dto;
package com.neotel.smfcore.security.rest.bean.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
......
......@@ -13,16 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.neotel.smfcore.security.service.dto;
package com.neotel.smfcore.security.rest.bean.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author Zheng Jie
* @date 2018-11-23
*/
@Data
public class RoleSmallDto implements Serializable {
......
package com.neotel.smfcore.security.rest.bean.query;
import com.neotel.smfcore.common.annotation.QueryCondition;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class MenuQueryCondition {
@QueryCondition(blurry = "title,component,permission")
private String blurry;
@QueryCondition(type = QueryCondition.Type.BETWEEN)
private List<Date> createTime;
@QueryCondition(type = QueryCondition.Type.IS_NULL, propName = "pid")
private Boolean pidIsNull;
@QueryCondition
private Long pid;
}
......@@ -16,8 +16,8 @@
package com.neotel.smfcore.security.service;
import com.neotel.smfcore.security.bean.SecurityProperties;
import com.neotel.smfcore.security.service.dto.JwtUserDto;
import com.neotel.smfcore.security.service.dto.OnlineUserDto;
import com.neotel.smfcore.security.rest.bean.dto.JwtUserDto;
import com.neotel.smfcore.security.rest.bean.dto.OnlineUserDto;
import com.neotel.smfcore.common.utils.EncryptUtils;
import com.neotel.smfcore.common.utils.FileUtil;
import com.neotel.smfcore.common.utils.PageUtil;
......@@ -41,35 +41,15 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class OnlineUserService {
private final SecurityProperties properties;
public final SecurityProperties properties;
static Map<String, OnlineUserDto> onlineUserMap = new ConcurrentHashMap<>();
public static Map<String, OnlineUserDto> onlineUserMap = new ConcurrentHashMap<>();
public OnlineUserService(SecurityProperties properties) {
this.properties = properties;
}
/**
* 保存在线用户信息
* @param jwtUserDto /
* @param token /
* @param request /
*/
public void save(JwtUserDto jwtUserDto, String token, HttpServletRequest request){
String ip = StringUtils.getIp(request);
String browser = StringUtils.getBrowser(request);
String address = StringUtils.getCityInfo(ip);
OnlineUserDto onlineUserDto = null;
try {
long seconds = properties.getTokenValidityInSeconds() / 1000;
onlineUserDto = new OnlineUserDto(jwtUserDto.getUsername(), browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
} catch (Exception e) {
log.error(e.getMessage(),e);
}
onlineUserMap.put(properties.getOnlineKey() + token, onlineUserDto);
}
/**
* 查询全部数据
* @param filter /
* @param pageable /
......
......@@ -18,7 +18,7 @@ package com.neotel.smfcore.security.service;
import com.neotel.smfcore.common.exception.BadRequestException;
import com.neotel.smfcore.common.exception.EntityNotFoundException;
import com.neotel.smfcore.security.bean.LoginProperties;
import com.neotel.smfcore.security.service.dto.JwtUserDto;
import com.neotel.smfcore.security.rest.bean.dto.JwtUserDto;
import com.neotel.smfcore.security.service.manager.IRoleManager;
import com.neotel.smfcore.security.service.manager.IUserManager;
import com.neotel.smfcore.security.service.po.Menu;
......
package com.neotel.smfcore.security.service.dao;
import com.neotel.smfcore.common.base.IBaseDao;
/**
* Created by sunke on 2021/7/8.
*/
public interface IMenuDao extends IBaseDao {
}
package com.neotel.smfcore.security.service.dao.impl;
import com.neotel.smfcore.common.base.AbstractBaseDao;
import com.neotel.smfcore.security.service.dao.IMenuDao;
import com.neotel.smfcore.security.service.dao.IRoleDao;
import com.neotel.smfcore.security.service.po.Menu;
import com.neotel.smfcore.security.service.po.User;
import org.springframework.stereotype.Service;
/**
* Created by sunke on 2021/7/7.
*/
@Service
public class MenuDaoImpl extends AbstractBaseDao implements IMenuDao {
@Override
public Class getEntityClass() {
return Menu.class;
}
}
package com.neotel.smfcore.security.service.manager;
import com.neotel.smfcore.common.base.IBaseManager;
import com.neotel.smfcore.security.service.po.Menu;
import com.neotel.smfcore.security.service.po.Role;
public interface IMenuManager extends IBaseManager<Menu> {
}
package com.neotel.smfcore.security.service.manager.impl;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.security.service.dao.IMenuDao;
import com.neotel.smfcore.security.service.dao.IRoleDao;
import com.neotel.smfcore.security.service.manager.IMenuManager;
import com.neotel.smfcore.security.service.manager.IRoleManager;
import com.neotel.smfcore.security.service.po.Menu;
import com.neotel.smfcore.security.service.po.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MenuManagerImpl implements IMenuManager {
@Autowired
protected IMenuDao menuDao;
@Override
public Menu get(String id) {
return menuDao.findOneById(id);
}
@Override
public Menu save(Menu menu) throws ValidateException {
return menuDao.save(menu);
}
@Override
public void delete(Menu object) throws ValidateException {
menuDao.removeOne(object);
}
@Override
public List<Menu> findByPage(Query query, Pageable pageable) {
return menuDao.findByQuery(query, pageable);
}
@Override
public List<Menu> findByQuery(Query query) {
return menuDao.findByQuery(query);
}
}
......@@ -17,16 +17,12 @@ package com.neotel.smfcore.security.service.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.neotel.smfcore.common.base.BasePo;
import com.neotel.smfcore.security.service.dto.DeptSmallDto;
import com.neotel.smfcore.security.service.dto.RoleSmallDto;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
/**
* @author Zheng Jie
......
server:
port: 8500
port: 8800
spring:
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!