Commit 716bdd11 by 李晓钟

websocket的文档处理

parent 9a15f298
......@@ -22,6 +22,8 @@ import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.wecloud.dispatch.extend.ActionRequest;
import com.wecloud.dispatch.extend.ArgumentBox;
import io.geekidea.springbootplus.config.properties.SwaggerProperties;
import io.geekidea.springbootplus.framework.common.exception.SpringBootPlusConfigException;
import io.swagger.annotations.Api;
......@@ -102,6 +104,8 @@ public class Swagger2Config {
HttpServletRequest.class,
HttpServletResponse.class,
HttpSession.class,
ActionRequest.class,
ArgumentBox.class,
ApiIgnore.class
};
@Autowired
......
......@@ -57,7 +57,6 @@ import java.util.Set;
*/
@Controller
@ActionMapping(value = "/sendtest")
@RequestMapping("/sendtest")
@Api(value = "测试方法类", tags = {"websocket报文-全部采用json传输"})
@Slf4j
public class WsTestAction {
......@@ -73,7 +72,6 @@ public class WsTestAction {
*/
@ActionMapping(value = "gogo")
@ApiOperation(value = "测试方法")
@PostMapping("gogo")
@ApiImplicitParams({
@ApiImplicitParam(name="reqId", value = "请求id", required = false),
@ApiImplicitParam(name="hello", value = "测试参数hello", required = true),
......
package com.wecloud.dispatch.annotation;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -10,17 +15,47 @@ import java.lang.annotation.Target;
*/
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@RequestMapping(method = RequestMethod.POST)
public @interface ActionMapping {
@AliasFor(annotation = RequestMapping.class)
String name() default "";
/**
* Alias for {@link RequestMapping#value}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] value() default {};
/**
* Alias for {@link RequestMapping#path}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] path() default {};
/**
* Mapping映射字段
* @return
* Alias for {@link RequestMapping#params}.
*/
String[] value() default "";
@AliasFor(annotation = RequestMapping.class)
String[] params() default {};
/**
*
* @return
* Alias for {@link RequestMapping#headers}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] headers() default {};
/**
* Alias for {@link RequestMapping#consumes}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] consumes() default {};
/**
* Alias for {@link RequestMapping#produces}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] produces() default {};
int order() default 10;
}
......@@ -6,6 +6,7 @@ import com.wecloud.dispatch.extend.ArgumentBox;
import com.wecloud.dispatch.extend.MethodArgumentResolver;
import com.wecloud.utils.JsonUtils;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.reflect.Array;
......@@ -38,15 +39,18 @@ public class GeneralMethodArgumentResolver implements MethodArgumentResolver {
ActionRequest request,
ArgumentBox argumentBox) {
Object object = null;
RequestBody requestBodyDefine = parameter.getParameterAnnotation(RequestBody.class);
if(requestBodyDefine != null) {
Class<?> clazz = parameter.getParameterType();
object = JsonUtils.beanCopyDeep(request.getData(), clazz);
return object;
}
RequestParam define = parameter.getParameterAnnotation(RequestParam.class);
// 获取属定义的名称
String name = null == define ? parameter.getParameterName() : define.value();
Class<?> clazz = parameter.getParameterType();
Object value = request.getData().get(name);
if(ActionRequest.class.isAssignableFrom(clazz)) {
object = request;
} else if (ArgumentBox.class.isAssignableFrom(clazz)) {
......
......@@ -63,20 +63,20 @@ public class ActionRegistry {
}
}
public void add(Method method) {
if (null != method) {
Annotation[] as = method.getDeclaringClass().getAnnotations();
ActionMapping am = null;
for (Annotation annotation : as) {
if (annotation instanceof ActionMapping) {
am = ((ActionMapping) annotation);
break;
}
}
String[] codes = null == am ? new String[] { "" } : am.value();
add(codes, method);
}
}
// public void add(Method method) {
// if (null != method) {
// Annotation[] as = method.getDeclaringClass().getAnnotations();
// ActionMapping am = null;
// for (Annotation annotation : as) {
// if (annotation instanceof ActionMapping) {
// am = ((ActionMapping) annotation);
// break;
// }
// }
// String[] codes = null == am ? new String[] { "" } : am.value();
// add(codes, method);
// }
// }
public void add(String[] codes, Method method) {
if (null != method) {
......
package com.wecloud.dispatch.swagger;
import com.google.common.base.Optional;
import com.wecloud.dispatch.annotation.ActionMapping;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.condition.NameValueExpression;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;
import springfox.documentation.spring.web.DescriptionResolver;
import springfox.documentation.swagger.common.SwaggerPluginSupport;
@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1)
public class CustomOperationPlugin implements OperationBuilderPlugin {
private final DescriptionResolver descriptions;
@Autowired
public CustomOperationPlugin(DescriptionResolver descriptions) {
this.descriptions = descriptions;
}
@Override
public void apply(OperationContext context) {
Optional<ApiOperation> apiOperationOp = context.findAnnotation(ApiOperation.class);
Optional<ActionMapping> acOp = context.findAnnotation(ActionMapping.class);
if (apiOperationOp.isPresent() || acOp.isPresent()) {
String notes = "";
if(apiOperationOp.isPresent()) {
notes = apiOperationOp.get().notes();
}
Optional<ActionMapping> hasActionMapping = context.findAnnotation(ActionMapping.class);
//添加权限码到notes中
if (hasActionMapping.isPresent()) {
notes = notes + "需要注意的是:<br/> 1、这是websocket接口;<br/> 2、请用ws://调用 <br/> 3、请求参数外层需要包一层:" +
"{ <br/>" +
"\t\"reqId\": Long类型, <br/>" +
"\t\"action\": 字符串类型(就是上面的地址) <br/>" +
"\t\"data\": 真正的请求参数(就是下面的请求参数), <br/>" +
"} ";
//编辑api文档信息, notes
context.operationBuilder().notes(descriptions.resolve(notes));
}
}
}
@Override
public boolean supports(DocumentationType documentationType) {
return SwaggerPluginSupport.pluginDoesApply(documentationType);
}
}
//package com.wecloud.dispatch.swagger;
//
//import com.fasterxml.classmate.TypeResolver;
//import com.google.common.collect.Sets;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.stereotype.Component;
//import springfox.documentation.builders.OperationBuilder;
//import springfox.documentation.builders.ParameterBuilder;
//import springfox.documentation.schema.ModelRef;
//import springfox.documentation.service.ApiDescription;
//import springfox.documentation.service.Operation;
//import springfox.documentation.service.Parameter;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spi.service.ApiListingScannerPlugin;
//import springfox.documentation.spi.service.contexts.DocumentationContext;
//import springfox.documentation.spring.web.readers.operation.CachingOperationNameGenerator;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//
//@Component
//public class SwaggerAddtion implements ApiListingScannerPlugin {
// @Override
// public List<ApiDescription> apply(DocumentationContext documentationContext) {
// String path = "/oauth/token";
// String description = "UserToken";
//
// List<Parameter> parameters = new ArrayList<>();
// Parameter param1 = new ParameterBuilder()
// .description("oauth2鉴权方式,如password")//参数描述
// .type(new TypeResolver().resolve(String.class))//参数数据类型
// .name("grant_type")//参数名称
// .defaultValue("password")//参数默认值
// .parameterType("query")//参数类型
// .parameterAccess("access")
// .required(true)//是否必填
// .modelRef(new ModelRef("string")) //参数数据类型
// .build();
// parameters.add(param1);
// Parameter param2 = new ParameterBuilder()
// .description("用户名")
// .type(new TypeResolver().resolve(String.class))
// .name("username")
// .parameterType("query")
// .parameterAccess("access")
// .required(true)
// .modelRef(new ModelRef("string")) //<5>
// .build();
// parameters.add(param2);
//
// Parameter param3 = new ParameterBuilder()
// .description("密码")
// .type(new TypeResolver().resolve(String.class))
// .name("password")
// .parameterType("query")
// .parameterAccess("access")
// .required(true)
// .modelRef(new ModelRef("string")) //<5>
// .build();
// parameters.add(param3);
//
// Operation operation = new OperationBuilder(
// new CachingOperationNameGenerator())
// .method(HttpMethod.POST)//http请求类型
// .produces(Sets.newHashSet(MediaType.APPLICATION_JSON_VALUE))
// .summary("获取token")
// .notes("获取token")//方法描述
// .tags(Sets.newHashSet("归类标签"))//归类标签
// .parameters(parameters)
// .build();
//
// ApiDescription apiDescription = new ApiDescription(
// path, //url
// description, //描述
// Arrays.asList(operation),
// false);
// List<ApiDescription> descriptions = new ArrayList<>();
// descriptions.add(apiDescription);
//
// return descriptions;
// }
//
// @Override
// public boolean supports(DocumentationType documentationType) {
// return DocumentationType.SWAGGER_2.equals(documentationType);
// }
//}
......@@ -15,6 +15,7 @@ import com.wecloud.im.ws.model.WsResponse;
import com.wecloud.im.ws.sender.ChannelSender;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -26,7 +27,7 @@ import org.springframework.stereotype.Component;
*/
@Slf4j
@Component
@ActionMapping(value = "/imMessage")
@ActionMapping(value = "/im/message")
public class MessageAction {
@Autowired
......@@ -42,6 +43,7 @@ public class MessageAction {
* @param reqId
*/
@ActionMapping("/withdraw")
@ApiOperation("消息撤回")
public void withdraw(ActionRequest request, ImMsgRecall msgRecall, String reqId) {
log.info("撤回消息内容:{}", JSON.toJSONString(msgRecall));
WsResponse<Boolean> wsResponse = new WsResponse<>();
......@@ -56,6 +58,7 @@ public class MessageAction {
* @param reqId
*/
@ActionMapping("/delete")
@ApiOperation("删除消息内容")
public void deleteMsg(ActionRequest request, MsgDeleteParam msgDeleteParam, String reqId) {
log.info("删除消息内容:{}", JSON.toJSONString(msgDeleteParam));
WsResponse<Boolean> wsResponse = new WsResponse<>();
......@@ -70,6 +73,7 @@ public class MessageAction {
* @param reqId
*/
@ActionMapping("/updateMsgById")
@ApiOperation("修改消息体")
public void updateMsgById(ActionRequest request, ImMsgUpdate imMsgUpdate, String reqId) {
log.info("修改消息内容:{}", JSON.toJSONString(imMsgUpdate));
WsResponse<Boolean> wsResponse = new WsResponse<>();
......@@ -84,6 +88,7 @@ public class MessageAction {
* @param reqId
*/
@ActionMapping("/getHistoryMsg")
@ApiOperation("查询某个会话历史消息分页列表")
public void getHistoryMsg(ActionRequest request, ImHistoryMessagePageParam param, String reqId) {
log.info("查询某个会话历史消息分页列表:{}", JSON.toJSONString(param));
WsResponse<Paging<OfflineMsgDto>> wsResponse = new WsResponse<>();
......@@ -98,6 +103,7 @@ public class MessageAction {
* @param reqId
*/
@ActionMapping("/getReaders")
@ApiOperation("查询某个消息已读client列表和未读client")
public void getReaders(ActionRequest request, GetReadersParam param, String reqId) {
log.info("查询某个消息已读client列表和未读client:{}", JSON.toJSONString(param));
WsResponse<ReaderList> wsResponse = new WsResponse<>();
......
......@@ -36,6 +36,7 @@ import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.netty.channel.Channel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -78,6 +79,7 @@ public class NormalChatAction {
private MqSender mqSender;
@ActionMapping("/normal/send")
@ApiOperation("普通消息发送")
public void sendMsg(ActionRequest request, ChatContentVo data, String reqId) {
if (log.isDebugEnabled()) {
log.debug("接收到参数,reqId: {},\n data: {}, ", reqId, data);
......
......@@ -20,6 +20,8 @@ import com.wecloud.im.service.ImConversationMembersService;
import com.wecloud.im.service.ImConversationService;
import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.thousandchat.cache.ThousandChatCacheManager;
import com.wecloud.im.thousandchat.param.LastestReceivedMsg;
import com.wecloud.im.thousandchat.service.ThousandChatService;
import com.wecloud.im.ws.enums.WsResponseCmdEnum;
import com.wecloud.im.ws.model.WsResponse;
import com.wecloud.im.ws.sender.ChannelSender;
......@@ -31,9 +33,16 @@ import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.netty.channel.Channel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
......@@ -46,7 +55,8 @@ import java.util.Map;
*/
@Slf4j
@Component
@ActionMapping(value = "/chat")
@ActionMapping
@Api(value = "万人群消息处理", tags = {"万人群消息处理"})
public class ThousandChatAction {
@Autowired
......@@ -63,11 +73,14 @@ public class ThousandChatAction {
private ChannelSender channelSender;
@Autowired
private ThousandChatCacheManager thousandChatCacheManager;
@Autowired
private ThousandChatService thousandChatService;
@Autowired
private MqSender mqSender;
@ActionMapping("/thousand/send")
@ActionMapping("/chat/thousand/send")
@ApiOperation(value = "万人群消息发送")
public void sendMsg(ActionRequest request, ChatContentVo data, String reqId) {
if (log.isDebugEnabled()) {
log.debug("接收到参数,reqId: {},\n data: {}, ", data);
......@@ -132,6 +145,24 @@ public class ThousandChatAction {
}
/**
* 消息修改为已接收状态
*/
@ActionMapping("/imState/msgReceivedUpdate")
@ApiOperation(value = "万人群消息修改为已接收状态")
public ApiResult<Boolean> updateImMsgReceived(@RequestBody @Validated LastestReceivedMsg lastestReceivedMsg) {
return thousandChatService.updateImMsgReceived(lastestReceivedMsg);
}
/**
* 消息修改为已读状态
*/
@ActionMapping("/imState/msgReadUpdate")
@ApiOperation(value = "万人群消息修改为已读状态")
public ApiResult<Boolean> updateInMsgReadUpdate(Long lastestMsgId) {
return thousandChatService.updateImMsgRead(lastestMsgId);
}
/**
* 发送消息给在线客户
* @param data
* @param imMessageOnlineSend
......
......@@ -20,29 +20,11 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/imState")
@Api(value = "万人群消息处理API", tags = {"万人群消息处理"})
@Api(value = "万人群消息处理API", tags = {"万人群消息处理API"})
public class ThousandChatController extends BaseController {
@Autowired
private ThousandChatService thousandChatService;
/**
* 消息修改为已接收状态
*/
@PostMapping("/msgReceivedUpdate")
@ApiOperation(value = "万人群消息修改为已接收状态")
public ApiResult<Boolean> updateImMsgReceived(@RequestBody @Validated LastestReceivedMsg lastestReceivedMsg) {
return thousandChatService.updateImMsgReceived(lastestReceivedMsg);
}
/**
* 消息修改为已读状态
*/
@PostMapping("/msgReadUpdate")
@ApiOperation(value = "万人群消息修改为已读状态")
public ApiResult<Boolean> updateInMsgReadUpdate(Long lastestMsgId) {
return thousandChatService.updateImMsgRead(lastestMsgId);
}
}
package com.wecloud.im.thousandchat.param;
import com.wecloud.dispatch.common.BaseRequest;
import io.geekidea.springbootplus.framework.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -9,6 +10,7 @@ import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @author lixiaozhong
......@@ -16,9 +18,8 @@ import javax.validation.constraints.NotNull;
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "ImMsgReceivedStatusUpdate")
public class LastestReceivedMsg extends BaseEntity {
@ApiModel(value = "LastestReceivedMsg")
public class LastestReceivedMsg implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "消息id,只需要发送最新的一条已接收消息", required = true)
......
......@@ -43,7 +43,7 @@ public class ChannelSender {
* 指定ip调用,router=address;
* injvm = false要设置成false,否则会调用到本地提供者
*/
@DubboReference(injvm = false, interfaceClass = RouterSendService.class, parameters = {"router", "address"})
@DubboReference(injvm = false, check = false, interfaceClass = RouterSendService.class, parameters = {"router", "address"})
private RouterSendService routerSendService;
/**
......
......@@ -68,10 +68,10 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
<!-- </dependency>-->
<!-- swagger end -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
......
......@@ -158,11 +158,11 @@
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.springfox</groupId>-->
<!-- <artifactId>springfox-swagger-ui</artifactId>-->
<!-- <version>${swagger2.version}</version>-->
<!-- </dependency>-->
<!-- swagger end -->
<dependency>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment