137 lines
5.2 KiB
Java
137 lines
5.2 KiB
Java
|
|
package com.gunshi.project.hsz.service;
|
||
|
|
|
||
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||
|
|
import com.gunshi.project.hsz.entity.so.TermiteSurveyPageSo;
|
||
|
|
import com.gunshi.project.hsz.mapper.RiskControlInfoMapper;
|
||
|
|
import com.gunshi.project.hsz.mapper.TermiteSurveyDetailMapper;
|
||
|
|
import com.gunshi.project.hsz.model.BzDictRel;
|
||
|
|
import com.gunshi.project.hsz.model.FileAssociations;
|
||
|
|
import com.gunshi.project.hsz.model.TermiteSurvey;
|
||
|
|
import com.gunshi.project.hsz.model.TermiteSurveyDetail;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
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-28 10:25:17
|
||
|
|
*/
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
@Transactional(rollbackFor = Exception.class)
|
||
|
|
public class TermiteSurveyDetailService extends ServiceImpl<TermiteSurveyDetailMapper, TermiteSurveyDetail>
|
||
|
|
{
|
||
|
|
@Autowired
|
||
|
|
private FileAssociationsService fileService;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private BzDictRelService bzDictRelService;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private RiskControlInfoMapper controlInfoMapper;
|
||
|
|
|
||
|
|
public void saveDetail(List<TermiteSurveyDetail> details, Long id) {
|
||
|
|
if(!CollectionUtils.isEmpty(details)){
|
||
|
|
List<FileAssociations> picList = new ArrayList<>();
|
||
|
|
List<FileAssociations> videoList = new ArrayList<>();
|
||
|
|
List<BzDictRel> relList = new ArrayList<>();
|
||
|
|
for (TermiteSurveyDetail detail : details){
|
||
|
|
Long detailId = IdWorker.getId();
|
||
|
|
detail.setId(detailId);
|
||
|
|
detail.setSurveyId(id);
|
||
|
|
if(CollectionUtils.isNotEmpty(detail.getActSign())){
|
||
|
|
detail.getActSign().stream().forEach(o->o.setBusinessId(detailId));
|
||
|
|
relList.addAll(detail.getActSign());
|
||
|
|
}
|
||
|
|
if(CollectionUtils.isNotEmpty(detail.getPics())){
|
||
|
|
detail.getPics().stream().forEach(o->o.setBusinessId(detailId.toString()));
|
||
|
|
picList.addAll(detail.getPics());
|
||
|
|
}
|
||
|
|
if(CollectionUtils.isNotEmpty(detail.getVideos())){
|
||
|
|
detail.getVideos().stream().forEach(o->o.setBusinessId(detailId.toString()));
|
||
|
|
videoList.addAll(detail.getVideos());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.saveBatch(details);
|
||
|
|
bzDictRelService.saveRel(relList,null,getGroupId());
|
||
|
|
fileService.save(picList,null,getGroupId(),getPicType());
|
||
|
|
fileService.save(videoList,null,getGroupId(),getVideoType());
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private String getPicType() {
|
||
|
|
return "termitePic";
|
||
|
|
}
|
||
|
|
|
||
|
|
private String getVideoType() {
|
||
|
|
return "termiteVideo";
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getGroupId() {
|
||
|
|
return "termiteSurvey";
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public void updateDetail(List<TermiteSurveyDetail> details, Long id) {
|
||
|
|
delDetail(id);
|
||
|
|
saveDetail(details,id);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void delDetail(Long id) {
|
||
|
|
List<TermiteSurveyDetail> list = getDetailById(id);
|
||
|
|
if(CollectionUtils.isEmpty(list)){
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
List<Long> detailIds = list.stream().map(TermiteSurveyDetail::getId).collect(Collectors.toList());
|
||
|
|
List<String> ids = detailIds.stream().map(Object::toString).collect(Collectors.toList());
|
||
|
|
//删除附件
|
||
|
|
fileService.removeByBzIds(ids);
|
||
|
|
//删除字典
|
||
|
|
bzDictRelService.removeByBzIds(detailIds);
|
||
|
|
this.removeBatchByIds(detailIds);
|
||
|
|
}
|
||
|
|
|
||
|
|
public TermiteSurvey detail(TermiteSurvey termiteSurvey) {
|
||
|
|
List<TermiteSurveyDetail> list = getDetailById(termiteSurvey.getId());
|
||
|
|
if(CollectionUtils.isEmpty(list)){
|
||
|
|
return termiteSurvey;
|
||
|
|
}
|
||
|
|
List<Long> ids = list.stream().map(TermiteSurveyDetail::getId).collect(Collectors.toList());
|
||
|
|
List<BzDictRel> relList = controlInfoMapper.queryRelList(ids);
|
||
|
|
Map<Long, List<BzDictRel>> map = relList.stream().collect(Collectors.groupingBy(BzDictRel::getBusinessId));
|
||
|
|
for(TermiteSurveyDetail detail : list){
|
||
|
|
detail.setActSign(map.get(detail.getId()));
|
||
|
|
detail.setPics(fileService.queryFileList(detail.getId().toString(),getGroupId(),getPicType()));
|
||
|
|
detail.setVideos(fileService.queryFileList(detail.getId().toString(),getGroupId(),getVideoType()));
|
||
|
|
}
|
||
|
|
termiteSurvey.setDetails(list);
|
||
|
|
return termiteSurvey;
|
||
|
|
}
|
||
|
|
|
||
|
|
private List<TermiteSurveyDetail> getDetailById(Long id){
|
||
|
|
LambdaQueryWrapper<TermiteSurveyDetail> queryWrapper = Wrappers.lambdaQuery();
|
||
|
|
queryWrapper.eq(TermiteSurveyDetail::getSurveyId,id);
|
||
|
|
return this.list(queryWrapper);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public Page<TermiteSurveyDetail> pageQuery(TermiteSurveyPageSo page) {
|
||
|
|
return this.baseMapper.pageQuery(page.getPageSo().toPage(),page);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|