TicketService.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. if(rightProof!=null){
  219. String[] stringArray = rightProof.split(",");
  220. List<String> proofGuids = new ArrayList<>(Arrays.asList(stringArray));
  221. List<SystemFile> systemFiles = new ArrayList<>();
  222. if (proofGuids.size() != 0) {
  223. try {
  224. String res = fileManagerService.getSystemFileFromFMS(proofGuids);
  225. systemFiles = JSONObject.parseArray(res, SystemFile.class);
  226. if (systemFiles == null) {
  227. systemFiles = new ArrayList<>();
  228. }
  229. } catch (Exception e) {
  230. }
  231. rightsProtectionVO.setProofGuids(proofGuids);
  232. rightsProtectionVO.setProofFileList(systemFiles);
  233. }
  234. }
  235. BeanUtils.copyProperties(ticketRightsProtection, rightsProtectionVO);
  236. }
  237. ticketVO.setTicketRightsProtectionVO(rightsProtectionVO);
  238. break;
  239. case 3:
  240. TicketLitigationRespondingVO litigationRespondingVO = new TicketLitigationRespondingVO();
  241. LambdaQueryWrapper<TicketLitigationResponding> respondingWrapper = new LambdaQueryWrapper<>();
  242. respondingWrapper.eq(TicketLitigationResponding::getTicketId, ticketId);
  243. TicketLitigationResponding ticketLitigationResponding = ticketLitigationRespondingService.getOne(respondingWrapper, false);
  244. if (ticketLitigationResponding != null) {
  245. BeanUtils.copyProperties(ticketLitigationResponding, litigationRespondingVO);
  246. }
  247. ticketVO.setTicketLitigationRespondingVO(litigationRespondingVO);
  248. break;
  249. case 4:
  250. TicketPatentApplyVO patentApplyVO = new TicketPatentApplyVO();
  251. LambdaQueryWrapper<TicketPatentApply> patentApplyWrapper = new LambdaQueryWrapper<>();
  252. patentApplyWrapper.eq(TicketPatentApply::getTicketId, ticketId);
  253. TicketPatentApply ticketPatentApply = ticketPatentApplyService.getOne(patentApplyWrapper, false);
  254. if (ticketPatentApply != null) {
  255. BeanUtils.copyProperties(ticketPatentApply, patentApplyVO);
  256. }
  257. ticketVO.setTicketPatentApplyVO(patentApplyVO);
  258. break;
  259. default:
  260. break;
  261. }
  262. ticketVOS.add(ticketVO);
  263. }
  264. }
  265. return ticketVOS;
  266. }
  267. /**
  268. * 更新工单状态
  269. *
  270. * @param ticketProcessUpDTO
  271. * @return
  272. */
  273. @Transactional(rollbackFor = Exception.class)
  274. public Integer updateProcess(TicketProcessUpDTO ticketProcessUpDTO) {
  275. Integer id = ticketProcessUpDTO.getId();
  276. Integer process = ticketProcessUpDTO.getProcess();
  277. Ticket ticket = this.getById(id);
  278. Boolean flag = this.ifHavePermission(ticket.getCreateId());
  279. if (!flag) {
  280. return 0;
  281. }
  282. ticket.setTicketProgress(process);
  283. ticket.updateById();
  284. if (process.equals(4)) {
  285. ticketFlowService.addTicketFlow(ticket, "工单已确认", false, null, 4,ticket.getCreateId());
  286. }
  287. if(process.equals(5))
  288. {
  289. ticketFlowService.addTicketFlow(ticket, "工单已取消", false, null, 5,ticket.getCreateId());
  290. }
  291. return ticket.getId();
  292. }
  293. /**
  294. * 更新工单状态
  295. *
  296. * @return
  297. */
  298. @Transactional(rollbackFor = Exception.class)
  299. public Integer updateProcess(String uuid, Integer process) {
  300. LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
  301. queryWrapper.eq(Ticket::getNum, uuid);
  302. Ticket ticket = this.getOne(queryWrapper, false);
  303. ticket.setTicketProgress(process);
  304. ticket.updateById();
  305. ticketFlowService.addTicketFlow(ticket, "工单支付成功", false, null, 3,ticket.getCreateId());
  306. return ticket.getId();
  307. }
  308. /**
  309. * 更新价格
  310. *
  311. * @param ticketPriceUpDTO
  312. * @return
  313. */
  314. @Transactional(rollbackFor = Exception.class)
  315. public Integer updatePrice(TicketPriceUpDTO ticketPriceUpDTO) {
  316. Integer id = ticketPriceUpDTO.getId();
  317. Double price = ticketPriceUpDTO.getPrice();
  318. Ticket ticket = this.getById(id);
  319. Boolean flag = this.ifHavePermission(null);
  320. if (!flag) {
  321. return 0;
  322. }
  323. ticket.setPrice(price);
  324. ticket.updateById();
  325. return ticket.getId();
  326. }
  327. private Boolean ifHavePermission(String id) {
  328. PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
  329. personnelVO.getPersonType();
  330. if (personnelVO.getPersonType().equals(0) || (id != null && personnelVO.getUuid().equals(id))) {
  331. return true;
  332. }
  333. return false;
  334. }
  335. public Ticket getTicketByUUid(String uuid) {
  336. LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
  337. queryWrapper.eq(Ticket::getNum, uuid);
  338. Ticket ticket = this.getOne(queryWrapper);
  339. return ticket;
  340. }
  341. @Transactional(rollbackFor = Exception.class)
  342. public Integer acceptTicket(AcceptTicketDTO acceptTicketDTO) {
  343. Integer id = acceptTicketDTO.getId();
  344. Double price = acceptTicketDTO.getPrice();
  345. //根据id查询工单
  346. Ticket ticket = this.getById(id);
  347. if (ticket == null) {
  348. throw new BusinessException("607", "未查询到工单");
  349. }
  350. if (ticket.getTicketProgress() > 2) {
  351. throw new BusinessException("607", "此工单不可进行操作");
  352. }
  353. ticket.setPrice(price);
  354. if (ticket.getTicketProgress() == 2) {
  355. ticketFlowService.addTicketFlow(ticket, "修改工单价格为" + price, false, null, 2);
  356. } else {
  357. ticket.setTicketProgress(2);
  358. ticketFlowService.addTicketFlow(ticket, "受理工单并且修改价格为" + price, false, null, 2);
  359. }
  360. ticket.updateById();
  361. return ticket.getId();
  362. }
  363. /**
  364. * 上传工单结果
  365. *
  366. * @param ticketUploadResultDTO
  367. * @return
  368. */
  369. @Transactional(rollbackFor = Exception.class)
  370. public Integer uploadTicketResult(TicketUploadResultDTO ticketUploadResultDTO) {
  371. List<String> fileGuids = new ArrayList<>();
  372. fileGuids = ticketUploadResultDTO.getFileGuids();
  373. String description = ticketUploadResultDTO.getDescription();
  374. Integer id = ticketUploadResultDTO.getId();
  375. //根据id查询工单
  376. Ticket ticket = this.getById(id);
  377. if (ticket == null) {
  378. throw new BusinessException("607", "未查询到工单");
  379. }
  380. if (ticket.getTicketProgress() > 3) {
  381. throw new BusinessException("607", "此工单不可进行操作");
  382. }
  383. //添加工单流程
  384. TicketFlow ticketFlow = ticketFlowService.addTicketFlow(ticket, "添加工单结果", true, description, 6);
  385. //添加结果
  386. assoTicketFileService.addTicketFile(fileGuids, 1, ticket, ticketFlow.getId());
  387. ticket.setTicketProgress(6);
  388. ticket.updateById();
  389. return ticket.getId();
  390. }
  391. public TicketDetailVO getTicketDetail(Integer ticketId) {
  392. TicketDetailVO ticketDetailVO = new TicketDetailVO();
  393. //根据id查询
  394. Ticket ticket = this.getById(ticketId);
  395. if (ticket == null) {
  396. return ticketDetailVO;
  397. }
  398. ticketDetailVO = this.loadTicketDetail(ticket);
  399. return ticketDetailVO;
  400. }
  401. public TicketDetailVO loadTicketDetail(Ticket ticket) {
  402. TicketDetailVO ticketDetailVO = new TicketDetailVO();
  403. BeanUtils.copyProperties(ticket, ticketDetailVO);
  404. Integer ticketId = ticket.getId();
  405. //附图
  406. LambdaQueryWrapper<AssoTicketFile> queryWrapper = new LambdaQueryWrapper<>();
  407. queryWrapper.eq(AssoTicketFile::getTicketId, ticketId)
  408. .eq(AssoTicketFile::getType, 0);
  409. List<AssoTicketFile> assoTicketFiles = assoTicketFileService.list(queryWrapper);
  410. if (assoTicketFiles != null && !assoTicketFiles.isEmpty()) {
  411. List<String> fileGuids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
  412. List<SystemFile> systemFiles = fileManagerService.getSystemFileByGuids(fileGuids);
  413. ticketDetailVO.setSystemFiles(systemFiles);
  414. }
  415. Integer ticketType = ticket.getTicketType();
  416. switch (ticketType) {
  417. case 1:
  418. TicketFillInVO ticketFillInVO = ticketFillInService.getVOByTicId(ticketId);
  419. ticketDetailVO.setTicketFillInVO(ticketFillInVO);
  420. break;
  421. case 2:
  422. TicketRightsProtectionVO rightsProtectionVO = ticketRightsProtectionService.getVOByTicId(ticketId);
  423. ticketDetailVO.setTicketRightsProtectionVO(rightsProtectionVO);
  424. break;
  425. case 3:
  426. TicketLitigationRespondingVO litigationRespondingVO = ticketLitigationRespondingService.getVOByTicId(ticketId);
  427. ticketDetailVO.setTicketLitigationRespondingVO(litigationRespondingVO);
  428. break;
  429. case 4:
  430. TicketPatentApplyVO patentApplyVO = ticketPatentApplyService.getVOByTicId(ticketId);
  431. ticketDetailVO.setTicketPatentApplyVO(patentApplyVO);
  432. break;
  433. default:
  434. break;
  435. }
  436. try {
  437. TicketFlowVO ticketFlowVO = ticketFlowService.getTicketResult(ticketId);
  438. ticketDetailVO.setTicketResult(ticketFlowVO);
  439. } catch (Exception e) {
  440. }
  441. return ticketDetailVO;
  442. }
  443. }