2025-08-26 17:36:32 +08:00
|
|
|
package com.gunshi.project.hsz.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.gunshi.project.hsz.entity.so.PrePlacePageSo;
|
|
|
|
|
import com.gunshi.project.hsz.entity.vo.PrePlaceTreeVo;
|
|
|
|
|
import com.gunshi.project.hsz.mapper.PrePlaceDetailMapper;
|
|
|
|
|
import com.gunshi.project.hsz.mapper.PrePlaceMapper;
|
|
|
|
|
import com.gunshi.project.hsz.model.PrePlace;
|
|
|
|
|
import com.gunshi.project.hsz.model.PrePlaceDetail;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
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.io.Serializable;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class PrePlaceService extends ServiceImpl<PrePlaceMapper, PrePlace> {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrePlaceDetailMapper prePlaceDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrePlaceMapper prePlaceMapper;
|
|
|
|
|
|
|
|
|
|
public boolean deleteById(Serializable id) {
|
|
|
|
|
//先查看细节表还有数据没
|
|
|
|
|
int count = prePlaceDetailMapper.selectByPreId(id);
|
|
|
|
|
if(count > 0){
|
|
|
|
|
throw new RuntimeException("该防治点,还有防治部位未删,请检查");
|
|
|
|
|
}
|
|
|
|
|
boolean res = deleteById(id);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<PrePlace> tree(PrePlacePageSo dto) {
|
|
|
|
|
LambdaQueryWrapper<PrePlace> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
if(!StringUtils.isBlank(dto.getPreId())){
|
|
|
|
|
wrapper.eq(PrePlace::getId, dto.getPreId());
|
|
|
|
|
}
|
|
|
|
|
List<PrePlace> prePlaces = prePlaceMapper.selectList(wrapper);
|
|
|
|
|
Iterator<PrePlace> iterator = prePlaces.iterator();
|
|
|
|
|
while(iterator.hasNext()){
|
|
|
|
|
PrePlace prePlace = iterator.next();
|
|
|
|
|
LambdaQueryWrapper<PrePlaceDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
if(!StringUtils.isBlank(dto.getPreName())){
|
|
|
|
|
queryWrapper.like(PrePlaceDetail::getDetailName, dto.getPreName());
|
|
|
|
|
}
|
2025-08-27 16:42:01 +08:00
|
|
|
queryWrapper.eq(PrePlaceDetail::getPreId, prePlace.getId());
|
2025-08-26 17:36:32 +08:00
|
|
|
List<PrePlaceDetail> prePlaceDetails = prePlaceDetailMapper.selectList(queryWrapper);
|
2025-08-27 16:42:01 +08:00
|
|
|
if(prePlaceDetails.isEmpty()){
|
2025-08-26 17:36:32 +08:00
|
|
|
iterator.remove();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
prePlace.setChildrens(prePlaceDetails);
|
|
|
|
|
}
|
|
|
|
|
return prePlaces;
|
|
|
|
|
}
|
|
|
|
|
}
|