SuggestCodeIdArtEqui

This commit is contained in:
2024-11-27 12:55:06 +01:00
parent bc4aaac3f7
commit 4af1cd1fd8
2 changed files with 108 additions and 11 deletions

View File

@@ -0,0 +1,101 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20241127125308 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createOrUpdateFunction("[suggestMtbArtEqui]", "CREATE FUNCTION [dbo].[suggestMtbArtEqui](\n" +
" @jsonParm VARCHAR(MAX)\n" +
")\n" +
" RETURNS TABLE\n" +
" AS\n" +
" RETURN( \n" +
" WITH tab_json AS (SELECT *\n" +
" FROM OPENJSON(@jsonParm)\n" +
" WITH (\n" +
" cod_mgrp VARCHAR(5) '$.codMgrp',\n" +
" cod_msgr VARCHAR(5) '$.codMsgr',\n" +
" cod_msfa VARCHAR(5) '$.codMsfa',\n" +
" cod_mtip VARCHAR(5) '$.codMtip',\n" +
" cod_mstp VARCHAR(5) '$.codMstp',\n" +
" cod_tcol_UI VARCHAR(100) '$.codTcolUI',\n" +
" marchio VARCHAR(255) '$.marchio',\n" +
" qta_cnf FLOAT '$.qtaCnf',\n" +
" peso_kg FLOAT '$.pesoKg'\n" +
" ))\n" +
" \n" +
" \n" +
" ,\n" +
" art AS (SELECT DISTINCT mtb_aart_equi.id_art_equi,\n" +
" mtb_aart_equi.descrizione,\n" +
" ISNULL(mtb_aart_equi.flag_equi_prezzo, 'T') AS flag_equi_prezzo,\n" +
" ISNULL(mtb_aart_equi.flag_equi_costo, 'N') AS flag_equi_costo,\n" +
" mtb_aart.cod_mgrp\n" +
" FROM mtb_aart left outer join mtb_aart_equi on mtb_aart.id_art_equi = mtb_aart_equi.id_art_equi\n" +
" WHERE EXISTS (SELECT *\n" +
" FROM tab_json\n" +
" WHERE mtb_aart.cod_mgrp = tab_json.cod_mgrp\n" +
" AND mtb_aart.cod_msgr = tab_json.cod_msgr \n" +
" AND mtb_aart.qta_cnf = tab_json.qta_cnf\n" +
" AND mtb_aart.peso_kg = tab_json.peso_kg\n" +
" AND (ISNULL(mtb_aart.marchio, '') = ISNULL(tab_json.marchio, ''))\n" +
" AND (ISNULL(mtb_aart.cod_msfa, '') = ISNULL(tab_json.cod_msfa, ''))\n" +
" AND (ISNULL(mtb_aart.cod_tcol_UI, '') = ISNULL(tab_json.cod_tcol_UI, ''))\n" +
" AND (ISNULL(mtb_aart.cod_mtip, '') = ISNULL(tab_json.cod_mtip, ''))\n" +
" AND (ISNULL(mtb_aart.cod_mstp, '') = ISNULL(tab_json.cod_mstp, '')))\n" +
" )\n" +
"\n" +
" SELECT *\n" +
" \n" +
" FROM (\n" +
" SELECT *\n" +
" FROM art\n" +
" UNION ALL\n" +
" SELECT NULL AS id_art_eqi,\n" +
" \n" +
" CONCAT_WS(' ', \n" +
" mtb_grup.tipo_mgrp,\n" +
" mtb_sgrp.descrizione, \n" +
" --mtb_sfam.descrizione, mtb_tipi.descrizione, \n" +
" case when mtb_sfam.descrizione like 'BAR%' then 'IN BARATTOLO '+ISNULL(mtb_tipi.descrizione,'') \n" +
" when mtb_sfam.descrizione like 'BOTTI%' then 'IN BOTTIGLIA '+ISNULL(mtb_tipi.descrizione,'') \n" +
" when mtb_sfam.descrizione like 'VASO%' then 'IN VASO '+ISNULL(mtb_tipi.descrizione,'') \n" +
" when mtb_sfam.descrizione like 'ASETT%' then 'IN BUSTA '+ISNULL(mtb_tipi.descrizione,'') \n" +
" else '' end,\n" +
" '-',\n" +
" mtb_aart.cod_tcol_UI, \n" +
" case when mtb_aart.qta_cnf = 1 then '' else convert(varchar(5), CAST(mtb_aart.qta_cnf AS FLOAT)) + ' x' end,\n" +
" CAST(mtb_aart.peso_kg AS FLOAT), 'Kg Net.',\n" +
" CASE WHEN mtb_stip.cod_mstp = 'TER' or mtb_aart.cod_mgrp = '00210' then 'C/TER.' else mtb_stip.descrizione end, mtb_aart.marchio) AS descrizione,\n" +
" \n" +
" \n" +
" 'T' AS flag_equi_prezzo,\n" +
" 'N' AS flag_equi_costo,\n" +
" mtb_aart.cod_mgrp\n" +
" FROM tab_json mtb_aart\n" +
" INNER JOIN mtb_grup ON mtb_aart.cod_mgrp = mtb_grup.cod_mgrp\n" +
" INNER JOIN mtb_sgrp ON mtb_aart.cod_mgrp = mtb_sgrp.cod_mgrp and mtb_aart.cod_msgr = mtb_sgrp.cod_msgr \n" +
" LEFT OUTER JOIN mtb_sfam on mtb_aart.cod_mgrp = mtb_sfam.cod_mgrp and mtb_aart.cod_msgr = mtb_sfam.cod_msgr and mtb_aart.cod_msfa = mtb_sfam.cod_msfa\n" +
" LEFT OUTER JOIN mtb_tipi ON mtb_aart.cod_mtip = mtb_tipi.cod_mtip\n" +
" LEFT OUTER JOIN mtb_stip ON mtb_aart.cod_mtip = mtb_stip.cod_mtip AND\n" +
" mtb_aart.cod_mstp = mtb_stip.cod_mstp\n" +
" WHERE EXISTS(SELECT * FROM tab_json)) t\n" +
" \n" +
" \n" +
" WHERE cod_mgrp IN ('00100', '00200', '00203', '00210')\n" +
" )");
}
@Override
public void down() throws Exception {
}
}

