parent
7c16d404cc
commit
13eb93bb0a
@ -1,98 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.12</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.sztzjy</groupId>
|
||||
<artifactId>foreign_exchange_trading</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<name>foreign_exchange_trading</name>
|
||||
<packaging>jar</packaging>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.12</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.sztzjy</groupId>
|
||||
<artifactId>foreign_exchange_trading</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<name>foreign_exchange_trading</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-jwt</artifactId>
|
||||
<version>1.1.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nimbusds</groupId>
|
||||
<artifactId>nimbus-jose-jwt</artifactId>
|
||||
<version>9.26</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-jwt</artifactId>
|
||||
<version>1.1.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nimbusds</groupId>
|
||||
<artifactId>nimbus-jose-jwt</artifactId>
|
||||
<version>9.26</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security.oauth</groupId>
|
||||
<artifactId>spring-security-oauth2</artifactId>
|
||||
<version>2.3.8.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-spatial</artifactId>
|
||||
</dependency>
|
||||
<!-- MySQL连接驱动 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security.oauth</groupId>
|
||||
<artifactId>spring-security-oauth2</artifactId>
|
||||
<version>2.3.8.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-spatial</artifactId>
|
||||
<version>5.4.29.Final</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<groupId>mysql</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- MySQL连接驱动 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.32</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.hibernate</groupId>-->
|
||||
<!-- <artifactId>hibernate-core</artifactId>-->
|
||||
<!-- <version>5.6.14.Final</version>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<!--true跳过测试-->
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.sztzjy.forex.trading_trading.controller;
|
||||
|
||||
import com.sztzjy.forex.trading_trading.dto.PageVO;
|
||||
import com.sztzjy.forex.trading_trading.entity.Log;
|
||||
import com.sztzjy.forex.trading_trading.service.LogService;
|
||||
import com.sztzjy.forex.trading_trading.util.ResultEntity;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Api(tags = "系统:操作日志")
|
||||
@RestController
|
||||
@RequestMapping("api/syslog")
|
||||
@RequiredArgsConstructor
|
||||
public class LogController {
|
||||
private final LogService logService;
|
||||
|
||||
@ApiOperation("根据条件查询操作日志(分页)")
|
||||
@GetMapping("findAll")
|
||||
public ResultEntity<PageVO<Log>> findAll(@ApiParam("ip地址") @RequestParam(required = false) String ipAddress,
|
||||
@ApiParam("开始时间") @RequestParam(required = false) Long startTime,
|
||||
@ApiParam("结束时间") @RequestParam(required = false) Long endTime,
|
||||
@ApiParam("分页索引:{0}为第一页") @RequestParam(required = false) Integer index,
|
||||
@ApiParam("页量") @RequestParam(required = false) Integer size,
|
||||
@ApiParam("操作人") @RequestParam(required = false) String operatorName
|
||||
) {
|
||||
Page<Log> page = logService.findByConditions(index, size, ipAddress, startTime, endTime, operatorName);
|
||||
PageVO<Log> pageVO = new PageVO<>();
|
||||
pageVO.setPageInfo(page, page.getContent());
|
||||
return new ResultEntity<>(HttpStatus.OK, pageVO);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.sztzjy.forex.trading_trading.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Getter;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分页输出VO
|
||||
*/
|
||||
@ApiModel("分页出参对象")
|
||||
@Getter
|
||||
public class PageVO<T> {
|
||||
private List<T> content;
|
||||
private Long totalElements;
|
||||
private Boolean last;
|
||||
private Integer totalPages;
|
||||
private Integer number;
|
||||
private Integer size;
|
||||
private Integer numberOfElements;
|
||||
private Boolean first;
|
||||
private Boolean empty;
|
||||
|
||||
/**
|
||||
* 转换分页实体
|
||||
* @param pageData org.springframework.data.domain.Page
|
||||
* @param voList 实体几何
|
||||
*/
|
||||
public void setPageInfo(Page<?> pageData, List<T> voList) {
|
||||
this.content = voList;
|
||||
this.totalPages = pageData.getTotalPages();
|
||||
this.size = pageData.getSize();
|
||||
this.number = pageData.getNumber();
|
||||
this.first = pageData.isFirst();
|
||||
this.last = pageData.isLast();
|
||||
this.empty = pageData.isEmpty();
|
||||
this.totalElements = pageData.getTotalElements();
|
||||
this.numberOfElements = pageData.getNumberOfElements();
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.sztzjy.forex.trading_trading.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.sztzjy.forex.trading_trading.config.DateToLongSerialized;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("基础实体类")
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
|
||||
public class Base {
|
||||
@ApiModelProperty("主键id")
|
||||
@Id
|
||||
@GenericGenerator(name = "system_uuid", strategy = "uuid")
|
||||
@GeneratedValue(generator = "system_uuid")
|
||||
private String id;
|
||||
@ApiModelProperty("创建时间")
|
||||
@JsonSerialize(using = DateToLongSerialized.class)
|
||||
private Date createTime = null;
|
||||
@ApiModelProperty("更新时间")
|
||||
@JsonSerialize(using = DateToLongSerialized.class)
|
||||
private Date updateTime = null;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.sztzjy.forex.trading_trading.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@ApiModel("日志")
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "sys_log")
|
||||
public class Log extends Base {
|
||||
@ApiModelProperty("执行的操作")
|
||||
private String action;
|
||||
@ApiModelProperty("操作来源IP地址")
|
||||
private String ipAddress;
|
||||
@ApiModelProperty("操作人ID")
|
||||
private String operatorId;
|
||||
@ApiModelProperty("操作人姓名")
|
||||
private String operatorName;
|
||||
@ApiModelProperty("客户端")
|
||||
private String userAgent;
|
||||
@ApiModelProperty("执行参数")
|
||||
private String params;
|
||||
@ApiModelProperty("描述")
|
||||
private String description;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.sztzjy.forex.trading_trading.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 自定义持久层接口
|
||||
* 当系统业务持久层需要自定义功能
|
||||
* 则需要继承此接口
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface IBaseJpaRepository<T, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.sztzjy.forex.trading_trading.repository;
|
||||
|
||||
|
||||
import com.sztzjy.forex.trading_trading.entity.Log;
|
||||
|
||||
public interface ILogRepository extends IBaseJpaRepository<Log, String> {
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.sztzjy.forex.trading_trading.service;
|
||||
|
||||
import com.sztzjy.forex.trading_trading.entity.Log;
|
||||
import com.sztzjy.forex.trading_trading.repository.ILogRepository;
|
||||
import com.sztzjy.forex.trading_trading.util.PageUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统日志服务层
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LogService {
|
||||
private final ILogRepository logRepository;
|
||||
|
||||
public Page<Log> findAll(Integer index, Integer size) {
|
||||
PageUtil pageUtil = new PageUtil(index, size);
|
||||
pageUtil.addSort("operatedTime", false);
|
||||
return logRepository.findAll(pageUtil.getPageable());
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Log add(Log logRecord) {
|
||||
logRecord.setCreateTime(new Date());
|
||||
logRepository.save(logRecord);
|
||||
return logRecord;
|
||||
}
|
||||
|
||||
public Page<Log> findByConditions(Integer index, Integer size, String ipAddress, Long startTime, Long endTime, String operatorName) {
|
||||
Specification<Log> specification = (Specification<Log>) (root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> andPredicate = new ArrayList<>();
|
||||
if (ipAddress != null && !ipAddress.isEmpty()) {
|
||||
andPredicate.add(criteriaBuilder.equal(root.get("ipAddress"), ipAddress));
|
||||
}
|
||||
if (startTime != null && startTime != 0) {
|
||||
andPredicate.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createTime"), new Date(startTime)));
|
||||
}
|
||||
if (endTime != null && endTime != 0) {
|
||||
andPredicate.add(criteriaBuilder.lessThanOrEqualTo(root.get("createTime"), new Date(endTime)));
|
||||
}
|
||||
if (operatorName != null && !operatorName.isEmpty()) {
|
||||
andPredicate.add(criteriaBuilder.like(root.get("operatorName"), operatorName + '%'));
|
||||
}
|
||||
return criteriaQuery.where(andPredicate.toArray(new Predicate[]{})).getRestriction();
|
||||
};
|
||||
PageUtil pageUtil = new PageUtil(index, size);
|
||||
pageUtil.addSort("createTime", false);
|
||||
return logRepository.findAll(specification, pageUtil.getPageable());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.sztzjy.forex.trading_trading.util;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* 分页工具类
|
||||
*/
|
||||
public class PageUtil {
|
||||
private final Integer index;
|
||||
private final Integer size;
|
||||
private Sort sort;
|
||||
|
||||
public PageUtil(Integer index, Integer size) {
|
||||
if (index == null || index < 0) index = 0;
|
||||
if (size == null || size < 0) size = 10;
|
||||
if (size > 200) size = 1000;
|
||||
this.index = index;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
//该方法用于数据量大的情况下分页导出
|
||||
public PageUtil(Integer index, Integer size, boolean type) {
|
||||
if (index == null || index < 0) index = 0;
|
||||
if (size == null || size < 0) size = 10;
|
||||
this.index = index;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void addSort(String columnName, Boolean asc) {
|
||||
Sort.Direction direction = Sort.Direction.ASC;
|
||||
if (!asc) direction = Sort.Direction.DESC;
|
||||
if (sort == null) {
|
||||
sort = Sort.by(direction, columnName);
|
||||
} else {
|
||||
sort = sort.and(Sort.by(direction, columnName));
|
||||
}
|
||||
}
|
||||
|
||||
public Pageable getPageable() {
|
||||
if (sort == null)
|
||||
return PageRequest.of(index, size);
|
||||
else
|
||||
return PageRequest.of(index, size, sort);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://${DB_HOST:118.31.7.2}:${DB_PORT:3306}}/${DB_NAME:foreign_trading_system}?useSSL=false&serverTimezone=UTC
|
||||
db-type: mysql
|
||||
url: jdbc:mysql://${DB_HOST:118.31.7.2}:${DB_PORT:3306}/${DB_NAME:foreign_exchange_trading}?useSSL=false&serverTimezone=UTC
|
||||
username: ${DB_USER:root}
|
||||
password: ${DB_PWD:sztzjy2017}
|
||||
password: ${DB_PWD:sztzjy2017}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
Loading…
Reference in New Issue