Browse Source

feat:维护记录中断时长显示bug+服务器维护信息后台逻辑

dev
zhaobing 2 years ago
parent
commit
794123a012
  1. 9
      api/app/lib/controllers/record/index.js
  2. 162
      api/app/lib/controllers/serverInfoMaintenanceRecord/index.js
  3. 25
      script/0.27/schema/create_equipment_maintenance_record.sql
  4. 9
      script/0.27/schema/create_equipment_maintenance_record_execute_user.sql
  5. 9
      script/0.27/schema/create_equipment_maintenance_record_project.sql
  6. 2
      web/client/src/sections/facility/nav-item.jsx
  7. 38
      web/client/src/sections/service/components/recordModal.jsx

9
api/app/lib/controllers/record/index.js

@ -82,12 +82,14 @@ async function addRecord(ctx) {
const transaction = await ctx.fs.dc.orm.transaction(); const transaction = await ctx.fs.dc.orm.transaction();
const { models } = ctx.fs.dc const { models } = ctx.fs.dc
const params = ctx.request.body const params = ctx.request.body
console.log('resss1', ctx.request.body)
const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg } = params const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg } = params
const breakTime = (Date.parse(solvingTime) - Date.parse(occurrencTime)) / 1000
try { try {
//中断时长
//console.log('resss1', Date.parse(solvingTime), occurrencTime)
if (id) { if (id) {
await models.MaintenanceRecord.update({ await models.MaintenanceRecord.update({
solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime
}, { where: { id } }) }, { where: { id } })
await models.MaintenanceRecordExecuteUser.destroy({ where: { maintenanceRecordId: id } }) await models.MaintenanceRecordExecuteUser.destroy({ where: { maintenanceRecordId: id } })
const resArry = settler.map((item) => { const resArry = settler.map((item) => {
@ -97,7 +99,7 @@ async function addRecord(ctx) {
}) })
await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) await models.MaintenanceRecordExecuteUser.bulkCreate(resArry)
} else { } else {
const aa = await models.MaintenanceRecord.create({ solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type }) const aa = await models.MaintenanceRecord.create({ solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime })
const recordId = aa.id const recordId = aa.id
const resArry = settler.map((item) => { const resArry = settler.map((item) => {
return { return {
@ -112,7 +114,6 @@ async function addRecord(ctx) {
ctx.status = 200 ctx.status = 200
} catch (error) { } catch (error) {
await transaction.rollback(); await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {

162
api/app/lib/controllers/serverInfoMaintenanceRecord/index.js

@ -0,0 +1,162 @@
'use strict';
const moment = require('moment');
//请求数据
async function getServerInfoMaintenanceRecord(ctx) {
const { clickHouse } = ctx.app.fs
try {
const query = ctx.query
//console.log('query2', query)
const { startTime, endTime, pageIndex, pageSize } = query
//console.log('res67', startTime.length)
const { models } = ctx.fs.dc
let whereOption = {}
if (startTime.length > 0 && endTime.length > 0) {
whereOption = { maintenanceStartTime: { $between: [moment(startTime).format('YYYY-MM-DD HH:mm:ss'), moment(endTime).format('YYYY-MM-DD HH:mm:ss')] } }
} else {
whereOption = {}
}
let resCount = await models.ServerMaintenanceRecord.count({
where: whereOption
})
let res = await models.ServerMaintenanceRecord.findAndCount({
order: [['id', 'DESC']],
attributes: ['id', 'sketch', 'reason', 'remark', 'maintenanceStartTime', 'maintenanceFinishTime', 'state'],
offset: (pageIndex - 1) * pageSize,
limit: pageSize,
where: whereOption,
include: [{
attributes: ['id', 'serverMaintenanceRecordId', 'pepUserId'],
model: models.ServerMaintenanceRecordRepairman
}]
})
//console.log('res', res)
const arrayUserId = []
res.rows.forEach((item) => { item.serverMaintenanceRecordRepairmans.forEach((item1) => { arrayUserId.push(item1.pepUserId) }) })
let userRes = []
if (arrayUserId.length > 0) {
const arrayUserIdCopy = [...new Set(arrayUserId)]
// console.log(arrayUserIdCopy, 'arrayUserIdCopy')
userRes = await clickHouse.pepEmis.query(`
SELECT * FROM user
WHERE id IN (${[...arrayUserIdCopy].join(',')},-1)`).toPromise()
//ctx.body = { count: resCount, res }
//console.log('userRes', userRes)
} else {
const arrayUserIdCopy = [...new Set(arrayUserId)]
//console.log(arrayUserIdCopy, 'arrayUserIdCopy')
userRes = await clickHouse.pepEmis.query(`
SELECT * FROM user
WHERE id IN (-1)`).toPromise()
}
const responseRes = res.rows.map((item) => {
return {
id: item.id,
sketch: item.sketch,
reason: item.reason,
remark: item.remark,
maintenanceStartTime: item.maintenanceStartTime,
maintenanceFinishTime: item.maintenanceFinishTime,
state: item.state,
serverMaintenanceRecordRepairmans:
item.serverMaintenanceRecordRepairmans.map((item1) => {
const nameArr = userRes.find((ac) => { return ac.id == item1.pepUserId })
return {
id: item1.id,
serverMaintenanceRecordId: item1.serverMaintenanceRecordId,
pepUserId: item1.pepUserId,
name: nameArr ? nameArr.name : ''
}
})
}
})
ctx.body = { count: resCount, responseRes }
ctx.status = 200
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
ctx.status = 400
ctx.body = {
message: `获取服务器信息维护记录失败`
}
}
}
//编辑或者新增
async function editServerInfoMaintenanceRecord(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
const payload = ctx.request.body//前端传过来的参数
const { models } = ctx.fs.dc
const { id, msg, maintenanceFinishTime, maintenanceStartTime, reason, remark, sketch, state, repairman } = payload
try {
if (id) {
//更新记录表
await models.ServerMaintenanceRecord.update({
maintenanceFinishTime, maintenanceStartTime, reason, remark, sketch, state,
}, { where: { id } })
//删除相关的维修人
await models.ServerMaintenanceRecordRepairman.destroy({ where: { serverMaintenanceRecordId: id } })
//重新创建相关的维修人
const insertUserVal = repairman.map((item) => {
return { serverMaintenanceRecordId: id, pepUserId: item }
})
await models.ServerMaintenanceRecordRepairman.bulkCreate(insertUserVal)
await transaction.commit();
ctx.status = 204
} else {
//没有传id,直接创建记录和相关的维修人
const res = await models.ServerMaintenanceRecord.create({
maintenanceFinishTime, maintenanceStartTime, reason, remark, sketch, state
})
if (repairman) {
const insertUserVal = repairman.map((item) => {
return {
serverMaintenanceRecordId: res.id, pepUserId: item
}
})
await models.ServerMaintenanceRecordRepairman.bulkCreate(insertUserVal)
}
await transaction.commit();
ctx.status = 204
}
} catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
ctx.status = 400
ctx.body = {
message: `${msg}失败`
}
}
}
//根据id删除
async function delServerInfoMaintenanceRecord(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc
const params = ctx.params//接收前端传过来的id
//console.log('params1', params)
await models.ServerMaintenanceRecordRepairman.destroy({ where: { serverMaintenanceRecordId: params.id } })
await models.ServerMaintenanceRecord.destroy({ where: { id: params.id } })
await transaction.commit();
ctx.status = 204
}
catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
ctx.status = 400
ctx.body = {
message: `删除服务器信息维护记录失败`
}
}
}
module.exports = {
getServerInfoMaintenanceRecord, editServerInfoMaintenanceRecord, delServerInfoMaintenanceRecord
};

25
script/0.27/schema/create_equipment_maintenance_record.sql

@ -0,0 +1,25 @@
create table equipment_maintenance_record
(
id serial
primary key,
equipment_type varchar(32),
equipment_category varchar(32),
maintenance_reason varchar(1024),
solution varchar(1024),
report_time timestamp with time zone,
completed_time timestamp with time zone,
status varchar(32)
);
comment on column public.equipment_maintenance_record.equipment_type is '设备型号';
comment on column public.equipment_maintenance_record.equipment_category is '设备类型';
comment on column public.equipment_maintenance_record.maintenance_reason is '维修原因';
comment on column public.equipment_maintenance_record.solution is '解决方案';
comment on column public.equipment_maintenance_record.report_time is '上报时间';
comment on column public.equipment_maintenance_record.completed_time is '维修完成时间';
comment on column public.equipment_maintenance_record.status is '状态';

9
script/0.27/schema/create_equipment_maintenance_record_execute_user.sql

@ -0,0 +1,9 @@
create table equipment_maintenance_record_execute_user
(
id serial
primary key,
equipment_maintenance_record_id integer
constraint equipment_maintenance_record_equipment_maintenance_record_fkey1
references equipment_maintenance_record,
pep_user_id integer
);

9
script/0.27/schema/create_equipment_maintenance_record_project.sql

@ -0,0 +1,9 @@
create table equipment_maintenance_record_project
(
id serial
primary key,
equipment_maintenance_record_id integer
constraint equipment_maintenance_record__equipment_maintenance_record_fkey
references equipment_maintenance_record,
project_id integer
);

2
web/client/src/sections/facility/nav-item.jsx

@ -6,7 +6,7 @@ export function getNavItem (user, dispatch) {
[ [
{ {
itemKey: 'facility', itemKey: 'facility',
text: '设备', text: '服务器',
icon: <IconCode />, icon: <IconCode />,
items: [ items: [
// { // {

38
web/client/src/sections/service/components/recordModal.jsx

@ -11,13 +11,15 @@ const RecordModal =(props)=>{
const [endTime,setEndTime]=useState('') const [endTime,setEndTime]=useState('')
const FormApi = useRef(); const FormApi = useRef();
const{service} =actions const{service} =actions
const tdd=parseInt((endTime-startTime)/1000/60/60/24)// // let t=0//
const tdh=parseInt((endTime-startTime)/1000/60/60%24)// // let h=0//
const tds=parseInt((endTime-startTime)/1000/60%60)// // let s=0//
// console.log('endTimex',endTime) // console.log('endTimex',endTime)
useEffect(()=>{ useEffect(()=>{
setEndTime(recordRow?.solvingTime) setEndTime(recordRow?.solvingTime)
setStartTime(recordRow?.occurrenceTime)
console.log('recordRow',recordRow) console.log('recordRow',recordRow)
},[recordRow]) },[recordRow])
const cancelHandler=()=>{ const cancelHandler=()=>{
onClose() onClose()
@ -60,8 +62,16 @@ const okHandler=()=>{
onOk={okHandler} onOk={okHandler}
> >
<Form wrapperCol={{ span: 20 }} <Form wrapperCol={{ span: 20 }}
initValues={{'name':recordRow?.sketch,'startTime':recordRow?.occurrenceTime, initValues={{'name':recordRow?.sketch,
'endTime':recordRow?.solvingTime,'settler':recordRow?.maintenanceRecordExecuteUsers.map((item)=>{return item.pepUserId}),'type':recordRow?.type,'record':recordRow?.record}} 'startTime':recordRow?.occurrenceTime,
'endTime':recordRow?.solvingTime,
'settler':recordRow?.maintenanceRecordExecuteUsers.map((item)=>{return item.pepUserId}),
'type':recordRow?.type,
'record':recordRow?.record,
'breakTime':recordRow?parseInt(recordRow.interruptDuration/60/60/24)+'天'+
parseInt(recordRow.interruptDuration/60/60%24)+'时'+
parseInt(recordRow.interruptDuration/60%60)+'分':'0天0时0秒'
}}
getFormApi={formApi => FormApi.current = formApi} getFormApi={formApi => FormApi.current = formApi}
labelPosition='left' labelPosition='left'
labelAlign='right'> labelAlign='right'>
@ -70,14 +80,26 @@ const okHandler=()=>{
placeholder='请输入故障简述' rules={[{ required: true, message:'请输入故障简述' }]} maxLength={30}/> placeholder='请输入故障简述' rules={[{ required: true, message:'请输入故障简述' }]} maxLength={30}/>
<Form.DatePicker field='startTime' label='发生时间:' rules={[{ required: true, message:'请输入发生时间' }]} <Form.DatePicker field='startTime' label='发生时间:' rules={[{ required: true, message:'请输入发生时间' }]}
type="dateTime" onChange={(e)=>{ type="dateTime" onChange={(e)=>{
const seconds=(moment(endTime).format('x')-moment(e).format('x'))/1000//
const tdd=e&&endTime?parseInt(seconds/60/60/24):0//
const tdh=e&&endTime?parseInt(seconds/60/60%24):0//
const tds=e&&endTime?parseInt(seconds/60%60):0//
setStartTime(e) setStartTime(e)
///console.log('e1',e) FormApi.current.setValue('breakTime',`${tdd}${tdh}${tds}`)
}} }}
/> />
<Form.DatePicker field='endTime' label='解决时间:' initValue={endTime} rules={[{ required: true, message:'请输入解决时间' }]} <Form.DatePicker field='endTime' label='解决时间:' initValue={endTime} rules={[{ required: true, message:'请输入解决时间' }]}
type="dateTime" onChange={(e)=>{setEndTime(e);//console.log('sss',moment(endTime-startTime).format('DDhhmm')) type="dateTime" onChange={(e)=>{
const seconds=(moment(e).format('x')-moment(startTime).format('x'))/1000//
const tdd=e&&startTime?parseInt(seconds/60/60/24):0//
const tdh=e&&startTime?parseInt(seconds/60/60%24):0//
const tds=e&&startTime?parseInt(seconds/60%60):0//
setEndTime(e);//console.log('sss',moment(endTime-startTime).format('DDhhmm'))
FormApi.current.setValue('breakTime',`${tdd}${tdh}${tds}`)
}} /> }} />
中断时间:{endTime&&startTime? <span style={{marginLeft:30}}>{`${tdd}${tdh}${tds}`}</span>:''} <Form.Input field='breakTime' label='中断时间:' disabled/>
{/* 中断时间:{endTime&&startTime? <span style={{marginLeft:30}}>{`${tdd}天${tdh}时${tds}分`}</span>:recordRow?.interruptDuration} */}
<Form.Select field='settler' label='解决者:' trigger='blur' style={{ width:'100%' }} <Form.Select field='settler' label='解决者:' trigger='blur' style={{ width:'100%' }}
filter filter
rules={[{ required: true, message:'请输入解决者' }]} multiple> rules={[{ required: true, message:'请输入解决者' }]} multiple>

Loading…
Cancel
Save