diff --git a/models/wuliaotest.pdf b/models/wuliaotest.pdf new file mode 100644 index 0000000..bcf3ab8 Binary files /dev/null and b/models/wuliaotest.pdf differ diff --git a/win-admin/src/main/java/com/win/web/controller/print/WinPrintServerControler.java b/win-admin/src/main/java/com/win/web/controller/print/WinPrintServerControler.java index 0573540..4ee1711 100644 --- a/win-admin/src/main/java/com/win/web/controller/print/WinPrintServerControler.java +++ b/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 winPrintModelParamsList = winPrintModel.getWinPrintModelParamsList(); List 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 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 data, PageSize pageSize, String modelName, String modeTypeSrc, String templatePath) { + private void printOneByOne(List 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 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 paramList, List dataList, String modelName, PageSize pageSize, String fileName, String modeTypeSrc, String templatePath) { + private void printMutilPage(List paramList, List 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 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 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); - } + } diff --git a/win-print/src/main/java/com/win/print/controller/WinPrintClientPrintersController.java b/win-print/src/main/java/com/win/print/controller/WinPrintClientPrintersController.java new file mode 100644 index 0000000..fa8b2d3 --- /dev/null +++ b/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 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 list = winPrintClientPrintersService.selectWinPrintClientPrintersList(winPrintClientPrinters); + ExcelUtil util = new ExcelUtil(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)); + } +} diff --git a/win-print/src/main/java/com/win/print/domain/PrintModelDataVo.java b/win-print/src/main/java/com/win/print/domain/PrintModelDataVo.java index 39eba78..ad00483 100644 --- a/win-print/src/main/java/com/win/print/domain/PrintModelDataVo.java +++ b/win-print/src/main/java/com/win/print/domain/PrintModelDataVo.java @@ -31,6 +31,7 @@ public class PrintModelDataVo { * 打印机名称必须穿 * */ private String printerName; + private String printerUuid;//全局打印机编码 /** * 计划打印时间, * */ diff --git a/win-print/src/main/java/com/win/print/domain/WinPrintClientPrinterSimple.java b/win-print/src/main/java/com/win/print/domain/WinPrintClientPrinterSimple.java new file mode 100644 index 0000000..4dffc12 --- /dev/null +++ b/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; + } + + +} diff --git a/win-print/src/main/java/com/win/print/domain/WinPrintClientPrinters.java b/win-print/src/main/java/com/win/print/domain/WinPrintClientPrinters.java new file mode 100644 index 0000000..87d9aba --- /dev/null +++ b/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(); + } +} diff --git a/win-print/src/main/java/com/win/print/domain/WinPrintModelSimple.java b/win-print/src/main/java/com/win/print/domain/WinPrintModelSimple.java new file mode 100644 index 0000000..e1691ae --- /dev/null +++ b/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; + } + + +} diff --git a/win-print/src/main/java/com/win/print/mapper/WinPrintClientPrintersMapper.java b/win-print/src/main/java/com/win/print/mapper/WinPrintClientPrintersMapper.java new file mode 100644 index 0000000..753c474 --- /dev/null +++ b/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 selectWinPrintClientPrintersList(WinPrintClientPrinters winPrintClientPrinters); + public List 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); +} diff --git a/win-print/src/main/java/com/win/print/mapper/WinPrintModelMapper.java b/win-print/src/main/java/com/win/print/mapper/WinPrintModelMapper.java index e721c83..d013ffa 100644 --- a/win-print/src/main/java/com/win/print/mapper/WinPrintModelMapper.java +++ b/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); /** * 查询打印模版设置列表 diff --git a/win-print/src/main/java/com/win/print/service/DictPrinterListService.java b/win-print/src/main/java/com/win/print/service/DictPrinterListService.java index a7d547e..8acf774 100644 --- a/win-print/src/main/java/com/win/print/service/DictPrinterListService.java +++ b/win-print/src/main/java/com/win/print/service/DictPrinterListService.java @@ -31,4 +31,14 @@ public class DictPrinterListService { } return ret; } + public List getPrintersNameList(){ + PrintService[] printServices = PrinterJob.lookupPrintServices(); + List ret=new ArrayList<>(); + if(printServices.length>0){ + for(int i=0;i selectWinPrintClientPrintersList(WinPrintClientPrinters winPrintClientPrinters); + public List 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); + +} diff --git a/win-print/src/main/java/com/win/print/service/IWinPrintModelService.java b/win-print/src/main/java/com/win/print/service/IWinPrintModelService.java index c68b726..90086b2 100644 --- a/win-print/src/main/java/com/win/print/service/IWinPrintModelService.java +++ b/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(); /** * 查询打印模版设置列表 diff --git a/win-print/src/main/java/com/win/print/service/IWinPrintTasksLogsService.java b/win-print/src/main/java/com/win/print/service/IWinPrintTasksLogsService.java index 9cca78b..6ddf326 100644 --- a/win-print/src/main/java/com/win/print/service/IWinPrintTasksLogsService.java +++ b/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); } diff --git a/win-print/src/main/java/com/win/print/service/LocalPrinterDataUpdateTask.java b/win-print/src/main/java/com/win/print/service/LocalPrinterDataUpdateTask.java new file mode 100644 index 0000000..e5e9ba5 --- /dev/null +++ b/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 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); + }); + } + } +} diff --git a/win-print/src/main/java/com/win/print/service/impl/WinPrintClientPrintersServiceImpl.java b/win-print/src/main/java/com/win/print/service/impl/WinPrintClientPrintersServiceImpl.java new file mode 100644 index 0000000..a5f5b7a --- /dev/null +++ b/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 selectWinPrintClientPrintersList(WinPrintClientPrinters winPrintClientPrinters) + { + return winPrintClientPrintersMapper.selectWinPrintClientPrintersList(winPrintClientPrinters); + } + @Override + public List 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); + } +} diff --git a/win-print/src/main/java/com/win/print/service/impl/WinPrintModelServiceImpl.java b/win-print/src/main/java/com/win/print/service/impl/WinPrintModelServiceImpl.java index c40fd49..118f1d0 100644 --- a/win-print/src/main/java/com/win/print/service/impl/WinPrintModelServiceImpl.java +++ b/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 diff --git a/win-print/src/main/java/com/win/print/service/impl/WinPrintTasksLogsServiceImpl.java b/win-print/src/main/java/com/win/print/service/impl/WinPrintTasksLogsServiceImpl.java index 9a83fe8..d1661c1 100644 --- a/win-print/src/main/java/com/win/print/service/impl/WinPrintTasksLogsServiceImpl.java +++ b/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); + } } diff --git a/win-print/src/main/java/com/win/print/util/PdfModelUitl.java b/win-print/src/main/java/com/win/print/util/PdfModelUitl.java new file mode 100644 index 0000000..82ef66b --- /dev/null +++ b/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 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 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> getFormKeywordsPos(PdfDocument templateDocument) { + int pages = templateDocument.getNumberOfPages(); + Map> 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 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 fontsMap(){ + Map 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; + } +} diff --git a/win-print/src/main/resources/mapper/print/WinPrintClientPrintersMapper.xml b/win-print/src/main/resources/mapper/print/WinPrintClientPrintersMapper.xml new file mode 100644 index 0000000..ecd0ff1 --- /dev/null +++ b/win-print/src/main/resources/mapper/print/WinPrintClientPrintersMapper.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + insert into win_print_client_printers + + tenant_id, + revision, + created_by, + created_time, + updated_by, + updated_time, + client_code, + printer_name, + printer_uuid, + printer_name_busy, + status, + + + #{tenantId}, + #{revision}, + #{createdBy}, + #{createdTime}, + #{updatedBy}, + #{updatedTime}, + #{clientCode}, + #{printerName}, + #{printerUuid}, + #{printerNameBusy}, + #{status}, + + + + + update win_print_client_printers + + revision = #{revision}, + created_by = #{createdBy}, + created_time = #{createdTime}, + updated_by = #{updatedBy}, + updated_time = #{updatedTime}, + client_code = #{clientCode}, + printer_name = #{printerName}, + printer_uuid=#{printerUuid}, + printer_name_busy=#{printerNameBusy}, + status=#{status}, + + where id = #{id} + + + + delete from win_print_client_printers where id = #{id} + + + delete from win_print_client_printers where printer_uuid = #{uuid} + + + delete from win_print_client_printers where client_code = #{clientCode} + + + + delete from win_print_client_printers where id in + + #{id} + + + + \ No newline at end of file diff --git a/win-print/src/main/resources/mapper/print/WinPrintModelMapper.xml b/win-print/src/main/resources/mapper/print/WinPrintModelMapper.xml index 51a3f3d..5927acf 100644 --- a/win-print/src/main/resources/mapper/print/WinPrintModelMapper.xml +++ b/win-print/src/main/resources/mapper/print/WinPrintModelMapper.xml @@ -23,6 +23,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + @@ -62,6 +66,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + + + + +
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ + + + + + \ No newline at end of file diff --git a/win-print/src/main/resources/templates/print/clientPrinters/clientPrinters.html b/win-print/src/main/resources/templates/print/clientPrinters/clientPrinters.html new file mode 100644 index 0000000..8b7ae82 --- /dev/null +++ b/win-print/src/main/resources/templates/print/clientPrinters/clientPrinters.html @@ -0,0 +1,111 @@ + + + + + + +
+
+
+
+
+
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • +  搜索 +  重置 +
  • +
+
+
+
+ + +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/win-print/src/main/resources/templates/print/clientPrinters/edit.html b/win-print/src/main/resources/templates/print/clientPrinters/edit.html new file mode 100644 index 0000000..4f64c73 --- /dev/null +++ b/win-print/src/main/resources/templates/print/clientPrinters/edit.html @@ -0,0 +1,58 @@ + + + + + + +
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ + + + \ No newline at end of file