123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package com.example.xiaoshiweixinback.service;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.example.xiaoshiweixinback.business.common.base.SystemFile;
- import com.example.xiaoshiweixinback.business.utils.CacheUtil;
- import com.example.xiaoshiweixinback.business.utils.LoginUtils;
- import com.example.xiaoshiweixinback.domain.AssoTicketFile;
- import com.example.xiaoshiweixinback.domain.Person;
- import com.example.xiaoshiweixinback.domain.Ticket;
- import com.example.xiaoshiweixinback.domain.TicketFlow;
- import com.example.xiaoshiweixinback.entity.dto.ticket.TicketFlowVO;
- import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
- import com.example.xiaoshiweixinback.mapper.TicketFlowMapper;
- import com.example.xiaoshiweixinback.service.common.FileManagerService;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * @author admin
- * @description 针对表【ticket_flow(工单流程)】的数据库操作Service实现
- * @createDate 2024-04-17 18:47:48
- */
- @Service
- public class TicketFlowService extends ServiceImpl<TicketFlowMapper, TicketFlow> {
- @Autowired
- private CacheUtil cacheUtil;
- @Autowired
- private AssoTicketFileService assoTicketFileService;
- @Autowired
- private FileManagerService fileManagerService;
- @Autowired
- private PersonService personService;
- /**
- * 添加工单流程
- *
- * @param ticket
- * @param description
- * @return
- */
- public TicketFlow addTicketFlow(Ticket ticket, String description, Boolean ifResult,String remark,Integer progress) {
- PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
- TicketFlow ticketFlow = new TicketFlow();
- ticketFlow.setTicketId(ticket.getId());
- ticketFlow.setTicketProcess(progress);
- ticketFlow.setCreateId(personnelVO.getUuid());
- ticketFlow.setDescription(description);
- ticketFlow.setRemark(remark);
- ticketFlow.setIfResult(ifResult);
- ticketFlow.insert();
- return ticketFlow;
- }
- /**
- * 查询工单结果
- *
- * @param ticketId
- */
- public TicketFlowVO getTicketResult(Integer ticketId) throws Exception {
- TicketFlowVO ticketFlowVO = new TicketFlowVO();
- //根据工单id查询工单结果流程
- LambdaQueryWrapper<TicketFlow> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TicketFlow::getTicketId, ticketId)
- .eq(TicketFlow::getIfResult, true)
- .orderByDesc(TicketFlow::getCreateTime);
- TicketFlow ticketFlow = this.getOne(queryWrapper, false);
- if (ticketFlow != null) {
- //根据工单流程查询文件
- List<TicketFlowVO> ticketFlowVOS = this.loadTicketFlows(Arrays.asList(ticketFlow));
- ticketFlowVO = ticketFlowVOS.get(0);
- }
- return ticketFlowVO;
- }
- public List<TicketFlowVO> getTicketFlows(Integer ticketId) {
- LambdaQueryWrapper<TicketFlow> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TicketFlow::getTicketId, ticketId)
- .orderByDesc(TicketFlow::getCreateTime);
- List<TicketFlow> ticketFlows = this.list(queryWrapper);
- List<TicketFlowVO> ticketFlowVOS = this.loadTicketFlows(ticketFlows);
- return ticketFlowVOS;
- }
- private List<TicketFlowVO> loadTicketFlows(List<TicketFlow> ticketFlows) {
- List<TicketFlowVO> ticketFlowVOS = new ArrayList<>();
- if(ticketFlows.size()==0){
- return ticketFlowVOS;
- }
- List<Integer> ticketFlowIds = ticketFlows.stream().map(TicketFlow::getId).collect(Collectors.toList());
- List<String> createIds =ticketFlows.stream().map(TicketFlow::getCreateId).collect(Collectors.toList());
- List<Person> personList=personService.getPersonsById(createIds);
- List<AssoTicketFile> assoTicketFiles =new ArrayList<>();
- //根据ids查询文件guid
- assoTicketFiles = assoTicketFileService.queryFileByFlowIds(ticketFlowIds);
- List<String> guids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
- //根据guid查询文件信息
- List<SystemFile> systemFiles =fileManagerService.getSystemFileByGuids(guids);
- for (TicketFlow ticketFlow : ticketFlows) {
- TicketFlowVO ticketFlowVO = new TicketFlowVO();
- BeanUtils.copyProperties(ticketFlow, ticketFlowVO);
- List<AssoTicketFile> assoTicketFileList = assoTicketFiles.stream().filter(item -> item.getFlowId().equals(ticketFlow.getId())).collect(Collectors.toList());
- if (assoTicketFileList.size() != 0) {
- List<String> temGuids = assoTicketFileList.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList());
- List<SystemFile> temSystemFiles = systemFiles.stream().filter(item -> temGuids.contains(item.getGuid())).collect(Collectors.toList());
- ticketFlowVO.setSystemFiles(temSystemFiles);
- }
- Person person= personList.stream().filter(item->item.getUuid().equals(ticketFlow.getCreateId())).findFirst().orElse(null);
- if(person!=null){
- ticketFlowVO.setCreateName(person.getName());
- }
- ticketFlowVOS.add(ticketFlowVO);
- }
- return ticketFlowVOS;
- }
- }
|