diff --git a/api/app/lib/controllers/equipment/index.js b/api/app/lib/controllers/equipment/index.js new file mode 100644 index 0000000..310b722 --- /dev/null +++ b/api/app/lib/controllers/equipment/index.js @@ -0,0 +1,203 @@ +'use strict'; +const moment = require('moment'); + +//设备维护记录 +async function getEquipment(ctx) { + try { + const { models } = ctx.fs.dc + const sequelize = ctx.fs.dc.ORM + const { clickHouse } = ctx.app.fs + const { startTime, endTime, pageSize, pageIndex, projectId } = ctx.query + //console.log('ressss', ctx.query) + let whereOption = {} + if (projectId) { + whereOption.projectId = projectId + } else { + whereOption = undefined + } + + //console.log('6666', ctx.query) + let resCount = await models.EquipmentMaintenanceRecord.count({ + include: [{ + model: models.EquipmentMaintenanceRecordProject, + where: whereOption + }], + where: { + $and: [ + sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '>=', moment(startTime).format('YYYY-MM-DD HH:mm:ss')), + sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '<=', moment(endTime).format('YYYY-MM-DD HH:mm:ss')), + ], + + + } + }) + const res = await models.EquipmentMaintenanceRecord.findAll({ + order: [['id', 'DESC']], + attributes: ['id', 'equipmentType', 'equipmentCategory', 'maintenanceReason', 'solution', 'reportTime', 'completedTime', 'status'], + offset: (pageIndex - 1) * pageSize, + limit: pageSize, + include: [{ + attributes: ['id', 'equipmentMaintenanceRecordId', 'projectId'], + model: models.EquipmentMaintenanceRecordProject, + where: whereOption + + }, + { + attributes: ['id', 'equipmentMaintenanceRecordId', 'pepUserId'], + model: models.EquipmentMaintenanceRecordExecuteUser + } + ], + where: { + $and: [ + sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '>=', moment(startTime).format('YYYY-MM-DD HH:mm:ss')), + sequelize.where(sequelize.fn('date', sequelize.col('report_time')), '<=', moment(endTime).format('YYYY-MM-DD HH:mm:ss')), + ], + + } + }) + //用户id + const arrayUserId = [] + + res.forEach((item) => { item.equipmentMaintenanceRecordExecuteUsers.forEach((item1) => { arrayUserId.push(item1.pepUserId) }) }) + const arrayUserIdCopy = [...new Set(arrayUserId)] + // (${[...pepProjectIds].join(',')}, -1) + let userRes = [] + if (arrayUserIdCopy.length > 0) { + userRes = await clickHouse.pepEmis.query(` + SELECT * FROM user + WHERE id IN (${[...arrayUserIdCopy].join(',')},-1) + `).toPromise() + } + const lastRes = res.map((item) => { + return { + reportTime: item.reportTime, + completedTime: item.completedTime, + equipmentCategory: item.equipmentCategory, + equipmentType: item.equipmentType, + id: item.id, + maintenanceReason: item.maintenanceReason, + solution: item.solution, + status: item.status, + equipmentMaintenanceRecordExecuteUsers: + item.equipmentMaintenanceRecordExecuteUsers.map((item1) => { + const userArr = userRes.find((ac) => { return ac.id == item1.pepUserId }) + return { + id: item1.id, + pepUserId: item1.pepUserId, + name: userArr ? userArr.name : '' + } + }), + equipmentMaintenanceRecordProjects: item.equipmentMaintenanceRecordProjects + } + }) + //console.log('res111', lastRes, resCount) + // console.log('res11', arrayUserIdCopy) + ctx.body = { result: lastRes, resCount } + ctx.status = 200 + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) + ctx.status = 400 + ctx.body = { + message: `查询设备维护记录失败` + } + } +} +//编辑和新增 +async function editEquipment(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + const query = ctx.request.body + try { + const { models } = ctx.fs.dc + const sequelize = ctx.fs.dc.ORM + console.log('query1111', query) + const { id, completedTime, deviceType, model, reason, reportTime, solution, status, solver, projectId } = query + if (id) { + await models.EquipmentMaintenanceRecord.update({ + equipmentType: model, + equipmentCategory: deviceType, + maintenanceReason: reason, + solution: solution, + reportTime, + completedTime, + status + }, { where: { id } }) + await models.EquipmentMaintenanceRecordExecuteUser.destroy({ where: { equipmentMaintenanceRecordId: id } }) + await models.EquipmentMaintenanceRecordProject.destroy({ where: { equipmentMaintenanceRecordId: id } }) + if (solver) { + const insertUserVal = solver.map((item) => { + return { + equipmentMaintenanceRecordId: id, pepUserId: item + } + }) + await models.EquipmentMaintenanceRecordExecuteUser.bulkCreate(insertUserVal) + } + + await models.EquipmentMaintenanceRecordProject.create({ + equipmentMaintenanceRecordId: id, projectId + }) + + + } else { + const equipment = await models.EquipmentMaintenanceRecord.create({ + equipmentType: model, + equipmentCategory: deviceType, + maintenanceReason: reason, + solution: solution, + reportTime, + completedTime, + status + }) + await models.EquipmentMaintenanceRecordProject.create({ + equipmentMaintenanceRecordId: equipment.id, projectId + }) + if (solver) { + const insertUserVal = solver.map((item) => { + return { + equipmentMaintenanceRecordId: equipment.id, pepUserId: item + } + }) + await models.EquipmentMaintenanceRecordExecuteUser.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: `${query.msg}失败` + } + } +} +//删除 +async function delEquipment(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const params = ctx.params + const { models } = ctx.fs.dc + await models.EquipmentMaintenanceRecordExecuteUser.destroy({ where: { equipmentMaintenanceRecordId: params.id } }) + await models.EquipmentMaintenanceRecordProject.destroy({ where: { equipmentMaintenanceRecordId: params.id } }) + await models.EquipmentMaintenanceRecord.destroy({ where: { id: params.id } }) + ctx.status = 204 + await transaction.commit(); + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) + ctx.status = 400 + ctx.body = { + message: `删除维护记录失败` + } + } +} + + + + + +module.exports = { + getEquipment, editEquipment, delEquipment +}; \ No newline at end of file diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 12b6f78..a4fe472 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -59,7 +59,9 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq const { AppInspection, ProjectApp, ProjectCorrelation, AppAlarm, App, AlarmAppearRecord, AlarmConfirmLog, EmailSendLog, LatestDynamicList, AlarmPushConfig, - MaintenanceRecord, MaintenanceRecordExecuteUser, MaintenancePlanExecuteUser, MaintenancePlan } = dc.models; + MaintenanceRecord, MaintenanceRecordExecuteUser, MaintenancePlanExecuteUser, MaintenancePlan, EquipmentMaintenanceRecord, EquipmentMaintenanceRecordProject, + EquipmentMaintenanceRecordExecuteUser, ServerMaintenanceRecordRepairman, ServerMaintenanceRecord + } = dc.models; AppInspection.belongsTo(App, { foreignKey: 'projectAppId', targetKey: 'id' }); App.hasMany(AppInspection, { foreignKey: 'projectAppId', sourceKey: 'id' }); @@ -109,4 +111,16 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq MaintenancePlanExecuteUser.belongsTo(MaintenancePlan, { foreignKey: 'maintenancePlanId', targetKey: 'id' }) MaintenancePlan.hasMany(MaintenancePlanExecuteUser, { foreignKey: 'maintenancePlanId', targetKey: 'id' }) + + + EquipmentMaintenanceRecordProject.belongsTo(EquipmentMaintenanceRecord, { foreignKey: 'equipmentMaintenanceRecordId', targetKey: 'id' }) + EquipmentMaintenanceRecord.hasMany(EquipmentMaintenanceRecordProject, { foreignKey: 'equipmentMaintenanceRecordId', targetKey: 'id' }) + + EquipmentMaintenanceRecordExecuteUser.belongsTo(EquipmentMaintenanceRecord, { foreignKey: 'equipmentMaintenanceRecordId', targetKey: 'id' }) + EquipmentMaintenanceRecord.hasMany(EquipmentMaintenanceRecordExecuteUser, { foreignKey: 'equipmentMaintenanceRecordId', targetKey: 'id' }) + + ServerMaintenanceRecordRepairman.belongsTo(ServerMaintenanceRecord, { foreignKey: 'serverMaintenanceRecordId', targetKey: 'id' }) + ServerMaintenanceRecord.hasMany(ServerMaintenanceRecordRepairman, { foreignKey: 'serverMaintenanceRecordId', targetKey: 'id' }) + + }; diff --git a/api/app/lib/models/equipment_maintenance_record.js b/api/app/lib/models/equipment_maintenance_record.js new file mode 100644 index 0000000..61185d9 --- /dev/null +++ b/api/app/lib/models/equipment_maintenance_record.js @@ -0,0 +1,88 @@ +/* eslint-disable*/ + +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const EquipmentMaintenanceRecord = sequelize.define("equipmentMaintenanceRecord", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true + }, + equipmentType: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "equipment_type", + autoIncrement: false + }, + equipmentCategory: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "equipment_category", + autoIncrement: false + }, + maintenanceReason: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "maintenance_reason", + autoIncrement: false + }, + solution: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "solution", + autoIncrement: false + }, + reportTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "report_time", + autoIncrement: false + }, + completedTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "completed_time", + autoIncrement: false + }, + status: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "status", + autoIncrement: false + } + }, { + tableName: "equipment_maintenance_record", + comment: "", + indexes: [] + }); + dc.models.EquipmentMaintenanceRecord = EquipmentMaintenanceRecord; + return EquipmentMaintenanceRecord; +}; \ No newline at end of file diff --git a/api/app/lib/models/equipment_maintenance_record_execute_user.js b/api/app/lib/models/equipment_maintenance_record_execute_user.js new file mode 100644 index 0000000..812ed78 --- /dev/null +++ b/api/app/lib/models/equipment_maintenance_record_execute_user.js @@ -0,0 +1,47 @@ +/* eslint-disable*/ + +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const EquipmentMaintenanceRecordExecuteUser = sequelize.define("equipmentMaintenanceRecordExecuteUser", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true + }, + equipmentMaintenanceRecordId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "equipment_maintenance_record_id", + autoIncrement: false, + references: { + key: "id", + model: "equipmentMaintenanceRecord" + } + }, + pepUserId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "pep_user_id", + autoIncrement: false + } + }, { + tableName: "equipment_maintenance_record_execute_user", + comment: "", + indexes: [] + }); + dc.models.EquipmentMaintenanceRecordExecuteUser = EquipmentMaintenanceRecordExecuteUser; + return EquipmentMaintenanceRecordExecuteUser; +}; \ No newline at end of file diff --git a/api/app/lib/models/equipment_maintenance_record_project.js b/api/app/lib/models/equipment_maintenance_record_project.js new file mode 100644 index 0000000..8b9b6b4 --- /dev/null +++ b/api/app/lib/models/equipment_maintenance_record_project.js @@ -0,0 +1,47 @@ +/* eslint-disable*/ + +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const EquipmentMaintenanceRecordProject = sequelize.define("equipmentMaintenanceRecordProject", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true + }, + equipmentMaintenanceRecordId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "equipment_maintenance_record_id", + autoIncrement: false, + references: { + key: "id", + model: "equipmentMaintenanceRecord" + } + }, + projectId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "project_id", + autoIncrement: false + } + }, { + tableName: "equipment_maintenance_record_project", + comment: "", + indexes: [] + }); + dc.models.EquipmentMaintenanceRecordProject = EquipmentMaintenanceRecordProject; + return EquipmentMaintenanceRecordProject; +}; \ No newline at end of file diff --git a/api/app/lib/models/server_maintenance_record.js b/api/app/lib/models/server_maintenance_record.js new file mode 100644 index 0000000..37d2994 --- /dev/null +++ b/api/app/lib/models/server_maintenance_record.js @@ -0,0 +1,79 @@ +/* eslint-disable*/ + +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const ServerMaintenanceRecord = sequelize.define("serverMaintenanceRecord", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true + }, + sketch: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "简述", + primaryKey: false, + field: "sketch", + autoIncrement: false + }, + reason: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "维修原因", + primaryKey: false, + field: "reason", + autoIncrement: false + }, + remark: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "备注", + primaryKey: false, + field: "remark", + autoIncrement: false + }, + maintenanceStartTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "维护开始时间", + primaryKey: false, + field: "maintenance_start_time", + autoIncrement: false + }, + maintenanceFinishTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "维护结束时间", + primaryKey: false, + field: "maintenance_finish_time", + autoIncrement: false + }, + state: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "完成状态 wait 待维修 / underway 维修中 / completed 维修完成 ", + primaryKey: false, + field: "state", + autoIncrement: false + } + }, { + tableName: "server_maintenance_record", + comment: "", + indexes: [] + }); + dc.models.ServerMaintenanceRecord = ServerMaintenanceRecord; + return ServerMaintenanceRecord; +}; \ No newline at end of file diff --git a/api/app/lib/models/server_maintenance_record_repairman.js b/api/app/lib/models/server_maintenance_record_repairman.js new file mode 100644 index 0000000..5c617eb --- /dev/null +++ b/api/app/lib/models/server_maintenance_record_repairman.js @@ -0,0 +1,47 @@ +/* eslint-disable*/ + +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const ServerMaintenanceRecordRepairman = sequelize.define("serverMaintenanceRecordRepairman", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true + }, + serverMaintenanceRecordId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "server_maintenance_record_id", + autoIncrement: false, + references: { + key: "id", + model: "serverMaintenanceRecord" + } + }, + pepUserId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "pep_user_id", + autoIncrement: false + } + }, { + tableName: "server_maintenance_record_repairman", + comment: "", + indexes: [] + }); + dc.models.ServerMaintenanceRecordRepairman = ServerMaintenanceRecordRepairman; + return ServerMaintenanceRecordRepairman; +}; \ No newline at end of file diff --git a/api/app/lib/routes/equipment/index.js b/api/app/lib/routes/equipment/index.js new file mode 100644 index 0000000..ddfffe2 --- /dev/null +++ b/api/app/lib/routes/equipment/index.js @@ -0,0 +1,15 @@ +'use strict'; + +const equipment = require('../../controllers/equipment'); + +module.exports = function (app, router, opts) { + app.fs.api.logAttr['GET/equipment'] = { content: '获取设备维护记录', visible: true }; + router.get('/equipment', equipment.getEquipment); + + app.fs.api.logAttr['POST/equipment'] = { content: '编辑或者新增设备维护记录', visible: true }; + router.post('/equipment', equipment.editEquipment); + + app.fs.api.logAttr['DEL/equipment/:id'] = { content: '删除设备维护记录', visible: true }; + router.delete('/equipment/:id', equipment.delEquipment); + +} \ No newline at end of file diff --git a/api/app/lib/routes/serverInfoMaintenance/index.js b/api/app/lib/routes/serverInfoMaintenance/index.js new file mode 100644 index 0000000..66a7607 --- /dev/null +++ b/api/app/lib/routes/serverInfoMaintenance/index.js @@ -0,0 +1,17 @@ +'use strict'; + +const serverInfoMaintenanceRecord = require('../../controllers/serverInfoMaintenanceRecord'); + +module.exports = function (app, router, opts) { + app.fs.api.logAttr['GET/serverInfoMaintenanceRecord'] = { content: '获取服务器维护记录列表', visible: true }; + router.get('/serverInfoMaintenanceRecord', serverInfoMaintenanceRecord.getServerInfoMaintenanceRecord) + + app.fs.api.logAttr['POST/serverInfoMaintenanceRecord'] = { content: '编辑服务器维护记录列表', visible: true }; + router.post('/serverInfoMaintenanceRecord', serverInfoMaintenanceRecord.editServerInfoMaintenanceRecord) + + app.fs.api.logAttr['DEL/serverInfoMaintenanceRecord/:id'] = { content: '删除服务器维护记录列表', visible: true }; + router.del('/serverInfoMaintenanceRecord/:id', serverInfoMaintenanceRecord.delServerInfoMaintenanceRecord) +} + + + diff --git a/script/0.27/schema/create_server_maintenance_record.sql b/script/0.27/schema/create_server_maintenance_record.sql new file mode 100644 index 0000000..3adf6bd --- /dev/null +++ b/script/0.27/schema/create_server_maintenance_record.sql @@ -0,0 +1,16 @@ +create table server_maintenance_record( + id serial primary key, + sketch varchar(512), + reason varchar(512), + remark varchar(1024), + maintenance_start_time timestamp with time zone, + maintenance_finish_time timestamp with time zone, + state varchar(32) + ); +comment on column public.server_maintenance_record.sketch is '简述'; +comment on column public.server_maintenance_record.reason is '维修原因'; +comment on column public.server_maintenance_record.remark is '备注'; +comment on column public.server_maintenance_record.maintenance_start_time is '维护开始时间'; +comment on column public.server_maintenance_record.maintenance_finish_time is '维护结束时间'; +comment on column public.server_maintenance_record.state is '维护结束时间'; +comment on column public.server_maintenance_record.state is '完成状态 wait 待维修 / underway 维修中 / completed 维修完成 '; diff --git a/script/0.27/schema/create_server_maintenance_record_repairman.sql b/script/0.27/schema/create_server_maintenance_record_repairman.sql new file mode 100644 index 0000000..2ac702e --- /dev/null +++ b/script/0.27/schema/create_server_maintenance_record_repairman.sql @@ -0,0 +1,5 @@ +create table server_maintenance_record_repairman( + id serial primary key, + server_maintenance_record_id integer references server_maintenance_record(id), + pep_user_id integer +) \ No newline at end of file diff --git a/web/client/src/sections/facility/actions/index.js b/web/client/src/sections/facility/actions/index.js index eb109ab..3d0dd1e 100644 --- a/web/client/src/sections/facility/actions/index.js +++ b/web/client/src/sections/facility/actions/index.js @@ -1,2 +1,5 @@ 'use strict'; - +import * as serverInfoMaintenanceRecord from '../actions/serverInfo' +export default { + ...serverInfoMaintenanceRecord +} \ No newline at end of file diff --git a/web/client/src/sections/facility/actions/serverInfo.js b/web/client/src/sections/facility/actions/serverInfo.js new file mode 100644 index 0000000..cd6ae90 --- /dev/null +++ b/web/client/src/sections/facility/actions/serverInfo.js @@ -0,0 +1,45 @@ +import { ApiTable, basicAction } from '$utils' + +export function getServerInfoMaintenanceRecord(query) { //获取服务器维护记录 + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query, + actionType: 'GET_SERVER_INFO_MAINTENANCE_RECORD', + url: `${ApiTable.getServerInfoMaintenanceRecord}`, + msg: { option: '获取服务器维护记录' }, + reducer: { + name: "getServerInfoMaintenanceRecord", + params: { noClear: true } + } + }); +} + + +export function editServerInfoMaintenanceRecord(data) {//添加/编辑服务器信息维护记录 + let msg = '' + if (data) { + msg = data.msg + } + return (dispatch) => + basicAction({ + type: "post", + dispatch: dispatch, + data, + actionType: "POST_SERVER_INFO_MAINTENANCE_RECORD", + url: `${ApiTable.editServerInfoMaintenanceRecord}`, + msg: { option: msg },//添加/编辑服务器信息维护记录 + }); +} + +export function delServerInfoMaintenanceRecord(id) {//删除服务器信息维护记录 + return (dispatch) => + basicAction({ + type: "del", + dispatch: dispatch, + actionType: "DEL_SERVER_INFO_MAINTENANCE_RECORD", + url: `${ApiTable.delServerInfoMaintenanceRecord.replace('{id}', id)}`, + msg: { option: '删除服务器信息维护记录' }, + }); +} + diff --git a/web/client/src/sections/facility/components/serverInfoModal.jsx b/web/client/src/sections/facility/components/serverInfoModal.jsx new file mode 100644 index 0000000..56e61d6 --- /dev/null +++ b/web/client/src/sections/facility/components/serverInfoModal.jsx @@ -0,0 +1,105 @@ +'use strict'; + +import React, { useEffect, useState, useRef } from 'react'; +import { Modal, Form, DatePicker, useFormApi, actions, Button } from '@douyinfe/semi-ui'; +import { connect } from 'react-redux'; +import moment from 'moment'; + +const ServerInfoModal = (props) => { + const { visible, onClose, dispatch, recordRow, pepList, actions, projectList } = props; + const [startTime, setStartTime] = useState(''); + const [endTime, setEndTime] = useState(''); + const { service,facility } = actions; + + // console.log('endTimex',endTime) + const api = useRef(); + + useEffect(() => { + //console.log('recordRow', recordRow) + }, [recordRow]); + const cancelHandler = () => { + onClose() + } + const okHandler = () => { + api.current.validate().then((res) => { + //console.log('res1', res) + const query = { + id: recordRow?.id, + sketch:res.sketch, + reason:res.reason, + repairman:res.repairman, + remark:res.remark, + maintenanceStartTime:res.maintenanceStartTime, + maintenanceFinishTime:res.maintenanceFinishTime, + state:res.state, + msg: recordRow ? '编辑服务器信息维护记录' : '添加服务器信息维护记录' + } + dispatch(facility.editServerInfoMaintenanceRecord(query)).then((res)=>{ + if(res.success) onClose() ; api.current.reset() + }) + + }) + } + return ( + 取消:
+ // + // + //
} + > +
{return item.pepUserId}), + remark:recordRow?.remark, + maintenanceStartTime:recordRow?.maintenanceStartTime, + maintenanceFinishTime:recordRow?.maintenanceFinishTime, + state:recordRow?.state, + }} + getFormApi={(formApi) => (api.current = formApi)} + labelPosition='left' + > + + + + {pepList?.map((item) => { + return ( + + {item.users.map((item1) => { + return ; + })} + + ); + })} + + + + + + 待维修 + 维修中 + 维修完成 + +
+
+ ); +}; +function mapStateToProps(state) { + const { auth, global, members, webSocket } = state; + return { + // loading: members.isRequesting, + // user: auth.user, + actions: global.actions + // members: members.data, + // socket: webSocket.socket + }; +} + +export default connect(mapStateToProps)(ServerInfoModal); diff --git a/web/client/src/sections/facility/containers/maintenanceRecords.jsx b/web/client/src/sections/facility/containers/maintenanceRecords.jsx index 27f758a..5d7d8c5 100644 --- a/web/client/src/sections/facility/containers/maintenanceRecords.jsx +++ b/web/client/src/sections/facility/containers/maintenanceRecords.jsx @@ -1,34 +1,224 @@ -import React, { useEffect } from 'react'; +import React, { useEffect,useState } from 'react'; import { connect } from 'react-redux'; +import moment from 'moment' +import { Button, DatePicker, Select, Table, Popconfirm, Tooltip, Pagination } from '@douyinfe/semi-ui'; +import ServerInfoModal from '../components/serverInfoModal' - -const Rest = (props) => { +const MaintenanceRecords = (props) => { const { dispatch, actions, user, loading, socket } = props - + const [addVis, setAddVis] = useState(false) + const [recordRow, setRecordRow] = useState(null) + const [pageSize,setPageSize]=useState(10) + const [pageIndex,setPageIndex]=useState(1) + const [total,setTotal]=useState() + const [pepList, setPepList] = useState([])//角色分配 + const {install,facility}=actions + const [startTime,setStartTime]=useState(null)//配置查询起止时间 + const [endTime,setEndTime]=useState(null) + const [recordList,setRecordList]=useState([]) useEffect(() => { }, []) + //获取服务器信息 + const getServerInfo=(query={startTime,endTime,pageIndex,pageSize})=>{ + dispatch(facility.getServerInfoMaintenanceRecord(query)).then((res)=>{ + if(res.success) setRecordList(res.payload.data.responseRes);setTotal(res?.payload.data.count) + }) + } + //删除逻辑 + const delHandler=(record)=>{ + dispatch(facility.delServerInfoMaintenanceRecord(record.id)).then((res)=>{ + if(res.success) { + getServerInfo({startTime,endTime,pageIndex:1,pageSize}) + setPageIndex(1) + } + }) + } + //查询按钮的逻辑 + const searchHandler=()=>{ + setPageIndex(1);setPageSize(10) + const query={startTime,endTime,pageIndex:1,pageSize:10} + getServerInfo(query) + } + //清楚日期选择框的逻辑 + const clearHandler=()=>{ + setStartTime(null) + setEndTime(null) + const query={startTime:null,endTime:null,pageIndex,pageSize} + getServerInfo(query) + } + useEffect(() => { + getServerInfo()//获取服务器信息维护记录 + dispatch(install.getOrganizationDeps()).then((res) => {//获取项企(PEP)全部部门及其下用户 + if(res.success) setPepList(res.payload.data) + }) + }, []) + const columns = [ + { + title: '序号', + render: (t, r, i) => { + return i + 1; + } + }, + + { + title: '维护描述', + dataIndex: 'sketch' + }, + { + title: '维护原因', + dataIndex: 'reason' + }, + { + title: '维修人', + render:(record) => { + return ( + + {record?.serverMaintenanceRecordRepairmans + .map((item) => { + return item.name; + }) + .toString()} + + ); + } + }, + { + title: '备注', + dataIndex: 'remark' + }, + + { + title: '维护开始时间', + render: (record) => { + return (record?.maintenanceStartTime?({moment(record.maintenanceStartTime).format('YYYY-MM-DD HH:mm:ss')}):'') + } + }, + { + title: '维护完成时间', + render: (record) => { + return (record?.maintenanceFinishTime?({moment(record.maintenanceFinishTime).format('YYYY-MM-DD HH:mm:ss')}):'') + } + }, + { + title: '状态', + render:(record)=>{ + switch(record.state){ + case 'completed': + return '维修完成' + case 'underway': + return '维修中' + case 'wait': + return '待维修' + default: + break + } + + } + }, + { + title: '操作', + render: (record) => { + //console.log('1111111',record) + return ( +
+ + { + delHandler(record) + }} + > + + +
+ ); + } + } + ]; + return ( - <> -
- -
- - ) -} +
+
+
+ {' '} + +
+
+ 上报时间 + { + setStartTime(dateTime[0]+'') + setEndTime(dateTime[1]+'') + }} onClear={clearHandler}> +
+
+ +
+
+
+
+
+
+ + 共{total}条信息 + + { + //console.log('pageIndex1',pageIndex,pageSize) + setPageIndex(pageIndex) + setPageSize(pageSize) + const query={ + pageIndex:pageIndex,pageSize:pageSize,startTime, endTime + } + getServerInfo(query) + }}> +
+ { + setAddVis(false); + setRecordRow(null); + getServerInfo() + }} + recordRow={recordRow} + pepList={pepList} + + > +
+ ); +}; -function mapStateToProps (state) { - const { auth, global, members, webSocket } = state; - return { - // loading: members.isRequesting, - // user: auth.user, - // actions: global.actions, - // members: members.data, - // socket: webSocket.socket - }; +function mapStateToProps(state) { + const { auth, global, members, webSocket, } = state; + return { + // loading: members.isRequesting, + // user: auth.user, + actions: global.actions, + // members: members.data, + // socket: webSocket.socket + }; } - -export default connect(mapStateToProps)(Rest); +export default connect(mapStateToProps)(MaintenanceRecords) diff --git a/web/client/src/sections/service/actions/equipment.js b/web/client/src/sections/service/actions/equipment.js new file mode 100644 index 0000000..5df82e5 --- /dev/null +++ b/web/client/src/sections/service/actions/equipment.js @@ -0,0 +1,46 @@ +'use strict'; + +import { ApiTable, basicAction } from '$utils' + +export function getEquipment(query) { //获取设备维护记录 + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query, + actionType: 'GET_EQUIPMENT', + url: `${ApiTable.getEquipment}`, + msg: { option: '获取设备维护记录' }, + reducer: { + name: "getEquipment", + params: { noClear: true } + } + }); +} + +export function editEquipment(query) { //获取设备维护记录 + let msg = '' + if (query) { + msg = query.msg + } + return dispatch => basicAction({ + type: 'post', + dispatch: dispatch, + data: query, + actionType: 'EDIT_EQUIPMENT', + url: `${ApiTable.editEquipment}`, + msg: { option: msg }, + + }); +} + + +export function delEquipment(query) { //删除设备维护记录 + return dispatch => basicAction({ + type: 'del', + dispatch: dispatch, + actionType: 'DEL_EQUIPMENT', + url: `${ApiTable.delEquipment.replace('{id}', query)}`, + msg: { option: '删除维护记录' }, + + }); +} diff --git a/web/client/src/sections/service/actions/index.js b/web/client/src/sections/service/actions/index.js index aa55316..5e6815f 100644 --- a/web/client/src/sections/service/actions/index.js +++ b/web/client/src/sections/service/actions/index.js @@ -3,6 +3,7 @@ import * as emPush from './emPush' import * as redcord from './record' import * as maintenancePlan from './maintenancePlan' +import * as equipment from './equipment' export default { - ...emPush, ...redcord, ...maintenancePlan + ...emPush, ...redcord, ...maintenancePlan, ...equipment } \ No newline at end of file diff --git a/web/client/src/sections/service/components/maintenanceRecordModal.jsx b/web/client/src/sections/service/components/maintenanceRecordModal.jsx new file mode 100644 index 0000000..b80f3f1 --- /dev/null +++ b/web/client/src/sections/service/components/maintenanceRecordModal.jsx @@ -0,0 +1,127 @@ +'use strict'; + +import React, { useEffect, useState, useRef } from 'react'; +import { Modal, Form, DatePicker, useFormApi, actions, Button } from '@douyinfe/semi-ui'; +import { connect } from 'react-redux'; +import moment from 'moment'; + +const MaintenanceRecordModal = (props) => { + const { visible, onClose, dispatch, recordRow, pepList, actions, projectList } = props; + const [startTime, setStartTime] = useState(''); + const [endTime, setEndTime] = useState(''); + const { service } = actions; + + // console.log('endTimex',endTime) + const api = useRef(); + + useEffect(() => { + console.log('recordRow', recordRow); + }, [recordRow]); + const cancelHandler = () => { + onClose(); + }; + const okHandler = () => { + api.current.validate().then((res) => { + console.log('res1', res) + const query = { + id: recordRow?.id, + projectId:res.projectName, + deviceType:res.deviceType, + model:res.model, + reason:res.reason, + solution:res.solution, + solver:res.solver, + reportTime:res.reportTime, + completedTime:res.completedTime, + status:res.status, + msg: recordRow ? '编辑维护记录' : '添加维护记录' + } + dispatch(service.editEquipment(query)).then((res)=>{ + if(res.success) onClose() ; api.current.reset() + }) + + }) + } + return ( + 取消:
+ // + // + //
} + > +
{ + return item.projectId; + })[0], + deviceType:recordRow?.equipmentCategory, + model:recordRow?.equipmentType, + reason:recordRow?.maintenanceReason, + solution:recordRow?.solution, + solver:recordRow?.equipmentMaintenanceRecordExecuteUsers.map((item)=>{return item.pepUserId}), + reportTime:recordRow?.reportTime, + completedTime:recordRow?.completedTime, + status:recordRow?.status + }} + getFormApi={(formApi) => (api.current = formApi)} + labelPosition='left' + > + + {projectList?.map((item) => { + return ; + })} + + + + + + + {pepList?.map((item) => { + return ( + + {item.users.map((item1) => { + return ; + })} + + ); + })} + + + + + 待维修 + 维修中 + 维修完成 + +
+
+ ); +}; +function mapStateToProps(state) { + const { auth, global, members, webSocket } = state; + return { + // loading: members.isRequesting, + // user: auth.user, + actions: global.actions + // members: members.data, + // socket: webSocket.socket + }; +} + +export default connect(mapStateToProps)(MaintenanceRecordModal); diff --git a/web/client/src/sections/service/containers/index.js b/web/client/src/sections/service/containers/index.js index 9b5272d..f50b383 100644 --- a/web/client/src/sections/service/containers/index.js +++ b/web/client/src/sections/service/containers/index.js @@ -7,5 +7,6 @@ import EmPush from './emPush'; import AppPush from './appPush'; import MaintenanceModel from './maintenanceModel'; import ServiceRecord from './serviceRecord'; +import MaintenanceRecords from './maintenanceRecords'; -export { ReportManagement, CyclePlan, TemporaryResponse, EmPush, AppPush, MaintenanceModel, ServiceRecord }; \ No newline at end of file +export { ReportManagement, CyclePlan, TemporaryResponse, EmPush, AppPush, MaintenanceModel, ServiceRecord, MaintenanceRecords }; \ No newline at end of file diff --git a/web/client/src/sections/service/containers/maintenanceRecords.jsx b/web/client/src/sections/service/containers/maintenanceRecords.jsx new file mode 100644 index 0000000..f732015 --- /dev/null +++ b/web/client/src/sections/service/containers/maintenanceRecords.jsx @@ -0,0 +1,238 @@ +import { Button, DatePicker, Select, Table, Popconfirm, Tooltip, Pagination } from '@douyinfe/semi-ui'; +import React, { useEffect, useState } from 'react'; +import { connect } from 'react-redux'; +import MaintenanceRecordModal from '../components/maintenanceRecordModal'; +import moment from 'moment'; + +const MaintenanceRecords = (props) => { + const { dispatch, actions, user, loading, socket, projectList } = props; + const [addVis, setAddVis] = useState(false); + const [recordRow, setRecordRow] = useState(null); + const [equipmentList, setEquipmentList] = useState([]); + const [pepList, setPepList] = useState([]); + const [pageSize, setPageSize] = useState(10); + const [pageIndex, setPageIndex] = useState(1); + const [startTime, setStartTime] = useState('1970-1-1'); + const [endTime, setEndTime] = useState('2099-1-1'); + const { install, service } = actions; + const [total,setTotal]=useState() + const [projectId,setProjectId]=useState(null) + const getEquipment = (query = { startTime, endTime, pageIndex, pageSize }) => { + dispatch(service.getEquipment(query)).then((res) => { + // console.log() + if (res.success) setEquipmentList(res?.payload.data.result); setTotal(res?.payload.data.resCount) + + + }); + }; + // console.log('equipmentList', equipmentList); + const findHandler=()=>{ + const query={ + pageIndex,pageSize,msg:'获取维护记录',startTime, endTime,projectId + } + console.log('canshu',projectId,startTime, endTime) + getEquipment(query) + } + const timeHandler=(e)=>{ + setEndTime(e[1]+'') + setStartTime(e[0]+'') + } + useEffect(() => { + dispatch(install.getOrganizationDeps()).then((res) => { + //获取项企(PEP)全部部门及其下用户 + setPepList(res.payload.data); + }); + getEquipment(); + }, []) + const delHandler=(record)=>{ + dispatch(service.delEquipment(record.id)).then((res)=>{ + if(res.success) getEquipment({ + pageIndex:1,pageSize,msg:'获取维护记录',startTime, endTime,projectId + });setPageIndex(1) + }) + } + const columns = [ + { + title: '序号', + render: (t, r, i) => { + return i + 1; + } + }, + { + title: '项目名称', + render: (record) => { + const currentId = record.equipmentMaintenanceRecordProjects.map((item1) => { + return item1.projectId; + })[0]; + const currnetObj = projectList?.find((item) => item.id === currentId)||{}; + const projectName = currnetObj.name ? currnetObj.name : currnetObj.pepProjectName; + return projectName?.length > 15 ? ( + {projectName}}> +
{projectName?.length > 15 ? `${projectName?.substr(0, 15)}...` : projectName}
+
+ ) : ( + projectName + ); + } + }, + { + title: '设备类型', + dataIndex: 'equipmentCategory' + }, + { + title: '设备型号', + dataIndex: 'equipmentType' + }, + { + title: '维修原因', + dataIndex: 'maintenanceReason' + }, + { + title: '解决方案', + dataIndex: 'solution' + }, + { + title: '维修人', + render: (record) => { + return ( + + {record?.equipmentMaintenanceRecordExecuteUsers + .map((item) => { + return item.name; + }) + .toString()} + + ); + } + }, + { + title: '上报时间', + render: (record) => { + return {moment(record.reportTime).format('YYYY-MM-DD HH:mm:ss')}; + } + }, + { + title: '维修完成时间', + render: (record) => { + //('record',record.completedTime) + return (record.completedTime?({moment(record.reportTime).format('YYYY-MM-DD HH:mm:ss')}):'') + } + }, + { + title: '状态', + dataIndex: 'status' + }, + { + title: '操作', + render: (record) => { + return ( +
+ + { + delHandler(record); + }} + > + + +
+ ); + } + } + ]; + + return ( +
+
+
+ {' '} + +
+
+ {' '} + 项目名称 + +
+
+ 上报时间 + {timeHandler(e)}} onClear={()=>{setStartTime('1970-1-1');setEndTime('2099-12-31')}}> +
+
+ +
+
+
+
+
+
+ + 共{total}条信息 + + { + //console.log('pageIndex1',pageIndex,pageSize) + setPageIndex(pageIndex) + setPageSize(pageSize) + const query={ + pageIndex,pageSize,msg:'获取维护记录',startTime, endTime,projectId + } + getEquipment(query) + }}> +
+ { + setAddVis(false); + setRecordRow(null); + getEquipment(); + }} + recordRow={recordRow} + pepList={pepList} + projectList={projectList} + > +
+ ); +}; + +function mapStateToProps(state) { + const { auth, global, members, webSocket, ProjectPoms } = state; + return { + // loading: members.isRequesting, + // user: auth.user, + actions: global.actions, + // members: members.data, + // socket: webSocket.socket + projectList: ProjectPoms.data?.rows + }; +} + +export default connect(mapStateToProps)(MaintenanceRecords); diff --git a/web/client/src/sections/service/containers/serviceRecord.jsx b/web/client/src/sections/service/containers/serviceRecord.jsx index b230808..cf5f374 100644 --- a/web/client/src/sections/service/containers/serviceRecord.jsx +++ b/web/client/src/sections/service/containers/serviceRecord.jsx @@ -37,7 +37,7 @@ const Server = (props) => { useEffect(() => { getRecordList() dispatch(install.getOrganizationDeps()).then((res) => {//获取项企(PEP)全部部门及其下用户 - setPepList(res.payload.data) + if(res.success) setPepList(res.payload.data) }) }, []) const delHandler=(id)=>{ @@ -115,7 +115,7 @@ const Server = (props) => { } }, { - title: '当前状态', + title: '操作', render:(record)=>{ return