陈昶聿
9 天以前 5b5b3860b978f9ac5860b9def1c4898ad2e380e6
Merge branch '20261111-妇幼档案随访' into smartor_ls_merge
已修改21个文件
已添加11个文件
2269 ■■■■■ 文件已修改
doc/api/妇保接口文档.md 646 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/core/event/FollowupCompletedEvent.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/api/TaskSubtaskApi.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/api/contract/TaskSubtaskApiImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/event/FollowupCompletedEventPublisher.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/mapper/ServiceSubtaskMapper.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/common/SpecificArchiveConstants.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/PatChildArchive.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/PatChildArchiveDetail.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/PatMaternityArchive.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/PatMaternityArchiveDetail.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/domain/PatSpecificArchiveGenerateLog.java 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/listener/InhospFollowupArchiveListener.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/PatSpecificArchiveGenerateLogMapper.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/IPatSpecificArchiveGenerateLogService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/IPatSpecificArchiveGenerateService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PatChildArchiveServiceImpl.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PatMaternityArchiveServiceImpl.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PatSpecificArchiveGenerateLogServiceImpl.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PatSpecificArchiveGenerateServiceImpl.java 601 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatChildArchiveDetailMapper.xml 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatChildArchiveMapper.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatMaternityArchiveDetailMapper.xml 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatMaternityArchiveMapper.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatSpecificArchiveGenerateLogMapper.xml 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/test/java/com/smartor/service/InhospFollowupArchiveLogicCheck.java 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sql/pat_specific_archive_generate_log_and_source_20261111.sql 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
doc/api/¸¾±£½Ó¿ÚÎĵµ.md
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,646 @@
# å¦‡ä¿æŽ¥å£æ–‡æ¡£ï¼ˆå¦‡ç§‘ / å„¿ç§‘档案)
> æœ¬æ–‡æ¡£ä»…包含以下 8 ä¸ªæŽ¥å£ï¼š
| åºå· | æ¨¡å— | æŽ¥å£ | æ–¹æ³• | è¯´æ˜Ž |
| --- | --- | --- | --- | --- |
| 1 | å¦‡ç§‘档案 | `/smartor/maternityArchive/selectPatMaternityArchiveList` | POST | æŸ¥è¯¢å¦‡ç§‘档案列表 |
| 2 | å¦‡ç§‘档案 | `/smartor/maternityArchive/insertOrUpdateMaternityArchive` | POST | æ–°å¢žæˆ–修改妇科档案 |
| 3 | å¦‡ç§‘档案 | `/smartor/maternityArchive/batchDelete` | POST | æ‰¹é‡åˆ é™¤å¦‡ç§‘档案(含详情) |
| 4 | å¦‡ç§‘档案详情 | `/smartor/maternityArchiveDetail/getInfo/{archiveid}` | GET | èŽ·å–å¦‡ç§‘æ¡£æ¡ˆè¯¦æƒ… |
| 5 | å„¿ç§‘档案 | `/smartor/childArchive/selectPatChildArchiveList` | POST | æŸ¥è¯¢å„¿ç§‘档案列表 |
| 6 | å„¿ç§‘档案 | `/smartor/childArchive/insertOrUpdateChildArchive` | POST | æ–°å¢žæˆ–修改儿科档案 |
| 7 | å„¿ç§‘档案 | `/smartor/childArchive/batchDelete` | POST | æ‰¹é‡åˆ é™¤å„¿ç§‘档案(含详情) |
| 8 | å„¿ç§‘档案详情 | `/smartor/childArchiveDetail/getInfo/{archiveid}` | GET | èŽ·å–å„¿ç§‘æ¡£æ¡ˆè¯¦æƒ… |
---
## ä¸€ã€é€šç”¨è¯´æ˜Ž
### 1.1 æœåŠ¡åœ°å€
- å‰ç¼€ï¼š`http://服务IP:端口`(默认开发环境为 `http://localhost:8080`)
### 1.2 è®¤è¯æ–¹å¼
- æ‰€æœ‰æŽ¥å£å‡éœ€ç™»å½•后调用。
- è¯·æ±‚头携带:`Authorization: Bearer {token}`
### 1.3 è¯·æ±‚与响应格式
- è¯·æ±‚体:`Content-Type: application/json`
- åˆ—表接口响应结构(TableDataInfo):
| å­—段 | ç±»åž‹ | è¯´æ˜Ž |
| --- | --- | --- |
| total | long | æ€»è®°å½•æ•° |
| rows | array | æ•°æ®åˆ—表 |
| code | int | çŠ¶æ€ç ï¼Œ200 ä¸ºæˆåŠŸ |
| msg | string | æç¤ºä¿¡æ¯ï¼Œå¦‚“查询成功” |
- éžåˆ—表接口响应结构(AjaxResult):
| å­—段 | ç±»åž‹ | è¯´æ˜Ž |
| --- | --- | --- |
| code | int | çŠ¶æ€ç ï¼Œ200 ä¸ºæˆåŠŸï¼Œ500 ä¸ºå¤±è´¥ |
| msg | string | æç¤ºä¿¡æ¯ï¼Œå¦‚“操作成功”、“操作失败” |
| data | object | ä¸šåŠ¡æ•°æ®ï¼ˆå¯èƒ½ä¸ºç©ºï¼‰ |
---
## äºŒã€å¦‡ç§‘档案接口
### 2.1 æŸ¥è¯¢å¦‡ç§‘档案列表
- **URL**:`POST /smartor/maternityArchive/selectPatMaternityArchiveList`
- **说明**:分页查询妇科档案主表列表(未删除数据 `del_flag = '0'`)。
**请求体(JSON,全部可选)**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| pageNum | Integer | å¦ | é¡µç ï¼ˆåˆ†é¡µæ—¶å¿…填) |
| pageSize | Integer | å¦ | æ¯é¡µæ¡æ•°ï¼ˆåˆ†é¡µæ—¶å¿…填) |
| archiveType | String | å¦ | æ¡£æ¡ˆç±»åž‹ï¼š1 æ—©å­•关爱,2 å›´ç»ç»æœŸMHI |
| outhospno | String | å¦ | é—¨è¯Šç¼–号(精确匹配) |
| inhospno | String | å¦ | ä½é™¢ç¼–号(精确匹配) |
| serialnum | String | å¦ | æµæ°´å·ï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| patid | Long | å¦ | æ‚£è€…ID |
| patname | String | å¦ | æ‚£è€…姓名(模糊匹配) |
| parentname | String | å¦ | å®¶é•¿å§“名(模糊匹配) |
| birthdate | Date | å¦ | å‡ºç”Ÿæ—¥æœŸ |
| idcardno | String | å¦ | è¯ä»¶å·ç ï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| phone | String | å¦ | è”系电话(精确匹配) |
| diagTime | Date | å¦ | è¯Šæ–­æ—¶é—´ |
| plannedFollowTime | Date | å¦ | æ‹Ÿéšè®¿æ—¶é—´ |
| followupCycleTimes | String | å¦ | éšè®¿å‘¨æœŸ(次数) |
| sex | Long | å¦ | æ€§åˆ«ï¼š1 ç”·ï¼Œ2 å¥³ |
| doctorCode | String | å¦ | ä¸»æ²»åŒ»ç”Ÿï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| doctorName | String | å¦ | ä¸»æ²»åŒ»ç”Ÿå§“名(模糊匹配) |
| managementDoctorCode | String | å¦ | ç»ç®¡åŒ»ç”Ÿï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| managementDoctorName | String | å¦ | ç»ç®¡åŒ»ç”Ÿå§“名(模糊匹配) |
| deptcode | String | å¦ | ç§‘室编号(精确匹配) |
| deptname | String | å¦ | ç§‘室名称(模糊匹配) |
| wardcode | String | å¦ | ç—…区编号(精确匹配) |
| wardname | String | å¦ | ç—…区名称(模糊匹配) |
| icd10code | String | å¦ | è¯Šæ–­ID(精确匹配) |
| diagname | String | å¦ | è¯Šæ–­åç§°ï¼ˆæ¨¡ç³ŠåŒ¹é…ï¼‰ |
| pregnancySituation | String | å¦ | å¦Šå¨ æƒ…况 |
| closeStatus | String | å¦ | ç»“案状态 |
| registerUser | String | å¦ | ç™»è®°äººå‘˜ |
| orgid | String | å¦ | åŒ»é™¢æœºæž„ID(后端按登录用户自动注入) |
| campusid | String | å¦ | é™¢åŒºID(后端按登录用户自动注入) |
| params.beginTime | String | å¦ | å»ºæ¡£æ—¶é—´èŒƒå›´å¼€å§‹ï¼Œæ ¼å¼ yyyy-MM-dd |
| params.endTime | String | å¦ | å»ºæ¡£æ—¶é—´èŒƒå›´ç»“束,格式 yyyy-MM-dd |
**请求示例**
```json
{
  "pageNum": 1,
  "pageSize": 10,
  "patname": "å¼ ",
  "archiveType": "1"
}
```
**响应示例**
```json
{
  "code": 200,
  "msg": "查询成功",
  "total": 1,
  "rows": [
    {
      "id": 1001,
      "archiveType": "1",
      "outhospno": "MZ20261001001",
      "inhospno": null,
      "serialnum": "LS20261001001",
      "patid": 9001,
      "patname": "张三",
      "parentname": null,
      "birthdate": "1995-06-01 00:00:00",
      "idcardno": "330102199506010022",
      "phone": "13800000000",
      "diagTime": "2026-10-01 09:30:00",
      "archiveTime": "2026-10-01 10:00:00",
      "plannedFollowTime": "2026-11-01 00:00:00",
      "followupCycleTimes": "4",
      "sex": 2,
      "doctorCode": "D001",
      "doctorName": "李医生",
      "managementDoctorCode": "D002",
      "managementDoctorName": "王医生",
      "deptcode": "FK",
      "deptname": "妇科",
      "wardcode": null,
      "wardname": null,
      "icd10code": "O20.0",
      "diagname": "先兆流产",
      "pregnancySituation": "孕12周",
      "closeStatus": "0",
      "registerUser": "李医生",
      "orgid": "1",
      "campusid": "1",
      "delFlag": "0"
    }
  ]
}
```
---
### 2.2 æ–°å¢žæˆ–修改妇科档案
- **URL**:`POST /smartor/maternityArchive/insertOrUpdateMaternityArchive`
- **说明**:同时维护妇科档案主表与详情表。
  - ä¸»è¡¨æœ‰ `archiveid`(或详情有 `id` ä¸”能反查)且存在时更新,否则新增。
  - è¿”回 `data` ä¸ºå¦‡ç§‘档案主表ID。
