Commit bdffa2a4811a11a6105941eebf3bbde320418be4
1 parent
507dd014
Exists in
master
Redmine #4483 Bloqueando serviço de transferência enquanto estiver sendo realiza…
…do o fechamento do mês.
Showing
2 changed files
with
78 additions
and
41 deletions
Show diff stats
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/TransferenciaController.java
... | ... | @@ -37,11 +37,14 @@ import org.springframework.web.bind.annotation.RequestMethod; |
37 | 37 | import org.springframework.web.bind.annotation.RequestParam; |
38 | 38 | import org.springframework.web.bind.annotation.ResponseBody; |
39 | 39 | |
40 | +import br.com.centralit.api.model.MyMensagemRetorno; | |
41 | +import br.com.centralit.api.model.MyRetornoStatus; | |
40 | 42 | import br.com.centralit.api.model.Transferencia; |
41 | 43 | import br.com.centralit.api.model.TransferenciaItem; |
42 | 44 | import br.com.centralit.api.service.BemPatrimonialService; |
43 | 45 | import br.com.centralit.api.service.DominioService; |
44 | 46 | import br.com.centralit.api.service.InternacionalizacaoService; |
47 | +import br.com.centralit.api.service.OrganizacaoService; | |
45 | 48 | import br.com.centralit.api.service.TransferenciaItemService; |
46 | 49 | import br.com.centralit.api.service.TransferenciaService; |
47 | 50 | import br.com.centralit.api.service.UsuarioService; |
... | ... | @@ -53,6 +56,7 @@ import br.com.centralit.framework.json.Views; |
53 | 56 | import br.com.centralit.framework.json.Views.TransferenciaEditView; |
54 | 57 | import br.com.centralit.framework.json.Views.TransferenciaListView; |
55 | 58 | import br.com.centralit.framework.model.Dominio; |
59 | +import br.com.centralit.framework.model.Organizacao; | |
56 | 60 | import br.com.centralit.framework.model.Usuario; |
57 | 61 | import br.com.centralit.framework.util.UtilColecao; |
58 | 62 | import br.com.centralit.framework.util.UtilDataBase; |
... | ... | @@ -106,6 +110,9 @@ public class TransferenciaController extends GenericController<Transferencia>{ |
106 | 110 | |
107 | 111 | @Autowired |
108 | 112 | private TransferenciaItemService transferenciaItemService; |
113 | + | |
114 | + @Autowired | |
115 | + private OrganizacaoService organizacaoService; | |
109 | 116 | |
110 | 117 | /** Atributo idioma. */ |
111 | 118 | private Dominio idioma; |
... | ... | @@ -336,41 +343,64 @@ public class TransferenciaController extends GenericController<Transferencia>{ |
336 | 343 | @RequestMapping(method = RequestMethod.POST, value = "") |
337 | 344 | @ResponseBody |
338 | 345 | public ResponseBodyWrapper save(@RequestBody Transferencia objeto) throws Exception { |
339 | - boolean uniqueConstraintViolate = true; | |
340 | - List<Transferencia> transferencias = new LinkedList<Transferencia>(); | |
341 | - | |
342 | - //TODO Solução temporária para evitar que sejam criados registros com o código duplicado. Alterar solução quando for implementado o cache compartilhado | |
343 | - for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | |
344 | - try{ | |
345 | - Transferencia transferencia = (Transferencia) BeanUtilsBean.getInstance().cloneBean(objeto); | |
346 | - transferencias = this.transferenciaService.salvarTransferencia(transferencia); | |
347 | - uniqueConstraintViolate = false; | |
348 | - }catch(PersistenceException e){ | |
349 | - if(e.getCause() instanceof ConstraintViolationException){ | |
350 | - ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | |
351 | - if(ex.getSQLException().getMessage().contains("codigo_unico")){ | |
352 | - uniqueConstraintViolate = true; | |
346 | + Organizacao organizacao = this.organizacaoService.find(this.getUsuario().getOrganizacao().getId()); | |
347 | + | |
348 | + if (!organizacao.getEmFechamento()) { | |
349 | + boolean uniqueConstraintViolate = true; | |
350 | + List<Transferencia> transferencias = new LinkedList<Transferencia>(); | |
351 | + | |
352 | + //TODO Solução temporária para evitar que sejam criados registros com o código duplicado. Alterar solução quando for implementado o cache compartilhado | |
353 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | |
354 | + try{ | |
355 | + Transferencia transferencia = (Transferencia) BeanUtilsBean.getInstance().cloneBean(objeto); | |
356 | + transferencias = this.transferenciaService.salvarTransferencia(transferencia); | |
357 | + uniqueConstraintViolate = false; | |
358 | + }catch(PersistenceException e){ | |
359 | + if(e.getCause() instanceof ConstraintViolationException){ | |
360 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | |
361 | + if(ex.getSQLException().getMessage().contains("codigo_unico")){ | |
362 | + uniqueConstraintViolate = true; | |
363 | + }else{ | |
364 | + throw e; | |
365 | + } | |
353 | 366 | }else{ |
354 | 367 | throw e; |
355 | 368 | } |
356 | - }else{ | |
357 | - throw e; | |
358 | 369 | } |
359 | 370 | } |
360 | - } | |
361 | 371 | |
362 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(transferencias, getEditView()); | |
372 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(transferencias, getEditView()); | |
363 | 373 | |
364 | - return responseBody; | |
374 | + return responseBody; | |
375 | + } else { | |
376 | + MyRetornoStatus retorno = new MyRetornoStatus(); | |
377 | + retorno.data = objeto; | |
378 | + retorno.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.warning, "MSG.ORGANIZACAO_EM_FECHAMENTO_MES")); | |
379 | + | |
380 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retorno, getEditView()); | |
381 | + | |
382 | + return responseBody; | |
383 | + } | |
365 | 384 | } |
366 | 385 | |
367 | 386 | @RequestMapping(method = RequestMethod.POST, value = "/update") |
368 | 387 | @ResponseBody |
369 | 388 | public ResponseBodyWrapper update(@RequestBody Transferencia objeto) { |
389 | + Organizacao organizacao = this.organizacaoService.find(this.getUsuario().getOrganizacao().getId()); | |
370 | 390 | |
371 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(this.transferenciaService.update(objeto), getEditView()); | |
391 | + if (!organizacao.getEmFechamento()) { | |
392 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(this.transferenciaService.update(objeto), getEditView()); | |
372 | 393 | |
373 | - return responseBody; | |
394 | + return responseBody; | |
395 | + } else { | |
396 | + MyRetornoStatus retorno = new MyRetornoStatus(); | |
397 | + retorno.data = objeto; | |
398 | + retorno.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.warning, "MSG.ORGANIZACAO_EM_FECHAMENTO_MES")); | |
399 | + | |
400 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retorno, getEditView()); | |
401 | + | |
402 | + return responseBody; | |
403 | + } | |
374 | 404 | } |
375 | 405 | |
376 | 406 | @RequestMapping(value = "/validarTransferenciaMesmoDia", method = RequestMethod.POST) | ... | ... |
citgrp-patrimonio-web/src/main/webapp/assets/js/angular/custom/controller/TransferenciaController.js
... | ... | @@ -330,30 +330,37 @@ citApp.controller('TransferenciaController', ['$scope', '$filter', '$timeout', ' |
330 | 330 | |
331 | 331 | function saveAposValidacoes(result) { |
332 | 332 | TransferenciaRepository.save($scope.transferencia).then(function(result) { |
333 | - $scope.estruturaOrganizacionalAdm = null; | |
334 | - angular.forEach(result, function(transferencia) { | |
335 | - angular.forEach(transferencia.documentos, function(documentoSalvo, key) { | |
336 | - // verifica se a entidade documento foi salva | |
337 | - if(documentoSalvo !== undefined && documentoSalvo.id !== undefined){ | |
338 | - // percorre todos os documentos temporarios para verificacao do numero do documento | |
339 | - angular.forEach($scope.saidaTemp.documentos, function(documentoTransient, key) { | |
340 | - // verifica se o numero do documento salvo e igual ao numero do documento transient que o anexo ainda esta vinculado | |
341 | - if(documentoSalvo.numero === documentoTransient.numero){ | |
342 | - //salva o anexo ao documento que tiver o mesmo numero do documento transient | |
343 | - salvarUpload(documentoSalvo, documentoTransient.uploadsDocumento); | |
344 | - } | |
345 | - }); | |
346 | - } | |
333 | + if (result.originalElement && result.originalElement.status != undefined && !result.originalElement.status && result.originalElement.mensagens) { | |
334 | + $scope.setLoading(false); | |
335 | + angular.forEach(result.originalElement.mensagens, function (mensagem) { | |
336 | + $scope.showAlert(mensagem.tipoMensagem, $translate.instant(mensagem.mensagem)); | |
337 | + }); | |
338 | + } else { | |
339 | + $scope.estruturaOrganizacionalAdm = null; | |
340 | + angular.forEach(result, function(transferencia) { | |
341 | + angular.forEach(transferencia.documentos, function(documentoSalvo, key) { | |
342 | + // verifica se a entidade documento foi salva | |
343 | + if(documentoSalvo !== undefined && documentoSalvo.id !== undefined){ | |
344 | + // percorre todos os documentos temporarios para verificacao do numero do documento | |
345 | + angular.forEach($scope.saidaTemp.documentos, function(documentoTransient, key) { | |
346 | + // verifica se o numero do documento salvo e igual ao numero do documento transient que o anexo ainda esta vinculado | |
347 | + if(documentoSalvo.numero === documentoTransient.numero){ | |
348 | + //salva o anexo ao documento que tiver o mesmo numero do documento transient | |
349 | + salvarUpload(documentoSalvo, documentoTransient.uploadsDocumento); | |
350 | + } | |
351 | + }); | |
352 | + } | |
353 | + }); | |
347 | 354 | }); |
348 | - }); | |
349 | 355 | |
350 | 356 | |
351 | - $scope.setLoading(false); | |
352 | - $scope.showAlert("success", $translate.instant("MSG.MG001")); | |
353 | - if(!$scope.edit){ | |
354 | - $scope.gerarReport(); | |
357 | + $scope.setLoading(false); | |
358 | + $scope.showAlert("success", $translate.instant("MSG.MG001")); | |
359 | + if(!$scope.edit){ | |
360 | + $scope.gerarReport(); | |
361 | + } | |
362 | + $scope.resetForm(); | |
355 | 363 | } |
356 | - $scope.resetForm(); | |
357 | 364 | }); |
358 | 365 | }; |
359 | 366 | ... | ... |