新增患者方法里新增头像保存内容已经配置管理新增了配置项
This commit is contained in:
parent
9db0f4019d
commit
d2399ff15f
@ -10,6 +10,11 @@ import lombok.SneakyThrows;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件工具类
|
* 文件工具类
|
||||||
@ -80,5 +85,31 @@ public class FileUtils {
|
|||||||
// 情况二:基于 content 计算
|
// 情况二:基于 content 计算
|
||||||
return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
|
return sha256Hex + '.' + FileTypeUtil.getType(new ByteArrayInputStream(content));
|
||||||
}
|
}
|
||||||
|
public static void saveBase64ToFile2(String base64String, String folderPath, String fileName, String extension) {
|
||||||
|
//参数校验
|
||||||
|
if (fileName.contains("..") || fileName.contains("/") || fileName.contains("\\")) {
|
||||||
|
throw new IllegalArgumentException("Invalid file name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] decodedBytes = Base64.getDecoder().decode(base64String);
|
||||||
|
|
||||||
|
// Path folder = Paths.get(folderPath);
|
||||||
|
// if (!Files.exists(folder)) {
|
||||||
|
// Files.createDirectories(folder);
|
||||||
|
// }
|
||||||
|
// Path filePath = folder.resolve(fileName + "." + extension);
|
||||||
|
|
||||||
|
File file = new File(folderPath);
|
||||||
|
file.setWritable(true, false);
|
||||||
|
file.mkdirs();
|
||||||
|
Path filePath = Paths.get(folderPath + "/" + fileName + "." + extension);
|
||||||
|
|
||||||
|
java.io.OutputStream outputStream = Files.newOutputStream(filePath, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||||
|
outputStream.write(decodedBytes);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("----------------------FileUtils Exception------------------------");
|
||||||
|
System.out.println(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,12 @@
|
|||||||
<groupId>cn.iocoder.boot</groupId>
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
<artifactId>yudao-spring-boot-starter-excel</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
|
<artifactId>yudao-module-infra-biz</artifactId>
|
||||||
|
<version>2.4.1-jdk8-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient;
|
package cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO;
|
||||||
|
import cn.iocoder.yudao.module.infra.service.config.ConfigService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -37,10 +40,24 @@ public class InspectPatientController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private InspectPatientService patientService;
|
private InspectPatientService patientService;
|
||||||
|
@Resource
|
||||||
|
private ConfigService configService;
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "创建患者信息")
|
@Operation(summary = "创建患者信息")
|
||||||
public CommonResult<Integer> createPatient(@Valid @RequestBody InspectPatientSaveReqVO createReqVO) {
|
public CommonResult<Integer> createPatient(@Valid @RequestBody InspectPatientSaveReqVO createReqVO) {
|
||||||
|
|
||||||
|
//处理头像
|
||||||
|
if(createReqVO.getHeadimage()!=null||createReqVO.getHeadimage()!="")
|
||||||
|
{
|
||||||
|
//获取配置项地址
|
||||||
|
ConfigDO path = configService.getConfigByKey("path.url");
|
||||||
|
|
||||||
|
ConfigDO config = configService.getConfigByKey("path.specific");
|
||||||
|
String uuid=UUID.randomUUID().toString();
|
||||||
|
FileUtils.saveBase64ToFile2(createReqVO.getHeadimage(),path.getValue(),createReqVO.getMedicalSn(),"png");
|
||||||
|
createReqVO.setHeadPicUrl(config.getValue()+createReqVO.getMedicalSn()+".png");
|
||||||
|
}
|
||||||
|
|
||||||
return success(patientService.createPatient(createReqVO));
|
return success(patientService.createPatient(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,4 +103,5 @@ public class InspectPatientController {
|
|||||||
BeanUtils.toBean(list, InspectPatientRespVO.class));
|
BeanUtils.toBean(list, InspectPatientRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -84,5 +84,6 @@ public class InspectPatientSaveReqVO {
|
|||||||
@Schema(description = "收费时间")
|
@Schema(description = "收费时间")
|
||||||
private LocalDateTime chargetime;
|
private LocalDateTime chargetime;
|
||||||
|
|
||||||
|
@Schema(description = "头像Base64")
|
||||||
|
private String headimage;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user