Browse Source

(*)抽取公里数提交

dev
peng.peng 1 year ago
parent
commit
e78e608fe6
  1. 74
      api/app/lib/controllers/report/index.js
  2. 27
      api/app/lib/models/road_spot_check_preview.js

74
api/app/lib/controllers/report/index.js

@ -3,7 +3,7 @@ const { QueryTypes } = require('sequelize');
const moment = require('moment');
const xlsxDownload = require('../../../../utils/xlsxDownload.js');
const fs = require('fs');
async function reportList (ctx) {
async function reportList(ctx) {
try {
const models = ctx.fs.dc.models;
const { limit, page, startTime, endTime, keyword, userId, reportType, isTop, asc, projectType, handleState = '', performerId = '', codeRoad } = ctx.query
@ -149,7 +149,7 @@ async function reportList (ctx) {
}
}
async function reportPosition (ctx) {
async function reportPosition(ctx) {
try {
const models = ctx.fs.dc.models;
const { startTime, endTime, userId, reportType } = ctx.query
@ -199,7 +199,7 @@ async function reportPosition (ctx) {
}
}
async function reportDetail (ctx) {
async function reportDetail(ctx) {
try {
const models = ctx.fs.dc.models;
const { reportId } = ctx.params
@ -228,7 +228,7 @@ async function reportDetail (ctx) {
}
}
async function reportHandle (ctx) {
async function reportHandle(ctx) {
try {
const { models } = ctx.fs.dc;
@ -258,7 +258,7 @@ async function reportHandle (ctx) {
}
}
async function createReport (ctx) {
async function createReport(ctx) {
try {
const { userId } = ctx.fs.api
const models = ctx.fs.dc.models;
@ -280,7 +280,7 @@ async function createReport (ctx) {
}
}
async function deleteReport (ctx) {
async function deleteReport(ctx) {
try {
const models = ctx.fs.dc.models;
const { reportId } = ctx.params;
@ -303,7 +303,7 @@ async function deleteReport (ctx) {
// TODO 小程序填写道路名称的时候的道路筛选 是一起都返回 还是不断传关键字搜索返回
async function spotPrepare (ctx) {
async function spotPrepare(ctx) {
try {
const { models } = ctx.fs.dc;
const sequelize = ctx.fs.dc.orm;
@ -375,7 +375,7 @@ async function spotPrepare (ctx) {
}
}
async function spotCheck (ctx) {
async function spotCheck(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc;
@ -477,7 +477,7 @@ async function spotCheck (ctx) {
}
}
}
async function spotCheckDetail (ctx) {
async function spotCheckDetail(ctx) {
const { models } = ctx.fs.dc
const { startTime, endTime } = ctx.query
try {
@ -516,7 +516,7 @@ async function spotCheckDetail (ctx) {
}
async function roadSpotPrepare (ctx) {
async function roadSpotPrepare(ctx) {
try {
const { models } = ctx.fs.dc;
const sequelize = ctx.fs.dc.orm;
@ -594,7 +594,7 @@ async function roadSpotPrepare (ctx) {
'乡': `route_code LIKE 'Y%'`,
'村': `route_code LIKE 'C%'`
}
async function getRoadTotalMileage (key, otherWhere = []) {
async function getRoadTotalMileage(key, otherWhere = []) {
let res = await sequelize.query(`
SELECT
SUM(COALESCE(CAST(chainage_mileage AS DOUBLE PRECISION), 0)) AS total_mileage
@ -606,7 +606,7 @@ async function roadSpotPrepare (ctx) {
return res[0][0].total_mileage
}
async function getRoadSpot (key, lastRoadIds = [], inOrNot, otherWhere = []) {
async function getRoadSpot(key, lastRoadIds = [], inOrNot, otherWhere = []) {
if (!lastRoadIds.length && !inOrNot) {
return []
}
@ -625,11 +625,11 @@ async function roadSpotPrepare (ctx) {
`, { type: QueryTypes.SELECT });
}
async function spotRoadId (key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) {
async function spotRoadId(key, lastRoadIds, targetMileage, otherWhere = [], villageIdList = []) {
let spotRoadIds = []
let accumulationMileage = 0
async function filterRoad (otherWhere, getRepeat = true) {
async function filterRoad(otherWhere, getRepeat = true) {
if (key == '村' && getRepeat == true) {
@ -657,6 +657,7 @@ async function roadSpotPrepare (ctx) {
spotRoadIds.push(r.id)
accumulationMileage += parseFloat(r.chainage_mileage)
if (accumulationMileage >= targetMileage) {
break;
}
}
@ -684,13 +685,17 @@ async function roadSpotPrepare (ctx) {
await filterRoad(otherWhere, true)
}
return spotRoadIds
return [spotRoadIds, accumulationMileage]
}
let villageMil = 0, townMil = 0, countryMil = 0;
// 抽县
const countryRoadTotalMileage = await getRoadTotalMileage('县')
const countryRoadNeedMileage = countryRoadTotalMileage * countyPercentage / 100
let spotCountyRoadIds = await spotRoadId('县', lastCountyRoadIds, countryRoadNeedMileage, [])
let spotCountyRoadIdsArr = await spotRoadId('县', lastCountyRoadIds, countryRoadNeedMileage, [])
let spotCountyRoadIds = spotCountyRoadIdsArr[0]
let countryMil_ = spotCountyRoadIdsArr[1]
if (countryMil_) countryMil += countryMil_;
// 抽乡
const allTownCodeRes = await sequelize.query(`
@ -705,15 +710,18 @@ async function roadSpotPrepare (ctx) {
let spotTownRoadIds = []
let spotVillageRoadIds = []
let spotVillageIds = []
for await (let t of allTownCodeRes) {
// 遍历每个乡镇并抽取
let otherWhere = [`township_code='${t.township_code}'`]
const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere)
const townRoadNeedMileage = townRoadTotalMileage * 25 / 100
let spotTownRoadIds_ = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere)
let spotTownRoadIdsArr = await spotRoadId('乡', lastTownRoadIds, townRoadNeedMileage, otherWhere)
let spotTownRoadIds_ = spotTownRoadIdsArr[0]
let townMil_ = spotTownRoadIdsArr[1]
spotTownRoadIds = spotTownRoadIds.concat(spotTownRoadIds_)
if (townMil_) townMil += townMil_
// 抽村
const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere)
const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100
@ -755,8 +763,11 @@ async function roadSpotPrepare (ctx) {
villageCheckIdList.unshift(spotFirstVillageId)
villageCheckIdList = [...(new Set(villageCheckIdList))]
let spotVillageRoadIds_ = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList)
let spotVillageRoadIdsArr = await spotRoadId('村', lastVillageRoadRoadIds, villageRoadNeedMileage, otherWhere, villageCheckIdList)
let spotVillageRoadIds_ = spotVillageRoadIdsArr[0]
let villageMil_ = spotVillageRoadIdsArr[1]
spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_)
if (villageMil_) villageMil += villageMil_
}
const previewRes = await models.RoadSpotCheckPreview.create({
@ -766,7 +777,10 @@ async function roadSpotPrepare (ctx) {
townshipRoadId: spotTownRoadIds,
villageRoadId: spotVillageRoadIds,
villageId: spotVillageIds,
checked: false
checked: false,
villageMil,
townMil,
countryMil
})
ctx.status = 200;
@ -775,6 +789,10 @@ async function roadSpotPrepare (ctx) {
spotCountyRoadCount: spotCountyRoadIds.length,
spotTownRoadCount: spotTownRoadIds.length,
spotVillageRoadCount: spotVillageRoadIds.length,
villageMil,
townMil,
countryMil
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
@ -785,7 +803,7 @@ async function roadSpotPrepare (ctx) {
}
}
async function confirmRoadSpot (ctx) {
async function confirmRoadSpot(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc;
@ -845,7 +863,7 @@ async function confirmRoadSpot (ctx) {
}
}
async function roadSpotList (ctx) {
async function roadSpotList(ctx) {
try {
const { models } = ctx.fs.dc;
const { startTime, endTime, page, limit } = ctx.query
@ -896,7 +914,7 @@ async function roadSpotList (ctx) {
}
}
async function roadSpotDetail (ctx) {
async function roadSpotDetail(ctx) {
try {
const { models } = ctx.fs.dc;
const { previewId, keyword } = ctx.query
@ -933,7 +951,7 @@ async function roadSpotDetail (ctx) {
}
}
async function roadSpotChange (ctx) {
async function roadSpotChange(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc;
@ -955,7 +973,7 @@ async function roadSpotChange (ctx) {
}
let previewUpdated = false
async function updatePreview (key) {
async function updatePreview(key) {
if (previewUpdated) return
if (previewRes[key] && previewRes[key].includes(originRoadId)) {
@ -1040,7 +1058,7 @@ async function roadSpotChange (ctx) {
}
}
async function roadSpotChangList (ctx) {
async function roadSpotChangList(ctx) {
try {
const { models } = ctx.fs.dc;
const { startTime, endTime, page, limit } = ctx.query
@ -1093,7 +1111,7 @@ async function roadSpotChangList (ctx) {
}
}
async function exportSpotRode (ctx) {
async function exportSpotRode(ctx) {
try {
const { models } = ctx.fs.dc;
const { previewId } = ctx.query
@ -1143,7 +1161,7 @@ async function exportSpotRode (ctx) {
title: '养护次数(次)',
},]
function judgeLevel (routeCode) {
function judgeLevel(routeCode) {
if (routeCode) {
if (routeCode.startsWith('X')) {
return '县道'

27
api/app/lib/models/road_spot_check_preview.js

@ -77,6 +77,33 @@ module.exports = dc => {
primaryKey: false,
field: "village_id",
autoIncrement: false
},
villageMil: {
type: DataTypes.DOUBLE,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "village_mil",
autoIncrement: false
},
townMil: {
type: DataTypes.DOUBLE,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "town_mil",
autoIncrement: false
},
countryMil: {
type: DataTypes.DOUBLE,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "country_mil",
autoIncrement: false
}
}, {
tableName: "road_spot_check_preview",

Loading…
Cancel
Save