86 lines
3.4 KiB
Java
86 lines
3.4 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.StringUtils;
|
|
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.mapper.MessageCenterMapper;
|
|
import com.gunshi.project.hsz.model.MentenceSt;
|
|
import com.gunshi.project.hsz.model.MentenceStDetail;
|
|
import com.gunshi.project.hsz.model.MessageCenter;
|
|
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.Date;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class MentenceStService extends ServiceImpl<MentenceStMapper, MentenceSt> {
|
|
|
|
@Autowired
|
|
private MentenceStDetailMapper mentenceStDetailMapper;
|
|
|
|
|
|
|
|
public boolean deleteById(Serializable id) {
|
|
LambdaQueryWrapper<MentenceStDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(MentenceStDetail::getMentenceStId, id);
|
|
Long count = mentenceStDetailMapper.selectCount(queryWrapper);
|
|
if(count > 0) {
|
|
throw new IllegalArgumentException("存在养护项目,无法删除");
|
|
}
|
|
removeById(id);
|
|
return true;
|
|
}
|
|
|
|
public List<MentenceSt> tree(MentenceStPageSo dto) {
|
|
LambdaQueryWrapper<MentenceSt> queryWrapper = new LambdaQueryWrapper<>();
|
|
if(!StringUtils.isBlank(dto.getStName())){
|
|
queryWrapper.like(MentenceSt::getStName, dto.getStName());
|
|
}
|
|
List<MentenceSt> mentenceSts = baseMapper.selectList(queryWrapper);
|
|
Iterator<MentenceSt> iterator = mentenceSts.iterator();
|
|
while(iterator.hasNext()) {
|
|
MentenceSt mentenceSt = iterator.next();
|
|
LambdaQueryWrapper<MentenceStDetail> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
if(!StringUtils.isBlank(dto.getStDetailName())){
|
|
queryWrapper2.like(MentenceStDetail::getStDetailName, dto.getStDetailName());
|
|
}
|
|
queryWrapper2.eq(MentenceStDetail::getMentenceStId,mentenceSt.getId());
|
|
queryWrapper2.eq(MentenceStDetail::getIsEnable,0);
|
|
List<MentenceStDetail> mentenceStDetails = mentenceStDetailMapper.selectList(queryWrapper2);
|
|
if(mentenceStDetails.isEmpty()){
|
|
iterator.remove();
|
|
continue;
|
|
}
|
|
mentenceSt.setChildrens(mentenceStDetails);
|
|
}
|
|
return mentenceSts;
|
|
}
|
|
|
|
public boolean saveDate(MentenceSt dto) {
|
|
LambdaQueryWrapper<MentenceSt> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(MentenceSt::getStName, dto.getStName());
|
|
MentenceSt mentenceSt = baseMapper.selectOne(queryWrapper);
|
|
if(Objects.nonNull(mentenceSt)){
|
|
throw new IllegalArgumentException("该名称已存在,请检查");
|
|
}
|
|
dto.setId(IdWorker.getId());
|
|
dto.setCreateTime(new Date());
|
|
save(dto);
|
|
return true;
|
|
}
|
|
}
|