This commit is contained in:
杨海航
2025-04-15 11:57:56 +08:00
parent 3b876e7ce6
commit ff745d6217

View File

@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
@@ -127,16 +128,65 @@ public class IdentifyBookDataServiceImpl implements IdentifyBookDataService {
bookData.setTestMethod(getTestMethods(testRecordInfo));//设置用到的实验方法
//设置检验过程
bookData.setTestProcessDes(testRecordInfo.getTestProcessDes());//设置检验过程
bookData.setTestResult(testRecordSampleDataService.generateQualitativeResults(businessId));
//设置检验结果
bookData.setTestResult(inspectRecordService.buildInspectOpinion(testRecordSampleDataService
.lambdaQuery()
.eq(TestRecordSampleData::getTestId, testRecordInfo.getId())
.eq(TestRecordSampleData::getSampleType, "Analyte")
.list()));
//检验日期
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
bookData.setTestStartDate(sdf.format(testRecordInfo.getCreateTime()));
bookData.setTestOptUser(testRecordInfo.getTestUserId());
bookData.setTestFinishDate(sdf.format(testRecordInfo.getUpdateTime()));
LocalDateTime testFinishDate = testRecordInfo.getUpdateTime();
String chineseTestFinishDate = convertToChineseDate(testFinishDate);
bookData.setTestFinishDate(chineseTestFinishDate);
System.out.println("打印的实验结束时间:" + chineseTestFinishDate);
return bookData;
}
// 自定义方法:将 LocalDateTime 转换为中文日期格式
public static String convertToChineseDate(LocalDateTime date) {
// 获取年月日
int year = date.getYear();
int month = date.getMonthValue();
int day = date.getDayOfMonth();
// 处理年:去掉“二零”前缀,只保留后两位
String yearStr = convertNumberToChineseForYear(year % 100) + "";
// 处理月和日
String monthStr = convertNumberToChinese(month) + "";
String dayStr = convertNumberToChinese(day) + "";
return yearStr + monthStr + dayStr;
}
// 数字转中文
public static String convertNumberToChinese(int number) {
String[] chineseDigits = {"", "", "", "", "", "", "", "", "", "", ""};
if (number <= 10) {
return chineseDigits[number];
} else if (number < 20) {
return "" + chineseDigits[number % 10];
} else if (number % 10 == 0) {
return chineseDigits[number / 10] + "";
} else {
return chineseDigits[number / 10] + "" + chineseDigits[number % 10];
}
}
// 数字转中文(用于年)
public static String convertNumberToChineseForYear(int number) {
String[] chineseDigits = {"", "", "", "", "", "", "", "", "", ""};
if (number < 10) {
return chineseDigits[number];
} else {
return chineseDigits[number / 10] + chineseDigits[number % 10];
}
}
//获取业务的实验对象
private TestRecord getTestRecordInfo(List<TestRecordSampleSolution> testRecordSampleSolutionList) {
List<String> testIdList = testRecordSampleSolutionList.stream().map(s -> s.getTestId()).collect(Collectors.toList());