package com.ruoyi.oa.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.http.HttpStatus;
|
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.PageUtils;
|
import com.ruoyi.common.core.page.PagePlus;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
import org.springframework.stereotype.Service;
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.ruoyi.oa.domain.bo.SgServerBo;
|
import com.ruoyi.oa.domain.vo.SgServerVo;
|
import com.ruoyi.oa.domain.SgServer;
|
import com.ruoyi.oa.mapper.SgServerMapper;
|
import com.ruoyi.oa.service.ISgServerService;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Collection;
|
|
/**
|
* 服务器Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2022-05-13
|
*/
|
@Service
|
public class SgServerServiceImpl extends ServicePlusImpl<SgServerMapper, SgServer, SgServerVo> implements ISgServerService {
|
|
@Override
|
public SgServerVo queryById(Long id) {
|
return getVoById(id);
|
}
|
|
@Override
|
public TableDataInfo<SgServerVo> queryPageList(SgServerBo bo) {
|
PagePlus<SgServer, SgServerVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
|
return PageUtils.buildDataInfo(result);
|
}
|
|
@Override
|
public List<SgServerVo> queryList(SgServerBo bo) {
|
return listVo(buildQueryWrapper(bo));
|
}
|
|
private LambdaQueryWrapper<SgServer> buildQueryWrapper(SgServerBo bo) {
|
Map<String, Object> params = bo.getParams();
|
LambdaQueryWrapper<SgServer> lqw = Wrappers.lambdaQuery();
|
lqw.eq(bo.getBuildingId() != null, SgServer::getBuildingId, bo.getBuildingId());
|
lqw.eq(bo.getOrganizationId() != null, SgServer::getOrganizationId, bo.getOrganizationId());
|
lqw.eq(bo.getConstructionBatchId() != null, SgServer::getConstructionBatchId, bo.getConstructionBatchId());
|
lqw.eq(StringUtils.isNotBlank(bo.getModel()), SgServer::getModel, bo.getModel());
|
lqw.eq(bo.getManufacturerId() != null, SgServer::getManufacturerId, bo.getManufacturerId());
|
lqw.eq(SgServer::getSchoolId, bo.getSchoolId());
|
lqw.like(StringUtils.isNotBlank(bo.getDeploymentName()), SgServer::getDeploymentName, bo.getDeploymentName());
|
lqw.orderByDesc(SgServer::getUpdateTime);
|
return lqw;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean insertByBo(SgServerBo bo) {
|
List<SgServer> list = baseMapper.selectList(new LambdaQueryWrapper<SgServer>()
|
.eq(SgServer::getDeploymentName, bo.getDeploymentName())
|
.eq(SgServer::getSchoolId, bo.getSchoolId()));
|
if (list.size() > 0) {
|
throw new ServiceException("部署名称重复", HttpStatus.HTTP_PARTIAL);
|
}
|
List<SgServer> lanList = baseMapper.selectList(new LambdaQueryWrapper<SgServer>()
|
.eq(SgServer::getLan, bo.getLan())
|
.eq(SgServer::getSchoolId, bo.getSchoolId()));
|
if (lanList.size() > 0) {
|
throw new ServiceException("LAN重复", HttpStatus.HTTP_PARTIAL);
|
}
|
SgServer add = BeanUtil.toBean(bo, SgServer.class);
|
validEntityBeforeSave(add);
|
boolean flag = save(add);
|
if (flag) {
|
bo.setId(add.getId());
|
}
|
return flag;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean updateByBo(SgServerBo bo) {
|
List<SgServer> list = baseMapper.selectList(new LambdaQueryWrapper<SgServer>()
|
.eq(SgServer::getDeploymentName, bo.getDeploymentName())
|
.eq(SgServer::getSchoolId, bo.getSchoolId())
|
.ne(SgServer::getId, bo.getId()));
|
if (list.size() > 0) {
|
throw new ServiceException("部署名称重复", HttpStatus.HTTP_PARTIAL);
|
}
|
List<SgServer> lanList = baseMapper.selectList(new LambdaQueryWrapper<SgServer>()
|
.eq(SgServer::getLan, bo.getLan())
|
.eq(SgServer::getSchoolId, bo.getSchoolId())
|
.ne(SgServer::getId, bo.getId()));
|
if (lanList.size() > 0) {
|
throw new ServiceException("LAN重复", HttpStatus.HTTP_PARTIAL);
|
}
|
SgServer update = BeanUtil.toBean(bo, SgServer.class);
|
validEntityBeforeSave(update);
|
return updateById(update);
|
}
|
|
/**
|
* 保存前的数据校验
|
*
|
* @param entity 实体类数据
|
*/
|
private void validEntityBeforeSave(SgServer entity) {
|
//TODO 做一些数据校验,如唯一约束
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
if (isValid) {
|
//TODO 做一些业务上的校验,判断是否需要校验
|
}
|
return removeByIds(ids);
|
}
|
}
|