View File

@@ -5,6 +5,8 @@ import com.annimon.stream.Optional;
import com.annimon.stream.Stream;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.integry.common.var.CommonConstants;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.json.ResponseJSONObjectMapper;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import it.integry.ems_model.annotation.ReloadRow;
import it.integry.ems_model.annotation.SqlField;
@@ -23,6 +25,7 @@ import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.context.ContextLoader;
import java.lang.reflect.Field;
import java.math.BigDecimal;
@@ -995,22 +998,15 @@ public class CommonRules extends QueryRules {
}
public static void setIdArtEqui(Connection conn, MtbAart entity) throws Exception {
if (!UtilityString.isNullOrEmpty(entity.getIdArtEqui())) return;
String sql = "select CAst( case when dbo.getGestSetup( 'MTB_AART', 'ID_ART_EQUI', 'INSERT_AUTO') = 'N' THEN 0 ELSE 1 END as BIT)";
Boolean setSetIdArtEqui = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
if ( !setSetIdArtEqui ) return;
Map<String, Object> data = new HashMap<>();
data.put("cod_mgrp", entity.getCodMgrp());
data.put("cod_msgr", entity.getCodMsgr());
data.put("cod_mtip", entity.getCodMtip());
data.put("qta_cnf", entity.getQtaCnf());
data.put("peso_kg", entity.getPesoKg());
data.put("cod_tcol_UI",entity.getCodTcolUi());
data.put("marchio", entity.getMarchio());
// Convertire in JSON
ObjectMapper objectMapper = new ObjectMapper();
String jsonParm = objectMapper.writeValueAsString(data);
entity.setOnlyPkMaster(false);
ResponseJSONObjectMapper objectMapper = ContextLoader.getCurrentWebApplicationContext().getBean(ResponseJSONObjectMapper.class);
String jsonParm = objectMapper.writeValueAsString(entity);
sql =
String.format(
"SELECT * FROM dbo.suggestMtbArtEqui('%s') " ,