diff --git a/web/web-admin/src/main/java/com/atjy/web/admin/controller/login/LoginController.java b/web/web-admin/src/main/java/com/atjy/web/admin/controller/login/LoginController.java index 4084639..6318c2c 100644 --- a/web/web-admin/src/main/java/com/atjy/web/admin/controller/login/LoginController.java +++ b/web/web-admin/src/main/java/com/atjy/web/admin/controller/login/LoginController.java @@ -36,9 +36,9 @@ public class LoginController { } @Operation(summary = "获取登陆用户个人信息") - @GetMapping("info") - public Result info() { - SystemUserInfoVo userInfo = service.getLoginUserInfo(LoginUserHolder.getLoginUser().getUserId()); + @PostMapping("info") + public Result info(@RequestParam String name) { + SystemUserInfoVo userInfo = service.getLoginUserInfo(name); return Result.ok(userInfo); } } \ No newline at end of file diff --git a/web/web-admin/src/main/java/com/atjy/web/admin/service/LoginService.java b/web/web-admin/src/main/java/com/atjy/web/admin/service/LoginService.java index b3a0779..a50838b 100644 --- a/web/web-admin/src/main/java/com/atjy/web/admin/service/LoginService.java +++ b/web/web-admin/src/main/java/com/atjy/web/admin/service/LoginService.java @@ -10,5 +10,5 @@ public interface LoginService { CaptchaVo getCaptcha(); - SystemUserInfoVo getLoginUserInfo(Long userId); + SystemUserInfoVo getLoginUserInfo(String name); } \ No newline at end of file diff --git a/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/DoctorInfoServiceImpl.java b/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/DoctorInfoServiceImpl.java index 03377bf..34fb8e4 100644 --- a/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/DoctorInfoServiceImpl.java +++ b/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/DoctorInfoServiceImpl.java @@ -105,13 +105,13 @@ public class DoctorInfoServiceImpl extends ServiceImpl ids) { for (Long id : ids) { - if (doctorAppointmentMapper.selectList(new LambdaQueryWrapper().eq(DoctorAppointment::getDoctorId, id)) != null) { + if (!doctorAppointmentMapper.selectList(new LambdaQueryWrapper().eq(DoctorAppointment::getDoctorId, id)).isEmpty()) { throw new HassleFreeException(ResultCodeEnum.DELETE_ERROR); } - if (articleInfoMapper.selectList(new LambdaQueryWrapper().eq(ArticleInfo::getDoctorId, id)) != null) { + if (!articleInfoMapper.selectList(new LambdaQueryWrapper().eq(ArticleInfo::getDoctorId, id)).isEmpty()) { throw new HassleFreeException(ResultCodeEnum.DELETE_ERROR); } - if (userAppointmentMapper.selectList(new LambdaQueryWrapper().eq(UserAppointment::getDoctorId, id)) != null) { + if (!userAppointmentMapper.selectList(new LambdaQueryWrapper().eq(UserAppointment::getDoctorId, id)).isEmpty()) { throw new HassleFreeException(ResultCodeEnum.DELETE_ERROR); } } diff --git a/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/LoginServiceImpl.java b/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/LoginServiceImpl.java index f0cc3fb..7fd4f5b 100644 --- a/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/LoginServiceImpl.java +++ b/web/web-admin/src/main/java/com/atjy/web/admin/service/impl/LoginServiceImpl.java @@ -92,13 +92,13 @@ public class LoginServiceImpl implements LoginService { } @Override - public SystemUserInfoVo getLoginUserInfo(Long userId) { - SystemUser systemUser = systemUserMapper.selectById(userId); + public SystemUserInfoVo getLoginUserInfo(String name) { + SystemUser systemUser = systemUserMapper.selectOne(new LambdaQueryWrapper().eq(SystemUser::getUsername, name)); SystemUserInfoVo systemUserInfoVo = new SystemUserInfoVo(); systemUserInfoVo.setName(systemUser.getName()); systemUserInfoVo.setAvatarUrl(graphInfoMapper.selectOne(new LambdaQueryWrapper() .eq(GraphInfo::getItemType, GraphItemType.ADMIN) - .eq(GraphInfo::getItemId, userId)) + .eq(GraphInfo::getItemId, systemUser.getId())) .getUrl()); return systemUserInfoVo; } diff --git a/web/web-app/src/main/java/com/atjy/web/app/WebAppApplication.java b/web/web-app/src/main/java/com/atjy/web/app/WebAppApplication.java index 7ede7a7..ac06e5e 100644 --- a/web/web-app/src/main/java/com/atjy/web/app/WebAppApplication.java +++ b/web/web-app/src/main/java/com/atjy/web/app/WebAppApplication.java @@ -1,14 +1,15 @@ package com.atjy.web.app; - import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; @MapperScan("com.atjy.web.app.mapper") @SpringBootApplication @EnableAsync +@EnableScheduling public class WebAppApplication { public static void main(String[] args) { diff --git a/web/web-app/src/main/java/com/atjy/web/app/controller/file/FileController.java b/web/web-app/src/main/java/com/atjy/web/app/controller/file/FileController.java new file mode 100644 index 0000000..54ca009 --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/controller/file/FileController.java @@ -0,0 +1,33 @@ +package com.atjy.web.app.controller.file; + +import com.atjy.common.result.Result; +import com.atjy.web.app.service.FileService; +import com.atjy.web.app.vo.file.FileVo; +import io.minio.errors.*; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +@Tag(name = "文件管理") +@RequestMapping("/app/file") +@RestController +public class FileController { + + @Autowired + private FileService service; + + @Operation(summary = "上传文件") + @PostMapping("upload") + public Result upload(@RequestParam MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException { + return Result.ok(service.upload(file)); + } +} diff --git a/web/web-app/src/main/java/com/atjy/web/app/controller/myself/UserInfo.java b/web/web-app/src/main/java/com/atjy/web/app/controller/myself/UserInfo.java new file mode 100644 index 0000000..b922c8f --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/controller/myself/UserInfo.java @@ -0,0 +1,25 @@ +package com.atjy.web.app.controller.myself; + +import com.atjy.common.result.Result; +import com.atjy.web.app.service.UserService; +import com.atjy.web.app.vo.user.UserVo; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "用户信息") +@RestController +@RequestMapping("/app/center/user") +public class UserInfo { + + @Autowired + private UserService service; + + @Operation(summary = "修改用户信息") + @PostMapping("updateUserInfo") + public Result updateUserInfo(@RequestBody UserVo userVo) { + service.updateUserInfo(userVo); + return Result.ok(); + } +} diff --git a/web/web-app/src/main/java/com/atjy/web/app/custom/config/Knife4jConfiguration.java b/web/web-app/src/main/java/com/atjy/web/app/custom/config/Knife4jConfiguration.java index c62bbc9..06895fd 100644 --- a/web/web-app/src/main/java/com/atjy/web/app/custom/config/Knife4jConfiguration.java +++ b/web/web-app/src/main/java/com/atjy/web/app/custom/config/Knife4jConfiguration.java @@ -78,4 +78,11 @@ public class Knife4jConfiguration { pathsToMatch("/app/appointment/**"). build(); } + + @Bean + public GroupedOpenApi fileAPI() { + return GroupedOpenApi.builder().group("文件信息"). + pathsToMatch("/app/file/**"). + build(); + } } diff --git a/web/web-app/src/main/java/com/atjy/web/app/custom/config/MinioConfiguration.java b/web/web-app/src/main/java/com/atjy/web/app/custom/config/MinioConfiguration.java new file mode 100644 index 0000000..9be06b9 --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/custom/config/MinioConfiguration.java @@ -0,0 +1,26 @@ +package com.atjy.web.app.custom.config; + +import com.atjy.common.minio.MinioProperties; +import io.minio.MinioClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(MinioProperties.class) +@ConditionalOnProperty(name = "minio.endpoint") +public class MinioConfiguration { + + @Autowired + private MinioProperties properties; + + @Bean + public MinioClient minioClient(){ + return MinioClient.builder() + .endpoint(properties.getEndpoint()) + .credentials(properties.getAccessKey(),properties.getSecretKey()) + .build(); + } +} \ No newline at end of file diff --git a/web/web-app/src/main/java/com/atjy/web/app/custom/config/WebMvcConfiguration.java b/web/web-app/src/main/java/com/atjy/web/app/custom/config/WebMvcConfiguration.java index a22f98c..c8b4c43 100644 --- a/web/web-app/src/main/java/com/atjy/web/app/custom/config/WebMvcConfiguration.java +++ b/web/web-app/src/main/java/com/atjy/web/app/custom/config/WebMvcConfiguration.java @@ -1,17 +1,28 @@ package com.atjy.web.app.custom.config; +import com.atjy.web.app.custom.converter.StringToBaseEnumConverterFactory; import com.atjy.web.app.custom.interceptor.AuthenticationInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebMvcConfiguration implements WebMvcConfigurer { + @Autowired + private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory; + @Autowired private AuthenticationInterceptor authenticationInterceptor; + @Override + public void addFormatters(FormatterRegistry registry) { + + registry.addConverterFactory(this.stringToBaseEnumConverterFactory); + } + @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(this.authenticationInterceptor) diff --git a/web/web-app/src/main/java/com/atjy/web/app/custom/converter/StringToBaseEnumConverterFactory.java b/web/web-app/src/main/java/com/atjy/web/app/custom/converter/StringToBaseEnumConverterFactory.java new file mode 100644 index 0000000..aa06e45 --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/custom/converter/StringToBaseEnumConverterFactory.java @@ -0,0 +1,25 @@ +package com.atjy.web.app.custom.converter; + +import com.atjy.model.enums.BaseEnum; +import org.springframework.core.convert.converter.Converter; +import org.springframework.core.convert.converter.ConverterFactory; +import org.springframework.stereotype.Component; + +@Component +public class StringToBaseEnumConverterFactory implements ConverterFactory { + @Override + public Converter getConverter(Class targetType) { + return new Converter() { + @Override + public T convert(String code) { + T[] enumConstants = targetType.getEnumConstants(); + for (T enumConstant : enumConstants) { + if (enumConstant.getCode().equals(Integer.valueOf(code))) { + return enumConstant; + } + } + throw new IllegalArgumentException("code" + code + "非法"); + } + }; + } +} \ No newline at end of file diff --git a/web/web-app/src/main/java/com/atjy/web/app/service/FileService.java b/web/web-app/src/main/java/com/atjy/web/app/service/FileService.java new file mode 100644 index 0000000..a130404 --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/service/FileService.java @@ -0,0 +1,14 @@ +package com.atjy.web.app.service; + +import com.atjy.web.app.vo.file.FileVo; +import io.minio.errors.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +public interface FileService { + + FileVo upload(MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException; +} \ No newline at end of file diff --git a/web/web-app/src/main/java/com/atjy/web/app/service/UserService.java b/web/web-app/src/main/java/com/atjy/web/app/service/UserService.java index f0df006..c687a2c 100644 --- a/web/web-app/src/main/java/com/atjy/web/app/service/UserService.java +++ b/web/web-app/src/main/java/com/atjy/web/app/service/UserService.java @@ -1,7 +1,9 @@ package com.atjy.web.app.service; import com.atjy.model.entity.UserInfo; +import com.atjy.web.app.vo.user.UserVo; import com.baomidou.mybatisplus.extension.service.IService; public interface UserService extends IService { + void updateUserInfo(UserVo userVo); } \ No newline at end of file diff --git a/web/web-app/src/main/java/com/atjy/web/app/service/impl/FileServiceImpl.java b/web/web-app/src/main/java/com/atjy/web/app/service/impl/FileServiceImpl.java new file mode 100644 index 0000000..c08790e --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/service/impl/FileServiceImpl.java @@ -0,0 +1,75 @@ +package com.atjy.web.app.service.impl; + +import com.atjy.common.minio.MinioProperties; +import com.atjy.web.app.service.FileService; +import com.atjy.web.app.vo.file.FileVo; +import io.minio.*; +import io.minio.errors.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.ErrorResponseException; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +@Service +public class FileServiceImpl implements FileService { + + @Autowired + private MinioClient minioClient; + + @Autowired + private MinioProperties properties; + + @Override + public FileVo upload(MultipartFile file) throws InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, ServerException, io.minio.errors.ErrorResponseException { + + boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(properties.getBucketName()).build()); + if (!bucketExists) { + minioClient.makeBucket( + MakeBucketArgs.builder() + .bucket(properties.getBucketName()) + .build()); + minioClient.setBucketPolicy( + SetBucketPolicyArgs.builder() + .bucket(properties.getBucketName()) + .config(createBucketPolicyConfig(properties.getBucketName())) + .build()); + } + String filename = new SimpleDateFormat("yyyyMMdd").format(new Date()) + + "/" + UUID.randomUUID() + "-" + file.getOriginalFilename(); + minioClient.putObject( + PutObjectArgs.builder() + .bucket(properties.getBucketName()) + .stream(file.getInputStream(), file.getSize(), -1) + .object(filename) + .contentType(file.getContentType()) + .build()); + + FileVo result = new FileVo(); + result.setUrl(String.join("/", properties.getEndpoint(), properties.getBucketName(), filename)); + result.setName(file.getOriginalFilename()); + + return result; + } + + private String createBucketPolicyConfig(String bucketName) { + + return """ + { + "Statement" : [ { + "Action" : "s3:GetObject", + "Effect" : "Allow", + "Principal" : "*", + "Resource" : "arn:aws:s3:::%s/*" + } ], + "Version" : "2012-10-17" + } + """.formatted(bucketName); + } +} diff --git a/web/web-app/src/main/java/com/atjy/web/app/service/impl/UserServiceImpl.java b/web/web-app/src/main/java/com/atjy/web/app/service/impl/UserServiceImpl.java index 2ec0996..46ad178 100644 --- a/web/web-app/src/main/java/com/atjy/web/app/service/impl/UserServiceImpl.java +++ b/web/web-app/src/main/java/com/atjy/web/app/service/impl/UserServiceImpl.java @@ -1,12 +1,46 @@ package com.atjy.web.app.service.impl; +import com.atjy.common.login.LoginUserHolder; +import com.atjy.model.entity.GraphInfo; import com.atjy.model.entity.UserInfo; +import com.atjy.model.enums.GraphItemType; +import com.atjy.web.app.mapper.GraphInfoMapper; import com.atjy.web.app.mapper.UserMapper; import com.atjy.web.app.service.UserService; +import com.atjy.web.app.vo.user.UserVo; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + @Service public class UserServiceImpl extends ServiceImpl implements UserService { + @Autowired + private UserMapper userMapper; + + @Autowired + private GraphInfoMapper graphInfoMapper; + + @Override + public void updateUserInfo(UserVo userVo) { + if (userVo.getUrlName() != null && !userVo.getUrlName().equals("")) { + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("item_type", GraphItemType.USER) + .eq("item_id", LoginUserHolder.getLoginUser().getUserId()) + .set("url", userVo.getAvatarUrl()) + .set("name", userVo.getUrlName()); + + graphInfoMapper.update(updateWrapper); + } + + if (userVo.getNickname() != null && !userVo.getNickname().equals("")) { + UpdateWrapper userInfoUpdateWrapper = new UpdateWrapper<>(); + userInfoUpdateWrapper.eq("id", LoginUserHolder.getLoginUser().getUserId()) + .set("nickname", userVo.getNickname()); + + userMapper.update(userInfoUpdateWrapper); + } + } } diff --git a/web/web-app/src/main/java/com/atjy/web/app/vo/file/FileVo.java b/web/web-app/src/main/java/com/atjy/web/app/vo/file/FileVo.java new file mode 100644 index 0000000..d55ecb1 --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/vo/file/FileVo.java @@ -0,0 +1,18 @@ +package com.atjy.web.app.vo.file; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "文件实体") +public class FileVo { + + @Schema(description = "图片id") + private Long urlId; + + @Schema(description = "图片url") + private String url; + + @Schema(description = "图片名称") + private String name; +} diff --git a/web/web-app/src/main/java/com/atjy/web/app/vo/user/UserVo.java b/web/web-app/src/main/java/com/atjy/web/app/vo/user/UserVo.java new file mode 100644 index 0000000..92797a2 --- /dev/null +++ b/web/web-app/src/main/java/com/atjy/web/app/vo/user/UserVo.java @@ -0,0 +1,18 @@ +package com.atjy.web.app.vo.user; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户信息") +@Data +public class UserVo { + + @Schema(description = "用户昵称") + private String nickname; + + @Schema(description = "头像") + private String avatarUrl; + + @Schema(description = "头像名称") + private String urlName; +} diff --git a/web/web-app/src/main/resources/application.yml b/web/web-app/src/main/resources/application.yml index 5fccd97..d1c6739 100644 --- a/web/web-app/src/main/resources/application.yml +++ b/web/web-app/src/main/resources/application.yml @@ -27,6 +27,13 @@ spring: port: 6379 database: 0 + servlet: + multipart: + # 单个文件最大大小 + max-file-size: 50MB + # 所有上传文件最大大小 + max-request-size: 50MB + mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl @@ -40,3 +47,8 @@ aliyun: access-key-secret: uuy4Fe0zGoF5WsBod4IEwrB1O7vR6d endpoint: dysmsapi.aliyuncs.com +minio: + endpoint: http://192.168.47.101:9000 + access-key: minioadmin + secret-key: minioadmin + bucket-name: hassle-free