优化设备权限的写法
This commit is contained in:
parent
023215ff3f
commit
41c4d3c5ba
|
@ -2,6 +2,7 @@ package com.ruoyi.bst.device.service;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
|
||||
import com.ruoyi.bst.device.domain.Device;
|
||||
import com.ruoyi.bst.device.domain.DeviceQuery;
|
||||
import com.ruoyi.bst.device.domain.DeviceVO;
|
||||
|
@ -35,6 +36,9 @@ public interface DeviceService
|
|||
*/
|
||||
public List<DeviceVO> selectDeviceList(DeviceQuery device);
|
||||
|
||||
List<DeviceVO> selectDeviceByIds(List<Long> ids, boolean scope, AreaJoinPermission permission);
|
||||
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
|
@ -210,5 +214,13 @@ public interface DeviceService
|
|||
*/
|
||||
public int updateByQuery(Device data, DeviceQuery query);
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备
|
||||
* @param id
|
||||
* @param sn
|
||||
* @param scope
|
||||
* @param permission
|
||||
* @return
|
||||
*/
|
||||
DeviceVO selectDevice(Long id, String sn, boolean scope, AreaJoinPermission permission);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,6 @@ public class DeviceServiceImpl implements DeviceService
|
|||
@Override
|
||||
public DeviceVO selectOne(DeviceQuery query) {
|
||||
PageHelper.startPage(1, 1);
|
||||
query.addAreaPermission(AreaJoinPermission.DEVICE_VIEW.getCode());
|
||||
List<DeviceVO> list = this.selectDeviceList(query);
|
||||
return CollectionUtils.firstElement(list);
|
||||
}
|
||||
|
@ -96,10 +95,21 @@ public class DeviceServiceImpl implements DeviceService
|
|||
@Override
|
||||
public List<DeviceVO> selectDeviceList(DeviceQuery query)
|
||||
{
|
||||
query.addAreaPermission(AreaJoinPermission.DEVICE_VIEW.getCode());
|
||||
return deviceMapper.selectDeviceList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceVO> selectDeviceByIds(List<Long> ids, boolean scope, AreaJoinPermission permission) {
|
||||
if (CollectionUtils.isEmptyElement(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setScope(scope);
|
||||
query.setIds(ids);
|
||||
query.addAreaPermission(permission.getCode());
|
||||
return this.selectDeviceList(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行带有SN和MAC锁的设备操作
|
||||
* @param device 设备信息
|
||||
|
@ -421,6 +431,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
DeviceQuery query = new DeviceQuery();
|
||||
query.setEqSn(sn);
|
||||
query.setScope(scope);
|
||||
query.addAreaPermission(AreaJoinPermission.DEVICE_VIEW.getCode());
|
||||
return this.selectOne(query);
|
||||
}
|
||||
|
||||
|
@ -585,5 +596,19 @@ public class DeviceServiceImpl implements DeviceService
|
|||
return deviceMapper.updateByQuery(data, query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceVO selectDevice(Long id, String sn, boolean scope, AreaJoinPermission permission) {
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
if (id != null) {
|
||||
query.setId(id);
|
||||
} else if (sn != null) {
|
||||
query.setSn(sn);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
query.addAreaPermission(permission.getCode());
|
||||
return this.selectOne(query);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.ruoyi.bst.device.utils.DeviceUtil;
|
||||
import com.ruoyi.bst.orderDevice.domain.enums.OrderDeviceStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -192,7 +193,7 @@ public class OrderValidatorImpl implements OrderValidator{
|
|||
ServiceUtil.assertion(device == null || device.getId() == null, "车辆不存在");
|
||||
ServiceUtil.assertion(!DeviceStatus.canUse().contains(device.getStatus()), "ID为%s的车辆当前状态不可使用", device.getId());
|
||||
ServiceUtil.assertion(MathUtils.smallerThan(device.getRemainingPower(), device.getAreaUndercharge()), "ID为%s的车辆电量不足%s%%,暂时无法使用", device.getId(), device.getAreaUndercharge());
|
||||
ServiceUtil.assertion(OrderDeviceStatus.inUse().contains(device.getOrderDeviceStatus()), "ID为%s的车辆当前有正在进行的订单,无法使用", device.getId());
|
||||
ServiceUtil.assertion(DeviceUtil.isOrderUsing(device), "ID为%s的车辆当前有正在进行的订单,无法使用", device.getId());
|
||||
ServiceUtil.assertion(device.getAreaId() == null, "当前车辆未绑定运营区,无法使用");
|
||||
ServiceUtil.assertion(AreaStatus.DISABLED.getCode().equals(device.getAreaStatus()), "运营区“%s”已停运,无法使用该车辆", device.getAreaName());
|
||||
ServiceUtil.assertion(!DateUtils.isBetween(LocalTime.now(), device.getAreaTimeStart(), device.getAreaTimeEnd()), "运营区“%s”当前不在营业时间,无法使用该车辆", device.getAreaName());
|
||||
|
|
|
@ -233,7 +233,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
boolean isDispatching = DeviceStatus.DISPATCHING.getCode().equals(device.getStatus()); // 是否调度中
|
||||
|
||||
// 是否有正在使用的订单,若没有订单则不处理
|
||||
boolean hasOrder = device.getOrderDeviceId() != null && OrderDeviceStatus.USING.getCode().equals(device.getOrderDeviceStatus());
|
||||
boolean hasOrder = DeviceUtil.isOrderUsing(device);
|
||||
if (!hasOrder) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package com.ruoyi.web.bst;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -65,6 +68,7 @@ public class DeviceController extends BaseController
|
|||
@Autowired
|
||||
private DeviceIotService deviceIotService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*/
|
||||
|
@ -75,6 +79,7 @@ public class DeviceController extends BaseController
|
|||
startPage();
|
||||
startOrderBy();
|
||||
query.setScope(true);
|
||||
query.addAreaPermission(AreaJoinPermission.DEVICE_VIEW.getCode());
|
||||
List<DeviceVO> list = deviceService.selectDeviceList(query);
|
||||
if (query.getRefresh() != null && query.getRefresh()) {
|
||||
deviceIotService.refresh(list, IotConstants.ONLINE_TYPE_COMMAND);
|
||||
|
@ -92,6 +97,7 @@ public class DeviceController extends BaseController
|
|||
return error("运营区ID不能为空");
|
||||
}
|
||||
query.setScope(true);
|
||||
query.addAreaPermission(AreaJoinPermission.DEVICE_VIEW.getCode());
|
||||
List<DeviceVO> list = deviceService.selectDeviceList(query);
|
||||
if (query.getRefresh() != null && query.getRefresh()) {
|
||||
deviceIotService.refresh(list, IotConstants.ONLINE_TYPE_COMMAND);
|
||||
|
@ -108,6 +114,7 @@ public class DeviceController extends BaseController
|
|||
public void export(HttpServletResponse response, DeviceQuery query)
|
||||
{
|
||||
query.setScope(true);
|
||||
query.addAreaPermission(AreaJoinPermission.DEVICE_VIEW.getCode());
|
||||
List<DeviceVO> list = deviceService.selectDeviceList(query);
|
||||
ExcelUtil<DeviceVO> util = new ExcelUtil<DeviceVO>(DeviceVO.class);
|
||||
util.exportExcel(response, list, "设备数据");
|
||||
|
@ -118,18 +125,11 @@ public class DeviceController extends BaseController
|
|||
*/
|
||||
@PreAuthorize("@ss.hasPermi('bst:device:query')")
|
||||
@GetMapping
|
||||
public AjaxResult getInfo(@RequestParam(required = false) Long id,
|
||||
public AjaxResult getInfo(@RequestParam(required = false) Long id,
|
||||
@RequestParam(required = false) String sn,
|
||||
@RequestParam(required = false, defaultValue = "false") Boolean refresh)
|
||||
{
|
||||
DeviceVO device = null;
|
||||
if (id != null) {
|
||||
device = deviceService.selectDeviceById(id, true);
|
||||
} else if (sn != null) {
|
||||
device = deviceService.selectDeviceBySn(sn, true);
|
||||
} else {
|
||||
return error("设备ID和SN不能同时为空");
|
||||
}
|
||||
DeviceVO device = deviceService.selectDevice(id, sn, true, AreaJoinPermission.DEVICE_VIEW);
|
||||
|
||||
if (refresh) {
|
||||
deviceIotService.refresh(device, IotConstants.ONLINE_TYPE_COMMAND);
|
||||
|
@ -198,7 +198,7 @@ public class DeviceController extends BaseController
|
|||
if (!deviceValidator.canOperate(ids)) {
|
||||
return error("您无权入仓ID为" + ids + "的设备");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.in(deviceList);
|
||||
if (count == 0) {
|
||||
return error("入仓失败");
|
||||
|
@ -216,7 +216,7 @@ public class DeviceController extends BaseController
|
|||
if (!deviceValidator.canOperate(ids)) {
|
||||
return error("您无权出仓ID为" + ids + "的设备");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.out(deviceList);
|
||||
if (count == 0) {
|
||||
return error("出仓失败");
|
||||
|
@ -234,7 +234,7 @@ public class DeviceController extends BaseController
|
|||
if (!deviceValidator.canOperate(ids)) {
|
||||
return error("您无权禁用ID为" + ids + "的设备");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.disable(deviceList);
|
||||
if (count == 0) {
|
||||
return error("禁用失败");
|
||||
|
@ -252,7 +252,7 @@ public class DeviceController extends BaseController
|
|||
if (!deviceValidator.canOperate(ids)) {
|
||||
return error("您无权启用ID为" + ids + "的设备");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.enable(deviceList);
|
||||
if (count == 0) {
|
||||
return error("启用失败");
|
||||
|
@ -273,7 +273,7 @@ public class DeviceController extends BaseController
|
|||
if (!areaValidator.canEdit(dto.getAreaId())) {
|
||||
return error("您无权将设备划拨到ID为" + dto.getAreaId() + "的运营区");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(dto.getIds(), true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(dto.getIds(), true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.transfer(deviceList, dto.getAreaId());
|
||||
if (count == 0) {
|
||||
return error("划拨失败");
|
||||
|
@ -291,7 +291,7 @@ public class DeviceController extends BaseController
|
|||
if (!deviceValidator.canOperate(ids)) {
|
||||
return error("您无权解绑ID为" + ids + "的设备");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.unbindMch(deviceList);
|
||||
if (count == 0) {
|
||||
return error("解绑失败");
|
||||
|
@ -309,7 +309,7 @@ public class DeviceController extends BaseController
|
|||
if (!deviceValidator.canOperate(ids)) {
|
||||
return error("您无权解绑ID为" + ids + "的设备");
|
||||
}
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true);
|
||||
List<DeviceVO> deviceList = deviceService.selectDeviceByIds(ids, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
int count = deviceService.unbindArea(deviceList);
|
||||
if (count == 0) {
|
||||
return error("解绑失败");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.web.bst;
|
||||
|
||||
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
@ -35,15 +36,7 @@ public class DeviceIotController extends BaseController {
|
|||
private DeviceValidator deviceValidator;
|
||||
|
||||
private DeviceVO getDevice(Long id, String sn) {
|
||||
if (id != null) {
|
||||
ServiceUtil.assertion(!deviceValidator.canOperate(id), "您无权限操作ID为%s的设备", id);
|
||||
return deviceService.selectDeviceById(id, true);
|
||||
} else if (sn != null) {
|
||||
ServiceUtil.assertion(!deviceValidator.canOperate(sn), "您无权限操作SN为%s的设备", sn);
|
||||
return deviceService.selectDeviceBySn(sn, true);
|
||||
} else {
|
||||
throw new ServiceException("SN和ID不能同时为空");
|
||||
}
|
||||
return deviceService.selectDevice(id, sn, true, AreaJoinPermission.DEVICE_EDIT);
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('bst:device:unlock')")
|
||||
|
|
Loading…
Reference in New Issue
Block a user