init:删除无用配置
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package org.nl.system.controller.lucence;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.system.service.lucene.LuceneService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 日志检索
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-11-16
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/lucene")
|
||||
@Slf4j
|
||||
public class LuceneController {
|
||||
|
||||
private final LuceneService luceneService;
|
||||
|
||||
@PostMapping("/getAll")
|
||||
public ResponseEntity<Object> get(@RequestBody JSONObject whereJson) {
|
||||
return new ResponseEntity<>(luceneService.getAll(whereJson), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/getTagName")
|
||||
public ResponseEntity<Object> getTagName() {
|
||||
return new ResponseEntity<>(luceneService.getTagName(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.nl.system.controller.lucence;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.system.service.logserver.LogQuery;
|
||||
import org.nl.system.service.logserver.LuceneLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年01月29日 18:55
|
||||
* @desc desc
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/esLog")
|
||||
@Slf4j
|
||||
public class LuceneLogController {
|
||||
|
||||
@Autowired
|
||||
private LuceneLogService luceneLogService;
|
||||
|
||||
|
||||
@GetMapping("/labels/{type}")
|
||||
//("获取标签")
|
||||
public ResponseEntity<Object> labelsValues(@PathVariable String type) {
|
||||
return new ResponseEntity<>(luceneLogService.getLabelsValues(type), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
//("日志查询")
|
||||
public ResponseEntity<Object> queryAll(@RequestBody LogQuery query) {
|
||||
return new ResponseEntity<>(luceneLogService.query(query), HttpStatus.OK);
|
||||
}
|
||||
@DeleteMapping("/clearLogs")
|
||||
//("清空日志")
|
||||
public ResponseEntity<Object> clearLogs(@RequestBody LogQuery query) {
|
||||
luceneLogService.clearLogs(query);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/thread")
|
||||
@SaIgnore
|
||||
@Log("线程追踪测试")
|
||||
//("清空日志")
|
||||
public ResponseEntity<Object> thread(@RequestBody LogQuery query) {
|
||||
log.info("线程链路测试"+Thread.currentThread().getName());
|
||||
log.error("线程链路测试"+Thread.currentThread().getName());
|
||||
luceneLogService.syncdemo();
|
||||
Thread thread = new Thread(()->{
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
log.info("线程链路测试"+Thread.currentThread().getName());
|
||||
log.error("线程链路测试"+Thread.currentThread().getName());
|
||||
log.info("线程链路测试"+Thread.currentThread().getName());
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,9 +13,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.utils.RedisUtils;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.common.utils.dto.CurrentUser;
|
||||
import org.nl.common.security.config.bean.LoginCodeEnum;
|
||||
import org.nl.common.security.config.bean.LoginProperties;
|
||||
import org.nl.system.service.secutiry.impl.OnlineUserService;
|
||||
import org.nl.system.service.secutiry.entity.LoginProperties;
|
||||
import org.nl.system.service.secutiry.enums.LoginCodeEnum;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,19 +39,17 @@ public class AuthorizationController {
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
@Autowired
|
||||
private OnlineUserService onlineUserService;
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
@Autowired
|
||||
private LoginProperties loginProperties;
|
||||
|
||||
|
||||
@PostMapping(value = "/login")
|
||||
public ResponseEntity<Object> login(@RequestBody Map authMap, HttpServletRequest request) throws Exception {
|
||||
public ResponseEntity<Object> login(@RequestBody JSONObject authMap, HttpServletRequest request) throws Exception {
|
||||
if (ObjectUtil.isEmpty(authMap)){
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
return ResponseEntity.ok(onlineUserService.login(authMap, request));
|
||||
return new ResponseEntity(userService.login(authMap),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,9 +99,6 @@ public class AuthorizationController {
|
||||
|
||||
@DeleteMapping(value = "/logout")
|
||||
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
||||
if (ObjectUtil.isNotEmpty(StpUtil.getTokenValue())) {
|
||||
onlineUserService.logout(StpUtil.getTokenValue());
|
||||
}
|
||||
StpUtil.logout();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 org.nl.system.controller.user;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
|
||||
import org.nl.common.utils.EncryptUtils;
|
||||
import org.nl.system.service.secutiry.impl.OnlineUserService;
|
||||
import org.nl.system.service.user.dto.OnlineUserDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/auth/online")
|
||||
public class OnlineController {
|
||||
|
||||
@Autowired
|
||||
private OnlineUserService onlineUserService;
|
||||
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> query(String filter, Pageable pageable){
|
||||
return new ResponseEntity<>(onlineUserService.getAll(filter, pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/download")
|
||||
public void download(HttpServletResponse response, String filter) throws IOException {
|
||||
onlineUserService.download(onlineUserService.getAll(filter), response);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody List<OnlineUserDto> keys) throws Exception {
|
||||
for (OnlineUserDto key : keys) {
|
||||
// 解密Key
|
||||
key.setKey(EncryptUtils.desDecrypt(key.getKey()));
|
||||
onlineUserService.kickOut(key);
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.nl.system.service.dept.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -24,6 +25,7 @@ public class SysUserDept implements Serializable {
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
@TableId
|
||||
private Long user_id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.nl.system.service.logserver;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/8 5:18 下午
|
||||
*/
|
||||
@Data
|
||||
public class LogQuery {
|
||||
/**
|
||||
* 创建时间范围查询
|
||||
*/
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
/**
|
||||
* 追踪id
|
||||
*/
|
||||
private String traceId;
|
||||
private String requestMethod;
|
||||
/**
|
||||
* 日志内容模糊匹配
|
||||
*/
|
||||
private String message;
|
||||
/**
|
||||
* 日志级别
|
||||
*/
|
||||
private String logLevel;
|
||||
/**
|
||||
* 系统标签
|
||||
*/
|
||||
private String system;
|
||||
/**
|
||||
* 是否只查询Http相关请求
|
||||
*/
|
||||
private Boolean isRequest = Boolean.TRUE;
|
||||
/**
|
||||
* 是否过滤wql日志
|
||||
*/
|
||||
private Boolean filterSql = Boolean.TRUE;
|
||||
|
||||
private Integer size = 20;
|
||||
|
||||
private Integer page = 1;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.nl.system.service.logserver;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/2/8 4:06 下午
|
||||
*/
|
||||
//@Document(indexName = "#{@ESConfig.index}", type = "mes_log")
|
||||
@Data
|
||||
public class LogRepositoryDTO {
|
||||
|
||||
private String message;
|
||||
private String host;
|
||||
private String logLevel;
|
||||
private String logger;
|
||||
private String requestTime;
|
||||
private String requestIp;
|
||||
@Id
|
||||
private String id;
|
||||
private String traceId;
|
||||
private String requestMethod;
|
||||
private String thread;
|
||||
private String system;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.nl.system.service.logserver;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年02月07日 14:34
|
||||
* @desc desc
|
||||
*/
|
||||
public interface LuceneLogService {
|
||||
|
||||
/**
|
||||
* 清空日志
|
||||
*/
|
||||
void clearLogs(LogQuery query);
|
||||
/**
|
||||
* 获取labels和values树
|
||||
* @return
|
||||
*/
|
||||
JSONArray getLabelsValues(String type);
|
||||
|
||||
/**
|
||||
* 日志查询
|
||||
* @param logQuery
|
||||
* @return
|
||||
*/
|
||||
JSONObject query(LogQuery logQuery);
|
||||
|
||||
void syncdemo();
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package org.nl.system.service.logserver;
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.db.PageResult;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.queryparser.classic.QueryParser;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.config.lucene.LuceneAppender;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LuceneLogServiceImpl implements LuceneLogService {
|
||||
|
||||
static String[] INFO_LEVEL = new String[]{"DEBUG","INFO","WARN","ERROR"};
|
||||
|
||||
@Value("${lucene.index.path}")
|
||||
private String indexUrl;
|
||||
|
||||
@Override
|
||||
public void clearLogs(LogQuery query) {
|
||||
try {
|
||||
IndexWriter indexWriter = LuceneAppender.indexWriter;
|
||||
if (indexWriter != null){
|
||||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
||||
DateTime offset = DateUtil.offset(new Date(), DateField.HOUR_OF_DAY, -10);
|
||||
TermRangeQuery termRangeQuery = new TermRangeQuery(
|
||||
"requestTime",null,
|
||||
new BytesRef(DateUtil.format(offset, "yyyy-MM-dd HH:mm:ss.SSS")), true, true);
|
||||
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
|
||||
indexWriter.deleteDocuments(termRangeQuery);
|
||||
indexWriter.commit();
|
||||
}
|
||||
}catch (Exception ex){
|
||||
throw new BadRequestException("删除失败:"+ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getLabelsValues(String type) {
|
||||
JSONArray result = new JSONArray();
|
||||
for (String v : INFO_LEVEL) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("label", v);
|
||||
item.put("value", v);
|
||||
result.add(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject query(LogQuery logQuery) {
|
||||
JSONObject res = new JSONObject();
|
||||
PageResult page = new PageResult();
|
||||
page.setPage(logQuery.getPage());
|
||||
page.setPageSize(logQuery.getSize());
|
||||
try {
|
||||
FSDirectory directory = FSDirectory.open(Paths.get(indexUrl));
|
||||
DirectoryReader open = DirectoryReader.open(directory);
|
||||
IndexSearcher searcher = new IndexSearcher(open);
|
||||
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
|
||||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
||||
//时间范围查询
|
||||
Date startDate = logQuery.getStartTime();
|
||||
Date endDate = logQuery.getEndTime();
|
||||
|
||||
if (startDate == null){
|
||||
Calendar calendar=Calendar.getInstance();
|
||||
calendar.set(1970, 0, 1);
|
||||
startDate = calendar.getTime(); }
|
||||
if (endDate == null){ endDate = new DateTime(); }
|
||||
TermRangeQuery termRangeQuery = new TermRangeQuery(
|
||||
"requestTime",
|
||||
new BytesRef(DateUtil.format(startDate, "yyyy-MM-dd HH:mm:ss.SSS")),
|
||||
new BytesRef(DateUtil.format(endDate, "yyyy-MM-dd HH:mm:ss.SSS")), true, true);
|
||||
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
|
||||
|
||||
// 字段之间的与或非关系,MUST表示and,MUST_NOT表示not,SHOULD表示or,有几个fields就必须有几个clauses
|
||||
if (ObjectUtil.isNotEmpty(logQuery.getTraceId())){
|
||||
TermQuery termQuery = new TermQuery(new Term("traceId", logQuery.getTraceId()));
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(logQuery.getLogLevel())){
|
||||
TermQuery termQuery = new TermQuery(new Term("logLevel", logQuery.getLogLevel()));
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(logQuery.getSystem())) {
|
||||
TermQuery termQuery = new TermQuery(new Term("system", logQuery.getSystem()));
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(logQuery.getRequestMethod())) {
|
||||
TermQuery termQuery = new TermQuery(new Term("requestMethod", logQuery.getRequestMethod()));
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST);
|
||||
}
|
||||
if (Boolean.TRUE.equals(logQuery.getIsRequest())) {
|
||||
Term traceid = new Term("traceId");
|
||||
TermQuery termQuery = new TermQuery(traceid);
|
||||
booleanQueryBuilder.add(termQuery, BooleanClause.Occur.MUST_NOT);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(logQuery.getMessage())){
|
||||
//查询解析器
|
||||
QueryParser queryParser = new QueryParser("message", new IKAnalyzer(true));
|
||||
Query query = queryParser.parse(logQuery.getMessage());
|
||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
||||
}
|
||||
|
||||
TopFieldCollector collector = TopFieldCollector.create(new Sort(new SortField("time", SortField.Type.LONG,true)), 20000, 0);
|
||||
searcher.search(booleanQueryBuilder.build(), collector);
|
||||
TopDocs topDocs = collector.topDocs((logQuery.getPage()-1)*logQuery.getSize(), logQuery.getSize());
|
||||
int totalSize = collector.getTotalHits();
|
||||
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
|
||||
|
||||
List<LogRepositoryDTO> list = new ArrayList<>();
|
||||
for (ScoreDoc scoreDoc : scoreDocs) {
|
||||
Document doc = open.document(scoreDoc.doc);
|
||||
LogRepositoryDTO dto = new LogRepositoryDTO();
|
||||
dto.setSystem(doc.get("system"));
|
||||
dto.setTraceId(doc.get("traceId"));
|
||||
dto.setLogger(doc.get("logger"));
|
||||
dto.setLogLevel(doc.get("logLevel"));
|
||||
dto.setMessage(doc.get("message"));
|
||||
dto.setRequestIp(doc.get("requestIp"));
|
||||
dto.setRequestMethod(doc.get("requestMethod"));
|
||||
dto.setRequestTime(doc.get("requestTime"));
|
||||
dto.setThread(doc.get("thread"));
|
||||
list.add(dto);
|
||||
}
|
||||
open.close();
|
||||
directory.close();
|
||||
page.addAll(list);
|
||||
page.setTotal(scoreDocs.length);
|
||||
res.put("total", totalSize);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
res.put("page",page);
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void syncdemo() {
|
||||
log.info("Async线程链路测试"+Thread.currentThread().getName());
|
||||
log.error("Async线程链路测试"+Thread.currentThread().getName());
|
||||
log.info("Async线程链路测试"+Thread.currentThread().getName());
|
||||
log.info("线程链路测试"+Thread.currentThread().getName());
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package org.nl.system.service.lucene;
|
||||
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 日志检索服务
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-11-16
|
||||
*/
|
||||
public interface LuceneExecuteLogService {
|
||||
/**
|
||||
* 设备光电变化实时光电信号
|
||||
*
|
||||
* @param device_code 设备编号
|
||||
* @param key plc信号
|
||||
* @param value plc信号值
|
||||
*/
|
||||
void deviceItemValue(String device_code, String key, String value);
|
||||
|
||||
/**
|
||||
* 设备执行日志,会保留历史记录
|
||||
*
|
||||
* @param luceneLogDto 日志结果对象
|
||||
*/
|
||||
void deviceExecuteLog(LuceneLogDto luceneLogDto);
|
||||
|
||||
/**
|
||||
* 接口日志,会保留历史记录
|
||||
* @param luceneLogDto 日志结果对象
|
||||
* @throws IOException
|
||||
*/
|
||||
void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException;
|
||||
|
||||
/**
|
||||
* 设备执行日志,会保留历史记录
|
||||
*
|
||||
* @param name 日志名称
|
||||
* @param message 日志信息
|
||||
*/
|
||||
void extLog(String name, String message);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package org.nl.system.service.lucene;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 、
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-11-16
|
||||
*/
|
||||
public interface LuceneService {
|
||||
|
||||
/**
|
||||
* 获取数据分页
|
||||
*
|
||||
* @param whereJson 条件
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> getAll(JSONObject whereJson);
|
||||
|
||||
/**
|
||||
* 获取枚举的标签名称
|
||||
* @return
|
||||
*/
|
||||
List<String> getTagName();
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package org.nl.system.service.lucene.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 日志DTO
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-11-16
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LuceneLogDto {
|
||||
|
||||
/**
|
||||
* 日志标识
|
||||
*/
|
||||
private String log_uuid;
|
||||
/**
|
||||
* 日志类型
|
||||
*/
|
||||
private String logType;
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
private String device_code;
|
||||
/**
|
||||
* 内容详情
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 任务编码
|
||||
*/
|
||||
private String task_code;
|
||||
/**
|
||||
* 指令编码
|
||||
*/
|
||||
private String instruct_code;
|
||||
/**
|
||||
* 任务标识
|
||||
*/
|
||||
private String task_id;
|
||||
/**
|
||||
* 载具号
|
||||
*/
|
||||
private String vehicle_code;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 日志类型
|
||||
*/
|
||||
private String log_type;
|
||||
/**
|
||||
* 方法
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private String requestparam;
|
||||
/**
|
||||
* 响应参数
|
||||
*/
|
||||
private String responseparam;
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String requesturl;
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
private String status_code;
|
||||
/**
|
||||
* 是否删除 1:是;0:否
|
||||
*/
|
||||
private String is_delete;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String create_by;
|
||||
/**
|
||||
* 创建时间 YYYY-MM-DD hh:mm:ss
|
||||
*/
|
||||
private String create_time;
|
||||
/**
|
||||
* 修改者
|
||||
*/
|
||||
private String update_by;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String update_time;
|
||||
|
||||
public LuceneLogDto (final String opc_server_code,final String opc_plc_code,
|
||||
final String device_code,final String to_home,final int last_home,
|
||||
final int home) {
|
||||
super ();
|
||||
this.device_code = device_code;
|
||||
this.content = "信号"
|
||||
+ opc_server_code + "."
|
||||
+ opc_plc_code + "."
|
||||
+ device_code + "."
|
||||
+ to_home + "变更从"
|
||||
+ last_home + "->"
|
||||
+ home;
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package org.nl.system.service.lucene.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.nl.common.enums.LogTypeEnum;
|
||||
import org.nl.config.lucene.DynamicLogger;
|
||||
import org.nl.config.lucene.LuceneIndexWriter;
|
||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author jlm
|
||||
* @description 服务实现
|
||||
* @date 2023-04-11
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
||||
|
||||
/**
|
||||
* 日志目录
|
||||
*/
|
||||
@Value("${logging.file.path}")
|
||||
private String logPath;
|
||||
|
||||
@Override
|
||||
public void deviceItemValue(String device_code, String key, String value) {
|
||||
String now = DateUtil.now();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void deviceExecuteLog(LuceneLogDto luceneLogDto) {
|
||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
addIndex(luceneLogDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException {
|
||||
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
|
||||
addIndex(luceneLogDto);
|
||||
}
|
||||
|
||||
private void addIndex(LuceneLogDto luceneLogDto) throws IOException {
|
||||
IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter();
|
||||
//创建一个Document对象
|
||||
Document document = new Document();
|
||||
try {
|
||||
//记录索引开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
//向document对象中添加域。
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) {
|
||||
document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) {
|
||||
document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) {
|
||||
document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) {
|
||||
document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) {
|
||||
document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) {
|
||||
document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES));
|
||||
}
|
||||
document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES));
|
||||
document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES));
|
||||
indexWriter.addDocument(document);
|
||||
//记录索引结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
indexWriter.commit();
|
||||
//实现日志文件按业务独立生成日志文件到指定路径
|
||||
DynamicLogger loggerBuilder =new DynamicLogger(logPath+"\\"+luceneLogDto.getLogType()+"\\");
|
||||
Logger logger = loggerBuilder.getLogger(luceneLogDto.getDevice_code());
|
||||
logger.info("{}",luceneLogDto.toString());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extLog(String name, String message) {
|
||||
try {
|
||||
MDC.put(name, name);
|
||||
log.info("{}", message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
MDC.remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package org.nl.system.service.lucene.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.config.lucene.Searcher;
|
||||
import org.nl.config.lucene.TagNameEnum;
|
||||
import org.nl.system.service.lucene.LuceneService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 、
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-11-16
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class LuceneServiceImpl implements LuceneService {
|
||||
|
||||
/**
|
||||
* 日志索引目录
|
||||
*/
|
||||
@Value("${lucene.index.path}")
|
||||
private String luceneUrl;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAll(JSONObject whereJson) {
|
||||
JSONObject jo = new JSONObject();
|
||||
try {
|
||||
JSONObject jsonObject = (JSONObject) Searcher.search(luceneUrl, whereJson);
|
||||
JSONArray array = jsonObject.getJSONArray("content");
|
||||
int totalElements = Integer.parseInt(jsonObject.get("totalElements").toString());
|
||||
jo.put("content", array);
|
||||
jo.put("totalElements", totalElements);
|
||||
} catch (Exception e) {
|
||||
log.error("索引查询为空", e);
|
||||
throw new NullPointerException(LangProcess.msg("error_NullPoint"));
|
||||
}
|
||||
|
||||
return jo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTagName() {
|
||||
return Arrays.stream(TagNameEnum.values()).map(TagNameEnum::getTag).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import org.nl.config.IdUtil;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.dict.dao.mapper.SysDictMapper;
|
||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
||||
import org.nl.system.service.menu.dto.MenuDto;
|
||||
import org.nl.system.service.menu.ISysMenuService;
|
||||
import org.nl.system.service.menu.dao.SysMenu;
|
||||
@@ -56,8 +55,6 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
@Autowired
|
||||
private SysDictMapper sysDictMapper;
|
||||
|
||||
@Autowired
|
||||
private LuceneExecuteLogService luceneExecuteLogService;
|
||||
|
||||
@Override
|
||||
public List<MenuDto> queryAll(Map<String, Object> param) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -34,13 +33,11 @@ public class SysDataPermission implements Serializable {
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@NotNull
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -35,13 +34,11 @@ public class SysQuartzJob implements Serializable {
|
||||
/**
|
||||
* bean名
|
||||
*/
|
||||
@NotBlank
|
||||
private String bean_name;
|
||||
|
||||
/**
|
||||
* corn表达式
|
||||
*/
|
||||
@NotBlank
|
||||
private String cron_expression;
|
||||
|
||||
/**
|
||||
@@ -52,13 +49,11 @@ public class SysQuartzJob implements Serializable {
|
||||
/**
|
||||
* 任务名称
|
||||
*/
|
||||
@NotBlank
|
||||
private String job_name;
|
||||
|
||||
/**
|
||||
* 方法名称
|
||||
*/
|
||||
@NotBlank
|
||||
private String method_name;
|
||||
|
||||
/**
|
||||
@@ -69,7 +64,6 @@ public class SysQuartzJob implements Serializable {
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@NotBlank
|
||||
private String description;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package org.nl.system.service.quartz.utils;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.tlog.task.quartz.TLogQuartzJobBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.nl.common.utils.RedisUtils;
|
||||
import org.nl.common.utils.ThrowableUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.config.thread.ThreadPoolExecutorUtil;
|
||||
import org.nl.system.service.quartz.ISysQuartzJobService;
|
||||
import org.nl.system.service.quartz.dao.SysQuartzJob;
|
||||
import org.nl.system.service.quartz.dao.SysQuartzLog;
|
||||
@@ -16,11 +13,11 @@ import org.nl.system.service.quartz.impl.SysQuartzJobServiceImpl;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@@ -33,18 +30,17 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
@SuppressWarnings({"unchecked", "all"})
|
||||
@Slf4j
|
||||
@DisallowConcurrentExecution
|
||||
public class ExecutionJob extends TLogQuartzJobBean {
|
||||
public class ExecutionJob extends QuartzJobBean {
|
||||
|
||||
/**
|
||||
* 该处仅供参考
|
||||
*/
|
||||
@Autowired
|
||||
@Qualifier("threadPoolExecutor")
|
||||
@Resource
|
||||
@Qualifier("meshandlerPool")
|
||||
private ThreadPoolExecutor EXECUTOR;
|
||||
|
||||
|
||||
@Override
|
||||
public void executeTask(JobExecutionContext context) throws JobExecutionException {
|
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
SysQuartzJob quartzJob = (SysQuartzJob) context.getMergedJobDataMap().get(SysQuartzJob.JOB_KEY);
|
||||
// 获取spring bean
|
||||
ISysQuartzJobService quartzJobService = SpringContextHolder.getBean(SysQuartzJobServiceImpl.class);
|
||||
@@ -54,7 +50,7 @@ public class ExecutionJob extends TLogQuartzJobBean {
|
||||
String uuid = quartzJob.getUuid();
|
||||
|
||||
SysQuartzLog logDto = new SysQuartzLog();
|
||||
logDto.setLog_id(IdUtil.getSnowflake(1, 1).nextIdStr());
|
||||
logDto.setLog_id(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||
logDto.setJob_name(quartzJob.getJob_name());
|
||||
logDto.setBean_name(quartzJob.getBean_name());
|
||||
logDto.setMethod_name(quartzJob.getMethod_name());
|
||||
@@ -63,8 +59,6 @@ public class ExecutionJob extends TLogQuartzJobBean {
|
||||
logDto.setCron_expression(quartzJob.getCron_expression());
|
||||
try {
|
||||
// 执行任务
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
System.out.println("任务开始执行,任务名称:" + quartzJob.getJob_name());
|
||||
QuartzRunnable task = new QuartzRunnable(quartzJob.getBean_name(), quartzJob.getMethod_name(),
|
||||
quartzJob.getParams());
|
||||
Future<?> future = EXECUTOR.submit(task);
|
||||
@@ -76,8 +70,6 @@ public class ExecutionJob extends TLogQuartzJobBean {
|
||||
}
|
||||
// 任务状态
|
||||
logDto.setIs_success(true);
|
||||
System.out.println("任务执行完毕,任务名称:" + quartzJob.getJob_name() + ", 执行时间:" + times + "毫秒");
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
// 判断是否存在子任务
|
||||
if (StrUtil.isNotEmpty(quartzJob.getSub_task())) {
|
||||
String[] tasks = quartzJob.getSub_task().split("[,,]");
|
||||
@@ -88,13 +80,11 @@ public class ExecutionJob extends TLogQuartzJobBean {
|
||||
if (StrUtil.isNotEmpty(uuid)) {
|
||||
redisUtils.set(uuid, false);
|
||||
}
|
||||
System.out.println("任务执行失败,任务名称:" + quartzJob.getJob_name());
|
||||
System.out.println("--------------------------------------------------------------");
|
||||
long times = System.currentTimeMillis() - startTime;
|
||||
logDto.setTime(times);
|
||||
// 任务状态 0:成功 1:失败
|
||||
logDto.setIs_success(false);
|
||||
logDto.setException_detail(ThrowableUtil.getStackTrace(e));
|
||||
logDto.setException_detail(e.getMessage());
|
||||
// 任务如果失败了则暂停
|
||||
if (quartzJob.getPause_after_failure() != null && quartzJob.getPause_after_failure()) {
|
||||
quartzJob.setIs_pause(false);
|
||||
@@ -102,7 +92,7 @@ public class ExecutionJob extends TLogQuartzJobBean {
|
||||
quartzJobService.updateIsPause(quartzJob);
|
||||
}
|
||||
//异常时候打印日志
|
||||
log.info(logDto.toString());
|
||||
log.error(logDto.toString());
|
||||
quartzLogMapper.insert(logDto);
|
||||
} finally {
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.nl.system.service.secutiry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface HandLoginService {
|
||||
/**
|
||||
* 手持登陆
|
||||
*
|
||||
* @param jsonObject 条件
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> handleLogin(Map<String, String> jsonObject);
|
||||
|
||||
/**
|
||||
* 手持登陆查询权限
|
||||
*
|
||||
* @param jsonObject 条件
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> queryAuthority(Map<String, String> jsonObject);
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.nl.system.service.secutiry.dto;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -28,10 +28,10 @@ import javax.validation.constraints.NotBlank;
|
||||
@Setter
|
||||
public class AuthUserDto {
|
||||
|
||||
@NotBlank
|
||||
|
||||
private String username;
|
||||
|
||||
@NotBlank
|
||||
|
||||
private String password;
|
||||
|
||||
private String code;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 org.nl.system.service.secutiry.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 在线用户
|
||||
* @author Zheng Jie
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class OnlineUserDto {
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 岗位
|
||||
*/
|
||||
private String dept;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* token
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Date loginTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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 org.nl.system.service.secutiry.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nl.common.base.BaseDTO;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-23
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserDto extends BaseDTO implements Serializable {
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private String id;
|
||||
|
||||
// private Set<RoleSmallDto> roles;
|
||||
|
||||
|
||||
private String username;
|
||||
|
||||
private String personName;
|
||||
|
||||
private String email;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String gender;
|
||||
|
||||
private String avatarName;
|
||||
|
||||
private String avatarPath;
|
||||
|
||||
private String extId;
|
||||
|
||||
private String extuserId;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
private String password;
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
@JsonIgnore
|
||||
private Boolean isAdmin = false;
|
||||
|
||||
private Date pwdResetTime;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* 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 org.nl.system.service.secutiry.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.system.service.secutiry.enums.LoginCodeEnum;
|
||||
|
||||
/**
|
||||
* 登录验证码配置信息
|
||||
*
|
||||
* @author: liaojinlong
|
||||
* @date: 2020/6/10 18:53
|
||||
*/
|
||||
@Data
|
||||
public class LoginCode {
|
||||
|
||||
/**
|
||||
* 验证码配置
|
||||
*/
|
||||
private LoginCodeEnum codeType;
|
||||
/**
|
||||
* 验证码有效期 分钟
|
||||
*/
|
||||
private Long expiration = 2L;
|
||||
/**
|
||||
* 验证码内容长度
|
||||
*/
|
||||
private int length = 2;
|
||||
/**
|
||||
* 验证码宽度
|
||||
*/
|
||||
private int width = 111;
|
||||
/**
|
||||
* 验证码高度
|
||||
*/
|
||||
private int height = 36;
|
||||
/**
|
||||
* 验证码字体
|
||||
*/
|
||||
private String fontName;
|
||||
/**
|
||||
* 字体大小
|
||||
*/
|
||||
private int fontSize = 25;
|
||||
|
||||
public LoginCodeEnum getCodeType() {
|
||||
return codeType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version loginCode.length.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-loginCode.length.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 org.nl.system.service.secutiry.entity;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.wf.captcha.*;
|
||||
import com.wf.captcha.base.Captcha;
|
||||
import lombok.Data;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.system.service.secutiry.enums.LoginCodeEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 配置文件读取
|
||||
*
|
||||
* @author liaojinlong
|
||||
* @date loginCode.length0loginCode.length0/6/10 17:loginCode.length6
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
public class LoginProperties {
|
||||
|
||||
/**
|
||||
* 账号单用户 登录
|
||||
*/
|
||||
private boolean singleLogin = false;
|
||||
|
||||
private LoginCode loginCode;
|
||||
/**
|
||||
* 用户登录信息缓存
|
||||
*/
|
||||
private boolean cacheEnable;
|
||||
|
||||
public boolean isSingleLogin() {
|
||||
return singleLogin;
|
||||
}
|
||||
|
||||
public boolean isCacheEnable() {
|
||||
return cacheEnable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码生产类
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public Captcha getCaptcha() {
|
||||
if (Objects.isNull(loginCode)) {
|
||||
loginCode = new LoginCode();
|
||||
if (Objects.isNull(loginCode.getCodeType())) {
|
||||
loginCode.setCodeType(LoginCodeEnum.arithmetic);
|
||||
}
|
||||
}
|
||||
return switchCaptcha(loginCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 依据配置信息生产验证码
|
||||
*
|
||||
* @param loginCode 验证码配置信息
|
||||
* @return /
|
||||
*/
|
||||
private Captcha switchCaptcha(LoginCode loginCode) {
|
||||
Captcha captcha;
|
||||
synchronized (this) {
|
||||
switch (loginCode.getCodeType()) {
|
||||
case arithmetic:
|
||||
// 算术类型 https://gitee.com/whvse/EasyCaptcha
|
||||
captcha = new ArithmeticCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
// 几位数运算,默认是两位
|
||||
captcha.setLen(loginCode.getLength());
|
||||
break;
|
||||
case chinese:
|
||||
captcha = new ChineseCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
captcha.setLen(loginCode.getLength());
|
||||
break;
|
||||
case chinese_gif:
|
||||
captcha = new ChineseGifCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
captcha.setLen(loginCode.getLength());
|
||||
break;
|
||||
case gif:
|
||||
captcha = new GifCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
captcha.setLen(loginCode.getLength());
|
||||
break;
|
||||
case spec:
|
||||
captcha = new SpecCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
captcha.setLen(loginCode.getLength());
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException("验证码配置信息错误!正确配置查看 LoginCodeEnum ");
|
||||
}
|
||||
}
|
||||
if(StrUtil.isNotEmpty(loginCode.getFontName())){
|
||||
captcha.setFont(new Font(loginCode.getFontName(), Font.PLAIN, loginCode.getFontSize()));
|
||||
}
|
||||
return captcha;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.nl.system.service.secutiry.enums;
|
||||
|
||||
public enum LoginCodeEnum {
|
||||
/**
|
||||
* 算数
|
||||
*/
|
||||
arithmetic,
|
||||
/**
|
||||
* 中文
|
||||
*/
|
||||
chinese,
|
||||
/**
|
||||
* 中文闪图
|
||||
*/
|
||||
chinese_gif,
|
||||
/**
|
||||
* 闪图
|
||||
*/
|
||||
gif,
|
||||
spec
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.nl.system.service.secutiry.impl;
|
||||
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.RedisUtils;
|
||||
import org.nl.common.utils.RsaUtils;
|
||||
import org.nl.common.utils.dto.CurrentUser;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.secutiry.HandLoginService;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class HandLoginServiceImpl implements HandLoginService {
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
@Autowired
|
||||
private ISysUserService iSysUserService;
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Map<String, Object> handleLogin(Map<String, String> param) {
|
||||
Assert.notNull(param,"请求参数不能为空");
|
||||
SysUser userInfo = iSysUserService.getOne(new QueryWrapper<SysUser>().eq("username",param.get("user")));
|
||||
if (userInfo == null||!userInfo.getPassword().equals(SaSecureUtil.md5BySalt(RsaUtils.decryptByPrivateKey(RsaUtils.KEY, param.get("password")), "salt"))) { // 这里需要密码加密
|
||||
throw new BadRequestException("账号或密码错误");
|
||||
}
|
||||
if (!userInfo.getIs_used()) {
|
||||
throw new BadRequestException("账号未激活");
|
||||
}
|
||||
List<String> permissionList = roleService.getPermissionList((JSONObject) JSON.toJSON(userInfo));
|
||||
// 登录输入,登出删除
|
||||
CurrentUser user = new CurrentUser();
|
||||
user.setId(userInfo.getUser_id());
|
||||
user.setUsername(userInfo.getUsername());
|
||||
user.setPresonName((userInfo.getPerson_name()));
|
||||
user.setUser(userInfo);
|
||||
user.setPermissions(permissionList);
|
||||
// SaLoginModel 配置登录相关参数
|
||||
StpUtil.login(userInfo.getUser_id(), new SaLoginModel()
|
||||
.setDevice("PC") // 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
|
||||
.setExtra("loginInfo", JSONObject.toJSONString(user)) // Token挂载的扩展参数 (此方法只有在集成jwt插件时才会生效)
|
||||
);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("token", StpUtil.getTokenValue());
|
||||
result.put("roles", permissionList);
|
||||
result.put("user", user);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAuthority(Map<String, String> jsonObject) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
/*
|
||||
* 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 org.nl.system.service.secutiry.impl;
|
||||
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.utils.*;
|
||||
import org.nl.config.RsaProperties;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.dto.CurrentUser;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.dept.dao.SysDept;
|
||||
import org.nl.system.service.secutiry.dto.UserDto;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.secutiry.dto.AuthUserDto;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.nl.system.service.user.dto.OnlineUserDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019年10月26日21:56:27
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OnlineUserService {
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private ISysDeptService deptService;
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
public OnlineUserService(RedisUtils redisUtils) {
|
||||
this.redisUtils = redisUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存在线用户信息
|
||||
* @param userDto /
|
||||
* @param token /
|
||||
* @param request /
|
||||
*/
|
||||
public void save(SysUser userDto, String token, HttpServletRequest request){
|
||||
// 获取用户部门
|
||||
List<SysDept> userDeptByUserId = deptService.getUserDeptByUserId(userDto.getUser_id());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (SysDept dept : userDeptByUserId) {
|
||||
sb.append(dept.getName()).append("、");
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
sb.setLength(sb.length() - 1);
|
||||
}
|
||||
String dept = sb.toString();
|
||||
String ip = StringUtils.getIp(request);
|
||||
String browser = StringUtils.getBrowser(request);
|
||||
String address = StringUtils.getCityInfo(ip);
|
||||
OnlineUserDto onlineUserDto = null;
|
||||
try {
|
||||
onlineUserDto = new OnlineUserDto(userDto.getUsername(), userDto.getPerson_name(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
redisUtils.set("oline-" + userDto.getUsername(), onlineUserDto, StpUtil.getTokenTimeout());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* @param filter /
|
||||
* @param pageable /
|
||||
* @return /
|
||||
*/
|
||||
public Map<String,Object> getAll(String filter, Pageable pageable){
|
||||
List<OnlineUserDto> onlineUserDtos = getAll(filter);
|
||||
return PageUtil.toPage(
|
||||
PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(), onlineUserDtos),
|
||||
onlineUserDtos.size()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据,不分页
|
||||
* @param filter /
|
||||
* @return /
|
||||
*/
|
||||
public List<OnlineUserDto> getAll(String filter){
|
||||
List<String> keys = redisUtils.scan("oline-*");
|
||||
Collections.reverse(keys);
|
||||
List<OnlineUserDto> onlineUserDtos = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
OnlineUserDto onlineUserDto = (OnlineUserDto) redisUtils.get(key);
|
||||
onlineUserDtos.add(onlineUserDto);
|
||||
}
|
||||
onlineUserDtos.sort((o1, o2) -> o2.getLoginTime().compareTo(o1.getLoginTime()));
|
||||
return onlineUserDtos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 踢出用户
|
||||
* @param key: OnlineUserDto /
|
||||
*/
|
||||
public void kickOut(OnlineUserDto key) {
|
||||
// 获取用户
|
||||
SysUser one = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, key.getUserName()));
|
||||
if (ObjectUtil.isNotEmpty(one)) {
|
||||
redisUtils.del("oline-" + one.getUsername());
|
||||
}
|
||||
// 通过token强退
|
||||
StpUtil.logoutByTokenValue(key.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* 踢出用户
|
||||
* @param key:token /
|
||||
*/
|
||||
public void kickOut(String key) {
|
||||
redisUtils.del(key);
|
||||
// 通过token强退
|
||||
StpUtil.logoutByTokenValue(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @param token /
|
||||
*/
|
||||
public void logout(String token) {
|
||||
redisUtils.del(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
* @param all /
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
public void download(List<OnlineUserDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (OnlineUserDto user : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", user.getUserName());
|
||||
map.put("部门", user.getDept());
|
||||
map.put("登录IP", user.getIp());
|
||||
map.put("登录地点", user.getAddress());
|
||||
map.put("浏览器", user.getBrowser());
|
||||
map.put("登录日期", user.getLoginTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
* @param key /
|
||||
* @return /
|
||||
*/
|
||||
public OnlineUserDto getOne(String key) {
|
||||
return (OnlineUserDto)redisUtils.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户是否在之前已经登录,已经登录踢下线
|
||||
* @param userName 用户名
|
||||
*/
|
||||
public void checkLoginOnUser(String userName, String igoreToken){
|
||||
List<OnlineUserDto> onlineUserDtos = getAll(userName);
|
||||
if(onlineUserDtos ==null || onlineUserDtos.isEmpty()){
|
||||
return;
|
||||
}
|
||||
for(OnlineUserDto onlineUserDto : onlineUserDtos){
|
||||
if(onlineUserDto.getUserName().equals(userName)){
|
||||
try {
|
||||
String token =EncryptUtils.desDecrypt(onlineUserDto.getKey());
|
||||
if(StrUtil.isNotEmpty(igoreToken)&&!igoreToken.equals(token)){
|
||||
this.kickOut(token);
|
||||
}else if(StrUtil.isEmpty(igoreToken)){
|
||||
this.kickOut(token);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("checkUser is error",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名强退用户
|
||||
* @param username /
|
||||
*/
|
||||
@Async
|
||||
public void kickOutForUsername(String username) throws Exception {
|
||||
List<OnlineUserDto> onlineUsers = getAll(username);
|
||||
for (OnlineUserDto onlineUser : onlineUsers) {
|
||||
if (onlineUser.getUserName().equals(username)) {
|
||||
String token = EncryptUtils.desDecrypt(onlineUser.getKey());
|
||||
kickOut(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@SneakyThrows
|
||||
public Map<String, Object> login(Map paramMap, HttpServletRequest request){
|
||||
// 密码解密 - 前端的加密规则: encrypt
|
||||
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
||||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||
// 查询验证码
|
||||
String code = (String) redisUtils.get(authUser.getUuid());
|
||||
// 清除验证码
|
||||
redisUtils.del(authUser.getUuid());
|
||||
if (StrUtil.isEmpty(code)) {
|
||||
throw new BadRequestException(LangProcess.msg("login_CodeNull"));
|
||||
}
|
||||
if (StrUtil.isEmpty(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
||||
throw new BadRequestException(LangProcess.msg("login_CodeError"));
|
||||
}
|
||||
|
||||
/*
|
||||
* 校验数据库
|
||||
* username:根据用户名查询,在比对密码
|
||||
* SaSecureUtil.md5BySalt(password, "salt"): 这里需要密码加密
|
||||
*/
|
||||
String salt = "salt";
|
||||
SysUser userInfo = sysUserService.getOne(new QueryWrapper<SysUser>().eq("username",authUser.getUsername()));
|
||||
if (userInfo == null||!userInfo.getPassword().equals(SaSecureUtil.md5BySalt(password, salt))) {
|
||||
throw new BadRequestException(LangProcess.msg("login_pwd"));
|
||||
}
|
||||
|
||||
// 获取权限列表 - 登录查找权限
|
||||
List<String> permissionList = roleService.getPermissionList((JSONObject) JSON.toJSON(userInfo));
|
||||
|
||||
|
||||
if (!userInfo.getIs_used()) {
|
||||
throw new BadRequestException(LangProcess.msg("login_account"));
|
||||
}
|
||||
|
||||
// 登录输入,登出删除
|
||||
CurrentUser user = new CurrentUser();
|
||||
user.setId(userInfo.getUser_id());
|
||||
user.setUsername(userInfo.getUsername());
|
||||
user.setPresonName((userInfo.getPerson_name()));
|
||||
user.setUser(userInfo);
|
||||
user.setPermissions(permissionList);
|
||||
|
||||
/*
|
||||
* SaLoginModel 配置登录相关参数
|
||||
* PC: 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
|
||||
* loginInfo: Token挂载的扩展参数 (此方法只有在集成jwt插件时才会生效)
|
||||
*/
|
||||
StpUtil.login(userInfo.getUser_id(), new SaLoginModel()
|
||||
.setDevice("PC")
|
||||
.setExtra("loginInfo", user)
|
||||
);
|
||||
|
||||
// 返回 token 与 用户信息
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("roles", permissionList);
|
||||
jsonObject.put("user", userInfo);
|
||||
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
|
||||
put("token", "Bearer " + StpUtil.getTokenValue());
|
||||
put("user", user);
|
||||
}};
|
||||
// 保存在线信息
|
||||
this.save(userInfo, StpUtil.getTokenValue(), request);
|
||||
return authInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.nl.system.service.user;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
@@ -80,4 +81,6 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
* @return List<String>
|
||||
*/
|
||||
List<String> getUserIdByDeptId(String deptId);
|
||||
|
||||
JSONObject login(JSONObject userDetail);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
package org.nl.system.service.user.impl;
|
||||
|
||||
import cn.dev33.satoken.secure.SaSecureUtil;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.RedisUtils;
|
||||
import org.nl.common.utils.RsaUtils;
|
||||
import org.nl.common.utils.dto.CurrentUser;
|
||||
import org.nl.config.FileProperties;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.config.IdUtil;
|
||||
import org.nl.system.service.dept.ISysDeptService;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.secutiry.dto.AuthUserDto;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.nl.system.service.user.dao.mapper.SysUserMapper;
|
||||
@@ -50,6 +59,8 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
private ISysDeptService deptService;
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
|
||||
@@ -156,4 +167,43 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
public List<String> getUserIdByDeptId(String deptId) {
|
||||
return sysUserMapper.getUserIdByDeptId(deptId);
|
||||
}
|
||||
@Override
|
||||
public JSONObject login(JSONObject userDetail) {
|
||||
AuthUserDto authUser = userDetail.toJavaObject(AuthUserDto.class);
|
||||
// 查询验证码
|
||||
String code = (String) redisUtils.get(authUser.getUuid());
|
||||
redisUtils.del(authUser.getUuid());
|
||||
// if (StrUtil.isEmpty(code)) {
|
||||
// throw new BadRequestException("验证码不存在或已过期");
|
||||
// }
|
||||
// if (StrUtil.isEmpty(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
||||
// throw new BadRequestException("验证码错误");
|
||||
// }
|
||||
SysUser userInfo = this.getOne(new QueryWrapper<SysUser>().eq("username",authUser.getUsername()));
|
||||
if (userInfo == null||!userInfo.getPassword().equals(SaSecureUtil.md5BySalt(RsaUtils.decryptByPrivateKey(RsaUtils.KEY, authUser.getPassword()), "salt"))) { // 这里需要密码加密
|
||||
throw new BadRequestException("账号或密码错误");
|
||||
}
|
||||
if (!userInfo.getIs_used()) {
|
||||
throw new BadRequestException("账号未激活");
|
||||
}
|
||||
List<String> permissionList = roleService.getPermissionList((JSONObject) JSON.toJSON(userInfo));
|
||||
// 登录输入,登出删除
|
||||
CurrentUser user = new CurrentUser();
|
||||
user.setId(userInfo.getUser_id());
|
||||
user.setUsername(userInfo.getUsername());
|
||||
user.setPresonName((userInfo.getPerson_name()));
|
||||
user.setUser(userInfo);
|
||||
user.setPermissions(permissionList);
|
||||
// SaLoginModel 配置登录相关参数
|
||||
StpUtil.login(userInfo.getUser_id(), new SaLoginModel()
|
||||
.setDevice("PC") // 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
|
||||
.setExtra("loginInfo", JSONObject.toJSONString(user)) // Token挂载的扩展参数 (此方法只有在集成jwt插件时才会生效)
|
||||
);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("token", StpUtil.getTokenValue());
|
||||
result.put("roles", permissionList);
|
||||
result.put("user", user);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user