RepairLeaveMessageController.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. @Override
  41. public CommonResult InsertrepairLeaveMessage(RepairLeaveMessage rc, BindingResult bindingResult) {
  42. if (bindingResult.hasErrors()) {
  43. String st = paramUtils.getParamError(bindingResult);
  44. return CommonResult.fail(st);
  45. }
  46. int result = repairLeaveMessageService.insertRepairLeaveMessage(rc);
  47. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  48. }
  49. @Override
  50. public CommonResult updaterepairLeaveMessageById(RepairLeaveMessage rc, BindingResult bindingResult) {
  51. if (bindingResult.hasErrors()) {
  52. String st = paramUtils.getParamError(bindingResult);
  53. return CommonResult.fail(st);
  54. }
  55. int result = repairLeaveMessageService.updateRepairLeaveMessage(rc);
  56. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  57. }
  58. @Override
  59. public CommonResult queryPagerepairLeaveMessages(int currentPage, int pageCount, String name) {
  60. PageUtils<RepairLeaveMessage> result = repairLeaveMessageService.queryPageRepairLeaveMessages(currentPage, pageCount, name);
  61. return CommonResult.ok(result);
  62. }
  63. @Override
  64. public CommonResult deleterepairLeaveMessageById(int id) {
  65. RepairLeaveMessage data = repairLeaveMessageService.getRepairById(id);
  66. if (data == null) {
  67. return CommonResult.fail("当前数据不存在,删除失败!");
  68. }
  69. int result = repairLeaveMessageService.deleteRepairLeaveMessageById(id);
  70. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  71. }
  72. @Override
  73. @Transactional(rollbackFor = {Exception.class})
  74. public CommonResult transferToLogistics(repairLeaveMessageRequest rlmr, BindingResult bindingResult) throws Exception {
  75. if (bindingResult.hasErrors()) {
  76. String st = paramUtils.getParamError(bindingResult);
  77. return CommonResult.fail(st);
  78. }
  79. //只有待确认能转后勤
  80. RepairRecord rr = repairRecordService.getRepairById(rlmr.getRecordId());
  81. if (rr == null) {
  82. return CommonResult.fail("报修单不存在,转后勤失败");
  83. }
  84. if (rr.getMaintenanceState() != eRecordStatu.ToConfirmed.getValue()) {
  85. return CommonResult.fail("待确认的报修单才能进行转后勤操作");
  86. }
  87. /**
  88. * 获取报修工单对应校区的所有后勤人员
  89. */
  90. List<RepairLogisticsVo> users = repairUserService.queryLogisticsList(rlmr.getRecordId());
  91. if (users.size() <= 0) {
  92. return CommonResult.fail("该报修区域缺少后勤人员");
  93. }
  94. //有可能有多个后勤
  95. List<RepairLeaveMessage> datas = new ArrayList<>();
  96. List<RepairSystemMessages> messages = new ArrayList<>();
  97. for (RepairLogisticsVo u : users) {
  98. RepairLeaveMessage data = new RepairLeaveMessage();
  99. data.setSenderId(rlmr.getUserId());
  100. data.setRecipientId(u.getId());
  101. data.setContent(rlmr.getContent());
  102. data.setRecordId(rlmr.getRecordId());
  103. datas.add(data);
  104. RepairSystemMessages rsm = new RepairSystemMessages();
  105. rsm.setIsRead(0);
  106. rsm.setRecordId(rlmr.getUserId());
  107. rsm.setRecipientId(u.getId());
  108. rsm.setContent("用户已提交留言,请尽快处理!");
  109. messages.add(rsm);
  110. }
  111. try {
  112. boolean result = repairLeaveMessageService.inserBatchLeaveMessage(datas);
  113. if (!result) {
  114. throw new Exception("转后勤失败!");
  115. }
  116. //将工单状态更改为待处理
  117. rr.setId(rlmr.getRecordId());
  118. rr.setMaintenanceState(eRecordStatu.ToLogistics.getValue());
  119. int updateR = repairRecordService.updateRepairRecord(rr);
  120. if (updateR <= 0) {
  121. throw new Exception("转后勤失败!");
  122. }
  123. boolean insertRsm = repairSystemMessagesService.inserBatchSystemMessage(messages);
  124. if (!insertRsm) {
  125. throw new Exception("报修单转后勤失败!");
  126. }
  127. //添加跟踪记录
  128. RepairTrackRecord rtr = new RepairTrackRecord();
  129. rtr.setRecordId(rlmr.getRecordId());
  130. rtr.setMaintenanceState(eRecordStatu.ToLogistics.getValue());
  131. rtr.setContent("用户转后勤:" + rlmr.getContent());
  132. rtr.setUserId(rlmr.getUserId());
  133. rtr.setUserZzstr("用户");
  134. int insertRtr = repairTrackRecordService.insertRepairTrackRecord(rtr);
  135. if (insertRtr <= 0) {
  136. throw new Exception("转后勤失败!");
  137. }
  138. } catch (Exception e) {
  139. throw new Exception("转后勤失败!");
  140. }
  141. return CommonResult.ok("转后勤成功");
  142. }
  143. }