This commit is contained in:
BLRTTX 2024-12-24 22:54:39 +08:00
parent e9075b3938
commit 54e8ad8b45
18 changed files with 312 additions and 11 deletions

View File

@ -36,9 +36,9 @@ public class LoginController {
}
@Operation(summary = "获取登陆用户个人信息")
@GetMapping("info")
public Result<SystemUserInfoVo> info() {
SystemUserInfoVo userInfo = service.getLoginUserInfo(LoginUserHolder.getLoginUser().getUserId());
@PostMapping("info")
public Result<SystemUserInfoVo> info(@RequestParam String name) {
SystemUserInfoVo userInfo = service.getLoginUserInfo(name);
return Result.ok(userInfo);
}
}

View File

@ -10,5 +10,5 @@ public interface LoginService {
CaptchaVo getCaptcha();
SystemUserInfoVo getLoginUserInfo(Long userId);
SystemUserInfoVo getLoginUserInfo(String name);
}

View File

@ -105,13 +105,13 @@ public class DoctorInfoServiceImpl extends ServiceImpl<DoctorInfoMapper, DoctorI
@Override
public void deleteDoctor(List<Long> ids) {
for (Long id : ids) {
if (doctorAppointmentMapper.selectList(new LambdaQueryWrapper<DoctorAppointment>().eq(DoctorAppointment::getDoctorId, id)) != null) {
if (!doctorAppointmentMapper.selectList(new LambdaQueryWrapper<DoctorAppointment>().eq(DoctorAppointment::getDoctorId, id)).isEmpty()) {
throw new HassleFreeException(ResultCodeEnum.DELETE_ERROR);
}
if (articleInfoMapper.selectList(new LambdaQueryWrapper<ArticleInfo>().eq(ArticleInfo::getDoctorId, id)) != null) {
if (!articleInfoMapper.selectList(new LambdaQueryWrapper<ArticleInfo>().eq(ArticleInfo::getDoctorId, id)).isEmpty()) {
throw new HassleFreeException(ResultCodeEnum.DELETE_ERROR);
}
if (userAppointmentMapper.selectList(new LambdaQueryWrapper<UserAppointment>().eq(UserAppointment::getDoctorId, id)) != null) {
if (!userAppointmentMapper.selectList(new LambdaQueryWrapper<UserAppointment>().eq(UserAppointment::getDoctorId, id)).isEmpty()) {
throw new HassleFreeException(ResultCodeEnum.DELETE_ERROR);
}
}

View File

@ -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<SystemUser>().eq(SystemUser::getUsername, name));
SystemUserInfoVo systemUserInfoVo = new SystemUserInfoVo();
systemUserInfoVo.setName(systemUser.getName());
systemUserInfoVo.setAvatarUrl(graphInfoMapper.selectOne(new LambdaQueryWrapper<GraphInfo>()
.eq(GraphInfo::getItemType, GraphItemType.ADMIN)
.eq(GraphInfo::getItemId, userId))
.eq(GraphInfo::getItemId, systemUser.getId()))
.getUrl());
return systemUserInfoVo;
}

View File

@ -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) {

View File

@ -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<FileVo> upload(@RequestParam MultipartFile file) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
return Result.ok(service.upload(file));
}
}

View File

@ -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();
}
}

View File

@ -78,4 +78,11 @@ public class Knife4jConfiguration {
pathsToMatch("/app/appointment/**").
build();
}
@Bean
public GroupedOpenApi fileAPI() {
return GroupedOpenApi.builder().group("文件信息").
pathsToMatch("/app/file/**").
build();
}
}

View File

@ -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();
}
}

View File

@ -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)

View File

@ -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<String, BaseEnum> {
@Override
public <T extends BaseEnum> Converter<String, T> getConverter(Class<T> targetType) {
return new Converter<String, T>() {
@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 + "非法");
}
};
}
}

View File

@ -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;
}

View File

@ -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<UserInfo> {
void updateUserInfo(UserVo userVo);
}

View File

@ -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);
}
}

View File

@ -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<UserMapper, UserInfo> implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private GraphInfoMapper graphInfoMapper;
@Override
public void updateUserInfo(UserVo userVo) {
if (userVo.getUrlName() != null && !userVo.getUrlName().equals("")) {
UpdateWrapper<GraphInfo> 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<UserInfo> userInfoUpdateWrapper = new UpdateWrapper<>();
userInfoUpdateWrapper.eq("id", LoginUserHolder.getLoginUser().getUserId())
.set("nickname", userVo.getNickname());
userMapper.update(userInfoUpdateWrapper);
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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