81 lines
2.8 KiB
Java
81 lines
2.8 KiB
Java
|
|
package com.gunshi.project.ss.service;
|
||
|
|
|
||
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||
|
|
import com.gunshi.project.ss.mapper.InspectItemMapper;
|
||
|
|
import com.gunshi.project.ss.mapper.InspectPointMapper;
|
||
|
|
import com.gunshi.project.ss.model.InspectItem;
|
||
|
|
import com.gunshi.project.ss.model.InspectPoint;
|
||
|
|
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;
|
||
|
|
import java.util.Objects;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 描述: 巡检点
|
||
|
|
* author: xusan
|
||
|
|
* date: 2024-08-29 09:57:48
|
||
|
|
*/
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
@Transactional(rollbackFor = Exception.class)
|
||
|
|
public class InspectPointService extends ServiceImpl<InspectPointMapper, InspectPoint>
|
||
|
|
{
|
||
|
|
@Autowired
|
||
|
|
private InspectItemMapper inspectItemMapper;
|
||
|
|
|
||
|
|
public InspectPoint saveData(InspectPoint dto) {
|
||
|
|
dto.setId(IdWorker.getId());
|
||
|
|
QueryWrapper<InspectPoint> queryWrapper = new QueryWrapper<>();
|
||
|
|
queryWrapper.orderBy(true, false, "order_index");
|
||
|
|
InspectPoint lastOne = super.getOne(queryWrapper, false);
|
||
|
|
int order = 0;
|
||
|
|
if (lastOne == null) {
|
||
|
|
order = 1;
|
||
|
|
} else {
|
||
|
|
order = lastOne.getOrderIndex() + 1;
|
||
|
|
}
|
||
|
|
dto.setOrderIndex(order);
|
||
|
|
this.save(dto);
|
||
|
|
return dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
public InspectPoint updateData(InspectPoint dto) {
|
||
|
|
if (Objects.isNull(this.getById(dto.getId()))) {
|
||
|
|
throw new IllegalArgumentException("当前数据不存在");
|
||
|
|
}
|
||
|
|
this.updateById(dto);
|
||
|
|
return dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Boolean delData(Serializable id) {
|
||
|
|
if (Objects.isNull(this.getById(id))) {
|
||
|
|
throw new IllegalArgumentException("当前数据不存在");
|
||
|
|
}
|
||
|
|
//判断是否关联巡检项
|
||
|
|
LambdaQueryWrapper<InspectItem> wrapper = Wrappers.lambdaQuery();
|
||
|
|
wrapper.eq(InspectItem::getPointId,id);
|
||
|
|
if(inspectItemMapper.selectCount(wrapper) > 0){
|
||
|
|
throw new IllegalArgumentException("请先删除关联的巡检项");
|
||
|
|
}
|
||
|
|
return this.removeById(id);
|
||
|
|
}
|
||
|
|
|
||
|
|
public List<InspectPoint> listWithItem() {
|
||
|
|
List<InspectPoint> list = this.lambdaQuery().orderByAsc(InspectPoint::getOrderIndex).list();
|
||
|
|
for(InspectPoint point : list){
|
||
|
|
point.setChildren(inspectItemMapper.selectList(new QueryWrapper<InspectItem>().eq("point_id",point.getId()).orderByAsc("order_index")));
|
||
|
|
}
|
||
|
|
return list;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|