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 { @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 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 ticketFlowVOS = this.loadTicketFlows(Arrays.asList(ticketFlow)); ticketFlowVO = ticketFlowVOS.get(0); } return ticketFlowVO; } public List getTicketFlows(Integer ticketId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(TicketFlow::getTicketId, ticketId) .orderByDesc(TicketFlow::getCreateTime); List ticketFlows = this.list(queryWrapper); List ticketFlowVOS = this.loadTicketFlows(ticketFlows); return ticketFlowVOS; } private List loadTicketFlows(List ticketFlows) { List ticketFlowVOS = new ArrayList<>(); if(ticketFlows.size()==0){ return ticketFlowVOS; } List ticketFlowIds = ticketFlows.stream().map(TicketFlow::getId).collect(Collectors.toList()); List createIds =ticketFlows.stream().map(TicketFlow::getCreateId).collect(Collectors.toList()); List personList=personService.getPersonsById(createIds); List assoTicketFiles =new ArrayList<>(); //根据ids查询文件guid assoTicketFiles = assoTicketFileService.queryFileByFlowIds(ticketFlowIds); List guids = assoTicketFiles.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList()); //根据guid查询文件信息 List systemFiles =fileManagerService.getSystemFileByGuids(guids); for (TicketFlow ticketFlow : ticketFlows) { TicketFlowVO ticketFlowVO = new TicketFlowVO(); BeanUtils.copyProperties(ticketFlow, ticketFlowVO); List assoTicketFileList = assoTicketFiles.stream().filter(item -> item.getFlowId().equals(ticketFlow.getId())).collect(Collectors.toList()); if (assoTicketFileList.size() != 0) { List temGuids = assoTicketFileList.stream().map(AssoTicketFile::getFileGuid).collect(Collectors.toList()); List 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; } }