**请求体(JSON)**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| id | Long | å¦ | å¦‡ç§‘档案详情主键ID(更新详情时传入) |
| archiveid | Long | å¦ | å¦‡ç§‘档案主表ID(更新主表时传入) |
| archiveType | String | å¦ | æ¡£æ¡ˆç±»åž‹ï¼š1 æ—©å­•关爱,2 å›´ç»ç»æœŸMHI |
| sourceType | String | å¦ | æ¥æºç±»åž‹ï¼š1 é—¨è¯ŠæŽ¥è¯Šï¼Œ2 ä½é™¢éšè®¿ï¼Œ3 æ‰‹å·¥æ–°å¢ž |
| sourceBizId | Long | å¦ | æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID |
| sourceBizNo | String | å¦ | æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 |
| sourceSubId | Long | å¦ | æ¥æºéšè®¿å­ä»»åŠ¡ID:住院随访生成时为 service_subtask.id |
| outhospno | String | å¦ | é—¨è¯Šç¼–号 |
| inhospno | String | å¦ | ä½é™¢ç¼–号 |
| serialnum | String | å¦ | æµæ°´å· |
| patid | Long | å¦ | æ‚£è€…ID |
| patname | String | å¦ | æ‚£è€…姓名 |
| birthdate | Date | å¦ | å‡ºç”Ÿæ—¥æœŸï¼Œæ ¼å¼ yyyy-MM-dd HH:mm:ss |
| idcardno | String | å¦ | è¯ä»¶å·ç  |
| phone | String | å¦ | è”系电话 |
| diagTime | Date | å¦ | è¯Šæ–­æ—¶é—´ |
| archiveTime | Date | å¦ | å»ºæ¡£æ—¶é—´ |
| plannedFollowTime | Date | å¦ | æ‹Ÿéšè®¿æ—¶é—´ |
| sex | Long | å¦ | æ€§åˆ«ï¼š1 ç”·ï¼Œ2 å¥³ |
| doctorCode | String | å¦ | ä¸»æ²»åŒ»ç”Ÿ |
| doctorName | String | å¦ | ä¸»æ²»åŒ»ç”Ÿå§“名 |
| managementDoctorCode | String | å¦ | ç»ç®¡åŒ»ç”Ÿ |
| managementDoctorName | String | å¦ | ç»ç®¡åŒ»ç”Ÿå§“名 |
| deptcode | String | å¦ | ç§‘室编号 |
| deptname | String | å¦ | ç§‘室名称 |
| wardcode | String | å¦ | ç—…区编号 |
| wardname | String | å¦ | ç—…区名称 |
| icd10code | String | å¦ | è¯Šæ–­ID |
| diagname | String | å¦ | è¯Šæ–­åç§° |
| pregnancySituation | String | å¦ | å¦Šå¨ æƒ…况 |
| specificSituation | String | å¦ | å…·ä½“情况 |
| handleSuggestion | String | å¦ | å¤„理建议 |
| closeStatus | String | å¦ | ç»“案状态 |
| isRecordEstablished | String | å¦ | æ˜¯å¦å»ºå†Œï¼š0 å¦ï¼Œ1 æ˜¯ |
| dueDate | Date | å¦ | é¢„产期 |
| registerUser | String | å¦ | ç™»è®°äººå‘˜ |
| followupPeriod | String | å¦ | éšè®¿å‘¨æœŸ |
| followupCycleTimes | String | å¦ | éšè®¿å‘¨æœŸ(次数) |
| lastMenstrualTime | Date | å¦ | æœ«æ¬¡æœˆç» |
| firstDoctorCode | String | å¦ | é¦–诊医生 |
| firstDoctorName | String | å¦ | é¦–诊医生姓名 |
| contactPhone | String | å¦ | è”系人联系电话 |
| address | String | å¦ | å±…住地址 |
| epEarlyPregnancyFollowupForm | String | å¦ | æ—©å­•关爱-早孕随访表 |
| mhiMenopauseFollowupSystemIssuesForm | String | å¦ | å›´ç»ç»æœŸMHI-更年期随访系统问题表 |
| mhiMhtInitialVisitMedicalRecordForm | String | å¦ | å›´ç»ç»æœŸMHI-MHT首诊病历表 |
| mhiMhtFollowUpMedicalRecordForm | String | å¦ | å›´ç»ç»æœŸMHI-MHT复诊病历表 |
| mhiModifiedKuppermanScoringScaleForm | String | å¦ | å›´ç»ç»æœŸMHI-改良Kupperman评分标准表 |
| mhiMenopauseRatingScaleForm | String | å¦ | å›´ç»ç»æœŸMHI-更年期评定量表(MRS) |
| mhiPittsburghSleepQualityIndexForm | String | å¦ | å›´ç»ç»æœŸMHI-匹兹堡睡眠质量指数量表(PSQI) |
| remark | String | å¦ | å¤‡æ³¨ |
| orgid | String | å¦ | åŒ»é™¢æœºæž„ID(后端按登录用户自动覆盖) |
| campusid | String | å¦ | é™¢åŒºID(后端按登录用户自动覆盖) |
| delFlag | String | å¦ | åˆ é™¤æ ‡å¿—:0 æœªåˆ é™¤ï¼Œ1 å·²åˆ é™¤ï¼ˆé»˜è®¤ 0) |
**请求示例(新增)**
```json
{
  "archiveType": "1",
  "patid": 9001,
  "patname": "张三",
  "birthdate": "1995-06-01 00:00:00",
  "idcardno": "330102199506010022",
  "phone": "13800000000",
  "diagTime": "2026-10-01 09:30:00",
  "archiveTime": "2026-10-01 10:00:00",
  "sex": 2,
  "deptcode": "FK",
  "deptname": "妇科",
  "pregnancySituation": "孕12周",
  "closeStatus": "0"
}
```
**响应示例**
```json
{
  "code": 200,
  "msg": "操作成功",
  "data": 1001
}
```
---
### 2.3 æ‰¹é‡åˆ é™¤å¦‡ç§‘档案
- **URL**:`POST /smartor/maternityArchive/batchDelete`
- **说明**:按主表ID批量删除妇科档案,同时逻辑删除对应的妇科档案详情表数据(`del_flag` ç½®ä¸º 1),两步在同一事务中。
**请求体(JSON)**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| ids | Long[] | æ˜¯ | å¦‡ç§‘档案主表ID数组 |
**请求示例**
```json
[1001, 1002, 1003]
```
**响应示例**
```json
{
  "code": 200,
  "msg": "操作成功"
}
```
---
### 2.4 èŽ·å–å¦‡ç§‘æ¡£æ¡ˆè¯¦æƒ…
- **URL**:`GET /smartor/maternityArchiveDetail/getInfo/{archiveid}`
- **说明**:按档案主表ID查询妇科档案详情(未删除数据 `del_flag = '0'`),返回第一条详情记录;无数据时 `data` ä¸º `null`。
**路径参数**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| archiveid | Long | æ˜¯ | å¦‡ç§‘档案主表ID(`pat_maternity_archive.id`) |
**响应示例**
```json
{
  "code": 200,
  "msg": "操作成功",
  "data": {
    "id": 5001,
    "archiveid": 1001,
    "archiveType": "1",
    "sourceType": "1",
    "outhospno": "MZ20261001001",
    "inhospno": null,
    "serialnum": "LS20261001001",
    "patid": 9001,
    "patname": "张三",
    "birthdate": "1995-06-01 00:00:00",
    "idcardno": "330102199506010022",
    "phone": "13800000000",
    "diagTime": "2026-10-01 09:30:00",
    "archiveTime": "2026-10-01 10:00:00",
    "plannedFollowTime": "2026-11-01 00:00:00",
    "sex": 2,
    "doctorCode": "D001",
    "doctorName": "李医生",
    "managementDoctorCode": "D002",
    "managementDoctorName": "王医生",
    "deptcode": "FK",
    "deptname": "妇科",
    "wardcode": null,
    "wardname": null,
    "icd10code": "O20.0",
    "diagname": "先兆流产",
    "pregnancySituation": "孕12周",
    "specificSituation": "具体情况",
    "handleSuggestion": "注意休息",
    "closeStatus": "0",
    "isRecordEstablished": "1",
    "dueDate": "2027-03-20 00:00:00",
    "registerUser": "李医生",
    "followupPeriod": "每月",
    "followupCycleTimes": "4",
    "lastMenstrualTime": "2026-06-10 00:00:00",
    "firstDoctorCode": "D001",
    "firstDoctorName": "李医生",
    "contactPhone": "13900000000",
    "address": "杭州市西湖区",
    "orgid": "1",
    "campusid": "1",
    "delFlag": "0"
  }
}
```
> è¿”回对象 `data` ä¸ºå¦‡ç§‘档案详情对象,字段说明同 2.2 è¯·æ±‚体字段。
---
## ä¸‰ã€å„¿ç§‘档案接口
### 3.1 æŸ¥è¯¢å„¿ç§‘档案列表
- **URL**:`POST /smartor/childArchive/selectPatChildArchiveList`
- **说明**:分页查询儿科档案主表列表(未删除数据 `del_flag = '0'`)。
**请求体(JSON,全部可选)**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| pageNum | Integer | å¦ | é¡µç ï¼ˆåˆ†é¡µæ—¶å¿…填) |
| pageSize | Integer | å¦ | æ¯é¡µæ¡æ•°ï¼ˆåˆ†é¡µæ—¶å¿…填) |
| archiveType | String | å¦ | æ¡£æ¡ˆç±»åž‹ï¼š1 è¥å…»æ€§ç–¾ç—…,2 å­¦ä¹ å›°éš¾ï¼Œ3 é«˜å±å„¿ä¸“案 |
| outhospno | String | å¦ | é—¨è¯Šç¼–号(精确匹配) |
| inhospno | String | å¦ | ä½é™¢ç¼–号(精确匹配) |
| serialnum | String | å¦ | æµæ°´å·ï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| patid | Long | å¦ | æ‚£è€…ID |
| patname | String | å¦ | æ‚£è€…姓名(模糊匹配) |
| parentname | String | å¦ | å®¶é•¿å§“名(模糊匹配) |
| birthdate | Date | å¦ | å‡ºç”Ÿæ—¥æœŸ |
| idcardno | String | å¦ | è¯ä»¶å·ç ï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| phone | String | å¦ | è”系电话(精确匹配) |
| diagTime | Date | å¦ | è¯Šæ–­æ—¶é—´ |
| plannedFollowTime | Date | å¦ | æ‹Ÿéšè®¿æ—¶é—´ |
| followupCycleTimes | String | å¦ | éšè®¿å‘¨æœŸ(次数) |
| sex | Long | å¦ | æ€§åˆ«ï¼š1 ç”·ï¼Œ2 å¥³ |
| doctorCode | String | å¦ | ä¸»æ²»åŒ»ç”Ÿï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| doctorName | String | å¦ | ä¸»æ²»åŒ»ç”Ÿå§“名(模糊匹配) |
| managementDoctorCode | String | å¦ | ç»ç®¡åŒ»ç”Ÿï¼ˆç²¾ç¡®åŒ¹é…ï¼‰ |
| managementDoctorName | String | å¦ | ç»ç®¡åŒ»ç”Ÿå§“名(模糊匹配) |
| deptcode | String | å¦ | ç§‘室编号(精确匹配) |
| deptname | String | å¦ | ç§‘室名称(模糊匹配) |
| wardcode | String | å¦ | ç—…区编号(精确匹配) |
| wardname | String | å¦ | ç—…区名称(模糊匹配) |
| icd10code | String | å¦ | è¯Šæ–­ID(精确匹配) |
| diagname | String | å¦ | è¯Šæ–­åç§°ï¼ˆæ¨¡ç³ŠåŒ¹é…ï¼‰ |
| closeStatus | String | å¦ | ç»“案状态 |
| registerUser | String | å¦ | ç™»è®°äººå‘˜ |
| orgid | String | å¦ | åŒ»é™¢æœºæž„ID(后端按登录用户自动注入) |
| campusid | String | å¦ | é™¢åŒºID(后端按登录用户自动注入) |
| params.beginTime | String | å¦ | å»ºæ¡£æ—¶é—´èŒƒå›´å¼€å§‹ï¼Œæ ¼å¼ yyyy-MM-dd |
| params.endTime | String | å¦ | å»ºæ¡£æ—¶é—´èŒƒå›´ç»“束,格式 yyyy-MM-dd |
**请求示例**
```json
{
  "pageNum": 1,
  "pageSize": 10,
  "patname": "王",
  "archiveType": "1"
}
```
**响应示例**
```json
{
  "code": 200,
  "msg": "查询成功",
  "total": 1,
  "rows": [
    {
      "id": 2001,
      "archiveType": "1",
      "outhospno": "MZ20261001002",
      "inhospno": null,
      "serialnum": "LS20261001002",
      "patid": 9002,
      "patname": "王小宝",
      "parentname": "王强",
      "birthdate": "2023-01-15 00:00:00",
      "idcardno": null,
      "phone": "13800000001",
      "diagTime": "2026-10-01 09:00:00",
      "archiveTime": "2026-10-01 09:30:00",
      "plannedFollowTime": "2026-11-01 00:00:00",
      "followupCycleTimes": "3",
      "sex": 1,
      "doctorCode": "D003",
      "doctorName": "赵医生",
      "managementDoctorCode": "D004",
      "managementDoctorName": "孙医生",
      "deptcode": "EK",
      "deptname": "儿科",
      "wardcode": null,
      "wardname": null,
      "icd10code": "E44.0",
      "diagname": "中度营养不良",
      "closeStatus": "0",
      "registerUser": "赵医生",
      "orgid": "1",
      "campusid": "1",
      "delFlag": "0"
    }
  ]
}
```
---
### 3.2 æ–°å¢žæˆ–修改儿科档案
- **URL**:`POST /smartor/childArchive/insertOrUpdateChildArchive`
- **说明**:同时维护儿科档案主表与详情表。
  - ä¸»è¡¨æœ‰ `archiveid`(或详情有 `id` ä¸”能反查)且存在时更新,否则新增。
  - è¿”回 `data` ä¸ºå„¿ç§‘档案主表ID。
**请求体(JSON)**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| id | Long | å¦ | å„¿ç§‘档案详情主键ID(更新详情时传入) |
| archiveid | Long | å¦ | å„¿ç§‘档案主表ID(更新主表时传入) |
| archiveType | String | å¦ | æ¡£æ¡ˆç±»åž‹ï¼š1 è¥å…»æ€§ç–¾ç—…,2 å­¦ä¹ å›°éš¾ï¼Œ3 é«˜å±å„¿ä¸“案 |
| sourceType | String | å¦ | æ¥æºç±»åž‹ï¼š1 é—¨è¯ŠæŽ¥è¯Šï¼Œ2 ä½é™¢éšè®¿ï¼Œ3 æ‰‹å·¥æ–°å¢ž |
| sourceBizId | Long | å¦ | æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID |
| sourceBizNo | String | å¦ | æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 |
| sourceSubId | Long | å¦ | æ¥æºéšè®¿å­ä»»åŠ¡ID:住院随访生成时为 service_subtask.id |
| outhospno | String | å¦ | é—¨è¯Šç¼–号 |
| inhospno | String | å¦ | ä½é™¢ç¼–号 |
| serialnum | String | å¦ | æµæ°´å· |
| patid | Long | å¦ | æ‚£è€…ID |
| patname | String | å¦ | æ‚£è€…姓名 |
| parentname | String | å¦ | å®¶é•¿å§“名 |
| parentRelation | String | å¦ | å®¶é•¿ä¸Žå„¿ç«¥å…³ç³» |
| parentPhone | String | å¦ | å®¶é•¿è”系电话 |
| parentIdcardno | String | å¦ | å®¶é•¿è¯ä»¶å·ç  |
| parentAddress | String | å¦ | å®¶é•¿è”系地址 |
| birthdate | Date | å¦ | å‡ºç”Ÿæ—¥æœŸï¼Œæ ¼å¼ yyyy-MM-dd HH:mm:ss |
| idcardno | String | å¦ | è¯ä»¶å·ç  |
| phone | String | å¦ | è”系电话 |
| diagTime | Date | å¦ | è¯Šæ–­æ—¶é—´ |
| archiveTime | Date | å¦ | å»ºæ¡£æ—¶é—´ |
| sex | Long | å¦ | æ€§åˆ«ï¼š1 ç”·ï¼Œ2 å¥³ |
| doctorCode | String | å¦ | ä¸»æ²»åŒ»ç”Ÿ |
| doctorName | String | å¦ | ä¸»æ²»åŒ»ç”Ÿå§“名 |
| managementDoctorCode | String | å¦ | ç»ç®¡åŒ»ç”Ÿ |
| managementDoctorName | String | å¦ | ç»ç®¡åŒ»ç”Ÿå§“名 |
| deptcode | String | å¦ | ç§‘室编号 |
| deptname | String | å¦ | ç§‘室名称 |
| wardcode | String | å¦ | ç—…区编号 |
| wardname | String | å¦ | ç—…区名称 |
| icd10code | String | å¦ | è¯Šæ–­ID |
| diagname | String | å¦ | è¯Šæ–­åç§° |
| nutritionIcd10Code | String | å¦ | è¥å…»æ€§ç–¾ç—…ID |
| nutritionDiagName | String | å¦ | è¥å…»æ€§ç–¾ç—…名称 |
| ndPhysicalMeasurements | String | å¦ | è¥å…»æ€§ç–¾ç—…-体格测量 |
| ndDietaryAssessment | String | å¦ | è¥å…»æ€§ç–¾ç—…-膳食评估 |
| ndInterventionProgram | String | å¦ | è¥å…»æ€§ç–¾ç—…-干预方案 |
| appointmentSituation | String | å¦ | å­¦ä¹ å›°éš¾-预约情况 |
| ldLearningAbilityAssessment | String | å¦ | å­¦ä¹ å›°éš¾-学习能力评估 |
| ldBehavioralAssessment | String | å¦ | å­¦ä¹ å›°éš¾-行为评估 |
| ldInterventionTrainingRecord | String | å¦ | å­¦ä¹ å›°éš¾-干预训练记录 |
| highRiskChildType | String | å¦ | é«˜å±å„¿ä¸“案-高危儿分类 |
| highRiskChildName | String | å¦ | é«˜å±å„¿ä¸“案-高危儿名称 |
| plannedFollowTime | Date | å¦ | é«˜å±å„¿ä¸“案-拟随访时间 |
| hrcGrowthDevelopmentMonitoring | String | å¦ | é«˜å±å„¿ä¸“案-生长发育检测 |
| hrcNeurologicalEvaluation | String | å¦ | é«˜å±å„¿ä¸“案-神经系统评估 |
| hrcInterventionRecords | String | å¦ | é«˜å±å„¿ä¸“案-干预记录 |
| closeStatus | String | å¦ | ç»“案状态 |
| gestationalWeek | BigDecimal | å¦ | å‡ºç”Ÿå­•周 |
| birthWeight | BigDecimal | å¦ | å‡ºç”Ÿä½“重(kg) |
| registerUser | String | å¦ | ç™»è®°äººå‘˜ |
| remark | String | å¦ | å¤‡æ³¨ |
| orgid | String | å¦ | åŒ»é™¢æœºæž„ID(后端按登录用户自动覆盖) |
| campusid | String | å¦ | é™¢åŒºID(后端按登录用户自动覆盖) |
| delFlag | String | å¦ | åˆ é™¤æ ‡å¿—:0 æœªåˆ é™¤ï¼Œ1 å·²åˆ é™¤ï¼ˆé»˜è®¤ 0) |
**请求示例(新增)**
```json
{
  "archiveType": "1",
  "patid": 9002,
  "patname": "王小宝",
  "parentname": "王强",
  "parentRelation": "父子",
  "parentPhone": "13900000001",
  "birthdate": "2023-01-15 00:00:00",
  "phone": "13800000001",
  "diagTime": "2026-10-01 09:00:00",
  "archiveTime": "2026-10-01 09:30:00",
  "sex": 1,
  "deptcode": "EK",
  "deptname": "儿科",
  "icd10code": "E44.0",
  "diagname": "中度营养不良",
  "nutritionIcd10Code": "E44.0",
  "nutritionDiagName": "中度营养不良",
  "closeStatus": "0"
}
```
**响应示例**
```json
{
  "code": 200,
  "msg": "操作成功",
  "data": 2001
}
```
---
### 3.3 æ‰¹é‡åˆ é™¤å„¿ç§‘档案
- **URL**:`POST /smartor/childArchive/batchDelete`
- **说明**:按主表ID批量删除儿科档案,同时逻辑删除对应的儿科档案详情表数据(`del_flag` ç½®ä¸º 1),两步在同一事务中。
**请求体(JSON)**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| ids | Long[] | æ˜¯ | å„¿ç§‘档案主表ID数组 |
**请求示例**
```json
[2001, 2002, 2003]
```
**响应示例**
```json
{
  "code": 200,
  "msg": "操作成功"
}
```
---
### 3.4 èŽ·å–å„¿ç§‘æ¡£æ¡ˆè¯¦æƒ…
- **URL**:`GET /smartor/childArchiveDetail/getInfo/{archiveid}`
- **说明**:按档案主表ID查询儿科档案详情(未删除数据 `del_flag = '0'`),返回第一条详情记录;无数据时 `data` ä¸º `null`。
**路径参数**
| å‚数名 | ç±»åž‹ | å¿…å¡« | è¯´æ˜Ž |
| --- | --- | --- | --- |
| archiveid | Long | æ˜¯ | å„¿ç§‘档案主表ID(`pat_child_archive.id`) |
**响应示例**
```json
{
  "code": 200,
  "msg": "操作成功",
  "data": {
    "id": 6001,
    "archiveid": 2001,
    "archiveType": "1",
    "sourceType": "1",
    "outhospno": "MZ20261001002",
    "inhospno": null,
    "serialnum": "LS20261001002",
    "patid": 9002,
    "patname": "王小宝",
    "parentname": "王强",
    "parentRelation": "父子",
    "parentPhone": "13900000001",
    "parentIdcardno": null,
    "parentAddress": "杭州市拱墅区",
    "birthdate": "2023-01-15 00:00:00",
    "idcardno": null,
    "phone": "13800000001",
    "diagTime": "2026-10-01 09:00:00",
    "archiveTime": "2026-10-01 09:30:00",
    "sex": 1,
    "doctorCode": "D003",
    "doctorName": "赵医生",
    "managementDoctorCode": "D004",
    "managementDoctorName": "孙医生",
    "deptcode": "EK",
    "deptname": "儿科",
    "wardcode": null,
    "wardname": null,
    "icd10code": "E44.0",
    "diagname": "中度营养不良",
    "nutritionIcd10Code": "E44.0",
    "nutritionDiagName": "中度营养不良",
    "closeStatus": "0",
    "gestationalWeek": 39.5,
    "birthWeight": 3.2,
    "registerUser": "赵医生",
    "orgid": "1",
    "campusid": "1",
    "delFlag": "0"
  }
}
```
> è¿”回对象 `data` ä¸ºå„¿ç§‘档案详情对象,字段说明同 3.2 è¯·æ±‚体字段。
ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java
@@ -56,6 +56,7 @@
import com.ruoyi.task.domain.SendMagParam;
import com.ruoyi.task.service.IServiceSubtaskRecordService;
import com.ruoyi.task.mapper.ServiceSubtaskPreachformMapper;
import com.ruoyi.task.event.FollowupCompletedEventPublisher;
import com.ruoyi.patarchive.mapper.PatArchiveMapper;
@Slf4j
@Component//监听此队列
@@ -72,6 +73,9 @@
    @Value("${req_path}")
    private String req_path;
    @Autowired
    private FollowupCompletedEventPublisher followupCompletedEventPublisher;
    @Autowired
    private IServiceOutPathService iServiceOutPathService;
@@ -898,6 +902,9 @@
            serviceSubtask.setSendstate(6L);
        }
        serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
        if (Long.valueOf(6L).equals(serviceSubtask.getSendstate())) {
            followupCompletedEventPublisher.publish(serviceSubtask.getId());
        }
        // æ›´æ–°å½“前发送方式明细;发送成功时允许当前行已经是 sendstate=2。
        currentPreachformRow.setSendstate(failSendstate);
