Browse Source

养护-上月数据查询接口提交

dev
LUCAS 2 years ago
parent
commit
d3bc1cfac9
  1. 2
      api/.vscode/launch.json
  2. 60
      api/app/lib/controllers/roadMaintenance/index.js
  3. 115
      api/app/lib/models/road_maintenance.js
  4. 110
      api/app/lib/models/road_maintenance_cost.js
  5. 13
      api/app/lib/routes/roadMaintenance/index.js
  6. BIN
      scripts/0.0.1/data/工具脚本(无需执行)/data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx
  7. 13
      scripts/0.0.1/data/工具脚本(无需执行)/dataIn.js
  8. 5
      scripts/0.0.1/data/工具脚本(无需执行)/index.js
  9. 21
      scripts/0.0.1/data/工具脚本(无需执行)/养护_字段对应.json
  10. 21
      scripts/0.0.1/data/工具脚本(无需执行)/养护_数据字段对应.json
  11. 21
      scripts/0.0.1/data/工具脚本(无需执行)/养护_数据库表对应.json
  12. 44
      scripts/0.0.1/data/工具脚本(无需执行)/养护_数据脚本对应.sql

2
api/.vscode/launch.json

@ -14,7 +14,7 @@
}, },
"args": [ "args": [
"-p 14000", "-p 14000",
"-f http://localhost:4000", "-f http://localhost:14000",
"-g postgres://postgres:123@10.8.30.32:5432/highways4good", "-g postgres://postgres:123@10.8.30.32:5432/highways4good",
"--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5", "--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5",
"--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa", "--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa",

60
api/app/lib/controllers/roadMaintenance/index.js

@ -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,
}

115
api/app/lib/models/road_maintenance.js

@ -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;
};

110
api/app/lib/models/road_maintenance_cost.js

@ -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;
};

13
api/app/lib/routes/roadMaintenance/index.js

@ -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);
}

BIN
scripts/0.0.1/data/工具脚本(无需执行)/data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx

Binary file not shown.

13
scripts/0.0.1/data/工具脚本(无需执行)/dataIn.js

@ -12,8 +12,8 @@ try {
const pool = new Pool({ const pool = new Pool({
user: 'postgres', user: 'postgres',
host: '10.8.30.32', host: '10.8.30.32',
// database: 'highways4good', database: 'highways4good',
database: 'highways4good_initd', // database: 'highways4good_initd',
password: '123', password: '123',
port: 5432, port: 5432,
}) })
@ -26,6 +26,11 @@ try {
await client.query('BEGIN') await client.query('BEGIN')
const fileList = [ const fileList = [
// {
// path: ['./data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx'],
// n: '养护',
// tableName: 'road_maintenance',
// },
// { // {
// path: ['./data/道路/村道第三方.xls'], // path: ['./data/道路/村道第三方.xls'],
// n: '道路', // n: '道路',
@ -139,14 +144,16 @@ try {
let worksheet = workbook.Sheets[firstSheetName]; let worksheet = workbook.Sheets[firstSheetName];
let res = XLSX.utils.sheet_to_json(worksheet); let res = XLSX.utils.sheet_to_json(worksheet);
const keyMap = require(`./${f.n}_数据库表对应.json`); const keyMap = require(`./${f.n}_数据库表对应.json`);
console.log(keyMap); console.log("keyMap:", keyMap);
for (let d of res) { for (let d of res) {
let insertStr = `INSERT INTO "${f.tableName}" (`; let insertStr = `INSERT INTO "${f.tableName}" (`;
let insertKeys = (f.defaultKey || []).concat([]); let insertKeys = (f.defaultKey || []).concat([]);
let insertValues = (f.defaultValue || []).concat([]); let insertValues = (f.defaultValue || []).concat([]);
for (let k in keyMap) { for (let k in keyMap) {
// 没做判重 // 没做判重
let v = d[k]; let v = d[k];
console.log(v)
if (v) { if (v) {
insertKeys.push(keyMap[k]); insertKeys.push(keyMap[k]);

5
scripts/0.0.1/data/工具脚本(无需执行)/index.js

@ -63,6 +63,11 @@ try {
// 有手动更改 不要轻易再次执行脚本 // 有手动更改 不要轻易再次执行脚本
const fileList = [ const fileList = [
// {
// path: './data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx',
// n: '养护',
// tableName: 'road_maintenance'
// },
// { // {
// path: './data/道路/县道第三方.xls', // path: './data/道路/县道第三方.xls',
// n: '道路', // n: '道路',

21
scripts/0.0.1/data/工具脚本(无需执行)/养护_字段对应.json

@ -0,0 +1,21 @@
{"序号" : "serialNumber",
"管养责任单位" : "responsibleUnitForManagementAndMaintenance",
"养护单位" : "maintenanceUnit",
"管理人员" : "management",
"工人" : "worker",
"公益岗位" : "publicWelfarePost",
"县道" : "countyHighway",
"乡道 " : "townshipRoad",
"村道" : "villageRoad",
"桥梁 " : "bridge"
}

21
scripts/0.0.1/data/工具脚本(无需执行)/养护_数据字段对应.json

@ -0,0 +1,21 @@
{ "serialNumber":"序号",
"responsibleUnitForManagementAndMaintenance":"管养责任单位",
"maintenanceUnit":"养护单位",
"management":"管理人员",
"worker":"工人",
"publicWelfarePost":"公益岗位",
"countyHighway":"县道",
"townshipRoad":"乡道 ",
"villageRoad":"村道",
"bridge":"桥梁 "
}

21
scripts/0.0.1/data/工具脚本(无需执行)/养护_数据库表对应.json

@ -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"
}

44
scripts/0.0.1/data/工具脚本(无需执行)/养护_数据脚本对应.sql

@ -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…
Cancel
Save