| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package com.doc.biz.controller;
- import com.doc.biz.domain.DocInfo;
- import com.doc.biz.domain.DocShare;
- import com.doc.biz.service.IDocInfoService;
- import com.doc.biz.service.IDocShareService;
- import com.doc.chat.domain.ChatMsg;
- import com.doc.chat.service.IChatMsgService;
- import com.doc.common.core.controller.BaseController;
- import com.doc.common.core.domain.AjaxResult;
- import com.doc.common.enums.SmsType;
- import com.doc.common.utils.SecurityUtils;
- import com.doc.sms.service.ISmsService;
- import com.doc.system.service.ISysUserService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import javafx.util.Pair;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 文档分享Controller
- *
- * @author wukai
- * @date 2023-08-15
- */
- @Api(tags = "文档分享")
- @RestController
- @RequestMapping("/biz/share")
- public class DocShareController extends BaseController {
- @Resource
- private IDocShareService docShareService;
- @Resource
- private IChatMsgService msgService;
- @Resource
- private ISysUserService userService;
- @Resource
- private IDocInfoService docInfoService;
- @Resource
- private ISmsService smsService;
- /**
- * 文件分享
- */
- @ApiOperation("获取已选择人员")
- @GetMapping("/{docId}")
- public List<DocShare> shareInfo(@ApiParam(value = "文件ID", required = true) @PathVariable(name = "docId") Long docId) {
- return docShareService.selectDocShareListByDocId(docId);
- }
- /**
- * 文件分享
- */
- @ApiOperation("添加人员")
- @PostMapping("/{docId}")
- public AjaxResult share(@ApiParam(value = "文件ID", required = true) @PathVariable(name = "docId") Long docId, @ApiParam(value = "分享人员", required = true) @RequestBody List<Long> users) {
- //获取之前已选择的人员
- List<DocShare> list = docShareService.selectDocShareListByDocId(docId);
- // docShareService.deleteDocShareByDocId(docId);
- List<Long> oldUsers = new ArrayList<>();
- list.forEach(au -> {
- if (!users.contains(au.getUserId())) {
- //如果当前列表没有的人员,则删除数据库记录
- docShareService.deleteDocShareByShareId(au.getShareId());
- } else {
- //如果数据库中已有该用户,则记录下来,后面的逻辑中使用
- oldUsers.add(au.getUserId());
- }
- });
- users.forEach(uid -> {
- if (oldUsers.contains(uid)) {
- //如果数据库中已有,则不作任何处理
- return;
- }
- //发送消息
- ChatMsg msg = new ChatMsg();
- msg.setMsgType("1");
- msg.setToId(uid);
- msg.setContent(docId + "");
- msg.setFromId(SecurityUtils.getUserId());
- msgService.send(msg);
- Pair<Boolean, String> pair = userService.isOnline(uid);
- if (!pair.getKey()) {
- String fromUser = SecurityUtils.getLoginUser().getUser().getNickName();
- DocInfo docInfo = docInfoService.selectDocInfoByDocId(docId);
- String fileName = docInfo.getFileName();
- String split = ".";
- int pos = fileName.indexOf(split);
- if (pos != -1) {
- fileName = fileName.substring(0, pos);
- }
- //如果不在线发送短信
- smsService.send(SmsType.FILE_SHARE, pair.getValue(), fromUser, fileName);
- }
- //添加人员
- DocShare share = new DocShare();
- share.setDocId(docId);
- share.setUserId(uid);
- docShareService.insertDocShare(share);
- });
- return success();
- }
- //
- // /**
- // * 查询文档分享列表
- // */
- //// @ApiOperation("查询文档分享列表")
- // //@PreAuthorize("@ss.hasPermi('biz:share:list')")
- // @GetMapping("/list")
- // public TableDataInfo list(DocShare docShare) {
- // startPage();
- // List<DocShare> list = docShareService.selectDocShareList(docShare);
- // return getDataTable(list);
- // }
- //
- // /**
- // * 导出文档分享列表
- // */
- //// @ApiOperation("导出文档分享列表")
- // //@PreAuthorize("@ss.hasPermi('biz:share:export')")
- // @Log(title = "文档分享", businessType = BusinessType.EXPORT)
- // @PostMapping("/export")
- // public void export(HttpServletResponse response, DocShare docShare) {
- // List<DocShare> list = docShareService.selectDocShareList(docShare);
- // ExcelUtil<DocShare> util = new ExcelUtil<DocShare>(DocShare.class);
- // util.exportExcel(response, list, "文档分享数据");
- // }
- //
- // /**
- // * 获取文档分享详细信息
- // */
- //// @ApiOperation("获取文档分享详细信息")
- // //@PreAuthorize("@ss.hasPermi('biz:share:query')")
- // @GetMapping(value = "/{shareId}")
- // public AjaxResult getInfo(@PathVariable("shareId") Long shareId) {
- // return success(docShareService.selectDocShareByShareId(shareId));
- // }
- //
- // /**
- // * 新增文档分享
- // */
- //// @ApiOperation("新增文档分享")
- // //@PreAuthorize("@ss.hasPermi('biz:share:add')")
- // @Log(title = "文档分享", businessType = BusinessType.INSERT)
- // @PostMapping
- // public AjaxResult add(@RequestBody DocShare docShare) {
- // return toAjax(docShareService.insertDocShare(docShare));
- // }
- //
- // /**
- // * 修改文档分享
- // */
- //// @ApiOperation("修改文档分享")
- // //@PreAuthorize("@ss.hasPermi('biz:share:edit')")
- // @Log(title = "文档分享", businessType = BusinessType.UPDATE)
- // @PutMapping
- // public AjaxResult edit(@RequestBody DocShare docShare) {
- // return toAjax(docShareService.updateDocShare(docShare));
- // }
- //
- // /**
- // * 删除文档分享
- // */
- //// @ApiOperation("删除文档分享")
- // //@PreAuthorize("@ss.hasPermi('biz:share:remove')")
- // @Log(title = "文档分享", businessType = BusinessType.DELETE)
- // @DeleteMapping("/{shareIds}")
- // public AjaxResult remove(@PathVariable Long[] shareIds) {
- // return toAjax(docShareService.deleteDocShareByShareIds(shareIds));
- // }
- }
|