ruoyi-common/src/main/java/com/ruoyi/common/core/event/FollowupCompletedEvent.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,46 @@
package com.ruoyi.common.core.event;
import java.io.Serializable;
import java.util.Date;
/**
 * éšè®¿å®Œæˆäº‹ä»¶ã€‚
 *
 * <p>仅携带子任务ID,消费方按ID重新加载最新数据,避免事件内容与库内状态不一致。</p>
 *
 * @author ruoyi
 * @date 2026-11-11
 */
public class FollowupCompletedEvent implements Serializable {
    private static final long serialVersionUID = 1L;
    /** éšè®¿å­ä»»åŠ¡ID */
    private Long subId;
    /** å®Œæˆæ—¶é—´ */
    private Date finishTime;
    public FollowupCompletedEvent() {
    }
    public FollowupCompletedEvent(Long subId, Date finishTime) {
        this.subId = subId;
        this.finishTime = finishTime;
    }
    public Long getSubId() {
        return subId;
    }
    public void setSubId(Long subId) {
        this.subId = subId;
    }
    public Date getFinishTime() {
        return finishTime;
    }
    public void setFinishTime(Date finishTime) {
        this.finishTime = finishTime;
    }
}
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -149,6 +149,12 @@
    private ICollectHISService ichService;
    @Autowired
    private IPatSpecificArchiveGenerateService patSpecificArchiveGenerateService;
    @Autowired
    private com.ruoyi.task.event.FollowupCompletedEventPublisher followupCompletedEventPublisher;
    @Autowired
    private ISysConfigService configService;
    @Autowired
@@ -1220,6 +1226,7 @@
                if (finishState) {
                    serviceSubtask.setSendstate(6L);
                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                    followupCompletedEventPublisher.publish(serviceSubtask.getId());
                    continue;
                }
@@ -1832,6 +1839,7 @@
                //说明,在某种方式发送失败后,又成功了(例如短信或公众号,在规定时间外患者做完了,这个时候,状态改成了9)
                serviceSubtask.setSendstate(6L);
                serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                followupCompletedEventPublisher.publish(serviceSubtask.getId());
                return "-1";
            }
            // å½“sort等于列表size时,并且所有sendstate都不等于9,则返回-1
@@ -2093,6 +2101,9 @@
        serviceSubtask.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark()) ? serviceSubtask.getRemark() + "," + remark : remark);
        log.info("serviceSubtask的入参是:{}",serviceSubtask);
        serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
        if (Long.valueOf(6L).equals(serviceSubtask.getSendstate())) {
            followupCompletedEventPublisher.publish(serviceSubtask.getId());
        }
        return true;
    }
@@ -2348,4 +2359,18 @@
        }
    }
    /**
     * ä½é™¢éšè®¿å®Œæˆç”Ÿæˆä¸“科档案补偿任务。
     *
     * <p>扫描近 7 å¤©å·²å®Œæˆä½†æœªç”Ÿæˆæ—¥å¿—的住院随访,按配置补生成妇科/儿科档案。</p>
     */
    public void generateInhospFollowupArchive() {
        try {
            int generated = patSpecificArchiveGenerateService.compensateInhospFollowups();
            log.info("【generateInhospFollowupArchive】住院随访专科档案补偿完成,生成数量={}", generated);
        } catch (Exception e) {
            log.error("【generateInhospFollowupArchive】住院随访专科档案补偿失败", e);
        }
    }
}
ruoyi-task/src/main/java/com/ruoyi/task/api/TaskSubtaskApi.java
@@ -53,6 +53,19 @@
    List<ServiceSubtask> findSubtasks(ServiceSubtaskEntity query);
    /**
     * æŸ¥è¯¢å·²å®Œæˆã€æŒ‡å®šæœºæž„/服务类型、完成时间在 startTime ä¹‹åŽçš„住院随访子任务。
     * ä¾›ä½é™¢éšè®¿æ¡£æ¡ˆè¡¥å¿ä»»åŠ¡ä½¿ç”¨ã€‚
     *
     * @param orgid        æœºæž„ID
     * @param serviceTypes æœåŠ¡ç±»åž‹ç™½åå•
     * @param startTime    å®Œæˆæ—¶é—´ä¸‹é™
     * @param limit        æœ€å¤§æ¡æ•°
     * @return å­ä»»åŠ¡åˆ—è¡¨
     */
    List<ServiceSubtask> findCompletedInhospFollowups(String orgid, List<String> serviceTypes,
                                                      java.util.Date startTime, int limit);
    /**
     * æ›´æ–°å­ä»»åŠ¡ï¼ˆåŽŸ {@code ServiceSubtaskMapper#updateServiceSubtask},动态 SQL åªæ”¹éžç©ºå­—段)
     *
     * @param subtask å¾…更新对象(必须带 id)
ruoyi-task/src/main/java/com/ruoyi/task/api/contract/TaskSubtaskApiImpl.java
@@ -12,6 +12,7 @@
import com.ruoyi.task.mapper.ServiceSubtaskMapper;
import com.ruoyi.task.service.IServiceSubtaskDetailTraceService;
import com.ruoyi.task.service.IServiceTaskService;
import com.ruoyi.task.event.FollowupCompletedEventPublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -49,6 +50,9 @@
    @Autowired
    private IServiceSubtaskDetailTraceService traceService;
    @Autowired
    private FollowupCompletedEventPublisher followupCompletedEventPublisher;
    @Override
    public ServiceSubtask getSubtask(Long subId) {
        return serviceSubtaskMapper.selectServiceSubtaskById(subId);
@@ -60,8 +64,18 @@
    }
    @Override
    public List<ServiceSubtask> findCompletedInhospFollowups(String orgid, List<String> serviceTypes,
                                                             java.util.Date startTime, int limit) {
        return serviceSubtaskMapper.selectCompletedInhospFollowups(orgid, serviceTypes, startTime, limit);
    }
    @Override
    public int updateSubtask(ServiceSubtask subtask) {
        Boolean updated = serviceSubtaskMapper.updateServiceSubtask(subtask);
        if (Boolean.TRUE.equals(updated) && subtask.getSendstate() != null
                && subtask.getSendstate() == 6 && subtask.getId() != null) {
            followupCompletedEventPublisher.publish(subtask.getId());
        }
        return Boolean.TRUE.equals(updated) ? 1 : 0;
    }
ruoyi-task/src/main/java/com/ruoyi/task/event/FollowupCompletedEventPublisher.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,37 @@
package com.ruoyi.task.event;
import com.ruoyi.common.core.event.FollowupCompletedEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
 * éšè®¿å®Œæˆäº‹ä»¶å‘布器。
 *
 * <p>任务模块在子任务状态更新为已完成(sendstate=6)后发布事件,
 * æ¡£æ¡ˆç­‰ä¸‹æ¸¸æ¨¡å—通过 {@code @TransactionalEventListener} å¼‚步消费。</p>
 *
 * @author ruoyi
 * @date 2026-11-11
 */
@Slf4j
@Component
public class FollowupCompletedEventPublisher {
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;
    public void publish(Long subId) {
        if (subId == null) {
            return;
        }
        try {
            applicationEventPublisher.publishEvent(new FollowupCompletedEvent(subId, new Date()));
        } catch (Exception e) {
            log.error("发布随访完成事件失败,subId={}", subId, e);
        }
    }
}
ruoyi-task/src/main/java/com/ruoyi/task/mapper/ServiceSubtaskMapper.java
@@ -48,6 +48,20 @@
    public List<ServiceSubtask> selectServiceSubtaskList(ServiceSubtaskEntity serviceSubtaskVO);
    /**
     * æŸ¥è¯¢å·²å®Œæˆã€ä¸”尚未被专科档案生成日志处理的住院随访子任务(补偿扫描用)。
     *
     * @param orgid        æœºæž„ID
     * @param serviceTypes æœåŠ¡ç±»åž‹ç™½åå•
     * @param startTime    å®Œæˆæ—¶é—´ä¸‹é™
     * @param limit        æœ€å¤§æ¡æ•°
     * @return å­ä»»åŠ¡é›†åˆ
     */
    public List<ServiceSubtask> selectCompletedInhospFollowups(@Param("orgid") String orgid,
                                                               @Param("serviceTypes") List<String> serviceTypes,
                                                               @Param("startTime") Date startTime,
                                                               @Param("limit") int limit);
    /**
     * åˆ†é¡µç¬¬ä¸€é˜¶æ®µï¼šåªå–当前页的子任务 id。
     * <p>
     * where / order ä¸Ž {@link #selectServiceSubtaskList} å…±ç”¨åŒä¸€ä»½ XML ç‰‡æ®µ
ruoyi-task/src/main/java/com/ruoyi/task/service/impl/ServiceSubtaskServiceImpl.java
@@ -126,6 +126,7 @@
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.mapper.ext.SysDept2Mapper;
import com.ruoyi.task.api.contract.OperationSubtaskWriter;
import com.ruoyi.task.event.FollowupCompletedEventPublisher;
/**
 * å•一任务(随访)Service业务层处理
@@ -145,6 +146,9 @@
     */
    @Autowired
    private OperationSubtaskWriter operationSubtaskWriter;
    @Autowired
    private FollowupCompletedEventPublisher followupCompletedEventPublisher;
    /**
     * æ»¡æ„åº¦æ¨¡å—对外门面(常驻 Bean)。
@@ -1579,7 +1583,12 @@
        if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 6)
            serviceSubtask.setFinishtime(new Date());
        return serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
        Boolean updated = serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
        if (Boolean.TRUE.equals(updated) && serviceSubtask.getSendstate() != null
                && serviceSubtask.getSendstate() == 6 && serviceSubtask.getId() != null) {
            followupCompletedEventPublisher.publish(serviceSubtask.getId());
        }
        return updated;
    }
    @Override
@@ -4958,6 +4967,7 @@
            serviceSubtask.setSendstate(6L);
            serviceSubtask.setPreachform("1");
            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
            followupCompletedEventPublisher.publish(serviceSubtask.getId());
        }
    }
@@ -5102,6 +5112,7 @@
        if (subtaskUpdated == 0) {
            throw new BaseException("微信公众号默认完成失败:子任务状态已变化,subid=" + current.getId());
        }
        followupCompletedEventPublisher.publish(current.getId());
        log.info("【微信公众号默认完成】subid:{},已按默认选项完成,填充题目数:{}", current.getId(), filled);
        return true;
ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml
@@ -1200,6 +1200,23 @@
        where id = #{id}
    </select>
    <select id="selectCompletedInhospFollowups" resultMap="ServiceSubtaskResult">
        <include refid="selectServiceSubtaskVo"/>
        where del_flag = '0'
          and sendstate = 6
          and hosp_type in ('2', '6')
          and orgid = #{orgid}
          and finishtime &gt;= #{startTime}
        <if test="serviceTypes != null and serviceTypes.size() > 0">
            and service_type in
            <foreach collection="serviceTypes" item="serviceType" open="(" separator="," close=")">
                #{serviceType}
            </foreach>
        </if>
        order by id asc
        limit #{limit}
    </select>
    <select id="selectServiceSubtaskByDiagname" parameterType="com.ruoyi.task.domain.ServiceSubtask"
            resultMap="ServiceSubtaskResult">
        select sendstate,starttime,endtime,nurse_name,phone,sex,task_name,sendname,leavediagname,visit_time FROM
smartor/src/main/java/com/smartor/common/SpecificArchiveConstants.java
@@ -16,6 +16,36 @@
     */
    public static final String DEFAULT_CAMPUS_ID = "1";
    /** æ¥æºç±»åž‹ï¼šé—¨è¯ŠæŽ¥è¯Šå®Œæˆ */
    public static final String SOURCE_TYPE_OUTHOSP = "1";
    /** æ¥æºç±»åž‹ï¼šä½é™¢éšè®¿å®Œæˆ */
    public static final String SOURCE_TYPE_INHOSP_FOLLOWUP = "2";
    /** æ¥æºç±»åž‹ï¼šæ‰‹å·¥æ–°å¢ž/手工导入 */
    public static final String SOURCE_TYPE_MANUAL = "3";
    /** éƒ¨é—¨åˆ†ç±»ï¼šå¦‡ç§‘ */
    public static final String DEPT_CATEGORY_GYNECOLOGY = "1";
    /** éƒ¨é—¨åˆ†ç±»ï¼šå„¿ç§‘ */
    public static final String DEPT_CATEGORY_PEDIATRICS = "2";
    /** ç”Ÿæˆç»“果:已生成 */
    public static final String RESULT_GENERATED = "1";
    /** ç”Ÿæˆç»“果:患者已有对应档案,跳过 */
    public static final String RESULT_EXISTS = "2";
    /** ç”Ÿæˆç»“果:未命中配置 */
    public static final String RESULT_NO_MATCH = "3";
    /** ç”Ÿæˆç»“果:失败 */
    public static final String RESULT_FAILED = "4";
    /** ä½é™¢éšè®¿æ¥æºçš„默认配置ID(未命中配置时写日志用) */
    public static final int NO_CONFIG_ID = 0;
    private SpecificArchiveConstants() {
    }
}
smartor/src/main/java/com/smartor/domain/PatChildArchive.java
@@ -30,6 +30,23 @@
    @ApiModelProperty(value = "儿科档案类型: 1 è¥å…»æ€§ç–¾ç—…2 å­¦ä¹ å›°éš¾3 é«˜å±å„¿ä¸“案")
    private String archiveType;
    /** æ¥æºç±»åž‹ï¼š1门诊接诊 2住院随访 3手工新增 */
    @Excel(name = "来源类型")
    @ApiModelProperty(value = "来源类型:1门诊接诊 2住院随访 3手工新增")
    private String sourceType;
    /** æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID */
    @ApiModelProperty(value = "来源业务ID:门诊记录ID/住院记录ID")
    private Long sourceBizId;
    /** æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 */
    @ApiModelProperty(value = "来源业务编号:门诊号/住院号")
    private String sourceBizNo;
    /** æ¥æºéšè®¿å­ä»»åŠ¡ID:住院随访生成时记录触发档案生成的 service_subtask.id */
    @ApiModelProperty(value = "来源随访子任务ID:住院随访生成时记录触发档案生成的 service_subtask.id")
    private Long sourceSubId;
    /** é—¨è¯Šç¼–号 */
    @Excel(name = "门诊编号")
    @ApiModelProperty(value = "门诊编号")
smartor/src/main/java/com/smartor/domain/PatChildArchiveDetail.java
@@ -35,11 +35,23 @@
    @ApiModelProperty(value = "档案类型: 1 è¥å…»æ€§ç–¾ç—…2 å­¦ä¹ å›°éš¾3 é«˜å±å„¿ä¸“案")
    private String archiveType;
    /** æ¥æºç±»åž‹: 1 é—¨è¯Šè®°å½• */
    /** æ¥æºç±»åž‹ï¼š1门诊接诊 2住院随访 3手工新增 */
    @Excel(name = "来源类型")
    @ApiModelProperty(value = "来源类型: 1 é—¨è¯Šè®°å½•")
    @ApiModelProperty(value = "来源类型:1门诊接诊 2住院随访 3手工新增")
    private String sourceType;
    /** æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID */
    @ApiModelProperty(value = "来源业务ID:门诊记录ID/住院记录ID")
    private Long sourceBizId;
    /** æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 */
    @ApiModelProperty(value = "来源业务编号:门诊号/住院号")
    private String sourceBizNo;
    /** æ¥æºéšè®¿å­ä»»åŠ¡ID:住院随访生成时记录触发档案生成的 service_subtask.id */
    @ApiModelProperty(value = "来源随访子任务ID:住院随访生成时记录触发档案生成的 service_subtask.id")
    private Long sourceSubId;
    /** é—¨è¯Šç¼–号 */
    @Excel(name = "门诊编号")
    @ApiModelProperty(value = "门诊编号")
smartor/src/main/java/com/smartor/domain/PatMaternityArchive.java
@@ -29,6 +29,23 @@
    @ApiModelProperty(value = "妇幼档案类型: 1 æ—©å­•关爱2 å›´ç»ç»æœŸMHI")
    private String archiveType;
    /** æ¥æºç±»åž‹ï¼š1门诊接诊 2住院随访 3手工新增 */
    @Excel(name = "来源类型")
    @ApiModelProperty(value = "来源类型:1门诊接诊 2住院随访 3手工新增")
    private String sourceType;
    /** æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID */
    @ApiModelProperty(value = "来源业务ID:门诊记录ID/住院记录ID")
    private Long sourceBizId;
    /** æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 */
    @ApiModelProperty(value = "来源业务编号:门诊号/住院号")
    private String sourceBizNo;
    /** æ¥æºéšè®¿å­ä»»åŠ¡ID:住院随访生成时记录触发档案生成的 service_subtask.id */
    @ApiModelProperty(value = "来源随访子任务ID:住院随访生成时记录触发档案生成的 service_subtask.id")
    private Long sourceSubId;
    /** é—¨è¯Šç¼–号 */
    @Excel(name = "门诊编号")
    @ApiModelProperty(value = "门诊编号")
