diff --git a/build.gradle b/build.gradle index 2baa962b..445905c4 100644 --- a/build.gradle +++ b/build.gradle @@ -57,6 +57,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-webflux' // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-graphql //implementation 'org.springframework.boot:spring-boot-starter-graphql:2.7.17' + implementation 'io.springfox:springfox-boot-starter:3.0.0' //graphql diff --git a/interface/share.json b/interface/share.json new file mode 100644 index 00000000..cd58d4c1 --- /dev/null +++ b/interface/share.json @@ -0,0 +1,152 @@ +[ + { + "url": "http://81.69.8.95:8080/share/usershare/create", + "method": "POST", + "body": { + "theme": "主题", + "date": "分享日期,如2023-01-01", + "time": "分享时间,如8:00", + "language": "分享语言,0-中文,1英文", + "presenter": "分享人昵称", + "org": "所属组织", + "twitter": "分享人推特", + "sharingDoc": "分享链接", + "label": "标签类别" + }, + "response": + { + "code": "200", + "msg": "success", + "data": 111 + } + }, + { + "url": "http://81.69.8.95:8080/share/usershare/update", + "method": "POST", + "body": { + "id":"分享id,如111", + "theme": "主题", + "date": "分享日期,如2023-01-01", + "time": "分享时间,如8:00", + "language": "分享语言,0-中文,1英文", + "presenter": "分享人昵称", + "org": "所属组织", + "twitter": "分享人推特", + "sharingDoc": "分享链接", + "label": "标签类别" + }, + "response": + { + "code": "200", + "msg": "success", + "data": null + } + }, + { + "url": "http://81.69.8.95:8080/share/usershare/delete?shareId=111", + "method": "POST", + "response": + { + "code": "200", + "msg": "success", + "data": null + } + }, + { + "url": "http://81.69.8.95:8080/share/usershare/all?pageNo=1&pageSize=10", + "method": "GET", + "response": + { + "code": "200", + "msg": "success", + "data": { + "data": [ + { + "id": "分享id", + "theme": "主题", + "date": "分享日期,如2023-01-01", + "time": "分享时间,如8:00", + "language": "分享语言,0-中文,1英文", + "presenter": "分享人昵称", + "org": "所属组织", + "twitter": "分享人推特", + "sharingDoc": "分享链接", + "label": "标签类别", + "locked": "锁定状态", + "meetingType": "会议类别", + "meetingId": "会议编号", + "meetingLink": "会议链接" + } + ], + "pagination": { + "totalCount": 0, + "totalPages": 0, + "currentPage": 1, + "currentPageSize": 0, + "hasNext": false + } + } + } + }, + { + "url": "http://81.69.8.95:8080/share/usershare/{memberId}?pageNo=1&pageSize=10", + "method": "GET", + "response": + { + "code": "200", + "msg": "success", + "data": { + "data": [ + { + "id": "分享id", + "theme": "主题", + "date": "分享日期,如2023-01-01", + "time": "分享时间,如8:00", + "language": "分享语言,0-中文,1英文", + "presenter": "分享人昵称", + "org": "所属组织", + "twitter": "分享人推特", + "sharingDoc": "分享链接", + "label": "标签类别", + "locked": "锁定状态", + "meetingType": "会议类别", + "meetingId": "会议编号", + "meetingLink": "会议链接" + } + ], + "pagination": { + "totalCount": 0, + "totalPages": 0, + "currentPage": 1, + "currentPageSize": 0, + "hasNext": false + } + } + } + }, + { + "url": "http://81.69.8.95:8080/share/usershare/queryByShareId?shareId=111", + "method": "GET", + "response": + { + "code": "200", + "msg": "success", + "data": { + "id": "分享id", + "theme": "主题", + "date": "分享日期,如2023-01-01", + "time": "分享时间,如8:00", + "language": "分享语言,0-中文,1英文", + "presenter": "分享人昵称", + "org": "所属组织", + "twitter": "分享人推特", + "sharingDoc": "分享链接", + "label": "标签类别", + "locked": "锁定状态", + "meetingType": "会议类别", + "meetingId": "会议编号", + "meetingLink": "会议链接" + } + } + } +] \ No newline at end of file diff --git a/src/main/java/com/dl/officialsite/config/CorsConfig.java b/src/main/java/com/dl/officialsite/config/CorsConfig.java index 407db3b4..345b6488 100644 --- a/src/main/java/com/dl/officialsite/config/CorsConfig.java +++ b/src/main/java/com/dl/officialsite/config/CorsConfig.java @@ -1,9 +1,15 @@ package com.dl.officialsite.config; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.List; + @Configuration public class CorsConfig implements WebMvcConfigurer { @Override @@ -22,4 +28,5 @@ public void addCorsMappings(CorsRegistry registry) { //暴露哪些原始请求头部信息 .exposedHeaders("*"); } + } diff --git a/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java b/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java index 2a0b132b..fd7f57c7 100644 --- a/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java +++ b/src/main/java/com/dl/officialsite/login/filter/LoginFilter.java @@ -43,13 +43,16 @@ public class LoginFilter extends OncePerRequestFilter { add("/login/check"); add("/login/check-session"); add("/login/logout"); + add("/share/usershare/all"); + add("/share/usershare/queryByShareId"); }} ; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { log.info("Login filter session id {}, request {}", request.getSession().getId(), request.getRequestURI()); try{ - if (noLoginApis.contains(request.getRequestURI())) { + String uri = request.getRequestURI(); + if (noLoginApis.contains(uri) || uri.contains("swagger")) { filterChain.doFilter(request, response); return; } diff --git a/src/main/java/com/dl/officialsite/sharing/constant/SharingPostType.java b/src/main/java/com/dl/officialsite/sharing/constant/SharingPostType.java new file mode 100644 index 00000000..ce970015 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/constant/SharingPostType.java @@ -0,0 +1,21 @@ +package com.dl.officialsite.sharing.constant; + +public enum SharingPostType { + + CLASSIC(0); + + private int code; + + SharingPostType(int code){ + this.code = code; + } + + public static SharingPostType codeOf(int code){ + for(SharingPostType postType: SharingPostType.values()){ + if(postType.code == code){ + return postType; + } + } + throw new IllegalArgumentException("SharingPostType "+code); + } +} diff --git a/src/main/java/com/dl/officialsite/sharing/controller/UserSharingController.java b/src/main/java/com/dl/officialsite/sharing/controller/UserSharingController.java index 2d027805..a3614973 100644 --- a/src/main/java/com/dl/officialsite/sharing/controller/UserSharingController.java +++ b/src/main/java/com/dl/officialsite/sharing/controller/UserSharingController.java @@ -7,13 +7,16 @@ import com.dl.officialsite.sharing.model.resp.AllSharingResp; import com.dl.officialsite.sharing.model.resp.SharingByUserResp; import com.dl.officialsite.sharing.service.IUserSharingService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.repository.query.Param; import org.springframework.web.bind.annotation.*; @RestController -@RequestMapping("share/v1/usershare") +@RequestMapping("share/usershare") @Slf4j public class UserSharingController { @@ -44,7 +47,7 @@ public BaseResponse updateSharing(UpdateSharingReq req){ * 删除分享 */ @PostMapping("delete") - public BaseResponse deleteSharing(long shareId){ + public BaseResponse deleteSharing(@RequestParam("shareId") long shareId){ this.userSharingService.deleteSharing(shareId); return BaseResponse.success(); } @@ -55,7 +58,8 @@ public BaseResponse deleteSharing(long shareId){ * @return */ @GetMapping("all") - public BaseResponse loadSharing(@Param("pageNo") int pageNo, @Param("pageSize") int pageSize){ + public BaseResponse loadSharing(@RequestParam(value = "pageNo",defaultValue = "1") int pageNo, + @RequestParam(value = "pageSize",defaultValue = "20") int pageSize){ return BaseResponse.successWithData(this.userSharingService.loadSharing(pageNo, pageSize)); } @@ -64,8 +68,8 @@ public BaseResponse loadSharing(@Param("pageNo") int pageNo, @Pa * @param shareId * @return */ - @GetMapping("{shareId}") - public BaseResponse querySharing(@PathVariable("shareId") long shareId){ + @GetMapping("queryByShareId") + public BaseResponse querySharing(@RequestParam("shareId") long shareId){ return BaseResponse.successWithData(this.userSharingService.querySharing(shareId)); } @@ -73,7 +77,9 @@ public BaseResponse querySharing(@PathVariable("shareId") long shareI * 查看用户的分享 */ @GetMapping("{memberId}") - public BaseResponse loadSharingByUser(@PathVariable("memberId") long memberId, @Param("pageNo") int pageNo, @Param("pageSize") int pageSize) { + public BaseResponse loadSharingByUser(@PathVariable("memberId") long memberId, + @RequestParam(value = "pageNo",defaultValue = "1") int pageNo, + @RequestParam(value = "pageSize",defaultValue = "20") int pageSize) { return BaseResponse.successWithData(this.userSharingService.loadSharingByUser(memberId, pageNo, pageSize)); } } diff --git a/src/main/java/com/dl/officialsite/sharing/handler/IPostHandler.java b/src/main/java/com/dl/officialsite/sharing/handler/IPostHandler.java new file mode 100644 index 00000000..ddccec58 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/handler/IPostHandler.java @@ -0,0 +1,14 @@ +package com.dl.officialsite.sharing.handler; + +import com.dl.officialsite.sharing.constant.SharingPostType; +import com.dl.officialsite.sharing.model.bo.PostGenerationInput; + +import java.io.IOException; +import java.io.OutputStream; + +public interface IPostHandler { + + void generateOutput(T input, OutputStream os) throws IOException; + + SharingPostType postType(); +} diff --git a/src/main/java/com/dl/officialsite/sharing/handler/PostClassicHandler.java b/src/main/java/com/dl/officialsite/sharing/handler/PostClassicHandler.java new file mode 100644 index 00000000..2ae3dad4 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/handler/PostClassicHandler.java @@ -0,0 +1,47 @@ +package com.dl.officialsite.sharing.handler; + +import com.dl.officialsite.sharing.constant.SharingPostType; +import com.dl.officialsite.sharing.model.bo.PostClassicalGeneratorInput; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ClassPathResource; +import org.springframework.stereotype.Component; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +@Component +@Slf4j +public class PostClassicHandler implements IPostHandler{ + @Override + public void generateOutput(PostClassicalGeneratorInput input, OutputStream os) throws IOException { + /** + * 加载模板 + */ + ClassPathResource classPathResource = new ClassPathResource("post/classic.png"); + try(InputStream ins = classPathResource.getInputStream()){ + BufferedImage image = ImageIO.read(ins); + log.info("image load finished"); + } + + + /** + * 画右上角组织图标 + */ + + /** + * Presenter + */ + + /** + * + */ + } + + @Override + public SharingPostType postType() { + return SharingPostType.CLASSIC; + } +} diff --git a/src/main/java/com/dl/officialsite/sharing/manager/PostImageManager.java b/src/main/java/com/dl/officialsite/sharing/manager/PostImageManager.java new file mode 100644 index 00000000..4985e4a4 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/manager/PostImageManager.java @@ -0,0 +1,48 @@ +package com.dl.officialsite.sharing.manager; + +import com.dl.officialsite.sharing.constant.SharingPostType; +import com.dl.officialsite.sharing.handler.IPostHandler; +import com.dl.officialsite.sharing.model.bo.PostGenerationInput; +import com.dl.officialsite.sharing.model.req.PostGenerateReq; +import com.google.common.base.Preconditions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 海报处理器 + */ +@Component +public class PostImageManager { + + private Map handlers; + + @Autowired + public PostImageManager(List handlers){ + this.handlers = new HashMap<>(); + + for(IPostHandler handler: handlers){ + this.handlers.put(handler.postType(), handler); + } + } + + public void generateTemplate(PostGenerateReq req){ + SharingPostType sharingPostType = SharingPostType.codeOf(req.getPostType()); + IPostHandler postHandler = this.handlers.get(sharingPostType); + Preconditions.checkState(postHandler !=null, "post type not found"); + + try{ + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + postHandler.generateOutput(req.getInput(), baos); + } catch (Throwable ex) + { + throw new RuntimeException(ex); + } + + } + +} diff --git a/src/main/java/com/dl/officialsite/sharing/model/bo/PostClassicalGeneratorInput.java b/src/main/java/com/dl/officialsite/sharing/model/bo/PostClassicalGeneratorInput.java new file mode 100644 index 00000000..5a5a5da3 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/model/bo/PostClassicalGeneratorInput.java @@ -0,0 +1,58 @@ +package com.dl.officialsite.sharing.model.bo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 经典海报款式数据信息 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class PostClassicalGeneratorInput extends PostGenerationInput { + + /** + * 组织图标,例如SECBIT图标 + */ + private String orgImageBase64; + + /** + * 项目方,例如Secbits Labs + */ + private String project; + + /** + * 分享标题,例如Lookup ArgumentsOverview + */ + private String theme; + + /** + * 分享者 + */ + private String presenter; + + /** + * 日期,例如2023.12.09 + */ + private String date; + + /** + * 时间,例如20:00 + */ + private String time; + + /** + * 会议类型,例如TENCENT-MEETING + */ + private String meetingType; + + /** + * 会议编号,例如711-901-942 + */ + private String meetingId; + + /** + * 会议链接 + */ + private String meetingLink; + +} diff --git a/src/main/java/com/dl/officialsite/sharing/model/bo/PostGenerationInput.java b/src/main/java/com/dl/officialsite/sharing/model/bo/PostGenerationInput.java new file mode 100644 index 00000000..0680da7c --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/model/bo/PostGenerationInput.java @@ -0,0 +1,6 @@ +package com.dl.officialsite.sharing.model.bo; + +public abstract class PostGenerationInput { + + +} diff --git a/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java b/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java index 0c1d0f0e..82e32da4 100644 --- a/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java +++ b/src/main/java/com/dl/officialsite/sharing/model/db/TbShare.java @@ -80,5 +80,7 @@ public class TbShare { private int meetingType; + private String meetingId; + private String meetingLink; } diff --git a/src/main/java/com/dl/officialsite/sharing/model/req/CreateSharingReq.java b/src/main/java/com/dl/officialsite/sharing/model/req/CreateSharingReq.java index 6378063b..45b28f97 100644 --- a/src/main/java/com/dl/officialsite/sharing/model/req/CreateSharingReq.java +++ b/src/main/java/com/dl/officialsite/sharing/model/req/CreateSharingReq.java @@ -1,5 +1,6 @@ package com.dl.officialsite.sharing.model.req; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -10,47 +11,56 @@ public class CreateSharingReq { /** * 分享主题 */ + @ApiModelProperty("分享主题") private String theme; /** * 分享日期 */ + @ApiModelProperty("分享日期,如2023-01-01") private String date; /** * 分享时间(UTC+8) */ + @ApiModelProperty("分享时间") private String time; /** * 分享语言 */ + @ApiModelProperty("分享语言,0-中文,1-英文") private int language; // 0 Chinese 1 English /** * 分享人匿称 */ + @ApiModelProperty("分享人昵称") private String presenter; /** * 分享所属组织 */ - private String Org; + @ApiModelProperty("所属组织") + private String org; /** * 分享人twitter */ + @ApiModelProperty("分享人twitter") private String twitter; /** * 文档连接 */ + @ApiModelProperty("分享链接") private String sharingDoc; /** * 标签类别 */ + @ApiModelProperty("标签类别") //defi zk underlying private String label; } diff --git a/src/main/java/com/dl/officialsite/sharing/model/req/PostGenerateReq.java b/src/main/java/com/dl/officialsite/sharing/model/req/PostGenerateReq.java new file mode 100644 index 00000000..4d4a3114 --- /dev/null +++ b/src/main/java/com/dl/officialsite/sharing/model/req/PostGenerateReq.java @@ -0,0 +1,14 @@ +package com.dl.officialsite.sharing.model.req; + +import com.dl.officialsite.sharing.model.bo.PostGenerationInput; +import lombok.Data; + +@Data +public class PostGenerateReq { + /** + * 模板款式,目前只有DL经典款式 + */ + private int postType; + + private PostGenerationInput input; +} diff --git a/src/main/java/com/dl/officialsite/sharing/model/req/UpdateSharingReq.java b/src/main/java/com/dl/officialsite/sharing/model/req/UpdateSharingReq.java index 7c676a67..0f6a96a3 100644 --- a/src/main/java/com/dl/officialsite/sharing/model/req/UpdateSharingReq.java +++ b/src/main/java/com/dl/officialsite/sharing/model/req/UpdateSharingReq.java @@ -1,5 +1,6 @@ package com.dl.officialsite.sharing.model.req; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @@ -8,50 +9,60 @@ public class UpdateSharingReq { /** * 分享id */ + @ApiModelProperty("分享id") private long id; /** * 分享主题 */ + @ApiModelProperty("分享主题") private String theme; /** * 分享日期 */ + @ApiModelProperty("分享日期") private String date; /** * 分享时间(UTC+8) */ + @ApiModelProperty("分享时间") private String time; /** * 分享语言 */ + @ApiModelProperty("分享语言") private int language; // 0 Chinese 1 English /** * 分享人匿称 */ + @ApiModelProperty("分享人昵称") private String presenter; /** * 分享所属组织 */ - private String Org; + @ApiModelProperty("分享所属组织") + private String org; /** * 分享人twitter */ + @ApiModelProperty("分享人推特") private String twitter; /** * 文档连接 */ + @ApiModelProperty("分享链接") private String sharingDoc; /** * 标签类别 */ + @ApiModelProperty("分享标签") private String label; } diff --git a/src/main/java/com/dl/officialsite/sharing/model/vo/SharingVo.java b/src/main/java/com/dl/officialsite/sharing/model/vo/SharingVo.java index 9d222ae3..6c20b589 100644 --- a/src/main/java/com/dl/officialsite/sharing/model/vo/SharingVo.java +++ b/src/main/java/com/dl/officialsite/sharing/model/vo/SharingVo.java @@ -32,6 +32,8 @@ public class SharingVo { private String meetingType; + private String meetingId; + private String meetingLink; public static SharingVo convert(TbShare entity) { @@ -48,6 +50,8 @@ public static SharingVo convert(TbShare entity) { vo.label = entity.getLabel(); vo.locked = entity.getLockStatus(); vo.meetingType = SharingMeetingType.codeOf(entity.getMeetingType()).name(); + vo.meetingId = entity.getMeetingId(); + vo.meetingLink = entity.getMeetingLink(); return vo; } } diff --git a/src/main/java/com/dl/officialsite/sharing/service/ISharingManagementService.java b/src/main/java/com/dl/officialsite/sharing/service/ISharingManagementService.java index f6ce8a8f..f827fa04 100644 --- a/src/main/java/com/dl/officialsite/sharing/service/ISharingManagementService.java +++ b/src/main/java/com/dl/officialsite/sharing/service/ISharingManagementService.java @@ -6,6 +6,8 @@ import com.dl.officialsite.sharing.model.resp.GenerateSharingDataResp; import com.dl.officialsite.sharing.model.resp.QueryMeetingResp; +import java.io.InputStream; + /** * 管理分享 */ @@ -23,6 +25,8 @@ public interface ISharingManagementService { void unlockSharing(long shareId); + byte[] generatePost(String presenter, String roomId, String roomLnk); + /** * 创建meeting room * @param req @@ -45,4 +49,5 @@ public interface ISharingManagementService { GenerateSharingDataResp viewSharingData(GenerateSharingDataReq req); + } diff --git a/src/main/java/com/dl/officialsite/sharing/service/impl/DefaultSharingManagementServiceImpl.java b/src/main/java/com/dl/officialsite/sharing/service/impl/DefaultSharingManagementServiceImpl.java index 71c4a62b..d9017ab3 100644 --- a/src/main/java/com/dl/officialsite/sharing/service/impl/DefaultSharingManagementServiceImpl.java +++ b/src/main/java/com/dl/officialsite/sharing/service/impl/DefaultSharingManagementServiceImpl.java @@ -21,6 +21,11 @@ public void unlockSharing(long shareId) { } + @Override + public byte[] generatePost(String presenter, String roomId, String roomLnk) { + return new byte[0]; + } + @Override public CreateMeetingRoomResp createSessionRoom(CreateSessionRoomReq req) { return null; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9c6a60ed..2f2b2c01 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -38,6 +38,12 @@ spring: cleanup-cron: 0 */3 * * * * timeout: 7200 + + mvc: + pathmatch: + matching-strategy: ant_path_matcher + + logging: level: org.springframework.security: debug @@ -57,4 +63,3 @@ oauth: userAuthorizationUri: https://github.com/login/oauth/authorize userInfoUri: https://api.github.com/user - diff --git a/src/main/resources/post/classic.png b/src/main/resources/post/classic.png new file mode 100644 index 00000000..c0a16bd4 Binary files /dev/null and b/src/main/resources/post/classic.png differ