Untitled

 avatar
unknown
plain_text
2 years ago
7.7 kB
4
Indexable
package br.com.senior.erpxcomven.pedido.converter.impl;

import java.util.Optional;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import br.com.senior.erpxcomven.foundation.E001endEntity;
import br.com.senior.erpxcomven.foundation.E001pesEntity;
import br.com.senior.erpxcomven.foundation.E007ufsEntity;
import br.com.senior.erpxcomven.foundation.E008raiEntity;
import br.com.senior.erpxcomven.foundation.E021motEntity;
import br.com.senior.erpxcomven.foundation.E070filEntity;
import br.com.senior.erpxcomven.foundation.E085hcl_com_gerEntity;
import br.com.senior.erpxcomven.foundation.repository.E085hcl_com_gerRepository;
import br.com.senior.erpxcomven.pedido.E120infEntity;
import br.com.senior.erpxcomven.pedido.EnumExternalAggregationType;
import br.com.senior.erpxcomven.pedido.ExternalOrderAggregationEntity;
import br.com.senior.erpxcomven.pedido.RecE007ufs;
import br.com.senior.erpxcomven.pedido.RecE008rai;
import br.com.senior.erpxcomven.pedido.RecE120inf;
import br.com.senior.erpxcomven.pedido.dto.GetAdditionalSaleInformationProjection;
import br.com.senior.erpxcomven.pedido.repository.ExternalOrderAggregationRepository;

@Component
public class RecE120infConverter  {
    
	@Inject
	private E085hcl_com_gerRepository e085hclComGerRepository;
	@Inject
	private ExternalOrderAggregationRepository externalOrderAggregationRepository;
	
	public RecE120inf retornarInfAdicionais(GetAdditionalSaleInformationProjection projection) {	        
	    E120infEntity e120inf = projection.getE120inf();
        E070filEntity e070fil = projection.getE070fil();
        E001endEntity e001endEnt = projection.getE001endEnt();
        E001pesEntity e001pesTra =  projection.getE001pesTra();
        E001pesEntity e001pesRed = projection.getE001pesRed();
        E021motEntity e021motInf = projection.getE021motInf();
        E008raiEntity e008raiInf = projection.getE008raiInf();
        E007ufsEntity e007ufsRaiInf = projection.getE007ufsRaiInf();
        E007ufsEntity ufsVei  = projection.getE007ufsVei();
	       
	    var recE120inf = new RecE120inf();
		recE120inf.id = e120inf.getId().toString();
		recE120inf.obsPed = e120inf.getObsPed();
		recE120inf.acePar = e120inf.getAcePar();
		recE120inf.pedCli = e120inf.getPedCli();
		recE120inf.codVia = Optional.ofNullable(e120inf.getCodVia()).map(Object::toString).orElse(null);
		recE120inf.plaVei = e120inf.getPlaVei();
		recE120inf.vlrFre = e120inf.getVlrFre();
		recE120inf.cifFob = Optional.ofNullable(e120inf.getCifFob()).map(Object::toString).orElse(null);
		recE120inf.vlrFrd = e120inf.getVlrFrd();
		recE120inf.vlrSeg = e120inf.getVlrSeg();
		recE120inf.vlrEmb = e120inf.getVlrEmb();
		recE120inf.vlrEnc = e120inf.getVlrEnc();
		recE120inf.vlrOut = e120inf.getVlrOut();
		recE120inf.vlrOud = e120inf.getVlrOud();
		recE120inf.perDad = e120inf.getPerDad();
		recE120inf.vlrDad = e120inf.getVlrDad();
		recE120inf.obsMot = e120inf.getObsMot();
		recE120inf.datEnt = e120inf.getDatEnt();
		recE120inf.datFat = e120inf.getDatFat();
		recE120inf.indPre = e120inf.getIndPre();
		recE120inf.indicativeIntermediation = e120inf.getIndicativeIntermediation();
		recE120inf.intermediaryTaxNumber = e120inf.getIntermediaryTaxNumber();
		recE120inf.intermediaryRegistration = e120inf.getIntermediaryRegistration();
		recE120inf.routeActivityCode = externalOrderAggregationRepository.findByE120pedAndAggregationType(e120inf.getE120ped(), EnumExternalAggregationType.RMS)
                    			        .map(ExternalOrderAggregationEntity::getExternalCode)
                    			        .orElse(null);
		recE120inf.routeOrder = e120inf.getRouteOrder();

		E085hcl_com_gerEntity customerBranch = e085hclComGerRepository
				.retrieveE085hclComGer(e120inf.getE120ped().getE070fil(), e120inf.getE120ped().getE001pesCli());
		recE120inf.aceParClienteComGer = Optional.ofNullable(customerBranch).map(E085hcl_com_gerEntity::getAcePar)
				.orElse(false);

        convertE008rai(e008raiInf, e007ufsRaiInf, recE120inf);
        convertE021motInf(e021motInf, recE120inf);
        convertE070fil(e070fil, recE120inf);
		convertE001endEnt(e001endEnt, recE120inf);
		convertE001pesTra(e001pesTra, recE120inf);
		convertE001pesRed(e001pesRed, recE120inf);
		convertE007ufsVei(ufsVei, recE120inf);

		return recE120inf;

	}

