Esportazione documenti DAS Accise
This commit is contained in:
@@ -10,6 +10,7 @@ import it.integry.ems.document.fatture.services.InvoicePAService;
|
||||
import it.integry.ems.export.base.BaseEntityExporter;
|
||||
import it.integry.ems.export.base.EntityExportResponse;
|
||||
import it.integry.ems.export.base.IEntityExporter;
|
||||
import it.integry.ems.order.export.service.OrdiniVenditaExportServices;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.*;
|
||||
@@ -106,6 +107,10 @@ public class DocumentiExporter extends BaseEntityExporter implements IEntityExpo
|
||||
DocumentiChepExportService chepExportServices = context.getBean(DocumentiChepExportService.class);
|
||||
entityExportResponse = chepExportServices.export(type, format, whereCond);
|
||||
break;
|
||||
case DAS:
|
||||
DocumentDasExport exportDASAccise = ContextLoader.getCurrentWebApplicationContext().getBean(DocumentDasExport.class);
|
||||
entityExportResponse = exportDASAccise.exportDASAccise(username,type, format, whereCond);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +218,7 @@ public class DocumentiExporter extends BaseEntityExporter implements IEntityExpo
|
||||
COOP("COOP"),
|
||||
SIAN("SIAN"),
|
||||
BRT("BRT"),
|
||||
DAS("DAS"),
|
||||
CHEP("CHEP");
|
||||
|
||||
private String text;
|
||||
|
||||
@@ -1,2 +1,126 @@
|
||||
package it.integry.ems.document.export.service;public class DocumentDasExport {
|
||||
package it.integry.ems.document.export.service;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.export.base.EntityExportResponse;
|
||||
import it.integry.ems.export.base.ExportFromQuery;
|
||||
import it.integry.ems.response.FileItem;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.HttpRestWrapper;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.entity.WtbUsersInfo;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityDate;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
@Scope(value = "request")
|
||||
public class DocumentDasExport {
|
||||
@Autowired
|
||||
MultiDBTransactionManager multiDBTransactionManager;
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
@Autowired
|
||||
ExportFromQuery exportFromQuery;
|
||||
|
||||
public EntityExportResponse exportDASAccise(String username, String type, String format, String whereCond) throws Exception {
|
||||
EntityExportResponse response = exportFromQuery.export(username, type, format, whereCond);
|
||||
FileItem xlsFile = ((ArrayList<FileItem>) response.getResponse()).stream().findFirst().orElse(null);
|
||||
|
||||
WtbUsersInfo wtbUsersInfo = new WtbUsersInfo().setUserName(username).setExportType(type).setFormatFile(format);
|
||||
wtbUsersInfo.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
entityProcessor.processEntity(wtbUsersInfo, multiDBTransactionManager);
|
||||
String profileDb = multiDBTransactionManager.getPrimaryDatasource().getProfile().toLowerCase();
|
||||
|
||||
String queryCustom = wtbUsersInfo.getQueryCustom();
|
||||
queryCustom = UtilityDB.addwhereCond(queryCustom, whereCond, true);
|
||||
List<HashMap<String, Object>> result = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), queryCustom);
|
||||
List<String> fullJsonArray = Stream.of(result).map(x -> x.get("cod_mart").toString()).distinct().toList();
|
||||
|
||||
String flagFileCompress = wtbUsersInfo.getFlagFileCompress();
|
||||
|
||||
EntityExportResponse<List<FileItem>> entityExportResponse = new EntityExportResponse<>();
|
||||
entityExportResponse.setResponse(new ArrayList<>());
|
||||
|
||||
String url = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "URL", "IMMAGINI_WEB");
|
||||
String regex = "[\\/]*" + profileDb + "[\\/]*\\b[^.]";
|
||||
url = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE).matcher(url).replaceAll("/");
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("profileDb", profileDb);
|
||||
params.put("XDEBUG_SESSION", "PHPSTORM");
|
||||
|
||||
int maxElementsPerPiece = 20;
|
||||
List<String> responses = new ArrayList<>();
|
||||
List<List<String>> jsonPieces;
|
||||
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
jsonPieces = Stream.of(fullJsonArray).chunkBy(x -> counter.getAndIncrement() / maxElementsPerPiece).toList();
|
||||
|
||||
for (List<String> jsonPiece : jsonPieces) {
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("articoli", jsonPiece);
|
||||
|
||||
String jsonPieceString = jsonObject.toString();
|
||||
|
||||
StringBuilder responseBodyString = new StringBuilder();
|
||||
HttpRestWrapper.callGeneric(
|
||||
url,
|
||||
null,
|
||||
null,
|
||||
jsonPieceString,
|
||||
ContentType.APPLICATION_JSON,
|
||||
responseBodyString,
|
||||
params
|
||||
);
|
||||
|
||||
if(!UtilityString.isNullOrEmpty(responseBodyString.toString()))
|
||||
responses.add(responseBodyString.toString());
|
||||
}
|
||||
|
||||
if (!responses.isEmpty()) {
|
||||
|
||||
String fileName;
|
||||
byte[] fileContent;
|
||||
|
||||
/* for (String responseBodyString : responses){
|
||||
JSONObject jsonObject = new JSONObject(responseBodyString);
|
||||
|
||||
for(String key : jsonObject.keySet()){
|
||||
|
||||
fileName = jsonObject.getString(key);
|
||||
|
||||
fileContent = downloadFile(new URL(url + profileDb + "/" + fileName));
|
||||
|
||||
FileItem fileItem = new FileItem(fileName, fileContent, FilenameUtils.getExtension(fileName));
|
||||
entityExportResponse.getResponse().add(fileItem);
|
||||
}
|
||||
}*/
|
||||
|
||||
entityExportResponse.getResponse().add(xlsFile);
|
||||
}
|
||||
|
||||
return entityExportResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -86,13 +86,18 @@ public class ProductController {
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_CONFIRM_TEMP_LISTINO, method = RequestMethod.GET)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse confirmTempListino(
|
||||
List<ServiceRestResponse> confirmTempListino(
|
||||
HttpServletRequest request,
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration) throws Exception {
|
||||
|
||||
ServiceRestResponse response = ServiceRestResponse.createPositiveResponse();
|
||||
response.setEntityList(importAnagListiniService.confirmTempListino());
|
||||
return response;
|
||||
List<ServiceRestResponse> respList = new ArrayList<ServiceRestResponse>();
|
||||
try {
|
||||
ServiceRestResponse response = ServiceRestResponse.createPositiveResponse();
|
||||
response.setEntityList(importAnagListiniService.confirmTempListino());
|
||||
} catch (Exception e) {
|
||||
logger.error(request.getRequestURI(), e);
|
||||
respList.add(new ServiceRestResponse(EsitoType.KO, configuration, e));
|
||||
}
|
||||
return respList;
|
||||
}
|
||||
|
||||
@RequestMapping(value = EmsRestConstants.PATH_IMPORT_ANAG_LISTINI, method = RequestMethod.POST)
|
||||
|
||||
Reference in New Issue
Block a user