RepairLeaveMessageController.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package com.repair.controller;
  2. import com.repair.api.RepairLeaveMessageControllerAPI;
  3. import com.repair.common.utils.paramUtils;
  4. import com.repair.model.enumModel.eRecordStatu;
  5. import com.repair.model.pojo.RepairLeaveMessage;
  6. import com.repair.model.pojo.RepairRecord;
  7. import com.repair.model.pojo.RepairSystemMessages;
  8. import com.repair.model.pojo.RepairTrackRecord;
  9. import com.repair.model.request.repairLeaveMessageRequest;
  10. import com.repair.model.result.CommonResult;
  11. import com.repair.model.result.PageUtils;
  12. import com.repair.model.vo.RepairLogisticsVo;
  13. import com.repair.services.*;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import org.springframework.validation.BindingResult;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. /**
  21. * <p>
  22. * 前端控制器
  23. * </p>
  24. *
  25. * @author ceshi
  26. * @since 2023-07-20
  27. */
  28. @RestController
  29. public class RepairLeaveMessageController implements RepairLeaveMessageControllerAPI {
  30. @Autowired
  31. private RepairUserService repairUserService;
  32. @Autowired
  33. private RepairRecordService repairRecordService;
  34. @Autowired
  35. private RepairTrackRecordService repairTrackRecordService;
  36. @Autowired
  37. private RepairLeaveMessageService repairLeaveMessageService;
  38. @Autowired
  39. private RepairSystemMessagesService repairSystemMessagesService;
  40. /**
  41. * 新增留言信息
  42. * @param rc 留言信息
  43. * @param bindingResult 是否为空判断
  44. * @return
  45. */
  46. @Override
  47. public CommonResult insertRepairLeaveMessage(RepairLeaveMessage rc, BindingResult bindingResult) {
  48. if (bindingResult.hasErrors()) {
  49. String st = paramUtils.getParamError(bindingResult);
  50. return CommonResult.fail(st);
  51. }
  52. int result = repairLeaveMessageService.insertRepairLeaveMessage(rc);
  53. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  54. }
  55. /**
  56. * 根据数据ID更新留言信息
  57. * @param rc 留言信息
  58. * @param bindingResult
  59. * @return
  60. */
  61. @Override
  62. public CommonResult updateRepairLeaveMessageById(RepairLeaveMessage rc, BindingResult bindingResult) {
  63. if (bindingResult.hasErrors()) {
  64. String st = paramUtils.getParamError(bindingResult);
  65. return CommonResult.fail(st);
  66. }
  67. int result = repairLeaveMessageService.updateRepairLeaveMessage(rc);
  68. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  69. }
  70. @Override
  71. public CommonResult queryPageRepairLeaveMessages(int currentPage, int pageCount, String name) {
  72. PageUtils<RepairLeaveMessage> result = repairLeaveMessageService.queryPageRepairLeaveMessages(currentPage, pageCount, name);
  73. return CommonResult.ok(result);
  74. }
  75. @Override
  76. public CommonResult deleteRepairLeaveMessageById(int id) {
  77. RepairLeaveMessage data = repairLeaveMessageService.getRepairById(id);
  78. if (data == null) {
  79. return CommonResult.fail("当前数据不存在,删除失败!");
  80. }
  81. int result = repairLeaveMessageService.deleteRepairLeaveMessageById(id);
  82. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  83. }
  84. @Override
  85. @Transactional(rollbackFor = {Exception.class})
  86. public CommonResult transferToLogistics(repairLeaveMessageRequest rlmr, BindingResult bindingResult) throws Exception {
  87. if (bindingResult.hasErrors()) {
  88. String st = paramUtils.getParamError(bindingResult);
  89. return CommonResult.fail(st);
  90. }
  91. //只有待确认能转后勤
  92. RepairRecord rr = repairRecordService.getRepairById(rlmr.getRecordId());
  93. if (rr == null) {
  94. return CommonResult.fail("报修单不存在,转后勤失败");
  95. }
  96. if (rr.getMaintenanceState() != eRecordStatu.ToConfirmed.getValue()) {
  97. return CommonResult.fail("待确认的报修单才能进行转后勤操作");
  98. }
  99. /**
  100. * 获取报修工单对应校区的所有后勤人员
  101. */
  102. List<RepairLogisticsVo> users = repairUserService.queryLogisticsList(rlmr.getRecordId());
  103. if (users.size() <= 0) {
  104. return CommonResult.fail("该报修区域缺少后勤人员");
  105. }
  106. //有可能有多个后勤
  107. List<RepairLeaveMessage> datas = new ArrayList<>();
  108. List<RepairSystemMessages> messages = new ArrayList<>();
  109. for (RepairLogisticsVo u : users) {
  110. RepairLeaveMessage data = new RepairLeaveMessage();
  111. data.setSenderId(rlmr.getUserId());
  112. data.setRecipientId(u.getId());
  113. data.setContent(rlmr.getContent());
  114. data.setRecordId(rlmr.getRecordId());
  115. datas.add(data);
  116. RepairSystemMessages rsm = new RepairSystemMessages();
  117. rsm.setIsRead(0);
  118. rsm.setRecordId(rlmr.getUserId());
  119. rsm.setRecipientId(u.getId());
  120. rsm.setContent("用户已提交留言,请尽快处理!");
  121. messages.add(rsm);
  122. }
  123. try {
  124. boolean result = repairLeaveMessageService.inserBatchLeaveMessage(datas);
  125. if (!result) {
  126. throw new Exception("转后勤失败!");
  127. }
  128. //将工单状态更改为待处理
  129. rr.setId(rlmr.getRecordId());
  130. rr.setMaintenanceState(eRecordStatu.ToLogistics.getValue());
  131. int updateR = repairRecordService.updateRepairRecord(rr);
  132. if (updateR <= 0) {
  133. throw new Exception("转后勤失败!");
  134. }
  135. boolean insertRsm = repairSystemMessagesService.inserBatchSystemMessage(messages);
  136. if (!insertRsm) {
  137. throw new Exception("报修单转后勤失败!");
  138. }
  139. //添加跟踪记录
  140. RepairTrackRecord rtr = new RepairTrackRecord();
  141. rtr.setRecordId(rlmr.getRecordId());
  142. rtr.setMaintenanceState(eRecordStatu.ToLogistics.getValue());
  143. rtr.setContent("用户转后勤:" + rlmr.getContent());
  144. rtr.setUserId(rlmr.getUserId());
  145. rtr.setUserZzstr("用户");
  146. int insertRtr = repairTrackRecordService.insertRepairTrackRecord(rtr);
  147. if (insertRtr <= 0) {
  148. throw new Exception("转后勤失败!");
  149. }
  150. } catch (Exception e) {
  151. throw new Exception("转后勤失败!");
  152. }
  153. return CommonResult.ok("转后勤成功");
  154. }
  155. }