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.SgIotBo;
|
import com.ruoyi.oa.domain.vo.SgIotVo;
|
import com.ruoyi.oa.domain.SgIot;
|
import com.ruoyi.oa.mapper.SgIotMapper;
|
import com.ruoyi.oa.service.ISgIotService;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Collection;
|
|
/**
|
* IoT设备Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2022-05-12
|
*/
|
@Service
|
public class SgIotServiceImpl extends ServicePlusImpl<SgIotMapper, SgIot, SgIotVo> implements ISgIotService {
|
|
@Override
|
public SgIotVo queryById(Long id) {
|
return getVoById(id);
|
}
|
|
@Override
|
public TableDataInfo<SgIotVo> queryPageList(SgIotBo bo) {
|
PagePlus<SgIot, SgIotVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
|
return PageUtils.buildDataInfo(result);
|
}
|
|
@Override
|
public List<SgIotVo> queryList(SgIotBo bo) {
|
return listVo(buildQueryWrapper(bo));
|
}
|
|
private LambdaQueryWrapper<SgIot> buildQueryWrapper(SgIotBo bo) {
|
Map<String, Object> params = bo.getParams();
|
LambdaQueryWrapper<SgIot> lqw = Wrappers.lambdaQuery();
|
lqw.like(StringUtils.isNotBlank(bo.getDeploymentName()), SgIot::getDeploymentName, bo.getDeploymentName());
|
lqw.eq(StringUtils.isNotBlank(bo.getEdition()), SgIot::getEdition, bo.getEdition());
|
lqw.eq(bo.getBuildingId() != null, SgIot::getBuildingId, bo.getBuildingId());
|
lqw.eq(bo.getOrganizationId() != null, SgIot::getOrganizationId, bo.getOrganizationId());
|
lqw.eq(bo.getConstructionBatchId() != null, SgIot::getConstructionBatchId, bo.getConstructionBatchId());
|
lqw.like(StringUtils.isNotBlank(bo.getMonitorObject()), SgIot::getMonitorObject, bo.getMonitorObject());
|
lqw.eq(SgIot::getSchoolId, bo.getSchoolId());
|
lqw.orderByDesc(SgIot::getUpdateTime);
|
if (bo.getPeripheralUnit() != null && StringUtils.isNotBlank(bo.getPassageway())) {
|
if ("1".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayOne, bo.getPeripheralUnit());
|
}
|
if ("2".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayTwo, bo.getPeripheralUnit());
|
}
|
if ("3".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayThree, bo.getPeripheralUnit());
|
}
|
if ("4".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayFour, bo.getPeripheralUnit());
|
}
|
if ("5".equals(bo.getPassageway())) {
|
lqw.and(i -> i.eq(SgIot::getPassagewayOne, bo.getPeripheralUnit())
|
.or().eq(SgIot::getPassagewayTwo, bo.getPeripheralUnit())
|
.or().eq(SgIot::getPassagewayThree, bo.getPeripheralUnit())
|
.or().eq(SgIot::getPassagewayFour, bo.getPeripheralUnit()));
|
}
|
}
|
return lqw;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean insertByBo(SgIotBo bo) {
|
List<SgIot> list = baseMapper.selectList(new LambdaQueryWrapper<SgIot>()
|
.eq(SgIot::getDeploymentName, bo.getDeploymentName())
|
.eq(SgIot::getSchoolId, bo.getSchoolId()));
|
if (list.size() > 0) {
|
throw new ServiceException("部署名称重复", HttpStatus.HTTP_PARTIAL);
|
}
|
List<SgIot> lanList = baseMapper.selectList(new LambdaQueryWrapper<SgIot>()
|
.eq(SgIot::getLan, bo.getLan())
|
.eq(SgIot::getSchoolId, bo.getSchoolId()));
|
if (lanList.size() > 0) {
|
throw new ServiceException("LAN重复", HttpStatus.HTTP_PARTIAL);
|
}
|
SgIot add = BeanUtil.toBean(bo, SgIot.class);
|
validEntityBeforeSave(add);
|
boolean flag = save(add);
|
if (flag) {
|
bo.setId(add.getId());
|
}
|
return flag;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean updateByBo(SgIotBo bo) {
|
List<SgIot> list = baseMapper.selectList(new LambdaQueryWrapper<SgIot>()
|
.eq(SgIot::getDeploymentName, bo.getDeploymentName())
|
.eq(SgIot::getSchoolId, bo.getSchoolId())
|
.ne(SgIot::getId, bo.getId()));
|
if (list.size() > 0) {
|
throw new ServiceException("部署名称重复", HttpStatus.HTTP_PARTIAL);
|
}
|
List<SgIot> lanList = baseMapper.selectList(new LambdaQueryWrapper<SgIot>()
|
.eq(SgIot::getLan, bo.getLan())
|
.eq(SgIot::getSchoolId, bo.getSchoolId())
|
.ne(SgIot::getId, bo.getId()));
|
if (lanList.size() > 0) {
|
throw new ServiceException("LAN重复", HttpStatus.HTTP_PARTIAL);
|
}
|
SgIot update = BeanUtil.toBean(bo, SgIot.class);
|
validEntityBeforeSave(update);
|
return updateById(update);
|
}
|
|
@Override
|
public int getNumber(SgIotBo bo) {
|
int sum = 0;
|
LambdaQueryWrapper<SgIot> lqw = Wrappers.lambdaQuery();
|
lqw.eq(SgIot::getSchoolId, bo.getSchoolId());
|
if (bo.getPeripheralUnit() != null && StringUtils.isNotBlank(bo.getPassageway())) {
|
if ("5".equals(bo.getPassageway())) {
|
lqw.and(i -> i.eq(SgIot::getPassagewayOne, bo.getPeripheralUnit())
|
.or().eq(SgIot::getPassagewayTwo, bo.getPeripheralUnit())
|
.or().eq(SgIot::getPassagewayThree, bo.getPeripheralUnit())
|
.or().eq(SgIot::getPassagewayFour, bo.getPeripheralUnit()));
|
List<SgIot> list = baseMapper.selectList(lqw);
|
if (list.size() > 0) {
|
for (SgIot s : list) {
|
if (s.getPassagewayOne() != null && s.getPassagewayOne().equals(bo.getPeripheralUnit())) {
|
sum = sum + 1;
|
}
|
if (s.getPassagewayTwo() != null && s.getPassagewayTwo().equals(bo.getPeripheralUnit())) {
|
sum = sum + 1;
|
}
|
if (s.getPassagewayThree() != null && s.getPassagewayThree().equals(bo.getPeripheralUnit())) {
|
sum = sum + 1;
|
}
|
if (s.getPassagewayFour() != null && s.getPassagewayFour().equals(bo.getPeripheralUnit())) {
|
sum = sum + 1;
|
}
|
}
|
} else {
|
sum = 0;
|
}
|
} else {
|
if ("1".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayOne, bo.getPeripheralUnit());
|
}
|
if ("2".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayTwo, bo.getPeripheralUnit());
|
}
|
if ("3".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayThree, bo.getPeripheralUnit());
|
}
|
if ("4".equals(bo.getPassageway())) {
|
lqw.eq(SgIot::getPassagewayFour, bo.getPeripheralUnit());
|
}
|
List<SgIot> list = baseMapper.selectList(lqw);
|
sum = list.size();
|
}
|
}
|
return sum;
|
}
|
|
/**
|
* 保存前的数据校验
|
*
|
* @param entity 实体类数据
|
*/
|
private void validEntityBeforeSave(SgIot entity) {
|
//TODO 做一些数据校验,如唯一约束
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
if (isValid) {
|
//TODO 做一些业务上的校验,判断是否需要校验
|
}
|
return removeByIds(ids);
|
}
|
}
|