smartor/src/main/java/com/smartor/domain/PatMaternityArchiveDetail.java
@@ -34,11 +34,23 @@
    @ApiModelProperty(value = "档案类型: 1 æ—©å­•关爱2 å›´ç»ç»æœŸMHI")
    private String archiveType;
    /** æ¥æºç±»åž‹: 1 é—¨è¯Šè®°å½• */
    /** æ¥æºç±»åž‹ï¼š1门诊接诊 2住院随访 3手工新增 */
    @Excel(name = "来源类型")
    @ApiModelProperty(value = "来源类型: 1 é—¨è¯Šè®°å½•")
    @ApiModelProperty(value = "来源类型:1门诊接诊 2住院随访 3手工新增")
    private String sourceType;
    /** æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID */
    @ApiModelProperty(value = "来源业务ID:门诊记录ID/住院记录ID")
    private Long sourceBizId;
    /** æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 */
    @ApiModelProperty(value = "来源业务编号:门诊号/住院号")
    private String sourceBizNo;
    /** æ¥æºéšè®¿å­ä»»åŠ¡ID:住院随访生成时记录触发档案生成的 service_subtask.id */
    @ApiModelProperty(value = "来源随访子任务ID:住院随访生成时记录触发档案生成的 service_subtask.id")
    private Long sourceSubId;
    /** é—¨è¯Šç¼–号 */
    @Excel(name = "门诊编号")
    @ApiModelProperty(value = "门诊编号")
smartor/src/main/java/com/smartor/domain/PatSpecificArchiveGenerateLog.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,90 @@
package com.smartor.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * ä¸“科档案生成日志对象 pat_specific_archive_generate_log。
 *
 * <p>用于住院随访完成后的幂等控制、来源追溯和补偿任务筛选。</p>
 *
 * @author ruoyi
 * @date 2026-11-11
 */
@Data
@ApiModel(value = "专科档案生成日志对象")
public class PatSpecificArchiveGenerateLog implements Serializable {
    private static final long serialVersionUID = 1L;
    /** ä¸»é”®ID */
    @ApiModelProperty(value = "主键ID")
    private Long id;
    /** æ¥æºç±»åž‹ï¼š1门诊接诊 2住院随访 */
    @ApiModelProperty(value = "来源类型:1门诊接诊 2住院随访")
    private String sourceType;
    /** æ¥æºä¸šåŠ¡ID:门诊记录ID/住院记录ID */
    @ApiModelProperty(value = "来源业务ID:门诊记录ID/住院记录ID")
    private Long sourceBizId;
    /** æ¥æºä¸šåŠ¡ç¼–å·ï¼šé—¨è¯Šå·/住院号 */
    @ApiModelProperty(value = "来源业务编号:门诊号/住院号")
    private String sourceBizNo;
    /** æ¥æºéšè®¿å­ä»»åŠ¡ID:触发档案生成的 service_subtask.id */
    @ApiModelProperty(value = "来源随访子任务ID:触发档案生成的 service_subtask.id")
    private Long sourceSubId;
    /** æ‚£è€…ID */
    @ApiModelProperty(value = "患者ID")
    private Long patid;
    /** æœºæž„ID */
    @ApiModelProperty(value = "机构ID")
    private String orgid;
    /** é™¢åŒºID */
    @ApiModelProperty(value = "院区ID")
    private String campusid;
    /** éƒ¨é—¨åˆ†ç±»ï¼š1妇科 2儿科 */
    @ApiModelProperty(value = "部门分类:1妇科 2儿科")
    private String deptCategory;
    /** æ¡£æ¡ˆç±»åž‹ */
    @ApiModelProperty(value = "档案类型")
    private String archiveType;
    /** å‘½ä¸­çš„配置ID;未命中配置时为0 */
    @ApiModelProperty(value = "命中的配置ID;未命中配置时为0")
    private Integer configId;
    /** ç”Ÿæˆæˆ–命中的档案主表ID */
    @ApiModelProperty(value = "生成或命中的档案主表ID")
    private Long archiveId;
    /** å¤„理结果:1生成 2已存在跳过 3未匹配 4失败 */
    @ApiModelProperty(value = "处理结果:1生成 2已存在跳过 3未匹配 4失败")
    private String processResult;
    /** å¤„理说明 */
    @ApiModelProperty(value = "处理说明")
    private String processMsg;
    /** é‡è¯•次数 */
    @ApiModelProperty(value = "重试次数")
    private Integer retryCount;
    /** åˆ›å»ºæ—¶é—´ */
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    /** æ›´æ–°æ—¶é—´ */
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;
}
smartor/src/main/java/com/smartor/listener/InhospFollowupArchiveListener.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,42 @@
package com.smartor.listener;
import com.ruoyi.common.core.event.FollowupCompletedEvent;
import com.smartor.service.IPatSpecificArchiveGenerateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
/**
 * éšè®¿å®Œæˆç”Ÿæˆä¸“科档案监听器。
 *
 * <p>使用 AFTER_COMMIT ä¿è¯éšè®¿å®ŒæˆçŠ¶æ€å·²è½åº“ï¼›å¼‚å¸¸åªè®°å½•æ—¥å¿—ï¼Œä¸å½±å“éšè®¿ä¸»æµç¨‹ã€‚</p>
 *
 * @author ruoyi
 * @date 2026-11-11
 */
@Slf4j
@Component
public class InhospFollowupArchiveListener {
    @Autowired
    private IPatSpecificArchiveGenerateService patSpecificArchiveGenerateService;
    @Async("threadPoolTaskExecutor")
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
    public void onFollowupCompleted(FollowupCompletedEvent event) {
        if (event == null || event.getSubId() == null) {
            return;
        }
        try {
            int generated = patSpecificArchiveGenerateService.generateByInhospFollowup(event.getSubId());
            if (generated > 0) {
                log.info("住院随访完成生成专科档案成功,subId={},生成数量={}", event.getSubId(), generated);
            }
        } catch (Throwable e) {
            log.error("住院随访完成生成专科档案失败,subId={}", event.getSubId(), e);
        }
    }
}
smartor/src/main/java/com/smartor/mapper/PatSpecificArchiveGenerateLogMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
package com.smartor.mapper;
import com.smartor.domain.PatSpecificArchiveGenerateLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
 * ä¸“科档案生成日志Mapper接口。
 *
 * @author ruoyi
 * @date 2026-11-11
 */
@Mapper
public interface PatSpecificArchiveGenerateLogMapper {
    /**
     * æŒ‰æ¥æº + éšè®¿å­ä»»åŠ¡ + é…ç½®æŸ¥è¯¢æ—¥å¿—。
     *
     * @param sourceType  æ¥æºç±»åž‹
     * @param sourceSubId æ¥æºéšè®¿å­ä»»åŠ¡ID
     * @param configId    é…ç½®ID,未命中配置传0
     * @return æ—¥å¿—记录,不存在返回 null
     */
    PatSpecificArchiveGenerateLog selectBySourceSubAndConfig(@Param("sourceType") String sourceType,
                                                             @Param("sourceSubId") Long sourceSubId,
                                                             @Param("configId") Integer configId);
    /**
     * æŸ¥è¯¢æ¥æºéšè®¿å­ä»»åŠ¡ä¸‹æ˜¯å¦å·²æœ‰æˆåŠŸ/跳过/未匹配的结果。
     *
     * @param sourceType  æ¥æºç±»åž‹
     * @param sourceSubId æ¥æºéšè®¿å­ä»»åŠ¡ID
     * @return å·²å¤„理条数
     */
    int countProcessedBySourceSub(@Param("sourceType") String sourceType,
                                  @Param("sourceSubId") Long sourceSubId);
    int insertPatSpecificArchiveGenerateLog(PatSpecificArchiveGenerateLog log);
    int updatePatSpecificArchiveGenerateLog(PatSpecificArchiveGenerateLog log);
}
smartor/src/main/java/com/smartor/service/IPatSpecificArchiveGenerateLogService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,18 @@
package com.smartor.service;
import com.smartor.domain.PatSpecificArchiveGenerateLog;
/**
 * ä¸“科档案生成日志Service接口。
 *
 * @author ruoyi
 * @date 2026-11-11
 */
