166 lines
6.5 KiB
Java
166 lines
6.5 KiB
Java
package com.gunshi.project.hsz.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
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.hsz.entity.so.InspectProblemPageSo;
|
|
import com.gunshi.project.hsz.entity.vo.InspectProblemVo;
|
|
import com.gunshi.project.hsz.entity.vo.InspectTaskDetailVo;
|
|
import com.gunshi.project.hsz.mapper.InspectTaskDetailMapper;
|
|
import com.gunshi.project.hsz.common.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.Date;
|
|
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<InspectTaskDetailMapper, InspectTaskDetail>
|
|
{
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
public void saveDetail(List<InspectTaskDetail> items, Long taskId) {
|
|
items.stream().forEach(o->{
|
|
o.setId(IdWorker.getId());
|
|
o.setTaskId(taskId);
|
|
});
|
|
this.saveBatch(items);
|
|
}
|
|
|
|
public void updateDetail(List<InspectTaskDetail> items, Long taskId) {
|
|
delDetail(taskId);
|
|
saveDetail(items,taskId);
|
|
}
|
|
|
|
public void delDetail(Long taskId) {
|
|
this.remove(new QueryWrapper<InspectTaskDetail>().eq("task_id",taskId));
|
|
}
|
|
|
|
public List<InspectTaskDetail> getByTaskId(Long taskId) {
|
|
return this.list(new QueryWrapper<InspectTaskDetail>().eq("task_id",taskId));
|
|
}
|
|
|
|
public List<InspectTaskDetailVo> inspectInfo(Long id) {
|
|
List<InspectTaskDetailVo> res = new ArrayList<>();
|
|
List<InspectTaskDetailVo> list = this.baseMapper.inspectInfo(id);
|
|
Map<Long, List<InspectTaskDetailVo>> map = list.stream().collect(Collectors.groupingBy(InspectTaskDetailVo::getPointId));
|
|
map.entrySet().forEach(t->{
|
|
InspectTaskDetailVo vo = new InspectTaskDetailVo();
|
|
Long pointId = t.getKey();
|
|
vo.setPointId(pointId);
|
|
List<InspectTaskDetailVo> value = t.getValue();
|
|
vo.setName(value.get(0).getName());
|
|
fillFile(value);
|
|
vo.setChildren(value);
|
|
res.add(vo);
|
|
});
|
|
return res;
|
|
}
|
|
|
|
private void fillFile(List<InspectTaskDetailVo> 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() != null && record.getIsHandle() == 1){
|
|
record.setHandlePics(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandlePicType()));
|
|
record.setHandleVideos(fileService.queryFileList(record.getId().toString(),getGroupId(),getHandleVideoType()));
|
|
}
|
|
}
|
|
}
|
|
|
|
public Page<InspectProblemVo> pageQuery(InspectProblemPageSo page) {
|
|
Page<InspectProblemVo> res = this.baseMapper.pageQuery(page.getPageSo().toPage(),page);
|
|
if (res.getRecords() != null) {
|
|
fillAttach(res.getRecords());
|
|
}
|
|
return res;
|
|
}
|
|
|
|
private void fillAttach(List<InspectProblemVo> 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() != null && 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<InspectTaskDetailVo> list) {
|
|
List<InspectTaskDetail> res = new ArrayList<>();
|
|
List<String> ids = list.stream().map(InspectTaskDetailVo::getId).map(Object::toString).collect(Collectors.toList());
|
|
if(CollectionUtils.isNotEmpty(ids)){
|
|
fileService.removeByBzIds(ids);
|
|
}
|
|
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);
|
|
}
|
|
|
|
public String handle(InspectProblemVo vo) {
|
|
InspectTaskDetail detail = new InspectTaskDetail();
|
|
BeanUtils.copyProperties(vo,detail,InspectTaskDetail.class);
|
|
detail.setIsHandle(1);
|
|
detail.setHandleTime(new Date());
|
|
this.updateById(detail);
|
|
fileService.save(vo.getHandlePics(),vo.getId().toString(),getGroupId(),getHandlePicType());
|
|
fileService.save(vo.getHandleVideos(),vo.getId().toString(),getGroupId(),getHandleVideoType());
|
|
return "处理成功";
|
|
}
|
|
|
|
public List<InspectProblemVo> handelList() {
|
|
List<InspectProblemVo> list = this.baseMapper.handleList();
|
|
if(CollectionUtils.isNotEmpty(list)){
|
|
fillAttach(list);
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|