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: