diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index d82da15e..eaa8220c 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -14,7 +14,7 @@ }, "args": [ "-p 14000", - "-f http://localhost:4000", + "-f http://localhost:14000", "-g postgres://postgres:123@10.8.30.32:5432/highways4good", "--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5", "--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa", diff --git a/api/app/lib/controllers/roadMaintenance/index.js b/api/app/lib/controllers/roadMaintenance/index.js new file mode 100644 index 00000000..fcb1720e --- /dev/null +++ b/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, +} \ No newline at end of file diff --git a/api/app/lib/models/road_maintenance.js b/api/app/lib/models/road_maintenance.js new file mode 100644 index 00000000..f960c576 --- /dev/null +++ b/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; +}; \ No newline at end of file diff --git a/api/app/lib/models/road_maintenance_cost.js b/api/app/lib/models/road_maintenance_cost.js new file mode 100644 index 00000000..a17a1612 --- /dev/null +++ b/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; +}; \ No newline at end of file diff --git a/api/app/lib/routes/roadMaintenance/index.js b/api/app/lib/routes/roadMaintenance/index.js new file mode 100644 index 00000000..dfd9e7e7 --- /dev/null +++ b/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); + +} \ No newline at end of file diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx b/scripts/0.0.1/data/工具脚本(无需执行)/data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx new file mode 100644 index 00000000..779bf870 Binary files /dev/null and b/scripts/0.0.1/data/工具脚本(无需执行)/data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx differ diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/dataIn.js b/scripts/0.0.1/data/工具脚本(无需执行)/dataIn.js index 9e5c422c..662e6e6f 100644 --- a/scripts/0.0.1/data/工具脚本(无需执行)/dataIn.js +++ b/scripts/0.0.1/data/工具脚本(无需执行)/dataIn.js @@ -12,8 +12,8 @@ try { const pool = new Pool({ user: 'postgres', host: '10.8.30.32', - // database: 'highways4good', - database: 'highways4good_initd', + database: 'highways4good', + // database: 'highways4good_initd', password: '123', port: 5432, }) @@ -26,6 +26,11 @@ try { await client.query('BEGIN') const fileList = [ + // { + // path: ['./data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx'], + // n: '养护', + // tableName: 'road_maintenance', + // }, // { // path: ['./data/道路/村道第三方.xls'], // n: '道路', @@ -139,14 +144,16 @@ try { let worksheet = workbook.Sheets[firstSheetName]; let res = XLSX.utils.sheet_to_json(worksheet); const keyMap = require(`./${f.n}_数据库表对应.json`); - console.log(keyMap); + console.log("keyMap:", keyMap); for (let d of res) { let insertStr = `INSERT INTO "${f.tableName}" (`; let insertKeys = (f.defaultKey || []).concat([]); let insertValues = (f.defaultValue || []).concat([]); + for (let k in keyMap) { // 没做判重 let v = d[k]; + console.log(v) if (v) { insertKeys.push(keyMap[k]); diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/index.js b/scripts/0.0.1/data/工具脚本(无需执行)/index.js index f4cf143f..7897c188 100644 --- a/scripts/0.0.1/data/工具脚本(无需执行)/index.js +++ b/scripts/0.0.1/data/工具脚本(无需执行)/index.js @@ -63,6 +63,11 @@ try { // 有手动更改 不要轻易再次执行脚本 const fileList = [ + // { + // path: './data/养护/南昌县农村公路各管养责任单位管养汇总表.xlsx', + // n: '养护', + // tableName: 'road_maintenance' + // }, // { // path: './data/道路/县道第三方.xls', // n: '道路', diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/养护_字段对应.json b/scripts/0.0.1/data/工具脚本(无需执行)/养护_字段对应.json new file mode 100644 index 00000000..17d39172 --- /dev/null +++ b/scripts/0.0.1/data/工具脚本(无需执行)/养护_字段对应.json @@ -0,0 +1,21 @@ +{"序号" : "serialNumber", + + "管养责任单位" : "responsibleUnitForManagementAndMaintenance", + + "养护单位" : "maintenanceUnit", + + "管理人员" : "management", + + "工人" : "worker", + + "公益岗位" : "publicWelfarePost", + + "县道" : "countyHighway", + + "乡道 " : "townshipRoad", + + "村道" : "villageRoad", + + "桥梁 " : "bridge" + + } \ No newline at end of file diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据字段对应.json b/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据字段对应.json new file mode 100644 index 00000000..4f995388 --- /dev/null +++ b/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据字段对应.json @@ -0,0 +1,21 @@ +{ "serialNumber":"序号", + + "responsibleUnitForManagementAndMaintenance":"管养责任单位", + + "maintenanceUnit":"养护单位", + + "management":"管理人员", + + "worker":"工人", + + "publicWelfarePost":"公益岗位", + + "countyHighway":"县道", + + "townshipRoad":"乡道 ", + + "villageRoad":"村道", + + "bridge":"桥梁 " + + } \ No newline at end of file diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据库表对应.json b/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据库表对应.json new file mode 100644 index 00000000..2891d624 --- /dev/null +++ b/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" + + } \ No newline at end of file diff --git a/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据脚本对应.sql b/scripts/0.0.1/data/工具脚本(无需执行)/养护_数据脚本对应.sql new file mode 100644 index 00000000..0aef952d --- /dev/null +++ b/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 '桥梁 '; + \ No newline at end of file