2025-02-17 17:00:27 +08:00
|
|
|
package com.dpkj.modules.autoReplyPrint.controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dpkj.common.vo.Result;
|
|
|
|
|
import com.dpkj.modules.autoReplyPrint.service.impl.TemplateService;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打印模板控制层
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
|
|
|
|
* @version 1.0
|
|
|
|
|
* @since 2025-01-17 15:25:03
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/autoReplyPrint")
|
|
|
|
|
public class TemplateController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private TemplateService templateService;
|
|
|
|
|
|
|
|
|
|
|
2025-02-18 15:26:28 +08:00
|
|
|
@PostMapping("/template/{templateName}")
|
2025-02-17 17:00:27 +08:00
|
|
|
public Result<String> testTemplate(@RequestParam String jsonData,
|
|
|
|
|
@RequestParam Integer width,
|
|
|
|
|
@RequestParam Integer height,
|
|
|
|
|
@PathVariable String templateName,
|
|
|
|
|
@RequestParam(defaultValue = "E:\\images") String saveDir) {
|
2025-03-17 10:28:17 +08:00
|
|
|
StringBuilder filePath = new StringBuilder();
|
|
|
|
|
this.templateService.generateReceiptImage(JSONObject.parseObject(jsonData), templateName, width, height, filePath);
|
2025-02-17 17:00:27 +08:00
|
|
|
return Result.ok("模板生成成功");
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 15:26:28 +08:00
|
|
|
@PostMapping("/template")
|
2025-02-17 17:00:27 +08:00
|
|
|
public Result<String> testTemplate(@RequestParam String jsonData,
|
|
|
|
|
@RequestParam Integer width,
|
|
|
|
|
@RequestParam Integer height, @RequestParam(defaultValue = "E:\\images") String saveDir) {
|
|
|
|
|
String html = "<!DOCTYPE html>\n" +
|
|
|
|
|
"<html>\n" +
|
|
|
|
|
"<head><title>Test</title></head>\n" +
|
|
|
|
|
"<body>\n" +
|
|
|
|
|
"<h1>你好,我是一个好的模板</h1>\n" +
|
|
|
|
|
"<h2><span th:text='${name}'> </span></h2>\n" +
|
|
|
|
|
"</body>\n" +
|
|
|
|
|
"</html>";
|
2025-03-17 10:28:17 +08:00
|
|
|
StringBuilder filePath = new StringBuilder();
|
|
|
|
|
this.templateService.generateReceiptImage(JSONObject.parseObject(jsonData), html, width, height, filePath);
|
2025-02-17 17:00:27 +08:00
|
|
|
return Result.ok("模板生成成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|