diff --git a/basic-properties/src/main/java/ink/wgink/properties/FileProperties.java b/basic-properties/src/main/java/ink/wgink/properties/FileProperties.java index 4762ecfa..b29ac640 100644 --- a/basic-properties/src/main/java/ink/wgink/properties/FileProperties.java +++ b/basic-properties/src/main/java/ink/wgink/properties/FileProperties.java @@ -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(); } diff --git a/basic-properties/src/main/java/ink/wgink/properties/onlyoffice/OnlyOfficeProperties.java b/basic-properties/src/main/java/ink/wgink/properties/onlyoffice/OnlyOfficeProperties.java new file mode 100644 index 00000000..607d8ef7 --- /dev/null +++ b/basic-properties/src/main/java/ink/wgink/properties/onlyoffice/OnlyOfficeProperties.java @@ -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; + } +} diff --git a/basic-properties/src/main/java/ink/wgink/properties/web/WebProperties.java b/basic-properties/src/main/java/ink/wgink/properties/web/WebProperties.java new file mode 100644 index 00000000..97e0c969 --- /dev/null +++ b/basic-properties/src/main/java/ink/wgink/properties/web/WebProperties.java @@ -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; + } +} diff --git a/basic-properties/src/main/java/ink/wgink/properties/wps/WpsProperties.java b/basic-properties/src/main/java/ink/wgink/properties/wps/WpsProperties.java deleted file mode 100644 index b8c47af6..00000000 --- a/basic-properties/src/main/java/ink/wgink/properties/wps/WpsProperties.java +++ /dev/null @@ -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; - } -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/consts/IWpsConsts.java b/module-wps/src/main/java/ink/wgink/module/wps/consts/IWpsConsts.java deleted file mode 100644 index a9e82999..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/consts/IWpsConsts.java +++ /dev/null @@ -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"; - -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/controller/api/WpsController.java b/module-wps/src/main/java/ink/wgink/module/wps/controller/api/WpsController.java deleted file mode 100644 index a092cf07..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/controller/api/WpsController.java +++ /dev/null @@ -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 download(@PathVariable("fileId") String fileId) throws Exception { - return wpsService.download(fileId); - } - -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/controller/route/WpsRouteController.java b/module-wps/src/main/java/ink/wgink/module/wps/controller/route/WpsRouteController.java deleted file mode 100644 index 7d72d5f2..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/controller/route/WpsRouteController.java +++ /dev/null @@ -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; - } - -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/enums/WpsPermissionEnum.java b/module-wps/src/main/java/ink/wgink/module/wps/enums/WpsPermissionEnum.java deleted file mode 100644 index 4c02f17b..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/enums/WpsPermissionEnum.java +++ /dev/null @@ -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(); - } -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/pojo/bos/WpsTokenBO.java b/module-wps/src/main/java/ink/wgink/module/wps/pojo/bos/WpsTokenBO.java deleted file mode 100644 index 6a3f2a02..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/pojo/bos/WpsTokenBO.java +++ /dev/null @@ -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; - } -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/pojo/dtos/WpsFileInfoDTO.java b/module-wps/src/main/java/ink/wgink/module/wps/pojo/dtos/WpsFileInfoDTO.java deleted file mode 100644 index 6614c35d..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/pojo/dtos/WpsFileInfoDTO.java +++ /dev/null @@ -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; - } - } - - -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/pojo/dtos/WpsSaveFileInfoDTO.java b/module-wps/src/main/java/ink/wgink/module/wps/pojo/dtos/WpsSaveFileInfoDTO.java deleted file mode 100644 index 90f72cc2..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/pojo/dtos/WpsSaveFileInfoDTO.java +++ /dev/null @@ -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; - } - } - -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/service/IWpsService.java b/module-wps/src/main/java/ink/wgink/module/wps/service/IWpsService.java deleted file mode 100644 index a59b2cf5..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/service/IWpsService.java +++ /dev/null @@ -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 download(String fileId) throws IOException; - - -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/service/impl/WpsServiceImpl.java b/module-wps/src/main/java/ink/wgink/module/wps/service/impl/WpsServiceImpl.java deleted file mode 100644 index c93e4971..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/service/impl/WpsServiceImpl.java +++ /dev/null @@ -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 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 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); - } -} diff --git a/module-wps/src/main/java/ink/wgink/module/wps/util/WpsUtil.java b/module-wps/src/main/java/ink/wgink/module/wps/util/WpsUtil.java deleted file mode 100644 index 49d547fc..00000000 --- a/module-wps/src/main/java/ink/wgink/module/wps/util/WpsUtil.java +++ /dev/null @@ -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 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 params) throws UnsupportedEncodingException { - StringBuilder builder = new StringBuilder(); - for (Map.Entry 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 params, String appSecret) { - List keys = new ArrayList(); - for (Map.Entry entry : params.entrySet()) { - keys.add(entry.getKey()); - } - - // 将所有参数按key的升序排序 - Collections.sort(keys, new Comparator() { - 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; - } - -} diff --git a/module-wps/src/main/resources/static/assets/wps/js/jwps.js b/module-wps/src/main/resources/static/assets/wps/js/jwps.js deleted file mode 100644 index df818be6..00000000 --- a/module-wps/src/main/resources/static/assets/wps/js/jwps.js +++ /dev/null @@ -1 +0,0 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).WPS={})}(this,function(e){"use strict";var t,n,o=function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n=0&&e._handleList.splice(n,1),window.removeEventListener("message",t,!1)},e.empty=function(){for(;e._handleList.length;)window.removeEventListener("message",e._handleList.shift(),!1)},e.parse=function(e){return"object"==typeof e?e:JSON.parse(e)},e._handleList=[],e}();!function(e){e.unknown="unknown",e.spreadsheet="s",e.writer="w",e.presentation="p",e.pdf="f"}(t||(t={})),function(e){e.wps="w",e.et="s",e.presentation="p",e.pdf="f"}(n||(n={}));var i,a,p,s,c,u,d,f=(i=0,function(){return++i}),l=(a=null,function(e,t){if(!a){a=document.createElement("iframe");var n={id:"wps-iframe",src:e,scrolling:"no",frameborder:"0",allowfullscreen:"allowfullscreen",webkitallowfullscreen:"true",mozallowfullscreen:"true"};for(var o in n)a.setAttribute(o,n[o]);t?t.appendChild(a):document.body.appendChild(a),a.destroy=function(){a.parentNode.removeChild(a),a=null}}return a}),m=function(e){l().contentWindow.postMessage(JSON.stringify(e),"*")},v=function(e){return new Promise(function(t){var n=f();e.type=w();var o=function(e){var i=r.parse(e.data);"wps.api.reply"===i.eventName&&i.msgId===n&&(t(i.data),r.remove(o))};r.add(o),m({eventName:"wps.jssdk.api",data:e,msgId:n})})},y=function(e){var t=o({},e),n=t.headers,r=void 0===n?{}:n,i=t.subscriptions,a=void 0===i?{}:i,p=(t.wpsUrl,r.backBtn),s=void 0===p?{}:p,c=r.shareBtn,u=void 0===c?{}:c,d=r.otherMenuBtn,f=void 0===d?{}:d,l=function(e,t){e.subscribe&&"function"==typeof e.subscribe&&(e.callback=t,a[t]=e.subscribe,delete e.subscribe)};if(l(s,"wpsconfig_back_btn"),l(u,"wpsconfig_share_btn"),l(f,"wpsconfig_other_menu_btn"),f.items&&Array.isArray(f.items)){var m=[];f.items.forEach(function(e,t){switch(void 0===e&&(e={}),e.type){case"export_img":e.type=1,e.callback="export_img";break;case"export_pdf":e.type=1,e.callback="export_pdf";break;case"save_version":e.type=1,e.callback="save_version";break;case"about_wps":e.type=1,e.callback="about_wps";break;case"split_line":e.type=2;break;case"custom":e.type=3,l(e,"wpsconfig_other_menu_btn_"+t),m.push(e)}}),m.length&&(b||F)&&(f.items=m)}if("object"==typeof a.print){var v="wpsconfig_print";"function"==typeof a.print.subscribe&&(a[v]=a.print.subscribe,t.print={callback:v},void 0!==a.print.custom&&(t.print.custom=a.print.custom)),delete a.print}"function"==typeof a.exportPdf&&(a[v="wpsconfig_export_pdf"]=a.exportPdf,t.exportPdf={callback:v},delete a.exportPdf);return o({},t,{subscriptions:a})},w=(p="",function(e){if(void 0===e&&(e=""),!p&&e){var o=e.toLowerCase();-1!==o.indexOf("/office/s/")&&(p=t.spreadsheet),-1!==o.indexOf("/office/w/")&&(p=t.writer),-1!==o.indexOf("/office/p/")&&(p=t.presentation),-1!==o.indexOf("/office/f/")&&(p=t.pdf)}if(!p){var r=e.match(/[\?&]type=([a-z]+)/)||[];p=n[r[1]]||""}return p}),x=window.navigator.userAgent.toLowerCase(),b=/Android|webOS|iPhone|iPod|BlackBerry|iPad/i.test(x),F=function(){try{return-1!==window._parent.location.search.indexOf("from=wxminiprogram")}catch(e){return!1}}();!function(e){e[e.wdExportFormatPDF=17]="wdExportFormatPDF",e[e.wdExportFormatXPS=18]="wdExportFormatXPS"}(s||(s={})),function(e){e[e.wdExportAllDocument=0]="wdExportAllDocument",e[e.wdExportSelection=1]="wdExportSelection",e[e.wdExportCurrentPage=2]="wdExportCurrentPage",e[e.wdExportFromTo=3]="wdExportFromTo"}(c||(c={})),function(e){e[e.wdExportDocumentContent=0]="wdExportDocumentContent",e[e.wdExportDocumentWithMarkup=7]="wdExportDocumentWithMarkup"}(u||(u={})),function(e){e[e.title=1]="title",e[e.tag=2]="tag"}(d||(d={}));var A;!function(e){e[e.xlTypePDF=0]="xlTypePDF",e[e.xlTypeXPS=1]="xlTypeXPS"}(A||(A={}));var P,E,h;!function(e){e[e.ppFixedFormatTypePDF=2]="ppFixedFormatTypePDF",e[e.ppFixedFormatTypeXPS=1]="ppFixedFormatTypeXPS"}(P||(P={})),function(e){e[e.ppPrintAll=1]="ppPrintAll",e[e.ppPrintCurrent=3]="ppPrintCurrent"}(E||(E={})),function(e){e[e.msoFalse=0]="msoFalse",e[e.msoTrue=-1]="msoTrue"}(h||(h={}));var g,k,D=function(){return new Promise(function(e){return k=e})},_=function(e){return"wps.advanced.api.ready"===e||"web_loaded"===e},T=function(e,t){void 0===e&&(e={});r.add(function(n){var o=r.parse(n.data),i=o.eventName,a=void 0===i?"":i,p=o.data,s=void 0===p?null:p,c=o.url,u=void 0===c?null:c;-1===["wps.jssdk.api"].indexOf(a)&&("ready"===a&&(m({eventName:"setConfig",data:e}),g.tokenData&&m({eventName:"setToken",data:g.tokenData}),k(),g.iframeReady=!0),_(a)&&S(),"function"==typeof t[a]&&t[a](g,u||s))})},S=function(){var e=w(g.url);e===t.writer&&function(e){e.WpsApplication=function(){return{ActiveDocument:{ExportAsFixedFormatAsync:function(e){var t={api:"WpsApplication().ActiveDocument.ExportAsFixedFormatAsync",args:o({ExportFormat:s.wdExportFormatPDF,Range:c.wdExportAllDocument,From:1,To:1,Item:u.wdExportDocumentWithMarkup,IncludeDocProps:!0},"object"==typeof e?e:{})};return v(t)},ImportDataIntoFieldsAsync:function(e){var t={api:"WpsApplication().ActiveDocument.ImportDataIntoFieldsAsync",args:{Data:e.Data,Options:e.Options}};return v(t)}},Enum:o({},s,c,u)}}}(g),e===t.spreadsheet&&function(e){e.EtApplication=function(){return{ActiveWorkbook:{ExportAsFixedFormatAsync:function(e){var t={api:"EtApplication().ActiveWorkbook.ExportAsFixedFormatAsync",args:o({Type:A.xlTypePDF,IncludeDocProps:!0},"object"==typeof e?e:{})};return v(t)},ActiveSheet:{ExportAsFixedFormatAsync:function(e){var t={api:"EtApplication().ActiveWorkbook.ActiveSheet.ExportAsFixedFormatAsync",args:o({Type:A.xlTypePDF,IncludeDocProps:!0},"object"==typeof e?e:{})};return v(t)}}},Enum:o({},A)}}}(g),e===t.presentation&&function(e){e.WppApplication=function(){return{ActivePresentation:{ExportAsFixedFormatAsync:function(e){var t={api:"WppApplication().ActivePresentation.ExportAsFixedFormatAsync",args:o({FixedFormatType:P.ppFixedFormatTypePDF,RangeType:E.ppPrintAll,FrameSlides:h.msoTrue},"object"==typeof e?e:{})};return v(t)}},Enum:o({},P,E)}}}(g)};console.log("WPS WebOffice JS-SDK V1.0.9"),e.config=function(e){void 0===e&&(e={}),g&&g.destroy();try{var t,n=y(e),i=n.wpsUrl,a=n.subscriptions,p=void 0===a?{}:a,s=n.mount,c=l(i,void 0===s?null:s);return delete n.mount,delete n.wpsUrl,delete n.subscriptions,D(),g={url:i,version:"1.0.9",iframe:c,Enum:o({},h),iframeReady:!1,tokenData:null,setToken:function(e){g.tokenData=e,g.iframeReady&&m({eventName:"setToken",data:e})},ready:function(){return t||(t=new Promise(function(e){var t=function(n){var o=r.parse(n.data).eventName;_(o)&&(e(),r.remove(t))};r.add(t)}))},destroy:function(){c.destroy(),r.empty(),g=null},save:function(){return v({api:"save"})}},T(n,p),g.ready(),g}catch(e){console.error(e)}},Object.defineProperty(e,"__esModule",{value:!0})}); diff --git a/module-wps/src/main/resources/templates/wps/wps.html b/module-wps/src/main/resources/templates/wps/wps.html deleted file mode 100644 index eb0b3308..00000000 --- a/module-wps/src/main/resources/templates/wps/wps.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index f06ac868..c48ec4e8 100644 --- a/pom.xml +++ b/pom.xml @@ -49,10 +49,10 @@ module-examine mongo-login mongo-menu - module-wps module-wechat-miniapp module-wechat-officialaccount module-wechat-pay + module-attn pom