调整配置,删除WPS模块
This commit is contained in:
parent
65e9e0f7c8
commit
c97a2d0c24
@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
|
||||
public class FileProperties {
|
||||
|
||||
private String uploadPath;
|
||||
private Boolean unique;
|
||||
private String imageTypes;
|
||||
private String videoTypes;
|
||||
private String audioTypes;
|
||||
@ -32,6 +33,14 @@ public class FileProperties {
|
||||
this.uploadPath = uploadPath;
|
||||
}
|
||||
|
||||
public Boolean getUnique() {
|
||||
return unique == null ? false : unique;
|
||||
}
|
||||
|
||||
public void setUnique(Boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
public String getImageTypes() {
|
||||
return imageTypes == null ? null : imageTypes.trim();
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package ink.wgink.properties.onlyoffice;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName: OnlyOfficeProperties
|
||||
* @Description: OnlyOffice配置
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/7/25 10:31
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "only-office")
|
||||
public class OnlyOfficeProperties {
|
||||
|
||||
private String server;
|
||||
|
||||
public String getServer() {
|
||||
return server == null ? "" : server.trim();
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package ink.wgink.properties.web;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName: WebProperties
|
||||
* @Description: 网站配置
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/7/25 19:56
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "web")
|
||||
public class WebProperties {
|
||||
|
||||
/**
|
||||
* 位置
|
||||
*/
|
||||
private String path;
|
||||
|
||||
public String getPath() {
|
||||
return path == null ? "" : path.trim();
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package ink.wgink.properties.wps;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsProperties
|
||||
* @Description: wps配置
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 20:50
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "wps")
|
||||
public class WpsProperties {
|
||||
|
||||
private String url;
|
||||
private String appId;
|
||||
private String appSecret;
|
||||
|
||||
public String getUrl() {
|
||||
return url == null ? "" : url.trim();
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId == null ? "" : appId.trim();
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public String getAppSecret() {
|
||||
return appSecret == null ? "" : appSecret.trim();
|
||||
}
|
||||
|
||||
public void setAppSecret(String appSecret) {
|
||||
this.appSecret = appSecret;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package ink.wgink.module.wps.consts;
|
||||
|
||||
/**
|
||||
* @ClassName: IWpsConsts
|
||||
* @Description: wps常量
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 21:21
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IWpsConsts {
|
||||
|
||||
String KEY_APP_ID = "_w_appid";
|
||||
String KEY_FILE_ID = "_w_fileid";
|
||||
String KEY_TOKEN_TYPE = "_w_tokentype";
|
||||
String KEY_SIGNATURE = "_w_signature";
|
||||
String KEY_SECRET_KEY = "_w_secretkey";
|
||||
String HEADER_WPS_WEB_OFFICE_TOKEN = "x-wps-weboffice-token";
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package ink.wgink.module.wps.controller.api;
|
||||
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.wps.consts.IWpsConsts;
|
||||
import ink.wgink.module.wps.pojo.dtos.WpsFileInfoDTO;
|
||||
import ink.wgink.module.wps.pojo.dtos.WpsSaveFileInfoDTO;
|
||||
import ink.wgink.module.wps.service.IWpsService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsController
|
||||
* @Description: WPS
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/22 09:22
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "wps")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.API_PREFIX + "/wps")
|
||||
public class WpsController {
|
||||
|
||||
@Autowired
|
||||
private IWpsService wpsService;
|
||||
|
||||
@ApiOperation(value = "保存文件", notes = "保存文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "_w_fileid", value = "文件ID", paramType = "form"),
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("v1/3rd/file/save")
|
||||
public WpsSaveFileInfoDTO save(@RequestHeader(IWpsConsts.HEADER_WPS_WEB_OFFICE_TOKEN) String wpsToken, @RequestParam(IWpsConsts.KEY_FILE_ID) String fileId, @RequestParam("file") MultipartFile file) {
|
||||
return wpsService.save(wpsToken, fileId, file);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "文件详情", notes = "文件详情接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "_w_fileid", value = "文件ID", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("v1/3rd/file/info")
|
||||
public WpsFileInfoDTO getFileInfo(@RequestHeader(IWpsConsts.HEADER_WPS_WEB_OFFICE_TOKEN) String wpsToken, @RequestParam(IWpsConsts.KEY_FILE_ID) String fileId) {
|
||||
return wpsService.getFileInfo(wpsToken, fileId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "文件下载", notes = "文件下载接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "fileId", value = "文件ID", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("download/{fileId}")
|
||||
public ResponseEntity<byte[]> download(@PathVariable("fileId") String fileId) throws Exception {
|
||||
return wpsService.download(fileId);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package ink.wgink.module.wps.controller.route;
|
||||
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.wps.enums.WpsPermissionEnum;
|
||||
import ink.wgink.module.wps.pojo.bos.WpsTokenBO;
|
||||
import ink.wgink.module.wps.service.IWpsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsRouteController
|
||||
* @Description: wps
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 23:30
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "wps路由接口")
|
||||
@Controller
|
||||
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/wps")
|
||||
public class WpsRouteController {
|
||||
|
||||
@Autowired
|
||||
private IWpsService wpsService;
|
||||
|
||||
@GetMapping("get/{fileId}")
|
||||
public ModelAndView get(@PathVariable("fileId") String fileId) throws UnsupportedEncodingException {
|
||||
ModelAndView mv = getBaseMV(WpsPermissionEnum.READ, fileId);
|
||||
mv.setViewName("wps/wps");
|
||||
return mv;
|
||||
}
|
||||
|
||||
@GetMapping("update/{fileId}")
|
||||
public ModelAndView update(@PathVariable("fileId") String fileId) throws UnsupportedEncodingException {
|
||||
ModelAndView mv = getBaseMV(WpsPermissionEnum.WRITE, fileId);
|
||||
mv.setViewName("wps/wps");
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基础ModelAndView
|
||||
*
|
||||
* @param fileId
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private ModelAndView getBaseMV(WpsPermissionEnum wpsPermissionEnum, String fileId) throws UnsupportedEncodingException {
|
||||
WpsTokenBO wpsTokenBO = wpsService.getToken(wpsPermissionEnum, fileId);
|
||||
ModelAndView mv = new ModelAndView();
|
||||
mv.addObject("wpsUrl", wpsTokenBO.getWpsUrl());
|
||||
mv.addObject("token", wpsTokenBO.getToken());
|
||||
return mv;
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package ink.wgink.module.wps.enums;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsPermissionEnums
|
||||
* @Description: WPS权限
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 23:44
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public enum WpsPermissionEnum {
|
||||
READ("read", "读"),
|
||||
WRITE("write", "写");
|
||||
|
||||
private String value;
|
||||
private String text;
|
||||
|
||||
WpsPermissionEnum(String value, String text) {
|
||||
this.value = value;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text == null ? "" : text.trim();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package ink.wgink.module.wps.pojo.bos;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsTokenDTO
|
||||
* @Description:
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 21:38
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@ApiModel
|
||||
public class WpsTokenBO {
|
||||
|
||||
@ApiModelProperty(name = "wpsUrl", value = "wps链接")
|
||||
private String wpsUrl;
|
||||
@ApiModelProperty(name = "token", value = "token")
|
||||
private String token;
|
||||
|
||||
public String getWpsUrl() {
|
||||
return wpsUrl == null ? "" : wpsUrl.trim();
|
||||
}
|
||||
|
||||
public void setWpsUrl(String wpsUrl) {
|
||||
this.wpsUrl = wpsUrl;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token == null ? "" : token.trim();
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
@ -1,331 +0,0 @@
|
||||
package ink.wgink.module.wps.pojo.dtos;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsFileInfoDTO
|
||||
* @Description: WPS文件类型
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/22 09:24
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@ApiModel
|
||||
public class WpsFileInfoDTO {
|
||||
|
||||
private File file;
|
||||
private User user;
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public static class File {
|
||||
@ApiModelProperty(name = "id", value = "文件id,字符串长度小于40,和 URL 中的fileid必须一致(https://wwo.wps.cn/office/<:type>/<:fileid>?_w_appid=xxx) (必填)")
|
||||
private String id;
|
||||
@ApiModelProperty(name = "name", value = "文件名(必须带文件后缀) (必填)")
|
||||
private String name;
|
||||
@ApiModelProperty(name = "version", value = "当前版本号,必须大于 0,同时位数小于 11 (必填)")
|
||||
private Integer version;
|
||||
@ApiModelProperty(name = "size", value = "文件大小,单位为B(文件真实大小,否则会出现异常) (必填)")
|
||||
private Long size;
|
||||
@ApiModelProperty(name = "creator", value = "创建者id,字符串长度小于40 (必填)")
|
||||
private String creator;
|
||||
@ApiModelProperty(name = "create_time", value = "创建时间,时间戳,单位为秒 (必填)")
|
||||
private Long create_time;
|
||||
@ApiModelProperty(name = "modifier", value = "修改者id,字符串长度小于40 (必填)")
|
||||
private String modifier;
|
||||
@ApiModelProperty(name = "modify_time", value = "修改时间,时间戳,单位为秒 (必填)")
|
||||
private Long modify_time;
|
||||
@ApiModelProperty(name = "download_url", value = "文档下载地址 (必填)")
|
||||
private String download_url;
|
||||
@ApiModelProperty(name = "preview_pages", value = "限制预览页数 (非必填,不超过5000)")
|
||||
private Integer preview_pages;
|
||||
@ApiModelProperty(name = "user_acl", value = "文档功能")
|
||||
private UserAcl user_acl;
|
||||
@ApiModelProperty(name = "watermark", value = "水印")
|
||||
private Watermark watermark;
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id.trim();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name.trim();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getVersion() {
|
||||
return version == null ? 0 : version;
|
||||
}
|
||||
|
||||
public void setVersion(Integer version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Long getSize() {
|
||||
return size == null ? 0 : size;
|
||||
}
|
||||
|
||||
public void setSize(Long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return creator == null ? "" : creator.trim();
|
||||
}
|
||||
|
||||
public void setCreator(String creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public Long getCreate_time() {
|
||||
return create_time == null ? 0 : create_time;
|
||||
}
|
||||
|
||||
public void setCreate_time(Long create_time) {
|
||||
this.create_time = create_time;
|
||||
}
|
||||
|
||||
public String getModifier() {
|
||||
return modifier == null ? "" : modifier.trim();
|
||||
}
|
||||
|
||||
public void setModifier(String modifier) {
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
public Long getModify_time() {
|
||||
return modify_time == null ? 0 : modify_time;
|
||||
}
|
||||
|
||||
public void setModify_time(Long modify_time) {
|
||||
this.modify_time = modify_time;
|
||||
}
|
||||
|
||||
public String getDownload_url() {
|
||||
return download_url == null ? "" : download_url.trim();
|
||||
}
|
||||
|
||||
public void setDownload_url(String download_url) {
|
||||
this.download_url = download_url;
|
||||
}
|
||||
|
||||
public Integer getPreview_pages() {
|
||||
return preview_pages == null ? 0 : preview_pages;
|
||||
}
|
||||
|
||||
public void setPreview_pages(Integer preview_pages) {
|
||||
this.preview_pages = preview_pages;
|
||||
}
|
||||
|
||||
public UserAcl getUser_acl() {
|
||||
return user_acl;
|
||||
}
|
||||
|
||||
public void setUser_acl(UserAcl user_acl) {
|
||||
this.user_acl = user_acl;
|
||||
}
|
||||
|
||||
public Watermark getWatermark() {
|
||||
return watermark;
|
||||
}
|
||||
|
||||
public void setWatermark(Watermark watermark) {
|
||||
this.watermark = watermark;
|
||||
}
|
||||
}
|
||||
|
||||
@ApiModel
|
||||
public static class UserAcl {
|
||||
@ApiModelProperty(name = "rename", value = "重命名权限,1为打开该权限,0为关闭该权限,默认为0")
|
||||
private Integer rename;
|
||||
@ApiModelProperty(name = "history", value = "历史版本权限,1为打开该权限,0为关闭该权限,默认为1")
|
||||
private Integer history;
|
||||
@ApiModelProperty(name = "copy", value = "复制")
|
||||
private Integer copy;
|
||||
@ApiModelProperty(name = "export", value = "导出PDF")
|
||||
private Integer export;
|
||||
@ApiModelProperty(name = "print", value = "打印")
|
||||
private Integer print;
|
||||
|
||||
public Integer getRename() {
|
||||
return rename == null ? 0 : rename;
|
||||
}
|
||||
|
||||
public void setRename(Integer rename) {
|
||||
this.rename = rename;
|
||||
}
|
||||
|
||||
public Integer getHistory() {
|
||||
return history == null ? 0 : history;
|
||||
}
|
||||
|
||||
public void setHistory(Integer history) {
|
||||
this.history = history;
|
||||
}
|
||||
|
||||
public Integer getCopy() {
|
||||
return copy == null ? 0 : copy;
|
||||
}
|
||||
|
||||
public void setCopy(Integer copy) {
|
||||
this.copy = copy;
|
||||
}
|
||||
|
||||
public Integer getExport() {
|
||||
return export == null ? 0 : export;
|
||||
}
|
||||
|
||||
public void setExport(Integer export) {
|
||||
this.export = export;
|
||||
}
|
||||
|
||||
public Integer getPrint() {
|
||||
return print == null ? 0 : print;
|
||||
}
|
||||
|
||||
public void setPrint(Integer print) {
|
||||
this.print = print;
|
||||
}
|
||||
}
|
||||
|
||||
@ApiModel
|
||||
public static class Watermark {
|
||||
@ApiModelProperty(name = "type", value = "水印类型, 0为无水印; 1为文字水印")
|
||||
private Integer type;
|
||||
@ApiModelProperty(name = "value", value = "文字水印的文字,当type为1时,此字段必填")
|
||||
private String value;
|
||||
@ApiModelProperty(name = "fillstyle", value = "水印的透明度,非必填,有默认值")
|
||||
private String fillstyle;
|
||||
@ApiModelProperty(name = "font", value = "水印的字体,非必填,有默认值")
|
||||
private String font;
|
||||
@ApiModelProperty(name = "rotate", value = "水印的旋转度,非必填,有默认值")
|
||||
private Float rotate;
|
||||
@ApiModelProperty(name = "horizontal", value = "水印水平间距,非必填,有默认值")
|
||||
private Integer horizontal;
|
||||
@ApiModelProperty(name = "vertical", value = "水印垂直间距,非必填,有默认值")
|
||||
private Integer vertical;
|
||||
|
||||
public Integer getType() {
|
||||
return type == null ? 1 : type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value == null ? "禁止传阅" : value.trim();
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getFillstyle() {
|
||||
return fillstyle == null ? "rgba( 192, 192, 192, 0.6 )" : fillstyle.trim();
|
||||
}
|
||||
|
||||
public void setFillstyle(String fillstyle) {
|
||||
this.fillstyle = fillstyle;
|
||||
}
|
||||
|
||||
public String getFont() {
|
||||
return font == null ? "bold 20px Serif" : font.trim();
|
||||
}
|
||||
|
||||
public void setFont(String font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public Float getRotate() {
|
||||
return rotate == null ? -0.7853982F : rotate;
|
||||
}
|
||||
|
||||
public void setRotate(Float rotate) {
|
||||
this.rotate = rotate;
|
||||
}
|
||||
|
||||
public Integer getHorizontal() {
|
||||
return horizontal == null ? 50 : horizontal;
|
||||
}
|
||||
|
||||
public void setHorizontal(Integer horizontal) {
|
||||
this.horizontal = horizontal;
|
||||
}
|
||||
|
||||
public Integer getVertical() {
|
||||
return vertical == null ? 100 : vertical;
|
||||
}
|
||||
|
||||
public void setVertical(Integer vertical) {
|
||||
this.vertical = vertical;
|
||||
}
|
||||
}
|
||||
|
||||
@ApiModel
|
||||
public static class User {
|
||||
@ApiModelProperty(name = "id", value = "用户id(用户名),长度小于32 (必填)")
|
||||
private String id;
|
||||
@ApiModelProperty(name = "name", value = "用户名称 (必填)")
|
||||
private String name;
|
||||
@ApiModelProperty(name = "permission", value = "用户操作权限,write:可编辑,read:预览 (必填)")
|
||||
private String permission;
|
||||
@ApiModelProperty(name = "avatar_url", value = "用户头像地址 (非必填)")
|
||||
private String avatar_url;
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id.trim();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name.trim();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission == null ? "" : permission.trim();
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public String getAvatar_url() {
|
||||
return avatar_url == null ? "" : avatar_url.trim();
|
||||
}
|
||||
|
||||
public void setAvatar_url(String avatar_url) {
|
||||
this.avatar_url = avatar_url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package ink.wgink.module.wps.pojo.dtos;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsSaveFileDTO
|
||||
* @Description: wps保存文件
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/22 17:49
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@ApiModel
|
||||
public class WpsSaveFileInfoDTO {
|
||||
|
||||
@ApiModelProperty(name = "file", value = "文件")
|
||||
private File file;
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public static class File {
|
||||
@ApiModelProperty(name = "id", value = "文件id,字符串长度小于40,和 URL 中的fileid必须一致(https://wwo.wps.cn/office/<:type>/<:fileid>?_w_appid=xxx) (必填)")
|
||||
private String id;
|
||||
@ApiModelProperty(name = "name", value = "文件名(必须带文件后缀) (必填)")
|
||||
private String name;
|
||||
@ApiModelProperty(name = "version", value = "当前版本号,必须大于 0,同时位数小于 11 (必填)")
|
||||
private Integer version;
|
||||
@ApiModelProperty(name = "size", value = "文件大小,单位为B(文件真实大小,否则会出现异常) (必填)")
|
||||
private Long size;
|
||||
@ApiModelProperty(name = "download_url", value = "文档下载地址 (必填)")
|
||||
private String download_url;
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id.trim();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name.trim();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getVersion() {
|
||||
return version == null ? 0 : version;
|
||||
}
|
||||
|
||||
public void setVersion(Integer version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Long getSize() {
|
||||
return size == null ? 0 : size;
|
||||
}
|
||||
|
||||
public void setSize(Long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getDownload_url() {
|
||||
return download_url == null ? "" : download_url.trim();
|
||||
}
|
||||
|
||||
public void setDownload_url(String download_url) {
|
||||
this.download_url = download_url;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package ink.wgink.module.wps.service;
|
||||
|
||||
import ink.wgink.module.wps.enums.WpsPermissionEnum;
|
||||
import ink.wgink.module.wps.pojo.bos.WpsTokenBO;
|
||||
import ink.wgink.module.wps.pojo.dtos.WpsFileInfoDTO;
|
||||
import ink.wgink.module.wps.pojo.dtos.WpsSaveFileInfoDTO;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* @ClassName: IWpsService
|
||||
* @Description: wps业务
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 21:46
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IWpsService {
|
||||
|
||||
/**
|
||||
* token
|
||||
*
|
||||
* @param wpsPermissionEnum
|
||||
* @param fileId
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
WpsTokenBO getToken(WpsPermissionEnum wpsPermissionEnum, String fileId) throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 保存文件
|
||||
*
|
||||
* @param wpsToken
|
||||
* @param fileId
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
WpsSaveFileInfoDTO save(String wpsToken, String fileId, MultipartFile file);
|
||||
|
||||
|
||||
/**
|
||||
* 文件详情
|
||||
*
|
||||
* @param wpsToken
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
WpsFileInfoDTO getFileInfo(String wpsToken, String fileId);
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
ResponseEntity<byte[]> download(String fileId) throws IOException;
|
||||
|
||||
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
package ink.wgink.module.wps.service.impl;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseService;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.exceptions.SearchException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.interfaces.user.IUserBaseService;
|
||||
import ink.wgink.module.file.service.v2.IFileV2Service;
|
||||
import ink.wgink.module.wps.consts.IWpsConsts;
|
||||
import ink.wgink.module.wps.enums.WpsPermissionEnum;
|
||||
import ink.wgink.module.wps.pojo.bos.WpsTokenBO;
|
||||
import ink.wgink.module.wps.pojo.dtos.WpsFileInfoDTO;
|
||||
import ink.wgink.module.wps.pojo.dtos.WpsSaveFileInfoDTO;
|
||||
import ink.wgink.module.wps.service.IWpsService;
|
||||
import ink.wgink.module.wps.util.WpsUtil;
|
||||
import ink.wgink.pojo.dtos.user.UserDTO;
|
||||
import ink.wgink.pojo.pos.FilePO;
|
||||
import ink.wgink.properties.FileProperties;
|
||||
import ink.wgink.properties.ServerProperties;
|
||||
import ink.wgink.properties.wps.WpsProperties;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsServiceImpl
|
||||
* @Description: wps
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 21:47
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class WpsServiceImpl extends DefaultBaseService implements IWpsService {
|
||||
|
||||
@Autowired
|
||||
private WpsProperties wpsProperties;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
@Autowired
|
||||
private IFileV2Service fileV2Service;
|
||||
@Autowired
|
||||
private IUserBaseService userBaseService;
|
||||
@Autowired
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
@Override
|
||||
public WpsTokenBO getToken(WpsPermissionEnum wpsPermissionEnum, String fileId) throws UnsupportedEncodingException {
|
||||
FilePO filePO = fileV2Service.getPO(fileId);
|
||||
if (filePO == null) {
|
||||
throw new SearchException("文件不存在");
|
||||
}
|
||||
if (!WpsUtil.isWpsFile(filePO.getFileType())) {
|
||||
throw new SearchException("文件格式不支持");
|
||||
}
|
||||
String userId = securityComponent.getCurrentUser().getUserId();
|
||||
String wpsUrl = wpsProperties.getUrl() + "/office/" + WpsUtil.getWpsType(filePO.getFileType()) + "/" + fileId + "?";
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put(IWpsConsts.KEY_APP_ID, wpsProperties.getAppId());
|
||||
paramMap.put(IWpsConsts.KEY_FILE_ID, fileId);
|
||||
paramMap.put(IWpsConsts.KEY_TOKEN_TYPE, "1");
|
||||
String signature = WpsUtil.getSignature(paramMap, wpsProperties.getAppSecret());
|
||||
wpsUrl += WpsUtil.getUrlParam(paramMap) + "&" + IWpsConsts.KEY_SIGNATURE + "=" + signature;
|
||||
WpsTokenBO wpsTokenBO = new WpsTokenBO();
|
||||
wpsTokenBO.setWpsUrl(wpsUrl);
|
||||
wpsTokenBO.setToken(wpsPermissionEnum.getValue() + ":" + userId);
|
||||
return wpsTokenBO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WpsSaveFileInfoDTO save(String wpsToken, String fileId, MultipartFile file) {
|
||||
/**
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
BufferedOutputStream out = new BufferedOutputStream(
|
||||
new FileOutputStream(new File()));
|
||||
out.write(file.getBytes());
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//// TODO: 返回保存后的文件信息 特别是文件大小与版本信息要准确
|
||||
FileModel filemodel = new FileModel();
|
||||
filemodel.name = fileNameMap.get(fileid);
|
||||
filemodel.size = file.getSize();
|
||||
filemodel.version = filemodel.version + 1;
|
||||
return filemodel;
|
||||
**/
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WpsFileInfoDTO getFileInfo(String wpsToken, String fileId) {
|
||||
String[] tokenArray = wpsToken.split(":");
|
||||
if (tokenArray.length != 2) {
|
||||
throw new ParamsException("token异常");
|
||||
}
|
||||
String permission = tokenArray[0];
|
||||
String userId = tokenArray[1];
|
||||
UserDTO userDTO = userBaseService.get(userId);
|
||||
if (userDTO == null) {
|
||||
throw new SearchException("用户不存在");
|
||||
}
|
||||
// 查询文件
|
||||
FilePO filePO = fileV2Service.getPO(fileId);
|
||||
if (filePO == null) {
|
||||
throw new SearchException("文件不存在");
|
||||
}
|
||||
if (!WpsUtil.isWpsFile(filePO.getFileType())) {
|
||||
throw new SearchException("文件格式不支持");
|
||||
}
|
||||
|
||||
// 文件情况
|
||||
Long gmtModified = DateTime.parse(filePO.getGmtModified(), DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)).getMillis();
|
||||
WpsFileInfoDTO.File file = new WpsFileInfoDTO.File();
|
||||
file.setId(filePO.getFileId());
|
||||
file.setName(filePO.getFileName());
|
||||
// 按修改时间确定版本
|
||||
file.setVersion((int) (gmtModified / 1000));
|
||||
file.setSize(filePO.getFileSize());
|
||||
file.setCreator(filePO.getCreator());
|
||||
file.setCreate_time(DateTime.parse(filePO.getGmtCreate(), DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD_HH_MM_SS)).getMillis() / 1000L);
|
||||
file.setModifier(filePO.getModifier());
|
||||
file.setModify_time(gmtModified / 1000);
|
||||
file.setPreview_pages(5000);
|
||||
file.setDownload_url(serverProperties.getUrl() + "/wps/download/" + filePO.getFileId());
|
||||
|
||||
// 用户情况
|
||||
WpsFileInfoDTO.User user = new WpsFileInfoDTO.User();
|
||||
user.setId(userDTO.getUserUsername());
|
||||
user.setName(userDTO.getUserName());
|
||||
user.setAvatar_url(userDTO.getUserAvatar());
|
||||
if (StringUtils.equals(permission, WpsPermissionEnum.WRITE.getValue())) {
|
||||
user.setPermission(WpsPermissionEnum.WRITE.getValue());
|
||||
} else {
|
||||
user.setPermission(WpsPermissionEnum.READ.getValue());
|
||||
}
|
||||
|
||||
WpsFileInfoDTO wpsFileInfoDTO = new WpsFileInfoDTO();
|
||||
wpsFileInfoDTO.setFile(file);
|
||||
wpsFileInfoDTO.setUser(user);
|
||||
return wpsFileInfoDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> download(String fileId) throws IOException {
|
||||
FilePO filePO = fileV2Service.getPO(fileId);
|
||||
if (filePO == null) {
|
||||
throw new SearchException("文件不存在");
|
||||
}
|
||||
if (!WpsUtil.isWpsFile(filePO.getFileType())) {
|
||||
throw new SearchException("文件格式不支持");
|
||||
}
|
||||
File file = new File(filePO.getFilePath());
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
byte[] body = new byte[inputStream.available()];
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filePO.getFileName(), "utf-8"));
|
||||
inputStream.read(body);
|
||||
return new ResponseEntity(body, headers, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
package ink.wgink.module.wps.util;
|
||||
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.wps.consts.IWpsConsts;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.tomcat.util.codec.binary.Base64.encodeBase64String;
|
||||
|
||||
/**
|
||||
* @ClassName: WpsUtil
|
||||
* @Description: wps工具
|
||||
* @Author: wanggeng
|
||||
* @Date: 2022/6/21 21:58
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class WpsUtil {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WpsUtil.class);
|
||||
private static final String[] WPS_FILE_TYPE_W = new String[]{"doc", "dot", "wps", "wpt", "docx", "dotx", "docm", "dotm", "rtf"};
|
||||
private static final String[] WPS_FILE_TYPE_P = new String[]{"ppt", "pptx", "pptm", "ppsx", "ppsm", "pps", "potx", "potm", "dpt", "dps"};
|
||||
private static final String[] WPS_FILE_TYPE_S = new String[]{"xls", "xlt", "et", "xlsx", "xltx", "csv", "xlsm", "xltm"};
|
||||
private static final String[] WPS_FILE_TYPE_F = new String[]{"pdf"};
|
||||
private static final List<String> WPS_FILE_TYPES = new ArrayList<>();
|
||||
|
||||
static {
|
||||
WPS_FILE_TYPES.addAll(Arrays.asList(WPS_FILE_TYPE_W));
|
||||
WPS_FILE_TYPES.addAll(Arrays.asList(WPS_FILE_TYPE_P));
|
||||
WPS_FILE_TYPES.addAll(Arrays.asList(WPS_FILE_TYPE_S));
|
||||
WPS_FILE_TYPES.addAll(Arrays.asList(WPS_FILE_TYPE_F));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是WPS文件
|
||||
*
|
||||
* @param fileType
|
||||
* @return
|
||||
*/
|
||||
public static Boolean isWpsFile(String fileType) {
|
||||
for (String wpsFileType : WPS_FILE_TYPES) {
|
||||
if (StringUtils.equalsIgnoreCase(wpsFileType, fileType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取wps文件类型
|
||||
*
|
||||
* @param fileType
|
||||
* @return
|
||||
*/
|
||||
public static String getWpsType(String fileType) {
|
||||
for (String w : WPS_FILE_TYPE_W) {
|
||||
if (StringUtils.equalsIgnoreCase(w, fileType)) {
|
||||
return "w";
|
||||
}
|
||||
}
|
||||
for (String p : WPS_FILE_TYPE_P) {
|
||||
if (StringUtils.equalsIgnoreCase(p, fileType)) {
|
||||
return "p";
|
||||
}
|
||||
}
|
||||
for (String s : WPS_FILE_TYPE_S) {
|
||||
if (StringUtils.equalsIgnoreCase(s, fileType)) {
|
||||
return "s";
|
||||
}
|
||||
}
|
||||
for (String f : WPS_FILE_TYPE_F) {
|
||||
if (StringUtils.equalsIgnoreCase(f, fileType)) {
|
||||
return "f";
|
||||
}
|
||||
}
|
||||
throw new ParamsException("文件格式错误");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路径参数
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String getUrlParam(Map<String, String> params) throws UnsupportedEncodingException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append('&');
|
||||
}
|
||||
builder.append(URLEncoder.encode(entry.getKey(), ISystemConstant.CHARSET_UTF8)).append('=').append(URLEncoder.encode(entry.getValue(), "utf-8"));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*
|
||||
* @param params
|
||||
* @param appSecret
|
||||
* @return
|
||||
*/
|
||||
public static String getSignature(Map<String, String> params, String appSecret) {
|
||||
List<String> keys = new ArrayList();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
keys.add(entry.getKey());
|
||||
}
|
||||
|
||||
// 将所有参数按key的升序排序
|
||||
Collections.sort(keys, new Comparator<String>() {
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
|
||||
// 构造签名的源字符串
|
||||
StringBuilder contents = new StringBuilder("");
|
||||
for (String key : keys) {
|
||||
if (key == IWpsConsts.KEY_SIGNATURE) {
|
||||
continue;
|
||||
}
|
||||
contents.append(key + "=").append(params.get(key));
|
||||
System.out.println("key:" + key + ",value:" + params.get(key));
|
||||
}
|
||||
contents.append(IWpsConsts.KEY_SECRET_KEY).append("=").append(appSecret);
|
||||
|
||||
// 进行hmac sha1 签名
|
||||
byte[] bytes = hmacSha1(appSecret.getBytes(), contents.toString().getBytes());
|
||||
//字符串经过Base64编码
|
||||
String sign = encodeBase64String(bytes);
|
||||
try {
|
||||
sign = URLEncoder.encode(sign, ISystemConstant.CHARSET_UTF8);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
LOG.debug("WPS sign: {}", sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param key
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static byte[] hmacSha1(byte[] key, byte[] data) {
|
||||
try {
|
||||
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
|
||||
Mac mac = Mac.getInstance(signingKey.getAlgorithm());
|
||||
mac.init(signingKey);
|
||||
return mac.doFinal(data);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
} catch (InvalidKeyException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<script src="assets/js/jquery-3.5.1.min.js"></script>
|
||||
<script src="assets/wps/js/jwps.js"></script>
|
||||
<style>
|
||||
* {box-sizing: border-box;}
|
||||
html, body {display: flex;flex-direction: column;padding: 0;margin: 0;height: 100%; /* 防止双击缩放 */touch-action: manipulation;}
|
||||
iframe {flex: 1;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script th:inline="javascript">
|
||||
var wps = WPS.config({wpsUrl: [[${wpsUrl}]]});
|
||||
wps.setToken({token: [[${token}]]});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
2
pom.xml
2
pom.xml
@ -49,10 +49,10 @@
|
||||
<module>module-examine</module>
|
||||
<module>mongo-login</module>
|
||||
<module>mongo-menu</module>
|
||||
<module>module-wps</module>
|
||||
<module>module-wechat-miniapp</module>
|
||||
<module>module-wechat-officialaccount</module>
|
||||
<module>module-wechat-pay</module>
|
||||
<module>module-attn</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user