    private static void convertE007ufsVei(E007ufsEntity ufsVei, RecE120inf recE120inf) {
        if (ufsVei != null){
			var ufsVeiculo = new RecE007ufs();
			ufsVeiculo.id = ufsVei.getId().toString();
			ufsVeiculo.nomUfs = ufsVei.getNomUfs();
			ufsVeiculo.sigUfs = ufsVei.getSigUfs();
			recE120inf.e007ufsVei = ufsVeiculo;
		}
    }

    private static void convertE001pesRed(E001pesEntity e001pesRed, RecE120inf recE120inf) {
        if (e001pesRed != null) {
			recE120inf.e001pesRed = e001pesRed.getId().toString();
			recE120inf.codPesRed = e001pesRed.getCodPes() != null ? e001pesRed.getCodPes().toString() : null;
			recE120inf.apePesRed = e001pesRed.getApePes();
		}
    }

    private static void convertE001pesTra(E001pesEntity e001pesTra, RecE120inf recE120inf) {
        if (e001pesTra != null) {
			recE120inf.e001pesTra = e001pesTra.getId().toString();
			recE120inf.codPesTra = e001pesTra.getCodPes() != null ? e001pesTra.getCodPes().toString() : null;
			recE120inf.apePesTra = e001pesTra.getApePes();
		}
    }

    private static void convertE001endEnt(E001endEntity e001endEnt, RecE120inf recE120inf) {
        if (e001endEnt != null) {
			recE120inf.e001endEnt = e001endEnt.getId().toString();
			recE120inf.endPesEnt = e001endEnt.getEndPes();
			recE120inf.baiEndEnt = e001endEnt.getBaiEnd();
			recE120inf.cidEndEnt = e001endEnt.getE008rai() != null ? e001endEnt.getE008rai().getNomCid()
					: StringUtils.EMPTY;
			recE120inf.sigUfsEnt = e001endEnt.getE007ufs() != null ? e001endEnt.getE007ufs().getSigUfs()
					: StringUtils.EMPTY;
			recE120inf.cepEndEnt =  Optional.ofNullable(e001endEnt.getPostalCode()).filter(StringUtils::isNotEmpty).map(Long::valueOf).orElse(0L);
			recE120inf.nenEndEnt = e001endEnt.getNenEnd();
			recE120inf.cplEndEnt = e001endEnt.getCplEnd();
		}
    }

    private static void convertE070fil(E070filEntity e070fil, RecE120inf recE120inf) {
        if (e070fil != null) {
            recE120inf.e070filfat = e070fil.getId().toString();
            recE120inf.codFil = e070fil.getCodFil() != null ? e070fil.getCodFil().toString() : null;
            recE120inf.sigFil = e070fil.getSigFil();
        }
    }

    private static void convertE021motInf(E021motEntity e021motInf, RecE120inf recE120inf) {
        if (e021motInf != null) {
            recE120inf.e021mot = e021motInf.getId().toString();
            recE120inf.codMot = e021motInf.getCodMot() != null ? e021motInf.getCodMot().toString() : null;
            recE120inf.desMot = e021motInf.getDesMot() != null ? e021motInf.getDesMot() : null;
        }
    }

    private static void convertE008rai(E008raiEntity e008raiInf, E007ufsEntity e007ufsRaiInf, RecE120inf recE120inf) {
        if (e008raiInf != null) {
            recE120inf.e008rai = new RecE008rai();
            recE120inf.e008rai.id = e008raiInf.getId().toString();
            recE120inf.e008rai.codRai = e008raiInf.getCodRai();
            recE120inf.e008rai.nomCid = e008raiInf.getNomCid();
            if (e007ufsRaiInf != null) {
                recE120inf.e008rai.e007ufs = new RecE007ufs();
                recE120inf.e008rai.e007ufs.sigUfs = e007ufsRaiInf.getSigUfs();
            }
        }
    }
	
	

}
Editor is loading...