73 lines
3.4 KiB
Java
73 lines
3.4 KiB
Java
|
|
package com.gunshi.project.ss.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.ss.entity.so.MentenceStPageSo;
|
||
|
|
import com.gunshi.project.ss.mapper.MentenceFarmerRecordMapper;
|
||
|
|
import com.gunshi.project.ss.mapper.MentencePlanDetailMapper;
|
||
|
|
import com.gunshi.project.ss.mapper.MentenceStDetailMapper;
|
||
|
|
import com.gunshi.project.ss.model.MentenceFarmerRecord;
|
||
|
|
import com.gunshi.project.ss.model.MentencePlanDetail;
|
||
|
|
import com.gunshi.project.ss.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;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
@Transactional(rollbackFor = Exception.class)
|
||
|
|
public class MentenceStDetailService extends ServiceImpl<MentenceStDetailMapper, MentenceStDetail> {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private MentencePlanDetailMapper mentencePlanDetailMapper;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private MentenceFarmerRecordMapper mentenceFarmerRecordMapper;
|
||
|
|
|
||
|
|
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());
|
||
|
|
queryWrapper.orderByAsc(MentenceStDetail::getOrder);
|
||
|
|
Page<MentenceStDetail> mentenceStDetailPage = baseMapper.selectPage(dto.getPageSo().toPage(), queryWrapper);
|
||
|
|
for (MentenceStDetail record : mentenceStDetailPage.getRecords()) {
|
||
|
|
LambdaQueryWrapper<MentencePlanDetail> queryWrapperDetail = new LambdaQueryWrapper<>();
|
||
|
|
queryWrapperDetail.eq(MentencePlanDetail::getMentenceStDetailId, record.getId());
|
||
|
|
Long count1 = mentencePlanDetailMapper.selectCount(queryWrapperDetail);
|
||
|
|
|
||
|
|
LambdaQueryWrapper<MentenceFarmerRecord> queryWrapperFarmerRecord = new LambdaQueryWrapper<>();
|
||
|
|
queryWrapperFarmerRecord.eq(MentenceFarmerRecord::getMentenceStDetailId,record.getId());
|
||
|
|
Long count2 = mentenceFarmerRecordMapper.selectCount(queryWrapperFarmerRecord);
|
||
|
|
if(count1 > 0 || count2 > 0) {
|
||
|
|
record.setHasUse(true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return mentenceStDetailPage;
|
||
|
|
}
|
||
|
|
}
|