Browse Source

(*)抽取公里数提交

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

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

@ -657,6 +657,7 @@ async function roadSpotPrepare (ctx) {
spotRoadIds.push(r.id) spotRoadIds.push(r.id)
accumulationMileage += parseFloat(r.chainage_mileage) accumulationMileage += parseFloat(r.chainage_mileage)
if (accumulationMileage >= targetMileage) { if (accumulationMileage >= targetMileage) {
break; break;
} }
} }
@ -684,13 +685,17 @@ async function roadSpotPrepare (ctx) {
await filterRoad(otherWhere, true) await filterRoad(otherWhere, true)
} }
return spotRoadIds return [spotRoadIds, accumulationMileage]
} }
let villageMil = 0, townMil = 0, countryMil = 0;
// 抽县 // 抽县
const countryRoadTotalMileage = await getRoadTotalMileage('县') const countryRoadTotalMileage = await getRoadTotalMileage('县')
const countryRoadNeedMileage = countryRoadTotalMileage * countyPercentage / 100 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(` const allTownCodeRes = await sequelize.query(`
@ -705,15 +710,18 @@ async function roadSpotPrepare (ctx) {
let spotTownRoadIds = [] let spotTownRoadIds = []
let spotVillageRoadIds = [] let spotVillageRoadIds = []
let spotVillageIds = [] let spotVillageIds = []
for await (let t of allTownCodeRes) { for await (let t of allTownCodeRes) {
// 遍历每个乡镇并抽取 // 遍历每个乡镇并抽取
let otherWhere = [`township_code='${t.township_code}'`] let otherWhere = [`township_code='${t.township_code}'`]
const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere) const townRoadTotalMileage = await getRoadTotalMileage('乡', otherWhere)
const townRoadNeedMileage = townRoadTotalMileage * 25 / 100 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_) spotTownRoadIds = spotTownRoadIds.concat(spotTownRoadIds_)
if (townMil_) townMil += townMil_
// 抽村 // 抽村
const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere) const villageRoadTotalMileage = await getRoadTotalMileage('村', otherWhere)
const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100 const villageRoadNeedMileage = villageRoadTotalMileage * 10 / 100
@ -755,8 +763,11 @@ async function roadSpotPrepare (ctx) {
villageCheckIdList.unshift(spotFirstVillageId) villageCheckIdList.unshift(spotFirstVillageId)
villageCheckIdList = [...(new Set(villageCheckIdList))] 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_) spotVillageRoadIds = spotVillageRoadIds.concat(spotVillageRoadIds_)
if (villageMil_) villageMil += villageMil_
} }
const previewRes = await models.RoadSpotCheckPreview.create({ const previewRes = await models.RoadSpotCheckPreview.create({
@ -766,7 +777,10 @@ async function roadSpotPrepare (ctx) {
townshipRoadId: spotTownRoadIds, townshipRoadId: spotTownRoadIds,
villageRoadId: spotVillageRoadIds, villageRoadId: spotVillageRoadIds,
villageId: spotVillageIds, villageId: spotVillageIds,
checked: false checked: false,
villageMil,
townMil,
countryMil
}) })
ctx.status = 200; ctx.status = 200;
@ -775,6 +789,10 @@ async function roadSpotPrepare (ctx) {
spotCountyRoadCount: spotCountyRoadIds.length, spotCountyRoadCount: spotCountyRoadIds.length,
spotTownRoadCount: spotTownRoadIds.length, spotTownRoadCount: spotTownRoadIds.length,
spotVillageRoadCount: spotVillageRoadIds.length, spotVillageRoadCount: spotVillageRoadIds.length,
villageMil,
townMil,
countryMil
} }
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);

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

@ -77,6 +77,33 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "village_id", field: "village_id",
autoIncrement: false 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", tableName: "road_spot_check_preview",

Loading…
Cancel
Save