second 2021年11月1日11:24:03
parent
312073ed9f
commit
26cdee56a5
|
|
@ -10,6 +10,18 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>mystyle-cloud-file</artifactId>
|
<artifactId>mystyle-cloud-file</artifactId>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>7</source>
|
||||||
|
<target>7</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
@ -41,5 +53,16 @@
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
|
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.oschina.zcx7878</groupId>
|
||||||
|
<artifactId>fastdfs-client-java</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zhangmeng</groupId>
|
||||||
|
<artifactId>mystyle-cloud-model</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -4,10 +4,17 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangmeng
|
||||||
|
* @date 2021年11月1日11:21:28
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
|
@ComponentScan(basePackages = {"com.zhangmeng.model","com.zhangmeng.file"})
|
||||||
public class FileApplication {
|
public class FileApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,35 @@
|
||||||
package com.zhangmeng.file.controller;
|
package com.zhangmeng.file.controller;
|
||||||
|
|
||||||
import com.zhangmeng.file.feign.UserFeignService;
|
import com.zhangmeng.file.feign.UserFeignService;
|
||||||
|
import com.zhangmeng.file.service.FileService;
|
||||||
|
import com.zhangmeng.model.base.baseController.BaseController;
|
||||||
|
import com.zhangmeng.model.entity.FileInfo;
|
||||||
|
import com.zhangmeng.model.vo.Result;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangmeng
|
||||||
|
* @date 2021年11月1日11:21:28
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/file")
|
@RequestMapping("/file")
|
||||||
public class FileController {
|
public class FileController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserFeignService userFeignService;
|
private UserFeignService userFeignService;
|
||||||
|
|
||||||
@GetMapping("/name")
|
@Autowired
|
||||||
public String file_name(String name){
|
private FileService fileService;
|
||||||
return this.userFeignService.hi(name);
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result list(){
|
||||||
|
List<FileInfo> all = this.fileService.findAll();
|
||||||
|
return this.success("查询成功",all);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.zhangmeng.file.dao;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||||
|
import com.zhangmeng.model.entity.FileInfo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月8日09:46:19
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface FileInfoDao extends AbstractBaseMapper<FileInfo> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.zhangmeng.file.service;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseService.BaseService;
|
||||||
|
import com.zhangmeng.model.dto.File;
|
||||||
|
import com.zhangmeng.model.entity.FileInfo;
|
||||||
|
|
||||||
|
public interface FileService extends BaseService<FileInfo> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.zhangmeng.file.service.impl;
|
||||||
|
|
||||||
|
import com.zhangmeng.file.service.FileService;
|
||||||
|
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||||
|
import com.zhangmeng.model.dto.File;
|
||||||
|
import com.zhangmeng.model.entity.FileInfo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class FileServiceImpl extends AbstractBaseServiceImpl<FileInfo> implements FileService {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
package com.zhangmeng.file.utils;
|
||||||
|
|
||||||
|
import org.csource.common.NameValuePair;
|
||||||
|
import org.csource.fastdfs.*;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class FastDfsClient {
|
||||||
|
|
||||||
|
static {
|
||||||
|
//从classpath下获取文件对象获取路径
|
||||||
|
String path = new ClassPathResource("fastDFS.config").getPath();
|
||||||
|
try {
|
||||||
|
ClientGlobal.init(path);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片上传
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String[] upload(com.zhangmeng.model.dto.File file) {
|
||||||
|
try {
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
StorageClient storageClient = new StorageClient(trackerServer, null);
|
||||||
|
//参数1 字节数组
|
||||||
|
//参数2 扩展名(不带点)
|
||||||
|
//参数3 元数据( 文件的大小,文件的作者,文件的创建时间戳)
|
||||||
|
NameValuePair[] meta_list = new NameValuePair[]{new NameValuePair(file.getAuthor()), new NameValuePair(file.getName())};
|
||||||
|
String[] strings = storageClient.upload_file(file.getContent(), file.getExt(), meta_list);
|
||||||
|
return strings;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片下载
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @param remoteFileName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static InputStream downFile(String groupName, String remoteFileName) {
|
||||||
|
ByteArrayInputStream byteArrayInputStream = null;
|
||||||
|
try {
|
||||||
|
//3.创建trackerclient对象
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
//4.创建trackerserver 对象
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
//5.创建stroageserver 对象
|
||||||
|
//6.创建storageclient 对象
|
||||||
|
StorageClient storageClient = new StorageClient(trackerServer, null);
|
||||||
|
//7.根据组名 和 文件名 下载图片
|
||||||
|
|
||||||
|
//参数1:指定组名
|
||||||
|
//参数2 :指定远程的文件名
|
||||||
|
byte[] bytes = storageClient.download_file(groupName, remoteFileName);
|
||||||
|
byteArrayInputStream = new ByteArrayInputStream(bytes);
|
||||||
|
return byteArrayInputStream;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (byteArrayInputStream != null) {
|
||||||
|
byteArrayInputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片删除
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @param remoteFileName
|
||||||
|
*/
|
||||||
|
public static void deleteFile(String groupName, String remoteFileName) {
|
||||||
|
try {
|
||||||
|
//3.创建trackerclient对象
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
//4.创建trackerserver 对象
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
//5.创建stroageserver 对象
|
||||||
|
//6.创建storageclient 对象
|
||||||
|
StorageClient storageClient = new StorageClient(trackerServer, null);
|
||||||
|
int i = storageClient.delete_file(groupName, remoteFileName);
|
||||||
|
if (i == 0) {
|
||||||
|
System.out.println("删除成功");
|
||||||
|
} else {
|
||||||
|
System.out.println("删除失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据组名获取组的信息
|
||||||
|
|
||||||
|
public static StorageServer getStorages(String groupName) {
|
||||||
|
try {
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
//4.创建trackerserver 对象
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
|
||||||
|
//参数1 指定traqckerserver 对象
|
||||||
|
//参数2 指定组名
|
||||||
|
StorageServer group1 = trackerClient.getStoreStorage(trackerServer, groupName);
|
||||||
|
return group1;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据文件名和组名获取文件的信息
|
||||||
|
|
||||||
|
public static FileInfo getFile(String groupName, String remoteFileName) {
|
||||||
|
try {
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
//4.创建trackerserver 对象
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
|
||||||
|
StorageClient storageClient = new StorageClient(trackerServer, null);
|
||||||
|
|
||||||
|
//参数1 指定组名
|
||||||
|
//参数2 指定文件的路径
|
||||||
|
FileInfo fileInfo = storageClient.get_file_info(groupName, remoteFileName);
|
||||||
|
return fileInfo;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文件名和组名 获取组信息的数组信息
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @param remoteFileName
|
||||||
|
* @return ServerInfo[]
|
||||||
|
*/
|
||||||
|
public static ServerInfo[] getServerInfo(String groupName, String remoteFileName) {
|
||||||
|
try {
|
||||||
|
//3.创建trackerclient对象
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
//4.创建trackerserver 对象
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
|
||||||
|
ServerInfo[] group1s = trackerClient.getFetchStorages(trackerServer, groupName, remoteFileName);
|
||||||
|
return group1s;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取tracker 的ip和端口的信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getTrackerUrl() {
|
||||||
|
try {
|
||||||
|
//3.创建trackerclient对象
|
||||||
|
TrackerClient trackerClient = new TrackerClient();
|
||||||
|
//4.创建trackerserver 对象
|
||||||
|
TrackerServer trackerServer = trackerClient.getConnection();
|
||||||
|
//tracker 的ip的信息
|
||||||
|
String hostString = trackerServer.getInetSocketAddress().getHostString();
|
||||||
|
int g_tracker_http_port = ClientGlobal.getG_tracker_http_port();
|
||||||
|
return "http://" + hostString + ":" + g_tracker_http_port;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,23 @@
|
||||||
server:
|
server:
|
||||||
port: 8763
|
port: 8763
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: mystyle-cloud-file
|
name: mystyle-cloud-file
|
||||||
|
datasource:
|
||||||
|
username: root
|
||||||
|
password: root
|
||||||
|
url: jdbc:mysql://127.0.0.1:3306/mystyle-blog?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
jpa:
|
||||||
|
database: mysql
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: update
|
||||||
|
naming:
|
||||||
|
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||||
|
show-sql: true
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
dialect: org.hibernate.dialect.MySQL5Dialect
|
||||||
zipkin:
|
zipkin:
|
||||||
sender:
|
sender:
|
||||||
type: web
|
type: web
|
||||||
|
|
@ -17,3 +31,13 @@ spring:
|
||||||
nacos:
|
nacos:
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848
|
server-addr: 127.0.0.1:8848
|
||||||
|
mybatis:
|
||||||
|
type-aliases-package: com.zhangmeng.domain.blog
|
||||||
|
configuration:
|
||||||
|
mapUnderscoreToCamelCase: true
|
||||||
|
default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler
|
||||||
|
mapper:
|
||||||
|
style: normal
|
||||||
|
enum-as-simple-type: true
|
||||||
|
identity: MYSQL
|
||||||
|
check-example-entity-class: true
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
connect_timeout=60
|
||||||
|
network_timeout=60
|
||||||
|
charset=UTF-8
|
||||||
|
http.tracker_http_port=8081
|
||||||
|
tracker_server=192.168.52.165:22122
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>mystyle-cloud-parent</artifactId>
|
||||||
|
<groupId>com.zhangmeng</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mystyle-cloud-model</artifactId>
|
||||||
|
<description>实体数据相关</description>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>6</source>
|
||||||
|
<target>6</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 操作数据库-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>tk.mybatis</groupId>
|
||||||
|
<artifactId>mapper-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.zhangmeng.model.base.baseController;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.vo.Result;
|
||||||
|
import com.zhangmeng.model.vo.StatusCode;
|
||||||
|
|
||||||
|
public class BaseController extends ResponseController {
|
||||||
|
|
||||||
|
protected Result success(){
|
||||||
|
return new Result(true, StatusCode.OK,"成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Result success(String message){
|
||||||
|
return new Result(true,StatusCode.OK,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Result success(String message,Object data){
|
||||||
|
return new Result(true,StatusCode.OK,message,data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Result failure() {
|
||||||
|
return new Result(false,StatusCode.ERROR,"失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Result failure(String message) {
|
||||||
|
return new Result(false,StatusCode.ERROR,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Result failure(String message,Object data) {
|
||||||
|
return new Result(false,StatusCode.ERROR,message,data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.zhangmeng.model.base.baseController;
|
||||||
|
|
||||||
|
public class ResponseController extends ResultController{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.zhangmeng.model.base.baseController;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.vo.ResultTree;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ResultController {
|
||||||
|
|
||||||
|
protected HttpServletRequest request;
|
||||||
|
|
||||||
|
protected HttpServletResponse response;
|
||||||
|
|
||||||
|
protected HttpSession session;
|
||||||
|
|
||||||
|
@ModelAttribute
|
||||||
|
public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
|
||||||
|
this.request = request;
|
||||||
|
|
||||||
|
this.response = response;
|
||||||
|
|
||||||
|
this.session = request.getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面跳转
|
||||||
|
* */
|
||||||
|
protected ModelAndView jumpPage(String path){
|
||||||
|
ModelAndView modelAndView = new ModelAndView();
|
||||||
|
modelAndView.setViewName(path);
|
||||||
|
return modelAndView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带参数的页面跳转
|
||||||
|
* */
|
||||||
|
public ModelAndView jumpPage(String path, Map<String,?> params){
|
||||||
|
ModelAndView modelAndView = new ModelAndView();
|
||||||
|
modelAndView.setViewName(path);
|
||||||
|
modelAndView.addAllObjects(params);
|
||||||
|
return modelAndView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describe: 返回 Tree 数据
|
||||||
|
* Param data
|
||||||
|
* Return Tree数据
|
||||||
|
* */
|
||||||
|
protected static ResultTree dataTree(Object data){
|
||||||
|
ResultTree resuTree = new ResultTree();
|
||||||
|
resuTree.setData(data);
|
||||||
|
return resuTree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.zhangmeng.model.base.baseDao;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import tk.mybatis.mapper.additional.insert.InsertListMapper;
|
||||||
|
import tk.mybatis.mapper.annotation.RegisterMapper;
|
||||||
|
import tk.mybatis.mapper.common.BaseMapper;
|
||||||
|
import tk.mybatis.mapper.common.ConditionMapper;
|
||||||
|
import tk.mybatis.mapper.common.ExampleMapper;
|
||||||
|
import tk.mybatis.mapper.common.IdsMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param <T>
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020年11月13日09:55:03
|
||||||
|
*/
|
||||||
|
@RegisterMapper
|
||||||
|
public interface AbstractBaseMapper<T extends BaseEntity<Long>> extends BaseMapper<T>, ConditionMapper<T>, InsertListMapper<T>, IdsMapper<T>, ExampleMapper<T> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.zhangmeng.model.base.baseDao;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
//数据访问层
|
||||||
|
public interface JpaDataAccessObject <T extends BaseEntity<Long>> extends JpaRepository<T, Long>, JpaSpecificationExecutor<T> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.zhangmeng.model.base.baseEntity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020年11月13日09:58:11
|
||||||
|
* @param <ID>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@MappedSuperclass
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true, value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
|
||||||
|
public class BaseEntity<ID extends Serializable> implements Serializable {
|
||||||
|
|
||||||
|
@Id //主键id
|
||||||
|
@GeneratedValue(strategy= GenerationType.IDENTITY)//主键生成策略
|
||||||
|
@Column(name="id")//数据库字段名
|
||||||
|
private ID id;
|
||||||
|
|
||||||
|
@Column(name = "addTime",length = 0)
|
||||||
|
private Date addTime = new Date();
|
||||||
|
|
||||||
|
@Column(name = "updateTime",length = 0)
|
||||||
|
private Date updateTime = new Date();
|
||||||
|
|
||||||
|
@Column(name = "deleteStatus")
|
||||||
|
private Boolean deleteStatus = false;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.zhangmeng.model.base.baseService;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import com.zhangmeng.model.dto.JpaQueryData;
|
||||||
|
import com.zhangmeng.model.dto.QueryParams;
|
||||||
|
import com.zhangmeng.model.dto.QueryResult;
|
||||||
|
import com.zhangmeng.model.dto.QuerySingleParams;
|
||||||
|
import com.zhangmeng.model.vo.Result;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
import tk.mybatis.mapper.entity.Condition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param <T>
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020年11月13日09:55:45
|
||||||
|
*/
|
||||||
|
public interface BaseService<T extends BaseEntity<Long>> {
|
||||||
|
|
||||||
|
public void save(T model);//持久化
|
||||||
|
|
||||||
|
public void save(List<T> models);//批量持久化
|
||||||
|
|
||||||
|
public void deleteById(Long id);//通过主鍵刪除
|
||||||
|
|
||||||
|
public void deleteByIds(String ids);//批量刪除 eg:ids -> “1,2,3,4”
|
||||||
|
|
||||||
|
public void update(T model);//更新
|
||||||
|
|
||||||
|
public T findById(Long id);//通过ID查找
|
||||||
|
|
||||||
|
public List<T> findByObj(T t);
|
||||||
|
|
||||||
|
public List<T> findByIds(String ids);//通过多个ID查找//eg:ids -> “1,2,3,4”
|
||||||
|
|
||||||
|
public List<T> findByCondition(Condition condition);//根据条件查找
|
||||||
|
|
||||||
|
public List<T> findAll();//获取所有
|
||||||
|
|
||||||
|
public List<T> findAll(QueryParams queryParams);
|
||||||
|
|
||||||
|
public List<Map<String, Object>> query(String sql);
|
||||||
|
|
||||||
|
public List<T> findByCondition(QueryParams queryParams);
|
||||||
|
|
||||||
|
public Integer selectCountByCondition(Condition condition);
|
||||||
|
|
||||||
|
public Integer selectCountEq(String key, Object value);
|
||||||
|
|
||||||
|
public PageInfo<T> findByCondition(QueryParams queryParams, boolean isPageInfo);
|
||||||
|
|
||||||
|
public List<T> findBySingleParams(@NonNull QuerySingleParams querySingleParams);
|
||||||
|
|
||||||
|
public List<T> findByParams(List<QuerySingleParams> querySingleParamsList);
|
||||||
|
|
||||||
|
public List<T> findByMapWithEq(Map<String, Object> map);
|
||||||
|
|
||||||
|
public Result<T> findByByConditionWithResult(QueryParams queryParams);
|
||||||
|
|
||||||
|
public QueryResult<T> findByCondition(QueryParams QueryParams, boolean isPageInfo, boolean isQueryResult);
|
||||||
|
|
||||||
|
public T jpa_findById(Long id);
|
||||||
|
|
||||||
|
public List<T> jpa_findByCondition(List<JpaQueryData> jpaQueryDataList);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,368 @@
|
||||||
|
package com.zhangmeng.model.base.baseService.impl;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.zhangmeng.model.base.baseDao.AbstractBaseMapper;
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import com.zhangmeng.model.base.baseService.BaseService;
|
||||||
|
import com.zhangmeng.model.dto.JpaQueryData;
|
||||||
|
import com.zhangmeng.model.dto.QueryParams;
|
||||||
|
import com.zhangmeng.model.dto.QueryResult;
|
||||||
|
import com.zhangmeng.model.dto.QuerySingleParams;
|
||||||
|
import com.zhangmeng.model.vo.Result;
|
||||||
|
import com.zhangmeng.model.vo.StatusCode;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import tk.mybatis.mapper.entity.Condition;
|
||||||
|
import tk.mybatis.mapper.entity.Example;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param <T>
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020年11月13日09:56:22
|
||||||
|
*/
|
||||||
|
public abstract class AbstractBaseServiceImpl<T extends BaseEntity<Long>> implements BaseService<T> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AbstractBaseMapper<T> baseDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
private final Class<T> modelClass;
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public AbstractBaseServiceImpl() {
|
||||||
|
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
|
||||||
|
modelClass = (Class<T>) pt.getActualTypeArguments()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(T model) {
|
||||||
|
this.baseDao.insert(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(List<T> models) {
|
||||||
|
this.baseDao.insertList(models);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteById(Long id) {
|
||||||
|
this.baseDao.deleteByPrimaryKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteByIds(String ids) {
|
||||||
|
this.baseDao.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(T model) {
|
||||||
|
this.baseDao.updateByPrimaryKeySelective(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T findById(Long id) {
|
||||||
|
return this.baseDao.selectByPrimaryKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> findByIds(String ids) {
|
||||||
|
return this.baseDao.selectByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> findByCondition(Condition condition) {
|
||||||
|
return this.baseDao.selectByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> findAll() {
|
||||||
|
return this.baseDao.selectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> findAll(QueryParams queryParams) {
|
||||||
|
if (queryParams != null) {
|
||||||
|
PageHelper.startPage(queryParams.getPageNum(), queryParams.getPageSize(), queryParams.getOrderBy());
|
||||||
|
List<T> list = this.baseDao.selectAll();
|
||||||
|
PageInfo<T> pageInfo = new PageInfo<>(list);
|
||||||
|
return pageInfo.getList();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> query(String sql) {
|
||||||
|
return this.jdbcTemplate.queryForList(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer selectCountByCondition(Condition condition) {
|
||||||
|
return this.baseDao.selectCountByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer selectCountEq(String key, Object value) {
|
||||||
|
Condition condition = new Condition(modelClass);
|
||||||
|
Example.Criteria criteria = condition.createCriteria();
|
||||||
|
criteria.andEqualTo(key, value);
|
||||||
|
return this.selectCountByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<T> findByCondition(QueryParams QueryParams) {
|
||||||
|
return (List<T>) findByParams(QueryParams, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
*
|
||||||
|
* @param QueryParams 查询参数
|
||||||
|
* @param isPageInfo 是否返回分页对象
|
||||||
|
* @return obj
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public PageInfo<T> findByCondition(QueryParams QueryParams, boolean isPageInfo) {
|
||||||
|
return (PageInfo<T>) findByParams(QueryParams, isPageInfo, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public QueryResult<T> findByCondition(QueryParams QueryParams, boolean isPageInfo, boolean isQueryResult) {
|
||||||
|
return (QueryResult<T>) findByParams(QueryParams, isPageInfo, isQueryResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据单个参数查询
|
||||||
|
*
|
||||||
|
* @return List<T>
|
||||||
|
*/
|
||||||
|
public List<T> findBySingleParams(QuerySingleParams querySingleParams) {
|
||||||
|
Condition condition = new Condition(modelClass);
|
||||||
|
Example.Criteria criteria = condition.createCriteria();
|
||||||
|
if (querySingleParams != null) {
|
||||||
|
String key = querySingleParams.getKey();
|
||||||
|
Object value = querySingleParams.getValue();
|
||||||
|
QuerySingleParams.Type type = querySingleParams.getType();
|
||||||
|
switch (type) {
|
||||||
|
case equal:
|
||||||
|
criteria.andEqualTo(key, value);
|
||||||
|
break;
|
||||||
|
case not_equal:
|
||||||
|
criteria.andNotEqualTo(key, value);
|
||||||
|
break;
|
||||||
|
case like:
|
||||||
|
criteria.andLike(key, "%" + value + "%");
|
||||||
|
break;
|
||||||
|
case not_like:
|
||||||
|
criteria.andNotLike(key, "%" + value + "%");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.baseDao.selectByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据参数查询
|
||||||
|
*
|
||||||
|
* @return List<T>
|
||||||
|
*/
|
||||||
|
public List<T> findByParams(List<QuerySingleParams> querySingleParamsList) {
|
||||||
|
Condition condition = new Condition(modelClass);
|
||||||
|
Example.Criteria criteria = condition.createCriteria();
|
||||||
|
if (querySingleParamsList.size() > 0) {
|
||||||
|
for (QuerySingleParams querySingleParams : querySingleParamsList) {
|
||||||
|
if (querySingleParams != null) {
|
||||||
|
String key = querySingleParams.getKey();
|
||||||
|
Object value = querySingleParams.getValue();
|
||||||
|
QuerySingleParams.Type type = querySingleParams.getType();
|
||||||
|
switch (type) {
|
||||||
|
case equal:
|
||||||
|
criteria.andEqualTo(key, value);
|
||||||
|
break;
|
||||||
|
case not_equal:
|
||||||
|
criteria.andNotEqualTo(key, value);
|
||||||
|
break;
|
||||||
|
case like:
|
||||||
|
criteria.andLike(key, "%" + value + "%");
|
||||||
|
break;
|
||||||
|
case not_like:
|
||||||
|
criteria.andNotLike(key, "%" + value + "%");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.baseDao.selectByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> findByMapWithEq(Map<String, Object> map) {
|
||||||
|
Condition condition = new Condition(modelClass);
|
||||||
|
Example.Criteria criteria = condition.createCriteria();
|
||||||
|
criteria.andEqualTo(map);
|
||||||
|
return this.baseDao.selectByCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> findByObj(T t) {
|
||||||
|
return this.baseDao.select(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<T> findByByConditionWithResult(QueryParams queryParams) {
|
||||||
|
PageInfo pageInfo = this.findByCondition(queryParams, true);
|
||||||
|
return new Result<>(true, StatusCode.OK, null, pageInfo.getTotal(), pageInfo.getList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object findByParams(QueryParams QueryParams, boolean isPageInfo, boolean isQueryResult) {
|
||||||
|
PageInfo<T> pageInfo = null;
|
||||||
|
|
||||||
|
if (QueryParams.getPageNum() == null) {
|
||||||
|
QueryParams.setPageNum(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QueryParams.getPageSize() == null) {
|
||||||
|
QueryParams.setPageSize(10);
|
||||||
|
}
|
||||||
|
if (isNotNull(QueryParams.getOrderBy())) {
|
||||||
|
pageInfo = pageHelper(QueryParams.getPageNum(), QueryParams.getPageSize(), QueryParams.getOrderBy(), QueryParams.getCondition());
|
||||||
|
} else {
|
||||||
|
pageInfo = pageHelper(QueryParams.getPageNum(), QueryParams.getPageSize(), QueryParams.getCondition());
|
||||||
|
}
|
||||||
|
if (isQueryResult) {
|
||||||
|
return page_params_response(pageInfo);
|
||||||
|
}
|
||||||
|
if (isPageInfo) {
|
||||||
|
return pageInfo;
|
||||||
|
}
|
||||||
|
return pageInfo.getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 每页记录数
|
||||||
|
* @param condition 查询条件
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
private PageInfo<T> pageHelper(Integer pageNum, Integer pageSize, Condition condition) {
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
List<T> ts = this.baseDao.selectByCondition(condition);
|
||||||
|
return new PageInfo<>(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 每页记录数
|
||||||
|
* @param orderBy 排序
|
||||||
|
* @param condition 查询条件
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
private PageInfo<T> pageHelper(Integer pageNum, Integer pageSize, String orderBy, Condition condition) {
|
||||||
|
PageHelper.startPage(pageNum, pageSize, orderBy);
|
||||||
|
List<T> ts = this.baseDao.selectByCondition(condition);
|
||||||
|
return new PageInfo<>(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T jpa_findById(Long id) {
|
||||||
|
SimpleJpaRepository<T, Long> jpaRepository = new SimpleJpaRepository<>(modelClass, entityManager);
|
||||||
|
return jpaRepository.getOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> jpa_findByCondition(List<JpaQueryData> jpaQueryDataList) {
|
||||||
|
SimpleJpaRepository<T, Long> jpaRepository = new SimpleJpaRepository<>(modelClass, entityManager);
|
||||||
|
Specification<T> spec = spec(jpaQueryDataList);
|
||||||
|
return jpaRepository.findAll(spec);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Specification<T> spec(List<JpaQueryData> jpaQueryDataList) {
|
||||||
|
|
||||||
|
return new Specification<T>() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param root 对查询对象属性的封装
|
||||||
|
* @param criteriaQuery 封装了我们要执行的查询中的各个部分的信息,select from order
|
||||||
|
* @param criteriaBuilder 查询条件的构造器
|
||||||
|
* @return Predicate
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
||||||
|
|
||||||
|
List<Predicate> list = new ArrayList<>();
|
||||||
|
if (jpaQueryDataList.size() > 0) {
|
||||||
|
for (JpaQueryData jpaQueryData : jpaQueryDataList) {
|
||||||
|
String key = jpaQueryData.getKey();
|
||||||
|
Object value = jpaQueryData.getValue();
|
||||||
|
JpaQueryData.Condition condition = jpaQueryData.getCondition();
|
||||||
|
switch (condition) {
|
||||||
|
case like:
|
||||||
|
list.add(criteriaBuilder.like(root.get(key), "%" + value + "%"));
|
||||||
|
break;
|
||||||
|
case equal:
|
||||||
|
list.add(criteriaBuilder.equal(root.get(key), value));
|
||||||
|
break;
|
||||||
|
case between:
|
||||||
|
JpaQueryData.Between between = jpaQueryData.getBetween();
|
||||||
|
Object var1 = between.getVar1();
|
||||||
|
Object var2 = between.getVar2();
|
||||||
|
|
||||||
|
if (var1 instanceof String) {
|
||||||
|
list.add(criteriaBuilder.between(root.get(key), var1.toString(), var2.toString()));
|
||||||
|
} else if (var1 instanceof Date) {
|
||||||
|
list.add(criteriaBuilder.between(root.get(key), (Date) var1, (Date) var2));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Predicate[] arr = new Predicate[list.size()];
|
||||||
|
return criteriaBuilder.and(list.toArray(arr));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNotNull(Object object) {
|
||||||
|
return object != null && !"".equals(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> QueryResult<T> page_params_response(PageInfo<T> pageInfo) {
|
||||||
|
QueryResult<T> queryResult = new QueryResult<>();
|
||||||
|
queryResult.setPageNum(pageInfo.getPageNum());
|
||||||
|
queryResult.setPageSize(pageInfo.getPageSize());
|
||||||
|
if (pageInfo.getPrePage() == 0 ){
|
||||||
|
queryResult.setPrevPage(1);
|
||||||
|
}else {
|
||||||
|
queryResult.setPrevPage(pageInfo.getPrePage());
|
||||||
|
}
|
||||||
|
if (pageInfo.getNextPage() == 0 ){
|
||||||
|
queryResult.setNextPage(1);
|
||||||
|
}else {
|
||||||
|
queryResult.setNextPage(pageInfo.getNextPage());
|
||||||
|
}
|
||||||
|
queryResult.setList(pageInfo.getList());
|
||||||
|
queryResult.setCount(pageInfo.getTotal());
|
||||||
|
return queryResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.zhangmeng.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class File implements Serializable {
|
||||||
|
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private byte[] content;
|
||||||
|
|
||||||
|
private String ext;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.zhangmeng.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jpa 查询条件封装
|
||||||
|
*
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年6月17日14:33:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class JpaQueryData implements Serializable {
|
||||||
|
|
||||||
|
public enum Condition {
|
||||||
|
between,
|
||||||
|
like,
|
||||||
|
equal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String key; //字段
|
||||||
|
|
||||||
|
private Object value; //值
|
||||||
|
|
||||||
|
private Condition condition; //条件
|
||||||
|
|
||||||
|
private Between between;
|
||||||
|
|
||||||
|
public static class Between {
|
||||||
|
|
||||||
|
private Object var1;
|
||||||
|
|
||||||
|
private Object var2;
|
||||||
|
|
||||||
|
public Object getVar1() {
|
||||||
|
return var1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVar1(Object var1) {
|
||||||
|
this.var1 = var1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getVar2() {
|
||||||
|
return var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVar2(Object var2) {
|
||||||
|
this.var2 = var2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.zhangmeng.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import tk.mybatis.mapper.entity.Condition;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QueryParams implements Serializable {
|
||||||
|
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
private Condition condition;
|
||||||
|
|
||||||
|
private String orderBy;
|
||||||
|
|
||||||
|
public QueryParams(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 每页记录数
|
||||||
|
* @param orderBy 排序
|
||||||
|
*/
|
||||||
|
public QueryParams(Integer pageNum, Integer pageSize, String orderBy) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
this.orderBy = orderBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryParams(Condition condition) {
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 每页记录数
|
||||||
|
* @param condition 查询条件
|
||||||
|
*/
|
||||||
|
public QueryParams(Integer pageNum, Integer pageSize, Condition condition) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pageNum 当前页
|
||||||
|
* @param pageSize 每页记录数
|
||||||
|
* @param condition 查询条件
|
||||||
|
* @param orderBy 排序
|
||||||
|
*/
|
||||||
|
public QueryParams(Integer pageNum, Integer pageSize, Condition condition, String orderBy) {
|
||||||
|
this.pageNum = pageNum;
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
this.condition = condition;
|
||||||
|
this.orderBy = orderBy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.zhangmeng.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QueryResult<T> implements Serializable {
|
||||||
|
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
private Integer prevPage;
|
||||||
|
|
||||||
|
private Integer nextPage;
|
||||||
|
|
||||||
|
private List<T> list;
|
||||||
|
|
||||||
|
private Long count;
|
||||||
|
|
||||||
|
private Object extend;//扩展参数
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.zhangmeng.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单个查询参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class QuerySingleParams implements Serializable {
|
||||||
|
|
||||||
|
public enum Type{
|
||||||
|
equal,
|
||||||
|
not_equal,
|
||||||
|
not_like,
|
||||||
|
like;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
private Object value;
|
||||||
|
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
private String orderBy;
|
||||||
|
|
||||||
|
public QuerySingleParams(String key, Object value, Type type) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuerySingleParams(String key, Object value, Type type, String orderBy) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
this.type = type;
|
||||||
|
this.orderBy = orderBy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.zhangmeng.model.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 转身的背影在心底里沉沦
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021/9/8 22:23
|
||||||
|
*/
|
||||||
|
public class RequestData {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月7日17:44:40
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "file_info")
|
||||||
|
public class FileInfo extends BaseEntity<Long> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储类型
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum StorageType{
|
||||||
|
LocalStorage("本地"),
|
||||||
|
FastDFS("fastDFS");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private StorageType(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传的类型
|
||||||
|
*/
|
||||||
|
public enum UploadType {
|
||||||
|
|
||||||
|
images("图片"),
|
||||||
|
video("视频"),
|
||||||
|
audio("视频");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private UploadType(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件的格式
|
||||||
|
*/
|
||||||
|
public enum FileType {
|
||||||
|
jpeg("图片"),
|
||||||
|
jpg("图片"),
|
||||||
|
png("图片"),
|
||||||
|
bmp("图片"),
|
||||||
|
gif("图片"),
|
||||||
|
svg("图片"),
|
||||||
|
mp4("视频"),
|
||||||
|
avi("视频"),
|
||||||
|
flv("视频");
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private FileType(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UploadType uploadType;//上传类型
|
||||||
|
|
||||||
|
private StorageType storageType;
|
||||||
|
|
||||||
|
private String path;//上传的路径
|
||||||
|
|
||||||
|
private String fullPath;//上传的真实全路径
|
||||||
|
|
||||||
|
private Integer imageWidth;//上传图片的宽度
|
||||||
|
|
||||||
|
private Integer imageHeight;//上传图片的高度
|
||||||
|
|
||||||
|
private String videoImages;//视频的封面
|
||||||
|
|
||||||
|
private Integer videoImagesWidth;//视频封面的宽
|
||||||
|
|
||||||
|
private Integer videoImagesHeight;//视频封面的高
|
||||||
|
|
||||||
|
private Long duration;//时长
|
||||||
|
|
||||||
|
private String fileTypeString;//文件格式字符传
|
||||||
|
|
||||||
|
private FileType fileType;
|
||||||
|
|
||||||
|
private Long size;//文件的大小
|
||||||
|
|
||||||
|
private String fileSize;//文件大小
|
||||||
|
|
||||||
|
private String md5;//md5
|
||||||
|
|
||||||
|
private String originalFileName;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String ext;//文件扩展名
|
||||||
|
|
||||||
|
private String author;//文件创建作者
|
||||||
|
|
||||||
|
private Long user_id;
|
||||||
|
|
||||||
|
private Long image_info_expand_id;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月7日11:38:42
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "permission")
|
||||||
|
public class Permission extends BaseEntity<Long> {
|
||||||
|
|
||||||
|
public enum Status{
|
||||||
|
show("显示"),
|
||||||
|
hidden("隐藏");
|
||||||
|
private String description;//描述
|
||||||
|
|
||||||
|
Status(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum Type{
|
||||||
|
CATALOG("目录"),
|
||||||
|
MENU("菜单"),
|
||||||
|
BUTTON("按钮");
|
||||||
|
private String description;//描述
|
||||||
|
|
||||||
|
Type(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String,Object>> valueListMap(){
|
||||||
|
Type[] values = Type.values();
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (Type value : values) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String description = value.getDescription();
|
||||||
|
map.put("description",description);
|
||||||
|
map.put("value",value);
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
private String href;
|
||||||
|
|
||||||
|
private String openType;
|
||||||
|
|
||||||
|
private Long parent_id;
|
||||||
|
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String checkArr = "0";
|
||||||
|
|
||||||
|
private Integer sort;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月7日17:44:40
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "role")
|
||||||
|
public class Role extends BaseEntity<Long> {
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
|
||||||
|
Super_Administrator("超级管理员") ,//超级管理员
|
||||||
|
Administrator("管理员"),//管理员
|
||||||
|
User("用户");//用户
|
||||||
|
|
||||||
|
private String description;//描述
|
||||||
|
|
||||||
|
Type(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String,Object>> enumListMap(){
|
||||||
|
Type[] values = Type.values();
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (Type value : values) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String description = value.getDescription();
|
||||||
|
map.put("description",description);
|
||||||
|
map.put("value",value);
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
|
||||||
|
Enable("开启") ,
|
||||||
|
DisEnable("关闭");
|
||||||
|
|
||||||
|
private String description;//描述
|
||||||
|
|
||||||
|
Status(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String,Object>> enumListMap(){
|
||||||
|
Status[] values = Status.values();
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (Status value : values) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String description = value.getDescription();
|
||||||
|
map.put("description",description);
|
||||||
|
map.put("value",value);
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String roleName;
|
||||||
|
|
||||||
|
private String roleCode;
|
||||||
|
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
private Long createUserId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月7日11:38:42
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "role_permission")
|
||||||
|
public class RolePermission extends BaseEntity<Long> {
|
||||||
|
private Long role_id;
|
||||||
|
private Long permission_id;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月7日11:38:42
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "user")
|
||||||
|
public class User extends BaseEntity<Long> {
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
DISABLED("已停用"),
|
||||||
|
VALID("正常"),
|
||||||
|
LOCKED("锁定");
|
||||||
|
|
||||||
|
Status(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String description;//描述
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String,Object>> enumListMap(){
|
||||||
|
Status[] values = Status.values();
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (Status value : values) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String description = value.getDescription();
|
||||||
|
map.put("description",description);
|
||||||
|
map.put("value",value);
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum Gender {
|
||||||
|
male("男"),
|
||||||
|
female("女");
|
||||||
|
|
||||||
|
Gender(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String description;//描述
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String,Object>> enumListMap(){
|
||||||
|
Gender[] values = Gender.values();
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (Gender value : values) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String description = value.getDescription();
|
||||||
|
map.put("description",description);
|
||||||
|
map.put("value",value);
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "longtext")
|
||||||
|
private String sign;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private String name;//姓名
|
||||||
|
|
||||||
|
private String nickname;//昵称
|
||||||
|
|
||||||
|
private String profession;//职业
|
||||||
|
|
||||||
|
private String qq;
|
||||||
|
|
||||||
|
private String telephone;
|
||||||
|
|
||||||
|
private Date birthday;
|
||||||
|
|
||||||
|
private Gender gender;//性别
|
||||||
|
|
||||||
|
private String remarks;//备注
|
||||||
|
|
||||||
|
private Role.Type roleType;//角色类型
|
||||||
|
|
||||||
|
private Long photo_id;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhengmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021年1月7日11:38:42
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "user_role")
|
||||||
|
public class UserRole extends BaseEntity<Long> {
|
||||||
|
|
||||||
|
private Long user_id;
|
||||||
|
private Long role_id;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.zhangmeng.model.entity;
|
||||||
|
|
||||||
|
import com.zhangmeng.model.base.baseEntity.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码
|
||||||
|
*
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2021/4/1 21:29
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Table(name = "verification_code")
|
||||||
|
public class VerificationCode extends BaseEntity<Long> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
public enum Type{
|
||||||
|
/**
|
||||||
|
* 手机
|
||||||
|
*/
|
||||||
|
mobile("手机"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网页
|
||||||
|
*/
|
||||||
|
pc("web");
|
||||||
|
|
||||||
|
Type(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
//描述
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
public enum Status{
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
*/
|
||||||
|
login("登录"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
*/
|
||||||
|
register("注册");
|
||||||
|
|
||||||
|
Status(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
private Status status;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String telephone;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.zhangmeng.model.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020年11月13日09:59:13
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -212536912267261005L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否成功
|
||||||
|
*/
|
||||||
|
private boolean flag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回码
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回消息
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private long count;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回数据
|
||||||
|
*/
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static Result error(String message) {
|
||||||
|
return new Result(false,StatusCode.ERROR,message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(long count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Result() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(boolean flag, Integer code) {
|
||||||
|
this.flag = flag;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(boolean flag, Integer code, String message) {
|
||||||
|
this.flag = flag;
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(Integer code, String message, Object data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = (T)data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(boolean flag, Integer code, String message, Object data) {
|
||||||
|
this.flag = flag;
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = (T) data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(boolean flag, Integer code, String message, long count, Object data){
|
||||||
|
this.flag = flag;
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = (T)data;
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFlag() {
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlag(boolean flag) {
|
||||||
|
this.flag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(Object data) {
|
||||||
|
this.data = (T)data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.zhangmeng.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ResultTree {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态信息
|
||||||
|
* */
|
||||||
|
private Status status = new Status();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回数据
|
||||||
|
* */
|
||||||
|
private Object data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所需内部类
|
||||||
|
* */
|
||||||
|
@Data
|
||||||
|
public static class Status{
|
||||||
|
|
||||||
|
private Integer code = 200;
|
||||||
|
|
||||||
|
private String message = "默认";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.zhangmeng.model.vo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zhangmeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020年11月13日09:59:37
|
||||||
|
*/
|
||||||
|
public class StatusCode implements Serializable {
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int OK = 2001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int ERROR = 1001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传成功
|
||||||
|
*/
|
||||||
|
public static final int FILE_UPLOAD_SUCCESS = 3001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传失败
|
||||||
|
*/
|
||||||
|
public static final int FILE_UPLOAD_ERROR = 3002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件已经存在,秒传 exist
|
||||||
|
*/
|
||||||
|
public static final int FILE_UPLOAD_EXIST = 3003;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传注册 register
|
||||||
|
*/
|
||||||
|
public static final int FILE_UPLOAD_REGISTER = 3004;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求的数据格式不符!
|
||||||
|
*/
|
||||||
|
public static final int BODY_NOT_MATCH = 4000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求的数字签名不匹配!
|
||||||
|
*/
|
||||||
|
public static final int SIGNATURE_NOT_MATCH = 4001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未找到该资源
|
||||||
|
*/
|
||||||
|
public static final int NOT_FOUND = 4004;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器内部错误!
|
||||||
|
*/
|
||||||
|
public static final int INTERNAL_SERVER_ERROR= 5000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务器正忙,请稍后再试!
|
||||||
|
*/
|
||||||
|
public static final int SERVER_BUSY = 5003;
|
||||||
|
|
||||||
|
}
|
||||||
40
pom.xml
40
pom.xml
|
|
@ -8,10 +8,23 @@
|
||||||
<artifactId>mystyle-cloud-parent</artifactId>
|
<artifactId>mystyle-cloud-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>7</source>
|
||||||
|
<target>7</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
<modules>
|
<modules>
|
||||||
<module>mystyle-cloud-user</module>
|
<module>mystyle-cloud-user</module>
|
||||||
<module>mystyle-cloud-file</module>
|
<module>mystyle-cloud-file</module>
|
||||||
<module>mystyle-cloud-gateway</module>
|
<module>mystyle-cloud-gateway</module>
|
||||||
|
<module>mystyle-cloud-model</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
@ -19,6 +32,10 @@
|
||||||
<spring-boot.version>2.4.4</spring-boot.version>
|
<spring-boot.version>2.4.4</spring-boot.version>
|
||||||
<spring-cloud.version>2020.0.2</spring-cloud.version>
|
<spring-cloud.version>2020.0.2</spring-cloud.version>
|
||||||
<spring-cloud-alibaba.version>2020.0.RC1</spring-cloud-alibaba.version>
|
<spring-cloud-alibaba.version>2020.0.RC1</spring-cloud-alibaba.version>
|
||||||
|
<tk.mapper.version>2.1.5</tk.mapper.version>
|
||||||
|
<pagehelper.version>1.3.0</pagehelper.version>
|
||||||
|
<fastdfs-client-java.version>1.27.0.0</fastdfs-client-java.version>
|
||||||
|
<jackson.version>2.9.7</jackson.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
@ -47,6 +64,29 @@
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>tk.mybatis</groupId>
|
||||||
|
<artifactId>mapper-spring-boot-starter</artifactId>
|
||||||
|
<version>${tk.mapper.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!--分页-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>${pagehelper.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.oschina.zcx7878</groupId>
|
||||||
|
<artifactId>fastdfs-client-java</artifactId>
|
||||||
|
<version>${fastdfs-client-java.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
</project>
|
</project>
|
||||||
Loading…
Reference in New Issue