public interface IPatSpecificArchiveGenerateLogService {
    PatSpecificArchiveGenerateLog selectBySourceSubAndConfig(String sourceType, Long sourceSubId, Integer configId);
    boolean existsProcessedBySourceSub(String sourceType, Long sourceSubId);
    int saveOrUpdate(PatSpecificArchiveGenerateLog log);
}
smartor/src/main/java/com/smartor/service/IPatSpecificArchiveGenerateService.java
@@ -19,4 +19,22 @@
     * @return æœ¬æ¬¡ç”Ÿæˆ/更新的档案数量
     */
    int generateByOuthosp(PatMedOuthosp patMedOuthosp, PatArchive patArchive);
    /**
     * æ ¹æ®ä½é™¢éšè®¿å­ä»»åŠ¡ç”Ÿæˆä¸“ç§‘æ¡£æ¡ˆã€‚
     *
     * <p>仅处理已完成的住院随访(hosp_type 2/6 + service_type ç™½åå•),
     * ä¸”仅对丽水市妇幼保健院生效。生成前按“患者 + ä¸“ç§‘ + æ¡£æ¡ˆç±»åž‹â€åˆ¤æ–­æ˜¯å¦å·²æœ‰æ¡£æ¡ˆã€‚</p>
     *
     * @param subId éšè®¿å­ä»»åŠ¡ID
     * @return æœ¬æ¬¡ç”Ÿæˆæ•°é‡
     */
    int generateByInhospFollowup(Long subId);
    /**
     * è¡¥å¿æ‰«æï¼šæŸ¥è¯¢è¿‘ 7 å¤©å·²å®Œæˆä½†å°šæœªå¤„理的住院随访并尝试生成档案。
     *
     * @return æœ¬æ¬¡ç”Ÿæˆæ•°é‡
     */
    int compensateInhospFollowups();
}
smartor/src/main/java/com/smartor/service/impl/PatChildArchiveServiceImpl.java
@@ -88,8 +88,9 @@
            log.error("insertOrUpdateChildArchive入参为空,请检查入参");
            throw new BaseException("儿科档案入参为空,请检查入参");
        }
        if (StringUtils.isEmpty(patChildArchiveDetail.getOuthospno())) {
            throw new BaseException("儿科档案入参门诊编号outhospno为空,请检查入参门诊编号");
        if (StringUtils.isEmpty(patChildArchiveDetail.getOuthospno())
                && StringUtils.isEmpty(patChildArchiveDetail.getInhospno())) {
            throw new BaseException("儿科档案入参门诊编号outhospno和住院编号inhospno不能同时为空");
        }
        if (StringUtils.isEmpty(patChildArchiveDetail.getArchiveType())) {
            throw new BaseException("儿科档案入参档案类型archiveType为空,请检查入参档案类型");
@@ -100,6 +101,7 @@
        key.setOrgid(patChildArchiveDetail.getOrgid());
        key.setPatid(patChildArchiveDetail.getPatid());
        key.setOuthospno(patChildArchiveDetail.getOuthospno());
        key.setInhospno(patChildArchiveDetail.getInhospno());
        key.setArchiveType(patChildArchiveDetail.getArchiveType());
        List<PatChildArchiveDetail> olds =
                patChildArchiveDetailService.selectPatChildArchiveDetailList(key);
@@ -117,6 +119,7 @@
            mainKey.setOrgid(patChildArchiveDetail.getOrgid());
            mainKey.setPatid(patChildArchiveDetail.getPatid());
            mainKey.setOuthospno(patChildArchiveDetail.getOuthospno());
            mainKey.setInhospno(patChildArchiveDetail.getInhospno());
            mainKey.setArchiveType(patChildArchiveDetail.getArchiveType());
            List<PatChildArchive> mainOlds =
                    patChildArchiveMapper.selectPatChildArchiveList(mainKey);
@@ -133,6 +136,17 @@
        }
        // æ–°å¢žæ¡£æ¡ˆæ—¶è¡¥é»˜è®¤æ¥æºï¼Œæ›´æ–°æ—¶ä¿ç•™åŽŸæ¥æº
        if (existArchiveId == null && patChildArchiveDetail.getId() == null) {
            if (StringUtils.isEmpty(patChildArchiveDetail.getSourceType())) {
                patChildArchiveDetail.setSourceType("3");
            }
            if (StringUtils.isEmpty(patChildArchiveDetail.getSourceBizNo())) {
                patChildArchiveDetail.setSourceBizNo(StringUtils.isNotEmpty(patChildArchiveDetail.getOuthospno())
                        ? patChildArchiveDetail.getOuthospno() : patChildArchiveDetail.getInhospno());
            }
        }
        // å°†è¯¦æƒ…中的公共字段复制到主表对象
        PatChildArchive patChildArchive = DtoConversionUtils.sourceToTarget(patChildArchiveDetail, PatChildArchive.class);
        if (patChildArchive == null) {
smartor/src/main/java/com/smartor/service/impl/PatMaternityArchiveServiceImpl.java
@@ -99,13 +99,15 @@
        patMaternityArchiveDetailVo.setOrgid(patMaternityArchiveDetail.getOrgid());
        patMaternityArchiveDetailVo.setPatid(patMaternityArchiveDetail.getPatid());
        patMaternityArchiveDetailVo.setOuthospno(patMaternityArchiveDetail.getOuthospno());
        patMaternityArchiveDetailVo.setInhospno(patMaternityArchiveDetail.getInhospno());
        patMaternityArchiveDetailVo.setArchiveType(patMaternityArchiveDetail.getArchiveType());
        List<PatMaternityArchiveDetail> patMaternityArchiveDetailOlds
                = patMaternityArchiveDetailService.selectPatMaternityArchiveDetailList(patMaternityArchiveDetailVo);
        if (StringUtils.isEmpty(patMaternityArchiveDetail.getOuthospno())) {
            throw new BaseException("妇科档案入参门诊编号outhospno为空,请检查入参门诊编号");
        if (StringUtils.isEmpty(patMaternityArchiveDetail.getOuthospno())
                && StringUtils.isEmpty(patMaternityArchiveDetail.getInhospno())) {
            throw new BaseException("妇科档案入参门诊编号outhospno和住院编号inhospno不能同时为空");
        }
        if (StringUtils.isEmpty(patMaternityArchiveDetail.getArchiveType())) {
            throw new BaseException("妇科档案入参档案类型archiveType为空,请检查入参档案类型");
@@ -116,6 +118,7 @@
        key.setOrgid(patMaternityArchiveDetail.getOrgid());
        key.setPatid(patMaternityArchiveDetail.getPatid());
        key.setOuthospno(patMaternityArchiveDetail.getOuthospno());
        key.setInhospno(patMaternityArchiveDetail.getInhospno());
        key.setArchiveType(patMaternityArchiveDetail.getArchiveType());
        List<PatMaternityArchiveDetail> olds =
                patMaternityArchiveDetailService.selectPatMaternityArchiveDetailList(key);
@@ -133,6 +136,7 @@
            mainKey.setOrgid(patMaternityArchiveDetail.getOrgid());
            mainKey.setPatid(patMaternityArchiveDetail.getPatid());
            mainKey.setOuthospno(patMaternityArchiveDetail.getOuthospno());
            mainKey.setInhospno(patMaternityArchiveDetail.getInhospno());
            mainKey.setArchiveType(patMaternityArchiveDetail.getArchiveType());
            List<PatMaternityArchive> mainOlds =
                    patMaternityArchiveMapper.selectPatMaternityArchiveList(mainKey);
@@ -156,6 +160,17 @@
            }
        }
        // æ–°å¢žæ¡£æ¡ˆæ—¶è¡¥é»˜è®¤æ¥æºï¼Œæ›´æ–°æ—¶ä¿ç•™åŽŸæ¥æº
        if (existArchiveId == null && patMaternityArchiveDetail.getId() == null) {
            if (StringUtils.isEmpty(patMaternityArchiveDetail.getSourceType())) {
                patMaternityArchiveDetail.setSourceType("3");
            }
            if (StringUtils.isEmpty(patMaternityArchiveDetail.getSourceBizNo())) {
                patMaternityArchiveDetail.setSourceBizNo(StringUtils.isNotEmpty(patMaternityArchiveDetail.getOuthospno())
                        ? patMaternityArchiveDetail.getOuthospno() : patMaternityArchiveDetail.getInhospno());
            }
        }
        // å°†è¯¦æƒ…中的公共字段复制到主表对象
        PatMaternityArchive patMaternityArchive = DtoConversionUtils.sourceToTarget(patMaternityArchiveDetail, PatMaternityArchive.class);
        if (patMaternityArchive == null) {
smartor/src/main/java/com/smartor/service/impl/PatSpecificArchiveGenerateLogServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,74 @@
package com.smartor.service.impl;
import com.smartor.domain.PatSpecificArchiveGenerateLog;
import com.smartor.mapper.PatSpecificArchiveGenerateLogMapper;
import com.smartor.service.IPatSpecificArchiveGenerateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
 * ä¸“科档案生成日志Service业务层处理。
 *
 * @author ruoyi
 * @date 2026-11-11
 */
@Service
public class PatSpecificArchiveGenerateLogServiceImpl implements IPatSpecificArchiveGenerateLogService {
    @Autowired
    private PatSpecificArchiveGenerateLogMapper logMapper;
    @Override
    public PatSpecificArchiveGenerateLog selectBySourceSubAndConfig(String sourceType, Long sourceSubId, Integer configId) {
        return logMapper.selectBySourceSubAndConfig(sourceType, sourceSubId,
                configId == null ? 0 : configId);
    }
    @Override
    public boolean existsProcessedBySourceSub(String sourceType, Long sourceSubId) {
        return logMapper.countProcessedBySourceSub(sourceType, sourceSubId) > 0;
    }
    @Override
    public int saveOrUpdate(PatSpecificArchiveGenerateLog log) {
        if (log == null) {
            return 0;
        }
        if (log.getSourceType() == null) {
            log.setSourceType("2");
        }
        if (log.getConfigId() == null) {
            log.setConfigId(0);
        }
        if (log.getRetryCount() == null) {
            log.setRetryCount(0);
        }
        Date now = new Date();
        log.setUpdateTime(now);
        PatSpecificArchiveGenerateLog old = logMapper.selectBySourceSubAndConfig(
                log.getSourceType(), log.getSourceSubId(), log.getConfigId());
        if (old == null) {
            log.setCreateTime(now);
            try {
                return logMapper.insertPatSpecificArchiveGenerateLog(log);
            } catch (DuplicateKeyException e) {
                // å¹¶å‘下另一个线程已写入,转为更新,保证幂等
                old = logMapper.selectBySourceSubAndConfig(
                        log.getSourceType(), log.getSourceSubId(), log.getConfigId());
                if (old == null) {
                    throw e;
                }
                log.setId(old.getId());
                return logMapper.updatePatSpecificArchiveGenerateLog(log);
            }
        }
        log.setId(old.getId());
        if (log.getCreateTime() == null) {
            log.setCreateTime(old.getCreateTime());
        }
        return logMapper.updatePatSpecificArchiveGenerateLog(log);
    }
}
smartor/src/main/java/com/smartor/service/impl/PatSpecificArchiveGenerateServiceImpl.java
@@ -3,20 +3,31 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.core.domain.entity.PatArchive;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.inhospvisit.api.InhospVisitFacade;
import com.ruoyi.inhospvisit.domain.PatMedInhosp;
import com.ruoyi.outpatientvisit.domain.PatMedOuthosp;
import com.ruoyi.patarchive.domain.PatSpecificArchiveGenerateConfig;
import com.ruoyi.patarchive.mapper.PatArchiveMapper;
import com.ruoyi.patarchive.service.IPatSpecificArchiveGenerateConfigService;
import com.ruoyi.task.api.TaskSubtaskApi;
import com.ruoyi.task.domain.ServiceSubtask;
import com.ruoyi.task.service.IServiceSubtaskService;
import com.smartor.common.SpecificArchiveConstants;
import com.smartor.domain.PatChildArchive;
import com.smartor.domain.PatChildArchiveDetail;
import com.smartor.domain.PatMaternityArchive;
import com.smartor.domain.PatMaternityArchiveDetail;
import com.smartor.domain.PatSpecificArchiveGenerateLog;
import com.smartor.service.IPatChildArchiveService;
import com.smartor.service.IPatMaternityArchiveService;
import com.smartor.service.IPatSpecificArchiveGenerateLogService;
import com.smartor.service.IPatSpecificArchiveGenerateService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -26,27 +37,37 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
 * ä¸“科档案生成Service业务层处理。
 *
 * <p>只处理丽水市妇幼保健院(orgid = 47226079133110211G1001)的门诊接诊完成记录,
 * æŒ‰ {@code pat_specific_archive_generate_config} é…ç½®åŒ¹é…ç§‘室和诊断后,
 * ç”Ÿæˆå¯¹åº”类型的妇科档案或儿科档案。</p>
 * <p>只处理丽水市妇幼保健院(orgid = 47226079133110211G1001):</p>
 * <ul>
 *     <li>门诊接诊完成:按科室/诊断匹配配置后生成妇科/儿科档案;</li>
 *     <li>住院随访完成:按出院/在院科室、病区、诊断匹配配置后生成妇科/儿科档案,
 *     ç”Ÿæˆå‰æŒ‰â€œæ‚£è€… + ä¸“ç§‘ + æ¡£æ¡ˆç±»åž‹â€åˆ¤æ–­æ˜¯å¦å·²æœ‰å¯¹åº”档案,已有则跳过。</li>
 * </ul>
 */
@Slf4j
@Service
public class PatSpecificArchiveGenerateServiceImpl implements IPatSpecificArchiveGenerateService {
    /** éƒ¨é—¨åˆ†ç±»ï¼šå¦‡ç§‘ */
    private static final String DEPT_CATEGORY_GYNECOLOGY = "1";
    /** éƒ¨é—¨åˆ†ç±»ï¼šå„¿ç§‘ */
    private static final String DEPT_CATEGORY_PEDIATRICS = "2";
    /** éƒ¨é—¨ç±»åž‹ï¼šç§‘室 */
    private static final String DEPT_TYPE_DEPARTMENT = "1";
    /** æ¥æºç±»åž‹ï¼šé—¨è¯Šè®°å½• */
    private static final String SOURCE_TYPE_OUTHOSP = "1";
    /** éƒ¨é—¨ç±»åž‹ï¼šç—…区 */
    private static final String DEPT_TYPE_WARD = "2";
    /** å°±è¯Šç±»åž‹ï¼šå‡ºé™¢ */
    private static final String HOSP_TYPE_DISCHARGE = "2";
    /** å°±è¯Šç±»åž‹ï¼šä½é™¢/入院 */
    private static final String HOSP_TYPE_INHOSP = "6";
    /** ä½é™¢éšè®¿å®ŒæˆçŠ¶æ€ */
    private static final Long SEND_STATE_FINISHED = 6L;
    /** ä½é™¢éšè®¿æ¡£æ¡ˆç”Ÿæˆçš„æœ€å¤§é‡è¯•次数 */
    private static final int MAX_RETRY = 3;
    /** Redis é”å‰ç¼€ */
    private static final String LOCK_PREFIX = "lock:archive:inhosp:";
    @Autowired
    private IPatSpecificArchiveGenerateConfigService patSpecificArchiveGenerateConfigService;
@@ -58,7 +79,32 @@
    private IPatChildArchiveService patChildArchiveService;
    @Autowired
    private IPatSpecificArchiveGenerateLogService patSpecificArchiveGenerateLogService;
    @Autowired
    private PatArchiveMapper patArchiveMapper;
    @Autowired
    private IServiceSubtaskService serviceSubtaskService;
    @Autowired
    private InhospVisitFacade inhospVisitFacade;
    @Autowired
    private TaskSubtaskApi taskSubtaskApi;
    @Autowired
    private RedisCache redisCache;
    /**
     * ä½é™¢éšè®¿æœåŠ¡ç±»åž‹ç™½åå•ï¼Œé»˜è®¤å‡ºé™¢éšè®¿ã€ä¸“ç§‘éšè®¿ã€å…¥é™¢éšè®¿ã€æ‰‹æœ¯éšè®¿ã€‚
     */
    @Value("${archive.inhosp.followup.service-types:2,13,18,19}")
    private String inhospFollowupServiceTypes;
    /** ä½é™¢éšè®¿ç”Ÿæˆä¸“科档案开关,默认开启,便于按机构灰度。 */
    @Value("${archive.inhosp.followup.enabled:true}")
    private boolean inhospFollowupEnabled;
    @Override
    public int generateByOuthosp(PatMedOuthosp patMedOuthosp, PatArchive patArchive) {
@@ -86,7 +132,7 @@
        }
        String campusid = StringUtils.isNotBlank(patMedOuthosp.getCampusid())
                ? patMedOuthosp.getCampusid() : "1";
                ? patMedOuthosp.getCampusid() : SpecificArchiveConstants.DEFAULT_CAMPUS_ID;
        List<PatSpecificArchiveGenerateConfig> configs =
                patSpecificArchiveGenerateConfigService.selectEffectiveConfigList(patMedOuthosp.getOrgid(), campusid);
        if (CollectionUtils.isEmpty(configs)) {
@@ -99,7 +145,8 @@
        Set<String> generatedKeys = new HashSet<>();
        int generatedCount = 0;
        for (PatSpecificArchiveGenerateConfig config : configs) {
            if (!matchConfig(config, patMedOuthosp)) {
            if (!matchConfig(config, patMedOuthosp.getDeptcode(), null,
                    patMedOuthosp.getIcd10code(), patMedOuthosp.getDiagname())) {
                continue;
            }
            String archiveType = config.getArchiveType();
@@ -116,12 +163,12 @@
            }
            try {
                if (DEPT_CATEGORY_GYNECOLOGY.equals(deptCategory)) {
                if (SpecificArchiveConstants.DEPT_CATEGORY_GYNECOLOGY.equals(deptCategory)) {
                    PatMaternityArchiveDetail detail =
                            buildMaternityDetail(patMedOuthosp, targetArchive, config, campusid);
                    patMaternityArchiveService.insertOrUpdateMaternityArchive(detail);
                    generatedCount++;
                } else if (DEPT_CATEGORY_PEDIATRICS.equals(deptCategory)) {
                } else if (SpecificArchiveConstants.DEPT_CATEGORY_PEDIATRICS.equals(deptCategory)) {
                    PatChildArchiveDetail detail =
                            buildChildDetail(patMedOuthosp, targetArchive, config, campusid);
                    patChildArchiveService.insertOrUpdateChildArchive(detail);
@@ -138,12 +185,276 @@
        return generatedCount;
    }
    @Override
    public int generateByInhospFollowup(Long subId) {
        if (!inhospFollowupEnabled || subId == null) {
            return 0;
        }
        ServiceSubtask subtask = serviceSubtaskService.selectServiceSubtaskById(subId);
        if (subtask == null || !SEND_STATE_FINISHED.equals(subtask.getSendstate())) {
            return 0;
        }
        if (!isInhospFollowup(subtask)) {
            return 0;
        }
        // ä»…限丽水妇幼,机构为空时用住院记录/患者档案兜底
        PatMedInhosp inhosp = resolveInhosp(subtask);
        PatArchive patArchive = resolvePatArchive(subtask.getPatid(), inhosp);
        String orgid = firstNotBlank(subtask.getOrgid(),
                inhosp == null ? null : inhosp.getOrgid(),
                patArchive == null ? null : patArchive.getOrgid());
        if (!SpecificArchiveConstants.LISHUI_MCH_ORG_ID.equals(orgid)) {
            log.debug("住院随访生成专科档案跳过:非丽水妇幼机构,subId={},orgid={}", subId, orgid);
            return 0;
        }
        Long patid = firstNonNull(subtask.getPatid(),
                inhosp == null ? null : inhosp.getPatid(),
                patArchive == null ? null : patArchive.getId());
        if (patid == null) {
            log.warn("住院随访生成专科档案跳过:未找到患者,subId={},inhospid={}", subId, subtask.getInhospid());
            return 0;
        }
        if (patArchive == null) {
            patArchive = patArchiveMapper.selectPatArchiveByPatid(patid);
        }
        String campusid = firstNotBlank(subtask.getCampusid(),
                inhosp == null ? null : inhosp.getCampusid(),
                patArchive == null ? null : patArchive.getCampusid(),
                SpecificArchiveConstants.DEFAULT_CAMPUS_ID);
        boolean admission = HOSP_TYPE_INHOSP.equals(subtask.getHospType());
        String deptCode = admission
                ? firstNotBlank(inhosp == null ? null : inhosp.getDeptcode(), subtask.getDeptcode(),
                subtask.getVisitDeptCode(), subtask.getLeaveldeptcode())
                : firstNotBlank(inhosp == null ? null : inhosp.getLeaveldeptcode(), subtask.getLeaveldeptcode(),
                subtask.getVisitDeptCode(), inhosp == null ? null : inhosp.getDeptcode());
        String deptName = admission
                ? firstNotBlank(inhosp == null ? null : inhosp.getDeptname(), subtask.getDeptname(),
                subtask.getVisitDeptName(), subtask.getLeaveldeptname())
                : firstNotBlank(inhosp == null ? null : inhosp.getLeaveldeptname(), subtask.getLeaveldeptname(),
                subtask.getVisitDeptName(), inhosp == null ? null : inhosp.getDeptname());
        String wardCode = admission
                ? firstNotBlank(inhosp == null ? null : inhosp.getHospitaldistrictcode(),
                subtask.getHospitaldistrictcode(), subtask.getLeavehospitaldistrictcode())
                : firstNotBlank(inhosp == null ? null : inhosp.getLeavehospitaldistrictcode(),
                subtask.getLeavehospitaldistrictcode(), subtask.getHospitaldistrictcode());
        String wardName = admission
                ? firstNotBlank(inhosp == null ? null : inhosp.getHospitaldistrictname(),
                subtask.getHospitaldistrictname(), subtask.getLeavehospitaldistrictname())
                : firstNotBlank(inhosp == null ? null : inhosp.getLeavehospitaldistrictname(),
                subtask.getLeavehospitaldistrictname(), subtask.getHospitaldistrictname());
        String icd10Code = admission
                ? firstNotBlank(inhosp == null ? null : inhosp.getIcd10code(), subtask.getLeaveicd10code())
                : firstNotBlank(inhosp == null ? null : inhosp.getLeaveicd10code(),
                subtask.getLeaveicd10code(), inhosp == null ? null : inhosp.getIcd10code());
        String diagName = admission
                ? firstNotBlank(inhosp == null ? null : inhosp.getDiagname(), subtask.getDiagname())
                : firstNotBlank(inhosp == null ? null : inhosp.getLeavediagname(),
                subtask.getLeavediagname(), inhosp == null ? null : inhosp.getDiagname());
        InhospArchiveContext context = new InhospArchiveContext();
        context.subtask = subtask;
        context.inhosp = inhosp;
        context.patArchive = patArchive;
        context.patid = patid;
        context.orgid = orgid;
        context.campusid = campusid;
        context.deptCode = deptCode;
        context.deptName = deptName;
        context.wardCode = wardCode;
        context.wardName = wardName;
        context.icd10Code = icd10Code;
        context.diagName = diagName;
        context.diagTime = firstDate(subtask.getFinishtime(), inhosp == null ? null : inhosp.getEndtime());
        List<PatSpecificArchiveGenerateConfig> configs =
                patSpecificArchiveGenerateConfigService.selectEffectiveConfigList(orgid, campusid);
        if (CollectionUtils.isEmpty(configs)) {
            recordLog(context, null, null, null, SpecificArchiveConstants.RESULT_NO_MATCH, null,
                    "机构未配置档案生成规则");
            return 0;
        }
        Set<String> generatedKeys = new HashSet<>();
        int generatedCount = 0;
        boolean anyMatched = false;
        for (PatSpecificArchiveGenerateConfig config : configs) {
            String archiveType = config.getArchiveType();
            String deptCategory = config.getDeptCategory();
            if (StringUtils.isBlank(archiveType) || StringUtils.isBlank(deptCategory)) {
                log.warn("住院随访生成专科档案跳过:配置不完整,configId={},deptCategory={},archiveType={}",
                        config.getId(), deptCategory, archiveType);
                continue;
            }
            if (!matchConfig(config, deptCode, wardCode, icd10Code, diagName)) {
                continue;
            }
            anyMatched = true;
            String generatedKey = deptCategory + "|" + archiveType;
            if (!generatedKeys.add(generatedKey)) {
                continue;
            }
            if (alreadyProcessed(subId, config.getId())) {
                continue;
            }
            String lockKey = LOCK_PREFIX + orgid + ":" + patid + ":" + deptCategory + ":" + archiveType;
            boolean locked = false;
            try {
                locked = redisCache.setCacheObjectIfAbsent(lockKey, "1", 30, TimeUnit.SECONDS);
            } catch (Exception e) {
                // Redis ä¸å¯ç”¨æ—¶ fail-open,依赖生成日志和数据库查询兜底,避免档案生成整体停摆
                locked = true;
                log.warn("住院随访生成专科档案获取Redis锁异常,降级为无锁执行,subId={},lockKey={}", subId, lockKey, e);
            }
            if (!locked) {
                // æœªæ‹¿åˆ°é”æ—¶ç”±è¡¥å¿ä»»åŠ¡é‡è¯•ï¼Œé¿å…å¹¶å‘é‡å¤ç”Ÿæˆ
                log.info("住院随访生成专科档案未获取到锁,等待补偿重试,subId={},lockKey={}", subId, lockKey);
                recordLog(context, config, deptCategory, archiveType, SpecificArchiveConstants.RESULT_FAILED,
                        null, "获取生成锁失败");
                continue;
            }
            try {
                Long existingArchiveId = findExistingArchiveId(orgid, patid, deptCategory, archiveType);
                if (existingArchiveId != null) {
                    recordLog(context, config, deptCategory, archiveType,
                            SpecificArchiveConstants.RESULT_EXISTS, existingArchiveId, "患者已有对应档案,跳过生成");
                    continue;
                }
                Long archiveId;
                if (SpecificArchiveConstants.DEPT_CATEGORY_GYNECOLOGY.equals(deptCategory)) {
                    PatMaternityArchiveDetail detail = buildInhospMaternityDetail(context, config);
                    archiveId = (long) patMaternityArchiveService.insertOrUpdateMaternityArchive(detail);
                } else if (SpecificArchiveConstants.DEPT_CATEGORY_PEDIATRICS.equals(deptCategory)) {
                    PatChildArchiveDetail detail = buildInhospChildDetail(context, config);
                    archiveId = (long) patChildArchiveService.insertOrUpdateChildArchive(detail);
                } else {
                    log.warn("住院随访生成专科档案跳过:未知部门分类,configId={},deptCategory={}",
                            config.getId(), deptCategory);
                    continue;
                }
                recordLog(context, config, deptCategory, archiveType,
                        SpecificArchiveConstants.RESULT_GENERATED, archiveId, "生成成功");
                generatedCount++;
            } catch (Exception e) {
                log.error("住院随访生成专科档案失败,subId={},configId={},deptCategory={},archiveType={}",
                        subId, config.getId(), deptCategory, archiveType, e);
                recordLog(context, config, deptCategory, archiveType,
                        SpecificArchiveConstants.RESULT_FAILED, null, truncateMsg(e.getMessage()));
            } finally {
                if (locked) {
                    try {
                        redisCache.deleteObject(lockKey);
                    } catch (Exception e) {
                        log.warn("住院随访生成专科档案释放Redis锁异常,lockKey={}", lockKey, e);
                    }
                }
            }
        }
        if (!anyMatched) {
            recordLog(context, null, null, null, SpecificArchiveConstants.RESULT_NO_MATCH, null,
                    "未命中科室/病区/诊断配置");
        }
        return generatedCount;
    }
    @Override
    public int compensateInhospFollowups() {
        if (!inhospFollowupEnabled) {
            return 0;
        }
        List<String> serviceTypes = parseCsv(inhospFollowupServiceTypes);
        if (CollectionUtils.isEmpty(serviceTypes)) {
            return 0;
        }
        Date startTime = new Date(System.currentTimeMillis() - 7L * 24 * 60 * 60 * 1000);
        List<ServiceSubtask> subtasks = taskSubtaskApi.findCompletedInhospFollowups(
                SpecificArchiveConstants.LISHUI_MCH_ORG_ID, serviceTypes, startTime, 200);
        if (CollectionUtils.isEmpty(subtasks)) {
            return 0;
        }
        int generated = 0;
        for (ServiceSubtask subtask : subtasks) {
            if (subtask.getId() == null
                    || patSpecificArchiveGenerateLogService.existsProcessedBySourceSub(
                    SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP, subtask.getId())) {
                continue;
            }
            try {
                generated += generateByInhospFollowup(subtask.getId());
            } catch (Exception e) {
                log.error("补偿生成住院随访专科档案失败,subId={}", subtask.getId(), e);
            }
        }
        return generated;
    }
    /**
     * åˆ¤æ–­é—¨è¯Šè®°å½•是否命中配置。
     * åˆ¤æ–­éšè®¿å­ä»»åŠ¡æ˜¯å¦å±žäºŽéœ€è¦ç”Ÿæˆæ¡£æ¡ˆçš„ä½é™¢éšè®¿ã€‚
     */
    private boolean isInhospFollowup(ServiceSubtask subtask) {
        if (!HOSP_TYPE_DISCHARGE.equals(subtask.getHospType())
                && !HOSP_TYPE_INHOSP.equals(subtask.getHospType())) {
            return false;
        }
        if (StringUtils.isBlank(subtask.getServiceType())) {
            return false;
        }
        return parseCsv(inhospFollowupServiceTypes).contains(subtask.getServiceType().trim());
    }
    private boolean alreadyProcessed(Long subId, Long configId) {
        int cid = configId == null ? SpecificArchiveConstants.NO_CONFIG_ID : configId.intValue();
        PatSpecificArchiveGenerateLog old = patSpecificArchiveGenerateLogService
                .selectBySourceSubAndConfig(SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP, subId, cid);
        if (old == null) {
            return false;
        }
        if (SpecificArchiveConstants.RESULT_FAILED.equals(old.getProcessResult())) {
            return old.getRetryCount() != null && old.getRetryCount() >= MAX_RETRY;
        }
        return true;
    }
    /**
     * æŸ¥è¯¢æ‚£è€…是否已有对应专科档案。
     *
     * <p>用户确认口径:按“专科 + æ¡£æ¡ˆç±»åž‹â€åˆ¤æ–­ã€‚妇科、儿科分表存储,因此妇科查妇科表,
     * å„¿ç§‘查儿科表,再按档案类型区分。</p>
     */
    private Long findExistingArchiveId(String orgid, Long patid, String deptCategory, String archiveType) {
        if (SpecificArchiveConstants.DEPT_CATEGORY_GYNECOLOGY.equals(deptCategory)) {
            PatMaternityArchive query = new PatMaternityArchive();
            query.setOrgid(orgid);
            query.setPatid(patid);
            query.setArchiveType(archiveType);
            List<PatMaternityArchive> list = patMaternityArchiveService.selectPatMaternityArchiveList(query);
            return CollectionUtils.isNotEmpty(list) ? list.get(0).getId() : null;
        }
        if (SpecificArchiveConstants.DEPT_CATEGORY_PEDIATRICS.equals(deptCategory)) {
            PatChildArchive query = new PatChildArchive();
            query.setOrgid(orgid);
            query.setPatid(patid);
            query.setArchiveType(archiveType);
            List<PatChildArchive> list = patChildArchiveService.selectPatChildArchiveList(query);
            return CollectionUtils.isNotEmpty(list) ? list.get(0).getId() : null;
        }
        return null;
    }
    /**
     * åˆ¤æ–­ç§‘室/病区、诊断是否命中配置。
     *
     * <p>部门条件与诊断条件为 OR å…³ç³»ï¼šä»»ä¸€æ¡ä»¶å‘½ä¸­å³ç”Ÿæˆï¼›ä¸¤ä¸ªé›†åˆéƒ½ä¸ºç©ºæ—¶é…ç½®æ— æ•ˆã€‚</p>
     */
    private boolean matchConfig(PatSpecificArchiveGenerateConfig config, PatMedOuthosp patMedOuthosp) {
    private boolean matchConfig(PatSpecificArchiveGenerateConfig config, String deptCode, String wardCode,
                                String icd10Code, String diagName) {
        List<String> deptCodes = parseCodes(config.getDeptCodes());
        List<String> icd10Codes = parseCodes(config.getIcd10Codes());
        if (CollectionUtils.isEmpty(deptCodes) && CollectionUtils.isEmpty(icd10Codes)) {
@@ -152,22 +463,21 @@
        boolean deptMatched = false;
        if (CollectionUtils.isNotEmpty(deptCodes)) {
            // é—¨è¯Šè®°å½•只有科室,没有病区;dept_type=2(病区)不参与门诊匹配
            if (DEPT_TYPE_DEPARTMENT.equals(config.getDeptType())) {
                deptMatched = containsIgnoreCase(deptCodes, patMedOuthosp.getDeptcode());
                deptMatched = containsIgnoreCase(deptCodes, deptCode);
            } else if (DEPT_TYPE_WARD.equals(config.getDeptType())) {
                deptMatched = containsIgnoreCase(deptCodes, wardCode);
            }
        }
        boolean diagnosisMatched = false;
        if (CollectionUtils.isNotEmpty(icd10Codes)) {
            String icd10code = patMedOuthosp.getIcd10code();
            String diagname = patMedOuthosp.getDiagname();
            diagnosisMatched = icd10Codes.stream().anyMatch(code -> {
                if (equalsIgnoreCase(code, icd10code)) {
                if (equalsIgnoreCase(code, icd10Code)) {
                    return true;
                }
                // éƒ¨åˆ† HIS æ•°æ®åªæœ‰è¯Šæ–­åç§°æ²¡æœ‰è¯Šæ–­ç ï¼Œæ­¤æ—¶å…è®¸æŒ‰è¯Šæ–­åç§°å…œåº•匹配
                return StringUtils.isBlank(icd10code) && equalsIgnoreCase(code, diagname);
                return StringUtils.isBlank(icd10Code) && equalsIgnoreCase(code, diagName);
            });
        }
@@ -179,7 +489,9 @@
        PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail();
        detail.setArchiveType(config.getArchiveType());
        detail.setFollowupPeriod(config.getFollowupPeriod());
        detail.setSourceType(SOURCE_TYPE_OUTHOSP);
        detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_OUTHOSP);
        detail.setSourceBizId(patMedOuthosp.getId());
        detail.setSourceBizNo(patMedOuthosp.getOuthospno());
        fillCommonDetail(detail, patMedOuthosp, patArchive, campusid);
        if (patArchive != null) {
            detail.setAddress(patArchive.getPlaceOfResidence());
@@ -192,7 +504,9 @@
        PatChildArchiveDetail detail = new PatChildArchiveDetail();
        detail.setArchiveType(config.getArchiveType());
        detail.setFollowupPeriod(config.getFollowupPeriod());
        detail.setSourceType(SOURCE_TYPE_OUTHOSP);
        detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_OUTHOSP);
        detail.setSourceBizId(patMedOuthosp.getId());
        detail.setSourceBizNo(patMedOuthosp.getOuthospno());
        fillCommonChildDetail(detail, patMedOuthosp, patArchive, campusid);
        detail.setParentPhone(patArchive != null
                ? firstNotBlank(patArchive.getTelcode(), patMedOuthosp.getTelcode())
@@ -205,6 +519,104 @@
            detail.setNutritionIcd10Code(patMedOuthosp.getIcd10code());
            detail.setNutritionDiagName(patMedOuthosp.getDiagname());
        }
        return detail;
    }
    private PatMaternityArchiveDetail buildInhospMaternityDetail(InhospArchiveContext context,
                                                                 PatSpecificArchiveGenerateConfig config) {
        PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail();
        detail.setArchiveType(config.getArchiveType());
        detail.setFollowupPeriod(config.getFollowupPeriod());
        detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP);
        detail.setSourceBizId(inInhospid(context));
        detail.setSourceBizNo(inInhospno(context));
        detail.setSourceSubId(context.subtask.getId());
        detail.setOuthospno(null);
        detail.setInhospno(inInhospno(context));
        detail.setSerialnum(inSerialnum(context));
        detail.setPatid(context.patid);
        detail.setPatname(firstNotBlank(context.patArchive == null ? null : context.patArchive.getName(),
                context.inhosp == null ? null : context.inhosp.getPatname()));
        detail.setBirthdate(context.patArchive == null ? null : context.patArchive.getBirthdate());
        detail.setIdcardno(firstNotBlank(context.patArchive == null ? null : context.patArchive.getIdcardno(),
                context.inhosp == null ? null : context.inhosp.getIdcardno()));
        detail.setPhone(firstNotBlank(context.patArchive == null ? null : context.patArchive.getTelcode(),
                context.inhosp == null ? null : context.inhosp.getTelcode()));
        detail.setSex(firstNonNull(context.patArchive == null ? null : context.patArchive.getSex(),
                context.inhosp == null ? null : context.inhosp.getSex(),
                context.subtask.getSex()));
        detail.setDiagTime(context.diagTime);
        detail.setArchiveTime(new Date());
        detail.setDoctorCode(inDrcode(context));
        detail.setDoctorName(inDrname(context));
        detail.setManagementDoctorCode(firstNotBlank(context.inhosp == null ? null : context.inhosp.getManagementDoctorCode(),
                inDrcode(context)));
        detail.setManagementDoctorName(firstNotBlank(context.inhosp == null ? null : context.inhosp.getManagementDoctor(),
                inDrname(context)));
        detail.setFirstDoctorCode(inDrcode(context));
        detail.setFirstDoctorName(inDrname(context));
        detail.setDeptcode(context.deptCode);
        detail.setDeptname(context.deptName);
        detail.setWardcode(context.wardCode);
        detail.setWardname(context.wardName);
        detail.setIcd10code(context.icd10Code);
        detail.setDiagname(context.diagName);
        detail.setAddress(context.patArchive == null ? null : context.patArchive.getPlaceOfResidence());
        detail.setRegisterUser("住院随访");
        detail.setOrgid(context.orgid);
        detail.setCampusid(context.campusid);
        detail.setDelFlag("0");
        return detail;
    }
    private PatChildArchiveDetail buildInhospChildDetail(InhospArchiveContext context,
                                                         PatSpecificArchiveGenerateConfig config) {
        PatChildArchiveDetail detail = new PatChildArchiveDetail();
        detail.setArchiveType(config.getArchiveType());
        detail.setFollowupPeriod(config.getFollowupPeriod());
        detail.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP);
        detail.setSourceBizId(inInhospid(context));
        detail.setSourceBizNo(inInhospno(context));
        detail.setSourceSubId(context.subtask.getId());
        detail.setOuthospno(null);
        detail.setInhospno(inInhospno(context));
        detail.setSerialnum(inSerialnum(context));
        detail.setPatid(context.patid);
        detail.setPatname(firstNotBlank(context.patArchive == null ? null : context.patArchive.getName(),
                context.inhosp == null ? null : context.inhosp.getPatname()));
        detail.setBirthdate(context.patArchive == null ? null : context.patArchive.getBirthdate());
        detail.setIdcardno(firstNotBlank(context.patArchive == null ? null : context.patArchive.getIdcardno(),
                context.inhosp == null ? null : context.inhosp.getIdcardno()));
        detail.setPhone(firstNotBlank(context.patArchive == null ? null : context.patArchive.getTelcode(),
                context.inhosp == null ? null : context.inhosp.getTelcode()));
        detail.setSex(firstNonNull(context.patArchive == null ? null : context.patArchive.getSex(),
                context.inhosp == null ? null : context.inhosp.getSex(),
                context.subtask.getSex()));
        detail.setDiagTime(context.diagTime);
        detail.setArchiveTime(new Date());
        detail.setDoctorCode(inDrcode(context));
        detail.setDoctorName(inDrname(context));
        detail.setManagementDoctorCode(firstNotBlank(context.inhosp == null ? null : context.inhosp.getManagementDoctorCode(),
                inDrcode(context)));
        detail.setManagementDoctorName(firstNotBlank(context.inhosp == null ? null : context.inhosp.getManagementDoctor(),
                inDrname(context)));
        detail.setDeptcode(context.deptCode);
        detail.setDeptname(context.deptName);
        detail.setWardcode(context.wardCode);
        detail.setWardname(context.wardName);
        detail.setIcd10code(context.icd10Code);
        detail.setDiagname(context.diagName);
        detail.setParentPhone(firstNotBlank(context.patArchive == null ? null : context.patArchive.getTelcode(),
                context.inhosp == null ? null : context.inhosp.getTelcode()));
        detail.setParentAddress(context.patArchive == null ? null : context.patArchive.getPlaceOfResidence());
        if ("1".equals(config.getArchiveType())) {
            detail.setNutritionIcd10Code(context.icd10Code);
            detail.setNutritionDiagName(context.diagName);
        }
        detail.setRegisterUser("住院随访");
        detail.setOrgid(context.orgid);
        detail.setCampusid(context.campusid);
        detail.setDelFlag("0");
        return detail;
    }
@@ -289,6 +701,85 @@
        return CollectionUtils.isNotEmpty(archives) ? archives.get(0) : null;
    }
    private PatArchive resolvePatArchive(Long patid, PatMedInhosp inhosp) {
        if (patid != null) {
            PatArchive archive = patArchiveMapper.selectPatArchiveByPatid(patid);
            if (archive != null) {
                return archive;
            }
        }
        Long inhospPatid = inhosp == null ? null : inhosp.getPatid();
        return inhospPatid == null ? null : patArchiveMapper.selectPatArchiveByPatid(inhospPatid);
    }
    private PatMedInhosp resolveInhosp(ServiceSubtask subtask) {
        if (subtask.getInhospid() != null) {
            PatMedInhosp inhosp = inhospVisitFacade.selectPatMedInhospByInhospid(subtask.getInhospid());
            if (inhosp != null) {
                return inhosp;
            }
        }
        if (StringUtils.isNotBlank(subtask.getHospno())) {
            PatMedInhosp query = new PatMedInhosp();
            query.setInhospno(subtask.getHospno());
            query.setOrgid(subtask.getOrgid());
            List<PatMedInhosp> list = inhospVisitFacade.selectPatMedInhosp(query);
            if (CollectionUtils.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }
    private void recordLog(InhospArchiveContext context, PatSpecificArchiveGenerateConfig config,
                           String deptCategory, String archiveType, String result, Long archiveId, String msg) {
        PatSpecificArchiveGenerateLog log = new PatSpecificArchiveGenerateLog();
        log.setSourceType(SpecificArchiveConstants.SOURCE_TYPE_INHOSP_FOLLOWUP);
        log.setSourceBizId(inInhospid(context));
        log.setSourceBizNo(inInhospno(context));
        log.setSourceSubId(context.subtask.getId());
        log.setPatid(context.patid);
        log.setOrgid(context.orgid);
        log.setCampusid(context.campusid);
        log.setDeptCategory(deptCategory);
        log.setArchiveType(archiveType);
        log.setConfigId(config == null || config.getId() == null
                ? SpecificArchiveConstants.NO_CONFIG_ID : config.getId().intValue());
        log.setArchiveId(archiveId);
        log.setProcessResult(result);
        log.setProcessMsg(msg);
        PatSpecificArchiveGenerateLog old = patSpecificArchiveGenerateLogService.selectBySourceSubAndConfig(
                log.getSourceType(), log.getSourceSubId(), log.getConfigId());
        int retry = old == null || old.getRetryCount() == null ? 0 : old.getRetryCount();
        if (SpecificArchiveConstants.RESULT_FAILED.equals(result)) {
            retry++;
        }
        log.setRetryCount(retry);
        patSpecificArchiveGenerateLogService.saveOrUpdate(log);
    }
    private Long inInhospid(InhospArchiveContext context) {
        return firstNonNull(context.inhosp == null ? null : context.inhosp.getInhospid(),
                context.subtask.getInhospid());
    }
    private String inInhospno(InhospArchiveContext context) {
        return firstNotBlank(context.inhosp == null ? null : context.inhosp.getInhospno(),
                context.subtask.getHospno());
    }
    private String inSerialnum(InhospArchiveContext context) {
        return context.inhosp == null ? null : context.inhosp.getSerialnum();
    }
    private String inDrcode(InhospArchiveContext context) {
        return firstNotBlank(context.inhosp == null ? null : context.inhosp.getDrcode(), context.subtask.getDrcode());
    }
    private String inDrname(InhospArchiveContext context) {
        return firstNotBlank(context.inhosp == null ? null : context.inhosp.getDrname(), context.subtask.getDrname());
    }
    private List<String> parseCodes(String raw) {
        if (StringUtils.isBlank(raw)) {
            return Collections.emptyList();
@@ -314,8 +805,42 @@
                .collect(Collectors.toList());
    }
    private String firstNotBlank(String first, String second) {
        return StringUtils.isNotBlank(first) ? first : second;
    private List<String> parseCsv(String raw) {
        if (StringUtils.isBlank(raw)) {
            return Collections.emptyList();
        }
        return Arrays.stream(raw.split(","))
                .map(String::trim)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toList());
    }
    private String firstNotBlank(String... values) {
        if (values == null) {
            return null;
        }
        for (String value : values) {
            if (StringUtils.isNotBlank(value)) {
                return value;
            }
        }
        return null;
    }
    private <T> T firstNonNull(T... values) {
        if (values == null) {
            return null;
        }
        for (T value : values) {
            if (value != null) {
                return value;
            }
        }
        return null;
    }
    private Date firstDate(Date first, Date second) {
        return first != null ? first : second;
    }
    private boolean containsIgnoreCase(List<String> source, String target) {
@@ -328,4 +853,30 @@
    private boolean equalsIgnoreCase(String first, String second) {
        return first != null && second != null && first.trim().equalsIgnoreCase(second.trim());
    }
    private String truncateMsg(String msg) {
        if (msg == null) {
            return null;
        }
        return msg.length() <= 900 ? msg : msg.substring(0, 900);
    }
    /**
     * ä½é™¢éšè®¿ç”Ÿæˆæ¡£æ¡ˆæ—¶ç”¨åˆ°çš„上下文。
     */
    private static class InhospArchiveContext {
        private ServiceSubtask subtask;
        private PatMedInhosp inhosp;
        private PatArchive patArchive;
        private Long patid;
        private String orgid;
        private String campusid;
        private String deptCode;
        private String deptName;
        private String wardCode;
        private String wardName;
        private String icd10Code;
        private String diagName;
        private Date diagTime;
    }
}
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
@@ -64,6 +64,7 @@
import com.ruoyi.task.domain.ServiceSubtaskPreachform;
import com.ruoyi.task.service.IServiceTaskService;
import com.ruoyi.task.mapper.ServiceSubtaskPreachformMapper;
import com.ruoyi.task.event.FollowupCompletedEventPublisher;
import com.ruoyi.patarchive.mapper.PatArchiveMapper;
/**
 * ä»»åŠ¡é—®å·é—®é¢˜é€‰é¡¹Service业务层处理
@@ -91,6 +92,9 @@
    @Autowired
    private ServiceSubtaskMapper serviceSubtaskMapper;
    @Autowired
    private FollowupCompletedEventPublisher followupCompletedEventPublisher;
    @Autowired
    private ServiceSubtaskPreachformMapper serviceSubtaskPreachformMapper;
@@ -476,6 +480,7 @@
                log.error("将该key和value从redis中,serviceSubtask的值为--------:{}", serviceSubtask);
                serviceSubtask.setScore(formatScore(scoreTotal));
                serviceSubtaskMapper.updateServiceSubtaskByCondition(serviceSubtask);
                followupCompletedEventPublisher.publish(serviceSubtask.getId());
                //将当前发送状态改成 9 å®Œæˆï¼ˆç¼“å­˜ preachform æŸ¥è¯¢ï¼‰
                String currentPreachform = serviceSubtask.getCurrentPreachform();
@@ -664,6 +669,7 @@
            serviceSubtask.setUpdateTime(new Date());
            serviceSubtask.setScore(formatScore(scoreTotal));
            serviceSubtaskMapper.updateServiceSubtaskByCondition(serviceSubtask);
            followupCompletedEventPublisher.publish(serviceSubtask.getId());
            //将当前发送状态改成9完成
            ServiceSubtaskPreachform serviceSubtaskPreachform = new ServiceSubtaskPreachform();
@@ -823,6 +829,7 @@
                serviceSubtask.setVisitTime(new Date());
                serviceSubtask.setScore(formatScore(scoreTotal));
                serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                followupCompletedEventPublisher.publish(serviceSubtask.getId());
                //将当前发送状态改成9完成
                ServiceSubtaskPreachform serviceSubtaskPreachform = new ServiceSubtaskPreachform();
                serviceSubtaskPreachform.setPreachform(serviceSubtask.getCurrentPreachform());
smartor/src/main/resources/mapper/smartor/PatChildArchiveDetailMapper.xml
@@ -9,6 +9,9 @@
        <result property="archiveid" column="archiveid"/>
        <result property="archiveType" column="archive_type"/>
        <result property="sourceType" column="source_type"/>
        <result property="sourceBizId" column="source_biz_id"/>
        <result property="sourceBizNo" column="source_biz_no"/>
        <result property="sourceSubId" column="source_sub_id"/>
        <result property="outhospno" column="outhospno"/>
        <result property="inhospno" column="inhospno"/>
        <result property="serialnum" column="serialnum"/>
@@ -70,6 +73,9 @@
               archiveid,
               archive_type,
               source_type,
               source_biz_id,
               source_biz_no,
               source_sub_id,
               outhospno,
               inhospno,
               serialnum,
@@ -136,6 +142,9 @@
            <if test="archiveType != null and archiveType != ''">and archive_type = #{archiveType}</if>
            <if test="followupPeriod != null and followupPeriod != ''">and followup_period = #{followupPeriod}</if>
            <if test="sourceType != null and sourceType != ''">and source_type = #{sourceType}</if>
            <if test="sourceBizId != null">and source_biz_id = #{sourceBizId}</if>
            <if test="sourceBizNo != null and sourceBizNo != ''">and source_biz_no = #{sourceBizNo}</if>
            <if test="sourceSubId != null">and source_sub_id = #{sourceSubId}</if>
            <if test="outhospno != null and outhospno != ''">and outhospno = #{outhospno}</if>
            <if test="inhospno != null and inhospno != ''">and inhospno = #{inhospno}</if>
            <if test="serialnum != null and serialnum != ''">and serialnum = #{serialnum}</if>
@@ -187,6 +196,9 @@
            <if test="archiveid != null">archiveid,</if>
            <if test="archiveType != null">archive_type,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="sourceBizId != null">source_biz_id,</if>
            <if test="sourceBizNo != null">source_biz_no,</if>
            <if test="sourceSubId != null">source_sub_id,</if>
            <if test="outhospno != null">outhospno,</if>
            <if test="inhospno != null">inhospno,</if>
            <if test="serialnum != null">serialnum,</if>
@@ -246,6 +258,9 @@
            <if test="archiveid != null">#{archiveid},</if>
            <if test="archiveType != null">#{archiveType},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="sourceBizId != null">#{sourceBizId},</if>
            <if test="sourceBizNo != null">#{sourceBizNo},</if>
            <if test="sourceSubId != null">#{sourceSubId},</if>
            <if test="outhospno != null">#{outhospno},</if>
            <if test="inhospno != null">#{inhospno},</if>
            <if test="serialnum != null">#{serialnum},</if>
@@ -309,6 +324,9 @@
            <if test="archiveid != null">archiveid = #{archiveid},</if>
            <if test="archiveType != null">archive_type = #{archiveType},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="sourceBizId != null">source_biz_id = #{sourceBizId},</if>
            <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if>
            <if test="sourceSubId != null">source_sub_id = #{sourceSubId},</if>
            <if test="outhospno != null">outhospno = #{outhospno},</if>
            <if test="inhospno != null">inhospno = #{inhospno},</if>
            <if test="serialnum != null">serialnum = #{serialnum},</if>
smartor/src/main/resources/mapper/smartor/PatChildArchiveMapper.xml
@@ -7,6 +7,10 @@
    <resultMap type="com.smartor.domain.PatChildArchive" id="PatChildArchiveResult">
        <result property="id" column="id"/>
        <result property="archiveType" column="archive_type"/>
        <result property="sourceType" column="source_type"/>
        <result property="sourceBizId" column="source_biz_id"/>
        <result property="sourceBizNo" column="source_biz_no"/>
        <result property="sourceSubId" column="source_sub_id"/>
        <result property="outhospno" column="outhospno"/>
        <result property="inhospno" column="inhospno"/>
        <result property="serialnum" column="serialnum"/>
@@ -52,6 +56,10 @@
    <sql id="selectPatChildArchiveVo">
        select id,
               archive_type,
               source_type,
               source_biz_id,
               source_biz_no,
               source_sub_id,
               outhospno,
               inhospno,
               serialnum,
@@ -101,6 +109,10 @@
        where 1=1
            and del_flag = '0'
            <if test="archiveType != null and archiveType != ''">and archive_type = #{archiveType}</if>
            <if test="sourceType != null and sourceType != ''">and source_type = #{sourceType}</if>
            <if test="sourceBizId != null">and source_biz_id = #{sourceBizId}</if>
            <if test="sourceBizNo != null and sourceBizNo != ''">and source_biz_no = #{sourceBizNo}</if>
            <if test="sourceSubId != null">and source_sub_id = #{sourceSubId}</if>
            <if test="outhospno != null and outhospno != ''">and outhospno = #{outhospno}</if>
            <if test="inhospno != null and inhospno != ''">and inhospno = #{inhospno}</if>
            <if test="serialnum != null and serialnum != ''">and serialnum = #{serialnum}</if>
@@ -152,6 +164,10 @@
        insert into pat_child_archive
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="archiveType != null">archive_type,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="sourceBizId != null">source_biz_id,</if>
            <if test="sourceBizNo != null">source_biz_no,</if>
            <if test="sourceSubId != null">source_sub_id,</if>
            <if test="outhospno != null">outhospno,</if>
            <if test="inhospno != null">inhospno,</if>
            <if test="serialnum != null">serialnum,</if>
@@ -195,6 +211,10 @@
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="archiveType != null">#{archiveType},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="sourceBizId != null">#{sourceBizId},</if>
            <if test="sourceBizNo != null">#{sourceBizNo},</if>
            <if test="sourceSubId != null">#{sourceSubId},</if>
            <if test="outhospno != null">#{outhospno},</if>
            <if test="inhospno != null">#{inhospno},</if>
            <if test="serialnum != null">#{serialnum},</if>
@@ -242,6 +262,10 @@
        update pat_child_archive
        <trim prefix="SET" suffixOverrides=",">
            <if test="archiveType != null">archive_type = #{archiveType},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="sourceBizId != null">source_biz_id = #{sourceBizId},</if>
            <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if>
            <if test="sourceSubId != null">source_sub_id = #{sourceSubId},</if>
            <if test="outhospno != null">outhospno = #{outhospno},</if>
            <if test="inhospno != null">inhospno = #{inhospno},</if>
            <if test="serialnum != null">serialnum = #{serialnum},</if>
smartor/src/main/resources/mapper/smartor/PatMaternityArchiveDetailMapper.xml
@@ -9,6 +9,9 @@
        <result property="archiveid" column="archiveid"/>
        <result property="archiveType" column="archive_type"/>
        <result property="sourceType" column="source_type"/>
        <result property="sourceBizId" column="source_biz_id"/>
        <result property="sourceBizNo" column="source_biz_no"/>
        <result property="sourceSubId" column="source_sub_id"/>
        <result property="outhospno" column="outhospno"/>
        <result property="inhospno" column="inhospno"/>
        <result property="serialnum" column="serialnum"/>
@@ -67,6 +70,9 @@
               archiveid,
               archive_type,
               source_type,
               source_biz_id,
               source_biz_no,
               source_sub_id,
               outhospno,
               inhospno,
               serialnum,
@@ -129,6 +135,9 @@
            <if test="archiveid != null">and archiveid = #{archiveid}</if>
            <if test="archiveType != null and archiveType != ''">and archive_type = #{archiveType}</if>
            <if test="sourceType != null and sourceType != ''">and source_type = #{sourceType}</if>
            <if test="sourceBizId != null">and source_biz_id = #{sourceBizId}</if>
            <if test="sourceBizNo != null and sourceBizNo != ''">and source_biz_no = #{sourceBizNo}</if>
            <if test="sourceSubId != null">and source_sub_id = #{sourceSubId}</if>
            <if test="outhospno != null and outhospno != ''">and outhospno = #{outhospno}</if>
            <if test="inhospno != null and inhospno != ''">and inhospno = #{inhospno}</if>
            <if test="serialnum != null and serialnum != ''">and serialnum = #{serialnum}</if>
@@ -174,6 +183,9 @@
            <if test="archiveid != null">archiveid,</if>
            <if test="archiveType != null">archive_type,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="sourceBizId != null">source_biz_id,</if>
            <if test="sourceBizNo != null">source_biz_no,</if>
            <if test="sourceSubId != null">source_sub_id,</if>
            <if test="outhospno != null">outhospno,</if>
            <if test="inhospno != null">inhospno,</if>
            <if test="serialnum != null">serialnum,</if>
@@ -230,6 +242,9 @@
            <if test="archiveid != null">#{archiveid},</if>
            <if test="archiveType != null">#{archiveType},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="sourceBizId != null">#{sourceBizId},</if>
            <if test="sourceBizNo != null">#{sourceBizNo},</if>
            <if test="sourceSubId != null">#{sourceSubId},</if>
            <if test="outhospno != null">#{outhospno},</if>
            <if test="inhospno != null">#{inhospno},</if>
            <if test="serialnum != null">#{serialnum},</if>
@@ -290,6 +305,9 @@
            <if test="archiveid != null">archiveid = #{archiveid},</if>
            <if test="archiveType != null">archive_type = #{archiveType},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="sourceBizId != null">source_biz_id = #{sourceBizId},</if>
            <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if>
            <if test="sourceSubId != null">source_sub_id = #{sourceSubId},</if>
            <if test="outhospno != null">outhospno = #{outhospno},</if>
            <if test="inhospno != null">inhospno = #{inhospno},</if>
            <if test="serialnum != null">serialnum = #{serialnum},</if>
smartor/src/main/resources/mapper/smartor/PatMaternityArchiveMapper.xml
@@ -7,6 +7,10 @@
    <resultMap type="com.smartor.domain.PatMaternityArchive" id="PatMaternityArchiveResult">
        <result property="id" column="id"/>
        <result property="archiveType" column="archive_type"/>
        <result property="sourceType" column="source_type"/>
        <result property="sourceBizId" column="source_biz_id"/>
        <result property="sourceBizNo" column="source_biz_no"/>
        <result property="sourceSubId" column="source_sub_id"/>
        <result property="outhospno" column="outhospno"/>
        <result property="inhospno" column="inhospno"/>
        <result property="serialnum" column="serialnum"/>
@@ -47,6 +51,10 @@
    <sql id="selectPatMaternityArchiveVo">
        select id,
               archive_type,
               source_type,
               source_biz_id,
               source_biz_no,
               source_sub_id,
               outhospno,
               inhospno,
               serialnum,
@@ -91,6 +99,10 @@
        where 1=1
            and del_flag = '0'
            <if test="archiveType != null and archiveType != ''">and archive_type = #{archiveType}</if>
            <if test="sourceType != null and sourceType != ''">and source_type = #{sourceType}</if>
            <if test="sourceBizId != null">and source_biz_id = #{sourceBizId}</if>
            <if test="sourceBizNo != null and sourceBizNo != ''">and source_biz_no = #{sourceBizNo}</if>
            <if test="sourceSubId != null">and source_sub_id = #{sourceSubId}</if>
            <if test="outhospno != null and outhospno != ''">and outhospno = #{outhospno}</if>
            <if test="inhospno != null and inhospno != ''">and inhospno = #{inhospno}</if>
            <if test="serialnum != null and serialnum != ''">and serialnum = #{serialnum}</if>
@@ -138,6 +150,10 @@
        insert into pat_maternity_archive
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="archiveType != null">archive_type,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="sourceBizId != null">source_biz_id,</if>
            <if test="sourceBizNo != null">source_biz_no,</if>
            <if test="sourceSubId != null">source_sub_id,</if>
            <if test="outhospno != null">outhospno,</if>
            <if test="inhospno != null">inhospno,</if>
            <if test="serialnum != null">serialnum,</if>
@@ -176,6 +192,10 @@
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="archiveType != null">#{archiveType},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="sourceBizId != null">#{sourceBizId},</if>
            <if test="sourceBizNo != null">#{sourceBizNo},</if>
            <if test="sourceSubId != null">#{sourceSubId},</if>
            <if test="outhospno != null">#{outhospno},</if>
            <if test="inhospno != null">#{inhospno},</if>
            <if test="serialnum != null">#{serialnum},</if>
@@ -218,6 +238,10 @@
        update pat_maternity_archive
        <trim prefix="SET" suffixOverrides=",">
            <if test="archiveType != null">archive_type = #{archiveType},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="sourceBizId != null">source_biz_id = #{sourceBizId},</if>
            <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if>
            <if test="sourceSubId != null">source_sub_id = #{sourceSubId},</if>
            <if test="outhospno != null">outhospno = #{outhospno},</if>
            <if test="inhospno != null">inhospno = #{inhospno},</if>
            <if test="serialnum != null">serialnum = #{serialnum},</if>
smartor/src/main/resources/mapper/smartor/PatSpecificArchiveGenerateLogMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.smartor.mapper.PatSpecificArchiveGenerateLogMapper">
    <resultMap type="com.smartor.domain.PatSpecificArchiveGenerateLog" id="PatSpecificArchiveGenerateLogResult">
        <result property="id" column="id"/>
        <result property="sourceType" column="source_type"/>
        <result property="sourceBizId" column="source_biz_id"/>
        <result property="sourceBizNo" column="source_biz_no"/>
        <result property="sourceSubId" column="source_sub_id"/>
        <result property="patid" column="patid"/>
        <result property="orgid" column="orgid"/>
        <result property="campusid" column="campusid"/>
        <result property="deptCategory" column="dept_category"/>
        <result property="archiveType" column="archive_type"/>
        <result property="configId" column="config_id"/>
        <result property="archiveId" column="archive_id"/>
        <result property="processResult" column="process_result"/>
        <result property="processMsg" column="process_msg"/>
        <result property="retryCount" column="retry_count"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <sql id="selectPatSpecificArchiveGenerateLogVo">
        select id,
               source_type,
               source_biz_id,
               source_biz_no,
               source_sub_id,
               patid,
               orgid,
               campusid,
               dept_category,
               archive_type,
               config_id,
               archive_id,
               process_result,
               process_msg,
               retry_count,
               create_time,
               update_time
        from pat_specific_archive_generate_log
    </sql>
    <select id="selectBySourceSubAndConfig" resultMap="PatSpecificArchiveGenerateLogResult">
        <include refid="selectPatSpecificArchiveGenerateLogVo"/>
        where source_type = #{sourceType}
          and source_sub_id = #{sourceSubId}
          and config_id = #{configId}
        limit 1
    </select>
    <select id="countProcessedBySourceSub" resultType="int">
        select count(1)
        from pat_specific_archive_generate_log
        where source_type = #{sourceType}
          and source_sub_id = #{sourceSubId}
          and process_result in ('1', '2', '3')
    </select>
    <insert id="insertPatSpecificArchiveGenerateLog" parameterType="com.smartor.domain.PatSpecificArchiveGenerateLog"
            useGeneratedKeys="true" keyProperty="id">
        insert into pat_specific_archive_generate_log
        (source_type, source_biz_id, source_biz_no, source_sub_id, patid, orgid, campusid,
         dept_category, archive_type, config_id, archive_id, process_result,
         process_msg, retry_count, create_time, update_time)
        values
        (#{sourceType}, #{sourceBizId}, #{sourceBizNo}, #{sourceSubId}, #{patid}, #{orgid}, #{campusid},
         #{deptCategory}, #{archiveType}, #{configId}, #{archiveId}, #{processResult},
         #{processMsg}, #{retryCount}, #{createTime}, #{updateTime})
    </insert>
    <update id="updatePatSpecificArchiveGenerateLog" parameterType="com.smartor.domain.PatSpecificArchiveGenerateLog">
        update pat_specific_archive_generate_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if>
            <if test="sourceSubId != null">source_sub_id = #{sourceSubId},</if>
            <if test="patid != null">patid = #{patid},</if>
            <if test="orgid != null">orgid = #{orgid},</if>
            <if test="campusid != null">campusid = #{campusid},</if>
            <if test="deptCategory != null">dept_category = #{deptCategory},</if>
            <if test="archiveType != null">archive_type = #{archiveType},</if>
            <if test="archiveId != null">archive_id = #{archiveId},</if>
            <if test="processResult != null">process_result = #{processResult},</if>
            <if test="processMsg != null">process_msg = #{processMsg},</if>
            <if test="retryCount != null">retry_count = #{retryCount},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
</mapper>
smartor/src/test/java/com/smartor/service/InhospFollowupArchiveLogicCheck.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,130 @@
package com.smartor.service;
import com.ruoyi.patarchive.domain.PatSpecificArchiveGenerateConfig;
import com.ruoyi.task.domain.ServiceSubtask;
import com.smartor.service.impl.PatSpecificArchiveGenerateServiceImpl;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
 * ä½é™¢éšè®¿ç”Ÿæˆä¸“科档案逻辑自检(纯 main,不依赖 JUnit / Spring / æ•°æ®åº“)。
 *
 * <p>覆盖:住院随访范围判断、科室/病区/诊断配置匹配、JSON/逗号配置解析、Mapper XML å¯è§£æžæ€§ã€‚</p>
 */
public final class InhospFollowupArchiveLogicCheck {
    private static int passed = 0;
    private static int failed = 0;
    private static void check(String key, Object expected, Object actual) {
        boolean ok = expected == null ? actual == null : expected.equals(actual);
        if (ok) {
            passed++;
            System.out.println("  [OK]   " + key + " = " + actual);
        } else {
            failed++;
            System.out.println("  [FAIL] " + key + " æœŸæœ›=" + expected + " å®žé™…=" + actual);
        }
    }
    private static void setField(Object target, String name, Object value) throws Exception {
        Field field = target.getClass().getDeclaredField(name);
        field.setAccessible(true);
        field.set(target, value);
    }
    private static ServiceSubtask subtask(String hospType, String serviceType) {
        ServiceSubtask subtask = new ServiceSubtask();
        subtask.setId(1001L);
        subtask.setHospType(hospType);
        subtask.setServiceType(serviceType);
        return subtask;
    }
    private static PatSpecificArchiveGenerateConfig config(String deptType, String archiveType,
                                                           String deptCodes, String icd10Codes) {
        PatSpecificArchiveGenerateConfig config = new PatSpecificArchiveGenerateConfig();
        config.setId(1L);
        config.setDeptType(deptType);
        config.setDeptCategory("2");
        config.setArchiveType(archiveType);
        config.setDeptCodes(deptCodes);
        config.setIcd10Codes(icd10Codes);
        return config;
    }
    public static void main(String[] args) throws Exception {
        System.out.println("========== ä½é™¢éšè®¿ç”Ÿæˆä¸“科档案逻辑自检 ==========");
        PatSpecificArchiveGenerateServiceImpl service = new PatSpecificArchiveGenerateServiceImpl();
        setField(service, "inhospFollowupServiceTypes", "2,13,18,19");
        Method isInhosp = PatSpecificArchiveGenerateServiceImpl.class
                .getDeclaredMethod("isInhospFollowup", ServiceSubtask.class);
        isInhosp.setAccessible(true);
        System.out.println("-- 1) ä½é™¢éšè®¿èŒƒå›´ --");
        check("出院随访 serviceType=2", true, isInhosp.invoke(service, subtask("2", "2")));
        check("入院随访 serviceType=18", true, isInhosp.invoke(service, subtask("6", "18")));
        check("门诊任务 hospType=1", false, isInhosp.invoke(service, subtask("1", "3")));
        check("宣教任务 serviceType=4", false, isInhosp.invoke(service, subtask("2", "4")));
        check("serviceType ä¸ºç©º", false, isInhosp.invoke(service, subtask("2", null)));
        Method match = PatSpecificArchiveGenerateServiceImpl.class.getDeclaredMethod(
                "matchConfig", PatSpecificArchiveGenerateConfig.class,
                String.class, String.class, String.class, String.class);
        match.setAccessible(true);
        System.out.println("-- 2) ç§‘室匹配 --");
        PatSpecificArchiveGenerateConfig deptConfig = config("1", "1", "[\"D001\"]", null);
        check("科室 D001 å‘½ä¸­", true, match.invoke(service, deptConfig, "D001", null, null, null));
        check("科室 D002 ä¸å‘½ä¸­", false, match.invoke(service, deptConfig, "D002", null, null, null));
        System.out.println("-- 3) ç—…区匹配 --");
        PatSpecificArchiveGenerateConfig wardConfig = config("2", "3", "[\"W001\"]", null);
        check("病区 W001 å‘½ä¸­", true, match.invoke(service, wardConfig, "D001", "W001", null, null));
        check("科室 D001 å¯¹ç—…区配置不命中", false,
                match.invoke(service, wardConfig, "D001", "D001", null, null));
        System.out.println("-- 4) è¯Šæ–­åŒ¹é… --");
        PatSpecificArchiveGenerateConfig diagConfig = config("1", "1", null, "[\"E46.x00x003\"]");
        check("诊断码命中", true, match.invoke(service, diagConfig, "D001", null, "E46.x00x003", "营养不良"));
        check("无诊断码时按诊断名称兜底", true,
                match.invoke(service, diagConfig, "D001", null, null, "E46.x00x003"));
        check("诊断不命中", false, match.invoke(service, diagConfig, "D001", null, "R00", "其他"));
        System.out.println("-- 5) é…ç½®ä¸ºç©º / éžæ³• JSON --");
        PatSpecificArchiveGenerateConfig emptyConfig = config("1", "1", null, null);
        check("科室和诊断都为空", false, match.invoke(service, emptyConfig, "D001", null, null, null));
        PatSpecificArchiveGenerateConfig commaConfig = config("1", "1", "D001,D002", null);
        check("逗号分隔配置兜底", true, match.invoke(service, commaConfig, "D002", null, null, null));
        System.out.println("-- 6) Mapper XML å¯è§£æžæ€§ --");
        String[] xmlFiles = new String[]{
                "smartor/src/main/resources/mapper/smartor/PatMaternityArchiveMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatChildArchiveMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatMaternityArchiveDetailMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatChildArchiveDetailMapper.xml",
                "smartor/src/main/resources/mapper/smartor/PatSpecificArchiveGenerateLogMapper.xml",
                "ruoyi-task/src/main/resources/mapper/task/ServiceSubtaskMapper.xml"
        };
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        for (String xmlFile : xmlFiles) {
            try {
                factory.newDocumentBuilder().parse(new File(xmlFile));
                check(xmlFile, "OK", "OK");
            } catch (Exception e) {
                check(xmlFile, "OK", e.getClass().getSimpleName() + ":" + e.getMessage());
            }
        }
        System.out.println("========== ç»“果:PASS=" + passed + ",FAIL=" + failed + " ==========");
        if (failed > 0) {
            System.exit(1);
        }
    }
}
sql/pat_specific_archive_generate_log_and_source_20261111.sql
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,105 @@
-- =============================================================================
-- ä½é™¢éšè®¿å®Œæˆç”Ÿæˆå¦‡ç§‘/儿科专科档案
-- 1. æ¡£æ¡ˆä¸»è¡¨/详情表增加来源字段
-- 2. æ–°å¢žä¸“科档案生成日志表(幂等 + è¡¥å¿ + è¿½æº¯ï¼‰
-- 3. å¢žåŠ æ‚£è€…æ¡£æ¡ˆæŸ¥è¯¢ç´¢å¼•
-- æ—¥æœŸï¼š2026-11-11
-- =============================================================================
-- -----------------------------------------------------------------------------
-- 1. æ¡£æ¡ˆä¸»è¡¨æ¥æºå­—段
-- -----------------------------------------------------------------------------
ALTER TABLE pat_maternity_archive
    ADD COLUMN source_type CHAR(1) DEFAULT NULL COMMENT '来源类型:1门诊接诊 2住院随访 3手工新增',
    ADD COLUMN source_biz_id BIGINT DEFAULT NULL COMMENT '来源业务ID:门诊记录ID/住院记录ID',
    ADD COLUMN source_biz_no VARCHAR(64) DEFAULT NULL COMMENT '来源业务编号:门诊号/住院号',
    ADD COLUMN source_sub_id BIGINT DEFAULT NULL COMMENT '来源随访子任务ID:service_subtask.id';
ALTER TABLE pat_child_archive
    ADD COLUMN source_type CHAR(1) DEFAULT NULL COMMENT '来源类型:1门诊接诊 2住院随访 3手工新增',
    ADD COLUMN source_biz_id BIGINT DEFAULT NULL COMMENT '来源业务ID:门诊记录ID/住院记录ID',
    ADD COLUMN source_biz_no VARCHAR(64) DEFAULT NULL COMMENT '来源业务编号:门诊号/住院号',
    ADD COLUMN source_sub_id BIGINT DEFAULT NULL COMMENT '来源随访子任务ID:service_subtask.id';
-- -----------------------------------------------------------------------------
-- 2. æ¡£æ¡ˆè¯¦æƒ…表补充来源业务ID/编号(source_type åŽŸè¡¨å·²æœ‰ï¼‰
-- -----------------------------------------------------------------------------
ALTER TABLE pat_maternity_archive_detail
    ADD COLUMN source_biz_id BIGINT DEFAULT NULL COMMENT '来源业务ID:门诊记录ID/住院记录ID',
    ADD COLUMN source_biz_no VARCHAR(64) DEFAULT NULL COMMENT '来源业务编号:门诊号/住院号',
    ADD COLUMN source_sub_id BIGINT DEFAULT NULL COMMENT '来源随访子任务ID:service_subtask.id';
ALTER TABLE pat_child_archive_detail
    ADD COLUMN source_biz_id BIGINT DEFAULT NULL COMMENT '来源业务ID:门诊记录ID/住院记录ID',
    ADD COLUMN source_biz_no VARCHAR(64) DEFAULT NULL COMMENT '来源业务编号:门诊号/住院号',
    ADD COLUMN source_sub_id BIGINT DEFAULT NULL COMMENT '来源随访子任务ID:service_subtask.id';
-- -----------------------------------------------------------------------------
-- 3. ç”Ÿæˆæ—¥å¿—表
-- -----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS pat_specific_archive_generate_log
(
    id            BIGINT        NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    source_type   CHAR(1)       NOT NULL DEFAULT '2' COMMENT '来源类型:1门诊接诊 2住院随访',
    source_biz_id BIGINT        DEFAULT NULL COMMENT '来源业务ID:门诊记录ID/住院记录ID',
    source_biz_no VARCHAR(64)   DEFAULT NULL COMMENT '来源业务编号:门诊号/住院号',
    source_sub_id BIGINT        DEFAULT NULL COMMENT '来源随访子任务ID:service_subtask.id',
    patid         BIGINT        DEFAULT NULL COMMENT '患者ID',
    orgid         VARCHAR(64)   DEFAULT NULL COMMENT '机构ID',
    campusid      VARCHAR(64)   DEFAULT NULL COMMENT '院区ID',
    dept_category CHAR(1)       DEFAULT NULL COMMENT '部门分类:1妇科 2儿科',
    archive_type  VARCHAR(32)   DEFAULT NULL COMMENT '档案类型',
    config_id     INT           NOT NULL DEFAULT 0 COMMENT '命中的配置ID;未命中配置时为0',
    archive_id    BIGINT        DEFAULT NULL COMMENT '生成或命中的档案主表ID',
    process_result CHAR(1)      NOT NULL COMMENT '处理结果:1生成 2已存在跳过 3未匹配 4失败',
    process_msg   VARCHAR(1000) DEFAULT NULL COMMENT '处理说明',
    retry_count   INT           NOT NULL DEFAULT 0 COMMENT '重试次数',
    create_time   DATETIME      DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    update_time   DATETIME      DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    PRIMARY KEY (id),
    UNIQUE KEY uk_pasgl_source_sub_config (source_type, source_sub_id, config_id),
    KEY idx_pasgl_biz_id (source_biz_id),
    KEY idx_pasgl_patid (patid, dept_category, archive_type),
    KEY idx_pasgl_archive (archive_id)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='专科档案生成日志表';
-- -----------------------------------------------------------------------------
-- 4. æ‚£è€…已有档案查询索引
-- -----------------------------------------------------------------------------
ALTER TABLE pat_maternity_archive
    ADD INDEX idx_pma_patid_type (orgid, patid, archive_type, del_flag);
ALTER TABLE pat_child_archive
    ADD INDEX idx_pca_patid_type (orgid, patid, archive_type, del_flag);
-- -----------------------------------------------------------------------------
-- 5. æ¥æºç±»åž‹å­—典(如字典表已有同类型数据,可跳过)
-- -----------------------------------------------------------------------------
INSERT INTO sys_dict_type (dict_name, dict_type, status, create_by, create_time, remark)
SELECT '专科档案来源', 'pat_archive_source_type', '0', 'system', NOW(), '专科档案生成来源'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM sys_dict_type WHERE dict_type = 'pat_archive_source_type'
);
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, is_default, status, create_by, create_time, remark)
SELECT 1, '门诊接诊', '1', 'pat_archive_source_type', 'N', '0', 'system', NOW(), '门诊接诊完成生成'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM sys_dict_data WHERE dict_type = 'pat_archive_source_type' AND dict_value = '1'
);
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, is_default, status, create_by, create_time, remark)
SELECT 2, '住院随访', '2', 'pat_archive_source_type', 'N', '0', 'system', NOW(), '住院随访完成生成'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM sys_dict_data WHERE dict_type = 'pat_archive_source_type' AND dict_value = '2'
);
INSERT INTO sys_dict_data (dict_sort, dict_label, dict_value, dict_type, is_default, status, create_by, create_time, remark)
SELECT 3, '手工新增', '3', 'pat_archive_source_type', 'N', '0', 'system', NOW(), '手工新增/导入'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM sys_dict_data WHERE dict_type = 'pat_archive_source_type' AND dict_value = '3'
);