feat: 表单使用场景可见闭环——form/list 返回绑定事项明细 refItems
build / build-push (push) Failing after 26s

- SvcFormVo 增 refItems(ItemBrief: id/itemCode/title/siteCode/status),referenced 同源派生;仅 list 填充,versions/get 不带
- ServiceItemRepository.findBySchIdAndFormCodeIsNotNull 一次查全量按 formCode 内存分组,替代逐表单 count 的 N+1
- ServiceFormServiceTest 5 用例(未绑定/单绑/跨站点/多版本聚合/分组不串)
- 前端配套(svc-hall-front 另推):绑定明细弹窗+直达事项编辑、发布未绑定引导、schema 预览、事项编辑页草稿表单提示
This commit is contained in:
chenxing
2026-09-16 16:33:55 +08:00
parent dedb4aa436
commit 76b35b2fb3
4 changed files with 171 additions and 2 deletions
@@ -355,6 +355,8 @@ public final class SvcModels {
private String schemaJson;
private LocalDateTime publishTime;
private Boolean referenced;
/** 绑定本表单的事项明细(仅 list 填充;表单页反查使用位置) */
private List<ItemBrief> refItems;
public static SvcFormVo of(com.yunhai.svchall.entity.ServiceForm form, Boolean referenced) {
SvcFormVo vo = new SvcFormVo();
@@ -368,6 +370,26 @@ public final class SvcModels {
vo.setReferenced(referenced);
return vo;
}
/** 表单绑定事项的摘要行(表单 sch 级共享,跨站点绑定如实展示站点) */
@Data
public static class ItemBrief {
private Integer id;
private String itemCode;
private String title;
private String siteCode;
private Integer status;
public static ItemBrief of(com.yunhai.svchall.entity.ServiceItem item) {
ItemBrief brief = new ItemBrief();
brief.setId(item.getId());
brief.setItemCode(item.getItemCode());
brief.setTitle(item.getTitle());
brief.setSiteCode(item.getSiteCode());
brief.setStatus(item.getStatus());
return brief;
}
}
}
// ===== 办件 =====
@@ -40,6 +40,9 @@ public interface ServiceItemRepository extends JpaRepository<ServiceItem, Intege
/** 表单被事项绑定计数(表单删除守护,按 form_code 判) */
long countBySchIdAndFormCode(Long schId, String formCode);
/** 已绑表单的全部事项(表单列表 refItems 明细,一次查出按 formCode 内存分组) */
List<ServiceItem> findBySchIdAndFormCodeIsNotNull(Long schId);
// ===== 门户筛选项计数(已发布口径,group by 一次往返/维度,承袭 CMS 口径)=====
@Query("select i.objectKey, count(i) from ServiceItem i"
@@ -4,6 +4,7 @@ import com.yunhai.platform.apistd.BizException;
import com.yunhai.platform.utils.exception.ErrorCode;
import com.yunhai.platform.utils.model.BoaUser;
import com.yunhai.svchall.entity.ServiceForm;
import com.yunhai.svchall.entity.ServiceItem;
import com.yunhai.svchall.model.svc.SvcModels.DeleteRequest;
import com.yunhai.svchall.model.svc.SvcModels.SvcFormSaveRequest;
import com.yunhai.svchall.model.svc.SvcModels.SvcFormVo;
@@ -18,7 +19,10 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
@@ -33,10 +37,14 @@ public class ServiceFormService {
private final ServiceItemRepository itemRepository;
private final SiteGuard siteGuard;
/** 表单列表(sch 级;同 code 多版本聚合成一行最新版,referenced=是否被事项绑定) */
/** 表单列表(sch 级;同 code 多版本聚合成一行最新版,referenced=是否被事项绑定,refItems=绑定事项明细) */
public List<SvcFormVo> list(BoaUser user, String siteCode) {
SiteInfo site = siteGuard.requireSiteManager(user, siteCode);
List<ServiceForm> forms = formRepository.findBySchIdOrderByCodeAscVersionDescIdAsc(site.getSchId());
Map<String, List<SvcFormVo.ItemBrief>> refs = new HashMap<>();
for (ServiceItem item : itemRepository.findBySchIdAndFormCodeIsNotNull(site.getSchId())) {
refs.computeIfAbsent(item.getFormCode(), k -> new ArrayList<>()).add(SvcFormVo.ItemBrief.of(item));
}
List<SvcFormVo> result = new ArrayList<>();
String lastCode = null;
for (ServiceForm form : forms) {
@@ -44,7 +52,10 @@ public class ServiceFormService {
continue;
}
lastCode = form.getCode();
result.add(SvcFormVo.of(form, itemRepository.countBySchIdAndFormCode(site.getSchId(), form.getCode()) > 0));
List<SvcFormVo.ItemBrief> briefs = refs.getOrDefault(form.getCode(), Collections.emptyList());
SvcFormVo vo = SvcFormVo.of(form, !briefs.isEmpty());
vo.setRefItems(briefs);
result.add(vo);
}
return result;
}