123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- package com.example.xiaoshiweixinback.service;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.example.xiaoshiweixinback.business.common.base.Records;
- import com.example.xiaoshiweixinback.business.common.base.SystemFile;
- import com.example.xiaoshiweixinback.business.exception.BusinessException;
- import com.example.xiaoshiweixinback.business.utils.BatchNoUtil;
- import com.example.xiaoshiweixinback.business.utils.CacheUtil;
- import com.example.xiaoshiweixinback.business.utils.LoginUtils;
- import com.example.xiaoshiweixinback.business.utils.StringUtils;
- import com.example.xiaoshiweixinback.domain.*;
- import com.example.xiaoshiweixinback.entity.dto.ticket.*;
- import com.example.xiaoshiweixinback.entity.vo.*;
- import com.example.xiaoshiweixinback.entity.vo.ticket.TicketDetailVO;
- import com.example.xiaoshiweixinback.mapper.TicketMapper;
- import com.example.xiaoshiweixinback.service.common.FileManagerService;
- import com.example.xiaoshiweixinback.service.common.NoticeService;
- import lombok.RequiredArgsConstructor;
- import org.joda.time.DateTime;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * @author admin
- * @description 针对表【ticket(工单)】的数据库操作Service实现
- * @createDate 2024-03-29 16:27:51
- */
- @Service
- @RequiredArgsConstructor
- public class TicketService extends ServiceImpl<TicketMapper, Ticket> {
- private final CacheUtil cacheUtil;
- private final TicketFillInService ticketFillInService;
- private final TicketRightsProtectionService ticketRightsProtectionService;
- private final TicketLitigationRespondingService ticketLitigationRespondingService;
- private final TicketPatentApplyService ticketPatentApplyService;
- private final AssoTicketFileService assoTicketFileService;
- private final TicketFlowService ticketFlowService;
- private final FileManagerService fileManagerService;
- private final NoticeService noticeService;
- /**
- * 新增or更新工单
- *
- * @param ticketDTO
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public Integer addorUpdateTicket(TicketDTO ticketDTO) {
- Integer reId = null;
- Ticket ticket = new Ticket();
- if (ticketDTO.getId() == null) {
- //工单基本信息入库
- BeanUtils.copyProperties(ticketDTO, ticket);
- PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
- ticket.setCreateId(personnelVO.getUuid());
- String num = BatchNoUtil.getBatchNo();
- ticket.setNum(num);
- ticket.setTicketProgress(1);
- ticket.insert();
- Integer ticketId = ticket.getId();
- //根据工单的不同类型 信息入库
- Integer ticketType = ticketDTO.getTicketType();
- switch (ticketType) {
- case 1:
- //填写工单
- TicketFillInAddDTO ticketFillInAddDTO = ticketDTO.getTicketFillInAddDTO();
- ticketFillInAddDTO.setTicketId(ticketId);
- reId = ticketFillInService.add(ticketFillInAddDTO);
- break;
- case 2:
- //知识产权维权工单
- TicketRightsProtectionAddDTO protectionAddDTO = ticketDTO.getProtectionAddDTO();
- protectionAddDTO.setTicketId(ticketId);
- reId = ticketRightsProtectionService.add(protectionAddDTO);
- break;
- case 3:
- //知识产权应诉工单
- TicketLitigationRespondingAddDTO respondingAddDTO = ticketDTO.getRespondingAddDTO();
- respondingAddDTO.setTicketId(ticketId);
- reId = ticketLitigationRespondingService.add(respondingAddDTO);
- break;
- case 4:
- //我要申请专利工单
- TicketPatentApplyAddDTO ticketPatentApplyAddDTO = ticketDTO.getTicketPatentApplyAddDTO();
- ticketPatentApplyAddDTO.setTicketId(ticketId);
- reId = ticketPatentApplyService.add(ticketPatentApplyAddDTO);
- break;
- default:
- reId = -1;
- break;
- }
- //处理工单的附件
- List<String> fileGuids = ticketDTO.getFileGuids();
- if (fileGuids != null && !fileGuids.isEmpty()) {
- List<AssoTicketFile> assoTicketFiles = new ArrayList<>();
- for (String fileGuid : fileGuids) {
- AssoTicketFile assoTicketFile = new AssoTicketFile();
- assoTicketFile.setTicketId(ticketId);
- assoTicketFile.setFileGuid(fileGuid);
- assoTicketFiles.add(assoTicketFile);
- }
- if (!assoTicketFiles.isEmpty()) {
- assoTicketFileService.saveBatch(assoTicketFiles);
- }
- }
- //添加工单流程记录
- ticketFlowService.addTicketFlow(ticket, "创建工单", false, null, 1);
- //通知管理员
- noticeService.noticeAdminToHandle(ticket.getNum());
- } else {
- //TODO 未装载
- ticket = this.getById(ticket.getId());
- ticket.updateById();
- }
- return reId;
- }
- @Transactional(rollbackFor = Exception.class)
- public Records queryTickets(TicketQueryDTO ticketQueryDTO) {
- String num = ticketQueryDTO.getNum();
- Integer ticketType = ticketQueryDTO.getTicketType();
- Integer process = ticketQueryDTO.getProcess();
- Integer pageNum = ticketQueryDTO.getCurrent();
- Integer pageSize = ticketQueryDTO.getSize();
- String contactPerson = ticketQueryDTO.getContactPerson();
- Date createTime = ticketQueryDTO.getCreateTime();
- Page<Ticket> page = new Page<>(pageNum, pageSize);
- QueryWrapper<Ticket> queryWrapper = new QueryWrapper<>();
- if (ticketType != null) {
- queryWrapper.lambda().eq(Ticket::getTicketType, ticketType);
- }
- if (num != null) {
- queryWrapper.lambda().like(Ticket::getNum, num);
- }
- if (process != null) {
- queryWrapper.lambda().eq(Ticket::getTicketProgress, process);
- }
- if (contactPerson != null) {
- queryWrapper.lambda().like(Ticket::getContactPerson, contactPerson);
- }
- PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
- Integer personType = personnelVO.getPersonType();
- if (personType != null && personType.equals(1)) {
- queryWrapper.lambda().eq(Ticket::getCreateId, personnelVO.getUuid());
- }
- if (createTime != null) {
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- String date = format.format(createTime);
- queryWrapper.eq("DATE_FORMAT(create_time,'%Y-%m-%d')", date);
- }
- queryWrapper.orderBy(true, false, "create_time");
- IPage<Ticket> ticketPage = this.page(page, queryWrapper);
- List<Ticket> tickets = ticketPage.getRecords();
- List<TicketVO> ticketVOS = this.loadTicketVO(tickets);
- Records records = new Records();
- records.setData(ticketVOS);
- records.setCurrent((long) pageNum);
- records.setSize((long) pageSize);
- records.setTotal(ticketPage.getTotal());
- return records;
- }
- public List<TicketVO> loadTicketVO(List<Ticket> tickets) {
- List<TicketVO> ticketVOS = new ArrayList<>();
- if (!tickets.isEmpty()) {
- List<String> createIds = new ArrayList<>();
- tickets.forEach(item -> {
- if (item.getCreateId() != null) {
- createIds.add(item.getCreateId());
- }
- });
- for (Ticket ticket : tickets) {
- TicketVO ticketVO = new TicketVO();
- BeanUtils.copyProperties(ticket, ticketVO);
- Integer ticketId = ticket.getId();
- //附图
- LambdaQueryWrapper<AssoTicketFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AssoTicketFile::getTicketId, ticketId)
- .eq(AssoTicketFile::getType,0);
- List<AssoTicketFile> assoTicketFiles = assoTicketFileService.list(queryWrapper);
- if (assoTicketFiles != null && !assoTicketFiles.isEmpty()) {
- List<String> fileGuids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
- List<SystemFile> systemFiles = fileManagerService.getSystemFileByGuids(fileGuids);
- ticketVO.setSystemFiles(systemFiles);
- }
- Integer ticketType = ticket.getTicketType();
- switch (ticketType) {
- case 1:
- TicketFillInVO ticketFillInVO = new TicketFillInVO();
- LambdaQueryWrapper<TicketFillIn> fillInWrapper = new LambdaQueryWrapper<>();
- fillInWrapper.eq(TicketFillIn::getTicketId, ticketId);
- TicketFillIn ticketFillIn = ticketFillInService.getOne(fillInWrapper, false);
- if (ticketFillIn != null) {
- BeanUtils.copyProperties(ticketFillIn, ticketFillInVO);
- String patentNoArray = ticketFillIn.getPatentNo();
- if (patentNoArray != null && StringUtils.isNotEmpty(patentNoArray)) {
- String[] stringArray = patentNoArray.split(",");
- List<String> patentNos = new ArrayList<>(Arrays.asList(stringArray));
- ticketFillInVO.setPatentNos(patentNos);
- }
- }
- ticketVO.setTicketFillInVO(ticketFillInVO);
- break;
- case 2:
- TicketRightsProtectionVO rightsProtectionVO = new TicketRightsProtectionVO();
- LambdaQueryWrapper<TicketRightsProtection> rightsProtectionWrapper = new LambdaQueryWrapper<>();
- rightsProtectionWrapper.eq(TicketRightsProtection::getTicketId, ticketId);
- TicketRightsProtection ticketRightsProtection = ticketRightsProtectionService.getOne(rightsProtectionWrapper, false);
- if (ticketRightsProtection != null) {
- String rightProof = ticketRightsProtection.getRightProof();
- if(rightProof!=null){
- String[] stringArray = rightProof.split(",");
- List<String> proofGuids = new ArrayList<>(Arrays.asList(stringArray));
- List<SystemFile> systemFiles = new ArrayList<>();
- if (proofGuids.size() != 0) {
- try {
- String res = fileManagerService.getSystemFileFromFMS(proofGuids);
- systemFiles = JSONObject.parseArray(res, SystemFile.class);
- if (systemFiles == null) {
- systemFiles = new ArrayList<>();
- }
- } catch (Exception e) {
- }
- rightsProtectionVO.setProofGuids(proofGuids);
- rightsProtectionVO.setProofFileList(systemFiles);
- }
- }
- BeanUtils.copyProperties(ticketRightsProtection, rightsProtectionVO);
- }
- ticketVO.setTicketRightsProtectionVO(rightsProtectionVO);
- break;
- case 3:
- TicketLitigationRespondingVO litigationRespondingVO = new TicketLitigationRespondingVO();
- LambdaQueryWrapper<TicketLitigationResponding> respondingWrapper = new LambdaQueryWrapper<>();
- respondingWrapper.eq(TicketLitigationResponding::getTicketId, ticketId);
- TicketLitigationResponding ticketLitigationResponding = ticketLitigationRespondingService.getOne(respondingWrapper, false);
- if (ticketLitigationResponding != null) {
- BeanUtils.copyProperties(ticketLitigationResponding, litigationRespondingVO);
- }
- ticketVO.setTicketLitigationRespondingVO(litigationRespondingVO);
- break;
- case 4:
- TicketPatentApplyVO patentApplyVO = new TicketPatentApplyVO();
- LambdaQueryWrapper<TicketPatentApply> patentApplyWrapper = new LambdaQueryWrapper<>();
- patentApplyWrapper.eq(TicketPatentApply::getTicketId, ticketId);
- TicketPatentApply ticketPatentApply = ticketPatentApplyService.getOne(patentApplyWrapper, false);
- if (ticketPatentApply != null) {
- BeanUtils.copyProperties(ticketPatentApply, patentApplyVO);
- }
- ticketVO.setTicketPatentApplyVO(patentApplyVO);
- break;
- default:
- break;
- }
- ticketVOS.add(ticketVO);
- }
- }
- return ticketVOS;
- }
- /**
- * 更新工单状态
- *
- * @param ticketProcessUpDTO
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public Integer updateProcess(TicketProcessUpDTO ticketProcessUpDTO) {
- Integer id = ticketProcessUpDTO.getId();
- Integer process = ticketProcessUpDTO.getProcess();
- Ticket ticket = this.getById(id);
- Boolean flag = this.ifHavePermission(ticket.getCreateId());
- if (!flag) {
- return 0;
- }
- ticket.setTicketProgress(process);
- ticket.updateById();
- if (process.equals(4)) {
- ticketFlowService.addTicketFlow(ticket, "工单已确认", false, null, 4,ticket.getCreateId());
- }
- if(process.equals(5))
- {
- ticketFlowService.addTicketFlow(ticket, "工单已取消", false, null, 5,ticket.getCreateId());
- }
- return ticket.getId();
- }
- /**
- * 更新工单状态
- *
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public Integer updateProcess(String uuid, Integer process) {
- LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(Ticket::getNum, uuid);
- Ticket ticket = this.getOne(queryWrapper, false);
- ticket.setTicketProgress(process);
- ticket.updateById();
- ticketFlowService.addTicketFlow(ticket, "工单支付成功", false, null, 3,ticket.getCreateId());
- return ticket.getId();
- }
- /**
- * 更新价格
- *
- * @param ticketPriceUpDTO
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public Integer updatePrice(TicketPriceUpDTO ticketPriceUpDTO) {
- Integer id = ticketPriceUpDTO.getId();
- Double price = ticketPriceUpDTO.getPrice();
- Ticket ticket = this.getById(id);
- Boolean flag = this.ifHavePermission(null);
- if (!flag) {
- return 0;
- }
- ticket.setPrice(price);
- ticket.updateById();
- return ticket.getId();
- }
- private Boolean ifHavePermission(String id) {
- PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
- personnelVO.getPersonType();
- if (personnelVO.getPersonType().equals(0) || (id != null && personnelVO.getUuid().equals(id))) {
- return true;
- }
- return false;
- }
- public Ticket getTicketByUUid(String uuid) {
- LambdaQueryWrapper<Ticket> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(Ticket::getNum, uuid);
- Ticket ticket = this.getOne(queryWrapper);
- return ticket;
- }
- @Transactional(rollbackFor = Exception.class)
- public Integer acceptTicket(AcceptTicketDTO acceptTicketDTO) {
- Integer id = acceptTicketDTO.getId();
- Double price = acceptTicketDTO.getPrice();
- //根据id查询工单
- Ticket ticket = this.getById(id);
- if (ticket == null) {
- throw new BusinessException("607", "未查询到工单");
- }
- if (ticket.getTicketProgress() > 2) {
- throw new BusinessException("607", "此工单不可进行操作");
- }
- ticket.setPrice(price);
- if (ticket.getTicketProgress() == 2) {
- ticketFlowService.addTicketFlow(ticket, "修改工单价格为" + price, false, null, 2);
- } else {
- ticket.setTicketProgress(2);
- ticketFlowService.addTicketFlow(ticket, "受理工单并且修改价格为" + price, false, null, 2);
- }
- ticket.updateById();
- return ticket.getId();
- }
- /**
- * 上传工单结果
- *
- * @param ticketUploadResultDTO
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public Integer uploadTicketResult(TicketUploadResultDTO ticketUploadResultDTO) {
- List<String> fileGuids = new ArrayList<>();
- fileGuids = ticketUploadResultDTO.getFileGuids();
- String description = ticketUploadResultDTO.getDescription();
- Integer id = ticketUploadResultDTO.getId();
- //根据id查询工单
- Ticket ticket = this.getById(id);
- if (ticket == null) {
- throw new BusinessException("607", "未查询到工单");
- }
- if (ticket.getTicketProgress() > 3) {
- throw new BusinessException("607", "此工单不可进行操作");
- }
- //添加工单流程
- TicketFlow ticketFlow = ticketFlowService.addTicketFlow(ticket, "添加工单结果", true, description, 6);
- //添加结果
- assoTicketFileService.addTicketFile(fileGuids, 1, ticket, ticketFlow.getId());
- ticket.setTicketProgress(6);
- ticket.updateById();
- return ticket.getId();
- }
- public TicketDetailVO getTicketDetail(Integer ticketId) {
- TicketDetailVO ticketDetailVO = new TicketDetailVO();
- //根据id查询
- Ticket ticket = this.getById(ticketId);
- if (ticket == null) {
- return ticketDetailVO;
- }
- ticketDetailVO = this.loadTicketDetail(ticket);
- return ticketDetailVO;
- }
- public TicketDetailVO loadTicketDetail(Ticket ticket) {
- TicketDetailVO ticketDetailVO = new TicketDetailVO();
- BeanUtils.copyProperties(ticket, ticketDetailVO);
- Integer ticketId = ticket.getId();
- //附图
- LambdaQueryWrapper<AssoTicketFile> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(AssoTicketFile::getTicketId, ticketId)
- .eq(AssoTicketFile::getType, 0);
- List<AssoTicketFile> assoTicketFiles = assoTicketFileService.list(queryWrapper);
- if (assoTicketFiles != null && !assoTicketFiles.isEmpty()) {
- List<String> fileGuids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
- List<SystemFile> systemFiles = fileManagerService.getSystemFileByGuids(fileGuids);
- ticketDetailVO.setSystemFiles(systemFiles);
- }
- Integer ticketType = ticket.getTicketType();
- switch (ticketType) {
- case 1:
- TicketFillInVO ticketFillInVO = ticketFillInService.getVOByTicId(ticketId);
- ticketDetailVO.setTicketFillInVO(ticketFillInVO);
- break;
- case 2:
- TicketRightsProtectionVO rightsProtectionVO = ticketRightsProtectionService.getVOByTicId(ticketId);
- ticketDetailVO.setTicketRightsProtectionVO(rightsProtectionVO);
- break;
- case 3:
- TicketLitigationRespondingVO litigationRespondingVO = ticketLitigationRespondingService.getVOByTicId(ticketId);
- ticketDetailVO.setTicketLitigationRespondingVO(litigationRespondingVO);
- break;
- case 4:
- TicketPatentApplyVO patentApplyVO = ticketPatentApplyService.getVOByTicId(ticketId);
- ticketDetailVO.setTicketPatentApplyVO(patentApplyVO);
- break;
- default:
- break;
- }
- try {
- TicketFlowVO ticketFlowVO = ticketFlowService.getTicketResult(ticketId);
- ticketDetailVO.setTicketResult(ticketFlowVO);
- } catch (Exception e) {
- }
- return ticketDetailVO;
- }
- }
|