mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-03-14 05:33:42 +08:00
init minio
This commit is contained in:
@@ -36,16 +36,9 @@ public class UserRolePermissionOperatorTool {
|
||||
if (user != null) {
|
||||
throw new BusinessException("用户已存在");
|
||||
}
|
||||
identityAccessService.upsertUser(new UserUpsertDto(null, name, name, true));
|
||||
identityAccessService.upsertUser(new UserUpsertDto(null, name, name, true, null));
|
||||
}
|
||||
|
||||
// @Tool(value = "查询用户")
|
||||
// List<User> queryUser(@P(value = "用户名",required = false) String username, @P(value =
|
||||
// "开始日期",required = false) LocalDateTime startDate, @P(value = "结束日期",required = false)
|
||||
// LocalDateTime endDate) {
|
||||
// return userRepository.fetchBy(new UserQueryDto(username, startDate, endDate));
|
||||
// }
|
||||
|
||||
@Tool(value = "删除用户")
|
||||
void deleteUser(@P(value = "用户名") String username) {
|
||||
userRepository.deleteByUsername(username);
|
||||
@@ -56,7 +49,7 @@ public class UserRolePermissionOperatorTool {
|
||||
@P(value = "用户名") String name,
|
||||
@P(value = "密码", required = false) String password,
|
||||
@P(value = "是否开启", required = false) Boolean enable) {
|
||||
identityAccessService.upsertUser(new UserUpsertDto(null, name, password, enable));
|
||||
identityAccessService.upsertUser(new UserUpsertDto(null, name, password, enable, null));
|
||||
}
|
||||
|
||||
@Tool(value = {"给用户绑定角色", "给用户分配角色"})
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.zl.mjga.config.minio;
|
||||
|
||||
import io.minio.MinioClient;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Setter
|
||||
@Getter
|
||||
@ConfigurationProperties(prefix = "minio")
|
||||
@Slf4j
|
||||
public class MinIoConfig {
|
||||
private String endpoint;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
private String defaultBucket;
|
||||
|
||||
@Bean
|
||||
public MinioClient minioClient() {
|
||||
return MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zl.mjga.controller;
|
||||
|
||||
import com.zl.mjga.config.minio.MinIoConfig;
|
||||
import com.zl.mjga.dto.PageRequestDto;
|
||||
import com.zl.mjga.dto.PageResponseDto;
|
||||
import com.zl.mjga.dto.department.DepartmentBindDto;
|
||||
@@ -12,17 +13,23 @@ import com.zl.mjga.repository.PermissionRepository;
|
||||
import com.zl.mjga.repository.RoleRepository;
|
||||
import com.zl.mjga.repository.UserRepository;
|
||||
import com.zl.mjga.service.IdentityAccessService;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.PutObjectArgs;
|
||||
import io.minio.errors.*;
|
||||
import jakarta.validation.Valid;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jooq.generated.mjga.tables.pojos.User;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.authentication.DisabledException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
@RestController
|
||||
@RequestMapping("/iam")
|
||||
@RequiredArgsConstructor
|
||||
@@ -32,6 +39,34 @@ public class IdentityAccessController {
|
||||
private final UserRepository userRepository;
|
||||
private final RoleRepository roleRepository;
|
||||
private final PermissionRepository permissionRepository;
|
||||
private final MinioClient minioClient;
|
||||
private final MinIoConfig minIoConfig;
|
||||
|
||||
@PostMapping(
|
||||
value = "/avatar/upload",
|
||||
consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
|
||||
produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String uploadAvatar(Principal principal, @RequestPart("file") MultipartFile multipartFile)
|
||||
throws Exception {
|
||||
String objectName = String.format("avatar/%s/avatar.jpg", principal.getName());
|
||||
if (multipartFile.isEmpty()) {
|
||||
throw new BusinessException("上传的文件不能为空");
|
||||
}
|
||||
long size = multipartFile.getSize();
|
||||
if (size > 200 * 1024) {
|
||||
throw new BusinessException("头像文件大小不能超过200KB");
|
||||
}
|
||||
BufferedImage img = ImageIO.read(multipartFile.getInputStream());
|
||||
if (img == null) {
|
||||
throw new BusinessException("非法的上传文件");
|
||||
}
|
||||
minioClient.putObject(
|
||||
PutObjectArgs.builder().bucket(minIoConfig.getDefaultBucket()).object(objectName).stream(
|
||||
multipartFile.getInputStream(), size, -1)
|
||||
.contentType(multipartFile.getContentType())
|
||||
.build());
|
||||
return objectName;
|
||||
}
|
||||
|
||||
@GetMapping("/me")
|
||||
UserRolePermissionDto currentUser(Principal principal) {
|
||||
|
||||
@@ -19,6 +19,8 @@ public class UserRolePermissionDto {
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
private String password;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private Boolean enable;
|
||||
@Builder.Default private List<RoleDto> roles = new LinkedList<>();
|
||||
|
||||
|
||||
@@ -14,4 +14,5 @@ public class UserUpsertDto {
|
||||
@NotEmpty private String username;
|
||||
private String password;
|
||||
@NotNull private Boolean enable;
|
||||
private String avatar;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class UserRepository extends UserDao {
|
||||
value(user.getId()).as("id"),
|
||||
value(user.getUsername()).as("username"),
|
||||
value(user.getPassword()).as("password"),
|
||||
value(user.getAvatar()).as("avatar"),
|
||||
value(user.getEnable()).as("enable"))
|
||||
.asTable("newUser"))
|
||||
.on(USER.ID.eq(DSL.field(DSL.name("newUser", "id"), Long.class)))
|
||||
@@ -46,11 +47,13 @@ public class UserRepository extends UserDao {
|
||||
StringUtils.isNotEmpty(user.getPassword())
|
||||
? DSL.field(DSL.name("newUser", "password"), String.class)
|
||||
: USER.PASSWORD)
|
||||
.set(USER.AVATAR, DSL.field(DSL.name("newUser", "avatar"), String.class))
|
||||
.set(USER.ENABLE, DSL.field(DSL.name("newUser", "enable"), Boolean.class))
|
||||
.whenNotMatchedThenInsert(USER.USERNAME, USER.PASSWORD, USER.ENABLE)
|
||||
.whenNotMatchedThenInsert(USER.USERNAME, USER.PASSWORD, USER.AVATAR, USER.ENABLE)
|
||||
.values(
|
||||
DSL.field(DSL.name("newUser", "username"), String.class),
|
||||
DSL.field(DSL.name("newUser", "password"), String.class),
|
||||
DSL.field(DSL.name("newUser", "avatar"), String.class),
|
||||
DSL.field(DSL.name("newUser", "enable"), Boolean.class))
|
||||
.execute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user