MessageController.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.bank.message.controller;
  18. import cn.hutool.json.JSONUtil;
  19. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import io.swagger.annotations.ApiParam;
  23. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  24. import lombok.AllArgsConstructor;
  25. import javax.validation.Valid;
  26. import org.springblade.bank.checklist.entity.Checklist;
  27. import org.springblade.bank.userlog.entity.UserLog;
  28. import org.springblade.bank.userlog.service.IUserLogService;
  29. import org.springblade.core.mp.support.Condition;
  30. import org.springblade.core.mp.support.Query;
  31. import org.springblade.core.secure.BladeUser;
  32. import org.springblade.core.secure.utils.AuthUtil;
  33. import org.springblade.core.tool.api.R;
  34. import org.springblade.core.tool.utils.DateUtil;
  35. import org.springblade.core.tool.utils.Func;
  36. import org.springblade.core.tool.utils.StringUtil;
  37. import org.springblade.modules.desk.entity.Notice;
  38. import org.springblade.modules.desk.service.INoticeService;
  39. import org.springblade.modules.resource.entity.Attach;
  40. import org.springblade.modules.resource.service.IAttachService;
  41. import org.springblade.modules.system.entity.Dept;
  42. import org.springblade.modules.system.entity.User;
  43. import org.springblade.modules.system.service.IDeptService;
  44. import org.springblade.modules.system.service.IUserService;
  45. import org.springframework.util.Assert;
  46. import org.springframework.util.StringUtils;
  47. import org.springframework.web.bind.annotation.*;
  48. import org.springframework.web.bind.annotation.RequestParam;
  49. import com.baomidou.mybatisplus.core.metadata.IPage;
  50. import org.springblade.bank.message.entity.Message;
  51. import org.springblade.bank.message.vo.MessageVO;
  52. import org.springblade.bank.message.wrapper.MessageWrapper;
  53. import org.springblade.bank.message.service.IMessageService;
  54. import org.springblade.core.boot.ctrl.BladeController;
  55. import java.util.ArrayList;
  56. import java.util.List;
  57. import java.util.stream.Collectors;
  58. /**
  59. * 信息發佈 控制器
  60. *
  61. * @author BladeX
  62. * @since 2021-08-13
  63. */
  64. @RestController
  65. @AllArgsConstructor
  66. @RequestMapping("bank/message")
  67. @Api(value = "信息發佈", tags = "信息發佈接口")
  68. public class MessageController extends BladeController {
  69. private final IMessageService messageService;
  70. private final IAttachService attachService;
  71. private final IDeptService deptService;
  72. private final IUserService userService;
  73. private final IUserLogService userLogService;
  74. private final INoticeService noticeService;
  75. /**
  76. * 详情
  77. */
  78. @GetMapping("/detail")
  79. @ApiOperationSupport(order = 1)
  80. @ApiOperation(value = "详情", notes = "传入message")
  81. public R<MessageVO> detail(Message message) {
  82. Message detail = messageService.getOne(Condition.getQueryWrapper(message));
  83. return R.data(MessageWrapper.build().entityVO(detail));
  84. }
  85. /**
  86. * 分页 信息發佈
  87. */
  88. @GetMapping("/list")
  89. @ApiOperationSupport(order = 2)
  90. @ApiOperation(value = "分页", notes = "传入message")
  91. public R<IPage<MessageVO>> list(Message message, Query query) {
  92. IPage<Message> pages = messageService.page(Condition.getPage(query), Condition.getQueryWrapper(message));
  93. return R.data(MessageWrapper.build().pageVO(pages));
  94. }
  95. /**
  96. * 自定义分页 信息發佈
  97. */
  98. @GetMapping("/page")
  99. @ApiOperationSupport(order = 3)
  100. @ApiOperation(value = "分页", notes = "传入message")
  101. public R<IPage<MessageVO>> page(MessageVO message, Query query) {
  102. // message.setCreateUser(AuthUtil.getUserId());
  103. message.setCurrentUserId(AuthUtil.getUserId());
  104. IPage<Message> pages = messageService.selectMessagePage(Condition.getPage(query), message);
  105. return R.data(MessageWrapper.build().pageVO(pages));
  106. }
  107. /**
  108. * 新增 信息發佈
  109. */
  110. @PostMapping("/save")
  111. @ApiOperationSupport(order = 4)
  112. @ApiOperation(value = "新增", notes = "传入message")
  113. public R save(@Valid @RequestBody Message message) {
  114. return R.status(messageService.save(message));
  115. }
  116. /**
  117. * 修改 信息發佈
  118. */
  119. @PostMapping("/update")
  120. @ApiOperationSupport(order = 5)
  121. @ApiOperation(value = "修改", notes = "传入message")
  122. public R update(@Valid @RequestBody Message message) {
  123. return R.status(messageService.updateById(message));
  124. }
  125. /**
  126. * 新增或修改 信息發佈
  127. */
  128. @PostMapping("/submit")
  129. @ApiOperationSupport(order = 6)
  130. @ApiOperation(value = "新增或修改", notes = "传入message")
  131. public R submit(@Valid @RequestBody Message message) {
  132. Attach attach = attachService.getOne(new QueryWrapper<>(new Attach()).lambda().eq(Attach::getLink, message.getFile()));
  133. // Assert.notNull(attach, "找不到附件");
  134. if (attach != null){
  135. message.setName(attach.getName());
  136. message.setDomain(attach.getDomain());
  137. message.setOriginalName(attach.getOriginalName());
  138. message.setExtension(attach.getExtension());
  139. message.setAttachSize(attach.getAttachSize());
  140. }
  141. List<String> deptIds = Func.toStrList(message.getDeptId());
  142. List<String> roleIds = Func.toStrList(message.getRoleId());
  143. List<User> userList = userService.getUsersByDeptIdsRoleIds(deptIds, roleIds);
  144. List<Long> userIdList = userList.stream().map(user -> user.getId()).collect(Collectors.toList());
  145. String join = StringUtil.join(userIdList);
  146. // join += "," + AuthUtil.getUserId();
  147. message.setTargetIds(join);
  148. boolean isAdd = message.getId() == null;
  149. BladeUser currentUser = AuthUtil.getUser();
  150. User user = userService.getById(currentUser.getUserId());
  151. Dept dept = deptService.getById(user.getDeptId());
  152. UserLog userLog = new UserLog();
  153. Message old = null;
  154. if (isAdd){
  155. // messageService.save(message);
  156. // message.setCreateDept(message.getDeptId());
  157. }else{
  158. old = messageService.getById(message.getId());
  159. }
  160. if (messageService.saveOrUpdate(message)){
  161. userLog.setTableName("message");
  162. userLog.setBankNo(dept.getBankNo());
  163. userLog.setOrgNo(dept.getOrgNo());
  164. userLog.setOrgName(dept.getDeptName());
  165. userLog.setNewData(JSONUtil.toJsonStr(message));
  166. userLog.setPersonNo(user.getEhr());
  167. userLog.setPersonName(user.getName());
  168. if (isAdd){
  169. userLog.setOperationType("add");
  170. // 發送通知
  171. noticeService.sendMessageNotice(message, false);
  172. }else{
  173. userLog.setOperationType("edit");
  174. userLog.setOldData(JSONUtil.toJsonStr(old));
  175. // 發送通知
  176. noticeService.sendMessageNotice(message, true);
  177. }
  178. userLogService.save(userLog);
  179. }
  180. return R.status(true);
  181. }
  182. /**
  183. * 删除 信息發佈
  184. */
  185. @PostMapping("/remove")
  186. @ApiOperationSupport(order = 7)
  187. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  188. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  189. List<Long> idList = Func.toLongList(ids);
  190. List<UserLog> userLogList = new ArrayList<>();
  191. // 日誌記錄
  192. BladeUser currentUser = AuthUtil.getUser();
  193. User user = userService.getById(currentUser.getUserId());
  194. Dept dept = deptService.getById(user.getDeptId());
  195. idList.forEach(id -> {
  196. UserLog userLog = new UserLog();
  197. Message message = messageService.getById(id);
  198. userLog.setTableName("message");
  199. userLog.setOperationType("del");
  200. userLog.setBankNo(dept.getBankNo());
  201. userLog.setOrgNo(dept.getOrgNo());
  202. userLog.setOrgName(dept.getDeptName());
  203. userLog.setOldData(JSONUtil.toJsonStr(message));
  204. userLog.setPersonNo(user.getEhr());
  205. userLog.setPersonName(user.getName());
  206. userLogList.add(userLog);
  207. });
  208. return R.status(messageService.deleteLogic(idList) && userLogService.saveBatch(userLogList));
  209. }
  210. }