小文件上传完成

This commit is contained in:
朱秀清 2022-01-07 03:00:24 +08:00
parent 4a2a0dcbfa
commit d67b79e678
40 changed files with 21944 additions and 1210 deletions

64
pom.xml
View File

@ -87,30 +87,29 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>5.1.44</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<!--H2-->
<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mybatis.spring.boot</groupId>-->
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
<!-- <version>2.1.3</version>-->
<!-- </dependency>-->
<!--分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.pagehelper</groupId>-->
<!-- <artifactId>pagehelper-spring-boot-starter</artifactId>-->
<!-- <version>1.2.3</version>-->
<!-- </dependency>-->
<!--druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>druid-spring-boot-starter</artifactId>-->
<!-- <version>1.1.10</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
@ -123,6 +122,7 @@
</dependencies>
<build>
<finalName>oneManager-java</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
@ -142,25 +142,11 @@
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
</dependencies>
<configuration>
<!--配置文件的路径-->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,11 +1,11 @@
package com.zhu.onemanager;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@MapperScan("com.zhu.onemanager.mapper")
@EnableScheduling
public class OnemanagerJavaApplication {
public static void main(String[] args) {

View File

@ -1,12 +1,16 @@
package com.zhu.onemanager.controller.onedrive;
import com.zhu.onemanager.logic.impl.OneDriveItemUrlImpl;
import com.zhu.onemanager.pojo.DriveParams;
import com.zhu.onemanager.pojo.OneDriveUploadItem;
import com.zhu.onemanager.result.R;
import com.zhu.onemanager.service.OnedriveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
/**
* @author ggBall
@ -23,6 +27,8 @@ public class OnedriveController {
@Resource
private OnedriveService onedriveService;
@Resource
private OneDriveItemUrlImpl oneDriveItemUrl;
/**
* @Author ggball
@ -44,9 +50,55 @@ public class OnedriveController {
log.info("itemId:{}",itemId);
String path = "me/drive/items/%s/children"+driveParams.getUrl();
String formatPath = String.format(path,itemId);
R r = onedriveService.children(formatPath);
R r = onedriveService.children(formatPath,itemId);
return r;
}
/**
* @Author ggball
* @Description 创建上传会话
* @Date 2022/1/6
* @Param [itemId] 项目id
* @return com.zhu.onemanager.result.R
**/
@GetMapping("/createSession")
public R createSession(String itemId,String fileName) {
OneDriveUploadItem uploadItem = OneDriveUploadItem.builder()
.itemId(itemId)
.fileName(fileName)
.build();
String uploadSession = oneDriveItemUrl.getUploadUrl(uploadItem);
return R.ok(uploadSession);
}
/**
* @Author ggball
* @Description 创建上传会话
* @Date 2022/1/6
* @Param [itemId] 项目id
* @return com.zhu.onemanager.result.R
**/
@PostMapping("/upload")
public R upload(@RequestParam("file") MultipartFile file,String itemId) throws IOException {
if (file.isEmpty()) {
return R.error("上传失败,请选择文件");
}
String fileName = file.getOriginalFilename();
OneDriveUploadItem uploadItem = OneDriveUploadItem.builder()
.fileName(fileName)
.itemId(itemId)
.file(file)
.build();
return onedriveService.uploadMIniFile(uploadItem);
}
}

View File

@ -0,0 +1,39 @@
package com.zhu.onemanager.handler;
import com.zhu.onemanager.pojo.Item;
/**
* 文件处理器
* @author ggball
*/
public interface ItemHandler {
/**
* @Author ggball
* @Description 文件类型
* @Date 2022/1/5
* @Param []
* @return java.lang.String
**/
String getType();
/**
* @Author ggball
* @Description 文件变动
* @Date 2022/1/5
* @Param item 项目
* @return void
**/
void change(Item item);
/**
* @Author ggball
* @Description 文件变动后置处理
* @Date 2022/1/5
* @Param oldItem 旧项目
* @Param newItem 新项目
* @return void
**/
void changeCallBack(Item oldItem,Item newItem);
}

View File

@ -0,0 +1,38 @@
package com.zhu.onemanager.handler;
import com.zhu.onemanager.pojo.Item;
/**
* @author ggBall
* @version 1.0.0
* @ClassName FileHandlerAbs.java
* @Description TODO
* @createTime 2022年01月05日 17:19:00
*/
public abstract class ItemHandlerAbs implements ItemHandler {
/**
* 上传
* @param item
*/
public abstract void upload(Item item);
/**
* 删除
* @param item
*/
public abstract void delete(Item item);
/**
* 更新
* @param item
*/
public abstract void update(Item item);
/**
* 查看
* @param id
* @return
*/
public abstract Item Check(String id);
}

View File

@ -0,0 +1,94 @@
package com.zhu.onemanager.handler;
import com.zhu.onemanager.pojo.Item;
/**
* @author ggBall
* @version 1.0.0
* @ClassName OneDriveFileHandler.java
* @Description TODO
* @createTime 2022年01月05日 17:20:00
*/
public class OneDriveItemHandler extends ItemHandlerAbs {
/**
* @return java.lang.String
* @Author ggball
* @Description 文件类型
* @Date 2022/1/5
* @Param []
**/
@Override
public String getType() {
return null;
}
/**
* @param item
* @return void
* @Author ggball
* @Description 文件变动
* @Date 2022/1/5
* @Param []
*/
@Override
public void change(Item item) {
}
/**
* @param oldItem
* @param newItem
* @return void
* @Author ggball
* @Description 文件变动后置处理
* @Date 2022/1/5
* @Param []
*/
@Override
public void changeCallBack(Item oldItem, Item newItem) {
}
/**
* 上传
*
* @param item
*/
@Override
public void upload(Item item) {
}
/**
* 删除
*
* @param item
*/
@Override
public void delete(Item item) {
}
/**
* 更新
*
* @param item
*/
@Override
public void update(Item item) {
}
/**
* 查看
*
* @param id
* @return
*/
@Override
public Item Check(String id) {
return null;
}
}

View File

@ -36,12 +36,12 @@ public class AuthTokenImpl implements AuthToken {
@Autowired
private ServletContext context;
@Resource
private SaveConfig saveConfig;
public AuthTokenImpl(SaveConfig saveConfig) {
this.saveConfig = saveConfig;
}
// @Resource
// private SaveConfig saveConfig;
//
// public AuthTokenImpl(SaveConfig saveConfig) {
// this.saveConfig = saveConfig;
// }
@Override
public void getAccessToken(OnedriveConfig config) throws IOException {
@ -62,15 +62,15 @@ public class AuthTokenImpl implements AuthToken {
@Override
public void getRefreshToken(OnedriveConfig config) throws IOException {
if ((context.getAttribute("refresh_token") == null && context.getAttribute("refresh_token").toString().isEmpty()) || (context.getAttribute("access_token") == null && context.getAttribute("access_token").toString().isEmpty())) {
if (config == null || config.getRefreshToken() == null || config.getAccessToken() == null) {
log.info("Refresh_token:==>" + context.getAttribute("refresh_token"));
log.info("Access_token:==>" + context.getAttribute("access_token"));
throw new AppException(ResponseEnum.Token_invalid);
throw new AppException(ResponseEnum.TOKEN_INVALID);
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("client_id", config.getClientId());
param.put("scope", "files.readwrite.all files.readwrite offline_access");
param.put("refresh_token", context.getAttribute("refresh_token").toString());
param.put("refresh_token", config.getRefreshToken());
param.put("redirect_uri", config.getRedirectUri());
param.put("grant_type", "refresh_token");
param.put("client_secret", config.getClientSecret());

View File

@ -0,0 +1,86 @@
package com.zhu.onemanager.logic.impl;
import cn.hutool.core.lang.Dict;
import cn.hutool.http.HttpUtil;
import com.zhu.onemanager.pojo.OneDriveUploadItem;
import com.zhu.onemanager.utlis.GHttpUtil;
import com.zhu.onemanager.utlis.Strings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
/**
* @author ggBall
* @version 1.0.0
* @ClassName FileUrlImpl.java
* @Description TODO
* @createTime 2022年01月05日 17:06:00
*/
@Service
public class OneDriveItemUrlImpl {
@Value("${microsoft-graph.root-url}")
String rootUrl;
/**
* @Author ggball
* @Description 获取大文件会话
* @Date 2022/1/5
* @Param [driveId, itemId]
* @return java.lang.String
**/
public String createUploadSession(OneDriveUploadItem uploadItem) {
String url = "/drives/%s/items/%s:/%s:/createUploadSession";
return String.format(url,uploadItem.getDriveId(),uploadItem.getItemId(),uploadItem.getFileName());
}
/**
* @Author ggball
* @Description 获取大文件会话
* @Date 2022/1/5
* @Param [driveId, itemId]
* @return java.lang.String
**/
public String createCurUploadSession(OneDriveUploadItem uploadItem) {
String url = "/me/drive/items/%s:/%s:/createUploadSession";
return String.format(url,uploadItem.getItemId(),uploadItem.getFileName());
}
/**
* @Author ggball
* @Description 获取大文件上传url
* @Date 2022/1/6
* @Param [itemId, fileName]
* @return java.lang.String
**/
public String getUploadUrl(OneDriveUploadItem uploadItem) {
String uploadSessionUrl = createUploadSession(uploadItem);
HashMap<String, String> parameter = new HashMap<>();
Dict dict = GHttpUtil.postResDict(rootUrl + uploadSessionUrl, String.valueOf(parameter));
System.out.println("dict = " + dict);
return dict.getStr("uploadUrl");
}
/**
* 获取小文件上传urL
* @param uploadItem
* @return
*/
public String getMiniUploadUrl(OneDriveUploadItem uploadItem) {
String url = "/drives/{drive-id}/items/{parent-id}:/{filename}:/content";
return rootUrl + Strings.solve(url,uploadItem.getDriveId(),uploadItem.getItemId(),uploadItem.getFileName());
}
/**
* 获取当前驱动器小文件上传urL
* @param uploadItem
* @return
*/
public String getCurMiniUploadUrl(OneDriveUploadItem uploadItem) {
String url = "/me/drive/items/{parent-id}:/{filename}:/content";
return rootUrl + Strings.solve(url,uploadItem.getItemId(),uploadItem.getFileName());
}
}

View File

@ -1,33 +0,0 @@
package com.zhu.onemanager.mapper;
import com.zhu.onemanager.pojo.OnedriveConfig;
import com.zhu.onemanager.pojo.OnedriveconfigExample;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface OnedriveconfigMapper {
int countByExample(OnedriveconfigExample example);
int deleteByExample(OnedriveconfigExample example);
int deleteByPrimaryKey(String clientid);
int insert(OnedriveConfig record);
int insertSelective(OnedriveConfig record);
List<OnedriveConfig> selectByExample(OnedriveconfigExample example);
OnedriveConfig selectByPrimaryKey(String clientid);
int updateByExampleSelective(@Param("record") OnedriveConfig record, @Param("example") OnedriveconfigExample example);
int updateByExample(@Param("record") OnedriveConfig record, @Param("example") OnedriveconfigExample example);
int updateByPrimaryKeySelective(OnedriveConfig record);
int updateByPrimaryKey(OnedriveConfig record);
}

View File

@ -17,7 +17,7 @@ import java.util.Date;
* @createTime 2021年12月17日 17:52:00
*/
@Data
public class DriveItem {
public class DriveItem extends Item{
/**
@ -92,6 +92,26 @@ public class DriveItem {
return null;
}
/**
*预览图
*/
public String getPreView() {
if (null != thumbnails && thumbnails.size() > 0) {
JSONObject thumbnailJson = (JSONObject)thumbnails.get(0);
JSONObject mediumImg = (JSONObject)thumbnailJson.get("large");
return mediumImg.getString("url");
}
return null;
}
/**
* 返回父级itemId
* @return
*/
public String getParentId() {
return parentReference.getString("id");
}
@JSONField(name = "@microsoft.graph.downloadUrl")

View File

@ -0,0 +1,11 @@
package com.zhu.onemanager.pojo;
/**
* @author ggBall
* @version 1.0.0
* @ClassName Item.java
* @Description 网盘单个项目
* @createTime 2022年01月05日 17:23:00
*/
public class Item {
}

View File

@ -0,0 +1,49 @@
package com.zhu.onemanager.pojo;
import lombok.Builder;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
/**
* @author ggBall
* @version 1.0.0
* @ClassName OneDriveUploadItem.java
* @Description onedrive 上传对象
* @createTime 2022年01月06日 23:43:00
*/
@Data
@Builder
public class OneDriveUploadItem implements UploadItem{
/**
* 驱动器id
*/
private String driveId;
/**
* driveItem id
*/
private String itemId;
/**
* 文件名
*/
private String fileName;
/**
* 文件大小
*/
private String size;
/**
* 文件
*/
private MultipartFile file;
@Override
public String getUploadUrl() {
return null;
}
}

View File

@ -0,0 +1,13 @@
package com.zhu.onemanager.pojo;
/**
* @author ggBall
* @version 1.0.0
* @ClassName UploadItem.java
* @Description TODO
* @createTime 2022年01月06日 23:42:00
*/
public interface UploadItem {
String getUploadUrl();
}

View File

@ -0,0 +1,27 @@
package com.zhu.onemanager.pojo.vo;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author ggBall
* @version 1.0.0
* @ClassName ItemList.java
* @Description 项目列表
* @createTime 2022年01月07日 02:03:00
*/
@Data
public class ItemListVO implements Serializable {
/**
* 当前项目id
*/
private String curItemId;
/**
* 项目列表
*/
private List itemList;
}

View File

@ -22,8 +22,20 @@ public class R {
this.data = data;
}
public R(ResponseEnum responseEnum, String message) {
this.code = responseEnum.getCode();
this.message = message;
this.data = null;
}
public static R ok(Object data) {
return new R(ResponseEnum.SUCCESS,data);
}
public static R error(String message) {
return new R(ResponseEnum.SYSTEM_ERROR,message);
}
}

View File

@ -7,8 +7,8 @@ public enum ResponseEnum {
SK_BUSY("4001","网络故障"),
ID_NOTFOUND("4002","状态错误"),
LIST_ERROR("4003","数据格式异常"),
Cookie_not_found("4004","Cookie获取失败"),
Token_invalid("4005","Token失效"),
COOKIE_NOT_FOUND("4004","Cookie获取失败"),
TOKEN_INVALID("4005","Token失效"),
PARAMETERS_ARE_MISSING("4006","参数缺失"),
AUTH_CODE_ISNULL("4007","Auth Code 为空"),
THE_RESULT_SET_IS_EMPTY("4008","请求结果集为Null,请联系管理员"),

View File

@ -1,7 +1,11 @@
package com.zhu.onemanager.service;
import com.zhu.onemanager.pojo.OneDriveUploadItem;
import com.zhu.onemanager.result.R;
import java.io.File;
import java.io.IOException;
public interface OnedriveService {
@ -21,5 +25,27 @@ public interface OnedriveService {
* @Param [path]
* @return com.zhu.onemanager.result.R
**/
R children(String path);
R children(String formatPath, String itemId);
/**
* @Author ggball
* @Description 上传大文件
* @Date 2022/1/6
* @Param [file]
* @return com.zhu.onemanager.result.R
**/
R uploadFile(File file);
/**
* @Author ggball
* @Description 上传小文件<=4mb
* @Date 2022/1/6
* @Param [uploadItem]
* @return com.zhu.onemanager.result.R
*
* @param uploadItem*/
R uploadMIniFile(OneDriveUploadItem uploadItem) throws IOException;
}

View File

@ -1,14 +1,22 @@
package com.zhu.onemanager.service.impl;
import cn.hutool.core.lang.Dict;
import com.alibaba.fastjson.JSONArray;
import com.zhu.onemanager.constant.FileConstant;
import com.zhu.onemanager.logic.impl.OneDriveItemUrlImpl;
import com.zhu.onemanager.pojo.DriveItem;
import com.zhu.onemanager.pojo.OneDriveUploadItem;
import com.zhu.onemanager.pojo.vo.ItemListVO;
import com.zhu.onemanager.result.R;
import com.zhu.onemanager.service.OnedriveService;
import com.zhu.onemanager.utlis.GHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -20,10 +28,13 @@ import java.util.Map;
* @createTime 2021年12月17日 13:21:00
*/
@Service
@Slf4j
public class OnedriveServiceImpl implements OnedriveService {
@Value("${microsoft-graph.root-url}")
String rootUrl;
@Resource
OneDriveItemUrlImpl oneDriveItemUrl;
/**
@ -35,17 +46,52 @@ public class OnedriveServiceImpl implements OnedriveService {
**/
@Override
public R getCurrentDriveInfo(String path) {
Map map = GHttpUtil.getMap(rootUrl + FileConstant.PATH_SEPARATOR + path);
Map map = GHttpUtil.getResMap(rootUrl + FileConstant.PATH_SEPARATOR + path);
JSONArray value = (JSONArray)map.get("value");
List<DriveItem> driveItemList = value.toJavaList(DriveItem.class);
return R.ok(driveItemList);
ItemListVO itemListVO = new ItemListVO();
itemListVO.setItemList(driveItemList);
itemListVO.setCurItemId(driveItemList.get(0).getParentId());
return R.ok(itemListVO);
}
@Override
public R children(String path) {
Map map = GHttpUtil.getMap(rootUrl + FileConstant.PATH_SEPARATOR + path);
public R children(String formatPath, String itemId) {
Map map = GHttpUtil.getResMap(rootUrl + FileConstant.PATH_SEPARATOR + formatPath);
JSONArray value = (JSONArray)map.get("value");
List<DriveItem> driveItemList = value.toJavaList(DriveItem.class);
return R.ok(driveItemList);
ItemListVO itemListVO = new ItemListVO();
itemListVO.setItemList(driveItemList);
itemListVO.setCurItemId(itemId);
return R.ok(itemListVO);
}
/**
* @param file
* @return com.zhu.onemanager.result.R
* @Author ggball
* @Description 上传文件
* @Date 2022/1/6
* @Param [file]
*/
@Override
public R uploadFile(File file) {
return null;
}
/**
* @param uploadItem
* @return com.zhu.onemanager.result.R
* @Author ggball
* @Description 上传小文件<=4mb
* @Date 2022/1/6
* @Param [uploadItem]
*/
@Override
public R uploadMIniFile(OneDriveUploadItem uploadItem) throws IOException {
String url = oneDriveItemUrl.getCurMiniUploadUrl(uploadItem);
Dict res = GHttpUtil.put(url, uploadItem.getFile().getBytes(), "text/plain");
log.info("res:{}",res);
return R.ok(res);
}
}

View File

@ -1,42 +1,41 @@
package com.zhu.onemanager.service.impl;/**
* @author: DnsLin
* @Title: SaveConfigImpl
* @ProjectName: Onemanager-java
* @Description:
* @date: 2021/10/31 18:28
*/
import com.zhu.onemanager.exception.AppException;
import com.zhu.onemanager.mapper.OnedriveconfigMapper;
import com.zhu.onemanager.pojo.OnedriveConfig;
import com.zhu.onemanager.result.ResponseEnum;
import com.zhu.onemanager.service.SaveConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SaveConfigImpl implements SaveConfig {
@Autowired
private OnedriveconfigMapper onedriveconfigMapper;
@Override
@Transactional
public void saveOnedriveConfig(OnedriveConfig config) {
if (config == null) {
throw new AppException(ResponseEnum.OBJECT_IS_EMPTY);
}
// 当clientId存在时候 为更新数据 不存在就插入
OnedriveConfig onedriveconfig = onedriveconfigMapper.selectByPrimaryKey(config.getClientId());
if (onedriveconfig == null) {
int state = onedriveconfigMapper.insertSelective(config);
if (state < 1) {
throw new AppException(ResponseEnum.INSERT_THE_FAILURE);
}
}else {
onedriveconfigMapper.updateByPrimaryKey(config);
}
}
}
//package com.zhu.onemanager.service.impl;/**
// * @author: DnsLin
// * @Title: SaveConfigImpl
// * @ProjectName: Onemanager-java
// * @Description:
// * @date: 2021/10/31 18:28
// */
//
//import com.zhu.onemanager.exception.AppException;
//import com.zhu.onemanager.pojo.OnedriveConfig;
//import com.zhu.onemanager.result.ResponseEnum;
//import com.zhu.onemanager.service.SaveConfig;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//
//@Service
//public class SaveConfigImpl implements SaveConfig {
// @Autowired
// private OnedriveconfigMapper onedriveconfigMapper;
//
// @Override
// @Transactional
// public void saveOnedriveConfig(OnedriveConfig config) {
// if (config == null) {
// throw new AppException(ResponseEnum.OBJECT_IS_EMPTY);
// }
// // 当clientId存在时候 为更新数据 不存在就插入
// OnedriveConfig onedriveconfig = onedriveconfigMapper.selectByPrimaryKey(config.getClientId());
// if (onedriveconfig == null) {
// int state = onedriveconfigMapper.insertSelective(config);
// if (state < 1) {
// throw new AppException(ResponseEnum.INSERT_THE_FAILURE);
// }
// }else {
// onedriveconfigMapper.updateByPrimaryKey(config);
// }
//
// }
//}

View File

@ -1,8 +1,7 @@
package com.zhu.onemanager.utlis;
import cn.hutool.http.GlobalHeaders;
import cn.hutool.http.HttpGlobalConfig;
import cn.hutool.http.HttpUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.http.*;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
@ -16,13 +15,39 @@ import java.util.Map;
*/
public class GHttpUtil extends HttpUtil {
public static Map getMap(String urlString) {
/*get请求*/
public static Map getResMap(String urlString) {
String res = get(urlString, HttpGlobalConfig.getTimeout());
return JSONObject.parseObject(res, Map.class);
}
public static Dict getResDict(String urlString) {
Map resMap = getResMap(urlString);
return Dict.parse(resMap);
}
public static Map postResMap(String urlString,String body) {
String res = post(urlString, body);
return JSONObject.parseObject(res, Map.class);
}
/*post请求*/
public static Dict postResDict(String urlString,String body) {
Map resMap = postResMap(urlString,body);
return Dict.parse(resMap);
}
public static void putHeaders(String name,String value) {
GlobalHeaders instance = GlobalHeaders.INSTANCE;
instance.header(name,value);
}
/*put请求*/
public static Dict put(String url,byte[] values,String contentType) {
String res = HttpRequest.put(url).contentType(contentType).body(values).execute().body();
return Dict.parse(JSONObject.parseObject(res, Map.class));
}
}

View File

@ -0,0 +1,100 @@
package com.zhu.onemanager.utlis;
import java.time.temporal.TemporalAccessor;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
/**
* @author ggBall
* @version 1.0.0
* @ClassName ObjectUtils.java
* @Description TODO
* @createTime 2022年01月07日 00:10:00
*/
public class ObjectUtils {
/**
* 如果obj为null则返回默认值不为null则返回obj
*
* @param obj obj
* @param defaultValue 默认值
* @param <T> 值泛型
* @return obj不为null 返回obj否则返回默认值
*/
public static <T> T defaultIfNull(T obj, T defaultValue) {
return obj != null ? obj : defaultValue;
}
//---------------------------------------------------------------------
// 对象类型判断
//---------------------------------------------------------------------
public static boolean isCollection(Object obj) {
return obj instanceof Collection;
}
public static boolean isMap(Object obj) {
return obj instanceof Map;
}
public static boolean isNumber(Object obj) {
return obj instanceof Number;
}
public static boolean isBoolean(Object obj) {
return obj instanceof Boolean;
}
public static boolean isEnum(Object obj) {
return obj instanceof Enum;
}
public static boolean isDate(Object obj) {
return obj instanceof Date || obj instanceof TemporalAccessor;
}
public static boolean isCharSequence(Object obj) {
return obj instanceof CharSequence;
}
/**
* 判断对象是否为八大基本类型包装类除外即(boolean, byte, char, short, int, long, float, and double)<br/>
*
* @param obj
* @return
*/
public static boolean isPrimitive(Object obj) {
return obj != null && obj.getClass().isPrimitive();
}
/**
* 判断对象是否为包装类或者非包装类的基本类型
*
* @param obj
* @return
*/
public static boolean isWrapperOrPrimitive(Object obj) {
return isPrimitive(obj) || isNumber(obj) || isCharSequence(obj) || isBoolean(obj);
}
/**
* 判断一个对象是否为数组
*
* @param obj
* @return
*/
public static boolean isArray(Object obj) {
return obj != null && obj.getClass().isArray();
}
/**
* 判断一个对象是否为基本类型数组即(int[], long[], boolean[], double[]....)
*
* @param obj
* @return
*/
public static boolean isPrimitiveArray(Object obj) {
return isArray(obj) && obj.getClass().getComponentType().isPrimitive();
}
}

View File

@ -0,0 +1,206 @@
package com.zhu.onemanager.utlis;
/**
* @author ggBall
* @version 1.0.0
* @ClassName PlaceholderResolver.java
* @Description TODO
* @createTime 2022年01月07日 00:04:00
*/
import java.util.Map;
import java.util.Properties;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* 占位符解析器
*
*/
public class PlaceholderResolver {
/**
* 默认前缀占位符
*/
public static final String DEFAULT_PLACEHOLDER_PREFIX = "{";
/**
* 默认后缀占位符
*/
public static final String DEFAULT_PLACEHOLDER_SUFFIX = "}";
/**
* 默认单例解析器
*/
private static PlaceholderResolver defaultResolver = new PlaceholderResolver();
/**
* 占位符前缀
*/
private String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;
/**
* 占位符后缀
*/
private String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX;
private PlaceholderResolver(){}
private PlaceholderResolver(String placeholderPrefix, String placeholderSuffix) {
this.placeholderPrefix = placeholderPrefix;
this.placeholderSuffix = placeholderSuffix;
}
/**
* 获取默认的占位符解析器即占位符前缀为"{", 后缀为"}"
* @return
*/
public static PlaceholderResolver getDefaultResolver() {
return defaultResolver;
}
public static PlaceholderResolver getResolver(String placeholderPrefix, String placeholderSuffix) {
return new PlaceholderResolver(placeholderPrefix, placeholderSuffix);
}
/**
* 解析带有指定占位符的模板字符串默认占位符为前缀{ 后缀}<br/><br/>
* template = category:{}:product:{}<br/>
* values = {"1", "2"}<br/>
* 返回 category:1:product:2<br/>
*
* @param content 要解析的带有占位符的模板字符串
* @param values 按照模板占位符索引位置设置对应的值
* @return
*/
public static String solve(String content, String... values) {
int start = content.indexOf(DEFAULT_PLACEHOLDER_PREFIX);
if (start == -1) {
return content;
}
//值索引
int valueIndex = 0;
StringBuilder result = new StringBuilder(content);
while (start != -1) {
int end = result.indexOf(DEFAULT_PLACEHOLDER_SUFFIX);
String replaceContent = values[valueIndex++];
result.replace(start, end + DEFAULT_PLACEHOLDER_SUFFIX.length(), replaceContent);
start = result.indexOf(DEFAULT_PLACEHOLDER_PREFIX, start + replaceContent.length());
}
return result.toString();
}
/**
* 解析带有指定占位符的模板字符串默认占位符为前缀{ 后缀}<br/><br/>
* template = category:{}:product:{}<br/>
* values = {"1", "2"}<br/>
* 返回 category:1:product:2<br/>
*
* @param content 要解析的带有占位符的模板字符串
* @param values 按照模板占位符索引位置设置对应的值
* @return
*/
public String resolve(String content, String... values) {
int start = content.indexOf(this.placeholderPrefix);
if (start == -1) {
return content;
}
//值索引
int valueIndex = 0;
StringBuilder result = new StringBuilder(content);
while (start != -1) {
int end = result.indexOf(this.placeholderSuffix);
String replaceContent = values[valueIndex++];
result.replace(start, end + this.placeholderSuffix.length(), replaceContent);
start = result.indexOf(this.placeholderPrefix, start + replaceContent.length());
}
return result.toString();
}
/**
* 解析带有指定占位符的模板字符串默认占位符为前缀{ 后缀}<br/><br/>
* template = category:{}:product:{}<br/>
* values = {"1", "2"}<br/>
* 返回 category:1:product:2<br/>
*
* @param content 要解析的带有占位符的模板字符串
* @param values 按照模板占位符索引位置设置对应的值
* @return
*/
public String resolve(String content, Object[] values) {
return resolve(content, Stream.of(values).map(String::valueOf).toArray(String[]::new));
}
/**
* 根据替换规则来替换指定模板中的占位符值
* @param content 要解析的字符串
* @param rule 解析规则回调
* @return
*/
public String resolveByRule(String content, Function<String, String> rule) {
int start = content.indexOf(this.placeholderPrefix);
if (start == -1) {
return content;
}
StringBuilder result = new StringBuilder(content);
while (start != -1) {
int end = result.indexOf(this.placeholderSuffix, start);
//获取占位符属性值{id}, 即获取id
String placeholder = result.substring(start + this.placeholderPrefix.length(), end);
//替换整个占位符内容即将{id}值替换为替换规则回调中的内容
String replaceContent = placeholder.trim().isEmpty() ? "" : rule.apply(placeholder);
result.replace(start, end + this.placeholderSuffix.length(), replaceContent);
start = result.indexOf(this.placeholderPrefix, start + replaceContent.length());
}
return result.toString();
}
/**
* 替换模板中占位符内容占位符的内容即为map key对应的值key为占位符中的内容<br/><br/>
* content = product:{id}:detail:{did}<br/>
* valueMap = id -> 1; pid -> 2<br/>
* 经过解析返回 product:1:detail:2<br/>
*
* @param content 模板内容
* @param valueMap 值映射
* @return 替换完成后的字符串
*/
public String resolveByMap(String content, final Map<String, Object> valueMap) {
return resolveByRule(content, placeholderValue -> String.valueOf(valueMap.get(placeholderValue)));
}
/**
* 根据properties文件替换占位符内容
* @param content
* @param properties
* @return
*/
public String resolveByProperties(String content, final Properties properties) {
return resolveByRule(content, placeholderValue -> properties.getProperty(placeholderValue));
}
/**
* 根据对象中字段路径(即类似js访问对象属性值)替换模板中的占位符 <br/><br/>
* content = product:{id}:detail:{detail.id} <br/>
* obj = Product.builder().id(1).detail(Detail.builder().id(2).build()).build(); <br/>
* 经过解析返回 product:1:detail:2 <br/>
*
* @param content 要解析的内容
* @param obj 填充解析内容的对象(如果是基本类型则所有占位符替换为相同的值)
* @return
*/
public String resolveByObject(String content, final Object obj) {
if (obj instanceof Map) {
return resolveByMap(content, (Map)obj);
}
return resolveByRule(content, placeholderValue -> String.valueOf(ReflectionUtils.getValueByFieldPath(obj, placeholderValue)));
}
public static void main(String[] args) {
String solve = PlaceholderResolver.solve("你好{},ss{}", "1", "2");
String solve2 = PlaceholderResolver.solve("你好{},ss{}", "7", "8");
System.out.println("solve = " + solve);
}
}

View File

@ -0,0 +1,256 @@
package com.zhu.onemanager.utlis;
import org.springframework.util.Assert;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
/**
* @author ggBall
* @version 1.0.0
* @ClassName ReflectionUtils.java
* @Description TODO
* @createTime 2022年01月07日 00:08:00
*/
public final class ReflectionUtils {
/**
* 获取所有field字段包含父类继承的
*
* @param clazz 字段所属类型
* @return
*/
public static Field[] getFields(Class<?> clazz) {
return getFields(clazz, null);
}
/**
* 获取指定类的所有的field,包括父类
*
* @param clazz 字段所属类型
* @param fieldFilter 字段过滤器
* @return 符合过滤器条件的字段数组
*/
public static Field[] getFields(Class<?> clazz, Predicate<Field> fieldFilter) {
List<Field> fields = new ArrayList<>(32);
while (Object.class != clazz && clazz != null) {
// 获得该类所有声明的字段即包括publicprivate和protected但是不包括父类的申明字段
// getFields获得某个类的所有的公共public的字段包括父类中的字段
for (Field field : clazz.getDeclaredFields()) {
if (fieldFilter != null && !fieldFilter.test(field)) {
continue;
}
fields.add(field);
}
clazz = clazz.getSuperclass();
}
return fields.toArray(new Field[0]);
}
/**
* 对指定类的所有字段执行consumer操作
*
* @param clazz 目标对象
* @param consumer 对字段进行操作
*/
public static void doWithFields(Class<?> clazz, Consumer<Field> consumer) {
Arrays.stream(getFields(clazz)).forEach(consumer);
}
/**
* 获取指定类的指定field,包括父类
*
* @param clazz 字段所属类型
* @param name 字段名
* @return
*/
public static Field getField(Class<?> clazz, String name) {
return getField(clazz, name, null);
}
/**
* 获取指定类的指定field,包括父类
*
* @param clazz 字段所属类型
* @param name 字段名
* @param type field类型
* @return Field对象
*/
public static Field getField(Class<?> clazz, String name, Class<?> type) {
Assert.notNull(clazz, "clazz不能为空");
while (clazz != Object.class && clazz != null) {
for (Field field : clazz.getDeclaredFields()) {
if ((name == null || name.equals(field.getName())) &&
(type == null || type.equals(field.getType()))) {
return field;
}
}
clazz = clazz.getSuperclass();
}
return null;
}
/**
* 获取字段值
*
* @param field 字段
* @param target 字段所属实例对象
* @return 字段值
*/
public static Object getFieldValue(Field field, Object target) {
makeAccessible(field);
try {
return field.get(target);
} catch (Exception e) {
throw new IllegalStateException(String.format("获取%s对象的%s字段值错误!"
, target.getClass().getName(), field.getName()), e);
}
}
/**
* 获取对象中指定field值
*
* @param obj 对象
* @param fieldName 字段名
* @return 字段值
*/
public static Object getFieldValue(Object obj, String fieldName) {
Assert.notNull(obj, "obj不能为空!");
if (ObjectUtils.isWrapperOrPrimitive(obj)) {
return obj;
}
return getFieldValue(getField(obj.getClass(), fieldName), obj);
}
/**
* 获取指定对象中指定字段路径的值(类似js访问对象属性) <br/>
* Product p = new Product(new User()) <br/>
* 可使用ReflectionUtils.getValueByFieldPath(p, "user.name")获取到用户的name属性
*
* @param obj 取值对象
* @param fieldPath 字段路径(形如 user.name)
* @return 字段value
*/
public static Object getValueByFieldPath(Object obj, String fieldPath) {
String[] fieldNames = fieldPath.split("\\.");
Object result = null;
for (String fieldName : fieldNames) {
result = getFieldValue(obj, fieldName);
if (result == null) {
return null;
}
obj = result;
}
return result;
}
/**
* 设置字段值
*
* @param field 字段
* @param target 字段所属对象实例
* @param value 需要设置的值
*/
public static void setFieldValue(Field field, Object target, Object value) {
makeAccessible(field);
try {
field.set(target, value);
} catch (Exception e) {
throw new IllegalStateException(String.format("设置%s对象的%s字段值错误!"
, target.getClass().getName(), field.getName()), e);
}
}
/**
* 设置字段为可见
*
* @param field
*/
public static void makeAccessible(Field field) {
if ((!Modifier.isPublic(field.getModifiers()) ||
!Modifier.isPublic(field.getDeclaringClass().getModifiers()) ||
Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
field.setAccessible(true);
}
}
/**
* 调用无参数方法
*
* @param method 方法对象
* @param target 调用对象
* @return 执行结果
*/
public static Object invokeMethod(Method method, Object target) {
return invokeMethod(method, target, new Object[0]);
}
/**
* 调用指定对象的方法
*
* @param method 方法对象
* @param target 调用对象
* @param args 方法参数
* @return 执行结果
*/
public static Object invokeMethod(Method method, Object target, Object... args) {
try {
makeAccessible(method);
return method.invoke(target, args);
} catch (Exception ex) {
throw new IllegalStateException(String.format("执行%s.%s()方法错误!"
, target.getClass().getName(), method.getName()), ex);
}
}
/**
* 设置方法可见性
*
* @param method 方法
*/
public static void makeAccessible(Method method) {
if ((!Modifier.isPublic(method.getModifiers()) ||
!Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) {
method.setAccessible(true);
}
}
/**
* 是否为equals方法
*
* @see java.lang.Object#equals(Object)
*/
public static boolean isEqualsMethod(Method method) {
if (!"equals".equals(method.getName())) {
return false;
}
Class<?>[] paramTypes = method.getParameterTypes();
return (paramTypes.length == 1 && paramTypes[0] == Object.class);
}
/**
* 是否为hashCode方法
*
* @see java.lang.Object#hashCode()
*/
public static boolean isHashCodeMethod(Method method) {
return "hashCode".equals(method.getName()) && method.getParameterCount() == 0;
}
/**
* 是否为Object的toString方法
*
* @see java.lang.Object#toString()
*/
public static boolean isToStringMethod(Method method) {
return "toString".equals(method.getName()) && method.getParameterCount() == 0;
}
}

View File

@ -0,0 +1,46 @@
package com.zhu.onemanager.utlis;
/**
* @author ggBall
* @version 1.0.0
* @ClassName Strings.java
* @Description TODO
* @createTime 2022年01月07日 00:23:00
*/
public class Strings {
/**
* @Author ggball
* @Description 解析占位符
* @Date 2022/1/7
* @Param [content 模板, values ]
* @return java.lang.String
**/
public static String solve(String content, String... values) {
return PlaceholderResolver.solve(content,values);
}
/**
* @Author ggball
* @Description 头部添加字符
* @Date 2022/1/7
* @Param [content, value]
* @return java.lang.String
**/
public static String insert(String content,String value) {
return value + content;
}
/**
* @Author ggball
* @Description 尾部添加字符
* @Date 2022/1/7
* @Param [content, value]
* @return java.lang.String
**/
public static String append(String content,String value) {
return content + value;
}
}

View File

@ -1,23 +1,10 @@
spring:
datasource:
druid:
url: jdbc:mysql://127.0.0.1:3306/onemanager?useUnicode=true&characterEncoding=utf-8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
initial-size: 10
max-active: 50
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
validation-query: SELECT 1 FROM DUAL
resources:
static-locations: classpath:/
logging:
level:
root: info
com.dnslin.onemanager: debug
com.zhu.onemanager: debug
server:
port: 8081

View File

@ -0,0 +1,27 @@
spring:
resources:
static-locations: classpath:/
logging:
level:
root: info
com.dnslin.onemanager: debug
server:
port: 8881
servlet:
context-path: /oneManagerjava
onedrive:
clientSecret: q847Q~yGYv6_GasCcKRaLF4syQUqpVz5D_HoH
scope: offline_access User.Read openid Mail.Read
redirectUri: http://localhost:8081/api/outlook
clientId: 0d5e84db-18cf-4ab7-bc67-4af2dc9bce6b
authenticateEndPoint: login.microsoftonline.com
# 文件应用密钥信息
file:
clientSecret: wfy7Q~0R2MmSF6Zl3YRTcXxkGF0L8XOb_CL7k
scope: offline_access Files.Read Files.ReadWrite Files.Read.All Files.ReadWrite.All
redirectUri: https://ggball.top/oneManagerjava/api/file/auth
clientId: 526c05e9-5e68-4178-aa62-43f70ba4ae96
authenticateEndPoint: login.microsoftonline.com
microsoft-graph:
root-url: https://graph.microsoft.com/v1.0

View File

@ -1,7 +1,7 @@
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/onemanager?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.user=root
jdbc.password=root
group.package=com.dnslin.onemanager
catalog.name=onemanager
#jdbc.driverClass=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://127.0.0.1:3306/onemanager?useUnicode=true&characterEncoding=utf-8&useSSL=false
#jdbc.user=root
#jdbc.password=root
#
#group.package=com.dnslin.onemanager
#catalog.name=onemanager

View File

@ -1,228 +0,0 @@
<?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="com.dnslin.onemanager.mapper.OnedriveconfigMapper" >
<resultMap id="BaseResultMap" type="com.zhu.onemanager.pojo.OnedriveConfig" >
<id column="clientId" property="clientid" jdbcType="VARCHAR" />
<result column="redirectUrl" property="redirecturl" jdbcType="VARCHAR" />
<result column="clientSecret" property="clientsecret" jdbcType="VARCHAR" />
<result column="accessToken" property="accesstoken" jdbcType="VARCHAR" />
<result column="refreshToken" property="refreshtoken" jdbcType="VARCHAR" />
<result column="expires" property="expires" jdbcType="BIGINT" />
</resultMap>
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List" >
clientId, redirectUrl, clientSecret, accessToken, refreshToken, expires
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.zhu.onemanager.pojo.OnedriveconfigExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from onedriveconfig
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from onedriveconfig
where clientId = #{clientid,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from onedriveconfig
where clientId = #{clientid,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="com.zhu.onemanager.pojo.OnedriveconfigExample" >
delete from onedriveconfig
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.zhu.onemanager.pojo.OnedriveConfig" >
insert into onedriveconfig (clientId, redirectUrl, clientSecret,
accessToken, refreshToken, expires
)
values (#{clientid,jdbcType=VARCHAR}, #{redirecturl,jdbcType=VARCHAR}, #{clientsecret,jdbcType=VARCHAR},
#{accesstoken,jdbcType=VARCHAR}, #{refreshtoken,jdbcType=VARCHAR}, #{expires,jdbcType=BIGINT}
)
</insert>
<insert id="insertSelective" parameterType="com.zhu.onemanager.pojo.OnedriveConfig" >
insert into onedriveconfig
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="clientid != null" >
clientId,
</if>
<if test="redirecturl != null" >
redirectUrl,
</if>
<if test="clientsecret != null" >
clientSecret,
</if>
<if test="accesstoken != null" >
accessToken,
</if>
<if test="refreshtoken != null" >
refreshToken,
</if>
<if test="expires != null" >
expires,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="clientid != null" >
#{clientid,jdbcType=VARCHAR},
</if>
<if test="redirecturl != null" >
#{redirecturl,jdbcType=VARCHAR},
</if>
<if test="clientsecret != null" >
#{clientsecret,jdbcType=VARCHAR},
</if>
<if test="accesstoken != null" >
#{accesstoken,jdbcType=VARCHAR},
</if>
<if test="refreshtoken != null" >
#{refreshtoken,jdbcType=VARCHAR},
</if>
<if test="expires != null" >
#{expires,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.zhu.onemanager.pojo.OnedriveconfigExample" resultType="java.lang.Integer" >
select count(*) from onedriveconfig
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update onedriveconfig
<set >
<if test="record.clientid != null" >
clientId = #{record.clientid,jdbcType=VARCHAR},
</if>
<if test="record.redirecturl != null" >
redirectUrl = #{record.redirecturl,jdbcType=VARCHAR},
</if>
<if test="record.clientsecret != null" >
clientSecret = #{record.clientsecret,jdbcType=VARCHAR},
</if>
<if test="record.accesstoken != null" >
accessToken = #{record.accesstoken,jdbcType=VARCHAR},
</if>
<if test="record.refreshtoken != null" >
refreshToken = #{record.refreshtoken,jdbcType=VARCHAR},
</if>
<if test="record.expires != null" >
expires = #{record.expires,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update onedriveconfig
set clientId = #{record.clientid,jdbcType=VARCHAR},
redirectUrl = #{record.redirecturl,jdbcType=VARCHAR},
clientSecret = #{record.clientsecret,jdbcType=VARCHAR},
accessToken = #{record.accesstoken,jdbcType=VARCHAR},
refreshToken = #{record.refreshtoken,jdbcType=VARCHAR},
expires = #{record.expires,jdbcType=BIGINT}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.zhu.onemanager.pojo.OnedriveConfig" >
update onedriveconfig
<set >
<if test="redirecturl != null" >
redirectUrl = #{redirecturl,jdbcType=VARCHAR},
</if>
<if test="clientsecret != null" >
clientSecret = #{clientsecret,jdbcType=VARCHAR},
</if>
<if test="accesstoken != null" >
accessToken = #{accesstoken,jdbcType=VARCHAR},
</if>
<if test="refreshtoken != null" >
refreshToken = #{refreshtoken,jdbcType=VARCHAR},
</if>
<if test="expires != null" >
expires = #{expires,jdbcType=BIGINT},
</if>
</set>
where clientId = #{clientid,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.zhu.onemanager.pojo.OnedriveConfig" >
update onedriveconfig
set redirectUrl = #{redirecturl,jdbcType=VARCHAR},
clientSecret = #{clientsecret,jdbcType=VARCHAR},
accessToken = #{accesstoken,jdbcType=VARCHAR},
refreshToken = #{refreshtoken,jdbcType=VARCHAR},
expires = #{expires,jdbcType=BIGINT}
where clientId = #{clientid,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -2,6 +2,7 @@
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"'
})
module.exports = {
NODE_ENV: '"development"',
BASE_URL:'"http://localhost:8081/"'
}

View File

@ -1,4 +1,6 @@
'use strict'
module.exports = {
NODE_ENV: '"production"'
NODE_ENV: '"production"',
// BASE_URL:'"https://ggball.top/oneManagerjava/"'
BASE_URL:'"http://localhost:8081/"'
}

File diff suppressed because it is too large Load Diff

View File

@ -6,21 +6,24 @@
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"prod": "webpack-dev-server --inline --progress --config build/webpack.prod.conf.js",
"start": "npm run dev",
"unit": "jest --config test/unit/jest.conf.js --coverage",
"e2e": "node test/e2e/runner.js",
"test": "npm run unit && npm run e2e",
"lint": "eslint --ext .js,.vue src test/unit test/e2e/specs",
"build": "node build/build.js"
"build-prod": "node build/build.js --config build/webpack.prod.conf.js",
"build-dev": "node build/build.js --config build/webpack.dev.conf.js"
},
"dependencies": {
"axios": "^0.24.0",
"css-loader": "^0.28.11",
"element-ui": "^2.0.0-rc.1",
"vue": "^2.5.2",
"vue-router": "^3.0.1",
"file-loader": "^1.1.11",
"sass-loader": "^7.1.0",
"css-loader": "^0.28.11"
"vue": "^2.5.2",
"vue-pdf": "^4.3.0",
"vue-router": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",

View File

@ -1,15 +0,0 @@
<template>
<div>
<input type="text" placeholder="写点什么吧">
</div>
</template>
<script>
export default {
name: 'Demo'
}
</script>
<style scoped>
</style>

View File

@ -1,10 +1,23 @@
<template>
<div id="table">
<el-row :gutter="20">
<el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
<el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
<el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
<el-col :span="6">
<el-row :gutter="24">
<el-col :span="1">
<el-button size="small" type="danger">删除</el-button>
</el-col>
<el-col :span="1">
<el-upload
class="upload-demo"
:action="uploadUrl"
:data="uploadExtraData"
:show-file-list="false"
:on-success="uploadSuccess"
:on-error="uploadError"
:on-exceed="handleExceed">
<el-button size="small" type="primary">上传</el-button>
<!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件且不超过500kb</div>-->
</el-upload>
</el-col>
<el-col :span="3">
<el-switch
v-model="isThumbnail"
active-text="缩略图模式"
@ -13,10 +26,37 @@
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="18">
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/layout' }">/</el-breadcrumb-item>
<el-breadcrumb-item v-for="(pathItem,index) in pathList" :key="index">
{{pathItem}}
</el-breadcrumb-item>
</el-breadcrumb>
</el-col>
</el-row>
<el-table
style="width: 100%"
v-loading="loading"
:data="fileList"
>
<el-table-column
prop="id"
label="id"
v-if="false"
></el-table-column>
<el-table-column
prop="preView"
label="preView"
v-if="false"
></el-table-column>
<el-table-column
prop="name"
label="文件名"
@ -29,7 +69,11 @@
v-if="isThumbnail"
>
<template slot-scope="scope">
<img :src="scope.row.thumbnail" min-width="70" height="70" />
<el-image
style="width: 70px; height: 70px"
:src="scope.row.thumbnail"
:preview-src-list=[scope.row.preView]
></el-image>
</template>
</el-table-column>
<el-table-column
@ -50,13 +94,24 @@
width="180"
>
<template slot-scope="scope">
<el-link :href="scope.row.downloadUrl" :underline="false" style="margin-left:15px">
<el-button
<el-link
:href="scope.row.downloadUrl"
:underline="false"
v-if="scope.row.itemType == 'folder' ? false : true"
style="margin-left:15px">
<el-button type="primary"
size="mini"
>{{scope.row.itemType == 'file' ? '下载' : '查看'}}</el-button>
>下载</el-button>
</el-link>
<el-button
type="primary"
size="mini"
v-on:click="checkChildren(scope.row);addPath(scope.row);"
v-if="scope.row.itemType == 'folder' ? true : false"
>查看</el-button>
</template>
</el-table-column>
</el-table>
</div>
@ -66,26 +121,57 @@
<script>
import axios from 'axios'
const baseUrl = 'http://localhost:8081/'
var env = process.env
const baseUrl = env.BASE_URL === 'undefined' ? 'http://localhost:8081/' : env.BASE_URL
export default {
name: 'Table',
created () {
mounted () {
this.index()
},
data () {
return {
// itemId
curItemId:"",
//
fileList: [],
//
isThumbnail: false,
//
loading: true,
//
pathList:[],
//
uploadUrl: baseUrl+"oneDrive/upload",
//
uploadExtraData: {}
}
},
watch: {
//
isThumbnail: 'watchThumbnail'
isThumbnail: 'watchThumbnail',
curItemId: 'buildUploadExtraData'
},
methods: {
//
refresh() {
this.checkChildren(this.curItemId)
},
//
checkChildren(row) {
console.log(row.id);
this.children(row.id);
},
//
addPath(raw) {
this.pathList.push(raw.name)
},
//
watchThumbnail(curVal,oldVal) {
// if false -> true reIndex
if (oldVal == false && curVal == true) {
@ -94,11 +180,10 @@ export default {
// console.log(curVal,oldVal);
},
handleDownload (index, row) {
console.log(index, row)
},
//
index () {
this.loading = true;
const that = this
return axios
.get(baseUrl + 'oneDrive/index',{
@ -108,7 +193,10 @@ export default {
})
.then(response => {
console.log(response.data.data)
that.fileList = response.data.data
this.fileList = response.data.data.itemList
this.curItemId = response.data.data.curItemId
console.log(this.curItemId)
this.loading = false;
return response.data.data
})
.catch(function (error) {
@ -116,6 +204,59 @@ export default {
})
},
// itemId
children(itemId) {
this.loading = true;
return axios
.get(baseUrl + 'oneDrive/'+itemId+'/children',{
params: {
thumbnail: this.isThumbnail
}
})
.then(response => {
console.log(response.data.data)
this.fileList = response.data.data.itemList
this.curItemId = response.data.data.curItemId
this.loading = false;
return response.data.data
})
.catch(function (error) {
console.log(error)
})
},
//
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePreview(file) {
console.log(file);
},
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${ file.name }`);
},
uploadSuccess(response, file, fileList) {
this.$message({
message: '上传成功',
type: 'success'
});
this.index()
},
uploadError(err, file, fileList) {
this.$message({
message: '上传失败',
type: 'error'
});
},
//
buildUploadExtraData () {
this.uploadExtraData = {"itemId":this.curItemId}
},
//
bytesToSize (item) {
var bytes = item.size

View File

@ -0,0 +1,31 @@
<template>
<div>
<el-steps :active="active" finish-status="success">
<el-step title="授权"></el-step>
<el-step title="获取token"></el-step>
</el-steps>
<el-button style="margin-top: 12px;" @click="next">下一步</el-button>
</div>
</template>
<script>
export default {
name: 'auth',
data() {
return {
active: 0
};
},
methods: {
next() {
if (this.active++ > 2) this.active = 0;
}
}
}
</script>
<style scoped>
</style>

View File

@ -12,8 +12,8 @@
background-color="#545c64"
text-color="#fff"
active-text-color="#ffd04b">
<el-menu-item index="1"><a :href="tokenUrl" target="_blank" style="text-decoration: none;" >授权</a></el-menu-item>
<el-menu-item index="2">网盘</el-menu-item>
<el-menu-item index="auth" id="auth"><a :href="tokenUrl" target="_blank" style="text-decoration: none;" >授权</a></el-menu-item>
<el-menu-item index="table" id="table">网盘列表</el-menu-item>
<!-- <el-menu-item index="3" disabled>消息中心</el-menu-item>-->
</el-menu>
</el-header>
@ -26,6 +26,11 @@
</template>
<script>
var env = process.env
const baseUrl = env.BASE_URL
export default {
name: 'navbar',
data () {
@ -33,13 +38,15 @@ export default {
msg: 'Welcome to Your Vue.js App',
activeIndex: '1',
activeIndex2: '0',
tokenUrl: 'https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id=526c05e9-5e68-4178-aa62-43f70ba4ae96&redirect_uri=http://localhost:8081/api/file/auth'
tokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id=526c05e9-5e68-4178-aa62-43f70ba4ae96&redirect_uri='+baseUrl+'api/file/auth&scope=offline_access Files.Read Files.ReadWrite Files.Read.All Files.ReadWrite.All'
}
},
methods: {
handleSelect (key, keyPath) {
console.log(key, keyPath)
}
console.log(key);
this.$emit('tableValue',key);
},
}
}
</script>

View File

@ -17,5 +17,10 @@ export default new Router({
name: 'Table',
component: Table
},
{
path: '/layout',
name: 'Layout',
component: Layout
},
]
})

View File

@ -2,12 +2,13 @@
<div id="layout">
<el-container>
<el-header>
<navbar/>
<navbar @tableValue="changeMain"/>
</el-header>
<el-main>
<Table/>
<Table v-if="tabValue === 'table'"/>
<auth v-if="tabValue === 'auth'"/>
</el-main>
<el-footer>Footer</el-footer>
<!-- <el-footer>Footer</el-footer>-->
</el-container>
</div>
</template>
@ -16,18 +17,30 @@
import navbar from '../components/navbar'
import Table from '../components/Table'
import auth from '../components/auth'
export default {
name: 'Layout',
components: {
navbar,
Table
Table,
auth
},
data () {
return {
tabValue: "",
}
},
methods: {
handleDownload (index, row) {
console.log(index, row)
}
},
changeMain(e) {
console.log('changeMain'+e);
this.tabValue = e;
},
// fetchData() {
// index().then((response) => {

18
start.bat Normal file
View File

@ -0,0 +1,18 @@
@echo off
echo 当前批处理全路径:%~f0
# 删除静态文件目录
rd /s /q src/main/resources/static
rd /s /q src/main/resources/templates
echo '删除静态文件夹成功'
cd src\main\resources\webapp
# 生成静态文件
npm run build & cd ../../../../ & mvn clean -DskipTests=true package
echo '生成静态文件成功'

1
start.sh Normal file
View File

@ -0,0 +1 @@
java -jar oneManager-java.jar --spring.profiles.active=prod