数字化大屏初始化
This commit is contained in:
15
src/main/java/cn/com/GogoApplication.java
Normal file
15
src/main/java/cn/com/GogoApplication.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package cn.com;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("cn.com.v2.mapper")
|
||||
public class GogoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GogoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
13
src/main/java/cn/com/ServletInitializer.java
Normal file
13
src/main/java/cn/com/ServletInitializer.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package cn.com;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(GogoApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
118
src/main/java/cn/com/v2/common/base/BaseController.java
Normal file
118
src/main/java/cn/com/v2/common/base/BaseController.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package cn.com.v2.common.base;
|
||||
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
|
||||
import cn.com.v2.common.domain.AjaxResult;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* web层通用数据处理
|
||||
*
|
||||
* @ClassName: BaseController
|
||||
* @author fuce
|
||||
* @date 2018年8月18日
|
||||
*
|
||||
*/
|
||||
|
||||
public class BaseController {
|
||||
|
||||
/**
|
||||
* 将前台传递过来的日期格式的字符串,自动转化为Date类型
|
||||
*/
|
||||
@InitBinder
|
||||
public void initBinder(WebDataBinder binder) {
|
||||
// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// dateFormat.setLenient(false);
|
||||
binder.registerCustomEditor(Date.class, new MyDateEditor());
|
||||
}
|
||||
|
||||
private class MyDateEditor extends PropertyEditorSupport {
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
// 通过两次异常的处理可以,绑定两次日期的格式
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = null;
|
||||
try {
|
||||
date = format.parse(text);
|
||||
} catch (ParseException e) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
date = format.parse(text);
|
||||
} catch (ParseException e1) {
|
||||
format = new SimpleDateFormat("yyyy/MM/dd H:mm");
|
||||
try {
|
||||
date = format.parse(text);
|
||||
} catch (ParseException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
setValue(date);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应返回结果
|
||||
*
|
||||
* @param rows 影响行数
|
||||
* @return 操作结果
|
||||
*/
|
||||
protected AjaxResult toAjax(int rows) {
|
||||
return rows > 0 ? success() : error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功
|
||||
*/
|
||||
public AjaxResult success() {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*/
|
||||
public AjaxResult error() {
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
public AjaxResult successData(int code, Object value) {
|
||||
AjaxResult json = new AjaxResult();
|
||||
json.put("code", code);
|
||||
json.put("data", value);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*/
|
||||
public AjaxResult success(String message) {
|
||||
return AjaxResult.success(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*/
|
||||
public AjaxResult error(String message) {
|
||||
return AjaxResult.error(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误码消息
|
||||
*/
|
||||
public AjaxResult error(int code, String message) {
|
||||
return AjaxResult.error(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回object数据
|
||||
*/
|
||||
public AjaxResult retobject(int code, Object data) {
|
||||
return AjaxResult.successData(code, data);
|
||||
}
|
||||
|
||||
}
|
||||
24
src/main/java/cn/com/v2/common/config/CorsConfig.java
Normal file
24
src/main/java/cn/com/v2/common/config/CorsConfig.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.com.v2.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
//重写WebMvcConfigurer实现全局跨域配置
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer{
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
// 是否发送Cookie
|
||||
.allowCredentials(true)
|
||||
// 放行哪些原始域
|
||||
.allowedOrigins("*")
|
||||
// 放行哪些请求方式
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE")
|
||||
// 放行哪些原始请求头部信息
|
||||
.allowedHeaders("*")
|
||||
// 暴露哪些头部信息
|
||||
.exposedHeaders("*");
|
||||
}
|
||||
}
|
||||
20
src/main/java/cn/com/v2/common/config/MybatisPlusConfig.java
Normal file
20
src/main/java/cn/com/v2/common/config/MybatisPlusConfig.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package cn.com.v2.common.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
/**
|
||||
* 新的分页插件,一缓和二缓遵循mybatis的规则,
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQLITE));
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
72
src/main/java/cn/com/v2/common/config/V2Config.java
Normal file
72
src/main/java/cn/com/v2/common/config/V2Config.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package cn.com.v2.common.config;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 读取项目相关配置
|
||||
*
|
||||
* @author fuce
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "v2")
|
||||
public class V2Config {
|
||||
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
private String fileurl;
|
||||
/**
|
||||
* 请求url
|
||||
*/
|
||||
private String httpurl;
|
||||
/**
|
||||
* 虚拟路径map
|
||||
*/
|
||||
private Map<String, String> xnljmap;
|
||||
|
||||
/**
|
||||
* 默认文件格式
|
||||
*/
|
||||
private String defaultFormat;
|
||||
|
||||
|
||||
public String getFileurl() {
|
||||
return fileurl;
|
||||
}
|
||||
|
||||
public void setFileurl(String fileurl) {
|
||||
this.fileurl = fileurl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getHttpurl() {
|
||||
return httpurl;
|
||||
}
|
||||
|
||||
public void setHttpurl(String httpurl) {
|
||||
this.httpurl = httpurl;
|
||||
}
|
||||
|
||||
public Map<String, String> getXnljmap() {
|
||||
return xnljmap;
|
||||
}
|
||||
|
||||
public void setXnljmap(Map<String, String> xnljmap) {
|
||||
this.xnljmap = xnljmap;
|
||||
}
|
||||
|
||||
public String getDefaultFormat() {
|
||||
return defaultFormat;
|
||||
}
|
||||
|
||||
public void setDefaultFormat(String defaultFormat) {
|
||||
this.defaultFormat = defaultFormat;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
104
src/main/java/cn/com/v2/common/domain/AjaxResult.java
Normal file
104
src/main/java/cn/com/v2/common/domain/AjaxResult.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package cn.com.v2.common.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @ClassName: AjaxResult
|
||||
* @Description: ajax操作消息提醒
|
||||
* @author fuce
|
||||
* @date 2018年8月18日
|
||||
*
|
||||
*/
|
||||
public class AjaxResult extends HashMap<String, Object>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 初始化一个新创建的 Message 对象
|
||||
*/
|
||||
public AjaxResult()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error()
|
||||
{
|
||||
return error(500, "操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @param msg 内容
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error(String msg)
|
||||
{
|
||||
return error(500, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @param code 错误码
|
||||
* @param msg 内容
|
||||
* @return 错误消息
|
||||
*/
|
||||
public static AjaxResult error(int code, String msg)
|
||||
{
|
||||
AjaxResult json = new AjaxResult();
|
||||
json.put("code", code);
|
||||
json.put("msg", msg);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @param msg 内容
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success(String msg)
|
||||
{
|
||||
AjaxResult json = new AjaxResult();
|
||||
json.put("msg", msg);
|
||||
json.put("code", 200);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success()
|
||||
{
|
||||
return AjaxResult.success("操作成功");
|
||||
}
|
||||
|
||||
public static AjaxResult successData(int code, Object value){
|
||||
AjaxResult json = new AjaxResult();
|
||||
json.put("code", code);
|
||||
json.put("data", value);
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @param key 键值
|
||||
* @param value 内容
|
||||
* @return 成功消息
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult put(String key, Object value)
|
||||
{
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
84
src/main/java/cn/com/v2/common/domain/ResultTable.java
Normal file
84
src/main/java/cn/com/v2/common/domain/ResultTable.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package cn.com.v2.common.domain;
|
||||
|
||||
public class ResultTable {
|
||||
/**
|
||||
* 状态码
|
||||
* */
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 提示消息
|
||||
* */
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 消息总量
|
||||
* */
|
||||
private Long count;
|
||||
|
||||
/**
|
||||
* 数据对象
|
||||
* */
|
||||
private Object data;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public Long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(Long count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构 建
|
||||
* */
|
||||
public static ResultTable pageTable(long count,Object data){
|
||||
ResultTable resultTable = new ResultTable();
|
||||
resultTable.setData(data);
|
||||
resultTable.setCode(0);
|
||||
resultTable.setCount(count);
|
||||
if(data!=null) {
|
||||
resultTable.setMsg("获取成功");
|
||||
}else {
|
||||
resultTable.setMsg("获取失败");
|
||||
}
|
||||
return resultTable;
|
||||
}
|
||||
|
||||
public static ResultTable dataTable(Object data){
|
||||
ResultTable resultTable = new ResultTable();
|
||||
resultTable.setData(data);
|
||||
resultTable.setCode(0);
|
||||
if(data!=null) {
|
||||
resultTable.setMsg("获取成功");
|
||||
}else {
|
||||
resultTable.setMsg("获取失败");
|
||||
}
|
||||
|
||||
return resultTable;
|
||||
}
|
||||
}
|
||||
50
src/main/java/cn/com/v2/common/domain/Tablepar.java
Normal file
50
src/main/java/cn/com/v2/common/domain/Tablepar.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package cn.com.v2.common.domain;
|
||||
|
||||
/**
|
||||
* boostrap table post 参数
|
||||
* @author fc
|
||||
*
|
||||
*/
|
||||
public class Tablepar {
|
||||
private int page;//页码
|
||||
private int limit;//数量
|
||||
private String orderByColumn;//排序字段
|
||||
private String isAsc;//排序字符 asc desc
|
||||
private String searchText;//列表table里面的搜索
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public String getOrderByColumn() {
|
||||
return orderByColumn;
|
||||
}
|
||||
public void setOrderByColumn(String orderByColumn) {
|
||||
this.orderByColumn = orderByColumn;
|
||||
}
|
||||
public String getIsAsc() {
|
||||
return isAsc;
|
||||
}
|
||||
public void setIsAsc(String isAsc) {
|
||||
this.isAsc = isAsc;
|
||||
}
|
||||
public String getSearchText() {
|
||||
return searchText;
|
||||
}
|
||||
public void setSearchText(String searchText) {
|
||||
this.searchText = searchText;
|
||||
}
|
||||
|
||||
}
|
||||
21
src/main/java/cn/com/v2/common/interceptor/Interceptor.java
Normal file
21
src/main/java/cn/com/v2/common/interceptor/Interceptor.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package cn.com.v2.common.interceptor;
|
||||
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 拦截器
|
||||
*/
|
||||
public class Interceptor implements HandlerInterceptor {
|
||||
/**
|
||||
* 在请求处理之前进行调用(Controller方法调用之前)
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
|
||||
return true;//如果设置为false时,被请求时,拦截器执行到此处将不会继续操作
|
||||
//如果设置为true时,请求将会继续执行后面的操作
|
||||
}
|
||||
|
||||
}
|
||||
91
src/main/java/cn/com/v2/common/interceptor/WebMvcConfig.java
Normal file
91
src/main/java/cn/com/v2/common/interceptor/WebMvcConfig.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package cn.com.v2.common.interceptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
import cn.com.v2.common.config.V2Config;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
@Configuration
|
||||
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
||||
|
||||
@Autowired
|
||||
private V2Config v2Config;
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("error.html").addResourceLocations("classpath:/META-INF/resources/static/error.html");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
|
||||
List<String> list1=new ArrayList<String>();
|
||||
List<String> list2=new ArrayList<String>();
|
||||
|
||||
Map<String, String> map= v2Config.getXnljmap();
|
||||
|
||||
Set<String> set = map.keySet();
|
||||
for (String o : set) {
|
||||
list1.add("/"+o+"/**");
|
||||
list2.add(map.get(o));
|
||||
}
|
||||
registry.addResourceHandler(ArrayUtil.toArray(list1, String.class)).addResourceLocations(ArrayUtil.toArray(list2, String.class));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重写addCorsMappings()解决跨域问题
|
||||
* 配置:允许http请求进行跨域访问
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
|
||||
// 设置允许多个域名请求
|
||||
//String[] allowDomains = {"http://www.toheart.xin","http://192.168.11.213:8080","http://localhost:8080"};
|
||||
|
||||
//指哪些接口URL需要增加跨域设置
|
||||
registry.addMapping("/**")
|
||||
//.allowedOrigins("*")//指的是前端哪些域名被允许跨域
|
||||
.allowedOriginPatterns("*")
|
||||
//需要带cookie等凭证时,设置为true,就会把cookie的相关信息带上
|
||||
.allowCredentials(true)
|
||||
//指的是允许哪些方法
|
||||
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
//cookie的失效时间,单位为秒(s),若设置为-1,则关闭浏览器就失效
|
||||
.maxAge(3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写addInterceptors()实现拦截器
|
||||
* 配置:要拦截的路径以及不拦截的路径
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
//注册Interceptor拦截器(Interceptor这个类是我们自己写的拦截器类)
|
||||
InterceptorRegistration registration = registry.addInterceptor(new Interceptor());
|
||||
//addPathPatterns()方法添加需要拦截的路径
|
||||
//所有路径都被拦截
|
||||
registration.addPathPatterns("/**");
|
||||
//excludePathPatterns()方法添加不拦截的路径
|
||||
|
||||
|
||||
String[] excludePatterns = new String[]{"/error","/error.html","/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**",
|
||||
"/api", "/api-docs", "/api-docs/**", "/doc.html/**",
|
||||
"/api/file/*"};
|
||||
|
||||
//添加不拦截路径
|
||||
registration.excludePathPatterns(excludePatterns);
|
||||
}
|
||||
|
||||
}
|
||||
92
src/main/java/cn/com/v2/controller/ApiController.java
Normal file
92
src/main/java/cn/com/v2/controller/ApiController.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package cn.com.v2.controller;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
import cn.com.v2.common.base.BaseController;
|
||||
import cn.com.v2.common.domain.AjaxResult;
|
||||
import cn.com.v2.model.SysUser;
|
||||
import cn.com.v2.service.ISysUserService;
|
||||
import cn.com.v2.util.SaTokenUtil;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/goview/sys")
|
||||
public class ApiController extends BaseController {
|
||||
@Autowired
|
||||
private ISysUserService iSysUserService;
|
||||
|
||||
@ApiOperation(value = "登陆", notes = "登陆")
|
||||
@PostMapping("/login")
|
||||
@ResponseBody
|
||||
public AjaxResult APIlogin(@RequestBody SysUser user, HttpServletRequest request) {
|
||||
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setId("1111111111111111111111");
|
||||
sysUser.setUsername("gaoxq");
|
||||
sysUser.setNickname("gaoxq");
|
||||
|
||||
// 判断是否登陆
|
||||
if (StpUtil.isLogin()) {
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("userinfo", SaTokenUtil.getUser());
|
||||
map.put("token", StpUtil.getTokenInfo());
|
||||
return success().put("data", map);
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(user.getUsername()) && StrUtil.isNotBlank(user.getPassword())) {
|
||||
// SysUser sysUser = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, user.getUsername()).eq(SysUser::getPassword, SecureUtil.md5(user.getPassword())).last("LIMIT 1"));
|
||||
if (sysUser != null) {
|
||||
StpUtil.login(sysUser.getId());
|
||||
SaTokenUtil.setUser(sysUser);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("userinfo", sysUser);
|
||||
map.put("token", StpUtil.getTokenInfo());
|
||||
|
||||
return success().put("data", map);
|
||||
} else {
|
||||
return error(500, "账户或者密码错误");
|
||||
}
|
||||
} else {
|
||||
return error(500, "账户密码不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "登陆", notes = "登陆")
|
||||
@GetMapping("/logout")
|
||||
@ResponseBody
|
||||
public AjaxResult logout() {
|
||||
|
||||
// 判断是否登陆
|
||||
StpUtil.logout();
|
||||
|
||||
return success();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "获取oss地址", notes = "获取oss地址")
|
||||
@GetMapping("/getOssInfo")
|
||||
@ResponseBody
|
||||
public AjaxResult getOssInfo() {
|
||||
|
||||
return success();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
376
src/main/java/cn/com/v2/controller/FileController.java
Normal file
376
src/main/java/cn/com/v2/controller/FileController.java
Normal file
@@ -0,0 +1,376 @@
|
||||
package cn.com.v2.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import cn.com.v2.common.base.BaseController;
|
||||
import cn.com.v2.common.config.V2Config;
|
||||
import cn.com.v2.common.domain.AjaxResult;
|
||||
import cn.com.v2.model.SysFile;
|
||||
import cn.com.v2.model.vo.SysFileVo;
|
||||
import cn.com.v2.service.ISysFileService;
|
||||
import cn.com.v2.util.SnowflakeIdWorker;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 文件上传controller
|
||||
* @author fuce
|
||||
* @date: 2018年9月16日 下午4:23:50
|
||||
*/
|
||||
@Api(value = "文件上传")
|
||||
@RestController
|
||||
@RequestMapping("/api/file")
|
||||
@Slf4j
|
||||
public class FileController extends BaseController{
|
||||
|
||||
|
||||
@Autowired
|
||||
private V2Config v2Config;
|
||||
@Autowired
|
||||
private ISysFileService iSysFileService;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除", notes = "删除")
|
||||
@DeleteMapping("/remove")
|
||||
public AjaxResult remove(String ids){
|
||||
Boolean b=iSysFileService.removeByIds(StrUtil.split(ids, ',',-1));
|
||||
if(b){
|
||||
return success();
|
||||
}else{
|
||||
return error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "修改", notes = "修改")
|
||||
@PutMapping("/update")
|
||||
public AjaxResult update(String id,@RequestBody MultipartFile object) throws IllegalStateException, IOException{
|
||||
SysFile sysFile=iSysFileService.getById(id);
|
||||
if(sysFile!=null){
|
||||
String fileurl=sysFile.getAbsolutePath()+sysFile.getRelativePath()+File.separator+sysFile.getFileName();
|
||||
object.transferTo(new File(fileurl));
|
||||
return success("修改成功");
|
||||
}else{
|
||||
return error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param object 文件流对象
|
||||
* @param bucketName 桶名
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
public AjaxResult upload(@RequestBody MultipartFile object) throws IOException{
|
||||
String fileName = object.getOriginalFilename();
|
||||
//默认文件格式
|
||||
String suffixName=v2Config.getDefaultFormat();
|
||||
String mediaKey="";
|
||||
Long filesize= object.getSize();
|
||||
//文件名字
|
||||
String fileSuffixName="";
|
||||
if(fileName.lastIndexOf(".")!=-1) {//有后缀
|
||||
suffixName = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
||||
//mediaKey=MD5.create().digestHex(fileName);
|
||||
mediaKey=SnowflakeIdWorker.getUUID();
|
||||
fileSuffixName=mediaKey+suffixName;
|
||||
}else {//无后缀
|
||||
//取得唯一id
|
||||
//mediaKey = MD5.create().digestHex(fileName+suffixName);
|
||||
mediaKey=SnowflakeIdWorker.getUUID();
|
||||
//fileSuffixName=mediaKey+suffixName;
|
||||
}
|
||||
String virtualKey=getFirstNotNull(v2Config.getXnljmap());
|
||||
String absolutePath=v2Config.getXnljmap().get(getFirstNotNull(v2Config.getXnljmap()));
|
||||
SysFile sysFile=new SysFile();
|
||||
sysFile.setId(SnowflakeIdWorker.getUUID());
|
||||
sysFile.setFileName(fileSuffixName);
|
||||
sysFile.setFileSize(Integer.parseInt(filesize+""));
|
||||
sysFile.setFileSuffix(suffixName);
|
||||
sysFile.setCreateTime(DateUtil.formatLocalDateTime(LocalDateTime.now()));
|
||||
String filepath=DateUtil.formatDate(new Date());
|
||||
sysFile.setRelativePath(filepath);
|
||||
sysFile.setVirtualKey(virtualKey);
|
||||
sysFile.setAbsolutePath(absolutePath.replace("file:",""));
|
||||
iSysFileService.saveOrUpdate(sysFile);
|
||||
File desc = getAbsoluteFile(v2Config.getFileurl()+File.separator+filepath,fileSuffixName);
|
||||
object.transferTo(desc);
|
||||
SysFileVo sysFileVo=BeanUtil.copyProperties(sysFile, SysFileVo.class);
|
||||
sysFileVo.setFileurl(v2Config.getHttpurl()+sysFile.getVirtualKey()+"/"+sysFile.getRelativePath()+"/"+sysFile.getFileName());
|
||||
return AjaxResult.successData(200, sysFileVo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base64字符串转成图片
|
||||
* @param str
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/uploadbase64")
|
||||
public synchronized AjaxResult uploadbase64(String base64str) throws IOException{
|
||||
if(StrUtil.isNotBlank(base64str)){
|
||||
String suffixName=v2Config.getDefaultFormat();
|
||||
String mediaKey=SnowflakeIdWorker.getUUID();
|
||||
String fileSuffixName=mediaKey+suffixName;
|
||||
String virtualKey=getFirstNotNull(v2Config.getXnljmap());
|
||||
String absolutePath=v2Config.getXnljmap().get(getFirstNotNull(v2Config.getXnljmap()));
|
||||
SysFile sysFile=new SysFile();
|
||||
sysFile.setId(SnowflakeIdWorker.getUUID());
|
||||
sysFile.setFileName(fileSuffixName);
|
||||
sysFile.setFileSuffix(suffixName);
|
||||
sysFile.setCreateTime(DateUtil.formatLocalDateTime(LocalDateTime.now()));
|
||||
String filepath=DateUtil.formatDate(new Date());
|
||||
sysFile.setRelativePath(filepath);
|
||||
sysFile.setVirtualKey(virtualKey);
|
||||
sysFile.setAbsolutePath(absolutePath.replace("file:",""));
|
||||
File desc = getAbsoluteFile(v2Config.getFileurl()+File.separator+filepath,fileSuffixName);
|
||||
File file=null;
|
||||
try {
|
||||
file=Base64.decodeToFile(base64str, desc);
|
||||
} catch (Exception e) {
|
||||
System.out.println("错误base64:"+base64str);
|
||||
e.printStackTrace();
|
||||
}
|
||||
sysFile.setFileSize(Integer.parseInt(file.length()+""));
|
||||
iSysFileService.saveOrUpdate(sysFile);
|
||||
SysFileVo sysFileVo=BeanUtil.copyProperties(sysFile, SysFileVo.class);
|
||||
sysFileVo.setFileurl(v2Config.getHttpurl()+sysFile.getVirtualKey()+"/"+sysFile.getRelativePath()+"/"+sysFile.getFileName());
|
||||
return AjaxResult.successData(200, sysFileVo);
|
||||
}
|
||||
return AjaxResult.error();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定制方法
|
||||
* 根据关键字与相对路径获取文件内容
|
||||
* @param key 访问关键字
|
||||
* @param rpf 相对路径+文件名字
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getFileText")
|
||||
public AjaxResult getFileText(String key,String relativePath){
|
||||
String absolutePath= v2Config.getXnljmap().get(key).replace("file:", "");
|
||||
String fileurl=absolutePath+relativePath;
|
||||
try {
|
||||
String text=FileUtil.readUtf8String(fileurl);
|
||||
return AjaxResult.successData(200, text);
|
||||
}catch (IORuntimeException e) {
|
||||
return AjaxResult.error("没有该文件");
|
||||
}
|
||||
catch (Exception e) {
|
||||
return AjaxResult.error("报错:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定制方法
|
||||
* 根据关键字与相对路径获取文件内容
|
||||
* @param key 访问关键字
|
||||
* @param rpf 相对路径+文件名字
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/getFileText302")
|
||||
public void getFileText302(String key,String relativePath,HttpServletResponse response) throws IOException{
|
||||
String str=v2Config.getHttpurl()+key+"/"+relativePath;
|
||||
response.sendRedirect(str);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 覆盖上传文件 key与指定路径
|
||||
* @param object 文件流对象
|
||||
* @param bucketName 桶名
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/coverupload")
|
||||
public AjaxResult coverupload(@RequestBody MultipartFile object,String key,String relativePath) throws IOException{
|
||||
|
||||
String fileName = object.getOriginalFilename();
|
||||
String suffixName=v2Config.getDefaultFormat();
|
||||
Long filesize= object.getSize();
|
||||
//文件名字
|
||||
String fileSuffixName="";
|
||||
if(fileName.lastIndexOf(".")!=-1) {//有后缀
|
||||
suffixName = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
||||
//mediaKey=MD5.create().digestHex(fileName);
|
||||
//mediaKey=SnowflakeIdWorker.getUUID();
|
||||
fileSuffixName=relativePath.substring(relativePath.lastIndexOf("/")+1,relativePath.length());
|
||||
}else {//无后缀
|
||||
//取得唯一id
|
||||
//mediaKey = MD5.create().digestHex(fileName+suffixName);
|
||||
//mediaKey=SnowflakeIdWorker.getUUID();
|
||||
//fileSuffixName=mediaKey+suffixName;
|
||||
}
|
||||
String virtualKey=key;
|
||||
String absolutePath=v2Config.getXnljmap().get(key).replace("file:", "");
|
||||
SysFile sysFile=new SysFile();
|
||||
sysFile.setId(SnowflakeIdWorker.getUUID());
|
||||
sysFile.setFileName(fileSuffixName);
|
||||
sysFile.setFileSize(Integer.parseInt(filesize+""));
|
||||
sysFile.setFileSuffix(suffixName);
|
||||
sysFile.setCreateTime(DateUtil.formatLocalDateTime(LocalDateTime.now()));
|
||||
String filepath=relativePath.substring(0,relativePath.lastIndexOf("/"));
|
||||
sysFile.setRelativePath(filepath);
|
||||
sysFile.setVirtualKey(virtualKey);
|
||||
sysFile.setAbsolutePath(absolutePath);
|
||||
iSysFileService.saveOrUpdate(sysFile);
|
||||
File desc = getAbsoluteFile(absolutePath+filepath,fileSuffixName);
|
||||
object.transferTo(desc);
|
||||
SysFileVo sysFileVo=BeanUtil.copyProperties(sysFile, SysFileVo.class);
|
||||
sysFileVo.setFileurl(v2Config.getHttpurl()+sysFile.getVirtualKey()+"/"+sysFile.getRelativePath()+"/"+sysFile.getFileName());
|
||||
return AjaxResult.successData(200, sysFileVo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据文件id查询文件信息json
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getFileid/{id}")
|
||||
public AjaxResult getFileid(@PathVariable("id") String id){
|
||||
SysFile sysFile=iSysFileService.getById(id);
|
||||
if(sysFile!=null){
|
||||
SysFileVo sysFileVo=BeanUtil.copyProperties(sysFile, SysFileVo.class);
|
||||
sysFileVo.setFileurl(v2Config.getHttpurl()+sysFile.getVirtualKey()+"/"+sysFile.getRelativePath()+"/"+sysFile.getFileName());
|
||||
return AjaxResult.successData(200, sysFileVo);
|
||||
}
|
||||
return AjaxResult.error("没有该文件");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件id 302跳转到绝对地址
|
||||
* @param id
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
@GetMapping("/getFileid/302/{id}")
|
||||
public void getFileid302(@PathVariable("id") String id,HttpServletResponse response) throws IOException{
|
||||
SysFile sysFile=iSysFileService.getById(id);
|
||||
if(sysFile!=null){
|
||||
String str=v2Config.getHttpurl()+sysFile.getVirtualKey()+"/"+sysFile.getRelativePath()+"/"+sysFile.getFileName();
|
||||
response.sendRedirect(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param current
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Object list(long current, long size){
|
||||
Page<SysFile> page= new Page<SysFile>(current, size);
|
||||
IPage<SysFile> sysFile=iSysFileService.page(page, new LambdaQueryWrapper<SysFile>());
|
||||
return sysFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取map中第一个非空数据key
|
||||
*
|
||||
* @param <K> Key的类型
|
||||
* @param <V> Value的类型
|
||||
* @param map 数据源
|
||||
* @return 返回的值
|
||||
*/
|
||||
public static <K, V> K getFirstNotNull(Map<K, V> map) {
|
||||
K obj = null;
|
||||
for (Entry<K, V> entry : map.entrySet()) {
|
||||
obj = entry.getKey();
|
||||
if (obj != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
public final static File getAbsoluteFile(String uploadDir, String filename) throws IOException
|
||||
{
|
||||
File desc = new File(uploadDir+File.separator + filename);
|
||||
|
||||
if (!desc.getParentFile().exists())
|
||||
{
|
||||
desc.getParentFile().mkdirs();
|
||||
}
|
||||
if (!desc.exists())
|
||||
{
|
||||
desc.createNewFile();
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取上传文件的md5
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public String getMd5(MultipartFile file) {
|
||||
try {
|
||||
//获取文件的byte信息
|
||||
byte[] uploadBytes = file.getBytes();
|
||||
// 拿到一个MD5转换器
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
byte[] digest = md5.digest(uploadBytes);
|
||||
//转换为16进制
|
||||
return new BigInteger(1, digest).toString(16);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
257
src/main/java/cn/com/v2/controller/GoviewProjectController.java
Normal file
257
src/main/java/cn/com/v2/controller/GoviewProjectController.java
Normal file
@@ -0,0 +1,257 @@
|
||||
package cn.com.v2.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import cn.com.v2.common.base.BaseController;
|
||||
import cn.com.v2.common.config.V2Config;
|
||||
import cn.com.v2.common.domain.AjaxResult;
|
||||
import cn.com.v2.common.domain.ResultTable;
|
||||
import cn.com.v2.common.domain.Tablepar;
|
||||
import cn.com.v2.model.GoviewProject;
|
||||
import cn.com.v2.model.GoviewProjectData;
|
||||
import cn.com.v2.model.SysFile;
|
||||
import cn.com.v2.model.vo.GoviewProjectVo;
|
||||
import cn.com.v2.model.vo.SysFileVo;
|
||||
import cn.com.v2.service.IGoviewProjectDataService;
|
||||
import cn.com.v2.service.IGoviewProjectService;
|
||||
import cn.com.v2.service.ISysFileService;
|
||||
import cn.com.v2.util.ConvertUtil;
|
||||
import cn.com.v2.util.SnowflakeIdWorker;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/goview/project")
|
||||
public class GoviewProjectController extends BaseController{
|
||||
@Autowired
|
||||
private ISysFileService iSysFileService;
|
||||
@Autowired
|
||||
private V2Config v2Config;
|
||||
@Autowired
|
||||
private IGoviewProjectService iGoviewProjectService;
|
||||
@Autowired
|
||||
private IGoviewProjectDataService iGoviewProjectDataService;
|
||||
|
||||
|
||||
@ApiOperation(value = "分页跳转", notes = "分页跳转")
|
||||
@GetMapping("/list")
|
||||
@ResponseBody
|
||||
public ResultTable list(Tablepar tablepar){
|
||||
Page<GoviewProject> page= new Page<GoviewProject>(tablepar.getPage(), tablepar.getLimit());
|
||||
IPage<GoviewProject> iPages=iGoviewProjectService.page(page, new LambdaQueryWrapper<GoviewProject>());
|
||||
ResultTable resultTable=new ResultTable();
|
||||
resultTable.setData(iPages.getRecords());
|
||||
resultTable.setCode(200);
|
||||
resultTable.setCount(iPages.getTotal());
|
||||
resultTable.setMsg("获取成功");
|
||||
return resultTable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增保存
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
//@Log(title = "项目表新增", action = "111")
|
||||
@ApiOperation(value = "新增", notes = "新增")
|
||||
@PostMapping("/create")
|
||||
@ResponseBody
|
||||
public AjaxResult add(@RequestBody GoviewProject goviewProject){
|
||||
goviewProject.setCreateTime(DateUtil.now());
|
||||
goviewProject.setState(-1);
|
||||
boolean b=iGoviewProjectService.save(goviewProject);
|
||||
if(b){
|
||||
return successData(200, goviewProject).put("msg", "创建成功");
|
||||
}else{
|
||||
return error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 项目表删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
//@Log(title = "项目表删除", action = "111")
|
||||
@ApiOperation(value = "删除", notes = "删除")
|
||||
@DeleteMapping("/delete")
|
||||
@ResponseBody
|
||||
public AjaxResult remove(String ids){
|
||||
List<String> lista=ConvertUtil.toListStrArray(ids);
|
||||
Boolean b=iGoviewProjectService.removeByIds(lista);
|
||||
if(b){
|
||||
return success();
|
||||
}else{
|
||||
return error();
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改保存", notes = "修改保存")
|
||||
@PostMapping("/edit")
|
||||
@ResponseBody
|
||||
public AjaxResult editSave(@RequestBody GoviewProject goviewProject)
|
||||
{
|
||||
Boolean b= iGoviewProjectService.updateById(goviewProject);
|
||||
if(b){
|
||||
return success();
|
||||
}
|
||||
return error();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "项目重命名", notes = "项目重命名")
|
||||
@PostMapping("/rename")
|
||||
@ResponseBody
|
||||
public AjaxResult rename(@RequestBody GoviewProject goviewProject)
|
||||
{
|
||||
|
||||
LambdaUpdateWrapper<GoviewProject> updateWrapper=new LambdaUpdateWrapper<GoviewProject>();
|
||||
updateWrapper.eq(GoviewProject::getId, goviewProject.getId());
|
||||
updateWrapper.set(GoviewProject::getProjectName, goviewProject.getProjectName());
|
||||
Boolean b=iGoviewProjectService.update(updateWrapper);
|
||||
if(b){
|
||||
return success();
|
||||
}
|
||||
return error();
|
||||
}
|
||||
|
||||
|
||||
//发布/取消项目状态
|
||||
@PutMapping("/publish")
|
||||
@ResponseBody
|
||||
public AjaxResult updateVisible(@RequestBody GoviewProject goviewProject){
|
||||
if(goviewProject.getState()==-1||goviewProject.getState()==1) {
|
||||
|
||||
LambdaUpdateWrapper<GoviewProject> updateWrapper=new LambdaUpdateWrapper<GoviewProject>();
|
||||
updateWrapper.eq(GoviewProject::getId, goviewProject.getId());
|
||||
updateWrapper.set(GoviewProject::getState, goviewProject.getState());
|
||||
Boolean b=iGoviewProjectService.update(updateWrapper);
|
||||
if(b){
|
||||
return success();
|
||||
}
|
||||
return error();
|
||||
}
|
||||
return error("警告非法字段");
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "获取项目存储数据", notes = "获取项目存储数据")
|
||||
@GetMapping("/getData")
|
||||
@ResponseBody
|
||||
public AjaxResult getData(String projectId, ModelMap map)
|
||||
{
|
||||
GoviewProject goviewProject= iGoviewProjectService.getById(projectId);
|
||||
|
||||
GoviewProjectData blogText=iGoviewProjectDataService.getProjectid(projectId);
|
||||
if(blogText!=null) {
|
||||
GoviewProjectVo goviewProjectVo=new GoviewProjectVo();
|
||||
BeanUtils.copyProperties(goviewProject,goviewProjectVo);
|
||||
goviewProjectVo.setContent(blogText.getContent());
|
||||
return AjaxResult.successData(200,goviewProjectVo).put("msg","获取成功");
|
||||
}
|
||||
return AjaxResult.successData(200, null).put("msg","无数据");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "保存项目数据", notes = "保存项目数据")
|
||||
@PostMapping("/save/data")
|
||||
@ResponseBody
|
||||
public AjaxResult saveData(GoviewProjectData data) {
|
||||
|
||||
GoviewProject goviewProject= iGoviewProjectService.getById(data.getProjectId());
|
||||
if(goviewProject==null) {
|
||||
return error("没有该项目ID");
|
||||
}
|
||||
GoviewProjectData goviewProjectData= iGoviewProjectDataService.getOne(new LambdaQueryWrapper<GoviewProjectData>().eq(GoviewProjectData::getProjectId, goviewProject.getId()));
|
||||
if(goviewProjectData!=null) {
|
||||
data.setId(goviewProjectData.getId());
|
||||
iGoviewProjectDataService.updateById(data);
|
||||
return success("数据保存成功");
|
||||
}else {
|
||||
iGoviewProjectDataService.save(data);
|
||||
return success("数据保存成功");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param object 文件流对象
|
||||
* @param bucketName 桶名
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
public AjaxResult upload(@RequestBody MultipartFile object) throws IOException{
|
||||
String fileName = object.getOriginalFilename();
|
||||
//默认文件格式
|
||||
String suffixName=v2Config.getDefaultFormat();
|
||||
String mediaKey="";
|
||||
Long filesize= object.getSize();
|
||||
//文件名字
|
||||
String fileSuffixName="";
|
||||
if(fileName.lastIndexOf(".")!=-1) {//有后缀
|
||||
suffixName = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
|
||||
//mediaKey=MD5.create().digestHex(fileName);
|
||||
mediaKey=SnowflakeIdWorker.getUUID();
|
||||
fileSuffixName=mediaKey+suffixName;
|
||||
}else {//无后缀
|
||||
//取得唯一id
|
||||
//mediaKey = MD5.create().digestHex(fileName+suffixName);
|
||||
mediaKey=SnowflakeIdWorker.getUUID();
|
||||
//fileSuffixName=mediaKey+suffixName;
|
||||
}
|
||||
String virtualKey=FileController.getFirstNotNull(v2Config.getXnljmap());
|
||||
String absolutePath=v2Config.getXnljmap().get(FileController.getFirstNotNull(v2Config.getXnljmap()));
|
||||
SysFile sysFile=new SysFile();
|
||||
sysFile.setId(SnowflakeIdWorker.getUUID());
|
||||
sysFile.setFileName(fileSuffixName);
|
||||
sysFile.setFileSize(Integer.parseInt(filesize+""));
|
||||
sysFile.setFileSuffix(suffixName);
|
||||
sysFile.setCreateTime(DateUtil.formatLocalDateTime(LocalDateTime.now()));
|
||||
String filepath=DateUtil.formatDate(new Date());
|
||||
sysFile.setRelativePath(filepath);
|
||||
sysFile.setVirtualKey(virtualKey);
|
||||
sysFile.setAbsolutePath(absolutePath.replace("file:",""));
|
||||
iSysFileService.saveOrUpdate(sysFile);
|
||||
File desc = FileController.getAbsoluteFile(v2Config.getFileurl()+File.separator+filepath,fileSuffixName);
|
||||
object.transferTo(desc);
|
||||
SysFileVo sysFileVo=BeanUtil.copyProperties(sysFile, SysFileVo.class);
|
||||
sysFileVo.setFileurl(v2Config.getHttpurl()+sysFile.getVirtualKey()+"/"+sysFile.getRelativePath()+"/"+sysFile.getFileName());
|
||||
return successData(200, sysFileVo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
21
src/main/java/cn/com/v2/controller/Indexcontroller.java
Normal file
21
src/main/java/cn/com/v2/controller/Indexcontroller.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package cn.com.v2.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class Indexcontroller {
|
||||
|
||||
@GetMapping("/")
|
||||
public void index(HttpServletResponse response) throws IOException {
|
||||
response.setContentType("text/html; charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println("<p style='color:orange'>goview后台首页</p>");
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
}
|
||||
}
|
||||
20
src/main/java/cn/com/v2/controller/SysUserController.java
Normal file
20
src/main/java/cn/com/v2/controller/SysUserController.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package cn.com.v2.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/v2/sys-user")
|
||||
public class SysUserController {
|
||||
|
||||
}
|
||||
16
src/main/java/cn/com/v2/mapper/GoviewProjectDataMapper.java
Normal file
16
src/main/java/cn/com/v2/mapper/GoviewProjectDataMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.com.v2.mapper;
|
||||
|
||||
import cn.com.v2.model.GoviewProjectData;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface GoviewProjectDataMapper extends BaseMapper<GoviewProjectData> {
|
||||
|
||||
}
|
||||
16
src/main/java/cn/com/v2/mapper/GoviewProjectMapper.java
Normal file
16
src/main/java/cn/com/v2/mapper/GoviewProjectMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.com.v2.mapper;
|
||||
|
||||
import cn.com.v2.model.GoviewProject;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface GoviewProjectMapper extends BaseMapper<GoviewProject> {
|
||||
|
||||
}
|
||||
17
src/main/java/cn/com/v2/mapper/SysFileMapper.java
Normal file
17
src/main/java/cn/com/v2/mapper/SysFileMapper.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package cn.com.v2.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import cn.com.v2.model.SysFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2022-12-22
|
||||
*/
|
||||
public interface SysFileMapper extends BaseMapper<SysFile> {
|
||||
|
||||
}
|
||||
16
src/main/java/cn/com/v2/mapper/SysUserMapper.java
Normal file
16
src/main/java/cn/com/v2/mapper/SysUserMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.com.v2.mapper;
|
||||
|
||||
import cn.com.v2.model.SysUser;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
|
||||
}
|
||||
45
src/main/java/cn/com/v2/model/GoviewProject.java
Normal file
45
src/main/java/cn/com/v2/model/GoviewProject.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package cn.com.v2.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@TableName("biz_view_project")
|
||||
@Data
|
||||
public class GoviewProject implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
private String projectName;
|
||||
|
||||
private Integer state;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createTime;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private Integer isDelete;
|
||||
|
||||
private String indexImage;
|
||||
|
||||
private String remarks;
|
||||
|
||||
}
|
||||
39
src/main/java/cn/com/v2/model/GoviewProjectData.java
Normal file
39
src/main/java/cn/com/v2/model/GoviewProjectData.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package cn.com.v2.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Blob;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@TableName("biz_view_project_data")
|
||||
@Data
|
||||
public class GoviewProjectData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
private String projectId;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createTime;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private String content;
|
||||
|
||||
|
||||
}
|
||||
119
src/main/java/cn/com/v2/model/SysFile.java
Normal file
119
src/main/java/cn/com/v2/model/SysFile.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package cn.com.v2.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2022-12-22
|
||||
*/
|
||||
@TableName("biz_view_file")
|
||||
public class SysFile implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
private String id;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private Integer fileSize;
|
||||
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* 虚拟路径
|
||||
*/
|
||||
private String virtualKey;
|
||||
|
||||
/**
|
||||
* 相对路径
|
||||
*/
|
||||
private String relativePath;
|
||||
|
||||
/**
|
||||
* 绝对路径
|
||||
*/
|
||||
private String absolutePath;
|
||||
|
||||
|
||||
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createTime;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public Integer getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
public void setFileSize(Integer fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
public String getFileSuffix() {
|
||||
return fileSuffix;
|
||||
}
|
||||
|
||||
public void setFileSuffix(String fileSuffix) {
|
||||
this.fileSuffix = fileSuffix;
|
||||
}
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
|
||||
public String getVirtualKey() {
|
||||
return virtualKey;
|
||||
}
|
||||
|
||||
public void setVirtualKey(String virtualKey) {
|
||||
this.virtualKey = virtualKey;
|
||||
}
|
||||
|
||||
public String getAbsolutePath() {
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
public void setAbsolutePath(String absolutePath) {
|
||||
this.absolutePath = absolutePath;
|
||||
}
|
||||
|
||||
public String getRelativePath() {
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
public void setRelativePath(String relativePath) {
|
||||
this.relativePath = relativePath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
39
src/main/java/cn/com/v2/model/SysUser.java
Normal file
39
src/main/java/cn/com/v2/model/SysUser.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package cn.com.v2.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@TableName("biz_view_user")
|
||||
@Data
|
||||
public class SysUser implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private Integer depId;
|
||||
|
||||
private String posId;
|
||||
|
||||
|
||||
}
|
||||
119
src/main/java/cn/com/v2/model/vo/GoviewProjectVo.java
Normal file
119
src/main/java/cn/com/v2/model/vo/GoviewProjectVo.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package cn.com.v2.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class GoviewProjectVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "项目名称")
|
||||
private String projectName;
|
||||
|
||||
@ApiModelProperty(value = "项目状态[-1未发布,1发布]")
|
||||
private Integer state;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "创建人id")
|
||||
private String createUserId;
|
||||
|
||||
@ApiModelProperty(value = "删除状态[1删除,-1未删除]")
|
||||
private Integer isDelete;
|
||||
|
||||
@ApiModelProperty(value = "首页图片")
|
||||
private String indexImage;
|
||||
|
||||
@ApiModelProperty(value = "项目介绍")
|
||||
private String remarks;
|
||||
|
||||
private String content;
|
||||
|
||||
|
||||
@JsonProperty("id")
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@JsonProperty("projectName")
|
||||
public String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public void setProjectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
@JsonProperty("state")
|
||||
public Integer getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(Integer state) {
|
||||
this.state = state;
|
||||
}
|
||||
@JsonProperty("createTime")
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
@JsonProperty("createUserId")
|
||||
public String getCreateUserId() {
|
||||
return createUserId;
|
||||
}
|
||||
|
||||
public void setCreateUserId(String createUserId) {
|
||||
this.createUserId = createUserId;
|
||||
}
|
||||
@JsonProperty("isDelete")
|
||||
public Integer getIsDelete() {
|
||||
return isDelete;
|
||||
}
|
||||
|
||||
public void setIsDelete(Integer isDelete) {
|
||||
this.isDelete = isDelete;
|
||||
}
|
||||
@JsonProperty("indexImage")
|
||||
public String getIndexImage() {
|
||||
return indexImage;
|
||||
}
|
||||
|
||||
public void setIndexImage(String indexImage) {
|
||||
this.indexImage = indexImage;
|
||||
}
|
||||
@JsonProperty("remarks")
|
||||
public String getRemarks() {
|
||||
return remarks;
|
||||
}
|
||||
|
||||
public void setRemarks(String remarks) {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String dateToStringConvert(Date date) {
|
||||
if(date!=null) {
|
||||
return DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
70
src/main/java/cn/com/v2/model/vo/SysFileVo.java
Normal file
70
src/main/java/cn/com/v2/model/vo/SysFileVo.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package cn.com.v2.model.vo;
|
||||
|
||||
|
||||
public class SysFileVo {
|
||||
|
||||
private String id;
|
||||
private String fileName;
|
||||
private Integer fileSize;
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 相对路径
|
||||
*/
|
||||
private String relativePath;
|
||||
|
||||
/**
|
||||
* 虚拟路径key
|
||||
*/
|
||||
private String virtualKey;
|
||||
|
||||
/**
|
||||
* 请求url
|
||||
*/
|
||||
private String fileurl;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
public Integer getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
public void setFileSize(Integer fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public String getRelativePath() {
|
||||
return relativePath;
|
||||
}
|
||||
public void setRelativePath(String relativePath) {
|
||||
this.relativePath = relativePath;
|
||||
}
|
||||
public String getVirtualKey() {
|
||||
return virtualKey;
|
||||
}
|
||||
public void setVirtualKey(String virtualKey) {
|
||||
this.virtualKey = virtualKey;
|
||||
}
|
||||
public String getFileurl() {
|
||||
return fileurl;
|
||||
}
|
||||
public void setFileurl(String fileurl) {
|
||||
this.fileurl = fileurl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.com.v2.service;
|
||||
|
||||
import cn.com.v2.model.GoviewProjectData;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IGoviewProjectDataService extends IService<GoviewProjectData> {
|
||||
|
||||
public GoviewProjectData getProjectid(String projectId);
|
||||
|
||||
}
|
||||
16
src/main/java/cn/com/v2/service/IGoviewProjectService.java
Normal file
16
src/main/java/cn/com/v2/service/IGoviewProjectService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.com.v2.service;
|
||||
|
||||
import cn.com.v2.model.GoviewProject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IGoviewProjectService extends IService<GoviewProject> {
|
||||
|
||||
}
|
||||
18
src/main/java/cn/com/v2/service/ISysFileService.java
Normal file
18
src/main/java/cn/com/v2/service/ISysFileService.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package cn.com.v2.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.com.v2.model.SysFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2022-12-22
|
||||
*/
|
||||
public interface ISysFileService extends IService<SysFile> {
|
||||
|
||||
|
||||
public SysFile selectByExamplefileName(String filename);
|
||||
}
|
||||
16
src/main/java/cn/com/v2/service/ISysUserService.java
Normal file
16
src/main/java/cn/com/v2/service/ISysUserService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package cn.com.v2.service;
|
||||
|
||||
import cn.com.v2.model.SysUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface ISysUserService extends IService<SysUser> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.com.v2.service.impl;
|
||||
|
||||
import cn.com.v2.model.GoviewProjectData;
|
||||
import cn.com.v2.mapper.GoviewProjectDataMapper;
|
||||
import cn.com.v2.service.IGoviewProjectDataService;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@Service
|
||||
public class GoviewProjectDataServiceImpl extends ServiceImpl<GoviewProjectDataMapper, GoviewProjectData> implements IGoviewProjectDataService {
|
||||
@Autowired
|
||||
GoviewProjectDataMapper dataMapper;
|
||||
@Override
|
||||
public GoviewProjectData getProjectid(String projectId) {
|
||||
LambdaQueryWrapper<GoviewProjectData> lambdaQueryWrapper=new LambdaQueryWrapper<GoviewProjectData>();
|
||||
lambdaQueryWrapper.eq(GoviewProjectData::getProjectId, projectId);
|
||||
return dataMapper.selectOne(lambdaQueryWrapper);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.com.v2.service.impl;
|
||||
|
||||
import cn.com.v2.model.GoviewProject;
|
||||
import cn.com.v2.mapper.GoviewProjectMapper;
|
||||
import cn.com.v2.service.IGoviewProjectService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@Service
|
||||
public class GoviewProjectServiceImpl extends ServiceImpl<GoviewProjectMapper, GoviewProject> implements IGoviewProjectService {
|
||||
|
||||
}
|
||||
30
src/main/java/cn/com/v2/service/impl/SysFileServiceImpl.java
Normal file
30
src/main/java/cn/com/v2/service/impl/SysFileServiceImpl.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package cn.com.v2.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.com.v2.mapper.SysFileMapper;
|
||||
import cn.com.v2.model.SysFile;
|
||||
import cn.com.v2.service.ISysFileService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2022-12-22
|
||||
*/
|
||||
@Service
|
||||
public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> implements ISysFileService {
|
||||
@Autowired
|
||||
private SysFileMapper sysFileMapper;
|
||||
|
||||
@Override
|
||||
public SysFile selectByExamplefileName(String filename) {
|
||||
SysFile sysFile=sysFileMapper.selectOne(new LambdaQueryWrapper<SysFile>().eq(SysFile::getFileName, filename));
|
||||
return sysFile;
|
||||
}
|
||||
|
||||
}
|
||||
20
src/main/java/cn/com/v2/service/impl/SysUserServiceImpl.java
Normal file
20
src/main/java/cn/com/v2/service/impl/SysUserServiceImpl.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package cn.com.v2.service.impl;
|
||||
|
||||
import cn.com.v2.model.SysUser;
|
||||
import cn.com.v2.mapper.SysUserMapper;
|
||||
import cn.com.v2.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author fc
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@Service
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||
|
||||
}
|
||||
252
src/main/java/cn/com/v2/util/ConvertUtil.java
Normal file
252
src/main/java/cn/com/v2/util/ConvertUtil.java
Normal file
@@ -0,0 +1,252 @@
|
||||
package cn.com.v2.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类型转换器
|
||||
*
|
||||
* @author fc
|
||||
*
|
||||
*/
|
||||
public class ConvertUtil {
|
||||
|
||||
/**
|
||||
* 转换为字符串<br>
|
||||
* 如果给定的值为null,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String toStr(Object value, String defaultValue) {
|
||||
if (null == value) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return (String) value;
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Integer数组<br>
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String str) {
|
||||
return toIntArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Integer数组<br>
|
||||
* @param split 分隔符
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String split, String str) {
|
||||
if (StrUtil.isEmpty(str)) {
|
||||
return new Integer[] {};
|
||||
}
|
||||
String[] strings = str.split(split);
|
||||
final Integer[] ints = new Integer[strings.length];
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
final Integer v = toInt(strings[i], 0);
|
||||
ints[i] = v;
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为int<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer toInt(Object value, Integer defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Integer) {
|
||||
return (Integer) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).intValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StrUtil.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(valueStr.trim());
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为List<String>数组<br>
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static List<String> toListStrArray(String str) {
|
||||
String[] stringArray = toStrArray(str);
|
||||
List<String> stringB = Arrays.asList(stringArray);
|
||||
return stringB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 转换为List<Long>数组<br>
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static List<Long> toListLongArray(String str) {
|
||||
Long[] stringArray = toLongArray(str);
|
||||
List<Long> stringB = Arrays.asList(stringArray);
|
||||
return stringB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转换为String数组<br>
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String str) {
|
||||
return toStrArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为String数组<br>
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String split, String str) {
|
||||
return str.split(split);
|
||||
}
|
||||
/**
|
||||
* 转换为Long数组<br>
|
||||
*
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long[] toLongArray(String str)
|
||||
{
|
||||
return toLongArray(",", str);
|
||||
}
|
||||
/**
|
||||
* 转换为Long数组<br>
|
||||
*
|
||||
* @param isIgnoreConvertError 是否忽略转换错误,忽略则给值null
|
||||
* @param values 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long[] toLongArray(String split, String str)
|
||||
{
|
||||
if (StrUtil.isEmpty(str))
|
||||
{
|
||||
return new Long[] {};
|
||||
}
|
||||
String[] arr = str.split(split);
|
||||
final Long[] longs = new Long[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
{
|
||||
final Long v = toLong(arr[i], null);
|
||||
longs[i] = v;
|
||||
}
|
||||
return longs;
|
||||
}
|
||||
/**
|
||||
* 转换为long<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long toLong(Object value, Long defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Long)
|
||||
{
|
||||
return (Long) value;
|
||||
}
|
||||
if (value instanceof Number)
|
||||
{
|
||||
return ((Number) value).longValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StrUtil.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
// 支持科学计数法
|
||||
return new BigDecimal(valueStr.trim()).longValue();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigDecimal<br>
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<br>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof BigDecimal)
|
||||
{
|
||||
return (BigDecimal) value;
|
||||
}
|
||||
if (value instanceof Long)
|
||||
{
|
||||
return new BigDecimal((Long) value);
|
||||
}
|
||||
if (value instanceof Double)
|
||||
{
|
||||
return new BigDecimal((Double) value);
|
||||
}
|
||||
if (value instanceof Integer)
|
||||
{
|
||||
return new BigDecimal((Integer) value);
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StrUtil.isEmpty(valueStr))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new BigDecimal(valueStr);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/main/java/cn/com/v2/util/MybatisPlusGenerator.java
Normal file
39
src/main/java/cn/com/v2/util/MybatisPlusGenerator.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package cn.com.v2.util;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import com.baomidou.mybatisplus.generator.fill.Column;
|
||||
|
||||
|
||||
public class MybatisPlusGenerator {
|
||||
public static void main(String[] args) {
|
||||
FastAutoGenerator.create(
|
||||
"jdbc:sqlite:D:\\eclipse-workspace\\v2-goview-bate\\sqllite\\goview.db",
|
||||
"", "").globalConfig(builder -> {
|
||||
builder.author("fc") // 设置作者
|
||||
// .enableSwagger() // 开启 swagger 模式
|
||||
.fileOverride() // 覆盖已生成文件
|
||||
.disableOpenDir() //禁止打开输出目录
|
||||
.outputDir(System.getProperty("user.dir") + "/src/main/java"); // 指定输出目录
|
||||
}).packageConfig(builder -> {
|
||||
builder.parent("cn.com") // 设置父包名
|
||||
.moduleName("v2") // 设置父包模块名
|
||||
.entity("model")
|
||||
// .service() // 设置自定义service路径,不设置就是默认路径
|
||||
.pathInfo(Collections.singletonMap(OutputFile.mapperXml,
|
||||
System.getProperty("user.dir") + "/src/main/resources/mapper/")); // 设置mapperXml生成路径
|
||||
}).strategyConfig(builder -> {
|
||||
builder.addInclude("t_goview_project_data") // 设置需要生成的表名
|
||||
.addTablePrefix("t_", "c_")
|
||||
// 设置自动填充的时间字段
|
||||
.entityBuilder().addTableFills(new Column("create_time", FieldFill.INSERT),
|
||||
new Column("update_time", FieldFill.INSERT_UPDATE)); // 设置过滤表前缀
|
||||
|
||||
}).templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
74
src/main/java/cn/com/v2/util/SaTokenUtil.java
Normal file
74
src/main/java/cn/com/v2/util/SaTokenUtil.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package cn.com.v2.util;
|
||||
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import cn.com.v2.model.SysUser;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
/**
|
||||
* 封装 Sa-Token 常用操作
|
||||
* @author kong
|
||||
*
|
||||
*/
|
||||
public class SaTokenUtil {
|
||||
|
||||
/**
|
||||
* 获取登录用户model
|
||||
*/
|
||||
public static SysUser getUser() {
|
||||
Object object=StpUtil.getSession().get("user");
|
||||
if(object!=null){
|
||||
SysUser tsysUser=new SysUser();
|
||||
BeanUtils.copyProperties(tsysUser, object);
|
||||
return tsysUser;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* set用户
|
||||
*/
|
||||
public static void setUser(SysUser user) {
|
||||
StpUtil.getSession().set("user", user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户id
|
||||
*/
|
||||
public static String getUserId() {
|
||||
return StpUtil.getLoginIdAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户name
|
||||
*/
|
||||
public static String getLoginName() {
|
||||
SysUser tsysUser = getUser();
|
||||
if (tsysUser == null){
|
||||
throw new RuntimeException("用户不存在!");
|
||||
}
|
||||
return tsysUser.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户ip
|
||||
* @return
|
||||
* @author fuce
|
||||
* @Date 2019年11月21日 上午9:58:26
|
||||
*/
|
||||
public static String getIp() {
|
||||
|
||||
return StpUtil.getTokenSession().getString("login_ip");
|
||||
}
|
||||
/**
|
||||
* 判断是否登录
|
||||
* @return
|
||||
* @author fuce
|
||||
* @Date 2019年11月21日 上午9:58:26
|
||||
*/
|
||||
public static boolean isLogin() {
|
||||
return StpUtil.isLogin();
|
||||
}
|
||||
|
||||
}
|
||||
155
src/main/java/cn/com/v2/util/SnowflakeIdWorker.java
Normal file
155
src/main/java/cn/com/v2/util/SnowflakeIdWorker.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package cn.com.v2.util;
|
||||
|
||||
/**
|
||||
* Twitter_Snowflake<br>
|
||||
* SnowFlake的结构如下(每部分用-分开):<br>
|
||||
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
|
||||
* 1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0<br>
|
||||
* 41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截)
|
||||
* 得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
|
||||
* 10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId<br>
|
||||
* 12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号<br>
|
||||
* 加起来刚好64位,为一个Long型。<br>
|
||||
* SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。
|
||||
*/
|
||||
public class SnowflakeIdWorker {
|
||||
|
||||
// ==============================Fields===========================================
|
||||
/** 开始时间截 (2015-01-01) */
|
||||
private final long twepoch = 1489111610226L;
|
||||
|
||||
/** 机器id所占的位数 */
|
||||
private final long workerIdBits = 5L;
|
||||
|
||||
/** 数据标识id所占的位数 */
|
||||
private final long dataCenterIdBits = 5L;
|
||||
|
||||
/** 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
|
||||
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
|
||||
|
||||
/** 支持的最大数据标识id,结果是31 */
|
||||
private final long maxDataCenterId = -1L ^ (-1L << dataCenterIdBits);
|
||||
|
||||
/** 序列在id中占的位数 */
|
||||
private final long sequenceBits = 12L;
|
||||
|
||||
/** 机器ID向左移12位 */
|
||||
private final long workerIdShift = sequenceBits;
|
||||
|
||||
/** 数据标识id向左移17位(12+5) */
|
||||
private final long dataCenterIdShift = sequenceBits + workerIdBits;
|
||||
|
||||
/** 时间截向左移22位(5+5+12) */
|
||||
private final long timestampLeftShift = sequenceBits + workerIdBits + dataCenterIdBits;
|
||||
|
||||
/** 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) */
|
||||
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
|
||||
|
||||
/** 工作机器ID(0~31) */
|
||||
private long workerId;
|
||||
|
||||
/** 数据中心ID(0~31) */
|
||||
private long dataCenterId;
|
||||
|
||||
/** 毫秒内序列(0~4095) */
|
||||
private long sequence = 0L;
|
||||
|
||||
/** 上次生成ID的时间截 */
|
||||
private long lastTimestamp = -1L;
|
||||
|
||||
|
||||
static SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1);
|
||||
//==============================Constructors=====================================
|
||||
/**
|
||||
* 构造函数
|
||||
* @param workerId 工作ID (0~31)
|
||||
* @param dataCenterId 数据中心ID (0~31)
|
||||
*/
|
||||
public SnowflakeIdWorker(long workerId, long dataCenterId) {
|
||||
if (workerId > maxWorkerId || workerId < 0) {
|
||||
throw new IllegalArgumentException(String.format("workerId can't be greater than %d or less than 0", maxWorkerId));
|
||||
}
|
||||
if (dataCenterId > maxDataCenterId || dataCenterId < 0) {
|
||||
throw new IllegalArgumentException(String.format("dataCenterId can't be greater than %d or less than 0", maxDataCenterId));
|
||||
}
|
||||
this.workerId = workerId;
|
||||
this.dataCenterId = dataCenterId;
|
||||
}
|
||||
|
||||
// ==============================Methods==========================================
|
||||
/**
|
||||
* 获得下一个ID (该方法是线程安全的)
|
||||
* @return SnowflakeId
|
||||
*/
|
||||
public synchronized long nextId() {
|
||||
long timestamp = timeGen();
|
||||
|
||||
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException(
|
||||
String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
|
||||
}
|
||||
|
||||
//如果是同一时间生成的,则进行毫秒内序列
|
||||
if (lastTimestamp == timestamp) {
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
//毫秒内序列溢出
|
||||
if (sequence == 0) {
|
||||
//阻塞到下一个毫秒,获得新的时间戳
|
||||
timestamp = tilNextMillis(lastTimestamp);
|
||||
}
|
||||
}
|
||||
//时间戳改变,毫秒内序列重置
|
||||
else {
|
||||
sequence = 0L;
|
||||
}
|
||||
|
||||
//上次生成ID的时间截
|
||||
lastTimestamp = timestamp;
|
||||
|
||||
//移位并通过或运算拼到一起组成64位的ID
|
||||
return ((timestamp - twepoch) << timestampLeftShift) //
|
||||
| (dataCenterId << dataCenterIdShift) //
|
||||
| (workerId << workerIdShift) //
|
||||
| sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻塞到下一个毫秒,直到获得新的时间戳
|
||||
* @param lastTimestamp 上次生成ID的时间截
|
||||
* @return 当前时间戳
|
||||
*/
|
||||
protected long tilNextMillis(long lastTimestamp) {
|
||||
long timestamp = timeGen();
|
||||
while (timestamp <= lastTimestamp) {
|
||||
timestamp = timeGen();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回以毫秒为单位的当前时间
|
||||
* @return 当前时间(毫秒)
|
||||
*/
|
||||
protected long timeGen() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
//==============================Test=============================================
|
||||
/** 测试 */
|
||||
public static void main(String[] args) {
|
||||
System.out.println(System.currentTimeMillis());
|
||||
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(1, 1);
|
||||
long startTime = System.nanoTime();
|
||||
for (int i = 0; i < 500; i++) {
|
||||
long id = idWorker.nextId();
|
||||
System.out.println(id);
|
||||
}
|
||||
System.out.println((System.nanoTime()-startTime)/1000000+"ms");
|
||||
}
|
||||
|
||||
public static String getUUID() {
|
||||
long id = idWorker.nextId();
|
||||
return String.valueOf(id);
|
||||
}
|
||||
}
|
||||
15
src/main/resources/application-dev.yml
Normal file
15
src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:33069/prd?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
# 替换为你的MySQL用户名
|
||||
username: dream
|
||||
# 替换为你的MySQL密码
|
||||
password: info_dream
|
||||
### 连接池配置
|
||||
druid:
|
||||
initial-size: 10
|
||||
max-active: 100
|
||||
min-idle: 30
|
||||
max-wait: 40
|
||||
validation-query: SELECT 1
|
||||
110
src/main/resources/application.yml
Normal file
110
src/main/resources/application.yml
Normal file
@@ -0,0 +1,110 @@
|
||||
v2:
|
||||
#虚拟路径映射路径 2个文件路径一一对应 第一个为主存储,其他为配置相关
|
||||
xnljmap:
|
||||
#win服务器 本地 注意!! 记住这个结尾有一个/
|
||||
oss: file:D:/upload/
|
||||
#linux服务器
|
||||
#oss: file:/home/webapps/oss/
|
||||
#虚拟路径映射路径 end
|
||||
#本地存放地址 注意!! 记住这个结尾没有/
|
||||
fileurl: D:/upload
|
||||
#http://127.0.0.1:8080/oss/{yy}/2022-12-22/c83a77ae134a540c30daa6a0666fa945.md
|
||||
httpurl: http://127.0.0.1:8083/
|
||||
defaultFormat: .png
|
||||
#tomcat config
|
||||
server :
|
||||
port : 8083
|
||||
##项目名字配置
|
||||
servlet :
|
||||
context-path : /
|
||||
#session过期
|
||||
session:
|
||||
timeout: PT4H
|
||||
#cookie:
|
||||
# name: jxfgzs
|
||||
tomcat :
|
||||
uri-encoding : UTF-8
|
||||
#xx 报错修改的地方
|
||||
max-connections: 200000
|
||||
max-http-form-post-size: 9000000
|
||||
threads:
|
||||
max: 128
|
||||
min-spare: 5
|
||||
spring :
|
||||
# 环境 dev|test|prod
|
||||
profiles :
|
||||
active : dev
|
||||
servlet:
|
||||
multipart:
|
||||
#设置总上传的数据大小
|
||||
max-request-size: 100MB
|
||||
#单个文件大小
|
||||
maxFileSize : 30MB
|
||||
#xx 报错修改的地方
|
||||
max-connections: 200000
|
||||
max-http-post-size: 9000000
|
||||
#热部署模块
|
||||
devtools:
|
||||
restart:
|
||||
#热部署开关
|
||||
enabled: true
|
||||
#指定热部署的目录
|
||||
additional-paths: src/main/java
|
||||
#指定目录不更新
|
||||
exclude: test/**
|
||||
mvc: #静态文件
|
||||
static-path-pattern : /static/**
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
#模板引擎
|
||||
thymeleaf:
|
||||
model: HTML5
|
||||
prefix: classpath:/templates/
|
||||
suffix: .html
|
||||
#指定编码
|
||||
encoding: utf-8
|
||||
#禁用缓存 默认false
|
||||
cache: false
|
||||
#mybatis
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: cn.com.v2.model
|
||||
global-config:
|
||||
# 数据库相关配置
|
||||
db-config:
|
||||
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID",ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
|
||||
id-type: INPUT
|
||||
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
|
||||
field-strategy: not_empty
|
||||
#驼峰下划线转换
|
||||
column-underline: true
|
||||
#数据库大写下划线转换
|
||||
#capital-mode: true
|
||||
#逻辑删除配置
|
||||
logic-delete-value: 0
|
||||
logic-not-delete-value: 1
|
||||
db-type: sqlite
|
||||
#刷新mapper 调试神器
|
||||
refresh: true
|
||||
# 原生配置
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
|
||||
sa-token:
|
||||
# token名称 (同时也是cookie名称)
|
||||
token-name: satoken
|
||||
# token有效期,单位s 默认30天, -1代表永不过期
|
||||
timeout: 2592000
|
||||
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||
activity-timeout: -1
|
||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
|
||||
is-share: true
|
||||
# token风格
|
||||
token-style: uuid
|
||||
# 是否输出操作日志
|
||||
is-log: false
|
||||
5
src/main/resources/mapper/GoviewProjectDataMapper.xml
Normal file
5
src/main/resources/mapper/GoviewProjectDataMapper.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.com.v2.mapper.GoviewProjectDataMapper">
|
||||
|
||||
</mapper>
|
||||
5
src/main/resources/mapper/GoviewProjectMapper.xml
Normal file
5
src/main/resources/mapper/GoviewProjectMapper.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.com.v2.mapper.GoviewProjectMapper">
|
||||
|
||||
</mapper>
|
||||
5
src/main/resources/mapper/SysFileMapper.xml
Normal file
5
src/main/resources/mapper/SysFileMapper.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.com.v2oss.mapper.SysFileMapper">
|
||||
|
||||
</mapper>
|
||||
5
src/main/resources/mapper/SysUserMapper.xml
Normal file
5
src/main/resources/mapper/SysUserMapper.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.com.v2.mapper.SysUserMapper">
|
||||
|
||||
</mapper>
|
||||
13
src/test/java/cn/com/jetshine/oos/OosApplicationTests.java
Normal file
13
src/test/java/cn/com/jetshine/oos/OosApplicationTests.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package cn.com.jetshine.oos;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class OosApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user