feat: 更改添加设备逻辑,根据用户ID获取团队
This commit is contained in:
parent
bf973f3d28
commit
ed0cc26eee
@ -43,9 +43,10 @@ public class DeviceController {
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('DEVICE_ADMIN')")
|
||||
@PostMapping
|
||||
public ResponseResult<?> addDevice(@RequestBody Device device) {
|
||||
deviceService.addDevice(device);
|
||||
@PostMapping("/{userId}")
|
||||
public ResponseResult<Device> addDevice(@PathVariable("userId") Long userId,
|
||||
@RequestBody Device device) {
|
||||
deviceService.addDevice(userId, device);
|
||||
return ResponseResult.success(device);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package github.benjamin.equipreservebackend.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -9,6 +11,7 @@ import java.time.LocalDateTime;
|
||||
@TableName("devices")
|
||||
public class Device {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
private String name;
|
||||
private String usageRequirement;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package github.benjamin.equipreservebackend.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import github.benjamin.equipreservebackend.entity.Device;
|
||||
import github.benjamin.equipreservebackend.vo.DeviceAdminVO;
|
||||
@ -12,7 +11,7 @@ import java.io.IOException;
|
||||
public interface DeviceService {
|
||||
Page<DeviceUserVO> getUserDevices(Page<Device> pageRequest, String name);
|
||||
|
||||
void addDevice(Device device);
|
||||
void addDevice(Long userId, Device device);
|
||||
|
||||
void deleteDevice(Long id);
|
||||
|
||||
|
@ -69,7 +69,10 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(Device device) {
|
||||
public void addDevice(Long userId, Device device) {
|
||||
User user = userMapper.selectById(userId);
|
||||
device.setDeviceAdminId(userId);
|
||||
device.setTeamId(user.getTeamId());
|
||||
deviceMapper.insert(device);
|
||||
}
|
||||
|
||||
@ -100,7 +103,7 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
|
||||
@Override
|
||||
public String saveImage(Long id, MultipartFile image) throws IOException {
|
||||
Device device = deviceMapper.selectOne(new LambdaQueryWrapper<Device>().eq(Device::getId, id));
|
||||
Device device = deviceMapper.selectById(id);
|
||||
String basePath = System.getProperty("user.dir");
|
||||
if (StringUtils.hasText(device.getImagePath())) {
|
||||
Path fullPath = Paths.get(basePath, device.getImagePath()).normalize();
|
||||
|
@ -6,6 +6,10 @@ spring:
|
||||
username: your-username
|
||||
password: your-password
|
||||
url: jdbc:mysql://127.0.0.1:3306/equip_reserve?serverTimeZone=UTC
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 15MB
|
||||
max-request-size: 25MB
|
||||
server:
|
||||
port: 8080
|
||||
jwt:
|
||||
|
Loading…
x
Reference in New Issue
Block a user