feat(apply): 办件详情出参补发 formSchemaJson——申请内容按表单 schema 显示中文 label 与分组
build / build-push (push) Successful in 48s
build / build-push (push) Successful in 48s
- ApplyVo 新增响应期字段 formSchemaJson(仅 detail 填,不入库) - ServiceFormService.schemaAt:按办件提交时 formVersion 精确命中,缺失回落最新已发布 - 无表单/事项清理/未发布 → null,前端回落按 key 展示 - 单测 ServiceApplyDetailSchemaTest 三态冻结(详情中文化分组 2026-09-17,详见验收清单)
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package com.yunhai.svchall.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yunhai.platform.utils.model.BoaUser;
|
||||
import com.yunhai.svchall.entity.ServiceApply;
|
||||
import com.yunhai.svchall.entity.ServiceForm;
|
||||
import com.yunhai.svchall.entity.ServiceItem;
|
||||
import com.yunhai.svchall.model.svc.SvcModels.ApplyVo;
|
||||
import com.yunhai.svchall.repository.ServiceApplyRepository;
|
||||
import com.yunhai.svchall.repository.ServiceItemRepository;
|
||||
import com.yunhai.svchall.service.FlowClient;
|
||||
import com.yunhai.svchall.service.SiteDirectory;
|
||||
import com.yunhai.svchall.service.SiteGuard;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 办件详情补发表单 schema(2026-09-17):前端「申请内容」不再以英文 key 当标签,
|
||||
* 改为按 schemaJson 的 groups/fields 显示中文 label 与分组;版本口径=办件提交时
|
||||
* formVersion 精确命中,缺失回落最新已发布版本(快照纪律的展示侧对齐)。
|
||||
*/
|
||||
@DisplayName("办件详情 formSchemaJson:版本精确命中/回落/无表单三态")
|
||||
class ServiceApplyDetailSchemaTest {
|
||||
|
||||
private ServiceApplyRepository applyRepository;
|
||||
private ServiceItemRepository itemRepository;
|
||||
private ServiceFormService formService;
|
||||
private ServiceApplyService service;
|
||||
private ServiceApply apply;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
applyRepository = mock(ServiceApplyRepository.class);
|
||||
itemRepository = mock(ServiceItemRepository.class);
|
||||
formService = mock(ServiceFormService.class);
|
||||
service = new ServiceApplyService(applyRepository, itemRepository, formService,
|
||||
mock(AttachmentService.class), mock(FlowClient.class), mock(SiteGuard.class),
|
||||
mock(SiteDirectory.class),
|
||||
new com.yunhai.svchall.service.ApplyViewGuard(mock(FlowClient.class)),
|
||||
new ObjectMapper(),
|
||||
new org.springframework.transaction.support.TransactionTemplate(
|
||||
mock(org.springframework.transaction.PlatformTransactionManager.class)));
|
||||
|
||||
apply = new ServiceApply();
|
||||
ReflectionTestUtils.setField(apply, "id", 42);
|
||||
apply.setSchId(1L);
|
||||
apply.setSiteCode("S1");
|
||||
apply.setItemId(7);
|
||||
apply.setItemCode("ITEM-1");
|
||||
apply.setFormVersion(2);
|
||||
apply.setFormDataJson("{\"name\":\"大猫咪2\"}");
|
||||
apply.setSubmitterId(9);
|
||||
apply.setSubmitterName("张三");
|
||||
when(applyRepository.findByIdAndSchId(42, 1L)).thenReturn(Optional.of(apply));
|
||||
|
||||
ServiceItem item = new ServiceItem();
|
||||
ReflectionTestUtils.setField(item, "id", 7);
|
||||
item.setSchId(1L);
|
||||
item.setItemCode("ITEM-1");
|
||||
item.setFormCode("FORM-1");
|
||||
when(itemRepository.findById(7)).thenReturn(Optional.of(item));
|
||||
}
|
||||
|
||||
private BoaUser submitter() {
|
||||
BoaUser user = mock(BoaUser.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
when(user.getId()).thenReturn(9);
|
||||
when(user.getType()).thenReturn(2);
|
||||
when(user.getCurrentRole().getSchId()).thenReturn(1);
|
||||
return user;
|
||||
}
|
||||
|
||||
private ServiceForm form(String schema) {
|
||||
ServiceForm f = new ServiceForm();
|
||||
f.setSchemaJson(schema);
|
||||
return f;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("formVersion 精确命中 → 出参 formSchemaJson = 该版本 schema")
|
||||
void detail_withVersionMatch_returnsSchema() {
|
||||
String schema = "{\"groups\":[{\"title\":\"基本信息\",\"fields\":[{\"key\":\"name\",\"label\":\"姓名\"}]}]}";
|
||||
when(formService.schemaAt(1L, "FORM-1", 2)).thenReturn(schema);
|
||||
ApplyVo vo = service.detail(submitter(), "S1", 42);
|
||||
assertEquals(schema, vo.getFormSchemaJson());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("办件无 formVersion(无表单事项)→ formSchemaJson 为 null")
|
||||
void detail_withoutFormVersion_returnsNullSchema() {
|
||||
apply.setFormVersion(null);
|
||||
ApplyVo vo = service.detail(submitter(), "S1", 42);
|
||||
assertNull(vo.getFormSchemaJson());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("事项未绑定表单 → formSchemaJson 为 null(不外溢查询)")
|
||||
void detail_itemWithoutFormCode_returnsNullSchema() {
|
||||
ServiceItem noForm = new ServiceItem();
|
||||
ReflectionTestUtils.setField(noForm, "id", 7);
|
||||
noForm.setFormCode(null);
|
||||
when(itemRepository.findById(7)).thenReturn(Optional.of(noForm));
|
||||
ApplyVo vo = service.detail(submitter(), "S1", 42);
|
||||
assertNull(vo.getFormSchemaJson());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user