|
|
@@ -1,14 +1,25 @@
|
|
|
package com.coffee.bus.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.mapper.Mapper;
|
|
|
+import com.coffee.bus.controller.vo.DeviceBindVo;
|
|
|
import com.coffee.bus.entity.BusDeviceEntity;
|
|
|
+import com.coffee.bus.enums.DeviceAlarmEnum;
|
|
|
+import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
import com.coffee.bus.service.LocalBusDeviceService;
|
|
|
import com.coffee.common.crud.BaseService;
|
|
|
import com.coffee.common.crud.controller.BaseCrudController;
|
|
|
+import com.coffee.common.exception.CustomException;
|
|
|
+import com.coffee.common.result.R;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author lifang
|
|
|
@@ -22,8 +33,40 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RequestMapping("/bus/device/info")
|
|
|
@Api(tags = "设备管理",description = "统一权限前缀(device:info),device:info:add")
|
|
|
public class BusDeviceController extends BaseCrudController<BusDeviceEntity, String> {
|
|
|
- private final LocalBusDeviceService deviceRegisteredService;
|
|
|
+ private final LocalBusDeviceService deviceService;
|
|
|
+ private final DeviceRegistry deviceRegistry;
|
|
|
+
|
|
|
+ @PostMapping("/shift/bind")
|
|
|
+ @ApiOperation(value = "设备换绑",notes = "权限【device:info:shift】")
|
|
|
+ public R shift(@RequestBody DeviceBindVo vo){
|
|
|
+ if(StrUtil.isEmpty(vo.getBindTenantId())|| CollectionUtil.isEmpty(vo.getDeviceIds())){
|
|
|
+ throw new CustomException("选择的医院、设备不能为空");
|
|
|
+ }
|
|
|
+ List<String> deviceIds = vo.getDeviceIds();
|
|
|
+ deviceService.update(new UpdateWrapper<BusDeviceEntity>().lambda()
|
|
|
+ .in(BusDeviceEntity::getDeviceId,deviceIds)
|
|
|
+ .set(BusDeviceEntity::getTenantId,vo.getBindTenantId()));
|
|
|
+ deviceIds.stream()
|
|
|
+ .map(deviceRegistry::getOperator)
|
|
|
+ .forEach(deviceOperator -> deviceOperator.setTenantId(vo.getBindTenantId()));
|
|
|
+ return R.success(DeviceAlarmEnum.values());
|
|
|
+ }
|
|
|
|
|
|
+ @PostMapping("/undo/bind")
|
|
|
+ @ApiOperation(value = "设备解绑",notes = "即自动将该设备绑定到默认医院上,权限【device:info:undo】")
|
|
|
+ public R undo(@RequestBody DeviceBindVo vo){
|
|
|
+ if( CollectionUtil.isEmpty(vo.getDeviceIds())){
|
|
|
+ throw new CustomException("选择的设备不能为空");
|
|
|
+ }
|
|
|
+ List<String> deviceIds = vo.getDeviceIds();
|
|
|
+ deviceService.update(new UpdateWrapper<BusDeviceEntity>().lambda()
|
|
|
+ .in(BusDeviceEntity::getDeviceId,deviceIds)
|
|
|
+ .set(BusDeviceEntity::getTenantId,"1"));
|
|
|
+ deviceIds.stream()
|
|
|
+ .map(deviceRegistry::getOperator)
|
|
|
+ .forEach(deviceOperator -> deviceOperator.setTenantId("1"));
|
|
|
+ return R.success(DeviceAlarmEnum.values());
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 权限控制前缀
|
|
|
@@ -37,6 +80,6 @@ public class BusDeviceController extends BaseCrudController<BusDeviceEntity, Str
|
|
|
|
|
|
@Override
|
|
|
public BaseService<? extends Mapper<BusDeviceEntity>, BusDeviceEntity, String> getService() {
|
|
|
- return deviceRegisteredService;
|
|
|
+ return deviceService;
|
|
|
}
|
|
|
}
|