|
|
@ -6,11 +6,11 @@ const moment = require("moment"); |
|
|
|
function getPlanCount(startTime,endTime,frequencyUnit){ |
|
|
|
switch(frequencyUnit){ |
|
|
|
case '天': |
|
|
|
return Math.ceil(moment(startTime).diff(endTime, 'days')) |
|
|
|
return Math.ceil(moment(endTime).diff(startTime, 'days')) |
|
|
|
case '周': |
|
|
|
return Math.ceil(moment(startTime).diff(endTime, 'weeks')) |
|
|
|
return Math.ceil(moment(endTime).diff(startTime, 'weeks')) |
|
|
|
case '月': |
|
|
|
return Math.ceil(moment(startTime).diff(endTime, 'months')) |
|
|
|
return Math.ceil(moment(endTime).diff(startTime, 'months')) |
|
|
|
default: |
|
|
|
break |
|
|
|
} |
|
|
@ -23,18 +23,17 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
let rslt = { planCount: 0, done: 0,count:0,bCount:0 } |
|
|
|
const models = ctx.fs.dc.models |
|
|
|
const { projectId, startTime, endTime } = ctx.query |
|
|
|
|
|
|
|
|
|
|
|
let planCount=0 |
|
|
|
const plan = await models.PatrolPlan.findAll({ |
|
|
|
where: { |
|
|
|
structureId: { $in: projectId.split(',') }, |
|
|
|
$or: [{ |
|
|
|
startTime: { $lte: startTime }, |
|
|
|
endTime: { $gte: endTime } |
|
|
|
startTime: { $lte: moment(startTime).format('YYYY-MM-DD HH:mm:ss') }, |
|
|
|
endTime: { $gte: moment(endTime).format('YYYY-MM-DD HH:mm:ss') } |
|
|
|
}, |
|
|
|
{ |
|
|
|
startTime: { $gt: startTime }, |
|
|
|
endTime: { $lt: endTime } |
|
|
|
startTime: { $gt: moment(startTime).format('YYYY-MM-DD HH:mm:ss') }, |
|
|
|
endTime: { $lt: moment(endTime).format('YYYY-MM-DD HH:mm:ss')} |
|
|
|
}, |
|
|
|
{ |
|
|
|
startTime: { $between: [startTime, endTime] }, |
|
|
@ -60,6 +59,7 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
patrolPlanId: c.id |
|
|
|
} |
|
|
|
}) |
|
|
|
planCount=getPlanCount(startTime,endTime,frequencyUnit) |
|
|
|
|
|
|
|
} else if (moment(c.startTime).isSameOrAfter(moment(startTime)) && moment(c.startTime).isSameOrBefore(moment(endTime))) { |
|
|
|
done = await models.PatrolRecord.count({ |
|
|
@ -68,6 +68,8 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
patrolPlanId: c.id |
|
|
|
} |
|
|
|
}) |
|
|
|
planCount=getPlanCount(c.startTime,c.endTime,frequencyUnit) |
|
|
|
|
|
|
|
} else if (moment(c.endTime).isSameOrAfter(moment(startTime)) && moment(c.endTime).isSameOrBefore(moment(endTime))) { |
|
|
|
done = await models.PatrolRecord.count({ |
|
|
|
where: { |
|
|
@ -75,6 +77,7 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
patrolPlanId: c.id |
|
|
|
} |
|
|
|
}) |
|
|
|
planCount=getPlanCount(c.startTime,endTime,frequencyUnit) |
|
|
|
} else if (moment(c.startTime).isAfter(moment(startTime)) && moment(c.endTime).isBefore(moment(endTime))) { |
|
|
|
done = await models.PatrolRecord.count({ |
|
|
|
where: { |
|
|
@ -82,6 +85,7 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
patrolPlanId: c.id |
|
|
|
} |
|
|
|
}) |
|
|
|
planCount=getPlanCount(startTime,c.endTime,frequencyUnit) |
|
|
|
} |
|
|
|
let dones = await models.PatrolRecord.count({ |
|
|
|
where: { |
|
|
@ -94,9 +98,9 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
count(case when prih.state!=6 then 1 end) as count, |
|
|
|
count(case when prih.state=6 then 1 end) as bCount |
|
|
|
from project p |
|
|
|
left join patrol_record pr |
|
|
|
inner join patrol_record pr |
|
|
|
on p.id = pr.project_id |
|
|
|
left join patrol_record_issue_handle prih |
|
|
|
inner join patrol_record_issue_handle prih |
|
|
|
on pr.id = prih.patrol_record_id |
|
|
|
and prih.create_time |
|
|
|
between '${startTime}' |
|
|
@ -105,11 +109,10 @@ async function findPatrolRecords(ctx, next) { |
|
|
|
group by p.name |
|
|
|
|
|
|
|
`)
|
|
|
|
const planCount=getPlanCount(c.startTime,c.endTime,frequencyUnit) |
|
|
|
rslt.planCount += frequencyNum * points * planCount- done |
|
|
|
rslt.done += dones |
|
|
|
rslt.bCount+=result[0][0].bCount |
|
|
|
rslt.count=result[0][0].count |
|
|
|
rslt.bCount+=result[0][0]?Number(result[0][0].bcount):0 |
|
|
|
rslt.count=result[0][0]?Number(result[0][0].count):0 |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -228,9 +231,9 @@ async function devicesGuarantee(ctx) { |
|
|
|
const rs = await sequelize.query(` |
|
|
|
SELECT d.type, COUNT(d.id) as count |
|
|
|
FROM device d |
|
|
|
LEFT JOIN point_device pd |
|
|
|
inner JOIN point_device pd |
|
|
|
ON d.id = pd.device_id |
|
|
|
LEFT JOIN point p |
|
|
|
inner JOIN point p |
|
|
|
ON pd.point_id = p.id |
|
|
|
WHERE p.project_id IN (${projectId}) |
|
|
|
GROUP by d.type`)
|
|
|
@ -256,9 +259,9 @@ async function getHistoricalFaults(ctx) { |
|
|
|
count(1) as count, |
|
|
|
count(case when prih.state=6 then 1 end) as bCount |
|
|
|
from project p |
|
|
|
left join patrol_record pr |
|
|
|
inner join patrol_record pr |
|
|
|
on p.id = pr.project_id |
|
|
|
left join patrol_record_issue_handle prih |
|
|
|
inner join patrol_record_issue_handle prih |
|
|
|
on pr.id = prih.patrol_record_id |
|
|
|
and prih.create_time |
|
|
|
between '${startTime}' |
|
|
@ -342,9 +345,9 @@ async function getCenterData(ctx) { |
|
|
|
count(1) as count, |
|
|
|
count(case when prih.state=6 then 1 end) as bCount |
|
|
|
from project p |
|
|
|
left join patrol_record pr |
|
|
|
inner join patrol_record pr |
|
|
|
on p.id = pr.project_id |
|
|
|
left join patrol_record_issue_handle prih |
|
|
|
inner join patrol_record_issue_handle prih |
|
|
|
on pr.id = prih.patrol_record_id |
|
|
|
where p.id in (${projectId}) |
|
|
|
`)
|
|
|
@ -364,7 +367,7 @@ async function getCenterData(ctx) { |
|
|
|
|
|
|
|
rslt.deviceCount=res.length |
|
|
|
rslt.questions=rs[0][0]?Number(rs[0][0].count):0 |
|
|
|
rslt.handleCount=rs[0][0]?Number(rs[0][0].count):0 |
|
|
|
rslt.handleCount=rs[0][0]?Number(rs[0][0].bcount):0 |
|
|
|
rslt.records=record |
|
|
|
rslt.reportCount=reportCount |
|
|
|
ctx.body = rslt |
|
|
|