gunshi-project-ss/src/main/java/com/gunshi/project/hsz/service/MentenceStDetailService.java

58 lines
2.5 KiB
Java

package com.gunshi.project.hsz.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.project.hsz.entity.so.MentenceStPageSo;
import com.gunshi.project.hsz.mapper.MentencePlanDetailMapper;
import com.gunshi.project.hsz.mapper.MentenceStDetailMapper;
import com.gunshi.project.hsz.mapper.MentenceStMapper;
import com.gunshi.project.hsz.model.MentencePlanDetail;
import com.gunshi.project.hsz.model.MentenceSt;
import com.gunshi.project.hsz.model.MentenceStDetail;
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.List;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class MentenceStDetailService extends ServiceImpl<MentenceStDetailMapper, MentenceStDetail> {
@Autowired
private MentencePlanDetailMapper mentencePlanDetailMapper;
public boolean deleteById(Serializable id) {
LambdaQueryWrapper<MentencePlanDetail> queryWrapperDetail = new LambdaQueryWrapper<>();
queryWrapperDetail.eq(MentencePlanDetail::getMentenceStDetailId, id);
Long count = mentencePlanDetailMapper.selectCount(queryWrapperDetail);
if(count > 0) {
throw new IllegalArgumentException("该维护项目,正关联着维护计划,不允许删除");
}
int delete = baseMapper.deleteById(id);
return true;
}
public boolean update(MentenceStDetail dto) {
LambdaQueryWrapper<MentencePlanDetail> queryWrapperDetail = new LambdaQueryWrapper<>();
queryWrapperDetail.eq(MentencePlanDetail::getMentenceStDetailId, dto.getId());
Long count = mentencePlanDetailMapper.selectCount(queryWrapperDetail);
if(count > 0) {
throw new IllegalArgumentException("该维护项目,正关联着维护计划,不允许更新");
}
baseMapper.updateById(dto);
return true;
}
public Page<MentenceStDetail> pageQuery(MentenceStPageSo dto) {
LambdaQueryWrapper<MentenceStDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MentenceStDetail::getMentenceStId,dto.getStId());
Page<MentenceStDetail> mentenceStDetailPage = baseMapper.selectPage(dto.getPageSo().toPage(), queryWrapper);
return mentenceStDetailPage;
}
}