VideoCallController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. package com.ruoyi.app.user;
  2. import java.util.List;
  3. import jakarta.servlet.http.HttpServletResponse;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.ruoyi.app.utils.PayPush;
  7. import com.ruoyi.common.annotation.Anonymous;
  8. import com.ruoyi.common.annotation.RepeatSubmit;
  9. import com.ruoyi.system.domain.InfoUser;
  10. import com.ruoyi.system.domain.vo.UserDTO;
  11. import com.ruoyi.system.mapper.VideoCallMapper;
  12. import com.ruoyi.system.service.IInfoUserService;
  13. import com.ruoyi.system.utils.Auth;
  14. import com.ruoyi.system.utils.JwtUtil;
  15. import com.ruoyi.system.utils.RedisUtils;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiOperation;
  18. import io.swagger.v3.oas.annotations.tags.Tag;
  19. import org.springframework.security.access.prepost.PreAuthorize;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import com.ruoyi.common.annotation.Log;
  23. import com.ruoyi.common.core.controller.BaseController;
  24. import com.ruoyi.common.core.domain.AjaxResult;
  25. import com.ruoyi.common.enums.BusinessType;
  26. import com.ruoyi.system.domain.VideoCall;
  27. import com.ruoyi.system.service.IVideoCallService;
  28. import com.ruoyi.common.utils.MessageUtils;
  29. import com.ruoyi.common.utils.poi.ExcelUtil;
  30. import com.ruoyi.common.core.page.TableDataInfo;
  31. /**
  32. * VideoCallController
  33. *
  34. * @author ruoyi
  35. * @date 2024-03-05
  36. */
  37. @Api(value = "VideoCallController", description = "视频呼叫")
  38. @RestController
  39. @RequestMapping("/system/call")
  40. public class VideoCallController extends BaseController
  41. {
  42. @Autowired
  43. private IVideoCallService videoCallService;
  44. @Autowired
  45. private IInfoUserService infoUserService;
  46. @Autowired
  47. private VideoCallMapper videoCallMapper;
  48. /**
  49. *
  50. * @param token
  51. * @return
  52. */
  53. @ApiOperation("主动挂断电话请求")
  54. @Anonymous
  55. @Auth
  56. @GetMapping("/ringoff")
  57. public AjaxResult ringoff(@RequestHeader String token) {
  58. JwtUtil jwtUtil = new JwtUtil();
  59. String id = jwtUtil.getusid(token);
  60. QueryWrapper<VideoCall> wrapper = new QueryWrapper<>();
  61. wrapper.eq("call_id",id).or().eq("user_id",id);
  62. List<VideoCall> call = videoCallService.list(wrapper);
  63. if(call.size()==0){
  64. return error(MessageUtils.message("no.user.call.status.not.exis"));
  65. }else {
  66. for (int i=0;i<call.size();i++){
  67. InfoUser user = infoUserService.getById(String.valueOf(id).equals(String.valueOf(call.get(i).getUserId()))?call.get(i).getCallId():call.get(i).getUserId());
  68. videoCallService.deleteVideoCallById(call.get(i).getId());
  69. PayPush push = new PayPush();
  70. if(user.getUserType().equals("0")){
  71. push.apppush(
  72. user.getCid(),
  73. MessageUtils.message("no.message.push.end.call"),
  74. MessageUtils.message("no.message.push.call.hangup"),
  75. ""
  76. );
  77. }
  78. if(user.getUserType().equals("1")){
  79. push.shpush(
  80. user.getCid(),
  81. MessageUtils.message("no.message.push.end.call"),
  82. MessageUtils.message("no.message.push.call.hangup"),
  83. ""
  84. );
  85. }
  86. if(user.getUserType().equals("2")){
  87. push.qspush(
  88. user.getCid(),
  89. MessageUtils.message("no.message.push.end.call"),
  90. MessageUtils.message("no.message.push.call.hangup"),
  91. ""
  92. );
  93. }
  94. }
  95. return success(MessageUtils.message("no.user.call.hangup.success"));
  96. }
  97. }
  98. /**
  99. *
  100. * @param token
  101. * @return
  102. */
  103. @ApiOperation("获取通话内容消息")
  104. @Anonymous
  105. @Auth
  106. @GetMapping("/getCall")
  107. public AjaxResult getCall(@RequestHeader String token) {
  108. JwtUtil jwtUtil = new JwtUtil();
  109. Long id = Long.valueOf(jwtUtil.getusid(token));
  110. QueryWrapper<VideoCall> wrapper = new QueryWrapper<>();
  111. wrapper.eq("call_id",id).or().eq("user_id",id);
  112. VideoCall call = videoCallService.getOne(wrapper);
  113. if(call==null){
  114. return error(MessageUtils.message("no.user.call.not.exist"));
  115. }
  116. JSONObject obj = new JSONObject();
  117. String content=call.getContent();
  118. String answer=call.getAnswer();
  119. JSONObject jscon=JSONObject.parseObject(content);
  120. JSONObject jsansw=JSONObject.parseObject(answer);
  121. obj.put("content",jscon);
  122. obj.put("answer",jsansw);
  123. return success(MessageUtils.message("no.action.success"), obj);
  124. }
  125. /**
  126. * 用户提交呼叫信息
  127. * @param token
  128. * @param videoCall
  129. * @return
  130. */
  131. @ApiOperation("用户提交呼叫信息")
  132. @Anonymous
  133. @Auth
  134. @RepeatSubmit(message = "请求过于频繁")
  135. @PostMapping("/userCall")
  136. public AjaxResult userCall(@RequestHeader String token, @RequestBody VideoCall videoCall) {
  137. JwtUtil jwtUtil = new JwtUtil();
  138. Long id = Long.valueOf(jwtUtil.getusid(token));
  139. QueryWrapper<VideoCall> wrapper = new QueryWrapper<>();
  140. wrapper.eq("user_id",id).or().eq("call_id",id);;
  141. VideoCall call = videoCallService.getOne(wrapper);
  142. if(call==null){
  143. QueryWrapper<VideoCall> query = new QueryWrapper<>();
  144. query.eq("call_id",videoCall.getCallId()).or().eq("user_id",videoCall.getCallId());
  145. VideoCall videoCall1 = videoCallService.getOne(query);
  146. if(videoCall1==null){
  147. VideoCall video = new VideoCall();
  148. PayPush push = new PayPush();
  149. video.setUserId(id);
  150. video.setCallId(videoCall.getCallId());
  151. video.setContent(videoCall.getContent());
  152. videoCallService.saveOrUpdate(video);
  153. InfoUser colluser = infoUserService.getById(videoCall.getCallId());
  154. InfoUser falluser = infoUserService.getById(id);
  155. if(colluser.getUserType().equals("0")){
  156. push.apppush(
  157. colluser.getCid(),
  158. MessageUtils.message("no.message.push.call.calling"),
  159. falluser.getNickName()+MessageUtils.message("no.message.push.call.request"),
  160. String.valueOf(falluser.getUserId())
  161. );
  162. }
  163. if(colluser.getUserType().equals("1")){
  164. push.shpush(
  165. colluser.getCid(),
  166. MessageUtils.message("no.message.push.call.calling"),
  167. falluser.getNickName()+MessageUtils.message("no.message.push.call.request"),
  168. String.valueOf(falluser.getUserId())
  169. );
  170. }
  171. if(colluser.getUserType().equals("2")){
  172. push.qspush(
  173. colluser.getCid(),
  174. MessageUtils.message("no.message.push.call.calling"),
  175. falluser.getNickName()+MessageUtils.message("no.message.push.call.request"),
  176. String.valueOf(falluser.getUserId())
  177. );
  178. }
  179. return success(MessageUtils.message("no.user.call.calling.success"));
  180. }else {
  181. return error(MessageUtils.message("no.user.call.other.is.calling"));
  182. }
  183. }else {
  184. if(call.getCallId().equals(id)){
  185. PayPush push = new PayPush();
  186. call.setAnswer(videoCall.getContent());
  187. videoCallService.updateVideoCall(call);
  188. InfoUser colluser = infoUserService.getById(call.getUserId());
  189. InfoUser falluser = infoUserService.getById(id);
  190. if(colluser.getUserType().equals("0")){
  191. push.apppush(
  192. colluser.getCid(),
  193. MessageUtils.message("no.message.push.call.accept"),
  194. falluser.getNickName() + MessageUtils.message("no.message.push.call.agree"),
  195. String.valueOf(falluser.getUserId())
  196. );
  197. }
  198. if(colluser.getUserType().equals("1")){
  199. push.shpush(
  200. colluser.getCid(),
  201. MessageUtils.message("no.message.push.call.accept"),
  202. falluser.getNickName() + MessageUtils.message("no.message.push.call.agree"),
  203. String.valueOf(falluser.getUserId())
  204. );
  205. }
  206. if(colluser.getUserType().equals("2")){
  207. push.qspush(
  208. colluser.getCid(),
  209. MessageUtils.message("no.message.push.call.accept"),
  210. falluser.getNickName() + MessageUtils.message("no.message.push.call.agree"),
  211. String.valueOf(falluser.getUserId())
  212. );
  213. }
  214. return success(MessageUtils.message("no.user.call.accept.success"));
  215. }else{
  216. PayPush push = new PayPush();
  217. call.setCallId(videoCall.getCallId());
  218. call.setContent(videoCall.getContent());
  219. videoCallService.updateVideoCall(call);
  220. InfoUser colluser = infoUserService.getById(call.getCallId());
  221. InfoUser falluser = infoUserService.getById(id);
  222. if(colluser.getUserType().equals("0")){
  223. push.apppush(
  224. colluser.getCid(),
  225. MessageUtils.message("no.message.push.call.calling"),
  226. falluser.getNickName()+MessageUtils.message("no.message.push.call.request"),
  227. String.valueOf(falluser.getUserId())
  228. );
  229. }
  230. if(colluser.getUserType().equals("1")){
  231. push.shpush(
  232. colluser.getCid(),
  233. MessageUtils.message("no.message.push.call.calling"),
  234. falluser.getNickName()+MessageUtils.message("no.message.push.call.request"),
  235. String.valueOf(falluser.getUserId())
  236. );
  237. }
  238. if(colluser.getUserType().equals("2")){
  239. push.qspush(
  240. colluser.getCid(),
  241. MessageUtils.message("no.message.push.call.calling"),
  242. falluser.getNickName()+MessageUtils.message("no.message.push.call.request"),
  243. String.valueOf(falluser.getUserId())
  244. );
  245. }
  246. return success(MessageUtils.message("no.user.call.request.success"));
  247. }
  248. }
  249. }
  250. /**
  251. * 查询VideoCall列表
  252. */
  253. @ApiOperation("查询VideoCall列表")
  254. @PreAuthorize("@ss.hasPermi('system:call:list')")
  255. @GetMapping("/list")
  256. public TableDataInfo list(VideoCall videoCall)
  257. {
  258. startPage();
  259. List<VideoCall> list = videoCallService.selectVideoCallList(videoCall);
  260. return getDataTable(list);
  261. }
  262. /**
  263. * 导出VideoCall列表
  264. */
  265. @ApiOperation("导出VideoCall列表")
  266. @PreAuthorize("@ss.hasPermi('system:call:export')")
  267. @Log(title = "VideoCall", businessType = BusinessType.EXPORT)
  268. @PostMapping("/export")
  269. public void export(HttpServletResponse response, VideoCall videoCall)
  270. {
  271. List<VideoCall> list = videoCallService.selectVideoCallList(videoCall);
  272. ExcelUtil<VideoCall> util = new ExcelUtil<VideoCall>(VideoCall.class);
  273. util.exportExcel(response, list, MessageUtils.message("no.export.excel.videocall"));
  274. }
  275. /**
  276. * 获取VideoCall详细信息
  277. */
  278. @ApiOperation("获取VideoCall详细信息")
  279. @PreAuthorize("@ss.hasPermi('system:call:query')")
  280. @GetMapping(value = "/{id}")
  281. public AjaxResult getInfo(@PathVariable("id") Long id)
  282. {
  283. return success(videoCallService.selectVideoCallById(id));
  284. }
  285. /**
  286. * 新增VideoCall
  287. */
  288. @ApiOperation("新增VideoCall")
  289. @PreAuthorize("@ss.hasPermi('system:call:add')")
  290. @Log(title = "VideoCall", businessType = BusinessType.INSERT)
  291. @PostMapping
  292. public AjaxResult add(@RequestBody VideoCall videoCall)
  293. {
  294. return toAjax(videoCallService.insertVideoCall(videoCall));
  295. }
  296. /**
  297. * 修改VideoCall
  298. */
  299. @ApiOperation("修改VideoCall")
  300. @PreAuthorize("@ss.hasPermi('system:call:edit')")
  301. @Log(title = "VideoCall", businessType = BusinessType.UPDATE)
  302. @PutMapping
  303. public AjaxResult edit(@RequestBody VideoCall videoCall)
  304. {
  305. return toAjax(videoCallService.updateVideoCall(videoCall));
  306. }
  307. /**
  308. * 删除VideoCall
  309. */
  310. @ApiOperation("删除VideoCall")
  311. @PreAuthorize("@ss.hasPermi('system:call:remove')")
  312. @Log(title = "VideoCall", businessType = BusinessType.DELETE)
  313. @DeleteMapping("/{ids}")
  314. public AjaxResult remove(@PathVariable Long[] ids)
  315. {
  316. return toAjax(videoCallService.deleteVideoCallByIds(ids));
  317. }
  318. }