@ -1,5 +1,142 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
module.exports = { |
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 |
||||
|
} |
||||
|
|
||||
|
@ -0,0 +1,151 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
|
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const AffordableHousing = sequelize.define("affordableHousing", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: "序号", |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: true |
||||
|
}, |
||||
|
houseCommunity: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: "小区名称", |
||||
|
primaryKey: false, |
||||
|
field: "house_community", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
houseBuildingNumber: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "栋号", |
||||
|
primaryKey: false, |
||||
|
field: "house_building_number", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
houseUnit: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "单元", |
||||
|
primaryKey: false, |
||||
|
field: "house_unit", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
houseNumber: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "房号", |
||||
|
primaryKey: false, |
||||
|
field: "house_number", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
houseArea: { |
||||
|
type: DataTypes.DOUBLE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "面积", |
||||
|
primaryKey: false, |
||||
|
field: "house_area", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
houseStatus: { |
||||
|
type: DataTypes.BOOLEAN, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "房源状态(是否空置)", |
||||
|
primaryKey: false, |
||||
|
field: "house_status", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
personName: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "租户姓名", |
||||
|
primaryKey: false, |
||||
|
field: "person_name", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
personStatus: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "租户身份", |
||||
|
primaryKey: false, |
||||
|
field: "person_status", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
personId: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "租户身份证号", |
||||
|
primaryKey: false, |
||||
|
field: "person_id", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
personAge: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "租户年龄", |
||||
|
primaryKey: false, |
||||
|
field: "person_age", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
personTownship: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "租户乡镇", |
||||
|
primaryKey: false, |
||||
|
field: "person_township", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
personCommunity: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "租户社区", |
||||
|
primaryKey: false, |
||||
|
field: "person_community", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
partOfCity: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "城市区域(东南西北)", |
||||
|
primaryKey: false, |
||||
|
field: "part_of_city", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
houseId: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "房屋唯一标识", |
||||
|
primaryKey: false, |
||||
|
field: "house_id", |
||||
|
autoIncrement: false |
||||
|
} |
||||
|
}, { |
||||
|
tableName: "affordable_housing", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.AffordableHousing = AffordableHousing; |
||||
|
return AffordableHousing; |
||||
|
}; |
@ -0,0 +1,19 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const community = require('../../controllers/superScreen/community'); |
||||
|
|
||||
|
module.exports = function (app, router, opts, AuthCode) { |
||||
|
|
||||
|
//获取租户家庭人口统计
|
||||
|
app.fs.api.logAttr['GET/home/person'] = { content: '获取租户家庭人口统计', visible: true }; |
||||
|
router.get('/home/person', community.getHomePerson(opts)); |
||||
|
|
||||
|
//获取租户年龄分布
|
||||
|
app.fs.api.logAttr['GET/person/age'] = { content: '获取租户年龄分布', visible: true }; |
||||
|
router.get('/person/age', community.getPersonAge(opts)); |
||||
|
|
||||
|
//获取社区房屋统计信息
|
||||
|
app.fs.api.logAttr['GET/community/info'] = { content: '获取社区房屋统计信息', visible: true }; |
||||
|
router.get('/community/info', community.getHomeInfo(opts)); |
||||
|
|
||||
|
}; |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,8 @@ |
|||||
|
const communtity_data = [ |
||||
|
{ lng: 115.886724, lat: 28.534257, type: 'home', name: '城西幸福庄园', address: '南昌县小蓝经济技术开发区富山三路761号', build: '2013' }, |
||||
|
{ lng: 115.956004, lat: 28.541413, type: 'home', name: '城东幸福庄园', address: '南昌县莲塘镇莲武路529号', build: '2009' }, |
||||
|
{ lng: 115.9335, lat: 28.541146, type: 'home', name: '城南幸福庄园', address: '南昌县莲塘镇莲西路120号', build: '2010' }, |
||||
|
{ lng: 115.91131, lat: 28.525062, type: 'home', name: '小蓝经投公租房', address: '富山五路以南、雄溪路以西', build: '2013' }, |
||||
|
] |
||||
|
|
||||
|
export { communtity_data } |