|
|
@@ -0,0 +1,480 @@
|
|
|
+package com.fs.his.task;
|
|
|
+
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.file.PathUtil;
|
|
|
+import cn.hutool.core.util.IdcardUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fs.common.utils.file.ImageUtils;
|
|
|
+import com.fs.framework.interceptor.impl.SameUrlDataInterceptor;
|
|
|
+import com.fs.his.domain.FsInquiryOrderDTO;
|
|
|
+import com.fs.his.domain.FsPrescribeDrugDTO;
|
|
|
+import com.fs.his.dto.FsInquiryOrderPatientDTO;
|
|
|
+import com.fs.his.mapper.FsInquiryOrderMapper;
|
|
|
+import com.fs.his.mapper.FsPrescribeDrugMapper;
|
|
|
+import com.fs.his.param.FurtherConsultationParam;
|
|
|
+import com.fs.his.param.PrescriptionParam;
|
|
|
+import com.fs.his.service.IFsPrescribeService;
|
|
|
+import com.qiniu.util.Json;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 互联网医疗服务定时任务
|
|
|
+ * 润天推送参考:每天从中午12点到下午17点,每个小时的整点执行一次
|
|
|
+ */
|
|
|
+@Component("netMedicalService")
|
|
|
+@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class NetMedicalService {
|
|
|
+
|
|
|
+ private final String prefix = "https://202.61.88.184:19200/";
|
|
|
+ private final String prescriptionPath = "wjw/upload/uploadRecipe";
|
|
|
+ private final String reconsultPath = "wjw/upload/uploadFurtherConsult";
|
|
|
+
|
|
|
+ private final IFsPrescribeService iFsPrescribeService;
|
|
|
+ private final FsPrescribeDrugMapper durgMapper;
|
|
|
+ private final FsInquiryOrderMapper inquiryOrderMapper;
|
|
|
+
|
|
|
+ public void uploadPrescription() {
|
|
|
+ log.info("互联网医疗服务定时任务启动,时间{}", LocalDateTime.now());
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1.抽取有生成电子处方and上传了首诊记录的数据
|
|
|
+ LocalDate today = LocalDate.now().minusDays(1);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String date = today.format(formatter);
|
|
|
+
|
|
|
+ // 此任务准备在凌晨执行,上传前一天的电子处方。
|
|
|
+ List<Map<String, Object>> result = iFsPrescribeService.selectUploadDate("2025-09-21");//TODO:测试修改
|
|
|
+ log.info("查询到 {} 条待上传处方数据", result.size());
|
|
|
+
|
|
|
+ if (result.isEmpty()) {
|
|
|
+ log.info("没有需要上传的处方数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PrescriptionParam> paramList = processPrescriptions(result);
|
|
|
+
|
|
|
+ uploadToRemoteService(paramList);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("上传处方任务执行失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 网络诊疗服务数据上传
|
|
|
+ * TODO:请求体太大,可能需要分批请求;
|
|
|
+ */
|
|
|
+ public void uploadReconsultDate() {
|
|
|
+ log.info("开始执行网络诊疗服务数据上传任务");
|
|
|
+
|
|
|
+ // 使用 DateTimeFormatter 替代 SimpleDateFormat
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ LocalDate today = LocalDate.now().minusDays(1);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String date = today.format(formatter);
|
|
|
+
|
|
|
+ log.info("查询日期: {}", date);
|
|
|
+ List<FsInquiryOrderDTO> fsInquiryOrderDTOS = inquiryOrderMapper.selectNeedUploadData("2025-01-01");//TODO:测试修改
|
|
|
+ log.info("查询到需要上传的数据条数: {}", fsInquiryOrderDTOS.size());
|
|
|
+
|
|
|
+ ArrayList<FurtherConsultationParam> paramList = new ArrayList<>();
|
|
|
+ int successCount = 0;
|
|
|
+ int skipCount = 0;
|
|
|
+ int errorCount = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < fsInquiryOrderDTOS.size(); i++) {
|
|
|
+ FsInquiryOrderDTO fsInquiryOrder = fsInquiryOrderDTOS.get(i);
|
|
|
+ String orderSn = fsInquiryOrder.getOrderSn();
|
|
|
+
|
|
|
+ log.debug("正在处理第 {}/{} 条数据, 订单号: {}", i + 1, fsInquiryOrderDTOS.size(), orderSn);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 检查是否开具处方
|
|
|
+ int isPrescribe = iFsPrescribeService.selectPrescribeByinquiryOrderId(fsInquiryOrder.getOrderId());
|
|
|
+ log.debug("订单 {} 处方检查结果: {}", orderSn, isPrescribe > 0 ? "有处方" : "无处方");
|
|
|
+
|
|
|
+ String imageUrl = fsInquiryOrder.getReportImages();
|
|
|
+ if (imageUrl == null || imageUrl.trim().isEmpty()) {
|
|
|
+ log.warn("订单 {} 报告图片URL为空,跳过处理", orderSn);
|
|
|
+ skipCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("订单 {} 报告图片URL: {}", orderSn, imageUrl);
|
|
|
+
|
|
|
+ Integer supportedImageFormat = getSupportedImageFormat(imageUrl);
|
|
|
+ if (Objects.isNull(supportedImageFormat)) {
|
|
|
+ log.warn("订单 {} 不支持的文件后缀,跳过处理,图片URL: {}", orderSn, imageUrl);
|
|
|
+ skipCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ log.debug("订单 {} 图片格式识别成功: {}", orderSn, supportedImageFormat);
|
|
|
+
|
|
|
+ byte[] image = ImageUtils.getImage(imageUrl);
|
|
|
+ if (image == null || image.length == 0) {
|
|
|
+ log.warn("订单 {} 无法获取图片数据,图片URL: {}", orderSn, imageUrl);
|
|
|
+ skipCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ log.debug("订单 {} 成功获取图片数据,图片大小: {} bytes", orderSn, image.length);
|
|
|
+
|
|
|
+ String base64Image = Base64.getEncoder().encodeToString(image);
|
|
|
+ log.debug("订单 {} Base64编码完成,编码后长度: {}", orderSn, base64Image.length());
|
|
|
+
|
|
|
+ // 安全处理时间字段
|
|
|
+ String applyTime = formatDateTimeSafely(fsInquiryOrder.getCreateTime(), dateTimeFormatter);
|
|
|
+ String startTime = formatDateTimeSafely(fsInquiryOrder.getStartTime(), dateTimeFormatter);
|
|
|
+ String endTime = formatDateTimeSafely(fsInquiryOrder.getFinishTime(), dateTimeFormatter);
|
|
|
+ String uploadTime = LocalDateTime.now().format(dateTimeFormatter);//TODO:这个完成时间必须传,业务上判断是否需要未完结的复诊数据
|
|
|
+
|
|
|
+ if (applyTime == null || startTime == null || endTime == null) {
|
|
|
+ log.warn("订单 {} 时间字段存在空值,跳过处理", orderSn);
|
|
|
+ skipCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ FurtherConsultationParam param = FurtherConsultationParam.builder()
|
|
|
+ .thirdUniqueid(orderSn)
|
|
|
+ .orgName(fsInquiryOrder.getHospitalName())
|
|
|
+ .orgCode("组织结构代码")
|
|
|
+ .channelName("平台名称")
|
|
|
+ .section(fsInquiryOrder.getDeptName())
|
|
|
+ .sectionCode(fsInquiryOrder.getDeptCode())
|
|
|
+ .docName(fsInquiryOrder.getDoctorName())
|
|
|
+ .certificateNum(fsInquiryOrder.getCertificateCode())
|
|
|
+ .patientName(fsInquiryOrder.getPatientName())
|
|
|
+ .patientAge(IdcardUtil.getAgeByIdCard(fsInquiryOrder.getIdCard()))
|
|
|
+ .patientSex(fsInquiryOrder.getSex())
|
|
|
+ .patientIdcardType(1)
|
|
|
+ .patientIdcardNum(fsInquiryOrder.getIdCard())
|
|
|
+ .furtherConsultNo(orderSn)
|
|
|
+ .furtherConsulType(1)
|
|
|
+ .medicalHistory(fsInquiryOrder.getSelfMedHistory())
|
|
|
+ .furtherConsultApplyTime(applyTime)
|
|
|
+ .furtherConsulStartTime(startTime)
|
|
|
+ .furtherConsulEndTime(endTime)
|
|
|
+ .furtherConsulIsReply(1)
|
|
|
+ .feeType(1)
|
|
|
+ .furtherConsultDiagnosis(fsInquiryOrder.getInquiryResult())
|
|
|
+ .furtherConsultDiagnosisNo("复诊icd诊断编码")
|
|
|
+ .furtherConsultPrice(fsInquiryOrder.getMoney().toBigInteger().doubleValue())
|
|
|
+ .patientEvaluate(1)
|
|
|
+ .complainInfo("")
|
|
|
+ .disposeResult("")
|
|
|
+ .isRiskWarn(1)
|
|
|
+ .isPatientSign(1)
|
|
|
+ .isPrescription(isPrescribe > 0 ? 1 : 0)
|
|
|
+ .uploadTime(uploadTime)
|
|
|
+ .consultDiagnosisType(supportedImageFormat)
|
|
|
+ .consultOrg("首诊机构")
|
|
|
+ .consultDiagnosis(base64Image)
|
|
|
+ .cityId("")
|
|
|
+ .isMark("1")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ paramList.add(param);
|
|
|
+ successCount++;
|
|
|
+ log.debug("订单 {} 参数构建完成,已添加到上传列表", orderSn);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ errorCount++;
|
|
|
+ log.error("处理订单 {} 时发生异常: {}", orderSn, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("数据处理完成 - 成功: {}条, 跳过: {}条, 异常: {}条", successCount, skipCount, errorCount);
|
|
|
+
|
|
|
+ if (paramList.isEmpty()) {
|
|
|
+ log.info("没有需要上传的数据,任务结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String jsonParam = JSON.toJSONString(paramList);
|
|
|
+ log.info("准备上传数据,参数条数: {}", paramList.size());
|
|
|
+// log.debug("请求参数JSON: {}", jsonParam);
|
|
|
+
|
|
|
+ String urlPath = prefix + reconsultPath;
|
|
|
+ log.info("请求URL: {}", urlPath);
|
|
|
+
|
|
|
+ HttpRequest post = HttpUtil.createPost(urlPath);
|
|
|
+ post.body(jsonParam, "application/json; charset=utf-8");
|
|
|
+
|
|
|
+ log.info("开始发送HTTP请求...");
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ HttpResponse response = post.execute();
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ log.info("HTTP请求完成,状态码: {}, 耗时: {}ms", response.getStatus(), endTime - startTime);
|
|
|
+
|
|
|
+ if (response.isOk()) {
|
|
|
+ String responseBody = response.body();
|
|
|
+ log.info("上传成功,响应内容: {}", responseBody);
|
|
|
+
|
|
|
+ // 可以在这里添加响应结果解析和业务逻辑判断
|
|
|
+ try {
|
|
|
+ JSONObject responseJson = JSON.parseObject(responseBody);
|
|
|
+ if (responseJson != null) {
|
|
|
+ String code = responseJson.getString("status");
|
|
|
+ String message = responseJson.getString("message");
|
|
|
+ log.info("响应解析 - 状态码: {}, 消息: {}", code, message);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("响应内容解析失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("上传失败,状态码: {}, 响应内容: {}", response.getStatus(), response.body());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据上传过程中发生异常: {}", e.getMessage(), e);
|
|
|
+ }
|
|
|
+ log.info("网络诊疗服务数据上传任务执行完毕");
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<PrescriptionParam> processPrescriptions(List<Map<String, Object>> prescriptions) {
|
|
|
+ List<PrescriptionParam> paramList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map<String, Object> prescribe : prescriptions) {
|
|
|
+ try {
|
|
|
+ PrescriptionParam param = processSinglePrescription(prescribe);
|
|
|
+ if (param != null) {
|
|
|
+ paramList.add(param);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理处方失败, prescribe_id: {}", prescribe.get("prescribe_id"), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("成功处理 {} 个处方", paramList.size());
|
|
|
+ return paramList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PrescriptionParam processSinglePrescription(Map<String, Object> prescribe) {
|
|
|
+ Long prescribeId = Convert.toLong(prescribe.get("prescribe_id"));
|
|
|
+ if (prescribeId == null) {
|
|
|
+ log.warn("处方ID为空,跳过处理");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 药品信息查询
|
|
|
+ List<FsPrescribeDrugDTO> drugs = durgMapper.selectDrugList(prescribeId);
|
|
|
+ if (drugs == null || drugs.isEmpty()) {
|
|
|
+ log.warn("处方 {} 没有药品信息,跳过处理", prescribeId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算总量
|
|
|
+ Double quantity = calculateTotalQuantity(drugs);
|
|
|
+ Double days = calculateTotalDays(drugs);
|
|
|
+
|
|
|
+ // 组装药品信息
|
|
|
+ Map<String, String> drugInfoMap = buildDrugInfoMap(drugs);
|
|
|
+
|
|
|
+ // 构建处方参数
|
|
|
+ return buildPrescriptionParam(prescribe, drugInfoMap, quantity, days);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double calculateTotalQuantity(List<FsPrescribeDrugDTO> drugs) {
|
|
|
+ return drugs.stream().map(FsPrescribeDrugDTO::getDrugNum).filter(Objects::nonNull).mapToDouble(Convert::toDouble).sum();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double calculateTotalDays(List<FsPrescribeDrugDTO> drugs) {
|
|
|
+ return drugs.stream().map(FsPrescribeDrugDTO::getUsageDays).filter(Objects::nonNull).mapToDouble(Convert::toDouble).sum();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> buildDrugInfoMap(List<FsPrescribeDrugDTO> drugs) {
|
|
|
+ Map<String, String> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("drugName", join(drugs, FsPrescribeDrugDTO::getDrugName));
|
|
|
+ resultMap.put("specification", join(drugs, FsPrescribeDrugDTO::getDrugSpec));
|
|
|
+ resultMap.put("frequency", join(drugs, FsPrescribeDrugDTO::getUsageFrequencyUnit));
|
|
|
+ resultMap.put("useMethod", join(drugs, FsPrescribeDrugDTO::getUsageMethod));
|
|
|
+ resultMap.put("usagePerUseUnit", join(drugs, FsPrescribeDrugDTO::getUsagePerUseUnit));
|
|
|
+ resultMap.put("drugCode", join(drugs, FsPrescribeDrugDTO::getBarCode));
|
|
|
+ resultMap.put("doseEachTime", join(drugs, FsPrescribeDrugDTO::getUsagePerUseCount)); // 修复类型
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PrescriptionParam buildPrescriptionParam(Map<String, Object> prescribe, Map<String, String> drugInfoMap, Double quantity, Double days) {
|
|
|
+ return PrescriptionParam.builder()
|
|
|
+ .thirdUniqueid(getString(prescribe, "prescribe_code"))
|
|
|
+ .orgName(getString(prescribe, "hospital_name"))
|
|
|
+ .orgCode("机构编码") // TODO: 不晓得从哪取
|
|
|
+ .section(getString(prescribe, "dept_name"))
|
|
|
+ .sectionCode(getString(prescribe, "dept_code"))
|
|
|
+ .docName(getString(prescribe, "doctor_name"))
|
|
|
+ .docCertificateNum(getString(prescribe, "certificate_code"))
|
|
|
+ .pharmacistName(getString(prescribe, "doctor_drug_name"))
|
|
|
+ .pharmacistCertificateNum(getString(prescribe, "doctor_drug_code"))
|
|
|
+ .patientName(getString(prescribe, "patient_name"))
|
|
|
+ .patientSex(getString(prescribe, "patient_gender"))
|
|
|
+ .patientAge(getInteger(prescribe, "patient_age"))
|
|
|
+ .patientIdcardType(1)
|
|
|
+ .feeType(1)
|
|
|
+ .patientIdcardNum(getString(prescribe, "id_card"))
|
|
|
+ .recipeTime(getString(prescribe, "create_time"))
|
|
|
+ .reviewTime(getString(prescribe, "create_time"))
|
|
|
+ .recipeUnitPrice(getDouble(prescribe, "total_price"))
|
|
|
+ .drugName(drugInfoMap.get("drugName"))
|
|
|
+ .drugCode(drugInfoMap.get("drugCode"))
|
|
|
+ .drugCommonName(drugInfoMap.get("drugName"))
|
|
|
+ .specification(drugInfoMap.get("specification"))
|
|
|
+ .frequency(drugInfoMap.get("frequency"))
|
|
|
+ .usage(drugInfoMap.get("useMethod"))
|
|
|
+ .doseUnit(drugInfoMap.get("usagePerUseUnit"))
|
|
|
+ .doseEachTime(drugInfoMap.get("doseEachTime"))
|
|
|
+ .medicationDays(days)
|
|
|
+ .quantity(quantity)
|
|
|
+ .drugPackage("药品包装") // TODO: 不晓得去哪取
|
|
|
+ .recipeAllPrice(getDouble(prescribe, "total_price"))
|
|
|
+ .uploadTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
|
|
+ .recipeNo(getString(prescribe, "prescribe_code"))
|
|
|
+ .cityId("") // TODO: 没有对应字典
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadToRemoteService(List<PrescriptionParam> paramList) {
|
|
|
+ if (paramList.isEmpty()) {
|
|
|
+ log.info("没有需要上传的数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String url = prefix + prescriptionPath;
|
|
|
+ log.info("开始上传 {} 个处方到: {}", paramList.size(), url);
|
|
|
+
|
|
|
+ HttpRequest post = HttpUtil.createPost(url);
|
|
|
+ String requestBody = JSON.toJSONString(paramList);
|
|
|
+ log.debug("上传数据: {}", requestBody);//很大一坨
|
|
|
+
|
|
|
+ post.body(requestBody);
|
|
|
+ HttpResponse response = post.execute();
|
|
|
+
|
|
|
+// log.info("上传完成,响应状态: {}", response.getStatus());
|
|
|
+ log.info("响应内容: {}", JSON.toJSONString(response));
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("上传处方数据到远程服务失败", e);
|
|
|
+ throw new RuntimeException("上传失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 工具方法
|
|
|
+ private String getString(Map<String, Object> map, String key) {
|
|
|
+ Object value = map.get(key);
|
|
|
+ return value != null ? value.toString() : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getInteger(Map<String, Object> map, String key) {
|
|
|
+ try {
|
|
|
+ Object value = map.get(key);
|
|
|
+ return value != null ? Integer.valueOf(value.toString()) : 0;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("字段 {} 转换整数失败, 使用默认值0", key);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getDouble(Map<String, Object> map, String key) {
|
|
|
+ try {
|
|
|
+ Object value = map.get(key);
|
|
|
+ return value != null ? Double.valueOf(value.toString()) : 0.0;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("字段 {} 转换浮点数失败, 使用默认值0.0", key);
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String join(List<FsPrescribeDrugDTO> drugs, Function<FsPrescribeDrugDTO, String> fieldExtractor) {
|
|
|
+ return drugs.stream().map(fieldExtractor).filter(Objects::nonNull).filter(str -> !str.trim().isEmpty()).collect(Collectors.joining("|"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取图片格式(只支持jpg、png、bmp)
|
|
|
+ *
|
|
|
+ * @param imagePath 图片路径
|
|
|
+ * @return 图片格式(jpeg, png, bmp),如果不支持则返回null
|
|
|
+ */
|
|
|
+ public static Integer getSupportedImageFormat(String imagePath) {
|
|
|
+ if (imagePath == null || imagePath.trim().isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理URL参数
|
|
|
+ String cleanPath = imagePath.split("[?#]")[0];
|
|
|
+
|
|
|
+ // 获取扩展名
|
|
|
+ String extension = "";
|
|
|
+ int lastDotIndex = cleanPath.lastIndexOf('.');
|
|
|
+ if (lastDotIndex > 0 && lastDotIndex < cleanPath.length() - 1) {
|
|
|
+ extension = cleanPath.substring(lastDotIndex + 1).toLowerCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只支持三种格式
|
|
|
+ switch (extension) {
|
|
|
+ case "jpg":
|
|
|
+ case "jpeg":
|
|
|
+ return 2;
|
|
|
+ case "png":
|
|
|
+ return 3;
|
|
|
+ case "bmp":
|
|
|
+ return 4;
|
|
|
+ default:
|
|
|
+ return null; // 不支持的格式返回null
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全格式化时间方法,处理各种时间类型
|
|
|
+ */
|
|
|
+ private String formatDateTimeSafely(Object dateTime, DateTimeFormatter formatter) {
|
|
|
+ if (dateTime == null) {
|
|
|
+ log.warn("时间字段为null");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (dateTime instanceof java.util.Date) {
|
|
|
+ // 转换 java.util.Date 到 LocalDateTime
|
|
|
+ Instant instant = ((java.util.Date) dateTime).toInstant();
|
|
|
+ return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).format(formatter);
|
|
|
+ } else if (dateTime instanceof java.sql.Timestamp) {
|
|
|
+ // 转换 java.sql.Timestamp 到 LocalDateTime
|
|
|
+ return ((java.sql.Timestamp) dateTime).toLocalDateTime().format(formatter);
|
|
|
+ } else if (dateTime instanceof LocalDateTime) {
|
|
|
+ // 直接格式化 LocalDateTime
|
|
|
+ return ((LocalDateTime) dateTime).format(formatter);
|
|
|
+ } else if (dateTime instanceof LocalDate) {
|
|
|
+ // 处理 LocalDate,添加时间部分
|
|
|
+ return ((LocalDate) dateTime).atStartOfDay().format(formatter);
|
|
|
+ } else {
|
|
|
+ log.warn("不支持的时间类型: {}", dateTime.getClass().getName());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("时间格式化失败: {}, 原始值: {}", e.getMessage(), dateTime);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|