Add seatable to excel

这个提交包含在:
maisui 2023-05-22 01:08:21 +08:00
父节点 210b69973d
当前提交 40699cce5b
共有 1 个文件被更改,包括 106 次插入63 次删除

169
app.js
查看文件

@ -41,6 +41,7 @@ console.log('');
console.log('请注意,Seatable请使用表格版本为')
console.log('v1.1.3及以上的版本对接该转换器。')
sendRequest(options[process.env.TABLE_APP], function (response) {
var data = {};
//根据配置判断模型
if (process.env.TABLE_APP == "nocodb") {
//todo
@ -51,19 +52,50 @@ sendRequest(options[process.env.TABLE_APP], function (response) {
}
});
} else if (process.env.TABLE_APP == "seatable") {
seatableGetBase = {
//住房表请求体
seatableGetHouseBase = {
method: "GET",
//dtable_server路径带有最右侧“/”
url: response.dtable_server + "dtables/" + response.dtable_uuid,
url: response.dtable_server + "api/v1/dtables/" + response.dtable_uuid+'/rows/',
params: {
convert: true,
table_name: '住房、产权信息',
convert_link_id: true,
start: 0,
limit: 1000
},
headers: {
Authorization: "Token " + response.access_token,
},
};
sendRequest(seatableGetBase, function (response) {
//console.log(response.tables);
sortData(response.tables,function(data){
})
//人口请求体
seatableGetPopBase = {
method: "GET",
//dtable_server路径带有最右侧“/”
url: response.dtable_server + "api/v1/dtables/" + response.dtable_uuid+'/rows/',
params: {
convert: true,
table_name: '人口信息',
convert_link_id: true,
start: 0,
limit: 1000
},
headers: {
Authorization: "Token " + response.access_token,
},
};
sendRequest(seatableGetHouseBase, function (response) {
data['house']=response['rows'];
sendRequest(seatableGetPopBase, function (response) {
//console.log(response['rows'])
data['population']=response['rows'];
//console.log(data)
sortData(data,function(data){
for (var key of Object.keys(data)) {
replaceExcel(data[key])
}
})
});
});
}
});
@ -116,6 +148,7 @@ async function replaceExcel(data) {
break;
default:
}
worksheet.getCell("M6").value = data["people"].length;//居住人口数
worksheet.getCell("N6").value = data["emergency_name"];
worksheet.getCell("O6").value = data["emergency_phone"];
@ -168,7 +201,7 @@ async function replaceExcel(data) {
registered_population++;
}
//填充表头居住人口
worksheet.getCell("M6").value = Number(k) + 1;//居住人口数
//worksheet.getCell("M6").value = Number(k) + 1;//居住人口数
}
//保存表格
await workbook.xlsx.writeFile(
@ -259,63 +292,73 @@ function sortData(data, callback) {
sorted_data[room["栋"] +"-" +room["单元"] +"-" +room["楼层"] +"-" +room["房号"]]=sorted_room_data;
}
} else if (process.env.TABLE_APP == "seatable") {
var house = {};//住房信息缓存
var house_columns = {} //住房信息表头缓存
var population = {};//人口信息缓存
var population_columns = {};//人口信息表头缓存
//console.log(data);
for (var i of Object.keys(data)) {
if(data[i]['name']=='人口信息'){
population = {};
population_columns = {};
//console.log(data[i]['columns'].length);
//创建替换表头的一对一键值
for(var col of Object.keys(data[i]['columns'])){
population_columns[data[i]['columns'][col].key] = data[i]['columns'][col]['name']
}
//每条数据/人
for(var pr of Object.keys(data[i]['rows'])){
//tranKey(data[i]['rows'][pr],population_columns,function(data){
//console.log(data)
//})
//console.log(data[i]['rows'][pr])
//console.log(data[i]['columns'])
newObj = {};
Object.keys(data[i]['rows'][pr]).forEach(item=>{
// 拿到rule中的key
Object.keys(data[i]['columns']).forEach(ele=>{
// 当两个key中的某一项值相同时,创建一个新的键值对。
if(item==data[i]['columns'][ele]['key']){
//console.log(ele)
newObj[data[i]['columns'][ele]['name']]=data[i]['rows'][pr][item]
//data[i]['columns'][ele]['key']
}else{
//TODO:替换没有写
//console.log(item)
//console.log(data[i]['columns'][ele]['key'])
}
})
var house = data['house'];//住房信息缓存
var population = data['population'];//人口信息缓存
//console.log(population)
//console.log(response);
Object.keys(house).forEach((houseKey)=>{
room = house[houseKey];
sorted_room_data = {
'building' :room['栋'],
'unit' :room['单元'],
'floor' :room['楼层'],
'room_no' :room['房号'],
'owner_name' :room['产权人姓名'],
'property_number' :room['产权证号']?room['产权证号']:null,
'owner_phone' :room['产权人电话']?room['产权人电话']:null,
'area' :room['面积']?room['面积']:0,
'housing_type' :room['房屋类型']?room['房屋类型']:null,
'housing_use' :room['房屋用途']?room['房屋用途']:null,
'emergency_name' :room['独居老人紧急联系人姓名']?room['独居老人紧急联系人姓名']:null,
'emergency_phone' :room['独居老人紧急联系人电话']?room['独居老人紧急联系人电话']:null,
'people' :Array(),
};
//console.log(room);
if(room['居住人口']){
Object.keys(room['居住人口']).forEach((popKey)=>{
//console.log(room['居住人口'][popKey])
Object.keys(population).forEach((pkey)=>{
if(room['居住人口'][popKey]['row_id']==population[pkey]['_id']){
people=population[pkey]
//console.log(people)
sorted_room_data['people'][popKey]={
'building' :people['栋']?people['栋']:null,
'unit' :people['单元']?people['单元']:null,
'floor' :people['楼层']?people['楼层']:null,
'room_no' :people['房号']?people['房号']:null,
'name' :people['姓名']?people['姓名']:null,
'id_card' :people['身份证号']?people['身份证号']:null,
'id_verification' :people['身份证校验']?people['身份证校验']:null,
'phone' :people['手机号']?people['手机号']:null,
'residence_address':people['户口所在地']?people['户口所在地']:null,
'urban_identification':people['户口类型']?people['户口类型']:null,
'ethnicity' :people['民族']?people['民族']:null,
'marriage' :people['婚姻状况']?people['婚姻状况']:null,
'political_appearance':people['政治面貌']?people['政治面貌']:null,
'education' :people['学历']?people['学历']:null,
'religious' :people['宗教信仰']?people['宗教信仰']:null,
'occupation' :people['职业类型']?people['职业类型']:null,
'consistency' :people['人户一致']?people['人户一致']:null,
'household_relationship':people['与户主关系']?people['与户主关系']:null,
'migration' :people['流动人口']?people['流动人口']:null,
'inflow_reason' :people['流入原因']?people['流入原因']:null,
'license_type' :people['办证类型']?people['办证类型']:null,
'license_number' :people['证件号码']?people['证件号码']:null,
'registration_date':people['登记日期']?people['登记日期']:null,
'license_expiration_date':people['证件到期日期']?people['证件到期日期']:null,
'residence_type' :people['住所类型']?people['住所类型']:null,
'key_populations' :people['重点关注人员']?people['重点关注人员']:null,
'create_time' :people['_ctime:'],
'update_time' :people['_mtime'],
}
}
//console.log(population[pkey]['_id'])
})
console.log(newObj);
/*
population_single = {};
for(var pro of Object.keys(data[i]['rows'][pr])){
population_single[population_columns[pro]]= data[i]['rows'][pr][pro]
}
console.log(population_columns)
console.log(population_single)
console.log(data[i]['rows'][pr])
*/
}
}else if(data[i]['name']=='住房、产权信息'){
house=data[i];
house_columns=data[i]['columns'];
})
}
}
//console.log(population_columns)
sorted_data[room["栋"] +"-" +room["单元"] +"-" +room["楼层"] +"-" +room["房号"]]=sorted_room_data;
//console.log(sorted_data)
})
}
callback(sorted_data);
}