Importazione inventario Slim2k + nuova regola su inventari

git-svn-id: https://serverad.studio-ml.local/svn/repo/projects/IntegryManagmentSystem/trunk@5694 7169d44f-50de-5945-979c-d5cbc11e8a2d
This commit is contained in:
MinaR
2017-03-08 08:46:50 +00:00
parent 483f47269e
commit 562aef99cd
17 changed files with 606 additions and 486 deletions

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -64,8 +64,6 @@ public class DataSource {
}
public synchronized void initialize(String profileDB, String pathConnectionIni, String connectionName) throws Exception {
boolean decryptPsw = true;
if(UtilityString.isNullOrEmpty(profileDB)){
throw new Exception("Profile DB non valorizzato - controllare la chiamata del servizio");
}
@@ -87,14 +85,15 @@ public class DataSource {
throw new SyncException("Configurazione DB non trovata o dati mancanti", profileDB);
}
String decryptPsw = props.getProperty("DECRYPT_DB_PSW_" + profileDB.toUpperCase(), "S");
String dns = params[0];
setDbName(dns);
DB_USER = params[1];
DB_PASSWORD = params[2];
if(decryptPsw){
DB_PASSWORD = CryptoUtils.decrypt(DB_PASSWORD);
if("S".equals(decryptPsw)){
DB_PASSWORD = CryptoUtils.decrypt(DB_PASSWORD);
}
if(EmsRestConstants.TypeDbMYSQL.equals(typeDb)){
if(params.length < 4)

View File

@@ -228,12 +228,12 @@ public class ServiceRestResponse {
this.report = report;
}
// @JsonProperty("entity") //In modo da essere serializzato con il nome entity
//@JsonProperty("entity") //In modo da essere serializzato con il nome entity
public void setJsonObject(JsonNode jsonNode){
this.jsonNode = jsonNode;
}
// @JsonProperty("entity") //In modo da essere serializzato con il nome entity
//@JsonProperty("entity") //In modo da essere serializzato con il nome entity
public JsonNode getJsonObject(){
return jsonNode;
}

View File

@@ -98,16 +98,17 @@ public class InventariRules extends CommonRules {
public static BigDecimal completeNumConf(Connection conn, String codMart, BigDecimal qtaInv) throws Exception {
String sql = "SELECT qta_cnf FROM mtb_aart WHERE cod_mart = " + UtilityDB.valueToString(codMart);
Map<String, Object> map = execSingleQuery(conn, sql);
BigDecimal qtaCnf = new BigDecimal (map.get("qta_cnf").toString());
if (qtaCnf.equals(BigDecimal.ZERO) )
qtaCnf = BigDecimal.ONE;
BigDecimal numConf = qtaInv.divide(qtaCnf, 0 ,RoundingMode.CEILING);
BigDecimal numConf = BigDecimal.ZERO;
if (qtaCnf.equals(BigDecimal.ZERO)|| qtaInv.equals(BigDecimal.ZERO) ) {
numConf = BigDecimal.ONE;
} else {
numConf = qtaInv.divide(qtaCnf, 0 ,RoundingMode.CEILING);
}
return numConf;

View File

@@ -5,6 +5,7 @@ import it.integry.ems.annotation.SqlField;
import it.integry.ems.entity.MtbColt;
import it.integry.ems.entity.MtbPartitaMag;
import it.integry.ems.resolver.SqlFieldHolder;
import it.integry.ems.types.OperationType;
import it.integry.ems.utility.UtilityString;
import java.lang.reflect.Field;
@@ -49,6 +50,7 @@ public class PackagesRules extends QueryRules {
if (dataScad != null){
partita.setDataScad(dataScad);
}
partita.setOperation(OperationType.INSERT_OR_UPDATE);
return partita;
}

View File

@@ -70,8 +70,18 @@ then
setCodTagl( $t.get("cod_tagl").toString() )
}
end
rule "completeParitaMagInventario"
no-loop
when
eval(checkRulesEnabled == 0)
$invR : MtbInvenr( codMart != null && partitaMag != null && mtbPartitaMag == null)
$partita: MtbPartitaMag() from PackagesRules.completePartitaMag($invR.codMart, $invR.partitaMag, $invR.dataScadPartitaMag)
then
modify ( $invR ) { setMtbPartitaMag($partita) }
end
/*
rule "checkBarCodeInv"
rule "checkBarCodeInv"\
no-loop
when
eval(checkRulesEnabled == 1)

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -85,4 +85,23 @@ public class Slim2kLogisticController {
return list;
}
}
@RequestMapping(value = EmsRestConstants.PATH_IMPORT_INVENTARIO_SLIM2K, method = RequestMethod.POST)
public @ResponseBody List<ServiceRestResponse> importInventarioSlim2k(HttpServletRequest request,
@RequestParam(CommonConstants.PROFILE_DB) String configuration) {
List<ServiceRestResponse> list = new ArrayList<ServiceRestResponse>();;
try {
ds.initialize(configuration, properties.getGlobalConnectionIniPath());
String username = request.getHeader("username");
String password = request.getHeader("password");
slim2kLogisticService.setUsername(username);
slim2kLogisticService.setPassword(password);
list = slim2kLogisticService.importInventario();
} catch (Exception e) {
logger.error(e.toString());
list.add(new ServiceRestResponse(EsitoType.KO, ds.getProfile(), e));
} finally {
return list;
}
}
}

View File

@@ -1,14 +1,14 @@
package it.integry.ems.logistic.service;
import java.util.Date;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.ws.rs.client.Client;
@@ -22,21 +22,24 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.base.Joiner;
import it.integry.common.var.CommonConstants;
import it.integry.ems.config.EmsRestConstants;
import it.integry.ems.datasource.DataSource;
import it.integry.ems.entity.MtbColr;
import it.integry.ems.entity.MtbColt;
import it.integry.ems.entity.MtbInvenr;
import it.integry.ems.entity.MtbInvent;
import it.integry.ems.entity.MtbPartitaMag;
import it.integry.ems.json.JSONObjectMapper;
import it.integry.ems.properties.EmsProperties;
import it.integry.ems.response.EsitoType;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.service.HttpRestWrapper;
import it.integry.ems.service.SetupGest;
import it.integry.ems.types.OperationType;
import it.integry.ems.utility.UtilityDB;
import it.integry.ems.utility.UtilityDate;
import it.integry.ems.utility.UtilityString;
import it.integry.ems.utility.UtilityXML;
import it.integry.security.utility.RestUtil;
@@ -52,6 +55,26 @@ public class Slim2kLogisticService {
private SetupGest setupGest;
@Autowired
private JSONObjectMapper jsonObjectMapper;
@Autowired
private HttpRestWrapper httpRestWrapper;
private String username, password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
// IMPORTAZIONE COLLI DI VENDITA DA SHIPPINGPLAN_EXPORT
@@ -489,4 +512,77 @@ public class Slim2kLogisticService {
}
}
public List<ServiceRestResponse> importInventario()throws Exception {
List<ServiceRestResponse> respList = new ArrayList<ServiceRestResponse>();
String profileSlim2k = (String) setupGest.getSetup(ds.getConnection(), "IMPORT_INVENTARIO", "SLIM2K", "PROFILE", "");
String codMdep = (String) setupGest.getSetup(ds.getConnection(), "IMPORT_INVENTARIO", "SLIM2K", "COD_MDEP", "");
if (UtilityString.isNullOrEmpty(profileSlim2k)) {
throw new Exception("Profile non configurato");
}
if (UtilityString.isNullOrEmpty(codMdep)) {
throw new Exception("Deposito non configurato");
}
DataSource dsSlim2k = new DataSource();
dsSlim2k.initialize(profileSlim2k, properties.getGlobalConnectionIniPath());
Date dataInventario = new Date();
dataInventario = UtilityDate.RelativeDateTime(dataInventario, -1);
//TODO -Mina valutare se bisogna lavorare a data -1
//Date dataInventario = UtilityString.parseDate("2017/03/05");
String query =
"SELECT trim(' ' from i.item) as item, "
+ " trim(' ' from s.workorder ) as partita_mag, "
+ " max(to_timestamp(s.stockdate)) as dataScad, "
+ " sum(s.qtystock) as Giacenza, "
+ " i.unit "
+ " FROM stocksintime s, items i "
+ " WHERE s.item=i.item AND "
+ " s.firm=i.firm AND "
+ " to_timestamp(s.stdate) = " + UtilityDB.valueDateToString(dataInventario, CommonConstants.DATE_FORMAT_YMD)
+ " GROUP BY s.stdate, i.item, s.workorder, i.unit "
+ " ORDER BY s.stdate, i.item, s.workorder ";
PreparedStatement ps = dsSlim2k.getConnection().prepareStatement(query);
ResultSet rs = ps.executeQuery();
MtbInvent mtbInvent = new MtbInvent();
List<MtbInvenr> righeInv = new ArrayList<MtbInvenr>();
while(rs.next()){
if (rs.getRow() == 1 ){
mtbInvent.setCodMdep(codMdep);
mtbInvent.setDataInventario(dataInventario);
mtbInvent.setMtbInvenr(righeInv);
mtbInvent.setOperation(OperationType.INSERT);
}
MtbInvenr mtbInvenr = new MtbInvenr();
mtbInvenr.setCodMart(rs.getString(1));
mtbInvenr.setPartitaMag(rs.getString(2));
mtbInvenr.setDataScadPartitaMag(rs.getDate(3));
mtbInvenr.setQtaInv(rs.getBigDecimal(4));
righeInv.add(mtbInvenr);
break;
}
rs.close();ps.close();
ArrayNode array = jsonObjectMapper.createArrayNode();
array.addPOJO(mtbInvent);
//CHIAMATA A PROCESS ENTITY LIST
if(array.size() > 0){
StringWriter writer = new StringWriter();
jsonObjectMapper.writeValue(writer, array);
String jsonBody = writer.toString();
respList = httpRestWrapper.callProcessEntityList(ds.getProfile(), username, password, jsonBody, true);
} else {
throw new Exception("Non ci sono movimenti in data " + new SimpleDateFormat("dd/MM/yyyy").format(dataInventario));
}
return respList;
}
}

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

File diff suppressed because it is too large Load Diff

View File

@@ -153,6 +153,7 @@ public class EmsRestConstants {
public static final String PATH_IMPORT_COLLI_SLIM2K = PATH + "importColliSlim2k";
public static final String PATH_IMPORT_COLLI_ACQ_SLIM2K = PATH + "importColliAcqSlim2k";
public static final String PATH_IMPORT_STOCKS_SLIM2K = PATH + "importStocksSlim2k";
public static final String PATH_IMPORT_INVENTARIO_SLIM2K = PATH + "importInventarioSlim2k";
//ECEDI
public static final String PATH_IMPORT_ECEDI = PATH + "importEcedi";

View File

@@ -3,6 +3,7 @@ package it.integry.ems.entity;
import it.integry.common.var.CommonConstants;
import it.integry.ems.annotation.ImportFromParent;
import it.integry.ems.annotation.PK;
import it.integry.ems.annotation.Priority;
import it.integry.ems.annotation.SqlDetailId;
import it.integry.ems.annotation.SqlField;
import it.integry.ems.annotation.Table;
@@ -14,6 +15,7 @@ import java.util.Date;
import org.kie.api.definition.type.PropertyReactive;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
@PropertyReactive
@@ -89,7 +91,13 @@ public class MtbInvenr extends EntityBase {
@ImportFromParent
private String regolaCalcoloCosto;
@JsonProperty
private Date dataScadPartitaMag;
@Priority(1)
private MtbPartitaMag mtbPartitaMag;
public String getRegolaCalcoloCosto() {
return regolaCalcoloCosto;
}
@@ -242,6 +250,22 @@ public class MtbInvenr extends EntityBase {
this.dataInventario = dataInventario;
}
public Date getDataScadPartitaMag() {
return dataScadPartitaMag;
}
public void setDataScadPartitaMag(Date dataScadPartitaMag) {
this.dataScadPartitaMag = dataScadPartitaMag;
}
public MtbPartitaMag getMtbPartitaMag() {
return mtbPartitaMag;
}
public void setMtbPartitaMag(MtbPartitaMag mtbPartitaMag) {
this.mtbPartitaMag = mtbPartitaMag;
}
@Override
public void checkPreSave() throws Exception {
}

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -23,10 +23,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>