From f94bbb4316606d9c30c17ff97bfc80479311ae1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20Hon=C3=B3rio?= Date: Tue, 14 Jul 2020 16:14:22 -0300 Subject: [PATCH 01/10] Retorna nu_contrato, vl_contrato e de_ugestora do contrato --- src/controllers/contratos.controller.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index b09edae..c2a6d86 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -55,7 +55,10 @@ exports.getContratosByQuery = (req, res) => { let query = `SELECT \ id_contrato, \ - de_obs \ + de_obs, \ + de_ugestora, \ + vl_total_contrato, + nu_contrato \ FROM \ ( \ SELECT \ From b2acbda555dfea9f4b9b5147a59f78544e7da79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20Hon=C3=B3rio?= Date: Thu, 16 Jul 2020 11:20:26 -0300 Subject: [PATCH 02/10] Altera parametros da consulta --- src/controllers/contratos.controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index c2a6d86..6fb6132 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -55,10 +55,10 @@ exports.getContratosByQuery = (req, res) => { let query = `SELECT \ id_contrato, \ - de_obs, \ + de_obs, \ de_ugestora, \ - vl_total_contrato, - nu_contrato \ + vl_total_contrato, \ + dt_ano \ FROM \ ( \ SELECT \ @@ -83,4 +83,4 @@ exports.getContratosByQuery = (req, res) => { mapToModel: true }).then(Contrato => res.status(SUCCESS).json(Contrato)) .catch(err => res.status(BAD_REQUEST).json({ err })); -} \ No newline at end of file +} From 94457f8c1adefd46796761ffe1dc7cd7f191e513 Mon Sep 17 00:00:00 2001 From: diegooalmeida Date: Fri, 17 Jul 2020 09:14:30 -0300 Subject: [PATCH 03/10] =?UTF-8?q?Adiciona=20rota=20de=20recupera=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20municipio=20pelo=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/regioes.controller.js | 13 +++++++++++++ src/routes/regioes.routes.js | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/controllers/regioes.controller.js b/src/controllers/regioes.controller.js index 90847b1..4e31b2a 100644 --- a/src/controllers/regioes.controller.js +++ b/src/controllers/regioes.controller.js @@ -16,3 +16,16 @@ exports.getMunicipios = async (req, res) => { .then(municipios => res.status(SUCCESS).json(municipios)) .catch(err => res.status(BAD_REQUEST).json({ err })); }; + +// Recupera o município pelo ID +exports.getMunicipioById = (req, res) => { + const id = req.params.id + + Municipio.findOne({ + where: { + cd_municipio: id + } + }) + .then(municipios => res.json(municipios)) + .catch(err => res.status(BAD_REQUEST).json({ err })); +} \ No newline at end of file diff --git a/src/routes/regioes.routes.js b/src/routes/regioes.routes.js index 6efafb5..fdc639c 100644 --- a/src/routes/regioes.routes.js +++ b/src/routes/regioes.routes.js @@ -5,10 +5,14 @@ */ const router = require('express-promise-router')(); -const licitacoesController = require('../controllers/regioes.controller'); +const regioesController = require('../controllers/regioes.controller'); // Retorna todos os municipios // Exemplo: http://localhost:3000/api/municipios/ -router.get('/municipios', licitacoesController.getMunicipios) +router.get('/municipios', regioesController.getMunicipios) + +// Retorna um municipio pelo id +// Exemplo: http://localhost:3000/api/municipios/001 +router.get('/municipios/:id', regioesController.getMunicipioById) module.exports = router; \ No newline at end of file From b288048d62d54d3feca80538f08325b5594f9867 Mon Sep 17 00:00:00 2001 From: samarasss Date: Mon, 20 Jul 2020 09:08:34 -0300 Subject: [PATCH 04/10] =?UTF-8?q?Altera=20vers=C3=A3o=20do=20pacote=20load?= =?UTF-8?q?sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index e737431..abcbd17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1086,7 +1086,7 @@ } }, "lodash": { - "version": "4.17.15", + "version": "4.17.19", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, From 2fec6cbf8211bd8cbeb3f874d29f049ed2cdef74 Mon Sep 17 00:00:00 2001 From: biabs1 Date: Fri, 24 Jul 2020 12:02:53 -0300 Subject: [PATCH 05/10] Corrige problema para caracteres especiais pertencentes a palavra --- package-lock.json | 2 +- src/controllers/contratos.controller.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index abcbd17..e737431 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1086,7 +1086,7 @@ } }, "lodash": { - "version": "4.17.19", + "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index 6fb6132..5c53c8b 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -11,10 +11,10 @@ const Op = models.Sequelize.Op; const BAD_REQUEST = 400; const SUCCESS = 200; -// Retorna todas os contratos de um município que possuem ID da licitação +// Retorna todas os contratos de um município que possuem ID da licitação exports.getContratosPorMunicipio = (req, res) => { const cd_municipio = req.query.cd_municipio - + Contrato.findAll({ where: { cd_municipio: cd_municipio, id_licitacao: { [Op.ne]: null} @@ -51,7 +51,8 @@ exports.getContratosByLicitacao = (req, res) => { exports.getContratosByQuery = (req, res) => { - const termos = req.query.termo.split(' ').join(' & ') + const termos = req.query.termo.replace(/&|!<()\:',/gi, '').split(' ').join(' & '); + console.log(termos); let query = `SELECT \ id_contrato, \ From 104b03719f3b6468ee63675b5a92d87a0fe7733a Mon Sep 17 00:00:00 2001 From: biabs1 Date: Mon, 27 Jul 2020 09:47:44 -0300 Subject: [PATCH 06/10] =?UTF-8?q?Remove=20excesso=20de=20espa=C3=A7os?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/contratos.controller.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index 5c53c8b..2dbc112 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -11,6 +11,18 @@ const Op = models.Sequelize.Op; const BAD_REQUEST = 400; const SUCCESS = 200; +function removeEmptyTermos(query) { + var termos = query.termo; + + for (const key of Object.keys(termos)) { + if (termos[key] === "") { + delete termos[key]; + } + } + + return termos; +} + // Retorna todas os contratos de um município que possuem ID da licitação exports.getContratosPorMunicipio = (req, res) => { const cd_municipio = req.query.cd_municipio @@ -51,8 +63,7 @@ exports.getContratosByLicitacao = (req, res) => { exports.getContratosByQuery = (req, res) => { - const termos = req.query.termo.replace(/&|!<()\:',/gi, '').split(' ').join(' & '); - console.log(termos); + const termos = req.query.termo.replace(/[&|!<()\\:',]/gi, '').replace( /\s+/g, ' ').trim().split(' ').join(' & '); let query = `SELECT \ id_contrato, \ From 23e247e1ebf0541327c7bedd578b19b92a7d8cce Mon Sep 17 00:00:00 2001 From: biabs1 Date: Mon, 27 Jul 2020 09:51:36 -0300 Subject: [PATCH 07/10] =?UTF-8?q?Remove=20fun=C3=A7=C3=A3o=20desnecess?= =?UTF-8?q?=C3=A1ria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/contratos.controller.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index 2dbc112..e298f8f 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -11,18 +11,6 @@ const Op = models.Sequelize.Op; const BAD_REQUEST = 400; const SUCCESS = 200; -function removeEmptyTermos(query) { - var termos = query.termo; - - for (const key of Object.keys(termos)) { - if (termos[key] === "") { - delete termos[key]; - } - } - - return termos; -} - // Retorna todas os contratos de um município que possuem ID da licitação exports.getContratosPorMunicipio = (req, res) => { const cd_municipio = req.query.cd_municipio From 2a1cf9caca213a7aa0c2f3760907c8aede8034f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20Hon=C3=B3rio?= Date: Thu, 30 Jul 2020 16:21:07 -0300 Subject: [PATCH 08/10] Recupera riscos dos contratos --- src/controllers/contratos.controller.js | 32 ++++++++++++++-- src/controllers/licitacoes.controller.js | 10 ++++- src/models/contrato.model.js | 8 ++++ src/models/index.model.js | 4 +- src/models/previsao.model.js | 47 ++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 src/models/previsao.model.js diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index e298f8f..e54068a 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -6,6 +6,8 @@ const models = require("../models/index.model"); const Contrato = models.contrato; +const Previsao = models.previsao; + const Op = models.Sequelize.Op; const BAD_REQUEST = 400; @@ -15,9 +17,17 @@ const SUCCESS = 200; exports.getContratosPorMunicipio = (req, res) => { const cd_municipio = req.query.cd_municipio - Contrato.findAll({ where: { - cd_municipio: cd_municipio, - id_licitacao: { [Op.ne]: null} + Contrato.findAll({ + include: [ + { + model: Previsao, + as: "previsaoContrato" + } + ], + where: { + cd_municipio: cd_municipio, + id_licitacao: { [Op.ne]: null + } }}) .then(contratos => res.status(SUCCESS).json(contratos)) .catch(err => res.status(BAD_REQUEST).json({ err })); @@ -28,6 +38,12 @@ exports.getContratoById = (req, res) => { const id = req.params.id Contrato.findOne({ + include: [ + { + model: Previsao, + as: "previsaoContrato" + } + ], where: { id_contrato: id } @@ -58,7 +74,15 @@ exports.getContratosByQuery = (req, res) => { de_obs, \ de_ugestora, \ vl_total_contrato, \ - dt_ano \ + dt_ano, \ + (\ + SELECT \ + vig_prob_1 \ + FROM \ + previsao \ + WHERE \ + p_search.id_contrato = previsao.id_contrato\ + ) \ FROM \ ( \ SELECT \ diff --git a/src/controllers/licitacoes.controller.js b/src/controllers/licitacoes.controller.js index ed4eeb1..0722b42 100644 --- a/src/controllers/licitacoes.controller.js +++ b/src/controllers/licitacoes.controller.js @@ -8,6 +8,8 @@ const models = require("../models/index.model"); const Contrato = models.contrato; const Licitacao = models.licitacao; const Participante = models.participante; +const Previsao = models.previsao; + const Op = models.Sequelize.Op; const BAD_REQUEST = 400; @@ -35,7 +37,13 @@ exports.getLicitacaoById = (req, res) => { include: [ { model: Contrato, - as: "contratosLicitacao" + as: "contratosLicitacao", + include: [ + { + model: Previsao, + as: "previsaoContrato" + } + ] }, { model: Participante, diff --git a/src/models/contrato.model.js b/src/models/contrato.model.js index 297da53..85b9c46 100644 --- a/src/models/contrato.model.js +++ b/src/models/contrato.model.js @@ -40,5 +40,13 @@ module.exports = (sequelize, type) => { } ); + + Contrato.associate = function (models) { + Contrato.hasOne(models.previsao, { + foreignKey: "id_contrato", + sourceKey: "id_contrato", + as: "previsaoContrato" + }); + } return Contrato; }; \ No newline at end of file diff --git a/src/models/index.model.js b/src/models/index.model.js index da50c6d..7267479 100644 --- a/src/models/index.model.js +++ b/src/models/index.model.js @@ -10,6 +10,7 @@ const LicitacaoModel = "./licitacao.model.js"; const MunicipioModel = "./municipio.model.js"; const ContratoModel = "./contrato.model.js"; const ParticipanteModel = "./participante.model.js" +const PrevisaoModel = "./previsao.model.js" global.models = { Sequelize: Sequelize, @@ -18,7 +19,8 @@ global.models = { licitacao: sequelize.import(LicitacaoModel), municipio: sequelize.import(MunicipioModel), contrato: sequelize.import(ContratoModel), - participante: sequelize.import(ParticipanteModel) + participante: sequelize.import(ParticipanteModel), + previsao: sequelize.import(PrevisaoModel) }; Object.keys(global.models).forEach(modelName => { diff --git a/src/models/previsao.model.js b/src/models/previsao.model.js new file mode 100644 index 0000000..c2acac4 --- /dev/null +++ b/src/models/previsao.model.js @@ -0,0 +1,47 @@ +/** + * TEMPORÁRIO + * Arquivo: models/previsao.model.js + * Descrição: arquivo com o modelo da previsao. + */ + +module.exports = (sequelize, type) => { + Previsao = sequelize.define( + "previsao", + { + id_contrato: { + type: type.STRING, + primaryKey: true + }, + cd_u_gestora: type.INTEGER, + nu_licitacao: type.STRING, + nu_contrato: type.STRING, + dt_ano: type.INTEGER, + data_inicio: type.DATE, + nu_cpfcnpj: type.STRING, + tp_licitacao: type.INTEGER, + vl_total_contrato: type.INTEGER, + n_licitacoes_part: type.INTEGER, + n_licitacoes_venceu: type.INTEGER, + montante_lic_venceu: type.INTEGER, + perc_vitoria: type.INTEGER, + media_n_licitacoes_part: type.INTEGER, + media_n_licitacoes_venceu: type.INTEGER, + n_propostas: type.INTEGER, + media_n_propostas: type.INTEGER, + total_ganho: type.INTEGER, + status_tramita: type.INTEGER, + razao_contrato_por_vl_recebido: type.INTEGER, + media_num_contratos: type.INTEGER, + num_contratos: type.INTEGER, + vig_pred: type.STRING, + vig_prob_0: type.INTEGER, + vig_prob_1: type.INTEGER + }, + { + freezeTableName: true, + timestamps: false + } + + ); + return Previsao; +}; \ No newline at end of file From 2604cc4d29448b74d37d202d92c9078b6027c05f Mon Sep 17 00:00:00 2001 From: diegooalmeida Date: Wed, 5 Aug 2020 08:29:14 -0300 Subject: [PATCH 09/10] Adiciona recuperacao dos contratos por risco --- src/controllers/contratos.controller.js | 27 +++++++++++++++++++++++++ src/routes/contratos.routes.js | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index e54068a..005b0df 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -9,6 +9,7 @@ const Contrato = models.contrato; const Previsao = models.previsao; const Op = models.Sequelize.Op; +const sequelize = models.sequelize; const BAD_REQUEST = 400; const SUCCESS = 200; @@ -65,6 +66,32 @@ exports.getContratosByLicitacao = (req, res) => { .catch(err => res.status(BAD_REQUEST).json({ err })); } +// Retorna todas os contratos, ordenados pelo Risco +exports.getContratosPorRisco = (req, res) => { + + Contrato.findAll({ + include: [ + { + model: Previsao, + as: "previsaoContrato" + } + ], + where: { + id_licitacao: { [Op.ne]: null }, + where: sequelize.where( sequelize.col('pr_vigencia'), '>=', sequelize.literal('CURRENT_TIMESTAMP')) + }, + order: [ + [ + {model: Previsao, as: 'previsaoContrato'}, + 'vig_prob_1', + 'DESC' + ] + ] + }) + .then(contratos => res.status(SUCCESS).json(contratos)) + .catch(err => res.status(BAD_REQUEST).json({ err })); +}; + exports.getContratosByQuery = (req, res) => { const termos = req.query.termo.replace(/[&|!<()\\:',]/gi, '').replace( /\s+/g, ' ').trim().split(' ').join(' & '); diff --git a/src/routes/contratos.routes.js b/src/routes/contratos.routes.js index ebe74e9..0e64ed1 100644 --- a/src/routes/contratos.routes.js +++ b/src/routes/contratos.routes.js @@ -20,4 +20,8 @@ router.get('/licitacoes/:id_licitacao/contratos', contratosController.getContrat router.get('/search', contratosController.getContratosByQuery) +// Busca todos os contratos +// Exemplo: http://localhost:3000/api/contratos/risco/geral +router.get('/contratos/risco/geral', contratosController.getContratosPorRisco) + module.exports = router; \ No newline at end of file From 2cdcfefdde3047f95a705daa347ff783f738cbdb Mon Sep 17 00:00:00 2001 From: diegooalmeida Date: Wed, 5 Aug 2020 10:25:45 -0300 Subject: [PATCH 10/10] Corrige rota e recuperacao de risco --- src/controllers/contratos.controller.js | 5 ++++- src/routes/contratos.routes.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/controllers/contratos.controller.js b/src/controllers/contratos.controller.js index 005b0df..836eb96 100644 --- a/src/controllers/contratos.controller.js +++ b/src/controllers/contratos.controller.js @@ -73,7 +73,10 @@ exports.getContratosPorRisco = (req, res) => { include: [ { model: Previsao, - as: "previsaoContrato" + as: "previsaoContrato", + where: { + id_contrato: { [Op.ne]: null } + } } ], where: { diff --git a/src/routes/contratos.routes.js b/src/routes/contratos.routes.js index 0e64ed1..af88f19 100644 --- a/src/routes/contratos.routes.js +++ b/src/routes/contratos.routes.js @@ -21,7 +21,7 @@ router.get('/licitacoes/:id_licitacao/contratos', contratosController.getContrat router.get('/search', contratosController.getContratosByQuery) // Busca todos os contratos -// Exemplo: http://localhost:3000/api/contratos/risco/geral -router.get('/contratos/risco/geral', contratosController.getContratosPorRisco) +// Exemplo: http://localhost:3000/api/contratos/riscos/paraiba +router.get('/contratos/riscos/paraiba', contratosController.getContratosPorRisco) module.exports = router; \ No newline at end of file