1 package ecar.historico;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.Set;
6 import java.util.Date;
7 import java.util.List;
8
9 import javax.servlet.http.HttpServletRequest;
10
11 import org.hibernate.Session;
12
13 import comum.database.Dao;
14
15 import ecar.dao.ConfiguracaoDao;
16 import ecar.exception.ECARException;
17 import ecar.pojo.ConfiguracaoCfg;
18 import ecar.pojo.HistoricoIettH;
19 import ecar.pojo.HistoricoIettSatbH;
20 import ecar.pojo.HistoricoIettutfaH;
21 import ecar.pojo.HistoricoMaster;
22 import ecar.pojo.HistoricoCorPtcH;
23 import ecar.pojo.HistoricoMotivo;
24 import ecar.pojo.HistoricoPtcH;
25 import ecar.pojo.ItemEstUsutpfuacIettutfa;
26 import ecar.pojo.ItemEstruturaIett;
27 import ecar.pojo.ItemEstruturaSisAtributoIettSatb;
28 import ecar.pojo.PontoCriticoPtc;
29 import ecar.pojo.PontocriticoCorPtccor;
30
31 public class HistoricoPtc implements IHistorico{
32
33
34 public static final int alteracao = 29;
35 public static final int exclusao = 30;
36
37 private HistoricoMaster historicoMaster = null;
38 private HistoricoCorPtcH historicoCorPtcH = null;
39 private PontoCriticoPtc ptc = null;
40 private Integer acao = null;
41 private Session session = null;
42 private HttpServletRequest request;
43 private ConfiguracaoDao cfgDao = null;
44
45 public HistoricoPtc(PontoCriticoPtc ptc,
46 int acao,
47 Session session,
48 ConfiguracaoDao cfgDao,
49 HttpServletRequest request){
50
51 this.ptc = ptc;
52 this.acao = acao;
53 this.session = session;
54 this.cfgDao = cfgDao;
55 this.request = request;
56
57 this.ptc.setUsuarioUsuInclusao(((ecar.login.SegurancaECAR) request.getSession().getAttribute("seguranca")).getUsuario());
58
59 }
60
61 public void gerarHistorico(PontoCriticoPtc ptc) throws ECARException {
62
63 this.ptc = ptc;
64
65 this.gerarHistorico();
66
67 }
68
69 public void gerarHistorico() throws ECARException {
70
71 ConfiguracaoCfg config = cfgDao.getConfiguracao();
72
73 if("S".equals(config.getIndGerarHistoricoCfg())) {
74
75 if(historicoMaster == null) {
76 this.gerarMaster(this.acao);
77 }
78
79 HistoricoPtcH ptch = new HistoricoPtcH();
80
81 ptch.setPontoCriticoPtc(ptc);
82 ptch.setHistoricoMaster(historicoMaster);
83 ptch.setIndAtivoPtc(ptc.getIndAtivoPtc());
84 ptch.setDataInclusaoPtc(ptc.getDataInclusaoPtc());
85 ptch.setDataSolucaoPtc(ptc.getDataSolucaoPtc());
86 ptch.setDescricaoSolucaoPtc(ptc.getDescricaoSolucaoPtc());
87 ptch.setIndAmbitoInternoGovPtc(ptc.getIndAmbitoInternoGovPtc());
88 ptch.setDataLimitePtc(ptc.getDataLimitePtc());
89 ptch.setDataIdentificacaoPtc(ptc.getDataIdentificacaoPtc());
90 ptch.setDescricaoPtc(ptc.getDescricaoPtc());
91 ptch.setItemEstruturaIett(ptc.getItemEstruturaIett());
92 ptch.setUsuarioUsu(ptc.getUsuarioUsu());
93 ptch.setUsuarioUsuInclusao(ptc.getUsuarioUsuInclusao());
94 ptch.setUsuarioUsuByCodUsuUltManutPtc(ptc.getUsuarioUsuByCodUsuUltManutPtc());
95 ptch.setDataUltManutencaoPtc(ptc.getDataUltManutencaoPtc());
96 ptch.setAcompRelatorioArel(ptc.getAcompRelatorioArel());
97 ptch.setSisAtributoTipo(ptc.getSisAtributoTipo());
98 ptch.setIndExcluidoPtc(ptc.getIndExcluidoPtc());
99
100 session.save(ptch);
101
102 this.setHistoricoCorPtch(ptc.getPontoCriticoCorPtccores(),ptch);
103 }
104
105 }
106
107 public void gerarMaster(Integer acao) throws ECARException {
108
109 this.historicoMaster = new HistoricoMaster();
110
111 this.acao = acao;
112
113 historicoMaster.setDataHoraHistorico(new Date());
114 historicoMaster.setUsuManutencao(((ecar.login.SegurancaECAR) request.getSession().getAttribute("seguranca")).getUsuario());
115 historicoMaster.setCodReferenciaGeral(ptc.getCodPtc());
116
117 if(alteracao == acao.intValue()) {
118 historicoMaster.setHistoricoMotivo((HistoricoMotivo)session.load(HistoricoMotivo.class, Long.valueOf(alteracao)));
119 } else if(exclusao == acao.intValue()) {
120 historicoMaster.setHistoricoMotivo((HistoricoMotivo)session.load(HistoricoMotivo.class, Long.valueOf(exclusao)));
121 }
122
123 session.save(historicoMaster);
124 }
125
126
127
128
129
130
131
132
133 public void setHistoricoCorPtch(Set pontoCriticoCorPtccores, HistoricoPtcH historicoPtcH) throws ECARException {
134
135
136
137
138 if(pontoCriticoCorPtccores != null) {
139 Iterator it = pontoCriticoCorPtccores.iterator();
140 while(it.hasNext()) {
141 PontocriticoCorPtccor pontocriticoCorPtccor = (PontocriticoCorPtccor) it.next();
142
143 this.historicoCorPtcH = new HistoricoCorPtcH();
144
145
146 if(pontocriticoCorPtccor.getCor().getIndPontoCriticoCor().equals("S")) {
147 historicoCorPtcH.setHistoricoPtcH(historicoPtcH);
148 historicoCorPtcH.setPontoCriticoPtc(pontocriticoCorPtccor.getPontoCriticoPtc());
149 historicoCorPtcH.setCor(pontocriticoCorPtccor.getCor());
150 historicoCorPtcH.setAntecedenciaPrimEmailPtccor(pontocriticoCorPtccor.getAntecedenciaPrimEmailPtccor());
151 historicoCorPtcH.setFrequenciaEnvioEmailPtccor(pontocriticoCorPtccor.getFrequenciaEnvioEmailPtccor());
152 historicoCorPtcH.setIndAtivoEnvioEmailPtccor(pontocriticoCorPtccor.getIndAtivoEnvioEmailPtccor());
153
154 session.save(historicoCorPtcH);
155 }
156 }
157 }
158 }
159
160 }