Browse Source

2024-07-29 修改接口方式,打印机查询、模版查询

master
zhousq 4 months ago
parent
commit
bb02c1cbd7
  1. BIN
      models/wuliaotest.pdf
  2. 153
      win-admin/src/main/java/com/win/web/controller/print/WinPrintServerControler.java
  3. 127
      win-print/src/main/java/com/win/print/controller/WinPrintClientPrintersController.java
  4. 1
      win-print/src/main/java/com/win/print/domain/PrintModelDataVo.java
  5. 71
      win-print/src/main/java/com/win/print/domain/WinPrintClientPrinterSimple.java
  6. 182
      win-print/src/main/java/com/win/print/domain/WinPrintClientPrinters.java
  7. 56
      win-print/src/main/java/com/win/print/domain/WinPrintModelSimple.java
  8. 65
      win-print/src/main/java/com/win/print/mapper/WinPrintClientPrintersMapper.java
  9. 3
      win-print/src/main/java/com/win/print/mapper/WinPrintModelMapper.java
  10. 10
      win-print/src/main/java/com/win/print/service/DictPrinterListService.java
  11. 65
      win-print/src/main/java/com/win/print/service/IWinPrintClientPrintersService.java
  12. 2
      win-print/src/main/java/com/win/print/service/IWinPrintModelService.java
  13. 2
      win-print/src/main/java/com/win/print/service/IWinPrintTasksLogsService.java
  14. 40
      win-print/src/main/java/com/win/print/service/LocalPrinterDataUpdateTask.java
  15. 109
      win-print/src/main/java/com/win/print/service/impl/WinPrintClientPrintersServiceImpl.java
  16. 7
      win-print/src/main/java/com/win/print/service/impl/WinPrintModelServiceImpl.java
  17. 28
      win-print/src/main/java/com/win/print/service/impl/WinPrintTasksLogsServiceImpl.java
  18. 290
      win-print/src/main/java/com/win/print/util/PdfModelUitl.java
  19. 117
      win-print/src/main/resources/mapper/print/WinPrintClientPrintersMapper.xml
  20. 8
      win-print/src/main/resources/mapper/print/WinPrintModelMapper.xml
  21. 57
      win-print/src/main/resources/templates/print/clientPrinters/add.html
  22. 111
      win-print/src/main/resources/templates/print/clientPrinters/clientPrinters.html
  23. 58
      win-print/src/main/resources/templates/print/clientPrinters/edit.html

BIN
models/wuliaotest.pdf

Binary file not shown.

153
win-admin/src/main/java/com/win/web/controller/print/WinPrintServerControler.java

