diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java index b51a838..eb46c8a 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/DateUtils.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.common.util.date; import cn.hutool.core.date.LocalDateTimeUtil; import java.time.*; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; @@ -145,5 +146,12 @@ public class DateUtils { public static boolean isYesterday(LocalDateTime date) { return LocalDateTimeUtil.isSameDay(date, LocalDateTime.now().minusDays(1)); } - + public static String generateUniqueCode() { + // 获取当前日期和时间 + LocalDateTime now = LocalDateTime.now(); + // 定义格式化模式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + // 格式化当前日期和时间为字符串 + return now.format(formatter); + } } diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java index 7ecc8cd..0f43e87 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java @@ -159,5 +159,21 @@ public class HttpUtils { return response.body(); } } - + /** + * HTTP post 请求,基于 {@link cn.hutool.http.HttpUtil} 实现 + * + * 该方法不需要传递 headers 参数,请求体为 JSON 格式 + * + * @param url URL + * @param jsonRequestBody 请求体,JSON 格式 + * @return 请求结果 + */ + public static String postJson(String url, String jsonRequestBody) { + try (HttpResponse response = HttpRequest.post(url) + .body(jsonRequestBody) + .contentType("application/json") + .execute()) { + return response.body(); + } + } } diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java index d236d18..8556850 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java @@ -4,6 +4,9 @@ import cn.hutool.core.text.StrPool; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; +import java.time.LocalDate; +import java.time.Period; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -76,5 +79,24 @@ public class StrUtils { .filter(line -> !line.contains(sequence)) .collect(Collectors.joining("\n")); } + /** + * 根据身份证号码计算年龄 + * + * @param idCard 身份证号码 + * @return 年龄 + */ + public static int calculateAgeFromIdCard(String idCard) { + if (idCard == null || idCard.length() != 18) { + return 0; // 身份证号码无效 + } + // 提取出生日期 + String birthDateStr = idCard.substring(6, 14); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + LocalDate birthDate = LocalDate.parse(birthDateStr, formatter); + + // 计算年龄 + LocalDate currentDate = LocalDate.now(); + return Period.between(birthDate, currentDate).getYears(); + } } diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java index f2c6377..477c544 100644 --- a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java @@ -1,12 +1,16 @@ package cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient; +import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.framework.common.util.http.HttpUtils; import cn.iocoder.yudao.framework.common.util.io.FileUtils; +import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import cn.iocoder.yudao.module.infra.service.config.ConfigService; import cn.iocoder.yudao.module.inspect.controller.admin.inspectpatientitems.vo.InspectPatientitemsSaveReqVO; import cn.iocoder.yudao.module.inspect.dal.dataobject.inspectitems.InspectitemsDO; import cn.iocoder.yudao.module.inspect.service.exammodule.ExammoduleService; import cn.iocoder.yudao.module.inspect.service.inspectpatientitems.InspectPatientitemsService; +import com.fasterxml.jackson.core.JsonProcessingException; import com.mysql.cj.result.Row; import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.ss.usermodel.Cell; @@ -28,6 +32,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -50,13 +55,14 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import com.fasterxml.jackson.databind.ObjectMapper; @Tag(name = "管理后台 - 患者信息") @RestController @RequestMapping("/inspect/patient") @Validated public class InspectPatientController { - + private static final AtomicInteger counter = new AtomicInteger(0); @Resource private InspectPatientService patientService; @Resource @@ -159,7 +165,8 @@ public class InspectPatientController { while (rowIterator.hasNext()) { org.apache.poi.ss.usermodel.Row row = rowIterator.next(); long timestamp = System.currentTimeMillis(); - String MedicalSn= Long.toString(timestamp); + long uniqueNumber = counter.incrementAndGet(); + String MedicalSn = Long.toString(timestamp) + String.format("%04d", uniqueNumber % 10000); //患者信息 InspectPatientSaveReqVO rowData = new InspectPatientSaveReqVO(); @@ -228,7 +235,10 @@ public class InspectPatientController { return success("读取Excel文件失败"); } } - + /** + * + * 判断当前值类型 + */ private String getCellValue(Cell cell) { switch (cell.getCellType()) { case STRING: @@ -249,7 +259,9 @@ public class InspectPatientController { } } - + /* + * 批量执行患者数据 + * */ private void batchInsertPatients(List dataList) { int batchSize = 1000; for (int i = 0; i < dataList.size(); i += batchSize) { @@ -258,7 +270,9 @@ public class InspectPatientController { patientService.createPatientList(batch); } } - + /* + * 批量执行患者项目数据 + * */ private void batchInsertPatientItems(List dataList2) { int batchSize = 1000; for (int i = 0; i < dataList2.size(); i += batchSize) { @@ -268,6 +282,56 @@ public class InspectPatientController { } } + public CommonResult syncinspectApplyTj(@RequestParam("medicalSn") String medicalSn) throws JsonProcessingException { + //获取患者信息 + InspectPatientDO patientDO= patientService.getPatientInfo(medicalSn); + if (patientDO!=null) + { + // 创建 ObjectMapper 实例 + ObjectMapper objectMapper = new ObjectMapper(); + // 创建 Java 对象 + Map patient = new HashMap<>(); + patient.put("patientName", patientDO.getPName()); + patient.put("idCard", patientDO.getCardId()); + patient.put("hospitalCode", "121526004609160793"); + patient.put("sampleSource", "TJ"); + patient.put("patientGender", patientDO.getGender()=="女"?"1":"0"); + patient.put("patientAge", StrUtils.calculateAgeFromIdCard(patientDO.getCardId())); + patient.put("patientAgeUnit", "S"); + patient.put("barCodeStatus", 3); + + List> billingItemList = new ArrayList<>(); + String checkBarCode1= DateUtils.generateUniqueCode(); + Map item1 = new HashMap<>(); + item1.put("groupCode", "XCG"); + item1.put("checkBarCode", checkBarCode1); + billingItemList.add(item1); + + String checkBarCode2= DateUtils.generateUniqueCode(); + Map item2 = new HashMap<>(); + item2.put("groupCode", "NCG"); + item2.put("checkBarCode", checkBarCode2); + billingItemList.add(item2); + + String checkBarCode3= DateUtils.generateUniqueCode(); + Map item3 = new HashMap<>(); + item3.put("groupCode", "SHQX"); + item3.put("checkBarCode", checkBarCode3); + billingItemList.add(item3); + + patient.put("billingItemList", billingItemList); + + // 将 Java 对象转换为 JSON 字符串 + String jsonRequestBody = objectMapper.writeValueAsString(patient); + + // 发送 POST 请求 + String url = "http://example.com/api/patient"; + String response = HttpUtils.postJson(url, jsonRequestBody); + } + + return success(true); + } + @PutMapping("/update") @Operation(summary = "更新患者信息") public CommonResult updatePatient(@Valid @RequestBody InspectPatientSaveReqVO updateReqVO) {