76 lines
2.8 KiB
Java
76 lines
2.8 KiB
Java
package com.gunshi.project.hsz.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
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.PrePlacePageSo;
|
|
import com.gunshi.project.hsz.mapper.ByPlanDetailMapper;
|
|
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;
|
|
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class PrePlaceDetailService extends ServiceImpl<PrePlaceDetailMapper, PrePlaceDetail> {
|
|
|
|
@Autowired
|
|
private PrePlaceMapper prePlaceMapper;
|
|
|
|
@Autowired
|
|
private ByPlanDetailMapper byPlanDetailMapper;
|
|
|
|
public Page<PrePlaceDetail> pageQuery(PrePlacePageSo pageSo) {
|
|
if(StringUtils.isBlank(pageSo.getPreId())) {
|
|
throw new IllegalArgumentException("请选择防治点");
|
|
}
|
|
LambdaQueryWrapper<PrePlaceDetail> query = new LambdaQueryWrapper<>();
|
|
query.eq(PrePlaceDetail::getPreId, pageSo.getPreId());
|
|
query.orderByAsc(PrePlaceDetail::getOrder);
|
|
Page<PrePlaceDetail> prePlaceDetailPage = this.baseMapper.selectPage(pageSo.getPageSo().toPage(), query);
|
|
return prePlaceDetailPage;
|
|
}
|
|
|
|
public boolean saveData(PrePlaceDetail dto) {
|
|
dto.setId(IdWorker.getId());
|
|
dto.setIsEnable(0);
|
|
Long preId = dto.getPreId();
|
|
PrePlace prePlace = prePlaceMapper.selectById(preId);
|
|
if(prePlace == null) {
|
|
throw new IllegalArgumentException("防治点不存在,请检查");
|
|
}
|
|
boolean save = save(dto);
|
|
return save;
|
|
}
|
|
|
|
public boolean deleteById(Serializable id) {
|
|
//先在防治计划中查看是否被引用
|
|
int count = byPlanDetailMapper.selectByPPDI(id);
|
|
if(count > 0){
|
|
throw new IllegalArgumentException("该防治点在防治计划中已被选择,不能删除");
|
|
}
|
|
boolean b = removeById(id);
|
|
return b;
|
|
}
|
|
|
|
public boolean update(PrePlaceDetail dto) {
|
|
int count = byPlanDetailMapper.selectByPPDI(dto.getId());
|
|
if(count > 0){
|
|
throw new IllegalArgumentException("该防治点在防治计划中已被选择,不能编辑");
|
|
}
|
|
boolean b = updateById(dto);
|
|
return b;
|
|
}
|
|
}
|