TicketService.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.example.xiaoshiweixinback.business.common.base.Records;
  9. import com.example.xiaoshiweixinback.business.common.base.SystemFile;
  10. import com.example.xiaoshiweixinback.business.exception.BusinessException;
  11. import com.example.xiaoshiweixinback.business.utils.BatchNoUtil;
  12. import com.example.xiaoshiweixinback.business.utils.CacheUtil;
  13. import com.example.xiaoshiweixinback.business.utils.LoginUtils;
  14. import com.example.xiaoshiweixinback.business.utils.StringUtils;
  15. import com.example.xiaoshiweixinback.domain.*;
  16. import com.example.xiaoshiweixinback.entity.dto.ticket.*;
  17. import com.example.xiaoshiweixinback.entity.vo.*;
  18. import com.example.xiaoshiweixinback.entity.vo.ticket.TicketDetailVO;
  19. import com.example.xiaoshiweixinback.mapper.TicketMapper;
  20. import com.example.xiaoshiweixinback.service.common.FileManagerService;
  21. import com.example.xiaoshiweixinback.service.common.NoticeService;
  22. import lombok.RequiredArgsConstructor;
  23. import org.joda.time.DateTime;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.stereotype.Service;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import java.text.SimpleDateFormat;
  28. import java.util.ArrayList;
  29. import java.util.Arrays;
  30. import java.util.Date;
  31. import java.util.List;
  32. import java.util.stream.Collectors;
  33. /**
  34. * @author admin
  35. * @description 针对表【ticket(工单)】的数据库操作Service实现
  36. * @createDate 2024-03-29 16:27:51
  37. */
  38. @Service
  39. @RequiredArgsConstructor
  40. public class TicketService extends ServiceImpl<TicketMapper, Ticket> {
  41. private final CacheUtil cacheUtil;
  42. private final TicketFillInService ticketFillInService;
  43. private final TicketRightsProtectionService ticketRightsProtectionService;
  44. private final TicketLitigationRespondingService ticketLitigationRespondingService;
  45. private final TicketPatentApplyService ticketPatentApplyService;
  46. private final AssoTicketFileService assoTicketFileService;
  47. private final TicketFlowService ticketFlowService;
  48. private final FileManagerService fileManagerService;
  49. private final NoticeService noticeService;
  50. /**
  51. * 新增or更新工单
  52. *
  53. * @param ticketDTO
  54. * @return
  55. */
  56. @Transactional(rollbackFor = Exception.class)
  57. public Integer addorUpdateTicket(TicketDTO ticketDTO) {
  58. Integer reId = null;
  59. Ticket ticket = new Ticket();
  60. if (ticketDTO.getId() == null) {
  61. //工单基本信息入库
  62. BeanUtils.copyProperties(ticketDTO, ticket);
  63. PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
  64. ticket.setCreateId(personnelVO.getUuid());
  65. String num = BatchNoUtil.getBatchNo();
  66. ticket.setNum(num);
  67. ticket.setTicketProgress(1);
  68. ticket.insert();
  69. Integer ticketId = ticket.getId();
  70. //根据工单的不同类型 信息入库
  71. Integer ticketType = ticketDTO.getTicketType();
  72. switch (ticketType) {
  73. case 1:
  74. //填写工单
  75. TicketFillInAddDTO ticketFillInAddDTO = ticketDTO.getTicketFillInAddDTO();
  76. ticketFillInAddDTO.setTicketId(ticketId);
  77. reId = ticketFillInService.add(ticketFillInAddDTO);
  78. break;
  79. case 2:
  80. //知识产权维权工单
  81. TicketRightsProtectionAddDTO protectionAddDTO = ticketDTO.getProtectionAddDTO();
  82. protectionAddDTO.setTicketId(ticketId);
  83. reId = ticketRightsProtectionService.add(protectionAddDTO);
  84. break;
  85. case 3:
  86. //知识产权应诉工单
  87. TicketLitigationRespondingAddDTO respondingAddDTO = ticketDTO.getRespondingAddDTO();
  88. respondingAddDTO.setTicketId(ticketId);
  89. reId = ticketLitigationRespondingService.add(respondingAddDTO);
  90. break;
  91. case 4:
  92. //我要申请专利工单
  93. TicketPatentApplyAddDTO ticketPatentApplyAddDTO = ticketDTO.getTicketPatentApplyAddDTO();
  94. ticketPatentApplyAddDTO.setTicketId(ticketId);
  95. reId = ticketPatentApplyService.add(ticketPatentApplyAddDTO);
  96. break;
  97. default:
  98. reId = -1;
  99. break;
  100. }
  101. //处理工单的附件
  102. List<String> fileGuids = ticketDTO.getFileGuids();
  103. if (fileGuids != null && !fileGuids.isEmpty()) {
  104. List<AssoTicketFile> assoTicketFiles = new ArrayList<>();
  105. for (String fileGuid : fileGuids) {
  106. AssoTicketFile assoTicketFile = new AssoTicketFile();
  107. assoTicketFile.setTicketId(ticketId);
  108. assoTicketFile.setFileGuid(fileGuid);
  109. assoTicketFiles.add(assoTicketFile);
  110. }
  111. if (!assoTicketFiles.isEmpty()) {
  112. assoTicketFileService.saveBatch(assoTicketFiles);
  113. }
  114. }
  115. //添加工单流程记录
  116. ticketFlowService.addTicketFlow(ticket, "创建工单", false, null, 1);
  117. //通知管理员
  118. noticeService.noticeAdminToHandle(ticket.getNum());
  119. } else {
  120. //TODO 未装载
  121. ticket = this.getById(ticket.getId());
  122. ticket.updateById();
  123. }
  124. return reId;
  125. }
  126. @Transactional(rollbackFor = Exception.class)
  127. public Records queryTickets(TicketQueryDTO ticketQueryDTO) {
  128. String num = ticketQueryDTO.getNum();
  129. Integer ticketType = ticketQueryDTO.getTicketType();
  130. Integer process = ticketQueryDTO.getProcess();
  131. Integer pageNum = ticketQueryDTO.getCurrent();
  132. Integer pageSize = ticketQueryDTO.getSize();
  133. String contactPerson = ticketQueryDTO.getContactPerson();
  134. Date createTime = ticketQueryDTO.getCreateTime();
  135. Page<Ticket> page = new Page<>(pageNum, pageSize);
  136. QueryWrapper<Ticket> queryWrapper = new QueryWrapper<>();
  137. if (ticketType != null) {
  138. queryWrapper.lambda().eq(Ticket::getTicketType, ticketType);
  139. }
  140. if (num != null) {
  141. queryWrapper.lambda().like(Ticket::getNum, num);
  142. }
  143. if (process != null) {
  144. queryWrapper.lambda().eq(Ticket::getTicketProgress, process);
  145. }
  146. if (contactPerson != null) {
  147. queryWrapper.lambda().like(Ticket::getContactPerson, contactPerson);
  148. }
  149. PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
  150. Integer personType = personnelVO.getPersonType();
  151. if (personType != null && personType.equals(1)) {
  152. queryWrapper.lambda().eq(Ticket::getCreateId, personnelVO.getUuid());
  153. }
  154. if (createTime != null) {
  155. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  156. String date = format.format(createTime);
  157. queryWrapper.eq("DATE_FORMAT(create_time,'%Y-%m-%d')", date);
  158. }
  159. queryWrapper.orderBy(true, false, "create_time");
  160. IPage<Ticket> ticketPage = this.page(page, queryWrapper);
  161. List<Ticket> tickets = ticketPage.getRecords();
  162. List<TicketVO> ticketVOS = this.loadTicketVO(tickets);
  163. Records records = new Records();
  164. records.setData(ticketVOS);
  165. records.setCurrent((long) pageNum);
  166. records.setSize((long) pageSize);
  167. records.setTotal(ticketPage.getTotal());
  168. return records;
  169. }
  170. public List<TicketVO> loadTicketVO(List<Ticket> tickets) {
  171. List<TicketVO> ticketVOS = new ArrayList<>();
  172. if (!tickets.isEmpty()) {
  173. List<String> createIds = new ArrayList<>();
  174. tickets.forEach(item -> {
  175. if (item.getCreateId() != null) {
  176. createIds.add(item.getCreateId());
  177. }
  178. });
  179. for (Ticket ticket : tickets) {
  180. TicketVO ticketVO = new TicketVO();
  181. BeanUtils.copyProperties(ticket, ticketVO);
  182. Integer ticketId = ticket.getId();
  183. //附图
  184. LambdaQueryWrapper<AssoTicketFile> queryWrapper = new LambdaQueryWrapper<>();
  185. queryWrapper.eq(AssoTicketFile::getTicketId, ticketId)
  186. .eq(AssoTicketFile::getType,0);
  187. List<AssoTicketFile> assoTicketFiles = assoTicketFileService.list(queryWrapper);
  188. if (assoTicketFiles != null && !assoTicketFiles.isEmpty()) {
  189. List<String> fileGuids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
  190. List<SystemFile> systemFiles = fileManagerService.getSystemFileByGuids(fileGuids);
  191. ticketVO.setSystemFiles(systemFiles);
  192. }
  193. Integer ticketType = ticket.getTicketType();
  194. switch (ticketType) {
  195. case 1:
  196. TicketFillInVO ticketFillInVO = new TicketFillInVO();
  197. LambdaQueryWrapper<TicketFillIn> fillInWrapper = new LambdaQueryWrapper<>();
  198. fillInWrapper.eq(TicketFillIn::getTicketId, ticketId);
  199. TicketFillIn ticketFillIn = ticketFillInService.getOne(fillInWrapper, false);
  200. if (ticketFillIn != null) {
  201. BeanUtils.copyProperties(ticketFillIn, ticketFillInVO);
  202. String patentNoArray = ticketFillIn.getPatentNo();
  203. if (patentNoArray != null && StringUtils.isNotEmpty(patentNoArray)) {
  204. String[] stringArray = patentNoArray.split(",");
  205. List<String> patentNos = new ArrayList<>(Arrays.asList(stringArray));
  206. ticketFillInVO.setPatentNos(patentNos);
  207. }
  208. }
  209. ticketVO.setTicketFillInVO(ticketFillInVO);
  210. break;
  211. case 2:
  212. TicketRightsProtectionVO rightsProtectionVO = new TicketRightsProtectionVO();
  213. LambdaQueryWrapper<TicketRightsProtection> rightsProtectionWrapper = new LambdaQueryWrapper<>();
  214. rightsProtectionWrapper.eq(TicketRightsProtection::getTicketId, ticketId);
  215. TicketRightsProtection ticketRightsProtection = ticketRightsProtectionService.getOne(rightsProtectionWrapper, false);
  216. if (ticketRightsProtection != null) {
  217. String rightProof = ticketRightsProtection.getRightProof();
  218. String[] stringArray = rightProof.split(",");
  219. List<String> proofGuids = new ArrayList<>(Arrays.asList(stringArray));
  220. List<SystemFile> systemFiles = new ArrayList<>();
  221. if (proofGuids.size() != 0) {
  222. try {
  223. String res = fileManagerService.getSystemFileFromFMS(proofGuids);
  224. systemFiles = JSONObject.parseArray(res, SystemFile.class);
  225. if (systemFiles == null) {
  226. systemFiles = new ArrayList<>();
  227. }
  228. } catch (Exception e) {
  229. }
  230. }
  231. rightsProtectionVO.setProofGuids(proofGuids);
  232. rightsProtectionVO.setProofFileList(systemFiles);
  233. BeanUtils.copyProperties(ticketRightsProtection, rightsProtectionVO);
  234. }
  235. ticketVO.setTicketRightsProtectionVO(rightsProtectionVO);
  236. break;
  237. case 3:
  238. TicketLitigationRespondingVO litigationRespondingVO = new TicketLitigationRespondingVO();
  239. LambdaQueryWrapper<TicketLitigationResponding> respondingWrapper = new LambdaQueryWrapper<>();
  240. respondingWrapper.eq(TicketLitigationResponding::getTicketId, ticketId);
  241. TicketLitigationResponding ticketLitigationResponding = ticketLitigationRespondingService.getOne(respondingWrapper, false);
  242. if (ticketLitigationResponding != null) {
  243. BeanUtils.copyProperties(ticketLitigationResponding, litigationRespondingVO);
  244. }
  245. ticketVO.setTicketLitigationRespondingVO(litigationRespondingVO);
  246. break;
  247. case 4:
  248. TicketPatentApplyVO patentApplyVO = new TicketPatentApplyVO();
  249. LambdaQueryWrapper<TicketPatentApply> patentApplyWrapper = new LambdaQueryWrapper<>();
  250. patentApplyWrapper.eq(TicketPatentApply::getTicketId, ticketId);
  251. TicketPatentApply ticketPatentApply = ticketPatentApplyService.getOne(patentApplyWrapper, false);
  252. if (ticketPatentApply != null) {
  253. BeanUtils.copyProperties(ticketPatentApply, patentApplyVO);
  254. }
  255. ticketVO.setTicketPatentApplyVO(patentApplyVO);
  256. break;
  257. default:
  258. break;
  259. }
  260. ticketVOS.add(ticketVO);
  261. }
  262. }
  263. return ticketVOS;
  264. }
  265. /**
  266. * 更新工单状态
  267. *
  268. * @param ticketProcessUpDTO
  269. * @return
  270. */
  271. @Transactional(rollbackFor = Exception.class)
  272. public Integer updateProcess(TicketProcessUpDTO ticketProcessUpDTO) {
  273. Integer id = ticketProcessUpDTO.getId();
  274. Integer process = ticketProcessUpDTO.getProcess();
  275. Ticket ticket = this.getById(id);
  276. Boolean flag = this.ifHavePermission(ticket.getCreateId());
  277. if (!flag) {
  278. return 0;
  279. }
  280. ticket.setTicketProgress(process);
  281. ticket.updateById();
  282. if (process.equals(4)) {
  283. ticketFlowService.addTicketFlow(ticket, "工单已确认", false, null, 4,ticket.getCreateId());
  284. }
  285. return ticket.getId();
  286. }
  287. /**
  288. * 更新工单状态
  289. *
  290. * @return
  291. */
  292. @Transactional(rollbackFor = Exception.class)
  293. public Integer updateProcess(String uuid, Integer process) {
  294. LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
  295. queryWrapper.eq(Ticket::getNum, uuid);
  296. Ticket ticket = this.getOne(queryWrapper, false);
  297. ticket.setTicketProgress(process);
  298. ticket.updateById();
  299. ticketFlowService.addTicketFlow(ticket, "工单支付成功", false, null, 3,ticket.getCreateId());
  300. return ticket.getId();
  301. }
  302. /**
  303. * 更新价格
  304. *
  305. * @param ticketPriceUpDTO
  306. * @return
  307. */
  308. @Transactional(rollbackFor = Exception.class)
  309. public Integer updatePrice(TicketPriceUpDTO ticketPriceUpDTO) {
  310. Integer id = ticketPriceUpDTO.getId();
  311. Double price = ticketPriceUpDTO.getPrice();
  312. Ticket ticket = this.getById(id);
  313. Boolean flag = this.ifHavePermission(null);
  314. if (!flag) {
  315. return 0;
  316. }
  317. ticket.setPrice(price);
  318. ticket.updateById();
  319. return ticket.getId();
  320. }
  321. private Boolean ifHavePermission(String id) {
  322. PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
  323. personnelVO.getPersonType();
  324. if (personnelVO.getPersonType().equals(0) || (id != null && personnelVO.getUuid().equals(id))) {
  325. return true;
  326. }
  327. return false;
  328. }
  329. public Ticket getTicketByUUid(String uuid) {
  330. LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
  331. queryWrapper.eq(Ticket::getNum, uuid);
  332. Ticket ticket = this.getOne(queryWrapper);
  333. return ticket;
  334. }
  335. @Transactional(rollbackFor = Exception.class)
  336. public Integer acceptTicket(AcceptTicketDTO acceptTicketDTO) {
  337. Integer id = acceptTicketDTO.getId();
  338. Double price = acceptTicketDTO.getPrice();
  339. //根据id查询工单
  340. Ticket ticket = this.getById(id);
  341. if (ticket == null) {
  342. throw new BusinessException("607", "未查询到工单");
  343. }
  344. if (ticket.getTicketProgress() > 2) {
  345. throw new BusinessException("607", "此工单不可进行操作");
  346. }
  347. ticket.setPrice(price);
  348. if (ticket.getTicketProgress() == 2) {
  349. ticketFlowService.addTicketFlow(ticket, "修改工单价格为" + price, false, null, 2);
  350. } else {
  351. ticket.setTicketProgress(2);
  352. ticketFlowService.addTicketFlow(ticket, "受理工单并且修改价格为" + price, false, null, 2);
  353. }
  354. ticket.updateById();
  355. return ticket.getId();
  356. }
  357. /**
  358. * 上传工单结果
  359. *
  360. * @param ticketUploadResultDTO
  361. * @return
  362. */
  363. @Transactional(rollbackFor = Exception.class)
  364. public Integer uploadTicketResult(TicketUploadResultDTO ticketUploadResultDTO) {
  365. List<String> fileGuids = new ArrayList<>();
  366. fileGuids = ticketUploadResultDTO.getFileGuids();
  367. String description = ticketUploadResultDTO.getDescription();
  368. Integer id = ticketUploadResultDTO.getId();
  369. //根据id查询工单
  370. Ticket ticket = this.getById(id);
  371. if (ticket == null) {
  372. throw new BusinessException("607", "未查询到工单");
  373. }
  374. if (ticket.getTicketProgress() > 3) {
  375. throw new BusinessException("607", "此工单不可进行操作");
  376. }
  377. //添加工单流程
  378. TicketFlow ticketFlow = ticketFlowService.addTicketFlow(ticket, "添加工单结果", true, description, 6);
  379. //添加结果
  380. assoTicketFileService.addTicketFile(fileGuids, 1, ticket, ticketFlow.getId());
  381. ticket.setTicketProgress(6);
  382. ticket.updateById();
  383. return ticket.getId();
  384. }
  385. public TicketDetailVO getTicketDetail(Integer ticketId) {
  386. TicketDetailVO ticketDetailVO = new TicketDetailVO();
  387. //根据id查询
  388. Ticket ticket = this.getById(ticketId);
  389. if (ticket == null) {
  390. return ticketDetailVO;
  391. }
  392. ticketDetailVO = this.loadTicketDetail(ticket);
  393. return ticketDetailVO;
  394. }
  395. public TicketDetailVO loadTicketDetail(Ticket ticket) {
  396. TicketDetailVO ticketDetailVO = new TicketDetailVO();
  397. BeanUtils.copyProperties(ticket, ticketDetailVO);
  398. Integer ticketId = ticket.getId();
  399. //附图
  400. LambdaQueryWrapper<AssoTicketFile> queryWrapper = new LambdaQueryWrapper<>();
  401. queryWrapper.eq(AssoTicketFile::getTicketId, ticketId)
  402. .eq(AssoTicketFile::getType, 0);
  403. List<AssoTicketFile> assoTicketFiles = assoTicketFileService.list(queryWrapper);
  404. if (assoTicketFiles != null && !assoTicketFiles.isEmpty()) {
  405. List<String> fileGuids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
  406. List<SystemFile> systemFiles = fileManagerService.getSystemFileByGuids(fileGuids);
  407. ticketDetailVO.setSystemFiles(systemFiles);
  408. }
  409. Integer ticketType = ticket.getTicketType();
  410. switch (ticketType) {
  411. case 1:
  412. TicketFillInVO ticketFillInVO = ticketFillInService.getVOByTicId(ticketId);
  413. ticketDetailVO.setTicketFillInVO(ticketFillInVO);
  414. break;
  415. case 2:
  416. TicketRightsProtectionVO rightsProtectionVO = ticketRightsProtectionService.getVOByTicId(ticketId);
  417. ticketDetailVO.setTicketRightsProtectionVO(rightsProtectionVO);
  418. break;
  419. case 3:
  420. TicketLitigationRespondingVO litigationRespondingVO = ticketLitigationRespondingService.getVOByTicId(ticketId);
  421. ticketDetailVO.setTicketLitigationRespondingVO(litigationRespondingVO);
  422. break;
  423. case 4:
  424. TicketPatentApplyVO patentApplyVO = ticketPatentApplyService.getVOByTicId(ticketId);
  425. ticketDetailVO.setTicketPatentApplyVO(patentApplyVO);
  426. break;
  427. default:
  428. break;
  429. }
  430. try {
  431. TicketFlowVO ticketFlowVO = ticketFlowService.getTicketResult(ticketId);
  432. ticketDetailVO.setTicketResult(ticketFlowVO);
  433. } catch (Exception e) {
  434. }
  435. return ticketDetailVO;
  436. }
  437. }