Creato servizio di stampa documenti
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
import it.integry.ems_model.utility.dto.IndexTableDTO;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Migration_20250307115037 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("ALTER TABLE wtb_jrept_setup ADD cod_dtip VARCHAR(5)");
|
||||
|
||||
executeStatement("ALTER TABLE wtb_jrept_setup\n" +
|
||||
"ADD CONSTRAINT wtb_jrept_setup_dtb_tipi_cod_dtip_fk FOREIGN KEY (cod_dtip)\n" +
|
||||
"REFERENCES dtb_tipi(cod_dtip)");
|
||||
|
||||
dropIndex("wtb_jrept_setup", "wtb_jrept_setup_cod_mdep_tipo_cod_anag_uindex");
|
||||
|
||||
createIndex(new IndexTableDTO()
|
||||
.setIndexName("idx_wtb_jrept_setup_unique")
|
||||
.setTableName("wtb_jrept_setup")
|
||||
.setColumnsIndex(Arrays.asList(
|
||||
new IndexTableDTO.ColumnIndex("cod_mdep"),
|
||||
new IndexTableDTO.ColumnIndex("tipo"),
|
||||
new IndexTableDTO.ColumnIndex("cod_anag"),
|
||||
new IndexTableDTO.ColumnIndex("cod_dtip")))
|
||||
.setUnique(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250312095802 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("ALTER TABLE wtb_jrept_setup ADD print_duplex BIT NOT NULL DEFAULT 0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ public class ReportTypeDTO {
|
||||
|
||||
private String codAnag;
|
||||
private String codMdep;
|
||||
private String codDtip;
|
||||
private List<PairsDTO> params;
|
||||
|
||||
|
||||
@@ -60,4 +61,13 @@ public class ReportTypeDTO {
|
||||
this.codMdep = codMdep;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodDtip() {
|
||||
return codDtip;
|
||||
}
|
||||
|
||||
public ReportTypeDTO setCodDtip(String codDtip) {
|
||||
this.codDtip = codDtip;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import javax.print.attribute.Attribute;
|
||||
import javax.print.attribute.AttributeSet;
|
||||
import javax.print.attribute.HashPrintRequestAttributeSet;
|
||||
import javax.print.attribute.PrintRequestAttributeSet;
|
||||
import javax.print.attribute.standard.Sides;
|
||||
import java.awt.print.Book;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.Paper;
|
||||
@@ -68,6 +69,11 @@ public class PrinterService {
|
||||
printFileType(myService, is, new HashPrintRequestAttributeSet(), mimeType, orientation);
|
||||
}
|
||||
|
||||
public void print(String printerName, InputStream is, HashPrintRequestAttributeSet attr, String mimeType, Orientation orientation) throws Exception {
|
||||
PrintService myService = configPrinter(printerName);
|
||||
printFileType(myService, is, attr, mimeType, orientation);
|
||||
}
|
||||
|
||||
public void print(String printerName, String fileName, String mimeType) throws Exception {
|
||||
PrintService myService = configPrinter(printerName);
|
||||
FileInputStream fis = new FileInputStream(fileName);
|
||||
@@ -111,7 +117,7 @@ public class PrinterService {
|
||||
job.setPageable(new PDFPageable(document, orientation));
|
||||
}
|
||||
|
||||
job.print();
|
||||
job.print(attrib);
|
||||
document.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -125,7 +131,6 @@ public class PrinterService {
|
||||
printJob.print(doc, attrib);
|
||||
}
|
||||
|
||||
|
||||
fis.close();
|
||||
}
|
||||
|
||||
@@ -238,17 +243,24 @@ public class PrinterService {
|
||||
return reportProcessor.getReportForReportType(reportTypeDTO);
|
||||
}
|
||||
|
||||
public void printReportType(ReportTypeDTO reportTypeDTO) throws Exception {
|
||||
public void printReport() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
public byte[] printReportType(ReportTypeDTO reportTypeDTO) throws Exception {
|
||||
HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
|
||||
WtbJreptSetup impostazioniStampa = reportProcessor.getReportForReportType(reportTypeDTO);
|
||||
if (impostazioniStampa == null) {
|
||||
logger.warn("Nessuna configurazione trovata per il tipo report " + reportTypeDTO.getReportType().toString());
|
||||
return;
|
||||
logger.warn("Nessuna configurazione trovata per il tipo report {}", reportTypeDTO.getReportType().toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
String printerName = impostazioniStampa.getPrinterName();
|
||||
Integer numberOfCopies = impostazioniStampa.getPrintQuantity();
|
||||
if (UtilityString.isNullOrEmpty(printerName)) {
|
||||
throw new Exception("Nessuna stampante configurata per il tipo report " + reportTypeDTO.getReportType().toString());
|
||||
}
|
||||
|
||||
byte[] bytes = reportProcessor.processReportType(reportTypeDTO);
|
||||
if (bytes != null) {
|
||||
Orientation orientation;
|
||||
@@ -267,15 +279,20 @@ public class PrinterService {
|
||||
orientation = Orientation.AUTO;
|
||||
break;
|
||||
}
|
||||
numberOfCopies = numberOfCopies == null ? 1 : numberOfCopies;
|
||||
for (int i = 0; i < numberOfCopies; i++) {
|
||||
print(printerName, new ByteArrayInputStream(bytes), "application/pdf", orientation);
|
||||
|
||||
if (impostazioniStampa.getPrintDuplex()){
|
||||
// Imposta la stampa fronte-retro (se supportata dalla stampante)
|
||||
attr.add(Sides.DUPLEX);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new EmptyReportException();
|
||||
numberOfCopies = numberOfCopies == null ? 1 : numberOfCopies;
|
||||
for (int i = 0; i < numberOfCopies; i++) {
|
||||
print(printerName, new ByteArrayInputStream(bytes), attr, "application/pdf", orientation);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
throw new EmptyReportException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -558,11 +558,13 @@ public class ReportProcessor {
|
||||
" tipo = :reportType " +
|
||||
" AND ((:codAnag is null and cod_anag is null) OR (:codAnag is not null and ISNULL(cod_anag,:codAnag) = :codAnag)) " +
|
||||
" AND ((:codMdep is null and cod_mdep is null) OR (:codMdep is not null and ISNULL(cod_mdep,:codMdep) = :codMdep)) " +
|
||||
" AND ((:codDtip is null and cod_dtip is null) OR (:codDtip is not null and ISNULL(cod_dtip,:codDtip) = :codDtip)) " +
|
||||
"order by cod_anag desc, cod_mdep desc";
|
||||
sql = sql
|
||||
.replace(":codAnag", UtilityDB.valueToString(reportTypeDTO.getCodAnag()))
|
||||
.replace(":reportType", UtilityDB.valueToString(reportTypeDTO.getReportType().getValue()))
|
||||
.replace(":codMdep", UtilityDB.valueToString(reportTypeDTO.getCodMdep()));
|
||||
.replace(":codDtip", UtilityDB.valueToString(reportTypeDTO.getCodDtip()))
|
||||
.replace(":codMdep", UtilityDB.valueToString(reportTypeDTO.getCodMdep()))
|
||||
.replace(":reportType", UtilityDB.valueToString(reportTypeDTO.getReportType().getValue()));
|
||||
List<WtbJreptSetup> wtbJreptSetup = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, WtbJreptSetup.class);
|
||||
return (wtbJreptSetup != null && !wtbJreptSetup.isEmpty()) ? wtbJreptSetup.get(0) : null;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ public class WtbJreptSetup extends EntityBase {
|
||||
@SqlField(value = "cod_anag", maxLength = 5)
|
||||
private String codAnag;
|
||||
|
||||
@SqlField(value = "cod_dtip", maxLength = 5)
|
||||
private String codDtip;
|
||||
|
||||
@SqlField(value = "orientation", nullable = false)
|
||||
private Orientation orientation;
|
||||
|
||||
@@ -50,6 +53,9 @@ public class WtbJreptSetup extends EntityBase {
|
||||
@SqlField(value = "print_quantity", nullable = false, defaultObjectValue = "1")
|
||||
private Integer printQuantity;
|
||||
|
||||
@SqlField(value = "print_duplex", nullable = false, defaultObjectValue = "false")
|
||||
private Boolean printDuplex;
|
||||
|
||||
public WtbJreptSetup() {
|
||||
super(logger);
|
||||
}
|
||||
@@ -117,6 +123,24 @@ public class WtbJreptSetup extends EntityBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodDtip() {
|
||||
return codDtip;
|
||||
}
|
||||
|
||||
public WtbJreptSetup setCodDtip(String codDtip) {
|
||||
this.codDtip = codDtip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getPrintDuplex() {
|
||||
return printDuplex;
|
||||
}
|
||||
|
||||
public WtbJreptSetup setPrintDuplex(Boolean printDuplex) {
|
||||
this.printDuplex = printDuplex;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
@@ -134,7 +158,8 @@ public class WtbJreptSetup extends EntityBase {
|
||||
WMS_SPEDIZIONE_PACKING_LIST_ORD((short) 4),
|
||||
STAMPA_LISTINI_VENDITA((short) 5),
|
||||
STAMPA_LISTINI_VENDITA_RANGE_PEDANE((short) 6),
|
||||
STAMPA_ORDINE_LAVORAZIONE((short) 7);
|
||||
STAMPA_ORDINE_LAVORAZIONE((short) 7),
|
||||
STAMPA_DOCUMENTI_VENDITA((short) 8);
|
||||
|
||||
private final short value;
|
||||
|
||||
|
||||
@@ -737,62 +737,27 @@ public class DocumentController {
|
||||
@PathVariable String fileName,
|
||||
@RequestParam(defaultValue = "false") boolean requestThumbnail) throws Exception {
|
||||
|
||||
StbActivityFile stbActivityFile = new StbActivityFile()
|
||||
.setId(id)
|
||||
.setFileName(fileName);
|
||||
stbActivityFile.setOperation(OperationType.SELECT_OBJECT);
|
||||
StbActivityFile stbActivityFile = new StbActivityFile()
|
||||
.setId(id)
|
||||
.setFileName(fileName);
|
||||
stbActivityFile.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
stbActivityFile = entityProcessor.processEntity(stbActivityFile, multiDBTransactionManager);
|
||||
stbActivityFile = entityProcessor.processEntity(stbActivityFile, multiDBTransactionManager);
|
||||
|
||||
if (stbActivityFile != null) {
|
||||
byte[] byteArr = requestThumbnail && stbActivityFile.getThumbnail() != null ? stbActivityFile.getThumbnail() : stbActivityFile.getContent();
|
||||
if (stbActivityFile != null) {
|
||||
byte[] byteArr = requestThumbnail && stbActivityFile.getThumbnail() != null ? stbActivityFile.getThumbnail() : stbActivityFile.getContent();
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(mimetypesFileTypeMap.getContentType(stbActivityFile.getFileName()).toString()))
|
||||
.contentLength(byteArr != null ? byteArr.length : 0)
|
||||
.header("Content-Disposition", "attachment; filename=\"" + stbActivityFile.getFileName() + "\"")
|
||||
.body(byteArr);
|
||||
}
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(mimetypesFileTypeMap.getContentType(stbActivityFile.getFileName()).toString()))
|
||||
.contentLength(byteArr != null ? byteArr.length : 0)
|
||||
.header("Content-Disposition", "attachment; filename=\"" + stbActivityFile.getFileName() + "\"")
|
||||
.body(byteArr);
|
||||
}
|
||||
|
||||
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
|
||||
// @RequestMapping(value = EmsRestConstants.PATH_DOWNLOAD_STB_ACTIVITY_FILE_ATTACHMENT + "/{id}/{fileName}", method = RequestMethod.GET)
|
||||
// public byte[] downloadStbActivityFileAttachmentPath(HttpServletRequest request, HttpServletResponse response,
|
||||
// @RequestParam(value = CommonConstants.PROFILE_DB, required = false) String config,
|
||||
// @PathVariable String id,
|
||||
// @PathVariable String fileName,
|
||||
// @RequestParam(defaultValue = "false") boolean requestThumbnail) {
|
||||
//
|
||||
// try {
|
||||
// StbActivityFile stbActivityFile = new StbActivityFile()
|
||||
// .setId(id)
|
||||
// .setFileName(fileName);
|
||||
// stbActivityFile.setOperation(OperationType.SELECT_OBJECT);
|
||||
//
|
||||
// stbActivityFile = entityProcessor.processEntity(stbActivityFile, multiDBTransactionManager);
|
||||
//
|
||||
// if (stbActivityFile != null) {
|
||||
// byte[] byteArr = requestThumbnail && stbActivityFile.getThumbnail() != null ? stbActivityFile.getThumbnail() : stbActivityFile.getContent();
|
||||
//
|
||||
// response.setContentType(mimetypesFileTypeMap.getContentType(stbActivityFile.getFileName()).toString());
|
||||
// response.setStatus(HttpServletResponse.SC_OK);
|
||||
// response.addHeader("Content-Disposition", "attachment; filename=\"" + stbActivityFile.getFileName() + "\"");
|
||||
// response.setContentLength(byteArr != null ? byteArr.length : 0);
|
||||
// return byteArr;
|
||||
// }
|
||||
//
|
||||
// response.sendError(404, "Allegato non trovato");
|
||||
// return null;
|
||||
// } catch (Exception e) {
|
||||
// logger.error(request.getRequestURI(), e);
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_REMOVE_FPX_INVIO_FILES, method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse removeFpxInvioFiles(HttpServletRequest request,
|
||||
@@ -802,7 +767,6 @@ public class DocumentController {
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/downloadPdfMinisterialeActive", method = RequestMethod.GET)
|
||||
public byte[] downloadPdfMinisterialeFromProgSDI(HttpServletRequest request, HttpServletResponse response,
|
||||
@RequestParam String progSdi,
|
||||
@@ -1043,21 +1007,27 @@ public class DocumentController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "popolaTabellaCosti", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse setTabellaCosti(HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestParam String codDtip,
|
||||
@RequestParam String codAnag,
|
||||
@RequestParam Date dataDoc,
|
||||
@RequestParam String serDoc,
|
||||
@RequestParam Integer numDoc,
|
||||
@RequestParam boolean deleteDoc) throws Exception {
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestParam String codDtip,
|
||||
@RequestParam String codAnag,
|
||||
@RequestParam Date dataDoc,
|
||||
@RequestParam String serDoc,
|
||||
@RequestParam Integer numDoc,
|
||||
@RequestParam boolean deleteDoc) throws Exception {
|
||||
|
||||
|
||||
documentService.popolaTabellaCosti(codAnag, codDtip, dataDoc, serDoc, numDoc, deleteDoc, true);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "printDocument", method = RequestMethod.POST)
|
||||
public ServiceRestResponse printDocument(HttpServletRequest request,
|
||||
@RequestBody PrintDocumentRequestDTO printDocumentRequest) throws Exception {
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(documentService.printDocument(printDocumentRequest));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package it.integry.ems.document.dto;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.report.dto.PairsDTO;
|
||||
import it.integry.ems_model.utility.UtilityDate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class PrintDocumentRequestDTO {
|
||||
|
||||
private String codDtip;
|
||||
private String codAnag;
|
||||
private Date dataDoc;
|
||||
private String serDoc;
|
||||
private Integer numDoc;
|
||||
|
||||
private boolean stampa;
|
||||
|
||||
public String getCodDtip() {
|
||||
return codDtip;
|
||||
}
|
||||
|
||||
public PrintDocumentRequestDTO setCodDtip(String codDtip) {
|
||||
this.codDtip = codDtip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodAnag() {
|
||||
return codAnag;
|
||||
}
|
||||
|
||||
public PrintDocumentRequestDTO setCodAnag(String codAnag) {
|
||||
this.codAnag = codAnag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataDoc() {
|
||||
return dataDoc;
|
||||
}
|
||||
|
||||
public PrintDocumentRequestDTO setDataDoc(Date dataDoc) {
|
||||
this.dataDoc = dataDoc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSerDoc() {
|
||||
return serDoc;
|
||||
}
|
||||
|
||||
public PrintDocumentRequestDTO setSerDoc(String serDoc) {
|
||||
this.serDoc = serDoc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getNumDoc() {
|
||||
return numDoc;
|
||||
}
|
||||
|
||||
public PrintDocumentRequestDTO setNumDoc(Integer numDoc) {
|
||||
this.numDoc = numDoc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isStampa() {
|
||||
return stampa;
|
||||
}
|
||||
|
||||
public PrintDocumentRequestDTO setStampa(boolean stampa) {
|
||||
this.stampa = stampa;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<PairsDTO> getReportParams(int copy) {
|
||||
List<PairsDTO> pairsDTOList = new ArrayList<>();
|
||||
|
||||
pairsDTOList.add(new PairsDTO("cod_anag", codAnag));
|
||||
pairsDTOList.add(new PairsDTO("ser_doc", serDoc));
|
||||
pairsDTOList.add(new PairsDTO("num_doc", numDoc));
|
||||
pairsDTOList.add(new PairsDTO("data_doc", UtilityDate.formatDate(dataDoc, "yyyy/MM/dd")));
|
||||
pairsDTOList.add(new PairsDTO("cod_dtip", codDtip));
|
||||
pairsDTOList.add(new PairsDTO("cod_dtip", codDtip));
|
||||
pairsDTOList.add(new PairsDTO("num_copia", copy));
|
||||
|
||||
return pairsDTOList;
|
||||
}
|
||||
}
|
||||
@@ -7,23 +7,30 @@ import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.document.dto.CreaBudgetDTO;
|
||||
import it.integry.ems.document.dto.DocDaScontrini;
|
||||
import it.integry.ems.document.dto.FilterDTO;
|
||||
import it.integry.ems.document.dto.PrintDocumentRequestDTO;
|
||||
import it.integry.ems.document.fatture.dto.FpxPDFTypeEnum;
|
||||
import it.integry.ems.document.fatture.xml.pa.FatturaElettronicaHeaderType;
|
||||
import it.integry.ems.document.fatture.xml.pa.FatturaElettronicaType;
|
||||
import it.integry.ems.document.fatture.xml.pa.FormatoTrasmissioneType;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.object_storage.minio.MinIOService;
|
||||
import it.integry.ems.report.dto.JasperDTO;
|
||||
import it.integry.ems.report.dto.ReportTypeDTO;
|
||||
import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.FileItem;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.rules.businessLogic.LoadColliService;
|
||||
import it.integry.ems.rules.businessLogic.dto.LoadColliDTO;
|
||||
import it.integry.ems.rules.completing.DocumentRules;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.service.PrinterService;
|
||||
import it.integry.ems.service.ReportProcessor;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.UserSession;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems.utility.UtilityFile;
|
||||
@@ -42,6 +49,7 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -67,6 +75,7 @@ import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static it.integry.ems_model.coollection.Coollection.eq;
|
||||
|
||||
@@ -92,6 +101,12 @@ public class DocumentService {
|
||||
private SettingsModel settingsModel;
|
||||
@Autowired
|
||||
private MailService mailService;
|
||||
@Autowired
|
||||
private PrinterService printerService;
|
||||
@Autowired
|
||||
private ReportProcessor reportProcessor;
|
||||
@Autowired
|
||||
private UserSession userSession;
|
||||
|
||||
public List<DtbDoct> createDocsFromColli(List<LoadColliDTO> colli) throws Exception {
|
||||
List<DtbDoct> documentiGenerati = new ArrayList<DtbDoct>();
|
||||
@@ -106,8 +121,6 @@ public class DocumentService {
|
||||
}
|
||||
|
||||
public DtbDoct createDocFromColli(LoadColliDTO loadColli) throws Exception {
|
||||
|
||||
|
||||
DtbDoct documentiGenerato = loadColliService.createDocFromColli(multiDBTransactionManager, loadColli);
|
||||
if (loadColli.isSaveDoc()) {
|
||||
entityProcessor.processEntity(documentiGenerato, multiDBTransactionManager);
|
||||
@@ -116,37 +129,6 @@ public class DocumentService {
|
||||
return documentiGenerato;
|
||||
}
|
||||
|
||||
|
||||
// public DtbDoct createDocFromColli(String xmlCollo) throws Exception {
|
||||
// Document doc = UtilityXML.convertStringToDocument(xmlCollo);
|
||||
// XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
// LoadColliDTO loadColliDTO = new LoadColliDTO();
|
||||
//
|
||||
// loadColliDTO.setCodDtip(xPath.compile("ROOT/COD_DTIP").evaluate(doc));
|
||||
// loadColliDTO.setDataDoc(UtilityString.parseDate(xPath.compile("ROOT/DATA_DOC").evaluate(doc)));
|
||||
// loadColliDTO.setSerDoc(xPath.compile("ROOT/SER_DOC").evaluate(doc));
|
||||
// loadColliDTO.setCalcPrz(xPath.compile("ROOT/CALC_PRZ").evaluate(doc));
|
||||
// loadColliDTO.setFlagLeggiDatiOrd("S".equalsIgnoreCase(xPath.compile("ROOT/LEGGI_DA_ORD").evaluate(doc)));
|
||||
// loadColliDTO.setFlagEvasoForzato(xPath.compile("ROOT/FLAG_EVASO_FORZATO").evaluate(doc));
|
||||
// loadColliDTO.setDataVers(UtilityString.parseDate(xPath.compile("ROOT/DATA_VERS").evaluate(doc)));
|
||||
//
|
||||
// NodeList nodelist = doc.getElementsByTagName("COLLO");
|
||||
// for (int i = 0; i < nodelist.getLength(); i++) {
|
||||
// MtbColt mtbColt = new MtbColt();
|
||||
// Node nodeCollo = nodelist.item(i);
|
||||
//
|
||||
// mtbColt.setGestione(xPath.compile("@GESTIONE").evaluate(nodeCollo));
|
||||
// mtbColt.setDataCollo(UtilityString.parseDate(xPath.compile("@DATA_COLLO").evaluate(nodeCollo)));
|
||||
// mtbColt.setSerCollo(xPath.compile("@SER_COLLO").evaluate(nodeCollo));
|
||||
// mtbColt.setNumCollo(new Integer(xPath.compile("@NUM_COLLO").evaluate(nodeCollo)));
|
||||
//
|
||||
// loadColliDTO.getColli().add(mtbColt);
|
||||
// }
|
||||
//
|
||||
// return loadColliService.createDocFromColli(multiDBTransactionManager, loadColliDTO);
|
||||
// }
|
||||
|
||||
|
||||
public List<ServiceRestResponse> regMovContFromDoc(String codAnag, String codDtip, Date dataDoc, String serDoc, Integer numDoc) throws Exception {
|
||||
List<ServiceRestResponse> respList = new ArrayList<ServiceRestResponse>();
|
||||
|
||||
@@ -1181,7 +1163,7 @@ public class DocumentService {
|
||||
|
||||
// Remove meta tags from html
|
||||
htmlInputStream = new ByteArrayInputStream(htmlOutputStream.toByteArray());
|
||||
org.jsoup.nodes.Document htmlDoc = Jsoup.parse(IOUtils.toString(htmlInputStream));
|
||||
Document htmlDoc = Jsoup.parse(IOUtils.toString(htmlInputStream));
|
||||
|
||||
htmlDoc.select("meta").remove();
|
||||
|
||||
@@ -1245,7 +1227,7 @@ public class DocumentService {
|
||||
|
||||
if (UtilityDebug.isIntegryServer()) {
|
||||
availableConnections = availableConnections.stream().filter(x ->
|
||||
x.getDbName().equalsIgnoreCase("STUDIOML"))
|
||||
x.getDbName().equalsIgnoreCase("STUDIOML"))
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -2094,4 +2076,155 @@ public class DocumentService {
|
||||
} else
|
||||
return mtbLisaCostoData;
|
||||
}
|
||||
|
||||
public byte[] printDocument(PrintDocumentRequestDTO printDocumentRequest) throws Exception {
|
||||
Connection conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
Date dataStampa = new Date();
|
||||
|
||||
String codDtip = printDocumentRequest.getCodDtip();
|
||||
String formattedDataDoc = UtilityDate.formatDate(printDocumentRequest.getDataDoc(), "yyyyMMdd");
|
||||
String formattedSerDoc = printDocumentRequest.getSerDoc().replace("/", "-").replace("\\", "-");
|
||||
formattedSerDoc = String.format("%-2s", formattedSerDoc).replace(' ', '-');
|
||||
|
||||
String fileName = String.format(
|
||||
"%s_%s_%s_%s_%05d.pdf",
|
||||
codDtip, formattedDataDoc, printDocumentRequest.getCodAnag(),
|
||||
formattedSerDoc, printDocumentRequest.getNumDoc()
|
||||
);
|
||||
|
||||
DtbTipi dtbTipi = new DtbTipi();
|
||||
dtbTipi.setCodDtip(codDtip)
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
entityProcessor.processEntity(dtbTipi, multiDBTransactionManager);
|
||||
|
||||
byte[] reportContent = new byte[0];
|
||||
|
||||
WtbJreptSetup.Tipo reportType;
|
||||
|
||||
switch (dtbTipi.getGestione()) {
|
||||
case "V":
|
||||
reportType = WtbJreptSetup.Tipo.STAMPA_DOCUMENTI_VENDITA;
|
||||
break;
|
||||
case "A":
|
||||
default:
|
||||
reportType = null;
|
||||
}
|
||||
|
||||
if (printDocumentRequest.isStampa()) {
|
||||
for (int i = 0; i < dtbTipi.getNumCopie(); i++) {
|
||||
byte[] printedReport = printerService.printReportType(
|
||||
new ReportTypeDTO()
|
||||
.setCodDtip(codDtip)
|
||||
.setReportType(reportType)
|
||||
.setParams(printDocumentRequest.getReportParams(i))
|
||||
);
|
||||
|
||||
if (i > 0)
|
||||
continue;
|
||||
|
||||
reportContent = printedReport;
|
||||
}
|
||||
} else {
|
||||
String sql = it.integry.ems_model.utility.Query.format(
|
||||
"SELECT wtb_jrept.report_name\n" +
|
||||
"FROM dtb_mod_stampa\n" +
|
||||
" INNER JOIN dtb_tipi ON dtb_mod_stampa.mod_stampa = dtb_tipi.mod_stamp\n" +
|
||||
" INNER JOIN wtb_jrept ON dtb_mod_stampa.report_id = wtb_jrept.id\n" +
|
||||
"WHERE report_id IS NOT NULL\n" +
|
||||
" AND dtb_tipi.cod_dtip = %s",
|
||||
codDtip
|
||||
);
|
||||
|
||||
String reportName = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
|
||||
if (reportName == null || reportName.isEmpty())
|
||||
throw new Exception("Nessun report trovato per il tipo documento " + codDtip);
|
||||
|
||||
JasperDTO jasperDTO = new JasperDTO()
|
||||
.setReportId(reportProcessor.getReportID(reportName))
|
||||
.setParams(printDocumentRequest.getReportParams(0));
|
||||
|
||||
reportContent = reportProcessor.processReport(jasperDTO);
|
||||
}
|
||||
|
||||
FileItem fileItem = new FileItem(fileName, reportContent);
|
||||
|
||||
String sql = it.integry.ems_model.utility.Query.format(
|
||||
"SELECT e_mail\n" +
|
||||
"FROM vtb_clie_pers_rif\n" +
|
||||
" INNER JOIN stb_tipi_indirizzi ON stb_tipi_indirizzi.tipo_indirizzo = vtb_clie_pers_rif.tipo_indirizzo\n" +
|
||||
"WHERE tipo_documento = %s\n" +
|
||||
" AND cod_anag = %s",
|
||||
codDtip, printDocumentRequest.getCodAnag()
|
||||
);
|
||||
String elencoEmail = String.join(",", UtilityDB.executeSimpleQueryOnlyFirstColumn(conn, sql));
|
||||
|
||||
if (!elencoEmail.isEmpty()) {
|
||||
String fullName = userSession.getCurrentUser() == null ? "" : userSession.getFullname();
|
||||
sql = "SELECT * FROM stb_gest_setup WHERE gest_name = 'w_einviomail_docupdf_dlg' AND key_section = 'CLIENTI'";
|
||||
List<StbGestSetup> stbGestSetupList = UtilityDB.executeSimpleQueryDTO(conn, sql, StbGestSetup.class);
|
||||
|
||||
String subject = "", msgText = "";
|
||||
if (stbGestSetupList != null && !stbGestSetupList.isEmpty()) {
|
||||
sql = it.integry.ems_model.utility.Query.format(
|
||||
"SELECT vtb_clie_pers_rif.persona_rif AS 'pers_rif',\n" +
|
||||
" dtb_doct.cod_anag AS 'cod_anag',\n" +
|
||||
" gtb_anag.rag_soc AS 'rag_soc',\n" +
|
||||
" cod_dtip AS 'cod_dtip',\n" +
|
||||
" %s AS 'des_modDoc',\n" +
|
||||
" FORMAT(data_doc, 'dd/MM/yyyy') AS 'data_doc',\n" +
|
||||
" ser_doc AS 'ser_doc',\n" +
|
||||
" CAST(num_doc AS VARCHAR) AS 'num_doc',\n" +
|
||||
" FORMAT(tot_imponib + dtb_doct.tot_iva, 'N', 'it-IT') AS 'tot_doc',\n" +
|
||||
" citta AS 'citta',\n" +
|
||||
" %s AS 'nome_utente'\n" +
|
||||
"FROM dtb_doct\n" +
|
||||
" INNER JOIN vtb_clie_pers_rif ON vtb_clie_pers_rif.cod_anag = dtb_doct.cod_anag\n" +
|
||||
" INNER JOIN gtb_anag ON dtb_doct.cod_anag = gtb_anag.cod_anag\n" +
|
||||
"WHERE num_doc = %s\n" +
|
||||
" AND ser_doc = %s\n" +
|
||||
" AND data_doc = %s\n" +
|
||||
" AND cod_dtip = %s\n" +
|
||||
" AND dtb_doct.cod_anag = %s",
|
||||
dtbTipi.getDescrizione(), fullName, printDocumentRequest.getNumDoc(),
|
||||
printDocumentRequest.getSerDoc(), printDocumentRequest.getDataDoc(), codDtip,
|
||||
printDocumentRequest.getCodAnag()
|
||||
);
|
||||
HashMap<String, Object> resultQuery = UtilityDB.executeSimpleQueryOnlyFirstRow(conn, sql);
|
||||
|
||||
for (StbGestSetup stbGestSetup : stbGestSetupList) {
|
||||
String valueText = stbGestSetup.getValue();
|
||||
valueText = valueText.replace("%%_", "");
|
||||
|
||||
for (String key : resultQuery.keySet()) {
|
||||
String value = resultQuery.get(key) == null ? "" : (String) resultQuery.get(key);
|
||||
valueText = valueText.replace(key, value);
|
||||
}
|
||||
|
||||
subject = stbGestSetup.getSection().contains("OGGETTO") ? valueText : subject;
|
||||
msgText = stbGestSetup.getSection().contains("TESTO") ? valueText : msgText;
|
||||
}
|
||||
}
|
||||
|
||||
mailService.sendMail(null, null, elencoEmail, null, null, subject, msgText, false, fileItem);
|
||||
}
|
||||
|
||||
if (dtbTipi.getFlagArchiviaPdf()) {
|
||||
DtbDocPdf dtbDocPdf = new DtbDocPdf();
|
||||
dtbDocPdf.setDataDoc(printDocumentRequest.getDataDoc());
|
||||
dtbDocPdf.setSerDoc(printDocumentRequest.getSerDoc());
|
||||
dtbDocPdf.setNumDoc(printDocumentRequest.getNumDoc());
|
||||
dtbDocPdf.setCodAnag(printDocumentRequest.getCodAnag());
|
||||
dtbDocPdf.setCodDtip(codDtip);
|
||||
dtbDocPdf.setFilename(fileName);
|
||||
dtbDocPdf.setFilecontentByteArr(reportContent);
|
||||
dtbDocPdf.setDataStampa(dataStampa);
|
||||
dtbDocPdf.setFilesize(new BigDecimal(reportContent.length));
|
||||
dtbDocPdf.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
entityProcessor.processEntity(dtbDocPdf, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
return reportContent;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user