Commit 507dd014b0fa24b7f636c125dea5b01408ca4742
1 parent
88ecdb38
Exists in
master
Redmine #4483 Bloqueando serviço de baixa quando o mês de referência estiver sendo fechado.
Showing
2 changed files
with
82 additions
and
36 deletions
Show diff stats
citgrp-patrimonio-web/src/main/java/br/com/centralit/controller/BaixaController.java
... | ... | @@ -11,10 +11,14 @@ import org.springframework.web.bind.annotation.RequestParam; |
11 | 11 | import org.springframework.web.bind.annotation.ResponseBody; |
12 | 12 | |
13 | 13 | import br.com.centralit.api.model.BaixaPatrimonio; |
14 | +import br.com.centralit.api.model.MyMensagemRetorno; | |
15 | +import br.com.centralit.api.model.MyRetornoStatus; | |
14 | 16 | import br.com.centralit.api.service.BaixaService; |
17 | +import br.com.centralit.api.service.OrganizacaoService; | |
15 | 18 | import br.com.centralit.framework.controller.GenericController; |
16 | 19 | import br.com.centralit.framework.json.ResponseBodyWrapper; |
17 | 20 | import br.com.centralit.framework.json.Views; |
21 | +import br.com.centralit.framework.model.Organizacao; | |
18 | 22 | import br.com.centralit.framework.util.UtilDate; |
19 | 23 | |
20 | 24 | /** |
... | ... | @@ -46,6 +50,9 @@ import br.com.centralit.framework.util.UtilDate; |
46 | 50 | public class BaixaController extends GenericController<BaixaPatrimonio> { |
47 | 51 | |
48 | 52 | private BaixaService baixaService; |
53 | + | |
54 | + @Autowired | |
55 | + private OrganizacaoService organizacaoService; | |
49 | 56 | |
50 | 57 | public BaixaController() { |
51 | 58 | super(); |
... | ... | @@ -83,32 +90,66 @@ public class BaixaController extends GenericController<BaixaPatrimonio> { |
83 | 90 | @RequestMapping(method = RequestMethod.POST, value = "") |
84 | 91 | @ResponseBody |
85 | 92 | public ResponseBodyWrapper save(@RequestBody BaixaPatrimonio entity) throws Exception{ |
86 | - boolean uniqueConstraintViolate = true; | |
87 | - | |
88 | - BaixaPatrimonio baixa = new BaixaPatrimonio(); | |
89 | - | |
90 | - //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 | |
91 | - for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | |
92 | - try{ | |
93 | - baixa = this.baixaService.save(SerializationUtils.clone(entity)); | |
94 | - uniqueConstraintViolate = false; | |
95 | - }catch(Throwable e){ | |
96 | - if(e.getCause() instanceof ConstraintViolationException){ | |
97 | - ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | |
98 | - if(ex.getSQLException().getMessage().contains("codigo_unico")){ | |
99 | - uniqueConstraintViolate = true; | |
93 | + Organizacao organizacao = this.organizacaoService.find(this.getUsuario().getOrganizacao().getId()); | |
94 | + | |
95 | + if (!organizacao.getEmFechamento()) { | |
96 | + | |
97 | + boolean uniqueConstraintViolate = true; | |
98 | + | |
99 | + BaixaPatrimonio baixa = new BaixaPatrimonio(); | |
100 | + | |
101 | + //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 | |
102 | + for(int i = 5; i > 0 && uniqueConstraintViolate; i--){ | |
103 | + try{ | |
104 | + baixa = this.baixaService.save(SerializationUtils.clone(entity)); | |
105 | + uniqueConstraintViolate = false; | |
106 | + }catch(Throwable e){ | |
107 | + if(e.getCause() instanceof ConstraintViolationException){ | |
108 | + ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); | |
109 | + if(ex.getSQLException().getMessage().contains("codigo_unico")){ | |
110 | + uniqueConstraintViolate = true; | |
111 | + }else{ | |
112 | + throw e; | |
113 | + } | |
100 | 114 | }else{ |
101 | 115 | throw e; |
102 | 116 | } |
103 | - }else{ | |
104 | - throw e; | |
105 | 117 | } |
106 | 118 | } |
119 | + | |
120 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(baixa, getEditView()); | |
121 | + | |
122 | + return responseBody; | |
123 | + | |
124 | + } else { | |
125 | + MyRetornoStatus retorno = new MyRetornoStatus(); | |
126 | + retorno.data = entity; | |
127 | + retorno.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.warning, "MSG.ORGANIZACAO_EM_FECHAMENTO_MES")); | |
128 | + | |
129 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retorno, getEditView()); | |
130 | + | |
131 | + return responseBody; | |
132 | + } | |
133 | + } | |
134 | + | |
135 | + @RequestMapping(method = RequestMethod.POST, value = "/update") | |
136 | + @ResponseBody | |
137 | + public ResponseBodyWrapper update(@RequestBody BaixaPatrimonio objeto) { | |
138 | + Organizacao organizacao = this.organizacaoService.find(this.getUsuario().getOrganizacao().getId()); | |
139 | + | |
140 | + if (!organizacao.getEmFechamento()) { | |
141 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(this.baixaService.merge(objeto), getEditView()); | |
142 | + | |
143 | + return responseBody; | |
144 | + } else { | |
145 | + MyRetornoStatus retorno = new MyRetornoStatus(); | |
146 | + retorno.data = objeto; | |
147 | + retorno.mensagens.add(new MyMensagemRetorno(MyMensagemRetorno.TipoMensagemRetorno.warning, "MSG.ORGANIZACAO_EM_FECHAMENTO_MES")); | |
148 | + | |
149 | + ResponseBodyWrapper responseBody = new ResponseBodyWrapper(retorno, getEditView()); | |
150 | + | |
151 | + return responseBody; | |
107 | 152 | } |
108 | - | |
109 | - ResponseBodyWrapper responseBody = new ResponseBodyWrapper(baixa, getEditView()); | |
110 | - | |
111 | - return responseBody; | |
112 | 153 | } |
113 | 154 | |
114 | 155 | @RequestMapping(value = "/findIdsBemPatrimonialPorData", method = RequestMethod.GET, produces = "application/json") | ... | ... |
citgrp-patrimonio-web/src/main/webapp/assets/js/angular/custom/controller/BaixaController.js
... | ... | @@ -744,27 +744,32 @@ citApp.controller('BaixaController', |
744 | 744 | $scope.setLoadingSalva(true); |
745 | 745 | |
746 | 746 | BaixaRepository.save($scope.baixa).then(function(result) { |
747 | + if (result.originalElement && result.originalElement.status != undefined && !result.originalElement.status && result.originalElement.mensagens) { | |
748 | + $scope.setLoading(false); | |
749 | + angular.forEach(result.originalElement.mensagens, function (mensagem) { | |
750 | + $scope.showAlert(mensagem.tipoMensagem, $translate.instant(mensagem.mensagem)); | |
751 | + }); | |
752 | + } else { | |
753 | + $scope.baixa = result.originalElement; | |
747 | 754 | |
748 | - $scope.baixa = result.originalElement; | |
749 | - | |
750 | - $scope.atualizarDominioSituacaoBaixa($scope.baixa); | |
755 | + $scope.atualizarDominioSituacaoBaixa($scope.baixa); | |
751 | 756 | |
752 | - if($scope.baixa.portador){ | |
753 | - $scope.baixa.portador['pessoa.nome'] = $scope.baixa.portador.pessoa.nome; | |
754 | - } | |
755 | - if($scope.baixa.destino){ | |
756 | - $scope.baixa.destino['pessoa.nome'] = $scope.baixa.destino.pessoa.nome; | |
757 | - } | |
758 | - | |
759 | - // depois de salvar a baixa ja tendo uma referencia do id da baixa, esse metodo ira salvar os documentos se existir | |
760 | - salvarListaDocumentos($scope.baixaTemp); | |
757 | + if($scope.baixa.portador){ | |
758 | + $scope.baixa.portador['pessoa.nome'] = $scope.baixa.portador.pessoa.nome; | |
759 | + } | |
760 | + if($scope.baixa.destino){ | |
761 | + $scope.baixa.destino['pessoa.nome'] = $scope.baixa.destino.pessoa.nome; | |
762 | + } | |
761 | 763 | |
762 | - $scope.setLoading(false); | |
764 | + // depois de salvar a baixa ja tendo uma referencia do id da baixa, esse metodo ira salvar os documentos se existir | |
765 | + salvarListaDocumentos($scope.baixaTemp); | |
763 | 766 | |
764 | - // exibe a MSG de sucesso de acordo com a especificacao do caso de uso | |
765 | - exibeMsgSucesso(); | |
766 | - $scope.resetForm(); | |
767 | + $scope.setLoading(false); | |
767 | 768 | |
769 | + // exibe a MSG de sucesso de acordo com a especificacao do caso de uso | |
770 | + exibeMsgSucesso(); | |
771 | + $scope.resetForm(); | |
772 | + } | |
768 | 773 | }); |
769 | 774 | } |
770 | 775 | ... | ... |