| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package cn.com.goldenwater.dcproj.controller.system;
- import cn.com.goldenwater.core.web.BaseController;
- import cn.com.goldenwater.core.web.BaseResponse;
- import cn.com.goldenwater.dcproj.socket.WebSocketServer;
- import cn.com.goldenwater.id.util.UuidUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.servlet.ModelAndView;
- /**
- * <p>
- * 利用webSocket实现实时打印的功能
- * </p>
- *
- * @author luneyq
- * @author liyz
- * @date 2019/4/16 14:32
- */
- @Api(value = "webSocket相关接口", tags = "webSocket相关接口")
- @Controller
- @RequestMapping("/socket")
- public class WebSocketController extends BaseController {
- @ApiOperation("推送数据接口")
- @ResponseBody
- @RequestMapping("/push/{sid}")
- public String pushToWeb(@PathVariable String sid, String message) throws InterruptedException {
- for (int i = 0; i < 10; i++) {
- // sid为空时向所有连接广播群发
- WebSocketServer.sendInfo(message + i, i == 5 ? null : sid);
- Thread.sleep(1000);
- }
- return "y";
- }
- @ApiOperation("页面请求(返回ModelAndView)")
- @GetMapping("/view/{sid}")
- public ModelAndView socket(@PathVariable String sid) {
- ModelAndView mav = new ModelAndView("websocket");
- mav.addObject("v1", "test1");
- return mav;
- }
- @ApiOperation("页面请求(直接返回页面)")
- @RequestMapping(value = "/view2", method = RequestMethod.GET, produces = "text/html; charset=UTF-8")
- public String view() {
- return "websocket";
- }
- @ApiOperation("获取UUID的接口")
- @RequestMapping(value = "/uuidStr", method = RequestMethod.GET)
- @ResponseBody
- public String getUuidStr() {
- return UuidUtil.uuid();
- }
- @ApiOperation("获取UUID的接口")
- @RequestMapping(value = "/uuid", method = RequestMethod.GET)
- @ResponseBody
- public BaseResponse<String> getUuid() {
- String uuid = UuidUtil.uuid();
- return buildSuccessResponse(uuid);
- }
- }
|