DocShareController.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package com.doc.biz.controller;
  2. import com.doc.biz.domain.DocInfo;
  3. import com.doc.biz.domain.DocShare;
  4. import com.doc.biz.service.IDocInfoService;
  5. import com.doc.biz.service.IDocShareService;
  6. import com.doc.chat.domain.ChatMsg;
  7. import com.doc.chat.service.IChatMsgService;
  8. import com.doc.common.core.controller.BaseController;
  9. import com.doc.common.core.domain.AjaxResult;
  10. import com.doc.common.enums.SmsType;
  11. import com.doc.common.utils.SecurityUtils;
  12. import com.doc.sms.service.ISmsService;
  13. import com.doc.system.service.ISysUserService;
  14. import io.swagger.annotations.Api;
  15. import io.swagger.annotations.ApiOperation;
  16. import io.swagger.annotations.ApiParam;
  17. import javafx.util.Pair;
  18. import org.springframework.web.bind.annotation.*;
  19. import javax.annotation.Resource;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. /**
  23. * 文档分享Controller
  24. *
  25. * @author wukai
  26. * @date 2023-08-15
  27. */
  28. @Api(tags = "文档分享")
  29. @RestController
  30. @RequestMapping("/biz/share")
  31. public class DocShareController extends BaseController {
  32. @Resource
  33. private IDocShareService docShareService;
  34. @Resource
  35. private IChatMsgService msgService;
  36. @Resource
  37. private ISysUserService userService;
  38. @Resource
  39. private IDocInfoService docInfoService;
  40. @Resource
  41. private ISmsService smsService;
  42. /**
  43. * 文件分享
  44. */
  45. @ApiOperation("获取已选择人员")
  46. @GetMapping("/{docId}")
  47. public List<DocShare> shareInfo(@ApiParam(value = "文件ID", required = true) @PathVariable(name = "docId") Long docId) {
  48. return docShareService.selectDocShareListByDocId(docId);
  49. }
  50. /**
  51. * 文件分享
  52. */
  53. @ApiOperation("添加人员")
  54. @PostMapping("/{docId}")
  55. public AjaxResult share(@ApiParam(value = "文件ID", required = true) @PathVariable(name = "docId") Long docId, @ApiParam(value = "分享人员", required = true) @RequestBody List<Long> users) {
  56. //获取之前已选择的人员
  57. List<DocShare> list = docShareService.selectDocShareListByDocId(docId);
  58. // docShareService.deleteDocShareByDocId(docId);
  59. List<Long> oldUsers = new ArrayList<>();
  60. list.forEach(au -> {
  61. if (!users.contains(au.getUserId())) {
  62. //如果当前列表没有的人员,则删除数据库记录
  63. docShareService.deleteDocShareByShareId(au.getShareId());
  64. } else {
  65. //如果数据库中已有该用户,则记录下来,后面的逻辑中使用
  66. oldUsers.add(au.getUserId());
  67. }
  68. });
  69. users.forEach(uid -> {
  70. if (oldUsers.contains(uid)) {
  71. //如果数据库中已有,则不作任何处理
  72. return;
  73. }
  74. //发送消息
  75. ChatMsg msg = new ChatMsg();
  76. msg.setMsgType("1");
  77. msg.setToId(uid);
  78. msg.setContent(docId + "");
  79. msg.setFromId(SecurityUtils.getUserId());
  80. msgService.send(msg);
  81. Pair<Boolean, String> pair = userService.isOnline(uid);
  82. if (!pair.getKey()) {
  83. String fromUser = SecurityUtils.getLoginUser().getUser().getNickName();
  84. DocInfo docInfo = docInfoService.selectDocInfoByDocId(docId);
  85. String fileName = docInfo.getFileName();
  86. String split = ".";
  87. int pos = fileName.indexOf(split);
  88. if (pos != -1) {
  89. fileName = fileName.substring(0, pos);
  90. }
  91. //如果不在线发送短信
  92. smsService.send(SmsType.FILE_SHARE, pair.getValue(), fromUser, fileName);
  93. }
  94. //添加人员
  95. DocShare share = new DocShare();
  96. share.setDocId(docId);
  97. share.setUserId(uid);
  98. docShareService.insertDocShare(share);
  99. });
  100. return success();
  101. }
  102. //
  103. // /**
  104. // * 查询文档分享列表
  105. // */
  106. //// @ApiOperation("查询文档分享列表")
  107. // //@PreAuthorize("@ss.hasPermi('biz:share:list')")
  108. // @GetMapping("/list")
  109. // public TableDataInfo list(DocShare docShare) {
  110. // startPage();
  111. // List<DocShare> list = docShareService.selectDocShareList(docShare);
  112. // return getDataTable(list);
  113. // }
  114. //
  115. // /**
  116. // * 导出文档分享列表
  117. // */
  118. //// @ApiOperation("导出文档分享列表")
  119. // //@PreAuthorize("@ss.hasPermi('biz:share:export')")
  120. // @Log(title = "文档分享", businessType = BusinessType.EXPORT)
  121. // @PostMapping("/export")
  122. // public void export(HttpServletResponse response, DocShare docShare) {
  123. // List<DocShare> list = docShareService.selectDocShareList(docShare);
  124. // ExcelUtil<DocShare> util = new ExcelUtil<DocShare>(DocShare.class);
  125. // util.exportExcel(response, list, "文档分享数据");
  126. // }
  127. //
  128. // /**
  129. // * 获取文档分享详细信息
  130. // */
  131. //// @ApiOperation("获取文档分享详细信息")
  132. // //@PreAuthorize("@ss.hasPermi('biz:share:query')")
  133. // @GetMapping(value = "/{shareId}")
  134. // public AjaxResult getInfo(@PathVariable("shareId") Long shareId) {
  135. // return success(docShareService.selectDocShareByShareId(shareId));
  136. // }
  137. //
  138. // /**
  139. // * 新增文档分享
  140. // */
  141. //// @ApiOperation("新增文档分享")
  142. // //@PreAuthorize("@ss.hasPermi('biz:share:add')")
  143. // @Log(title = "文档分享", businessType = BusinessType.INSERT)
  144. // @PostMapping
  145. // public AjaxResult add(@RequestBody DocShare docShare) {
  146. // return toAjax(docShareService.insertDocShare(docShare));
  147. // }
  148. //
  149. // /**
  150. // * 修改文档分享
  151. // */
  152. //// @ApiOperation("修改文档分享")
  153. // //@PreAuthorize("@ss.hasPermi('biz:share:edit')")
  154. // @Log(title = "文档分享", businessType = BusinessType.UPDATE)
  155. // @PutMapping
  156. // public AjaxResult edit(@RequestBody DocShare docShare) {
  157. // return toAjax(docShareService.updateDocShare(docShare));
  158. // }
  159. //
  160. // /**
  161. // * 删除文档分享
  162. // */
  163. //// @ApiOperation("删除文档分享")
  164. // //@PreAuthorize("@ss.hasPermi('biz:share:remove')")
  165. // @Log(title = "文档分享", businessType = BusinessType.DELETE)
  166. // @DeleteMapping("/{shareIds}")
  167. // public AjaxResult remove(@PathVariable Long[] shareIds) {
  168. // return toAjax(docShareService.deleteDocShareByShareIds(shareIds));
  169. // }
  170. }