1
2
3
4 package ecar.dao;
5
6 import java.util.ArrayList;
7 import java.util.Calendar;
8 import java.util.Collection;
9 import java.util.Date;
10 import java.util.HashSet;
11 import java.util.Iterator;
12 import java.util.List;
13 import java.util.Set;
14
15 import javax.servlet.http.HttpServletRequest;
16
17 import org.hibernate.HibernateException;
18 import org.hibernate.Query;
19 import org.hibernate.Transaction;
20
21 import comum.database.Dao;
22 import comum.util.Data;
23 import comum.util.FileUpload;
24 import comum.util.Pagina;
25
26 import ecar.exception.ECARException;
27 import ecar.historico.HistoricoPtc;
28 import ecar.pojo.AcompRelatorioArel;
29 import ecar.pojo.ApontamentoApt;
30 import ecar.pojo.Cor;
31 import ecar.pojo.HistoricoPtcH;
32 import ecar.pojo.ItemEstruturaIett;
33 import ecar.pojo.PaiFilho;
34 import ecar.pojo.PontoCriticoPtc;
35 import ecar.pojo.PontocriticoCorPtccor;
36 import ecar.pojo.SisAtributoSatb;
37 import ecar.pojo.UsuarioUsu;
38 import ecar.util.Dominios;
39
40
41
42
43 public class PontoCriticoDao extends Dao {
44
45 public PontoCriticoDao(HttpServletRequest request) {
46 super();
47 this.request = request;
48 }
49
50
51
52
53
54
55
56 public Collection getAtivos(ItemEstruturaIett itemEstrutura) throws ECARException {
57 try {
58 Query query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " where ptc.itemEstruturaIett.codIett = :codIett" + " and (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.indAtivoPtc = 'S'");
59 query.setLong("codIett", itemEstrutura.getCodIett().longValue());
60
61 return query.list();
62 } catch (HibernateException e) {
63 this.logger.error(e);
64 throw new ECARException(e);
65 }
66 }
67
68
69
70
71
72
73
74 public Collection getAtivos(ItemEstruturaIett itemEstrutura, String codSgaPontoCritico) throws ECARException {
75
76 try {
77 Query query = null;
78
79 if (codSgaPontoCritico == null || "".equals(codSgaPontoCritico)) {
80 query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " where ptc.itemEstruturaIett.codIett = :codIett" + " and (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.indAtivoPtc = 'S'");
81 query.setLong("codIett", itemEstrutura.getCodIett().longValue());
82
83 }
84 else {
85
86 query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " where ptc.itemEstruturaIett.codIett = :codIett" + " and (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.indAtivoPtc = 'S' and ptc.sisAtributoTipo.codSatb = :codSatb");
87
88 query.setLong("codIett", itemEstrutura.getCodIett().longValue());
89 query.setLong("codSatb", Long.valueOf(codSgaPontoCritico));
90 }
91
92 return query.list();
93 } catch (HibernateException e) {
94 this.logger.error(e);
95 throw new ECARException(e);
96 }
97 }
98
99
100
101
102
103
104
105 public Collection getInativos(ItemEstruturaIett itemEstrutura) throws ECARException {
106 try {
107 Query query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " where ptc.itemEstruturaIett.codIett = :codIett" + " and (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.indAtivoPtc != 'S'");
108 query.setLong("codIett", itemEstrutura.getCodIett().longValue());
109
110 return query.list();
111 } catch (HibernateException e) {
112 this.logger.error(e);
113 throw new ECARException(e);
114 }
115 }
116
117
118
119
120
121
122
123 public void setPontoCritico(HttpServletRequest request, PontoCriticoPtc pontoCritico) throws ECARException {
124 ItemEstruturaIett itemEstrutura = null;
125
126
127
128
129
130 pontoCritico.setIndExcluidoPtc(Pagina.NAO);
131
132 if (!Pagina.getParamStr(request, "codIett").trim().equals("")) {
133 itemEstrutura = (ItemEstruturaIett) this.buscar(ItemEstruturaIett.class, Long.valueOf(Pagina.getParamStr(request, "codIett")));
134 pontoCritico.setItemEstruturaIett(itemEstrutura);
135 }
136
137 if (!"".equals(Pagina.getParamStr(request, "codArel"))) {
138 AcompRelatorioArel acompRelatorioArel = (AcompRelatorioArel) this.buscar(AcompRelatorioArel.class, Long.valueOf(Pagina.getParamStr(request, "codArel")));
139 pontoCritico.setAcompRelatorioArel(acompRelatorioArel);
140
141 if (itemEstrutura == null) {
142 itemEstrutura = acompRelatorioArel.getAcompReferenciaItemAri().getItemEstruturaIett();
143 }
144
145 }
146
147 if (!"".equals(Pagina.getParamStr(request, "cod")))
148 pontoCritico.setCodPtc(Long.valueOf(Pagina.getParamStr(request, "cod")));
149 if (!"".equals(Pagina.getParamStr(request, "dataIdentificacaoPtc")))
150 pontoCritico.setDataIdentificacaoPtc(Pagina.getParamDataBanco(request, "dataIdentificacaoPtc"));
151 pontoCritico.setDescricaoPtc(Pagina.getParamStr(request, "descricaoPtc"));
152 if (!"".equals(Pagina.getParamStr(request, "dataLimitePtc")))
153 pontoCritico.setDataLimitePtc(Pagina.getParamDataBanco(request, "dataLimitePtc"));
154 pontoCritico.setDataSolucaoPtc(Pagina.getParamDataBanco(request, "dataSolucaoPtc"));
155 pontoCritico.setDescricaoSolucaoPtc(Pagina.getParamStr(request, "descricaoSolucaoPtc"));
156 pontoCritico.setIndAmbitoInternoGovPtc(Pagina.getParamStr(request, "indAmbitoInternoGovPtc"));
157 pontoCritico.setIndAtivoPtc(Pagina.getParamStr(request, "indAtivoPtc"));
158
159 if (!"".equals(Pagina.getParamStr(request, "codSgaPontoCritico")))
160 pontoCritico.setSisAtributoTipo((SisAtributoSatb) this.buscar(SisAtributoSatb.class, Long.valueOf(Pagina.getParam(request, "codSgaPontoCritico"))));
161
162 if ((!"".equals(Pagina.getParamStr(request, "codUsu"))) && (!"".equals(Pagina.getParamStr(request, "dataSolucaoPtc")))) {
163 UsuarioUsu usuario = (UsuarioUsu) this.buscar(UsuarioUsu.class, Long.valueOf(Pagina.getParamStr(request, "codUsu")));
164 pontoCritico.setUsuarioUsu(usuario);
165 }
166 else {
167 pontoCritico.setUsuarioUsu(null);
168 }
169
170 this.setPontoCriticoCor(request, pontoCritico);
171 }
172
173
174
175
176
177
178
179 public void setPontoCritico(HttpServletRequest request, List campos, PontoCriticoPtc pontoCritico) throws ECARException {
180 try {
181 ItemEstruturaIett itemEstrutura = null;
182
183 itemEstrutura = (ItemEstruturaIett) this.buscar(ItemEstruturaIett.class, Long.valueOf(FileUpload.verificaValorCampo(campos, "codIett")));
184
185 pontoCritico.setItemEstruturaIett(itemEstrutura);
186
187 if (!"".equals(FileUpload.verificaValorCampo(campos, "codArel"))) {
188 AcompRelatorioArel acompRelatorioArel = (AcompRelatorioArel) this.buscar(AcompRelatorioArel.class, Long.valueOf(FileUpload.verificaValorCampo(campos, "codArel")));
189 pontoCritico.setAcompRelatorioArel(acompRelatorioArel);
190 }
191
192 if (!"".equals(FileUpload.verificaValorCampo(campos, "cod")))
193 pontoCritico.setCodPtc(Long.valueOf(FileUpload.verificaValorCampo(campos, "cod")));
194
195 if (!"".equals(FileUpload.verificaValorCampo(campos, "dataIdentificacaoPtc")))
196 pontoCritico.setDataIdentificacaoPtc(FileUpload.verificaValorCampoDataBanco(campos, "dataIdentificacaoPtc"));
197
198 pontoCritico.setDescricaoPtc(FileUpload.verificaValorCampo(campos, "descricaoPtc"));
199
200 if (!"".equals(FileUpload.verificaValorCampo(campos, "dataLimitePtc")))
201 pontoCritico.setDataLimitePtc(FileUpload.verificaValorCampoDataBanco(campos, "dataLimitePtc"));
202
203 pontoCritico.setDataSolucaoPtc(FileUpload.verificaValorCampoDataBanco(campos, "dataSolucaoPtc"));
204
205 pontoCritico.setDescricaoSolucaoPtc(FileUpload.verificaValorCampo(campos, "descricaoSolucaoPtc"));
206
207 pontoCritico.setIndAmbitoInternoGovPtc(FileUpload.verificaValorCampo(campos, "indAmbitoInternoGovPtc"));
208
209 pontoCritico.setIndAtivoPtc(FileUpload.verificaValorCampo(campos, "indAtivoPtc"));
210
211 if (!"".equals(FileUpload.verificaValorCampo(campos, "codSgaPontoCritico")))
212 pontoCritico.setSisAtributoTipo((SisAtributoSatb) this.buscar(SisAtributoSatb.class, Long.valueOf(FileUpload.verificaValorCampo(campos, "codSgaPontoCritico"))));
213
214 if ((!"".equals(FileUpload.verificaValorCampo(campos, "codUsu"))) && (!"".equals(FileUpload.verificaValorCampo(campos, "dataSolucaoPtc")))) {
215 UsuarioUsu usuario = (UsuarioUsu) this.buscar(UsuarioUsu.class, Long.valueOf(FileUpload.verificaValorCampo(campos, "codUsu")));
216 pontoCritico.setUsuarioUsu(usuario);
217 }
218 else {
219 pontoCritico.setUsuarioUsu(null);
220 }
221
222 this.setPontoCriticoCor(request, campos, pontoCritico);
223
224 } catch (Exception e) {
225
226 }
227 }
228
229
230
231
232
233
234 public void alterar(PontoCriticoPtc pontoCritico, HttpServletRequest request, UsuarioUsu usuario, HistoricoPtc historico) throws ECARException {
235 Transaction tx = null;
236
237 try {
238 ArrayList objetos = new ArrayList();
239 super.inicializarLogBean();
240
241 tx = session.beginTransaction();
242
243 PontoCriticoPtc pontoCriticoOld = (PontoCriticoPtc) buscar(PontoCriticoPtc.class, Long.valueOf(pontoCritico.getCodPtc()));
244
245
246 historico.gerarHistorico(pontoCriticoOld);
247
248
249
250 if (pontoCritico.getPontoCriticoCorPtccores() != null) {
251 Iterator itAtb = pontoCritico.getPontoCriticoCorPtccores().iterator();
252 while (itAtb.hasNext()) {
253 PontocriticoCorPtccor ptcCor = (PontocriticoCorPtccor) itAtb.next();
254 session.delete(ptcCor);
255 objetos.add(ptcCor);
256 }
257 }
258 pontoCritico.setPontoCriticoCorPtccores(null);
259
260 this.setPontoCritico(request, pontoCritico);
261
262 pontoCritico.setUsuarioUsuByCodUsuUltManutPtc(usuario);
263 pontoCritico.setDataUltManutencaoPtc(Data.getDataAtual());
264
265 List filhos = new ArrayList();
266 if (pontoCritico.getPontoCriticoCorPtccores() != null)
267 filhos.addAll(pontoCritico.getPontoCriticoCorPtccores());
268
269 session.update(pontoCritico);
270 objetos.add(pontoCritico);
271
272 Iterator it = filhos.iterator();
273
274 while (it.hasNext()) {
275 PaiFilho object = (PaiFilho) it.next();
276 object.atribuirPKPai();
277
278 session.save(object);
279 objetos.add(object);
280 }
281
282 tx.commit();
283
284 if (super.logBean != null) {
285 super.logBean.setCodigoTransacao(Data.getHoraAtual(false));
286 super.logBean.setOperacao("INC_ALT_EXC");
287 Iterator itObj = objetos.iterator();
288
289 while (itObj.hasNext()) {
290 super.logBean.setObj(itObj.next());
291 super.loggerAuditoria.info(logBean.toString());
292 }
293 }
294
295 } catch (HibernateException e) {
296 if (tx != null)
297 try {
298 tx.rollback();
299 } catch (HibernateException r) {
300 this.logger.error(r);
301 throw new ECARException("erro.hibernateException");
302 }
303 this.logger.error(e);
304 throw new ECARException("erro.hibernateException");
305 } catch (ECARException e) {
306 this.logger.error(e);
307 if (tx != null)
308 try {
309 tx.rollback();
310 } catch (HibernateException r) {
311 this.logger.error(r);
312 throw new ECARException("erro.hibernateException");
313 }
314 throw e;
315 }
316 }
317
318
319
320
321
322
323 public void alterar(PontoCriticoPtc pontoCritico, HttpServletRequest request, List campos, UsuarioUsu usuario, HistoricoPtc historico) throws ECARException {
324 Transaction tx = null;
325
326 try {
327 ArrayList objetos = new ArrayList();
328 super.inicializarLogBean();
329
330 tx = session.beginTransaction();
331
332 PontoCriticoPtc pontoCriticoOld = (PontoCriticoPtc) buscar(PontoCriticoPtc.class, Long.valueOf(pontoCritico.getCodPtc()));
333
334
335 historico.gerarHistorico(pontoCriticoOld);
336
337
338
339 if (pontoCritico.getPontoCriticoCorPtccores() != null) {
340 Iterator itAtb = pontoCritico.getPontoCriticoCorPtccores().iterator();
341 while (itAtb.hasNext()) {
342 PontocriticoCorPtccor ptcCor = (PontocriticoCorPtccor) itAtb.next();
343 session.delete(ptcCor);
344 objetos.add(ptcCor);
345 }
346 }
347 pontoCritico.setPontoCriticoCorPtccores(null);
348
349 this.setPontoCritico(request, campos, pontoCritico);
350
351 pontoCritico.setUsuarioUsuByCodUsuUltManutPtc(usuario);
352 pontoCritico.setDataUltManutencaoPtc(Data.getDataAtual());
353
354 List filhos = new ArrayList();
355 if (pontoCritico.getPontoCriticoCorPtccores() != null)
356 filhos.addAll(pontoCritico.getPontoCriticoCorPtccores());
357
358 session.update(pontoCritico);
359 objetos.add(pontoCritico);
360
361 Iterator it = filhos.iterator();
362
363 while (it.hasNext()) {
364 PaiFilho object = (PaiFilho) it.next();
365 object.atribuirPKPai();
366
367 session.save(object);
368 objetos.add(object);
369 }
370
371 tx.commit();
372
373 if (super.logBean != null) {
374 super.logBean.setCodigoTransacao(Data.getHoraAtual(false));
375 super.logBean.setOperacao("INC_ALT_EXC");
376 Iterator itObj = objetos.iterator();
377
378 while (itObj.hasNext()) {
379 super.logBean.setObj(itObj.next());
380 super.loggerAuditoria.info(logBean.toString());
381 }
382 }
383
384 } catch (HibernateException e) {
385 if (tx != null)
386 try {
387 tx.rollback();
388 } catch (HibernateException r) {
389 this.logger.error(r);
390 throw new ECARException("erro.hibernateException");
391 }
392 this.logger.error(e);
393 throw new ECARException("erro.hibernateException");
394 } catch (ECARException e) {
395 this.logger.error(e);
396 if (tx != null)
397 try {
398 tx.rollback();
399 } catch (HibernateException r) {
400 this.logger.error(r);
401 throw new ECARException("erro.hibernateException");
402 }
403 throw e;
404 }
405 }
406
407
408
409
410
411
412
413
414 public void setPontoCriticoCor(HttpServletRequest request, PontoCriticoPtc pontoCritico) throws ECARException {
415
416 PontocriticoCorPtccor ptcCor = null;
417 List setCores = new CorDao(request).listar(Cor.class, new String[] { "ordemCor", "asc" });
418 Cor cor = null;
419 Iterator itCores = null;
420
421 if (setCores != null)
422 itCores = setCores.iterator();
423
424 while (itCores.hasNext()) {
425 cor = (Cor) itCores.next();
426
427 ptcCor = new PontocriticoCorPtccor();
428 ptcCor.setCor(cor);
429 ptcCor.setPontoCriticoPtc(pontoCritico);
430 ptcCor.setAntecedenciaPrimEmailPtccor(Integer.valueOf(Pagina.getParamInt(request, "ant_" + cor.getCodCor())));
431 ptcCor.setFrequenciaEnvioEmailPtccor(Integer.valueOf(Pagina.getParamInt(request, "freq_" + cor.getCodCor())));
432 ptcCor.setIndAtivoEnvioEmailPtccor("S".equals(Pagina.getParamStr(request, "ativo[" + cor.getCodCor() + "]").trim()) ? "S" : "N");
433
434 if (pontoCritico.getPontoCriticoCorPtccores() == null)
435 pontoCritico.setPontoCriticoCorPtccores(new HashSet());
436 pontoCritico.getPontoCriticoCorPtccores().add(ptcCor);
437 }
438 }
439
440
441
442
443
444
445
446
447 public void setPontoCriticoCor(HttpServletRequest request, List campos, PontoCriticoPtc pontoCritico) throws ECARException {
448 try {
449
450 PontocriticoCorPtccor ptcCor = null;
451 List setCores = new CorDao(request).listar(Cor.class, new String[] { "ordemCor", "asc" });
452 Cor cor = null;
453 Iterator itCores = null;
454
455 if (setCores != null)
456 itCores = setCores.iterator();
457
458 while (itCores.hasNext()) {
459 cor = (Cor) itCores.next();
460
461 ptcCor = new PontocriticoCorPtccor();
462 ptcCor.setCor(cor);
463 ptcCor.setPontoCriticoPtc(pontoCritico);
464 ptcCor.setAntecedenciaPrimEmailPtccor(Integer.valueOf(FileUpload.verificaValorCampo(campos, "ant_" + cor.getCodCor())));
465 ptcCor.setFrequenciaEnvioEmailPtccor(Integer.valueOf(FileUpload.verificaValorCampo(campos, "freq_" + cor.getCodCor())));
466 ptcCor.setIndAtivoEnvioEmailPtccor("S".equals(FileUpload.verificaValorCampo(campos, "ativo[" + cor.getCodCor() + "]").trim()) ? "S" : "N");
467
468 if (pontoCritico.getPontoCriticoCorPtccores() == null)
469 pontoCritico.setPontoCriticoCorPtccores(new HashSet());
470 pontoCritico.getPontoCriticoCorPtccores().add(ptcCor);
471 }
472 } catch (Exception e) {
473
474 }
475 }
476
477
478
479
480
481
482
483
484
485
486 public void excluir(String[] codigosParaExcluir, UsuarioUsu usuario) throws ECARException {
487
488 Transaction tx = null;
489
490 try {
491
492 super.inicializarLogBean();
493 tx = session.beginTransaction();
494
495 for (int i = 0; i < codigosParaExcluir.length; i++) {
496 PontoCriticoPtc pontoCritico = (PontoCriticoPtc) this.buscar(PontoCriticoPtc.class, Long.valueOf(codigosParaExcluir[i]));
497 if (pontoCritico.getApontamentoApts() != null && pontoCritico.getApontamentoApts().size() > 0) {
498 throw new ECARException("itemEstrutura.pontoCritico.exclusao.possuiApontamentos");
499 }
500 else {
501
502
503 PontoCriticoPtc old = (PontoCriticoPtc) buscar(PontoCriticoPtc.class, Long.valueOf(pontoCritico.getCodPtc()));
504
505 pontoCritico.setDataUltManutencaoPtc(Data.getDataAtual());
506 pontoCritico.setUsuarioUsuByCodUsuUltManutPtc(usuario);
507 pontoCritico.setIndExcluidoPtc(Dominios.SIM);
508
509
510 HistoricoPtc historico = new HistoricoPtc(pontoCritico, HistoricoPtc.exclusao, session, new ConfiguracaoDao(request), request);
511 historico.gerarHistorico(old);
512
513
514 session.update(pontoCritico);
515 }
516 }
517
518 tx.commit();
519
520 if (super.logBean != null) {
521 super.logBean.setCodigoTransacao(Data.getHoraAtual(false));
522 super.logBean.setOperacao("EXC");
523
524 }
525
526 } catch (HibernateException e) {
527 if (tx != null)
528 try {
529 tx.rollback();
530 } catch (HibernateException r) {
531 this.logger.error(r);
532 throw new ECARException("erro.hibernateException");
533 }
534 this.logger.error(e);
535 throw new ECARException("erro.hibernateException");
536 }
537 }
538
539
540
541
542
543
544 public void salvar(PontoCriticoPtc pontoCritico) throws ECARException {
545 pontoCritico.setDataInclusaoPtc(Data.getDataAtual());
546 List filhos = new ArrayList();
547 if (pontoCritico.getPontoCriticoCorPtccores() != null)
548 filhos.addAll(pontoCritico.getPontoCriticoCorPtccores());
549 super.salvar(pontoCritico, filhos);
550 }
551
552
553
554
555
556
557 public Collection getPontosCriticosSolucionados(ItemEstruturaIett item) throws ECARException {
558 try {
559 Query query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " where ptc.itemEstruturaIett.codIett = :codIett" + " and ptc.itemEstruturaIett.indAtivoIett = 'S'" + " and (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.indAtivoPtc = 'S'" + " and ptc.dataSolucaoPtc is not null");
560 query.setLong("codIett", item.getCodIett().longValue());
561 return query.list();
562 } catch (HibernateException e) {
563 this.logger.error(e);
564 throw new ECARException(e);
565 }
566 }
567
568
569
570
571
572
573 public Collection getPontosCriticosNaoSolucionados(ItemEstruturaIett item) throws ECARException {
574 try {
575 Query query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " where ptc.itemEstruturaIett.codIett = :codIett" + " and ptc.itemEstruturaIett.indAtivoIett = 'S'" + " and (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.indAtivoPtc = 'S'" + " and ptc.dataSolucaoPtc is null");
576 query.setLong("codIett", item.getCodIett().longValue());
577 return query.list();
578 } catch (HibernateException e) {
579 this.logger.error(e);
580 throw new ECARException(e);
581 }
582 }
583
584
585
586
587
588
589 public boolean verificaDatasUltrapassadas(Collection lista) {
590
591 if (lista != null && lista.size() > 0) {
592 Iterator it = lista.iterator();
593
594 while (it.hasNext()) {
595 PontoCriticoPtc pontoCritico = (PontoCriticoPtc) it.next();
596
597 Calendar dataAtual = Calendar.getInstance();
598
599 dataAtual.clear(Calendar.HOUR);
600 dataAtual.clear(Calendar.HOUR_OF_DAY);
601 dataAtual.clear(Calendar.MINUTE);
602 dataAtual.clear(Calendar.SECOND);
603 dataAtual.clear(Calendar.MILLISECOND);
604 dataAtual.clear(Calendar.AM_PM);
605
606 Calendar dataLimite = Calendar.getInstance();
607 dataLimite.setTime(pontoCritico.getDataLimitePtc());
608
609 dataLimite.clear(Calendar.HOUR);
610 dataLimite.clear(Calendar.HOUR_OF_DAY);
611 dataLimite.clear(Calendar.MINUTE);
612 dataLimite.clear(Calendar.SECOND);
613 dataLimite.clear(Calendar.MILLISECOND);
614 dataLimite.clear(Calendar.AM_PM);
615
616 if (dataAtual.after(dataLimite) && pontoCritico.getDataSolucaoPtc() == null) {
617 return true;
618 }
619 }
620 }
621
622 return false;
623 }
624
625
626
627
628
629
630
631 public String[] getRelogioNaData(PontoCriticoPtc pontoCritico, Date data) throws ECARException {
632 String corRelogio = "Branco";
633 String descRelogio = "Data registrada (Nenhuma ação requerida)";
634 int diasAntecedencia;
635 Date dataCorrente = data;
636 String dataCorrStr = Data.parseDate(dataCorrente);
637 Date dataLimitePtc = pontoCritico.getDataLimitePtc();
638 String dataLimiteStr = Data.parseDate(dataLimitePtc);
639
640 if ("S".equals(pontoCritico.getIndAtivoPtc())) {
641 if (pontoCritico.getDataSolucaoPtc() != null) {
642 corRelogio = "Checked";
643 descRelogio = "Solucionado";
644 }
645 else {
646 if ((dataLimitePtc.before(dataCorrente)) || (dataLimiteStr.equals(dataCorrStr))) {
647 corRelogio = "PretoFixo";
648 descRelogio = "Data Limite Ultrapassada";
649 }
650
651
652
653
654 else {
655 List listPtcCor = this.ordenaSet(pontoCritico.getPontoCriticoCorPtccores(), "this.antecedenciaPrimEmailPtccor", "asc");
656 Iterator itPtcCor = listPtcCor.iterator();
657 boolean encontrouLimite = false;
658 while ((itPtcCor.hasNext()) && (!encontrouLimite)) {
659 PontocriticoCorPtccor ptcCor = (PontocriticoCorPtccor) itPtcCor.next();
660 if (ptcCor.getAntecedenciaPrimEmailPtccor() == null)
661 diasAntecedencia = 0;
662 else
663 diasAntecedencia = ptcCor.getAntecedenciaPrimEmailPtccor().intValue();
664
665 Date dataComparacao = Data.addDias(diasAntecedencia, dataCorrente);
666 String dataCompStr = Data.parseDate(dataComparacao);
667
668
669
670
671 if ((dataComparacao.after(dataLimitePtc)) || (dataCompStr.equals(dataLimiteStr))) {
672 if (diasAntecedencia > 0) {
673 corRelogio = ptcCor.getCor().getNomeCor();
674 descRelogio = ptcCor.getCor().getSignificadoCor();
675 encontrouLimite = true;
676 }
677 }
678 }
679 }
680 }
681 }
682 else {
683 corRelogio = "Proibido";
684 descRelogio = "Cancelado";
685 }
686 String[] retorno = { corRelogio, descRelogio };
687 return (retorno);
688 }
689
690
691
692
693
694
695
696
697
698
699
700 public List listarPontoCriticoAtivoNExcluidoNSolucionado(String situacao, String excluido) throws ECARException {
701 List list = null;
702 try {
703 Query query = session.createQuery("from PontoCriticoPtc " + "where indAtivoPtc = :situacao and ind_excluido_ptc <> :excluido and data_solucao_ptc is null " + "order by codPtc asc ");
704 query.setString("situacao", situacao);
705 query.setString("excluido", excluido);
706 list = query.list();
707 } catch (HibernateException e) {
708 this.logger.error(e);
709 throw new ECARException("erro.hibernateException");
710 }
711 return list;
712 }
713
714
715
716
717
718
719
720 public boolean contemListaApontamentos(PontoCriticoPtc pontoCritico) {
721 Set<ApontamentoApt> apontamentos = null;
722 if (pontoCritico != null) {
723 apontamentos = pontoCritico.getApontamentoApts();
724 }
725 if (apontamentos != null && apontamentos.size() > 0) {
726 return true;
727 }
728 return false;
729 }
730
731
732
733
734
735
736
737
738
739 public List listar(ItemEstruturaIett itemEstrutura) throws ECARException {
740 List list = null;
741
742 try {
743 Query query = session.createQuery("select ptc from PontoCriticoPtc ptc" + " where " + " (ptc.indExcluidoPtc <> 'S' or ptc.indExcluidoPtc is null) " + " and ptc.itemEstruturaIett.codIett = :codIett");
744 query.setLong("codIett", itemEstrutura.getCodIett());
745
746 list = query.list();
747 } catch (HibernateException e) {
748 this.logger.error(e);
749 throw new ECARException("erro.hibernateException");
750 }
751
752 return list;
753 }
754
755
756
757
758
759
760
761
762
763 public List listarItensIncluidosAntesDaDataBase(ItemEstruturaIett itemEstrutura, Date dataBase) throws ECARException {
764 List list = null;
765 try {
766 Query query = session.createQuery("select ptc from PontoCriticoPtc ptc" + " where " +
767
768
769
770 " ptc.itemEstruturaIett.codIett = :codIett " + " and ptc.dataInclusaoPtc < :dataBase " + " order by ptc.codPtc");
771 query.setLong("codIett", itemEstrutura.getCodIett());
772 query.setDate("dataBase", dataBase);
773
774 list = query.list();
775 } catch (HibernateException e) {
776 this.logger.error(e);
777 throw new ECARException("erro.hibernateException");
778 }
779
780 return list;
781 }
782
783
784
785
786
787
788
789
790 public List listarExcluidos(long codIett) throws ECARException {
791 List list = null;
792
793 try {
794 Query query = this.getSession().createQuery("select ptc from PontoCriticoPtc ptc" + " join ptc.itemEstruturaIett itemEstrutura " + " where ptc.indExcluidoPtc = 'S' and itemEstrutura.codIett = :codIett");
795 query.setLong("codIett", codIett);
796 list = query.list();
797 } catch (HibernateException e) {
798 this.logger.error(e);
799 throw new ECARException("erro.hibernateException");
800 }
801
802 return list;
803 }
804
805
806
807
808
809
810
811
812 public List<HistoricoPtcH> listarHistorico(PontoCriticoPtc pontoCritico, Date dataBase) throws ECARException {
813 List list = null;
814
815 try {
816 Query query = session.createQuery("select ptcH from HistoricoPtcH ptcH " + " where " + " ptcH.pontoCriticoPtc.codPtc = :codPtc " + " and (ptcH.dataUltManutencaoPtc is null or ptcH.dataUltManutencaoPtc < :dataBase)" + " order by ptcH.codPtcH asc ");
817
818 query.setLong("codPtc", pontoCritico.getCodPtc());
819 query.setDate("dataBase", dataBase);
820
821 list = query.list();
822 } catch (HibernateException e) {
823 this.logger.error(e);
824 throw new ECARException("erro.hibernateException");
825 }
826
827 return list;
828 }
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905 }