package cn.iocoder.yudao.module.qcreport.engine.context;
|
|
import lombok.Data;
|
import lombok.experimental.Accessors;
|
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 报告上下文。
|
* <p>
|
* 模板里的 {@code {{path}}} 全部相对这个结构解析:report 是报告级字段,inspectionItems 是检验项数组。
|
* 业务单据 → 上下文的映射由调用方负责,模板本身只认这个标准结构,
|
* 换行业、换单据来源都不需要改模板与组件。
|
* <p>
|
* 取值时先摊平成 Map({@link #toScope()}),不靠反射读 POJO 属性:
|
* 只暴露这里显式放进去的字段,模板路径不可能顺着 getClass 之类读到不该给的东西。
|
*/
|
@Data
|
@Accessors(chain = true)
|
public class ReportContext {
|
|
private ReportFields report = new ReportFields();
|
private List<InspectionItem> inspectionItems = new ArrayList<>();
|
|
/** 空白上下文:字段齐全但没有值,便于逐项填充 */
|
public static ReportContext empty() {
|
return new ReportContext();
|
}
|
|
/** 报告级字段 → Map */
|
public Map<String, Object> reportMap() {
|
Map<String, Object> map = new LinkedHashMap<>();
|
map.put("reportNo", report.getReportNo());
|
map.put("reportName", report.getReportName());
|
map.put("sampleNo", report.getSampleNo());
|
map.put("productCode", report.getProductCode());
|
map.put("productName", report.getProductName());
|
map.put("spec", report.getSpec());
|
map.put("batchNo", report.getBatchNo());
|
map.put("workOrderNo", report.getWorkOrderNo());
|
map.put("inspectType", report.getInspectType());
|
map.put("inspector", report.getInspector());
|
map.put("inspectDate", report.getInspectDate());
|
map.put("department", report.getDepartment());
|
map.put("customerName", report.getCustomerName());
|
map.put("supplierName", report.getSupplierName());
|
map.put("result", report.getResult());
|
map.put("resultText", report.getResultText());
|
map.put("conclusion", report.getConclusion());
|
map.put("passRate", report.getPassRate());
|
map.put("qcResult", report.getQcResult());
|
map.put("qcResultText", report.getQcResultText());
|
map.put("total", report.getTotal());
|
map.put("passCount", report.getPassCount());
|
map.put("failCount", report.getFailCount());
|
return map;
|
}
|
|
/** 检验项列表 → Map,渲染与规则求值都从这里取值 */
|
public static List<Object> itemMaps(List<InspectionItem> items) {
|
List<Object> maps = new ArrayList<>(items.size());
|
for (InspectionItem item : items) {
|
maps.add(itemMap(item));
|
}
|
return maps;
|
}
|
|
/** 渲染作用域的根:{ report, inspectionItems } */
|
public Map<String, Object> toScope() {
|
return scope(inspectionItems);
|
}
|
|
/**
|
* 指定检验项列表的作用域:{ report, inspectionItems }。
|
* <p>
|
* 逐项判定要用原始列表、报告级判定要用判定后的列表,两者不能共用一份,
|
* 所以这里把「用哪份列表」做成显式参数,避免取错。
|
*/
|
public Map<String, Object> scope(List<InspectionItem> items) {
|
Map<String, Object> scope = new LinkedHashMap<>();
|
scope.put("report", reportMap());
|
scope.put("inspectionItems", itemMaps(items));
|
return scope;
|
}
|
|
public static Map<String, Object> itemMap(InspectionItem item) {
|
Map<String, Object> map = new LinkedHashMap<>();
|
map.put("index", item.getIndex());
|
map.put("itemCode", item.getItemCode());
|
map.put("itemName", item.getItemName());
|
map.put("standardValue", item.getStandardValue());
|
map.put("actualValue", item.getActualValue());
|
map.put("unit", item.getUnit());
|
map.put("requirement", item.getRequirement());
|
map.put("checkMethod", item.getCheckMethod());
|
// 没有分组的报告不放这个键:模板里一个 {{item.group.x}} 都没有,放个空的空格子只会白占作用域
|
if (item.getGroup() != null) {
|
map.put("group", groupMap(item.getGroup()));
|
}
|
map.put("upperLimit", item.getUpperLimit());
|
map.put("lowerLimit", item.getLowerLimit());
|
map.put("result", item.getResult());
|
map.put("resultText", item.getResultText());
|
map.put("remark", item.getRemark());
|
return map;
|
}
|
|
/** 分组信息 → Map:三个字段一个都不能少,否则模板里对应的绑定会取不到值 */
|
public static Map<String, Object> groupMap(InspectionItem.Group group) {
|
Map<String, Object> map = new LinkedHashMap<>();
|
map.put("childName", group.getChildName());
|
map.put("span", group.getSpan());
|
map.put("hidden", group.getHidden());
|
return map;
|
}
|
|
}
|