forked from dyf/fys-Multi-tenant
设备类型管理
This commit is contained in:
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
|
||||
import java.util.List;
|
||||
@ -51,7 +52,7 @@ public interface DeviceTypeService extends IService<DeviceType> {
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void update(DeviceType resources);
|
||||
void update(DeviceTypeForm resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
@ -60,4 +61,11 @@ public interface DeviceTypeService extends IService<DeviceType> {
|
||||
*/
|
||||
void deleteAll(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获取设备类型通讯方式
|
||||
*
|
||||
* @param id /
|
||||
* @return DeviceTypeDto
|
||||
*/
|
||||
DeviceType getCommunicationMode(Long id);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.core.utils.PageUtil;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.constants.DeviceConstants;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
@ -56,6 +57,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
@Override
|
||||
public PageResult<Device> queryAll(DeviceQueryCriteria criteria, Page<Object> page) throws IOException {
|
||||
|
||||
criteria.setCustomerId(LoginHelper.getUserId());
|
||||
IPage<Device> devices = deviceMapper.findAll(criteria, page);
|
||||
|
||||
List<Device> records = devices.getRecords();
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.common.core.domain.PageResult;
|
||||
import com.fuyuanshen.common.core.utils.PageUtil;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
@ -14,7 +16,9 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -38,6 +42,7 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
*/
|
||||
@Override
|
||||
public PageResult<DeviceType> queryAll(DeviceTypeQueryCriteria criteria, Page<Object> page) {
|
||||
criteria.setCustomerId(LoginHelper.getUserId());
|
||||
return PageUtil.toPage(deviceTypeMapper.findAll(criteria, page));
|
||||
}
|
||||
|
||||
@ -84,8 +89,18 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(DeviceType resources) {
|
||||
deviceTypeMapper.updateById(resources);
|
||||
public void update(DeviceTypeForm resources) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(resources.getId());
|
||||
if (deviceType == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
throw new RuntimeException("无权修改该设备类型");
|
||||
}
|
||||
// if (deviceMapper.countByTypeId(resources.getId()) > 0)
|
||||
// throw new RuntimeException("该设备类型已被使用,无法删除");
|
||||
BeanUtil.copyProperties(resources, deviceType);
|
||||
deviceTypeMapper.updateById(deviceType);
|
||||
}
|
||||
|
||||
|
||||
@ -97,8 +112,41 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteAll(List<Long> ids) {
|
||||
|
||||
List<Long> invalidIds = new ArrayList<>();
|
||||
|
||||
for (Long id : ids) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
if (deviceType == null || !Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
invalidIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!invalidIds.isEmpty()) {
|
||||
throw new RuntimeException("以下设备类型无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
}
|
||||
|
||||
deviceTypeMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备类型通讯方式
|
||||
*
|
||||
* @param id /
|
||||
* @return DeviceTypeDto
|
||||
*/
|
||||
@Override
|
||||
public DeviceType getCommunicationMode(Long id) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
if (deviceType == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
throw new RuntimeException("无权获取该设备类型通讯方式");
|
||||
}
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user