政务数据资源中心(Government data Resource center) 03专项3期主要建设内容
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

142 lines
4.8 KiB

'use strict';
function getPersonAge(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
let errMsg = { message: '获取租户年龄分布失败' }
try {
let age17 = 0, age18 = 0, age29 = 0, age41 = 0, age66 = 0, age85 = 0
// 17岁以下 18-28岁 29-40岁 41-65岁 66-85岁 85岁以上
age17 = await models.AffordableHousing.count({ where: { houseStatus: false, personAge: { $lte: 17 } } });
age18 = await models.AffordableHousing.count({ where: { houseStatus: false, personAge: { $between: [18, 28] } } });
age29 = await models.AffordableHousing.count({ where: { houseStatus: false, personAge: { $between: [29, 40] } } });
age41 = await models.AffordableHousing.count({ where: { houseStatus: false, personAge: { $between: [41, 65] } } });
age66 = await models.AffordableHousing.count({ where: { houseStatus: false, personAge: { $between: [66, 85] } } });
age85 = await models.AffordableHousing.count({ where: { houseStatus: false, personAge: { $gte: 86 } } });
ctx.status = 200;
ctx.body = {
age17, age18, age29, age41, age66, age85
};
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = errMsg
}
}
}
function getHomePerson(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
let errMsg = { message: '获取租户家庭人口统计失败' }
try {
const home = await models.AffordableHousing.count({
attributes: [
'house_id', // 分组的字段
],
group: ['house_id'], // 分组的字段
where: {
houseStatus: false
}
});
ctx.status = 200;
ctx.body = {
home
};
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = errMsg
}
}
}
function getHomeInfo(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
let errMsg = { message: '获取社区房屋统计信息' }
try {
let communitys = await models.AffordableHousing.findAll({
attributes: [
'houseCommunity', // 分组的字段
],
group: ['houseCommunity'], // 分组的字段
where: {
houseStatus: false
}
});
let communityInUse = []
for (let i = 0; i < communitys.length; i++) {
let arr = await models.AffordableHousing.findAll({
attributes: [
'house_id', // 分组的字段
],
group: ['house_id'], // 分组的字段
where: {
houseStatus: false,
houseCommunity: communitys[i].houseCommunity
}
})
communityInUse.push({
"houseCommunity": communitys[i].houseCommunity,
"count": arr.length
})
}
//安社区分类-社区空置套数
let communityUnUse = await models.AffordableHousing.count({
attributes: [
'houseCommunity', // 分组的字段
],
group: ['houseCommunity'], // 分组的字段
where: {
houseStatus: true
}
});
//租赁套数
let inuse = 0;
let useHomes = await models.AffordableHousing.count({
attributes: [
'house_id', // 分组的字段
],
group: ['house_id'], // 分组的字段
where: {
houseStatus: false
}
});
inuse = useHomes.length;
//空置套数
const unuse = await models.AffordableHousing.count({
where: {
houseStatus: true
}
});
ctx.status = 200;
ctx.body = {
inuse: inuse, //租赁中套数
unuse: unuse, //空置套数
communityInUse,
communityUnUse
};
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = errMsg
}
}
}
module.exports = {
getPersonAge,
getHomePerson,
getHomeInfo
}