feat:增加挂号打印模块
This commit is contained in:
parent
f966dd9387
commit
fc1e02264d
|
@ -0,0 +1,44 @@
|
|||
package com.dpkj.modules.print.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||
import com.dpkj.common.vo.Result;
|
||||
import com.dpkj.modules.print.service.PrintService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 挂号controller
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @since 2025-02-08 11:49:46
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/print")
|
||||
public class RegisterController {
|
||||
|
||||
@Resource(name = "registerService")
|
||||
private PrintService printService;
|
||||
|
||||
/**
|
||||
* 挂号
|
||||
*/
|
||||
@GetMapping("/register/{templateName}")
|
||||
public Result<LexMarkResultDTO> register(@RequestParam String jsonData,
|
||||
@PathVariable String templateName,
|
||||
@RequestParam(defaultValue = "600") Integer width,
|
||||
@RequestParam(defaultValue = "950") Integer height
|
||||
){
|
||||
return Result.ok((LexMarkResultDTO)printService.printImage(JSONObject.parseObject(jsonData), templateName, width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂号,通过文件路径
|
||||
*/
|
||||
@GetMapping("/register")
|
||||
public Result<LexMarkResultDTO> registerByFilePath(@RequestParam(defaultValue = "D:\\images") String filePath){
|
||||
return Result.ok((LexMarkResultDTO)printService.printImage(null, null, 0, 0, filePath));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.dpkj.modules.print.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* 打印服务接口
|
||||
*
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @version 1.0
|
||||
* @since 2025-02-08 10:35:27
|
||||
*/
|
||||
public interface PrintService {
|
||||
|
||||
|
||||
/**
|
||||
* 生成小票图片
|
||||
*
|
||||
* @param data json数据,用来填充模板
|
||||
* @param template 模板(html字符串或者模板名称)
|
||||
* @param width 图片宽度
|
||||
* @param height 图片高度
|
||||
* @param saveDir 图片的保存路径,如果为空,那么不进行图片的保存
|
||||
*/
|
||||
Object printImage(JSONObject data, String template, int width, int height, String saveDir);
|
||||
|
||||
/**
|
||||
* 默认实现,给定一个默认可用的图片保存路径
|
||||
*/
|
||||
default Object printImage(JSONObject data, String template, int width, int height) {
|
||||
return printImage(data, template, width, height, "D:\\images");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.dpkj.modules.print.service.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dpkj.common.dto.LexMarkDTO;
|
||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||
import com.dpkj.common.utils.TemplateUtils;
|
||||
import com.dpkj.common.utils.ThirdService;
|
||||
import com.dpkj.modules.print.service.PrintService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 挂号服务打印
|
||||
*
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @version 1.0
|
||||
* @since 2025-02-08 10:36:25
|
||||
*/
|
||||
@Service("registerService")
|
||||
public class RegisterServiceImpl implements PrintService {
|
||||
|
||||
@Resource
|
||||
private ThirdService thirdService;
|
||||
|
||||
@Override
|
||||
public LexMarkResultDTO printImage(JSONObject data, String template, int width, int height, String saveDir) {
|
||||
StringBuilder filePath = new StringBuilder(saveDir);
|
||||
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
||||
if ( !StringUtils.isEmpty(template) && !StringUtils.isEmpty(saveDir)){
|
||||
byte[] image = new TemplateUtils().generateReceiptImage(data, template, width, height, filePath);
|
||||
}
|
||||
|
||||
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||
lexMarkDTO.setActionName("PrintForm");
|
||||
lexMarkDTO.setCallID(19256);
|
||||
lexMarkDTO.setDevName("ReceiptPrinter");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("TimeOut", 30000);
|
||||
param.put("formName", "ReceiptForm");
|
||||
param.put("mediaName", "ReceiptMedia");
|
||||
param.put("alignment", 0);
|
||||
param.put("offsetX", 0);
|
||||
param.put("offsetY", 0);
|
||||
param.put("resolution", 1);
|
||||
param.put("mediaCtrl", 1);
|
||||
param.put("fields", "LOGO=" + filePath);
|
||||
lexMarkDTO.setParam(param.toJSONString());
|
||||
return thirdService.callDevice(lexMarkDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue