TicketFlowService.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.example.xiaoshiweixinback.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.example.xiaoshiweixinback.business.common.base.SystemFile;
  6. import com.example.xiaoshiweixinback.business.utils.CacheUtil;
  7. import com.example.xiaoshiweixinback.business.utils.LoginUtils;
  8. import com.example.xiaoshiweixinback.domain.AssoTicketFile;
  9. import com.example.xiaoshiweixinback.domain.Person;
  10. import com.example.xiaoshiweixinback.domain.Ticket;
  11. import com.example.xiaoshiweixinback.domain.TicketFlow;
  12. import com.example.xiaoshiweixinback.entity.dto.ticket.TicketFlowVO;
  13. import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
  14. import com.example.xiaoshiweixinback.mapper.TicketFlowMapper;
  15. import com.example.xiaoshiweixinback.service.common.FileManagerService;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21. import java.util.List;
  22. import java.util.stream.Collectors;
  23. /**
  24. * @author admin
  25. * @description 针对表【ticket_flow(工单流程)】的数据库操作Service实现
  26. * @createDate 2024-04-17 18:47:48
  27. */
  28. @Service
  29. public class TicketFlowService extends ServiceImpl<TicketFlowMapper, TicketFlow> {
  30. @Autowired
  31. private CacheUtil cacheUtil;
  32. @Autowired
  33. private AssoTicketFileService assoTicketFileService;
  34. @Autowired
  35. private FileManagerService fileManagerService;
  36. @Autowired
  37. private PersonService personService;
  38. /**
  39. * 添加工单流程
  40. *
  41. * @param ticket
  42. * @param description
  43. * @return
  44. */
  45. public TicketFlow addTicketFlow(Ticket ticket, String description, Boolean ifResult,String remark,Integer progress) {
  46. PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
  47. TicketFlow ticketFlow = new TicketFlow();
  48. ticketFlow.setTicketId(ticket.getId());
  49. ticketFlow.setTicketProcess(progress);
  50. ticketFlow.setCreateId(personnelVO.getUuid());
  51. ticketFlow.setDescription(description);
  52. ticketFlow.setRemark(remark);
  53. ticketFlow.setIfResult(ifResult);
  54. ticketFlow.insert();
  55. return ticketFlow;
  56. }
  57. /**
  58. * 查询工单结果
  59. *
  60. * @param ticketId
  61. */
  62. public TicketFlowVO getTicketResult(Integer ticketId) throws Exception {
  63. TicketFlowVO ticketFlowVO = new TicketFlowVO();
  64. //根据工单id查询工单结果流程
  65. LambdaQueryWrapper<TicketFlow> queryWrapper = new LambdaQueryWrapper<>();
  66. queryWrapper.eq(TicketFlow::getTicketId, ticketId)
  67. .eq(TicketFlow::getIfResult, true)
  68. .orderByDesc(TicketFlow::getCreateTime);
  69. TicketFlow ticketFlow = this.getOne(queryWrapper, false);
  70. if (ticketFlow != null) {
  71. //根据工单流程查询文件
  72. List<TicketFlowVO> ticketFlowVOS = this.loadTicketFlows(Arrays.asList(ticketFlow));
  73. ticketFlowVO = ticketFlowVOS.get(0);
  74. }
  75. return ticketFlowVO;
  76. }
  77. public List<TicketFlowVO> getTicketFlows(Integer ticketId) {
  78. LambdaQueryWrapper<TicketFlow> queryWrapper = new LambdaQueryWrapper<>();
  79. queryWrapper.eq(TicketFlow::getTicketId, ticketId)
  80. .orderByDesc(TicketFlow::getCreateTime);
  81. List<TicketFlow> ticketFlows = this.list(queryWrapper);
  82. List<TicketFlowVO> ticketFlowVOS = this.loadTicketFlows(ticketFlows);
  83. return ticketFlowVOS;
  84. }
  85. private List<TicketFlowVO> loadTicketFlows(List<TicketFlow> ticketFlows) {
  86. List<TicketFlowVO> ticketFlowVOS = new ArrayList<>();
  87. if(ticketFlows.size()==0){
  88. return ticketFlowVOS;
  89. }
  90. List<Integer> ticketFlowIds = ticketFlows.stream().map(TicketFlow::getId).collect(Collectors.toList());
  91. List<String> createIds =ticketFlows.stream().map(TicketFlow::getCreateId).collect(Collectors.toList());
  92. List<Person> personList=personService.getPersonsById(createIds);
  93. List<AssoTicketFile> assoTicketFiles =new ArrayList<>();
  94. //根据ids查询文件guid
  95. assoTicketFiles = assoTicketFileService.queryFileByFlowIds(ticketFlowIds);
  96. List<String> guids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
  97. //根据guid查询文件信息
  98. List<SystemFile> systemFiles =fileManagerService.getSystemFileByGuids(guids);
  99. for (TicketFlow ticketFlow : ticketFlows) {
  100. TicketFlowVO ticketFlowVO = new TicketFlowVO();
  101. BeanUtils.copyProperties(ticketFlow, ticketFlowVO);
  102. List<AssoTicketFile> assoTicketFileList = assoTicketFiles.stream().filter(item -> item.getFlowId().equals(ticketFlow.getId())).collect(Collectors.toList());
  103. if (assoTicketFileList.size() != 0) {
  104. List<String> temGuids = assoTicketFileList.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
  105. List<SystemFile> temSystemFiles = systemFiles.stream().filter(item -> temGuids.contains(item.getGuid())).collect(Collectors.toList());
  106. ticketFlowVO.setSystemFiles(temSystemFiles);
  107. }
  108. Person person= personList.stream().filter(item->item.getUuid().equals(ticketFlow.getCreateId())).findFirst().orElse(null);
  109. if(person!=null){
  110. ticketFlowVO.setCreateName(person.getName());
  111. }
  112. ticketFlowVOS.add(ticketFlowVO);
  113. }
  114. return ticketFlowVOS;
  115. }
  116. }