@ -19,13 +19,11 @@ import com.win.common.core.controller.BaseController;
import com.win.common.core.domain.AjaxResult;
import com.win.common.utils.ServletUtils;
import com.win.common.utils.file.FileUtils;
import com.win.print.domain.PrintModelDataVo;
import com.win.print.domain.WinPrintModel;
import com.win.print.domain.WinPrintModelParams;
import com.win.print.domain.WinPrintTasksLogs;
import com.win.print.domain.*;
import com.win.print.service.*;
import com.win.print.util.DataUnitl;
import com.win.print.util.HTMLConvertUitl;
import com.win.print.util.PdfModelUitl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@ -62,10 +60,13 @@ public class WinPrintServerControler extends BaseController {
@Resource
IWinPrintModelService winPrintModelService;//模版配置
@Resource
PrintTaskService printTaskService;
DictPrinterListService dictPrinterListService;
@Resource
IWinPrintTasksLogsService iPrintTasksLogsService;
@Resource
IWinPrintClientPrintersService iWinPrintClientPrintersService;
@Resource
PdfModelUitl pdfModelUitl;
@PostMapping("/model")
@Operation(summary = "模版打印接口,服务调用只处理模版并生成pdf文件!")
public AjaxResult getclientPdf(@RequestBody PrintModelDataVo dataVo) {
@ -74,11 +75,14 @@ public class WinPrintServerControler extends BaseController {
}
String fileServer ="http://"+ServletUtils.getRequest().getServerName()+":"+ServletUtils.getRequest().getServerPort()+prefix+"/file";//当前接收打印的服务器URL
String modelCode = dataVo.getModelCode();
String clientCode = dataVo.getClientCode();
String printerName=dataVo.getPrinterName();
if (StrUtil.isEmpty(clientCode)) {
return AjaxResult.error("打印失败!未指定打印客户端!");
String printerUuid=dataVo.getPrinterUuid();
WinPrintClientPrinterSimple winPrintClientPrinterSimple = iWinPrintClientPrintersService.selectWinPrintClientPrintersByUuid(printerUuid);
if (ObjectUtil.isEmpty(winPrintClientPrinterSimple)) {
return AjaxResult.error("打印失败!未找到指定打印机信息!!");
}
String clientCode = winPrintClientPrinterSimple.getClientCode();
String printerName=winPrintClientPrinterSimple.getPrinterName();
if (StrUtil.isEmpty(modelCode)) {
return AjaxResult.error("打印失败!未指定模版!");
}
@ -116,10 +120,6 @@ public class WinPrintServerControler extends BaseController {
//生成打印任务文件
String pdfDir = DataUnitl.getWorkingDir(printFilepath);
String templateDir = DataUnitl.getWorkingDir(templatePathDefault);
if ("PDF".equalsIgnoreCase(modelType)) {
//渲染打印模版
return AjaxResult.error("暂时不支持PDF模版打印!");
}
//获取参数和值-不给值默认空,数据为数组,数组大小为1时调用单页处理,数组大于1时
List<WinPrintModelParams> winPrintModelParamsList = winPrintModel.getWinPrintModelParamsList();
List<JSONObject> printData = dataVo.getPrintData();
@ -127,28 +127,18 @@ public class WinPrintServerControler extends BaseController {
String pdfPath = pdfDir + "/" ;
if ("1".equals(dataVo.getDocModel())) { //单文单件务打印
String fileName= clientCode + "_" + modelCode + "_"+String.valueOf(System.currentTimeMillis()) + ".pdf";
printMutilPage(winPrintModelParamsList, printData, modelName, pageSize, pdfPath +fileName, modelTypeSrc, templateDir);
printMutilPage(winPrintModelParamsList, printData, modelName, pageSize, pdfPath +fileName, modelTypeSrc, templateDir,modelType);
//printTaskService.putTaskToQueue(info, DateUtil.now(),fileName,remoteAddr,"model",winPrintModel.getmPageSize(),winPrintModel.getmPageRotate(),1);
createTaskLog(clientCode,fileName,taskId,"model",modelCode,printerName, requestType,copyCounts, modelPage, isPageRolated, "",printeDate, fileServer);
iPrintTasksLogsService.createTaskLog(clientCode,fileName,taskId,"model",modelCode,printerName, requestType,copyCounts, modelPage, isPageRolated, "",printeDate, fileServer);
} else {
AtomicInteger fileCount = new AtomicInteger(1);
String finalModelName = modelName;
Date finalPrinteDate = printeDate;
printData.forEach(pdata -> {
Map<String, String> modelData = new HashMap<>();
winPrintModelParamsList.forEach(item -> {
if ("QRIMG".equalsIgnoreCase(item.getParamType())) {
String mg = qrCodeService.getBase64QRCodeSrc(pdata.getString(item.getParamCode()), 172, 172, "png");
modelData.put(item.getParamCode(), Optional.ofNullable(mg).orElse(""));
} else {
modelData.put(item.getParamCode(), Optional.ofNullable(pdata.getString(item.getParamCode())).orElse(""));
}
});
String pdfFileName = clientCode + "_" + modelCode + "_"+ String.valueOf(fileCount.getAndIncrement()) + "_" + String.valueOf(System.currentTimeMillis()) + ".pdf";
File file = new File(pdfPath+pdfFileName);
printOneByOne(file, modelType, modelData, pageSize, finalModelName, modelTypeSrc, templateDir);
createTaskLog(clientCode,pdfFileName,taskId,"model",modelCode,printerName, requestType,copyCounts, modelPage, isPageRolated, "", finalPrinteDate,fileServer);
printOneByOne(winPrintModelParamsList,file, modelType, pdata, pageSize, finalModelName, modelTypeSrc, templateDir);
iPrintTasksLogsService.createTaskLog(clientCode,pdfFileName,taskId,"model",modelCode,printerName, requestType,copyCounts, modelPage, isPageRolated, "", finalPrinteDate,fileServer);
});
}
@ -195,13 +185,14 @@ public class WinPrintServerControler extends BaseController {
String taskId=IdUtil.fastSimpleUUID();
String printType_n = Optional.ofNullable(printType).orElse("doc");
Integer copyCounts_n=Optional.ofNullable(copyCounts).orElse(1);
createTaskLog(clientCode,fileName,taskId,printType_n,"file_model",printerName, "doc",copyCounts,String.valueOf(copyCounts_n) , "N", "", printTime_n,fileServer);
iPrintTasksLogsService.createTaskLog(clientCode,fileName,taskId,printType_n,"file_model",printerName, "doc",copyCounts,String.valueOf(copyCounts_n) , "N", "", printTime_n,fileServer);
return AjaxResult.error("打印任务已发送,等待打印机处理!");
}
/**
* 获取打印文件预览
* */
@GetMapping("/file/{name}")
@ResponseBody
public void pdfview(@PathVariable("name") String fileName, HttpServletResponse response) {
try
{
@ -209,60 +200,112 @@ public class WinPrintServerControler extends BaseController {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, fileName);
FileUtils.writeBytes(pdfDir+fileName, response.getOutputStream());
//return AjaxResult.success("任务成功下发!");
}
catch (Exception e)
{
e.printStackTrace();
};
}
/**
* 数据库方式
* 获取指定客户端编码的打印机列表all时为所有客户端的所有打印机
* 适用于固定服务接口的访问
* */
@GetMapping("/printerList")
@ResponseBody
public AjaxResult getPrinterList() {
return AjaxResult.success(iWinPrintClientPrintersService.selectClientPrintersList());
}
@GetMapping("/printers/local")
@ResponseBody
public AjaxResult getPrinterLocalList() {
return AjaxResult.success(dictPrinterListService.getPrintersNameList());
}
/**
* 获取在线客户端列表
* */
@GetMapping("/clientsList")
@ResponseBody
public AjaxResult getClientsList() {
WinPrintClientinfo winPrintClientinfo=new WinPrintClientinfo();
return AjaxResult.success(winPrintClientinfoService.selectWinPrintClientinfoList(winPrintClientinfo));
}
/**
* 获取模版列表
* */
@GetMapping("/modelList")
@ResponseBody
public AjaxResult getModelList() {
return AjaxResult.success(winPrintModelService.selectWinPrintModelListSimple());
}
/**
* 单页打印
*/
private void printOneByOne(File pdfFileName, String modeType, Map<String, String> data, PageSize pageSize, String modelName, String modeTypeSrc, String templatePath) {
private void printOneByOne(List<WinPrintModelParams> paramList,File pdfFileName, String modeType, JSONObject data, PageSize pageSize, String modelName, String modeTypeSrc, String templatePath) {
try {
if ("PDF".equalsIgnoreCase(modeType)) {
pdfModelUitl.pdfMdelFromRender(paramList,pdfFileName,data,modelName,templatePath);
log.info("处理PDF模版");
} else if ("freemarker".equalsIgnoreCase(modeType)) {
log.info("处理freemarker模版");
} else {
log.info("thymeleaf");
HTMLConvertUitl.html2Pdf_thymeleaf(pdfFileName, data, pageSize, modelName, modeTypeSrc, templatePath);
Map<String, String> modelData = new HashMap<>();
paramList.forEach(item -> {
if ("QRIMG".equalsIgnoreCase(item.getParamType())) {
String mg = qrCodeService.getBase64QRCodeSrc(data.getString(item.getParamCode()), 172, 172, "png");
modelData.put(item.getParamCode(), Optional.ofNullable(mg).orElse(""));
} else {
modelData.put(item.getParamCode(), Optional.ofNullable(data.getString(item.getParamCode())).orElse(""));
}
});
HTMLConvertUitl.html2Pdf_thymeleaf(pdfFileName, modelData, pageSize, modelName, modeTypeSrc, templatePath);
}
} catch (IOException e) {
e.printStackTrace();
log.error("printOneByOne-error", e.toString());
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
/**
* 多以合并
*/
private void printMutilPage(List<WinPrintModelParams> paramList, List<JSONObject> dataList, String modelName, PageSize pageSize, String fileName, String modeTypeSrc, String templatePath) {
private void printMutilPage(List<WinPrintModelParams> paramList, List<JSONObject> dataList, String modelName, PageSize pageSize, String fileName, String modeTypeSrc, String templatePath,String modelType) {
try {
PdfDocument destDoc = new PdfDocument(new PdfWriter(fileName));
destDoc.setDefaultPageSize(pageSize);
PdfMerger pdfMerger = new PdfMerger(destDoc);
dataList.forEach(pdata -> {
try {
Map<String, String> modelData = new HashMap<>();
paramList.forEach(item -> {
if ("QRIMG".equalsIgnoreCase(item.getParamType())) {
String mg = qrCodeService.getBase64QRCodeSrc(pdata.getString(item.getParamCode()), 172, 172, "png");
modelData.put(item.getParamCode(), Optional.ofNullable(mg).orElse(""));
} else {
modelData.put(item.getParamCode(), Optional.ofNullable(pdata.getString(item.getParamCode())).orElse(""));
}
});
File tempFile = File.createTempFile("temp_" + String.valueOf(System.currentTimeMillis()), ".pdf");
HTMLConvertUitl.html2Pdf_thymeleaf(tempFile, modelData, pageSize, modelName, modeTypeSrc, templatePath);
if("PDF".equalsIgnoreCase(modelType)){
pdfModelUitl.pdfMdelFromRender(paramList,tempFile,pdata,modelName,templatePath);
}else{
Map<String, String> modelData = new HashMap<>();
paramList.forEach(item -> {
if ("QRIMG".equalsIgnoreCase(item.getParamType())) {
String mg = qrCodeService.getBase64QRCodeSrc(pdata.getString(item.getParamCode()), 172, 172, "png");
modelData.put(item.getParamCode(), Optional.ofNullable(mg).orElse(""));
} else {
modelData.put(item.getParamCode(), Optional.ofNullable(pdata.getString(item.getParamCode())).orElse(""));
}
});
HTMLConvertUitl.html2Pdf_thymeleaf(tempFile, modelData, pageSize, modelName, modeTypeSrc, templatePath);
}
PdfDocument sourcePdf = new PdfDocument(new PdfReader(tempFile));
pdfMerger.merge(sourcePdf, 1, sourcePdf.getNumberOfPages());
sourcePdf.close();
tempFile.delete();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
});
pdfMerger.close();
@ -271,25 +314,5 @@ public class WinPrintServerControler extends BaseController {
log.error("printMutilPage-error", e.toString());
}
}
private void createTaskLog(String clientCode, String fileName, String taskId, String printType, String modelCode, String printerName, String requestType, Integer copyCounts, String modelPage, String isPageRolated, String remark, Date printTime,String fileServer){
WinPrintTasksLogs logs=new WinPrintTasksLogs();
logs.setClientCode(clientCode);
logs.setTaskId(Optional.ofNullable(taskId).orElse(IdUtil.fastSimpleUUID()));
logs.setCreatedBy(WinConfig.getClientCode());
logs.setCreatedTime(DateUtil.date());
logs.setDataFile(fileName);
logs.setIpAddr(fileServer);
logs.setPrintType(printType);
logs.setModelCode(modelCode);
logs.setPrinterName(printerName);
logs.setRequestType(requestType);
logs.setTaskStatus("0");
logs.setSettingCode("");
logs.setCopyCounts(copyCounts);
logs.setModelPage(modelPage);
logs.setIsPageRolated(isPageRolated);
logs.setRemark(remark);
logs.setPrintTime(printTime);
iPrintTasksLogsService.insertWinPrintTasksLogs(logs);
}
}

127
win-print/src/main/java/com/win/print/controller/WinPrintClientPrintersController.java

@ -0,0 +1,127 @@
package com.win.print.controller;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.win.common.annotation.Log;
import com.win.common.enums.BusinessType;
import com.win.print.domain.WinPrintClientPrinters;
import com.win.print.service.IWinPrintClientPrintersService;
import com.win.common.core.controller.BaseController;
import com.win.common.core.domain.AjaxResult;
import com.win.common.utils.poi.ExcelUtil;
import com.win.common.core.page.TableDataInfo;
/**
* 客户端打印机对照Controller
*
* @author zhousq
* @date 2024-07-29
*/
@Controller
@RequestMapping("/print/clientPrinters")
public class WinPrintClientPrintersController extends BaseController
{
private String prefix = "print/clientPrinters";
@Autowired
private IWinPrintClientPrintersService winPrintClientPrintersService;
@RequiresPermissions("print:clientPrinters:view")
@GetMapping()
public String clientPrinters()
{
return prefix + "/clientPrinters";
}
/**
* 查询客户端打印机对照列表
*/
@RequiresPermissions("print:clientPrinters:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(WinPrintClientPrinters winPrintClientPrinters)
{
startPage();
List<WinPrintClientPrinters> list = winPrintClientPrintersService.selectWinPrintClientPrintersList(winPrintClientPrinters);
return getDataTable(list);
}
/**
* 导出客户端打印机对照列表
*/
@RequiresPermissions("print:clientPrinters:export")
@Log(title = "客户端打印机对照", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(WinPrintClientPrinters winPrintClientPrinters)
{
List<WinPrintClientPrinters> list = winPrintClientPrintersService.selectWinPrintClientPrintersList(winPrintClientPrinters);
ExcelUtil<WinPrintClientPrinters> util = new ExcelUtil<WinPrintClientPrinters>(WinPrintClientPrinters.class);
return util.exportExcel(list, "客户端打印机对照数据");
}
/**
* 新增客户端打印机对照
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存客户端打印机对照
*/
@RequiresPermissions("print:clientPrinters:add")
@Log(title = "客户端打印机对照", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(WinPrintClientPrinters winPrintClientPrinters)
{
return toAjax(winPrintClientPrintersService.insertWinPrintClientPrinters(winPrintClientPrinters));
}
/**
* 修改客户端打印机对照
*/
@RequiresPermissions("print:clientPrinters:edit")
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id , ModelMap mmap)
{
WinPrintClientPrinters winPrintClientPrinters = winPrintClientPrintersService.selectWinPrintClientPrintersById(id);
mmap.put("winPrintClientPrinters", winPrintClientPrinters);
return prefix + "/edit";
}
/**
* 修改保存客户端打印机对照
*/
@RequiresPermissions("print:clientPrinters:edit")
@Log(title = "客户端打印机对照", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(WinPrintClientPrinters winPrintClientPrinters)
{
return toAjax(winPrintClientPrintersService.updateWinPrintClientPrinters(winPrintClientPrinters));
}
/**
* 删除客户端打印机对照
*/
@RequiresPermissions("print:clientPrinters:remove")
@Log(title = "客户端打印机对照", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(winPrintClientPrintersService.deleteWinPrintClientPrintersByIds(ids));
}
}

1
win-print/src/main/java/com/win/print/domain/PrintModelDataVo.java

@ -31,6 +31,7 @@ public class PrintModelDataVo {
* 打印机名称必须穿
* */
private String printerName;
private String printerUuid;//全局打印机编码
/**
* 计划打印时间
* */

71
win-print/src/main/java/com/win/print/domain/WinPrintClientPrinterSimple.java

@ -0,0 +1,71 @@
package com.win.print.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.win.common.annotation.Excel;
import com.win.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
/**
* 客户端打印机对照对象 win_print_client_printers
*
* @author zhousq
* @date 2024-07-29
*/
public class WinPrintClientPrinterSimple extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 客户端编码 */
@Excel(name = "客户端编码")
private String clientCode;
/** 打印机名称 */
@Excel(name = "打印机名称")
private String printerName;
@Excel(name = "打印机编码")
private String printerUuid ;
/** 打印机业务名称 */
@Excel(name = "打印机业务名称")
private String printerNameBusy ;
public void setClientCode(String clientCode)
{
this.clientCode = clientCode;
}
public String getClientCode()
{
return clientCode;
}
public void setPrinterName(String printerName)
{
this.printerName = printerName;
}
public String getPrinterName()
{
return printerName;
}
public String getPrinterUuid() {
return printerUuid;
}
public void setPrinterUuid(String printerUuid) {
this.printerUuid = printerUuid;
}
public String getPrinterNameBusy() {
return printerNameBusy;
}
public void setPrinterNameBusy(String printerNameBusy) {
this.printerNameBusy = printerNameBusy;
}
}

182
win-print/src/main/java/com/win/print/domain/WinPrintClientPrinters.java

@ -0,0 +1,182 @@
package com.win.print.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.win.common.annotation.Excel;
import com.win.common.core.domain.BaseEntity;
/**
* 客户端打印机对照对象 win_print_client_printers
*
* @author zhousq
* @date 2024-07-29
*/
public class WinPrintClientPrinters extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 租户号 */
private String tenantId;
/** 乐观锁 */
private Long revision;
/** 创建人 */
private String createdBy;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date createdTime;
/** 更新人 */
private String updatedBy;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date updatedTime;
/** 客户端编码 */
@Excel(name = "客户端编码")
private String clientCode;
/** 打印机名称 */
@Excel(name = "打印机名称")
private String printerName;
@Excel(name = "打印机编码")
private String printerUuid ;
/** 打印机业务名称 */
@Excel(name = "打印机业务名称")
private String printerNameBusy ;
private Long id;
private String status;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public void setTenantId(String tenantId)
{
this.tenantId = tenantId;
}
public String getTenantId()
{
return tenantId;
}
public void setRevision(Long revision)
{
this.revision = revision;
}
public Long getRevision()
{
return revision;
}
public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}
public String getCreatedBy()
{
return createdBy;
}
public void setCreatedTime(Date createdTime)
{
this.createdTime = createdTime;
}
public Date getCreatedTime()
{
return createdTime;
}
public void setUpdatedBy(String updatedBy)
{
this.updatedBy = updatedBy;
}
public String getUpdatedBy()
{
return updatedBy;
}
public void setUpdatedTime(Date updatedTime)
{
this.updatedTime = updatedTime;
}
public Date getUpdatedTime()
{
return updatedTime;
}
public void setClientCode(String clientCode)
{
this.clientCode = clientCode;
}
public String getClientCode()
{
return clientCode;
}
public void setPrinterName(String printerName)
{
this.printerName = printerName;
}
public String getPrinterName()
{
return printerName;
}
public String getPrinterUuid() {
return printerUuid;
}
public void setPrinterUuid(String printerUuid) {
this.printerUuid = printerUuid;
}
public String getPrinterNameBusy() {
return printerNameBusy;
}
public void setPrinterNameBusy(String printerNameBusy) {
this.printerNameBusy = printerNameBusy;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("tenantId", getTenantId())
.append("revision", getRevision())
.append("createdBy", getCreatedBy())
.append("createdTime", getCreatedTime())
.append("updatedBy", getUpdatedBy())
.append("updatedTime", getUpdatedTime())
.append("clientCode", getClientCode())
.append("printerName", getPrinterName())
.toString();
}
}

56
win-print/src/main/java/com/win/print/domain/WinPrintModelSimple.java

@ -0,0 +1,56 @@
package com.win.print.domain;
import com.win.common.annotation.Excel;
import com.win.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
import java.util.List;
/**
* 打印模版设置对象 win_print_model
*
* @author zhousq
* @date 2024-07-22
*/
public class WinPrintModelSimple extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 模版名称 */
//"模版名称")
private String mName;
/** 模版编号 */
//模版编号"
private String mCode;
public void setmName(String mName)
{
this.mName = mName;
}
public String getmName()
{
return mName;
}
public void setmCode(String mCode)
{
this.mCode = mCode;
}
public String getmCode()
{
return mCode;
}
}

65
win-print/src/main/java/com/win/print/mapper/WinPrintClientPrintersMapper.java

@ -0,0 +1,65 @@
package com.win.print.mapper;
import java.util.List;
import com.win.print.domain.WinPrintClientPrinterSimple;
import com.win.print.domain.WinPrintClientPrinters;
/**
* 客户端打印机对照Mapper接口
*
* @author zhousq
* @date 2024-07-29
*/
public interface WinPrintClientPrintersMapper
{
/**
* 查询客户端打印机对照
*
* @param id 客户端打印机对照主键
* @return 客户端打印机对照
*/
public WinPrintClientPrinters selectWinPrintClientPrintersById(Long id);
public WinPrintClientPrinterSimple selectClientPrinteByUuid(String uuid);
/**
* 查询客户端打印机对照列表
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 客户端打印机对照集合
*/
public List<WinPrintClientPrinters> selectWinPrintClientPrintersList(WinPrintClientPrinters winPrintClientPrinters);
public List<WinPrintClientPrinters> selectClientPrintersList();
/**
* 新增客户端打印机对照
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 结果
*/
public int insertWinPrintClientPrinters(WinPrintClientPrinters winPrintClientPrinters);
/**
* 修改客户端打印机对照
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 结果
*/
public int updateWinPrintClientPrinters(WinPrintClientPrinters winPrintClientPrinters);
/**
* 删除客户端打印机对照
*
* @param id 客户端打印机对照主键
* @return 结果
*/
public int deleteWinPrintClientPrintersById(Long id);
public int deleteWinPrintClientPrintersByCode(String code);
/**
* 批量删除客户端打印机对照
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteWinPrintClientPrintersByIds(String[] ids);
}

3
win-print/src/main/java/com/win/print/mapper/WinPrintModelMapper.java

@ -3,6 +3,7 @@ package com.win.print.mapper;
import java.util.List;
import com.win.print.domain.WinPrintModel;
import com.win.print.domain.WinPrintModelParams;
import com.win.print.domain.WinPrintModelSimple;
/**
* 打印模版设置Mapper接口
@ -19,6 +20,8 @@ public interface WinPrintModelMapper
* @return 打印模版设置
*/
public WinPrintModel selectWinPrintModelById(Long id);
public WinPrintModelSimple selectWinPrintModelListSimple();
public WinPrintModel selectWinPrintModelByCode(String code);
/**
* 查询打印模版设置列表

10
win-print/src/main/java/com/win/print/service/DictPrinterListService.java

@ -31,4 +31,14 @@ public class DictPrinterListService {
}
return ret;
}
public List<String> getPrintersNameList(){
PrintService[] printServices = PrinterJob.lookupPrintServices();
List<String> ret=new ArrayList<>();
if(printServices.length>0){
for(int i=0;i<printServices.length;i++){
ret.add(printServices[i].getName());
}
}
return ret;
}
}

65
win-print/src/main/java/com/win/print/service/IWinPrintClientPrintersService.java

@ -0,0 +1,65 @@
package com.win.print.service;
import java.util.List;
import com.win.print.domain.WinPrintClientPrinterSimple;
import com.win.print.domain.WinPrintClientPrinters;
/**
* 客户端打印机对照Service接口
*
* @author zhousq
* @date 2024-07-29
*/
public interface IWinPrintClientPrintersService
{
/**
* 查询客户端打印机对照
*
* @param id 客户端打印机对照主键
* @return 客户端打印机对照
*/
public WinPrintClientPrinters selectWinPrintClientPrintersById(Long id);
public WinPrintClientPrinterSimple selectWinPrintClientPrintersByUuid(String uuid);
/**
* 查询客户端打印机对照列表
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 客户端打印机对照集合
*/
public List<WinPrintClientPrinters> selectWinPrintClientPrintersList(WinPrintClientPrinters winPrintClientPrinters);
public List<WinPrintClientPrinters> selectClientPrintersList();
/**
* 新增客户端打印机对照
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 结果
*/
public int insertWinPrintClientPrinters(WinPrintClientPrinters winPrintClientPrinters);
/**
* 修改客户端打印机对照
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 结果
*/
public int updateWinPrintClientPrinters(WinPrintClientPrinters winPrintClientPrinters);
/**
* 批量删除客户端打印机对照
*
* @param ids 需要删除的客户端打印机对照主键集合
* @return 结果
*/
public int deleteWinPrintClientPrintersByIds(String ids);
/**
* 删除客户端打印机对照信息
*
* @param id 客户端打印机对照主键
* @return 结果
*/
public int deleteWinPrintClientPrintersById(Long id);
public int deleteWinPrintClientPrintersByCode(String code);
}

2
win-print/src/main/java/com/win/print/service/IWinPrintModelService.java

@ -2,6 +2,7 @@ package com.win.print.service;
import java.util.List;
import com.win.print.domain.WinPrintModel;
import com.win.print.domain.WinPrintModelSimple;
/**
* 打印模版设置Service接口
@ -18,6 +19,7 @@ public interface IWinPrintModelService
* @return 打印模版设置
*/
public WinPrintModel selectWinPrintModelById(Long id);
public WinPrintModelSimple selectWinPrintModelListSimple();
/**
* 查询打印模版设置列表

2
win-print/src/main/java/com/win/print/service/IWinPrintTasksLogsService.java

@ -1,5 +1,6 @@
package com.win.print.service;
import java.util.Date;
import java.util.List;
import com.win.print.domain.WinPrintTasksLogs;
@ -59,4 +60,5 @@ public interface IWinPrintTasksLogsService
* @return 结果
*/
public int deleteWinPrintTasksLogsById(Long id);
public void createTaskLog(String clientCode, String fileName, String taskId, String printType, String modelCode, String printerName, String requestType, Integer copyCounts, String modelPage, String isPageRolated, String remark, Date printTime, String fileServer);
}

40
win-print/src/main/java/com/win/print/service/LocalPrinterDataUpdateTask.java

@ -0,0 +1,40 @@
package com.win.print.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.win.common.config.WinConfig;
import com.win.print.domain.WinPrintClientPrinters;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 手动任务可以下发通知接收到打印数据更新
*
* */
@Service
public class LocalPrinterDataUpdateTask {
@Resource
IWinPrintClientPrintersService iWinPrintClientPrintersService;
@Resource
DictPrinterListService dictPrinterListService;
@Transactional()
public void updatePrinterToDb(){
iWinPrintClientPrintersService.deleteWinPrintClientPrintersByCode(WinConfig.getClientCode());
List<String> printersNameList = dictPrinterListService.getPrintersNameList();
if(CollUtil.isNotEmpty(printersNameList)){
printersNameList.forEach(item->{
WinPrintClientPrinters wp=new WinPrintClientPrinters();
wp.setUpdatedBy("auto");
wp.setCreatedBy("auto");
wp.setPrinterName(item);
wp.setUpdatedTime(DateUtil.date());
wp.setCreatedTime(DateUtil.date());
wp.setClientCode(WinConfig.getClientCode());
iWinPrintClientPrintersService.insertWinPrintClientPrinters(wp);
});
}
}
}

109
win-print/src/main/java/com/win/print/service/impl/WinPrintClientPrintersServiceImpl.java

@ -0,0 +1,109 @@
package com.win.print.service.impl;
import java.util.List;
import com.win.print.domain.WinPrintClientPrinterSimple;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.win.print.mapper.WinPrintClientPrintersMapper;
import com.win.print.domain.WinPrintClientPrinters;
import com.win.print.service.IWinPrintClientPrintersService;
import com.win.common.core.text.Convert;
/**
* 客户端打印机对照Service业务层处理
*
* @author zhousq
* @date 2024-07-29
*/
@Service
public class WinPrintClientPrintersServiceImpl implements IWinPrintClientPrintersService
{
@Resource
private WinPrintClientPrintersMapper winPrintClientPrintersMapper;
/**
* 查询客户端打印机对照
*
* @param id 客户端打印机对照主键
* @return 客户端打印机对照
*/
@Override
public WinPrintClientPrinters selectWinPrintClientPrintersById(Long id)
{
return winPrintClientPrintersMapper.selectWinPrintClientPrintersById(id);
}
@Override
public WinPrintClientPrinterSimple selectWinPrintClientPrintersByUuid(String uuid)
{
return winPrintClientPrintersMapper.selectClientPrinteByUuid(uuid);
}
/**
* 查询客户端打印机对照列表
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 客户端打印机对照
*/
@Override
public List<WinPrintClientPrinters> selectWinPrintClientPrintersList(WinPrintClientPrinters winPrintClientPrinters)
{
return winPrintClientPrintersMapper.selectWinPrintClientPrintersList(winPrintClientPrinters);
}
@Override
public List<WinPrintClientPrinters> selectClientPrintersList(){
return winPrintClientPrintersMapper.selectClientPrintersList();
}
/**
* 新增客户端打印机对照
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 结果
*/
@Override
public int insertWinPrintClientPrinters(WinPrintClientPrinters winPrintClientPrinters)
{
return winPrintClientPrintersMapper.insertWinPrintClientPrinters(winPrintClientPrinters);
}
/**
* 修改客户端打印机对照
*
* @param winPrintClientPrinters 客户端打印机对照
* @return 结果
*/
@Override
public int updateWinPrintClientPrinters(WinPrintClientPrinters winPrintClientPrinters)
{
return winPrintClientPrintersMapper.updateWinPrintClientPrinters(winPrintClientPrinters);
}
/**
* 批量删除客户端打印机对照
*
* @param ids 需要删除的客户端打印机对照主键
* @return 结果
*/
@Override
public int deleteWinPrintClientPrintersByIds(String ids)
{
return winPrintClientPrintersMapper.deleteWinPrintClientPrintersByIds(Convert.toStrArray(ids));
}
/**
* 删除客户端打印机对照信息
*
* @param id 客户端打印机对照主键
* @return 结果
*/
@Override
public int deleteWinPrintClientPrintersById(Long id)
{
return winPrintClientPrintersMapper.deleteWinPrintClientPrintersById(id);
}
@Override
public int deleteWinPrintClientPrintersByCode(String code){
return winPrintClientPrintersMapper.deleteWinPrintClientPrintersByCode(code);
}
}

7
win-print/src/main/java/com/win/print/service/impl/WinPrintModelServiceImpl.java

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List;
import cn.hutool.core.date.DateUtil;
import com.win.print.domain.WinPrintModelSimple;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -39,6 +40,12 @@ public class WinPrintModelServiceImpl implements IWinPrintModelService
{
return winPrintModelMapper.selectWinPrintModelById(id);
}
@Override
public WinPrintModelSimple selectWinPrintModelListSimple()
{
return winPrintModelMapper.selectWinPrintModelListSimple();
}
@Override

28
win-print/src/main/java/com/win/print/service/impl/WinPrintTasksLogsServiceImpl.java

@ -1,6 +1,12 @@
package com.win.print.service.impl;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.win.common.config.WinConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.win.print.mapper.WinPrintTasksLogsMapper;
@ -104,4 +110,26 @@ public class WinPrintTasksLogsServiceImpl implements IWinPrintTasksLogsService
{
return winPrintTasksLogsMapper.deleteWinPrintTasksLogsById(id);
}
@Override
public void createTaskLog(String clientCode, String fileName, String taskId, String printType, String modelCode, String printerName, String requestType, Integer copyCounts, String modelPage, String isPageRolated, String remark, Date printTime, String fileServer){
WinPrintTasksLogs logs=new WinPrintTasksLogs();
logs.setClientCode(clientCode);
logs.setTaskId(Optional.ofNullable(taskId).orElse(IdUtil.fastSimpleUUID()));
logs.setCreatedBy(WinConfig.getClientCode());
logs.setCreatedTime(DateUtil.date());
logs.setDataFile(fileName);
logs.setIpAddr(fileServer);
logs.setPrintType(printType);
logs.setModelCode(modelCode);
logs.setPrinterName(printerName);
logs.setRequestType(requestType);
logs.setTaskStatus("0");
logs.setSettingCode("");
logs.setCopyCounts(copyCounts);
logs.setModelPage(modelPage);
logs.setIsPageRolated(isPageRolated);
logs.setRemark(remark);
logs.setPrintTime(printTime);
winPrintTasksLogsMapper.insertWinPrintTasksLogs(logs);
}
}

290
win-print/src/main/java/com/win/print/util/PdfModelUitl.java

@ -0,0 +1,290 @@
package com.win.print.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.io.image.ImageType;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
import com.itextpdf.kernel.pdf.annot.PdfWidgetAnnotation;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.win.common.utils.file.ImageUtils;
import com.win.print.domain.WinPrintModel;
import com.win.print.domain.WinPrintModelParams;
import com.win.print.service.IWinPrintModelParamsService;
import com.win.print.service.IWinPrintModelService;
import com.win.print.service.IWinPrintTasksLogsService;
import com.win.print.service.QRCodeService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* pdf 模版处理工具类
*/
@Service
public class PdfModelUitl {
private static final Logger log = LoggerFactory.getLogger(PdfModelUitl.class);
//通过pdfform方式进行模版渲染后生成新的文档
@Resource
QRCodeService qrCodeService;
@Value("${win.path.template}")
private String templatePathDefault; //打印模版的存储路径
@Value("${win.path.print}")
private String printFilepath; //生成的打印文件存储路径
/**
* 待填充的PDF模板文档
*/
public void pdfMdelFromRender(List<WinPrintModelParams> paramsList,File tempFile, JSONObject data, String modelName, String templatePath) throws IOException, NoSuchFieldException {
PdfReader reader = new PdfReader(templatePath+"/"+modelName);
PdfWriter writer = new PdfWriter(tempFile);
PdfDocument pdf = new PdfDocument(reader, writer);
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
if (CollUtil.isNotEmpty(paramsList)) {
if (ObjectUtil.isNotEmpty(data)) {
paramsList.forEach(item -> {
if ("QRIMG".equals(item.getParamType())) {
//渲染Qr图片
qrCodeService.generateQRCode(Optional.ofNullable(data.getString(item.getParamCode())).orElse(""),172,172);
} else if ("IMG".equals(item.getParamType())) {
//渲染普通图片
} else {
Optional.ofNullable( form.getField(item.getParamCode())).ifPresent(act->{act.setValue(Optional.ofNullable(data.getString(item.getParamCode())).orElse(""));});
}
});
} else {
throw new NoSuchFieldException("没有任何可渲染的数据内容!");
}
} else { //如果没有配置任何模版参数抛出异常
throw new NoSuchFieldException("没找到模版的参数配置信息!");
}
// 重复以上步骤,根据需要填充所有字段
// 设置表单为只读(可选)
form.flattenFields();
pdf.close();
}
/**
* 填充及返回填充后的数据
*
* @param fillData - 待填充数据
* @return - 填充后bytes数据
*/
public void fill(Map<String, Object> fillData,PdfDocument templateDocument) {
try {
PdfAcroForm form = PdfAcroForm.getAcroForm(templateDocument, true);
fillData.forEach((keyword, value) -> {
Optional.ofNullable(form.getField(keyword)).ifPresent(templateFormField -> {
if (value instanceof byte[]) {
PdfArray pos = templateFormField.getWidgets().get(0).getRectangle();
float x = pos.getAsNumber(0).floatValue();
float y = pos.getAsNumber(1).floatValue();
float width = pos.getAsNumber(2).floatValue() - x;
float height = pos.getAsNumber(3).floatValue() - y;
Rectangle rectangle = new Rectangle(x, y, width, height);
PdfWidgetAnnotation widget = new PdfWidgetAnnotation(rectangle);
PdfFormField formField = PdfFormField.createEmptyField(templateDocument);
PdfPage annotationPage = findAnnotationPage(keyword,templateDocument);
if (annotationPage != null) {
doFillFieldImage(annotationPage, formField, (byte[]) value);
}
} else {
templateFormField.setValue(String.valueOf(value));
if (defaultFont() != null) {
templateFormField.setFont(templateFormField.getFont());
}
}
form.partialFormFlattening(keyword);
});
});
form.flattenFields();
} finally {
if (templateDocument != null) {
templateDocument.close();
}
}
}
/**
* 图片填充
*
* @param newPage - 当前页
* @param formField - 表单文本域
* @param imgBytes - 图片文件字节数组
*/
private void doFillFieldImage(PdfPage newPage, PdfFormField formField, byte[] imgBytes) {
Rectangle rtl = formField.getWidgets().get(0).getRectangle().toRectangle(); // 获取表单域的xy坐标
PdfCanvas canvas = new PdfCanvas(newPage);
ImageData img = ImageDataFactory.create(imgBytes);
if (Float.compare(img.getWidth(), rtl.getWidth()) <= 0 && Float.compare(img.getHeight(), rtl.getHeight()) <= 0) {// 不处理
canvas.addImage(img, rtl.getX(), rtl.getY(), true);
} else {
// 压缩图片。计算得到图片放缩的最大比例
float scale = Math.max(img.getWidth() / rtl.getWidth(), img.getHeight() / rtl.getHeight());
int imgWidth = Math.round(img.getWidth() / scale);
int imgHeight = Math.round(img.getHeight() / scale);
// 压缩图片
byte[] compressImgBytes;
Image scale1 = ImgUtil.scale(ImgUtil.toImage(imgBytes), scale);
compressImgBytes = ImgUtil.toBytes(scale1, ImgUtil.IMAGE_TYPE_PNG);
img = ImageDataFactory.create(compressImgBytes);
canvas.addImage(img, rtl.getX(), rtl.getY(), true);
}
}
/**
* 根据表单域关键字查找当前关键字所在页对象PdfPage
*
* @param keyword - 关键字
* @return - page object
*/
private PdfPage findAnnotationPage(String keyword,PdfDocument templateDocument) {
int pages = templateDocument.getNumberOfPages();
for (int index = 1; index <= pages; index++) {
PdfPage page = templateDocument.getPage(index);
for (PdfAnnotation annotation : page.getAnnotations()) {
PdfString title = annotation.getPdfObject().getAsString(PdfName.T);
if (title != null && keyword.equals(String.valueOf(title))) {
return page;
}
}
}
return null;
}
/**
* 获取模板文件表单域关键字位置信息
*/
private Map<Integer, Map<String, float[]>> getFormKeywordsPos(PdfDocument templateDocument) {
int pages = templateDocument.getNumberOfPages();
Map<Integer, Map<String, float[]>> maps = new HashMap<>(pages);
for (int index = 1; index <= pages; index++) {
maps.putIfAbsent(index, new HashMap<>());
PdfPage page = templateDocument.getPage(index);
// 获取当前页的表单域
int finalIndex = index;
page.getAnnotations().forEach(anno -> {
PdfString title = anno.getTitle();
PdfArray rectangle = anno.getRectangle();
float x = rectangle.getAsNumber(0).floatValue();
float y = rectangle.getAsNumber(1).floatValue();
float width = rectangle.getAsNumber(2).floatValue() - x;
float height = rectangle.getAsNumber(3).floatValue() - y;
maps.get(finalIndex).put(title.getValue(), new float[]{x, y, width, height});
});
}
return maps;
}
/**
* 加载字体
*/
private static final String ILLEGAL_CHARACTERS_REGEX = "[\\\\/:*?\"<>|]";
private static final String DEFAULT_FONT_PATH = "/fonts/STKAITI.TTF";
private static final String DEFAULT_EXTEND_PATH = "/fonts/extend/";
private static final Map<String, String> FONTS_MAP = fontsMap();
/**
* 默认字体
* @return PdfFont
* @throws IOException
*/
private PdfFont defaultFont() {
// 默认华文楷体
PdfFont baseFont;
try {
baseFont = PdfFontFactory.createFont(DEFAULT_FONT_PATH, PdfEncodings.IDENTITY_H);
} catch (Exception e) {
throw new RuntimeException("无法获取默认字体:" + e.getMessage(),e);
}
return baseFont;
}
/**
* 获取字体
* @param font 字体信息
* @return PdfFont
*/
String extendPath = "D:\\fonts\\";
private PdfFont getFont(PdfFont font) {
String fontName = font.getFontProgram().getFontNames().getFontName();
String fontKey = FONTS_MAP.get(fontName);
if(fontKey==null){
font = defaultFont();
}else {
try {
if(fontKey.toLowerCase().endsWith("ttc")){
font = PdfFontFactory.createFont(this.extendPath + fontKey + ",0", PdfEncodings.IDENTITY_H);
}else {
font = PdfFontFactory.createFont(this.extendPath + fontKey, PdfEncodings.IDENTITY_H);
}
} catch (IOException e) {
font = defaultFont();
e.printStackTrace();
}
}
return font;
}
/**
* 字体映射关系
* @return
*/
private static Map<String, String> fontsMap(){
Map<String, String> map = new HashMap<>();
// 字体映射关系,可扩展
// itext字体标注/字体文件名
map.put("DengXian", "Deng.ttf");//等线
map.put("DengXian-Light", "Dengl.ttf");//等线Light
map.put("DengXian,Bold", "Dengb.ttf");//等线粗体
map.put("FZShuTi", "FZSTK.TTF");//方正舒体
map.put("FZYaoTi", "FZYTK.TTF");//方正姚体
map.put("FangSong", "simfang.ttf");//仿宋
map.put("SimHei", "simhei.ttf");//黑体
map.put("STCaiyun", "STCAIYUN.TTF");//华文彩云
map.put("STFangsong", "STFANGSO.TTF");//华文仿宋
map.put("STHupo", "STHUPO.TTF");//华文琥珀
map.put("STKaiti", "STKAITI.TTF");//华文楷体
map.put("STLiti", "STLITI.TTF");//华文隶书
map.put("STSong", "STSONG.TTF");//华文宋体
map.put("STXihei", "STXIHEI.TTF");//华文细黑
map.put("STXinwei", "STXINWEI.TTF");//华文新魏
map.put("STXingkai", "STXINGKA.TTF");//华文行楷
map.put("STZhongsong", "STZHONGS.TTF");//华文中宋
map.put("KaiTi", "simkai.ttf");//楷体
map.put("LiSu", "SIMLI.TTF");//隶书
map.put("SimSun", "simsun.ttc");//宋体
map.put("MicrosoftYaHei", "msyh.ttc");//微软雅黑
map.put("MicrosoftYaHeiLight", "msyhl.ttc");//微软雅黑Light
map.put("MicrosoftYaHei,Bold", "msyhbd.ttc");//微软雅黑粗体
map.put("NSimSun", "simsun.ttc");//新宋体
map.put("YouYuan", "SIMYOU.TTF");//幼圆
return map;
}
}

117
win-print/src/main/resources/mapper/print/WinPrintClientPrintersMapper.xml

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.win.print.mapper.WinPrintClientPrintersMapper">
<resultMap type="WinPrintClientPrinters" id="WinPrintClientPrintersResult">
<result property="tenantId" column="tenant_id" />
<result property="revision" column="revision" />
<result property="createdBy" column="created_by" />
<result property="createdTime" column="created_time" />
<result property="updatedBy" column="updated_by" />
<result property="updatedTime" column="updated_time" />
<result property="clientCode" column="client_code" />
<result property="printerName" column="printer_name" />
<result property="printerUuid" column="printer_uuid" />
<result property="printerNameBusy" column="printer_name_busy" />
<result property="id" column="id" />
<result property="status" column="status" />
</resultMap>
<resultMap type="WinPrintClientPrinterSimple" id="WinPrintClientPrintersResultSimple">
<result property="clientCode" column="client_code" />
<result property="printerName" column="printer_name" />
<result property="printerUuid" column="printer_uuid" />
<result property="printerNameBusy" column="printer_name_busy" />
</resultMap>
<sql id="selectWinPrintClientPrintersVo">
select tenant_id, revision, created_by, created_time, updated_by, updated_time, client_code, printer_name,printer_uuid,printer_name_busy,id,status from win_print_client_printers
</sql>
<select id="selectWinPrintClientPrintersList" parameterType="WinPrintClientPrinters" resultMap="WinPrintClientPrintersResult">
<include refid="selectWinPrintClientPrintersVo"/>
<where>
<if test="clientCode != null and clientCode != ''"> and client_code = #{clientCode}</if>
<if test="printerName != null and printerName != ''"> and printer_name like concat('%', #{printerName}, '%')</if>
<if test="printerNameBusy != null and printerNameBusy != ''"> and printer_name_busy like concat('%', #{printerNameBusy}, '%')</if>
</where>
</select>
<select id="selectClientPrintersList" resultMap="WinPrintClientPrintersResultSimple">
<include refid="selectWinPrintClientPrintersVo"/>
where status='0'
order by printer_uuid desc
</select>
<select id="selectClientPrinteByUuid" parameterType="String" resultMap="WinPrintClientPrintersResultSimple">
<include refid="selectWinPrintClientPrintersVo"/>
where status='0' and printer_uuid=#{uuid}
</select>
<select id="selectWinPrintClientPrintersById" parameterType="Long" resultMap="WinPrintClientPrintersResult">
<include refid="selectWinPrintClientPrintersVo"/>
where id = #{id}
</select>
<insert id="insertWinPrintClientPrinters" parameterType="WinPrintClientPrinters">
insert into win_print_client_printers
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="tenantId != null">tenant_id,</if>
<if test="revision != null">revision,</if>
<if test="createdBy != null">created_by,</if>
<if test="createdTime != null">created_time,</if>
<if test="updatedBy != null">updated_by,</if>
<if test="updatedTime != null">updated_time,</if>
<if test="clientCode != null">client_code,</if>
<if test="printerName != null">printer_name,</if>
<if test="printerUuid != null">printer_uuid,</if>
<if test="printerNameBusy != null">printer_name_busy,</if>
<if test="status != null">status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="tenantId != null">#{tenantId},</if>
<if test="revision != null">#{revision},</if>
<if test="createdBy != null">#{createdBy},</if>
<if test="createdTime != null">#{createdTime},</if>
<if test="updatedBy != null">#{updatedBy},</if>
<if test="updatedTime != null">#{updatedTime},</if>
<if test="clientCode != null">#{clientCode},</if>
<if test="printerName != null">#{printerName},</if>
<if test="printerUuid != null">#{printerUuid},</if>
<if test="printerNameBusy != null">#{printerNameBusy},</if>
<if test="status != null">#{status},</if>
</trim>
</insert>
<update id="updateWinPrintClientPrinters" parameterType="WinPrintClientPrinters">
update win_print_client_printers
<trim prefix="SET" suffixOverrides=",">
<if test="revision != null">revision = #{revision},</if>
<if test="createdBy != null">created_by = #{createdBy},</if>
<if test="createdTime != null">created_time = #{createdTime},</if>
<if test="updatedBy != null">updated_by = #{updatedBy},</if>
<if test="updatedTime != null">updated_time = #{updatedTime},</if>
<if test="clientCode != null">client_code = #{clientCode},</if>
<if test="printerName != null">printer_name = #{printerName},</if>
<if test="printerUuid != null">printer_uuid=#{printerUuid},</if>
<if test="printerNameBusy != null">printer_name_busy=#{printerNameBusy},</if>
<if test="status != null">status=#{status},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteWinPrintClientPrintersById" parameterType="Long">
delete from win_print_client_printers where id = #{id}
</delete>
<delete id="deleteWinPrintClientPrintersByUuid" parameterType="String">
delete from win_print_client_printers where printer_uuid = #{uuid}
</delete>
<delete id="deleteWinPrintClientPrintersByCode" parameterType="String">
delete from win_print_client_printers where client_code = #{clientCode}
</delete>
<delete id="deleteWinPrintClientPrintersByIds" parameterType="String">
delete from win_print_client_printers where id in
<foreach item="ids" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

8
win-print/src/main/resources/mapper/print/WinPrintModelMapper.xml

@ -23,6 +23,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="isPageRotate" column="is_page_rotate" />
<result property="mData" column="m_data" />
</resultMap>
<resultMap type="WinPrintModelSimple" id="WinPrintModelWinPrintSimple">
<result property="mName" column="m_name" />
<result property="mCode" column="m_code" />
</resultMap>
<resultMap id="WinPrintModelWinPrintModelParamsResult" type="WinPrintModel" extends="WinPrintModelResult">
<collection property="winPrintModelParamsList" ofType="WinPrintModelParams" column="m_code" select="selectWinPrintModelParamsList" />
@ -62,6 +66,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectWinPrintModelVo"/>
where id = #{id}
</select>
<select id="selectWinPrintModelListSimple" resultMap="WinPrintModelWinPrintSimple">
select m_name, m_code from win_print_model
</select>
<select id="selectWinPrintModelByCode" parameterType="String" resultMap="WinPrintModelWinPrintModelParamsResult">
<include refid="selectWinPrintModelVo"/>
where m_code = #{code}

57
win-print/src/main/resources/templates/print/clientPrinters/add.html

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('新增打印机')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-clientPrinters-add">
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">客户端编码:</label>
<div class="col-sm-8">
<input name="clientCode" class="form-control" type="text" required>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">打印机实体名:</label>
<div class="col-sm-8">
<input name="printerName" class="form-control" type="text" required>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">打印机全局码:</label>
<div class="col-sm-8">
<input name="printerUuid" class="form-control" type="text" required>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">打印机业务名:</label>
<div class="col-sm-8">
<input name="printerNameBusy" class="form-control" type="text" required>
</div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var prefix = ctx + "print/clientPrinters"
$("#form-clientPrinters-add").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/add", $('#form-clientPrinters-add').serialize());
}
}
</script>
</body>
</html>

111
win-print/src/main/resources/templates/print/clientPrinters/clientPrinters.html

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('客户端打印机对照列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
<label>客户端编码:</label>
<input type="text" name="clientCode"/>
</li>
<li>
<label>打印机实体名称:</label>
<input type="text" name="printerName"/>
</li>
<li>
<label>打印机业务名称:</label>
<input type="text" name="printerNameBusy"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="print:clientPrinters:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="print:clientPrinters:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="print:clientPrinters:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="print:clientPrinters:export">
<i class="fa fa-download"></i> 导出
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('print:clientPrinters:edit')}]];
var removeFlag = [[${@permission.hasPermi('print:clientPrinters:remove')}]];
var prefix = ctx + "print/clientPrinters";
$(function() {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "客户端打印机对照",
columns: [{
checkbox: true
},
{
field: 'clientCode',
title: '客户端编码'
},
{
field: 'printerName',
title: '打印机实体名称'
},
{
field: 'printerUuid',
title: '打印机编码',
visible: false
},
{
field: 'printerNameBusy',
title: '打印机业务名称'
},
{
field: 'status',
title: '状态'
},
{
field: 'id',
title: '',
visible: false
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
}]
};
$.table.init(options);
});
</script>
</body>
</html>

58
win-print/src/main/resources/templates/print/clientPrinters/edit.html

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改打印机')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-clientPrinters-edit" th:object="${winPrintClientPrinters}">
<input name="id" th:field="*{id}" type="hidden">
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">客户端编码:</label>
<div class="col-sm-8">
<input name="clientCode" th:field="*{clientCode}" class="form-control" type="text" required>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">打印机实体名称:</label>
<div class="col-sm-8">
<input name="printerName" th:field="*{printerName}" class="form-control" type="text" required>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">打印机全局码:</label>
<div class="col-sm-8">
<input name="printerUuid" class="form-control" th:field="*{printerUuid}" type="text" readonly>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label class="col-sm-3 control-label">打印机业务名称:</label>
<div class="col-sm-8">
<input name="printerNameBusy" th:field="*{printerNameBusy}" class="form-control" type="text" required>
</div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var prefix = ctx + "print/clientPrinters";
$("#form-clientPrinters-edit").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-clientPrinters-edit').serialize());
}
}
</script>
</body>
</html>
Loading…
Cancel
Save