From 794123a012d1521507f7d469ad5d31bbfbf9dae5 Mon Sep 17 00:00:00 2001 From: zhaobing Date: Mon, 26 Jun 2023 16:29:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=BB=B4=E6=8A=A4=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=B8=AD=E6=96=AD=E6=97=B6=E9=95=BF=E6=98=BE=E7=A4=BAbug+?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=BB=B4=E6=8A=A4=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/record/index.js | 9 +- .../serverInfoMaintenanceRecord/index.js | 162 ++++++++++++++++++ .../create_equipment_maintenance_record.sql | 25 +++ ...ipment_maintenance_record_execute_user.sql | 9 + ...e_equipment_maintenance_record_project.sql | 9 + web/client/src/sections/facility/nav-item.jsx | 2 +- .../service/components/recordModal.jsx | 38 +++- 7 files changed, 241 insertions(+), 13 deletions(-) create mode 100644 api/app/lib/controllers/serverInfoMaintenanceRecord/index.js create mode 100644 script/0.27/schema/create_equipment_maintenance_record.sql create mode 100644 script/0.27/schema/create_equipment_maintenance_record_execute_user.sql create mode 100644 script/0.27/schema/create_equipment_maintenance_record_project.sql diff --git a/api/app/lib/controllers/record/index.js b/api/app/lib/controllers/record/index.js index 50d376c..7f37144 100644 --- a/api/app/lib/controllers/record/index.js +++ b/api/app/lib/controllers/record/index.js @@ -82,12 +82,14 @@ async function addRecord(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); const { models } = ctx.fs.dc const params = ctx.request.body - console.log('resss1', ctx.request.body) const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg } = params + const breakTime = (Date.parse(solvingTime) - Date.parse(occurrencTime)) / 1000 try { + //中断时长 + //console.log('resss1', Date.parse(solvingTime), occurrencTime) if (id) { await models.MaintenanceRecord.update({ - solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type + solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime }, { where: { id } }) await models.MaintenanceRecordExecuteUser.destroy({ where: { maintenanceRecordId: id } }) const resArry = settler.map((item) => { @@ -97,7 +99,7 @@ async function addRecord(ctx) { }) await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) } 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 resArry = settler.map((item) => { return { @@ -112,7 +114,6 @@ async function addRecord(ctx) { ctx.status = 200 } catch (error) { await transaction.rollback(); - ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { diff --git a/api/app/lib/controllers/serverInfoMaintenanceRecord/index.js b/api/app/lib/controllers/serverInfoMaintenanceRecord/index.js new file mode 100644 index 0000000..f75c596 --- /dev/null +++ b/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 +}; \ No newline at end of file diff --git a/script/0.27/schema/create_equipment_maintenance_record.sql b/script/0.27/schema/create_equipment_maintenance_record.sql new file mode 100644 index 0000000..6337613 --- /dev/null +++ b/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 '状态'; \ No newline at end of file diff --git a/script/0.27/schema/create_equipment_maintenance_record_execute_user.sql b/script/0.27/schema/create_equipment_maintenance_record_execute_user.sql new file mode 100644 index 0000000..4ac2617 --- /dev/null +++ b/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 +); diff --git a/script/0.27/schema/create_equipment_maintenance_record_project.sql b/script/0.27/schema/create_equipment_maintenance_record_project.sql new file mode 100644 index 0000000..67d593f --- /dev/null +++ b/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 +); \ No newline at end of file diff --git a/web/client/src/sections/facility/nav-item.jsx b/web/client/src/sections/facility/nav-item.jsx index 47d2263..6aa6bbd 100644 --- a/web/client/src/sections/facility/nav-item.jsx +++ b/web/client/src/sections/facility/nav-item.jsx @@ -6,7 +6,7 @@ export function getNavItem (user, dispatch) { [ { itemKey: 'facility', - text: '设备', + text: '服务器', icon: , items: [ // { diff --git a/web/client/src/sections/service/components/recordModal.jsx b/web/client/src/sections/service/components/recordModal.jsx index 1847e78..f69c67f 100644 --- a/web/client/src/sections/service/components/recordModal.jsx +++ b/web/client/src/sections/service/components/recordModal.jsx @@ -11,13 +11,15 @@ const RecordModal =(props)=>{ const [endTime,setEndTime]=useState('') const FormApi = useRef(); const{service} =actions - const tdd=parseInt((endTime-startTime)/1000/60/60/24)//取整天 - const tdh=parseInt((endTime-startTime)/1000/60/60%24)//取整时 - const tds=parseInt((endTime-startTime)/1000/60%60)//取整分 + // let t=0//天数 + // let h=0//小时数 + // let s=0//秒数 // console.log('endTimex',endTime) useEffect(()=>{ setEndTime(recordRow?.solvingTime) + setStartTime(recordRow?.occurrenceTime) console.log('recordRow',recordRow) + },[recordRow]) const cancelHandler=()=>{ onClose() @@ -60,8 +62,16 @@ const okHandler=()=>{ onOk={okHandler} >
{return item.pepUserId}),'type':recordRow?.type,'record':recordRow?.record}} + initValues={{'name':recordRow?.sketch, + '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} labelPosition='left' labelAlign='right'> @@ -70,14 +80,26 @@ const okHandler=()=>{ placeholder='请输入故障简述' rules={[{ required: true, message:'请输入故障简述' }]} maxLength={30}/> { + 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) - ///console.log('e1',e) + FormApi.current.setValue('breakTime',`${tdd}天${tdh}时${tds}分`) }} /> {setEndTime(e);//console.log('sss',moment(endTime-startTime).format('DD天hh时mm分')) + 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('DD天hh时mm分')) + FormApi.current.setValue('breakTime',`${tdd}天${tdh}时${tds}分`) + }} /> - 中断时间:{endTime&&startTime? {`${tdd}天${tdh}时${tds}分`}:''} + + {/* 中断时间:{endTime&&startTime? {`${tdd}天${tdh}时${tds}分`}:recordRow?.interruptDuration} */}