forked from dyf/fys-Multi-tenant
设备行为
This commit is contained in:
@ -1,11 +1,16 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -19,6 +24,7 @@ import com.fuyuanshen.equipment.service.IDeviceLogService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 设备日志Service业务层处理
|
||||
@ -33,6 +39,9 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
|
||||
private final DeviceLogMapper baseMapper;
|
||||
|
||||
private final DeviceAssignmentsMapper deviceAssignmentsMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备日志
|
||||
*
|
||||
@ -40,7 +49,7 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
* @return 设备日志
|
||||
*/
|
||||
@Override
|
||||
public DeviceLogVo queryById(Long id){
|
||||
public DeviceLogVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
@ -53,6 +62,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<DeviceLogVo> queryPageList(DeviceLogBo bo, PageQuery pageQuery) {
|
||||
|
||||
|
||||
LambdaQueryWrapper<DeviceLog> lqw = buildQueryWrapper(bo);
|
||||
Page<DeviceLogVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
@ -71,6 +82,15 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DeviceLog> buildQueryWrapper(DeviceLogBo bo) {
|
||||
|
||||
Long userId = LoginHelper.getUserId();
|
||||
List<DeviceAssignments> assignments = deviceAssignmentsMapper.selectList(new QueryWrapper<DeviceAssignments>().eq("assignee_id", userId));
|
||||
List<Long> deviceIds = assignments.stream().map(DeviceAssignments::getDeviceId).collect(Collectors.toList());
|
||||
if (deviceIds.isEmpty()) {
|
||||
deviceIds.add(-1L);
|
||||
}
|
||||
bo.setDeviceIds(deviceIds);
|
||||
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<DeviceLog> lqw = Wrappers.lambdaQuery();
|
||||
lqw.orderByDesc(DeviceLog::getCreateTime);
|
||||
@ -78,6 +98,7 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), DeviceLog::getDeviceName, bo.getDeviceName());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getDataSource()), DeviceLog::getDataSource, bo.getDataSource());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getContent()), DeviceLog::getContent, bo.getContent());
|
||||
lqw.in(CollectionUtil.isNotEmpty(bo.getDeviceIds()), DeviceLog::getDeviceId, bo.getDeviceIds());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@ -115,8 +136,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(DeviceLog entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
private void validEntityBeforeSave(DeviceLog entity) {
|
||||
// TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,8 +149,8 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
if (isValid) {
|
||||
// TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user