package com.gunshi.project.xyt.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gunshi.project.xyt.entity.so.InspectProblemPageSo; import com.gunshi.project.xyt.entity.vo.InspectProblemVo; import com.gunshi.project.xyt.entity.vo.InspectTaskDetailVo; import com.gunshi.project.xyt.mapper.InspectTaskDetailMapper; import com.gunshi.project.xyt.model.InspectTaskDetail; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 描述: 巡查信息 * author: xusan * date: 2024-08-29 14:21:45 */ @Service @Slf4j @Transactional(rollbackFor = Exception.class) public class InspectTaskDetailService extends ServiceImpl { @Autowired private FileAssociationsService fileService; public void saveDetail(List items, Long taskId) { items.stream().forEach(o->{ o.setId(IdWorker.getId()); o.setTaskId(taskId); }); this.saveBatch(items); } public void updateDetail(List items, Long taskId) { delDetail(taskId); saveDetail(items,taskId); } public void delDetail(Long taskId) { this.remove(new QueryWrapper().eq("task_id",taskId)); } public List getByTaskId(Long taskId) { return this.list(new QueryWrapper().eq("task_id",taskId)); } public List inspectInfo(Long id) { List res = new ArrayList<>(); List list = this.baseMapper.inspectInfo(id); Map> map = list.stream().collect(Collectors.groupingBy(InspectTaskDetailVo::getPointId)); map.entrySet().forEach(t->{ InspectTaskDetailVo vo = new InspectTaskDetailVo(); Long pointId = t.getKey(); vo.setPointId(pointId); List value = t.getValue(); vo.setName(value.get(0).getName()); fillFile(value); vo.setChildren(value); res.add(vo); }); return res; } private void fillFile(List value) { for (InspectTaskDetailVo record : value) { record.setInspectPics(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType())); record.setInspectVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getVideoType())); if(record.getIsHandle() == 1){ record.setHandlePics(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandlePicType())); record.setHandleVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandleVideoType())); } } } public Page pageQuery(InspectProblemPageSo page) { Page res = this.baseMapper.pageQuery(page.getPageSo().toPage(),page); if (res.getRecords() != null) { fillAttach(res.getRecords()); } return res; } private void fillAttach(List records) { for (InspectProblemVo record : records) { record.setInspectPics(fileService.queryFileList(record.getId().toString(),getGroupId(),getPicType())); record.setInspectVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getVideoType())); if(record.getIsHandle() == 1){ record.setHandlePics(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandlePicType())); record.setHandleVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandleVideoType())); } } } public String getGroupId() { return "inspectTask"; } private String getPicType() { return "inspectPic"; } private String getVideoType() { return "inspectVideo"; } private String getHandlePicType() { return "handlePic"; } private String getHandleVideoType() { return "handleVideo"; } public void finish(List list) { List res = new ArrayList<>(); for(InspectTaskDetailVo vo : list){ InspectTaskDetail detail = new InspectTaskDetail(); BeanUtils.copyProperties(vo,detail); res.add(detail); fileService.save(vo.getInspectPics(),vo.getId().toString(),getGroupId(),getPicType()); fileService.save(vo.getInspectVideos(),vo.getId().toString(),getGroupId(),getVideoType()); fileService.save(vo.getHandlePics(),vo.getId().toString(),getGroupId(),getHandlePicType()); fileService.save(vo.getHandleVideos(),vo.getId().toString(),getGroupId(),getHandleVideoType()); } //更新任务巡检信息表 this.updateBatchById(res); } }