package jnpf.limsController;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import jnpf.exception.DataException;
|
import jnpf.limsEntity.LimsPrintTemplateEntity;
|
import jnpf.limsService.LimsPrintTemplateService;
|
import jnpf.limsService.print.PrintRendererRegistry;
|
import jnpf.limsService.print.PrintTemplateRenderer;
|
import jnpf.util.R;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.Map;
|
|
@Slf4j
|
@Tag(name = "lims打印接口", description = "通用打印模板渲染")
|
@RestController
|
@RequestMapping("/lims/biz/print")
|
public class LimsPrintController {
|
|
@Autowired
|
private LimsPrintTemplateService limsPrintTemplateService;
|
|
@Autowired
|
private PrintRendererRegistry printRendererRegistry;
|
|
/**
|
* 渲染打印模板:按 template_id 命中模板配置 + 路由到 renderer,组装前端
|
* 渲染所需的数据。
|
*
|
* 请求体:{ "template_id": "jianyan_baogao", "id": "<业务实体 f_id>" }
|
*/
|
@Operation(summary = "渲染打印模板")
|
@PostMapping("/render")
|
public R<Map<String, Object>> render(@RequestBody Map<String, String> params) {
|
if (params == null) {
|
return R.error("缺少入参");
|
}
|
String templateId = params.get("template_id");
|
String id = params.get("id");
|
if (templateId == null || templateId.isEmpty()) {
|
return R.error("缺少 template_id");
|
}
|
if (id == null || id.isEmpty()) {
|
return R.error("缺少 id");
|
}
|
|
LimsPrintTemplateEntity tpl = limsPrintTemplateService.findActiveByTemplateId(templateId);
|
if (tpl == null) {
|
return R.error("找不到启用的打印模板: " + templateId);
|
}
|
|
PrintTemplateRenderer renderer;
|
try {
|
renderer = printRendererRegistry.get(templateId);
|
} catch (DataException e) {
|
return R.error(e.getMessage());
|
}
|
|
try {
|
Map<String, Object> data = renderer.render(id, tpl);
|
return R.success(data);
|
} catch (DataException e) {
|
return R.error(e.getMessage());
|
}
|
}
|
}
|