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