Modifiche per popolamento tabella con giacenza partire dall'inventario
This commit is contained in:
@@ -427,6 +427,11 @@
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
<component name="ExportableFileTemplateSettings">
|
||||
<default_templates>
|
||||
<template name="IntegryMigrationClass.java" file-name="Migration_${YEAR}${MONTH}${DAY}${HOUR}${MINUTE}${SECOND}" reformat="true" live-template-enabled="false" />
|
||||
</default_templates>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$/ems-engine" />
|
||||
|
||||
@@ -957,14 +957,14 @@ public abstract class EntityBase implements Serializable, Cloneable, EntityInter
|
||||
}
|
||||
execStoredProcedure();
|
||||
managePriorityPost();
|
||||
if (this.getClass().getAnnotation(Master.class) != null) {
|
||||
String publicationId = AsyncManager.getPublicationIdIfExists(connection, this);
|
||||
|
||||
if (publicationId != null) {
|
||||
if (transactionGroupId == null) transactionGroupId = AsyncManager.getNextTransactionGroupId(connection);
|
||||
AsyncManager.saveNewTransaction(connection, this, transactionGroupId);
|
||||
}
|
||||
}
|
||||
// if (this.getClass().getAnnotation(Master.class) != null) {
|
||||
// String publicationId = AsyncManager.getPublicationIdIfExists(connection, this);
|
||||
//
|
||||
// if (publicationId != null) {
|
||||
// if (transactionGroupId == null) transactionGroupId = AsyncManager.getNextTransactionGroupId(connection);
|
||||
// AsyncManager.saveNewTransaction(connection, this, transactionGroupId);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void insert() throws Exception {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package it.integry.ems_model.entity;
|
||||
|
||||
import it.integry.ems_model.annotation.EntityChild;
|
||||
import it.integry.ems_model.annotation.Master;
|
||||
import it.integry.ems_model.annotation.PK;
|
||||
import it.integry.ems_model.annotation.SqlField;
|
||||
import it.integry.ems_model.annotation.Table;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@Table(CarelliGiacenzaProg.ENTITY)
|
||||
@JsonTypeName(CarelliGiacenzaProg.ENTITY)
|
||||
public class CarelliGiacenzaProg extends EntityBase {
|
||||
public CarelliGiacenzaProg() {
|
||||
super();
|
||||
}
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final String ENTITY = "carelli_giacenza_prog";
|
||||
@PK
|
||||
@SqlField(value = "cod_mart")
|
||||
private String codMart;
|
||||
@PK
|
||||
@SqlField(value = "cod_mdep")
|
||||
private String codMdep;
|
||||
|
||||
@SqlField(value = "data_ins")
|
||||
private Date dataIns;
|
||||
|
||||
@SqlField(value = "data_reg")
|
||||
private Date dataReg;
|
||||
|
||||
@SqlField(value = "qta_car", defaultObjectValue = "0")
|
||||
private BigDecimal qtaCar;
|
||||
|
||||
@SqlField(value = "qta_scar", defaultObjectValue = "0")
|
||||
private BigDecimal qtaScar;
|
||||
|
||||
@SqlField(value = "tipo_car")
|
||||
private String tipoCar;
|
||||
@SqlField(value = "id_inventario")
|
||||
private Integer idInventario;
|
||||
|
||||
@Override
|
||||
public void checkPreSave() throws Exception {}
|
||||
|
||||
|
||||
public String getCodMart() {
|
||||
return codMart;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setCodMart(String codMart) {
|
||||
this.codMart = codMart;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodMdep() {
|
||||
return codMdep;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setCodMdep(String codMdep) {
|
||||
this.codMdep = codMdep;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataIns() {
|
||||
return dataIns;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setDataIns(Date dataIns) {
|
||||
this.dataIns = dataIns;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataReg() {
|
||||
return dataReg;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setDataReg(Date dataReg) {
|
||||
this.dataReg = dataReg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getQtaCar() {
|
||||
return qtaCar;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setQtaCar(BigDecimal qtaCar) {
|
||||
this.qtaCar = qtaCar;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getQtaScar() {
|
||||
return qtaScar;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setQtaScar(BigDecimal qtaScar) {
|
||||
this.qtaScar = qtaScar;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTipoCar() {
|
||||
return tipoCar;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setTipoCar(String tipoCar) {
|
||||
this.tipoCar = tipoCar;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getIdInventario() {
|
||||
return idInventario;
|
||||
}
|
||||
|
||||
public CarelliGiacenzaProg setIdInventario(Integer idInventario) {
|
||||
this.idInventario = idInventario;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.MtbInvenr;
|
||||
import it.integry.ems_model.entity.MtbInvent;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
@@ -36,8 +37,13 @@ public class InventarioImporterService {
|
||||
|
||||
@Autowired
|
||||
EntityProcessor entityProcessor;
|
||||
@Autowired
|
||||
SetupGest setupGest;
|
||||
|
||||
public List<EntityBase> importInventarioRgis(String type, String format, ImportRequestDTO requestDTO) throws Exception {
|
||||
|
||||
HashMap<String, String> setup = setupGest.getImportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
|
||||
|
||||
String fileName = requestDTO.getFileName();
|
||||
fileName = fileName.substring(0, fileName.indexOf("."));
|
||||
String[] datiFile = fileName.split("_");
|
||||
@@ -89,13 +95,15 @@ public class InventarioImporterService {
|
||||
String.format(
|
||||
"Impossibile salvare l'inventario del deposito %s, i seguenti articoli non sono presenti in anagrafica: %s%s",
|
||||
codMdep, CommonConstants.A_CAPO,
|
||||
StringUtils.join(elencoArticoli, "/n")));
|
||||
StringUtils.join(elencoArticoli, " , ")));
|
||||
|
||||
|
||||
MtbInvent mtbInvent =
|
||||
new MtbInvent()
|
||||
.setDataInventario(dataInv)
|
||||
.setCodMdep(codMdep);
|
||||
.setCodMdep(codMdep)
|
||||
.setFlagOperazione(setup.get("FLAG_OPERAZIONE"))
|
||||
.setFiltro("FILTRO");
|
||||
mtbInvent.setOperation(OperationType.INSERT);
|
||||
|
||||
List<MtbInvenr> listMtbInvenr = Stream.of(inventario)
|
||||
|
||||
@@ -964,7 +964,8 @@ public class InventarioService {
|
||||
query = query + "UNION " + queryFiltro;
|
||||
}
|
||||
return query;
|
||||
}public List<ServiceRestResponse> registraInventario(DocDaInventarioDTO datiDoc) throws Exception {
|
||||
}
|
||||
public List<ServiceRestResponse> registraInventario(DocDaInventarioDTO datiDoc) throws Exception {
|
||||
List<ServiceRestResponse> respList = new ArrayList<ServiceRestResponse>();
|
||||
String query, gestione = "", codMdep = "";
|
||||
Integer idInventario = new Integer("0");
|
||||
|
||||
@@ -65,6 +65,8 @@ public class PvmController {
|
||||
private RequestDataDTO requestDataDTO;
|
||||
@Autowired
|
||||
private SmartEnterpriseService smartEnterpriseService;
|
||||
@Autowired
|
||||
private GiacenzaService giacenzaService;
|
||||
|
||||
|
||||
@Autowired
|
||||
@@ -737,4 +739,16 @@ public class PvmController {
|
||||
return ServiceRestResponse.createPositiveResponse(pvmService.retrieveInventarioRil(inventoryId, codMdep));
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "popolaGiancezaDaInventario", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse popolaGiancezaDaInventario(@RequestParam(CommonConstants.PROFILE_DB) String profileDB) throws Exception {
|
||||
|
||||
try {
|
||||
giacenzaService.popolaGiancezaDaInventario();
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
} catch (Exception e ){
|
||||
return ServiceRestResponse.createNegativeResponse(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
package it.integry.ems.retail.pvmRetail.service;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.dto.UserDTO;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.db.ResultSetMapper;
|
||||
import it.integry.ems_model.entity.CarelliGiacenzaProg;
|
||||
import it.integry.ems_model.entity.MtbInvenr;
|
||||
import it.integry.ems_model.entity.StbUser;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
public class GiacenzaService {
|
||||
@Autowired
|
||||
MultiDBTransactionManager multiDBTransactionManager;
|
||||
@Autowired
|
||||
SetupGest setupGest;
|
||||
@Autowired
|
||||
PvmService pvmService;
|
||||
@Autowired
|
||||
EntityProcessor entityProcessor;
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
public void popolaGiancezaDaInventario() throws Exception {
|
||||
Date startDate = new Date();
|
||||
|
||||
final String queryArt =
|
||||
"SELECT mtb_aart.cod_mart AS cod_mart,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_aart.articolo_composto = 'S' AND mtb_comp.cod_comp IS NOT NULL THEN mtb_comp.cod_comp\n" +
|
||||
" ELSE mtb_aart.cod_mart END AS cod_mart_mov,\n" +
|
||||
" ISNULL(mtb_comp.qta_std, 1) AS qta_std\n" +
|
||||
"FROM mtb_aart\n" +
|
||||
" LEFT OUTER JOIN mtb_comp ON mtb_aart.cod_mart = mtb_comp.cod_mart";
|
||||
|
||||
String sql =
|
||||
"SELECT cod_mdep\n" +
|
||||
"FROM stb_gest_setup_depo\n" +
|
||||
"WHERE gest_name = 'DATI_AZIENDA'\n" +
|
||||
" AND section = 'GIACENZA_DA_INV'\n" +
|
||||
" AND key_section = 'ATTIVO'\n" +
|
||||
" AND value = 'S'";
|
||||
|
||||
List<String> depositi = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
depositi = new ArrayList<>();
|
||||
depositi.add("10");
|
||||
|
||||
for (String codMdep: depositi) {
|
||||
popolamentoDatiDeposito(codMdep, queryArt, startDate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void popolamentoDatiDeposito(String codMdep, String queryArt, Date startDate) throws Exception {
|
||||
String sql;
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT cod_mart\n" +
|
||||
"FROM carelli_giacenza_prog\n" +
|
||||
"WHERE carelli_giacenza_prog.cod_mdep = %s", codMdep);
|
||||
|
||||
List<String> articoliSalvati = UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
popolaQtaCarInventario(codMdep, queryArt, articoliSalvati);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - popolamento qta_car da inventario deposito %s: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
popolaQtaMovimenti(codMdep, queryArt, articoliSalvati);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - popolamento qta da movimenti deposito %s: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
nuoviInserimenti(codMdep, queryArt);
|
||||
logger.debug(String.format(GiacenzaService.class.getSimpleName() + " - popolamento articoli da griglia deposito %s: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs", codMdep));
|
||||
}
|
||||
|
||||
private void nuoviInserimenti(String codMdep, String queryArt) throws Exception {
|
||||
String sql = Query.format(
|
||||
"SELECT g.cod_mdep, a.cod_mart_mov, GETDATE() as data_ins, Cast(getDate() as date) as data_reg\n" +
|
||||
"FROM dbo.getgrigliaacquisto(NULL, %s, NULL, NULL, NULL) g\n" +
|
||||
" INNER JOIN (" + queryArt + ") a ON g.cod_mart = a.cod_mart\n" +
|
||||
" INNER JOIN mtb_aart ON a.cod_mart_mov = mtb_aart.cod_mart\n" +
|
||||
"WHERE g.tipo_variazione <> 'D'\n" +
|
||||
" AND mtb_aart.data_ult_car IS NULL\n" +
|
||||
" AND NOT EXISTS\n" +
|
||||
" (SELECT cod_mart\n" +
|
||||
" FROM carelli_giacenza_prog\n" +
|
||||
" WHERE carelli_giacenza_prog.cod_mart = a.cod_mart\n" +
|
||||
" AND carelli_giacenza_prog.cod_mdep = g.cod_mdep)",
|
||||
codMdep);
|
||||
|
||||
List<CarelliGiacenzaProg> carelliGiacenzaProgs = new ResultSetMapper().mapQuerySetToList(multiDBTransactionManager.getPrimaryConnection(), sql, CarelliGiacenzaProg.class);
|
||||
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList(carelliGiacenzaProgs, false, true, false);
|
||||
|
||||
UtilityEntity.throwEntitiesException(entityRet);
|
||||
}
|
||||
|
||||
private void popolaQtaMovimenti(String codMdep, String queryArt, List<String> articoliSalvati) throws Exception {
|
||||
String sql;
|
||||
sql =
|
||||
(
|
||||
"WITH art AS (" + queryArt + "),\n" +
|
||||
" movimenti AS (SELECT mtb_movi.cod_mdep,\n" +
|
||||
" mtb_movi.cod_mart,\n" +
|
||||
" mtb_movi.data_reg,\n" +
|
||||
" mtb_movi.qta_car AS qta_car,\n" +
|
||||
" mtb_movi.qta_scar AS qta_scar,\n" +
|
||||
" dtb_doct.data_ins,\n" +
|
||||
" 'D' as tipo_car\n" +
|
||||
" FROM mtb_movi\n" +
|
||||
" INNER JOIN dtb_doct ON dtb_doct.cod_anag = mtb_movi.cod_anag AND\n" +
|
||||
" dtb_doct.cod_dtip = mtb_movi.cod_dtip AND\n" +
|
||||
" dtb_doct.data_doc = mtb_movi.data_doc AND\n" +
|
||||
" dtb_doct.ser_doc = mtb_movi.ser_doc AND\n" +
|
||||
" dtb_doct.num_doc = mtb_movi.num_doc\n" +
|
||||
" WHERE mtb_movi.cod_mdep = '[COD_MDEP]'\n" +
|
||||
" UNION ALL\n" +
|
||||
" SELECT wdtb_doct.cod_mdep,\n" +
|
||||
" wdtb_docr.cod_mart,\n" +
|
||||
" wdtb_doct.data_reg,\n" +
|
||||
" wdtb_docr.qta_doc * wdtb_docr.rap_conv,\n" +
|
||||
" 0,\n" +
|
||||
" wdtb_doct.data_ins,\n" +
|
||||
" 'W' as tipo_car\n" +
|
||||
" FROM wdtb_doct\n" +
|
||||
" INNER JOIN wdtb_docr ON wdtb_doct.cod_anag = wdtb_docr.cod_anag AND\n" +
|
||||
" wdtb_doct.cod_dtip = wdtb_docr.cod_dtip AND\n" +
|
||||
" wdtb_doct.data_doc = wdtb_docr.data_doc AND\n" +
|
||||
" wdtb_doct.ser_doc = wdtb_docr.ser_doc AND\n" +
|
||||
" wdtb_doct.num_doc = wdtb_docr.num_doc\n" +
|
||||
" WHERE wdtb_doct.flag_elaborato <> 'S'\n" +
|
||||
" AND wdtb_doct.cod_mdep = '[COD_MDEP]'\n" +
|
||||
" UNION ALL\n" +
|
||||
" SELECT ntb_doct.cod_mdep,\n" +
|
||||
" ntb_docr.cod_mart,\n" +
|
||||
" NULL,\n" +
|
||||
" 0,\n" +
|
||||
" ntb_docr.qta_doc * ntb_docr.qta_cnf,\n" +
|
||||
" ntb_doct.data_import,\n" +
|
||||
" null as tipo_car\n" +
|
||||
" FROM ntb_doct\n" +
|
||||
" INNER JOIN ntb_docr ON ntb_doct.cod_mdep = ntb_docr.cod_mdep AND\n" +
|
||||
" ntb_doct.cod_cassa = ntb_docr.cod_cassa AND\n" +
|
||||
" ntb_doct.data_doc = ntb_docr.data_doc\n" +
|
||||
" LEFT OUTER JOIN dtb_tipi ON ntb_doct.cod_dtip_val = dtb_tipi.cod_dtip\n" +
|
||||
" WHERE ntb_doct.cod_mdep = '[COD_MDEP]'\n" +
|
||||
" AND ntb_doct.causale = 'V'\n" +
|
||||
" AND (ntb_doct.data_doc_val IS NOT NULL OR dtb_tipi.segno_qta_scar <> 0))\n" +
|
||||
"\n" +
|
||||
"SELECT movimenti.cod_mdep,\n" +
|
||||
" movimenti.cod_mart,\n" +
|
||||
" SUM(movimenti.qta_car) + IsNull(giac.qta_car, 0) as qta_car,\n" +
|
||||
" SUM(movimenti.qta_scar) + IsNull(giac.qta_scar, 0) as qta_scar,\n" +
|
||||
" getdate() as data_ins,\n" +
|
||||
" max(movimenti.tipo_car) as tipo_car\n" +
|
||||
"FROM movimenti\n" +
|
||||
" INNER JOIN art ON movimenti.cod_mart = art.cod_mart\n" +
|
||||
" LEFT OUTER JOIN carelli_giacenza_prog giac ON giac.cod_mdep = movimenti.cod_mdep\n" +
|
||||
" AND giac.cod_mart = movimenti.cod_mart\n" +
|
||||
"WHERE movimenti.data_reg >= ISNULL(giac.data_reg, CAST(GETDATE() AS DATE))\n" +
|
||||
" AND (giac.data_ins IS NULL OR (movimenti.data_ins >= giac.data_ins))\n" +
|
||||
"GROUP BY movimenti.cod_mdep,\n " +
|
||||
" movimenti.cod_mart,\n"+
|
||||
" giac.qta_car,\n"+
|
||||
" giac.qta_scar\n").replace("[COD_MDEP]", codMdep);
|
||||
|
||||
List<CarelliGiacenzaProg> carelliGiacenzaProgs = new ResultSetMapper().mapQuerySetToList(multiDBTransactionManager.getPrimaryConnection(), sql, CarelliGiacenzaProg.class);
|
||||
|
||||
Stream.of(carelliGiacenzaProgs)
|
||||
.forEach(x-> {
|
||||
if (articoliSalvati.contains(x.getCodMart()))
|
||||
x.setOperation(OperationType.UPDATE);
|
||||
else {
|
||||
x.setOperation(OperationType.INSERT);
|
||||
articoliSalvati.add(x.getCodMart());
|
||||
}
|
||||
});
|
||||
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList(carelliGiacenzaProgs, false, true, false);
|
||||
|
||||
UtilityEntity.throwEntitiesException(entityRet);
|
||||
}
|
||||
|
||||
private void popolaQtaCarInventario(String codMdep, String queryArt, List<String> articoliSalvati) throws Exception {
|
||||
String sql =
|
||||
Query.format("SELECT min(data_reg) from carelli_giacenza_prog WHERE cod_mdep = %s and id_inventario is not null", codMdep);
|
||||
|
||||
Date dataIniz = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (dataIniz == null) {
|
||||
String dataParm = setupGest.getSetupDepo(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "GIACENZA_DA_INV", "DATA_INIZ", codMdep);
|
||||
if (!UtilityString.isNullOrEmpty(dataParm))
|
||||
dataIniz = UtilityString.parseDate(dataParm);
|
||||
else
|
||||
//throw new Exception(String.format("Data inizio popolamento non valorizzata per il depostio %s", codMdep));
|
||||
dataIniz = UtilityDate.dateFromPart(2023, 10,17);
|
||||
}
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT id_inventario,\n" +
|
||||
"DateAdd(dd, (case when flag_operazione = 1 then 1 else 0 end), mtb_invent.data_inventario) as data_inventario,\n" +
|
||||
"flag_stato,\n " +
|
||||
"filtro\n" +
|
||||
"FROM mtb_invent\n " +
|
||||
"WHERE cod_mdep = %s AND \n" +
|
||||
"data_inventario >= %s AND\n " +
|
||||
"flag_stato <> 2 AND\n "+
|
||||
"NOT EXISTS(SELECT * FROM carelli_giacenza_prog WHERE mtb_invent.id_inventario = carelli_giacenza_prog.id_inventario AND mtb_invent.cod_mdep = carelli_giacenza_prog.cod_mdep )",
|
||||
codMdep, dataIniz);
|
||||
|
||||
List<HashMap<String, Object>> inventari = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
for (HashMap<String, Object> inv : inventari) {
|
||||
Integer idInventario = UtilityHashMap.getValueIfExists(inv, "id_inventario");
|
||||
Date dataInv = UtilityHashMap.getValueIfExists(inv, "data_inventario");
|
||||
String flagStato = UtilityHashMap.getValueIfExists(inv, "flag_stato");
|
||||
String filtroInv = UtilityHashMap.getValueIfExists(inv, "filtro");
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT art.cod_mart_mov as cod_mart,\n" +
|
||||
"sum(mtb_invenr.qta_inv * art.qta_std) as qta_inv\n" +
|
||||
"FROM mtb_invenr " +
|
||||
" INNER JOIN (" + queryArt + ") art on mtb_invenr.cod_mart = art.cod_mart\n" +
|
||||
"WHERE mtb_invenr.id_inventario = %s AND\n" +
|
||||
"mtb_invenr.cod_mdep = %s\n " +
|
||||
"GROUP BY art.cod_mart_mov ",
|
||||
idInventario, codMdep);
|
||||
|
||||
List<MtbInvenr> mtbInvenrs = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbInvenr.class);
|
||||
if (mtbInvenrs == null || mtbInvenrs.size() == 0 )
|
||||
continue;
|
||||
|
||||
List<CarelliGiacenzaProg> giacDaInv = Stream.of(mtbInvenrs)
|
||||
.map(x -> {
|
||||
CarelliGiacenzaProg carelliGiacenzaProg = new CarelliGiacenzaProg()
|
||||
.setCodMdep(codMdep)
|
||||
.setCodMart(x.getCodMart())
|
||||
.setQtaCar(x.getQtaInv())
|
||||
.setQtaScar(BigDecimal.ZERO)
|
||||
.setDataReg(dataInv)
|
||||
.setTipoCar("I")
|
||||
.setDataIns(dataInv)
|
||||
.setIdInventario(idInventario);
|
||||
if (articoliSalvati.contains(x.getCodMart()))
|
||||
carelliGiacenzaProg.setOperation(OperationType.UPDATE);
|
||||
else {
|
||||
carelliGiacenzaProg.setOperation(OperationType.INSERT);
|
||||
articoliSalvati.add(x.getCodMart());
|
||||
}
|
||||
return carelliGiacenzaProg;
|
||||
}).toList();
|
||||
|
||||
List<EntityBase> entityBases = new ArrayList<>();
|
||||
entityBases.addAll(giacDaInv);
|
||||
|
||||
if (flagStato.equalsIgnoreCase("0")) {
|
||||
String whereCondFiltro = "";
|
||||
if (!UtilityString.isNullOrEmpty(filtroInv))
|
||||
whereCondFiltro = pvmService.getWhereCondFiltro(filtroInv);
|
||||
|
||||
List<String> elencoArt;
|
||||
if (!giacDaInv.isEmpty())
|
||||
elencoArt = Stream.of(giacDaInv)
|
||||
.map(CarelliGiacenzaProg::getCodMart).toList();
|
||||
else {
|
||||
elencoArt = new ArrayList<>();
|
||||
}
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT mtb_aart.cod_mart " +
|
||||
" FROM mtb_aart " +
|
||||
"WHERE exists(select * from mtb_sart where mtb_aart.cod_marT = mtb_sart.cod_mart and mtb_sart.cod_mdep = %s and \n" +
|
||||
"(qta_iniz <> 0 or qta_car <> 0 or qta_scar <> 0 ))", codMdep);
|
||||
sql = UtilityDB.addwhereCond(sql, whereCondFiltro, true);
|
||||
List<String> datiArt = UtilityDB.executeSimpleQueryOnlyFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
giacDaInv =
|
||||
Stream.of(datiArt)
|
||||
.filterNot(x-> elencoArt.contains(x))
|
||||
.map(x -> {
|
||||
CarelliGiacenzaProg carelliGiacenzaProg = new CarelliGiacenzaProg()
|
||||
.setCodMdep(codMdep)
|
||||
.setCodMart(x)
|
||||
.setQtaCar(BigDecimal.ZERO)
|
||||
.setQtaScar(BigDecimal.ZERO)
|
||||
.setDataReg(dataInv)
|
||||
.setDataIns(dataInv)
|
||||
.setIdInventario(idInventario);
|
||||
if (articoliSalvati.contains(x))
|
||||
carelliGiacenzaProg.setOperation(OperationType.UPDATE);
|
||||
else {
|
||||
carelliGiacenzaProg.setOperation(OperationType.INSERT);
|
||||
articoliSalvati.add(x);
|
||||
}
|
||||
return carelliGiacenzaProg;
|
||||
}).toList();
|
||||
entityBases.addAll(giacDaInv);
|
||||
}
|
||||
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
List<List<EntityBase>> list = Stream.of(entityBases).chunkBy(x -> counter.getAndIncrement() / 50).toList();
|
||||
|
||||
List<Runnable> calls = new ArrayList<>();
|
||||
for (List<EntityBase> entityList: list) {
|
||||
calls.add(() -> {
|
||||
try {
|
||||
for (EntityBase entityBase:entityList) {
|
||||
entityProcessor.processEntity(entityBase, true,true, "", multiDBTransactionManager);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage(), ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
UtilityThread.executeParallel(calls);
|
||||
|
||||
|
||||
//List<EntityBase> entityRet = entityProcessor.processEntityList(entityBases, false, true, false);
|
||||
//UtilityEntity.throwEntitiesException(entityRet);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user