LUCAS
2 years ago
12 changed files with 421 additions and 4 deletions
@ -0,0 +1,60 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
'use strict'; |
||||
|
const moment = require('moment'); |
||||
|
const { QueryTypes } = require('sequelize'); |
||||
|
|
||||
|
async function getLastMonthCost(ctx) { |
||||
|
let rslt = []; |
||||
|
try { |
||||
|
const startTime = new Date(moment().startOf('year')), endTime = new Date(moment().endOf('year').valueOf()); |
||||
|
const models = ctx.fs.dc.models; |
||||
|
const costList = await models.RoadMaintenanceCost.findAll({ |
||||
|
where: { |
||||
|
maintenanceDate: { '$between': [startTime, endTime] } |
||||
|
} |
||||
|
}) |
||||
|
if (!costList || !costList.length) { |
||||
|
const dataList = await models.RoadMaintenance.findAll(); |
||||
|
for (var i = 0; i < 12; i++) { |
||||
|
dataList.map(item => { |
||||
|
const { countyHighway, townshipRoad, villageRoad, responsibleUnitForManagementAndMaintenance } = item; |
||||
|
const randomNum = 0.1 * (0.8 + Math.random() / 2); |
||||
|
const dateTime = new Date(moment().month(i)); |
||||
|
|
||||
|
let data = { |
||||
|
countyName: responsibleUnitForManagementAndMaintenance, |
||||
|
roadLengthCounty: countyHighway ? countyHighway * randomNum : 0, |
||||
|
roadLengthTownship: townshipRoad ? townshipRoad * randomNum : 0, |
||||
|
roadLengthVillage: villageRoad ? villageRoad * randomNum : 0, |
||||
|
maintenanceDate: dateTime |
||||
|
} |
||||
|
data.roadCostCounty = data.roadLengthCounty * 15000 / 12, |
||||
|
data.roadCostTownship = data.roadLengthTownship * 7500 / 12, |
||||
|
data.roadCostVillage = data.roadLengthVillage * 3900 / 12; |
||||
|
|
||||
|
rslt.push(data) |
||||
|
|
||||
|
models.RoadMaintenanceCost.create(data) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
rslt = costList |
||||
|
} |
||||
|
|
||||
|
|
||||
|
ctx.status = 200; |
||||
|
ctx.body = rslt; |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: typeof error == 'string' ? error : undefined |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
getLastMonthCost, |
||||
|
} |
@ -0,0 +1,115 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const RoadMaintenance = sequelize.define("roadMaintenance", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: true, |
||||
|
unique: "road_maintenance_id_uindex" |
||||
|
}, |
||||
|
serialNumber: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "序号", |
||||
|
primaryKey: false, |
||||
|
field: "serial_number", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
responsibleUnitForManagementAndMaintenance: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "管养责任单位", |
||||
|
primaryKey: false, |
||||
|
field: "responsible_unit_for_management_and_maintenance", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
maintenanceUnit: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护单位", |
||||
|
primaryKey: false, |
||||
|
field: "maintenance_unit", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
management: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "管理人员", |
||||
|
primaryKey: false, |
||||
|
field: "management", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
worker: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "工人", |
||||
|
primaryKey: false, |
||||
|
field: "worker", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
publicWelfarePost: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "公益岗位", |
||||
|
primaryKey: false, |
||||
|
field: "public_welfare_post", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
countyHighway: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "县道", |
||||
|
primaryKey: false, |
||||
|
field: "county_highway", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
townshipRoad: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "乡道 ", |
||||
|
primaryKey: false, |
||||
|
field: "township_road", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
villageRoad: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "村道", |
||||
|
primaryKey: false, |
||||
|
field: "village_road", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
bridge: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "桥梁 ", |
||||
|
primaryKey: false, |
||||
|
field: "bridge", |
||||
|
autoIncrement: false |
||||
|
} |
||||
|
}, { |
||||
|
tableName: "road_maintenance", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.RoadMaintenance = RoadMaintenance; |
||||
|
return RoadMaintenance; |
||||
|
}; |
@ -0,0 +1,110 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const RoadMaintenanceCost = sequelize.define("roadMaintenanceCost", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: true, |
||||
|
}, |
||||
|
mId: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护id", |
||||
|
primaryKey: false, |
||||
|
field: "mId", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
countyName: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "管养责任单位", |
||||
|
primaryKey: false, |
||||
|
field: "county_name", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
|
||||
|
roadLengthCounty: { |
||||
|
type: DataTypes.FLOAT, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护长度", |
||||
|
primaryKey: false, |
||||
|
field: "road_length_county", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
roadCostCounty: { |
||||
|
type: DataTypes.DOUBLE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护费用", |
||||
|
primaryKey: false, |
||||
|
field: "road_cost_county", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
roadLengthVillage: { |
||||
|
type: DataTypes.FLOAT, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护长度", |
||||
|
primaryKey: false, |
||||
|
field: "road_length_village", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
roadCostVillage: { |
||||
|
type: DataTypes.DOUBLE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护费用", |
||||
|
primaryKey: false, |
||||
|
field: "road_cost_village", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
roadLengthTownship: { |
||||
|
type: DataTypes.FLOAT, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护长度", |
||||
|
primaryKey: false, |
||||
|
field: "road_length_township", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
roadCostTownship: { |
||||
|
type: DataTypes.DOUBLE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护费用", |
||||
|
primaryKey: false, |
||||
|
field: "road_cost_township", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
maintenanceDate: { |
||||
|
type: DataTypes.DATE, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "养护日期", |
||||
|
primaryKey: false, |
||||
|
field: "maintenance_date", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
}, { |
||||
|
tableName: "road_maintenance_cost", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.RoadMaintenanceCost = RoadMaintenanceCost; |
||||
|
return RoadMaintenanceCost; |
||||
|
}; |
@ -0,0 +1,13 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const roadMaintenance = require('../../controllers/roadMaintenance'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
|
||||
|
app.fs.api.logAttr['GET/road/maintenance/cost/query'] = { content: '获取上月道路养护费用', visible: false }; |
||||
|
router.get('/road/maintenance/cost/query', roadMaintenance.getLastMonthCost); |
||||
|
|
||||
|
// app.fs.api.logAttr['GET/road/maintenance/cost/query'] = { content: '获取上月道路养护费用', visible: false };
|
||||
|
// router.get('/road/maintenance/cost/query', roadMaintenance.getLastMonthCost);
|
||||
|
|
||||
|
} |
Binary file not shown.
@ -0,0 +1,21 @@ |
|||||
|
{"序号" : "serialNumber", |
||||
|
|
||||
|
"管养责任单位" : "responsibleUnitForManagementAndMaintenance", |
||||
|
|
||||
|
"养护单位" : "maintenanceUnit", |
||||
|
|
||||
|
"管理人员" : "management", |
||||
|
|
||||
|
"工人" : "worker", |
||||
|
|
||||
|
"公益岗位" : "publicWelfarePost", |
||||
|
|
||||
|
"县道" : "countyHighway", |
||||
|
|
||||
|
"乡道 " : "townshipRoad", |
||||
|
|
||||
|
"村道" : "villageRoad", |
||||
|
|
||||
|
"桥梁 " : "bridge" |
||||
|
|
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
{ "serialNumber":"序号", |
||||
|
|
||||
|
"responsibleUnitForManagementAndMaintenance":"管养责任单位", |
||||
|
|
||||
|
"maintenanceUnit":"养护单位", |
||||
|
|
||||
|
"management":"管理人员", |
||||
|
|
||||
|
"worker":"工人", |
||||
|
|
||||
|
"publicWelfarePost":"公益岗位", |
||||
|
|
||||
|
"countyHighway":"县道", |
||||
|
|
||||
|
"townshipRoad":"乡道 ", |
||||
|
|
||||
|
"villageRoad":"村道", |
||||
|
|
||||
|
"bridge":"桥梁 " |
||||
|
|
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
{"序号" : "serial_number", |
||||
|
|
||||
|
"管养责任单位" : "responsible_unit_for_management_and_maintenance", |
||||
|
|
||||
|
"养护单位" : "maintenance_unit", |
||||
|
|
||||
|
"管理人员" : "management", |
||||
|
|
||||
|
"工人" : "worker", |
||||
|
|
||||
|
"公益岗位" : "public_welfare_post", |
||||
|
|
||||
|
"县道" : "county_Highway", |
||||
|
|
||||
|
"乡道 " : "township_Road", |
||||
|
|
||||
|
"村道" : "village_Road", |
||||
|
|
||||
|
"桥梁 " : "bridge" |
||||
|
|
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
|
||||
|
-- 养护 |
||||
|
create table if not exists "road_maintenance" |
||||
|
( |
||||
|
id serial not null |
||||
|
); |
||||
|
|
||||
|
create unique index if not exists road_maintenance_id_uindex |
||||
|
on road_maintenance (id); |
||||
|
|
||||
|
alter table road_maintenance |
||||
|
add constraint road_maintenance_pk |
||||
|
primary key (id); |
||||
|
|
||||
|
alter table road_maintenance add Serial_Number varchar(1024); |
||||
|
comment on column road_maintenance.Serial_Number is '序号'; |
||||
|
|
||||
|
alter table road_maintenance add Responsible_Unit_For_Management_And_Maintenance varchar(1024); |
||||
|
comment on column road_maintenance.Responsible_Unit_For_Management_And_Maintenance is '管养责任单位'; |
||||
|
|
||||
|
alter table road_maintenance add Maintenance_Unit varchar(1024); |
||||
|
comment on column road_maintenance.Maintenance_Unit is '养护单位'; |
||||
|
|
||||
|
alter table road_maintenance add Management varchar(1024); |
||||
|
comment on column road_maintenance.Management is '管理人员'; |
||||
|
|
||||
|
alter table road_maintenance add Worker varchar(1024); |
||||
|
comment on column road_maintenance.Worker is '工人'; |
||||
|
|
||||
|
alter table road_maintenance add Public_Welfare_Post varchar(1024); |
||||
|
comment on column road_maintenance.Public_Welfare_Post is '公益岗位'; |
||||
|
|
||||
|
alter table road_maintenance add County_Highway varchar(1024); |
||||
|
comment on column road_maintenance.County_Highway is '县道'; |
||||
|
|
||||
|
alter table road_maintenance add Township_Road varchar(1024); |
||||
|
comment on column road_maintenance.Township_Road is '乡道 '; |
||||
|
|
||||
|
alter table road_maintenance add Village_Road varchar(1024); |
||||
|
comment on column road_maintenance.Village_Road is '村道'; |
||||
|
|
||||
|
alter table road_maintenance add Bridge varchar(1024); |
||||
|
comment on column road_maintenance.Bridge is '桥梁 '; |
||||
|
|
Loading…
Reference in new issue