package com.smartor.service.mch;
|
|
import com.ruoyi.system.service.ISysConfigService;
|
import com.smartor.common.MchFollowupConstants;
|
import com.smartor.common.SpecificArchiveConstants;
|
import com.smartor.domain.MchFollowupPlan;
|
import com.smartor.domain.MchFollowupPlanItem;
|
import com.smartor.domain.MchFollowupTaskQuery;
|
import com.smartor.domain.MchFollowupTaskVO;
|
import com.smartor.domain.PatChildArchiveDetail;
|
import com.smartor.domain.PatMaternityArchiveDetail;
|
import com.smartor.mapper.MchFollowupPlanItemMapper;
|
import com.smartor.mapper.MchFollowupPlanMapper;
|
import com.smartor.mapper.PatChildArchiveDetailMapper;
|
import com.smartor.mapper.PatMaternityArchiveDetailMapper;
|
|
import java.lang.reflect.Field;
|
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.Method;
|
import java.lang.reflect.Proxy;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 妇幼随访计划服务自检(纯 main,使用动态代理模拟 Mapper,不依赖数据库)。
|
*
|
* 覆盖:计划生成、节点时间、幂等重建、拟随访时间为空、儿保家长电话兜底。
|
*/
|
public final class MchFollowupPlanServiceCheck {
|
|
private static int passed = 0;
|
private static int failed = 0;
|
|
private static final SimpleDateFormat DATE_TIME = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
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 Date date(String text) throws Exception {
|
return DATE_TIME.parse(text);
|
}
|
|
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 Object defaultValue(Class<?> type) {
|
if (!type.isPrimitive()) {
|
return null;
|
}
|
if (type == boolean.class) {
|
return false;
|
}
|
if (type == byte.class) {
|
return (byte) 0;
|
}
|
if (type == short.class) {
|
return (short) 0;
|
}
|
if (type == int.class) {
|
return 0;
|
}
|
if (type == long.class) {
|
return 0L;
|
}
|
if (type == float.class) {
|
return 0F;
|
}
|
if (type == double.class) {
|
return 0D;
|
}
|
if (type == char.class) {
|
return '\0';
|
}
|
return null;
|
}
|
|
@SuppressWarnings("unchecked")
|
private static <T> T proxy(Class<T> type, InvocationHandler handler) {
|
return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, handler);
|
}
|
|
private static MchFollowupPlanAssembler assembler() throws Exception {
|
MchFollowupPlanAssembler assembler = new MchFollowupPlanAssembler();
|
setField(assembler, "timeResolver", new MchFollowupTimeResolver());
|
return assembler;
|
}
|
|
private static PatMaternityArchiveDetail maternityDetail(Long detailId, Long archiveId, Date plannedTime) {
|
PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail();
|
detail.setId(detailId);
|
detail.setArchiveid(archiveId);
|
detail.setOrgid(SpecificArchiveConstants.LISHUI_MCH_ORG_ID);
|
detail.setCampusid("1");
|
detail.setSourceType("1");
|
detail.setSourceBizNo("MZ001");
|
detail.setPatid(100L);
|
detail.setPatname("张三");
|
detail.setPhone("13800000000");
|
detail.setIdcardno("330102199001010000");
|
detail.setPlannedFollowTime(plannedTime);
|
detail.setFollowupStatus(MchFollowupConstants.FOLLOWUP_STATUS_ACTIVE);
|
detail.setFollowupPeriod("{\"items\":["
|
+ "{\"dayOffset\":0,\"sendTime\":\"09:00\",\"sendType\":\"sms\",\"content\":\"短信1\"},"
|
+ "{\"dayOffset\":3,\"sendType\":\"wechat\",\"templateId\":16,\"content\":\"微信2\"},"
|
+ "{\"dayOffset\":7,\"sendType\":\"sms\",\"content\":\"短信3\"}]}");
|
return detail;
|
}
|
|
private static PatChildArchiveDetail childDetail(Long detailId, Long archiveId, Date plannedTime) {
|
PatChildArchiveDetail detail = new PatChildArchiveDetail();
|
detail.setId(detailId);
|
detail.setArchiveid(archiveId);
|
detail.setOrgid(SpecificArchiveConstants.LISHUI_MCH_ORG_ID);
|
detail.setCampusid("1");
|
detail.setSourceType("1");
|
detail.setSourceBizNo("MZ002");
|
detail.setPatid(200L);
|
detail.setPatname("李四");
|
detail.setPhone("13900000000");
|
detail.setParentPhone("13700000000");
|
detail.setIdcardno("330102199202020000");
|
detail.setPlannedFollowTime(plannedTime);
|
detail.setFollowupStatus(MchFollowupConstants.FOLLOWUP_STATUS_ACTIVE);
|
detail.setFollowupPeriod("{\"items\":[{\"dayOffset\":1,\"sendType\":\"sms\",\"content\":\"儿保短信\"}]}");
|
return detail;
|
}
|
|
public static void main(String[] args) throws Exception {
|
System.out.println("========== 妇幼随访计划服务自检 ==========");
|
|
List<MchFollowupPlan> activePlans = new ArrayList<>();
|
List<MchFollowupPlanItem> insertedItems = new ArrayList<>();
|
long[] planId = {1L};
|
long[] itemId = {1L};
|
|
MchFollowupPlanMapper planMapper = proxy(MchFollowupPlanMapper.class, (p, method, a) -> {
|
String name = method.getName();
|
if ("selectActiveByArchive".equals(name)) {
|
return new ArrayList<>(activePlans);
|
}
|
if ("insertMchFollowupPlan".equals(name)) {
|
MchFollowupPlan plan = (MchFollowupPlan) a[0];
|
plan.setId(planId[0]++);
|
activePlans.add(plan);
|
return 1;
|
}
|
if ("cancelById".equals(name)) {
|
Long id = (Long) a[0];
|
for (MchFollowupPlan plan : activePlans) {
|
if (id.equals(plan.getId())) {
|
plan.setPlanStatus(MchFollowupConstants.PLAN_STATUS_CANCELED);
|
}
|
}
|
return 1;
|
}
|
if ("completeById".equals(name)) {
|
return 1;
|
}
|
return defaultValue(method.getReturnType());
|
});
|
|
MchFollowupPlanItem[] updatedFollowupItem = new MchFollowupPlanItem[1];
|
MchFollowupPlanItemMapper itemMapper = proxy(MchFollowupPlanItemMapper.class, (p, method, a) -> {
|
String name = method.getName();
|
if ("insertMchFollowupPlanItem".equals(name)) {
|
MchFollowupPlanItem item = (MchFollowupPlanItem) a[0];
|
item.setId(itemId[0]++);
|
insertedItems.add(item);
|
return 1;
|
}
|
if ("cancelPendingByPlanId".equals(name)) {
|
return 1;
|
}
|
if ("countPendingByPlanId".equals(name)) {
|
return 1;
|
}
|
if ("selectMchFollowupPlanItemById".equals(name)) {
|
MchFollowupPlanItem item = new MchFollowupPlanItem();
|
item.setId((Long) a[0]);
|
return item;
|
}
|
if ("updateFollowupResult".equals(name)) {
|
updatedFollowupItem[0] = (MchFollowupPlanItem) a[0];
|
return 1;
|
}
|
if ("selectByPlanId".equals(name)) {
|
Long queryPlanId = (Long) a[0];
|
List<MchFollowupPlanItem> list = new ArrayList<>();
|
for (MchFollowupPlanItem item : insertedItems) {
|
if (queryPlanId.equals(item.getPlanId())) {
|
list.add(item);
|
}
|
}
|
return list;
|
}
|
if ("selectTaskList".equals(name)) {
|
MchFollowupTaskVO vo = new MchFollowupTaskVO();
|
vo.setItemId(1L);
|
vo.setPlanId(1L);
|
vo.setTaskname("早孕关爱随访");
|
vo.setPatid(100L);
|
vo.setPatname("张三");
|
vo.setSendname("张三");
|
List<MchFollowupTaskVO> list = new ArrayList<>();
|
list.add(vo);
|
return list;
|
}
|
return defaultValue(method.getReturnType());
|
});
|
|
Map<Long, PatMaternityArchiveDetail> maternityMap = new HashMap<>();
|
maternityMap.put(20L, maternityDetail(20L, 10L, date("2026-11-20 14:30:00")));
|
maternityMap.put(21L, maternityDetail(21L, 11L, null));
|
PatMaternityArchiveDetail pendingDetail = maternityDetail(22L, 13L, date("2026-11-25 10:00:00"));
|
pendingDetail.setFollowupStatus(MchFollowupConstants.FOLLOWUP_STATUS_PENDING);
|
maternityMap.put(22L, pendingDetail);
|
PatMaternityArchiveDetailMapper maternityMapper = proxy(PatMaternityArchiveDetailMapper.class, (p, method, a) -> {
|
String name = method.getName();
|
if ("selectPatMaternityArchiveDetailById".equals(name)) {
|
return maternityMap.get((Long) a[0]);
|
}
|
if ("selectPatMaternityArchiveDetailList".equals(name)) {
|
PatMaternityArchiveDetail query = (PatMaternityArchiveDetail) a[0];
|
List<PatMaternityArchiveDetail> list = new ArrayList<>();
|
for (PatMaternityArchiveDetail detail : maternityMap.values()) {
|
if (query.getArchiveid() == null || query.getArchiveid().equals(detail.getArchiveid())) {
|
list.add(detail);
|
}
|
}
|
return list;
|
}
|
return defaultValue(method.getReturnType());
|
});
|
|
Map<Long, PatChildArchiveDetail> childMap = new HashMap<>();
|
childMap.put(30L, childDetail(30L, 12L, date("2026-12-01 08:00:00")));
|
PatChildArchiveDetailMapper childMapper = proxy(PatChildArchiveDetailMapper.class, (p, method, a) -> {
|
String name = method.getName();
|
if ("selectPatChildArchiveDetailById".equals(name)) {
|
return childMap.get((Long) a[0]);
|
}
|
if ("selectPatChildArchiveDetailList".equals(name)) {
|
return new ArrayList<>(childMap.values());
|
}
|
return defaultValue(method.getReturnType());
|
});
|
|
ISysConfigService configService = proxy(ISysConfigService.class, (p, method, a) -> {
|
if ("selectConfigByKey".equals(method.getName())) {
|
return null;
|
}
|
return defaultValue(method.getReturnType());
|
});
|
|
MchFollowupPlanServiceImpl service = new MchFollowupPlanServiceImpl();
|
setField(service, "planMapper", planMapper);
|
setField(service, "itemMapper", itemMapper);
|
setField(service, "maternityDetailMapper", maternityMapper);
|
setField(service, "childDetailMapper", childMapper);
|
setField(service, "periodParser", new MchFollowupPeriodParser());
|
setField(service, "planAssembler", assembler());
|
setField(service, "configService", configService);
|
|
System.out.println("-- 1) 妇保计划生成 --");
|
int generated = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 10L, 20L);
|
check("生成节点数", 3, generated);
|
check("计划数", 1, activePlans.size());
|
check("计划状态", MchFollowupConstants.PLAN_STATUS_ACTIVE, activePlans.get(0).getPlanStatus());
|
check("计划机构", SpecificArchiveConstants.LISHUI_MCH_ORG_ID, activePlans.get(0).getOrgid());
|
check("节点数", 3, insertedItems.size());
|
check("节点1时间", "2026-11-20 09:00:00", DATE_TIME.format(insertedItems.get(0).getSendTime()));
|
check("节点2时间", "2026-11-23 14:30:00", DATE_TIME.format(insertedItems.get(1).getSendTime()));
|
check("节点3时间", "2026-11-27 14:30:00", DATE_TIME.format(insertedItems.get(2).getSendTime()));
|
|
System.out.println("-- 2) 相同基准日/周期幂等 --");
|
int again = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 10L, 20L);
|
check("幂等返回", 0, again);
|
check("计划数不变", 1, activePlans.size());
|
check("节点数不变", 3, insertedItems.size());
|
|
System.out.println("-- 2.1) 待确认档案不生成 --");
|
int pendingGenerated = service.rebuildForArchive(
|
MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 13L, 22L);
|
check("待确认不生成", 0, pendingGenerated);
|
check("待确认计划数不变", 1, activePlans.size());
|
check("待确认节点数不变", 3, insertedItems.size());
|
|
System.out.println("-- 3) 拟随访时间为空 --");
|
int waiting = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 11L, 21L);
|
check("等待计划不生成节点", 0, waiting);
|
check("等待计划数", 2, activePlans.size());
|
check("等待计划状态", MchFollowupConstants.PLAN_STATUS_WAITING, activePlans.get(1).getPlanStatus());
|
|
System.out.println("-- 4) 儿保家长电话兜底 --");
|
int childGenerated = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_CHILD, 12L, 30L);
|
check("儿保节点数", 1, childGenerated);
|
check("儿保计划数", 3, activePlans.size());
|
check("儿保电话", "13700000000", activePlans.get(2).getPhone());
|
check("儿保节点时间", "2026-12-02 08:00:00",
|
DATE_TIME.format(insertedItems.get(insertedItems.size() - 1).getSendTime()));
|
|
System.out.println("-- 5) 非丽水妇幼不生成 --");
|
PatMaternityArchiveDetail other = maternityDetail(40L, 20L, date("2026-11-20 14:30:00"));
|
other.setOrgid("OTHER_ORG");
|
maternityMap.put(40L, other);
|
int otherGenerated = service.rebuildForArchive(MchFollowupConstants.ARCHIVE_TYPE_MATERNITY, 20L, 40L);
|
check("其他机构不生成", 0, otherGenerated);
|
|
System.out.println("-- 6) 回填人工随访结果 --");
|
MchFollowupPlanItem feedback = new MchFollowupPlanItem();
|
feedback.setId(1L);
|
feedback.setFollowupDate(date("2026-11-24 10:00:00"));
|
feedback.setFollowupUserId("U001");
|
feedback.setFollowupUserName("王护士");
|
feedback.setFollowupSituation("电话随访,情况稳定");
|
feedback.setFollowupStatus(MchFollowupConstants.ITEM_FOLLOWUP_STATUS_DONE);
|
int feedbackUpdated = service.updateItemFollowupResult(feedback);
|
check("回填更新行数", 1, feedbackUpdated);
|
check("回填状态", MchFollowupConstants.ITEM_FOLLOWUP_STATUS_DONE,
|
updatedFollowupItem[0].getFollowupStatus());
|
check("回填人员", "王护士", updatedFollowupItem[0].getFollowupUserName());
|
check("回填时间非空", true, updatedFollowupItem[0].getUpdateTime() != null);
|
check("节点列表数", 3, service.listItems(1L).size());
|
|
System.out.println("-- 7) 妇幼任务列表字段 --");
|
MchFollowupTaskQuery taskQuery = new MchFollowupTaskQuery();
|
taskQuery.setOrgid(SpecificArchiveConstants.LISHUI_MCH_ORG_ID);
|
List<MchFollowupTaskVO> taskList = service.listTasks(taskQuery);
|
check("任务列表数", 1, taskList.size());
|
check("taskid为空", null, taskList.get(0).getTaskid());
|
check("taskname", "早孕关爱随访", taskList.get(0).getTaskname());
|
check("sendname", "张三", taskList.get(0).getSendname());
|
check("patid", 100L, taskList.get(0).getPatid());
|
|
System.out.println("========== 结果:PASS=" + passed + ",FAIL=" + failed + " ==========");
|
if (failed > 0) {
|
System.exit(1);
|
}
|
}
|
}
|