此功能旨在创建图像中的数据库。
exports.processosjudiciais = functions.https.onRequest(async (request, response): Promise<any> => {
const jwtClient = new google.auth.JWT({
email: serviceAccount.client_email,
key: serviceAccount.private_key,
scopes: ['https://www.googleapis.com/auth/spreadsheets']
})
await jwtClient.authorize()
const { data } = await sheets.spreadsheets.values.get({
auth: jwtClient,
spreadsheetId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
range: `Processos judiciais!A11664:E11667`
})
const updatePromises = new Array()
data.values?.forEach(row => {
const [processoBE, autoresBE, documentosDosautores, arbitramentoDeHonoráriosBE, valorDaCausa] = row
firestore.collection("Processos judiciais").doc(processoBE).set({
processoBE, autoresBE, documentosDosautores, valorDaCausa
})
arbitramentoDeHonoráriosBE.split("; ").forEach((v: string) => {
updatePromises.push(
firestore.collection("Processos judiciais").doc(processoBE).collection('fee-arbitrations - Base de Execução').doc(v).set({
arbitramentoDeHonoráriosBE: v,
processoBE,
})
)
})
})
return await Promise.all(updatePromises)
})
我需要将我用红色箭头突出显示的数据与谷歌电子表格中的值(我也在图像中以红色突出显示)进行比较。我该如何进行这种比较?从我制作的代码中,如果我只与第一个“where”进行比较,我可以提取结果。我需要与两个“哪里”进行比较。我究竟做错了什么?为什么我不能做这个比较?
import * as functions from 'firebase-functions'
import { google } from 'googleapis'
import { initializeApp } from 'firebase-admin/app'
const serviceAccount = require('../sheets_updater_service_account.json')
const sheets = google.sheets('v4')
import { getFirestore } from "firebase-admin/firestore"
initializeApp()
const firestore = getFirestore()
module.exports.readAndUpdateAdministrativeSheet = functions.https.onRequest(async (request, response) => {
// =========================== AUTENTICAÇÃO FIREBASE ===================================
const jwtClient = new google.auth.JWT({
email: serviceAccount.client_email,
key: serviceAccount.private_key,
scopes: ['https://www.googleapis.com/auth/spreadsheets']
})
await jwtClient.authorize()
// ================= CONEXÃO COM A PLANILHA CRIAÇÃO DE FILTROS =========================
const { data } = await sheets.spreadsheets.values.get({
auth: jwtClient,
spreadsheetId: '1bGJGQInmGmI-ODHM5hSZtQdvbPFVzWT70oPD6mTxcmU',
range: `Listagem de pagamento!A2:X6`,
})
// ========= CRIAÇÃO DE BANCO DE DADOS DA COLEÇÃO LISTAGEM DE PAGAMENTO ================
const generateDuplicities = data.values!.map(async row => {
const [idade, nome, cpf, cpf_x, numeroRequerimento, arbitramentoHonorários,
valorArbitrado, valorDeferido, valorComplementar, status, resultado, codigoBanco,
banco, agencia, conta, dataDoRequerimento, dataRequerimento, dataStatus,
comarca, vara, ato, assistidos, email, telefone] = row
firestore.collection("Listagem de pagamento").doc(numeroRequerimento).set({
idade, nome, cpf, cpf_x, numeroRequerimento, arbitramentoHonorários,
valorArbitrado, valorDeferido, valorComplementar, status, resultado, codigoBanco,
banco, agencia, conta, dataDoRequerimento, dataRequerimento, dataStatus, comarca, vara, ato,
assistidos, email, telefone
})
const duplicitiesWithJudicialCharges = new Array()
const resultduplicitiesWithJudicialCharges = firestore.collection("Processos judiciais") //1VgkQFGZCKvINMLtnVLIeC0tQhAjxeNk92PQN5QKLq-Q (Base de dados de execuções)
.where("arbitramentoDeHonoráriosBE", "array-contains", arbitramentoHonorários) // Arbitramento de Honorários => Planilha Base de dados de execuções / Arbitramento de Honorários => Planilha de Criação de filtros
.where("documentosDosautores", "==", cpf) // documentosDosautores => Planilha Base de dados de execuções / cpf => Planilha de Criação de filtros
const resDuplicitiesWithJudicialCharges = await resultduplicitiesWithJudicialCharges.get()
if (resDuplicitiesWithJudicialCharges.size) {
resDuplicitiesWithJudicialCharges.forEach(doc => {
if (resDuplicitiesWithJudicialCharges.size == 1) {
functions.logger.log("Foi encontrada " + `${resDuplicitiesWithJudicialCharges.size} ` + "duplicidade judicial referente a pessoa " + `${nome}.`)
functions.logger.log(doc.id) // NÃO MEXER
functions.logger.log(doc.data()) //NÃO MEXER
duplicitiesWithJudicialCharges.push(`${'arbitramentoHonorários'}: ${arbitramentoHonorários}`, `${'nome'}: ${nome}`, `${'processoBE'}: ${doc.data().processoBE}`)
functions.logger.log(duplicitiesWithJudicialCharges)//NÃO MEXER
} else if (resDuplicitiesWithJudicialCharges.size > 1) {
functions.logger.log("Foram encontradas " + `${resDuplicitiesWithJudicialCharges.size} ` + "duplicidades Judicial referente a pessoa " + `${nome}.`)
}
})
}
else if (resDuplicitiesWithJudicialCharges.size <= 0){
functions.logger.log('Não há duplicidades judicial nesta lista')
}
})
await Promise.all(generateDuplicities)
})
谁能告诉我我做错了什么?
在这行代码上:
const resultduplicitiesWithJudicialCharges = firestore.collection("Processos judiciais") //1VgkQFGZCKvINMLtnVLIeC0tQhAjxeNk92PQN5QKLq-Q (Base de dados de execuções)
.where("arbitramentoDeHonoráriosBE", "array-contains", arbitramentoHonorários) // Arbitramento de Honorários => Planilha Base de dados de execuções / Arbitramento de Honorários => Planilha de Criação de filtros
.where("documentosDosautores", "==", cpf)
有一些问题我想指出。
Processos judiciais
集合内的文档,因此您的查询无法到达子集合内的文档。array-contains
只能在显示的图像中类型为. 的字段中使用。array
string
arbitramentoHonorários
是array
,则应改用in
运算符。如果是,string
那么您应该使用==
运算符。.where("documentosDosautores", "==", cpf)
。为了能够查询集合和子集合,必须先查询集合并循环所有匹配的数据,然后调用另一个查询来查询文档的子集合并将其推送到初始化的数组中。请参见下面的代码:
const resultduplicitiesWithJudicialCharges = db.collection('Processos judiciais').where('documentosDosautores', '==', cpf);
const duplicitiesWithJudicialCharges = [];
resultduplicitiesWithJudicialCharges.get().then((querySnapshot) => {
// Loop through all the matched result from the parent collection query.
querySnapshot.forEach((parentDoc) => {
// Logs documents from the parent collection.
console.log(childDoc.id, " => ", doc.data());
// Queries the subcollection where in `parentDoc.ref` are the documents from the result of 1st query.
parentDoc.ref.collection(<'YOUR-SUBCOLLECTION-NAME'>).where('arbitramentoDeHonoráriosBE', '==', arbitramentoHonorários).get().then((querySnapshot) => {
// Loop through all matched result from the subcollection query for each document matched from the parent query.
querySnapshot.forEach((childDoc) => {
// Logs documents from the subcollection.
console.log(childDoc.id, " => ", doc.data());
// Push data to the initialized array. Also used the `parentDoc.data()` that we fetched on the previous query.
duplicitiesWithJudicialCharges.push(`${'arbitramentoHonorários'}: ${arbitramentoHonorários}`, `${'nome'}: ${nome}`, `${'processoBE'}: ${parentDoc.data().processoBE}`)
});
});
});
});
在上面的代码片段上添加了一些注释以获得更好的解释。
有关更多相关信息,您可以查看以下文档:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句