From bbe5e7bba019b82ccd034d7aed12b426f6f42a29 Mon Sep 17 00:00:00 2001 From: zhaobing Date: Wed, 21 Jun 2023 15:21:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/record/index.js | 63 ++++++++++++++----- api/app/lib/routes/record/index.js | 4 +- .../src/sections/service/actions/record.js | 20 +++++- .../service/components/cycAddmodal.jsx | 3 +- .../service/components/recordModal.jsx | 27 ++++---- .../sections/service/containers/cyclePlan.jsx | 6 +- .../service/containers/serviceRecord.jsx | 40 +++++++++--- .../service/containers/temporaryResponse.jsx | 6 +- 8 files changed, 127 insertions(+), 42 deletions(-) diff --git a/api/app/lib/controllers/record/index.js b/api/app/lib/controllers/record/index.js index a0f8974..50d376c 100644 --- a/api/app/lib/controllers/record/index.js +++ b/api/app/lib/controllers/record/index.js @@ -7,7 +7,8 @@ async function getRecord(ctx) { const { models } = ctx.fs.dc; const sequelize = ctx.fs.dc.ORM; const { startTime, endTime, pageSize, pageIndex } = ctx.query - //console.log('queryz', ctx.query) + console.log('queryz', ctx.query) + let resCount = await models.MaintenanceRecord.count({ where: { $and: [ @@ -76,22 +77,37 @@ async function getRecord(ctx) { } } } -//新增服务记录 +//新增和编辑服务记录 async function addRecord(ctx) { const transaction = await ctx.fs.dc.orm.transaction(); const { models } = ctx.fs.dc const params = ctx.request.body - const { solvingTime, occurrencTime, sketch, record, settler, type } = params + console.log('resss1', ctx.request.body) + const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg } = params try { + if (id) { + await models.MaintenanceRecord.update({ + solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type + }, { where: { id } }) + await models.MaintenanceRecordExecuteUser.destroy({ where: { maintenanceRecordId: id } }) + const resArry = settler.map((item) => { + return { + maintenanceRecordId: id, pepUserId: item + } + }) + await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) + } else { + const aa = await models.MaintenanceRecord.create({ solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type }) + const recordId = aa.id + const resArry = settler.map((item) => { + return { + maintenanceRecordId: recordId, pepUserId: item + } + }) + await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) + } //console.log('params1', params) - const aa = await models.MaintenanceRecord.create({ solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type }) - const recordId = aa.id - const resArry = settler.map((item) => { - return { - maintenanceRecordId: recordId, pepUserId: item - } - }) - await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) + await transaction.commit(); ctx.status = 200 } catch (error) { @@ -100,14 +116,33 @@ async function addRecord(ctx) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { - message: '新增服务记录失败' + message: `${msg}失败` + } + } +} +//删除服务记录 +async function delRecord(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + const { models } = ctx.fs.dc + const params = ctx.params + console.log('params', params) + try { + await models.MaintenanceRecordExecuteUser.destroy({ where: { maintenanceRecordId: params.id } }) + await models.MaintenanceRecord.destroy({ where: { id: params.id } }) + await transaction.commit(); + ctx.status = 200 + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) + ctx.status = 400 + ctx.body = { + message: `删除服务记录失败` } } } - module.exports = { - getRecord, addRecord + getRecord, addRecord, delRecord }; \ No newline at end of file diff --git a/api/app/lib/routes/record/index.js b/api/app/lib/routes/record/index.js index 284c66f..14ecba6 100644 --- a/api/app/lib/routes/record/index.js +++ b/api/app/lib/routes/record/index.js @@ -6,8 +6,10 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/record'] = { content: '获取服务记录列表', visible: true }; router.get('/record', record.getRecord); - app.fs.api.logAttr['PUT/record'] = { content: '新增/服务记录', visible: true }; + app.fs.api.logAttr['PUT/record'] = { content: '新增/编辑服务记录', visible: true }; router.put('/record', record.addRecord); + app.fs.api.logAttr['DEL/record/:id'] = { content: '删除服务记录', visible: true }; + router.del('/record/:id', record.delRecord); }; \ No newline at end of file diff --git a/web/client/src/sections/service/actions/record.js b/web/client/src/sections/service/actions/record.js index 55897b4..9f9e1fa 100644 --- a/web/client/src/sections/service/actions/record.js +++ b/web/client/src/sections/service/actions/record.js @@ -18,14 +18,18 @@ export function getRecord(query) { //获取服务记录 } -export function addRecord(query) { //新增服务记录 +export function addRecord(query) { //新增服务记录和编辑 + let msg = '' + if (query) { + msg = query.msg + } return dispatch => basicAction({ type: 'put', dispatch: dispatch, data: query, actionType: 'ADD_RECORD', url: `${ApiTable.addRecord}`, - msg: { option: '新增服务记录' } + msg: { option: msg } }); } @@ -42,5 +46,17 @@ export function calculability(query) {//计算系统可用性 params: { noClear: true } } + }); +} +export function delRecord(query) {//删除服务记录 + return dispatch => basicAction({ + type: 'del', + dispatch: dispatch, + //query: query, + actionType: 'DELRECORD', + url: `${ApiTable.delRecord.replace('{id}', query)}`, + msg: { option: '删除服务记录' }, + + }); } \ No newline at end of file diff --git a/web/client/src/sections/service/components/cycAddmodal.jsx b/web/client/src/sections/service/components/cycAddmodal.jsx index 53e119d..44f3ea3 100644 --- a/web/client/src/sections/service/components/cycAddmodal.jsx +++ b/web/client/src/sections/service/components/cycAddmodal.jsx @@ -27,7 +27,8 @@ const okHandler=()=>{ msg:recordRow?'编辑周期性计划':'添加周期性计划' } dispatch(service.editMaintenancePlan(query)).then((res)=>{ - if(res.success) onClose() + if(res.success) onClose() ; api.current.reset() + }) diff --git a/web/client/src/sections/service/components/recordModal.jsx b/web/client/src/sections/service/components/recordModal.jsx index 1adde9c..4ff0977 100644 --- a/web/client/src/sections/service/components/recordModal.jsx +++ b/web/client/src/sections/service/components/recordModal.jsx @@ -17,6 +17,7 @@ const RecordModal =(props)=>{ // console.log('endTimex',endTime) useEffect(()=>{ setEndTime(recordRow?.solvingTime) + console.log('recordRow',recordRow) },[recordRow]) const cancelHandler=()=>{ onClose() @@ -26,14 +27,16 @@ const cancelHandler=()=>{ } const okHandler=()=>{ FormApi.current.validate().then((res)=>{ - // console.log('res',res) + console.log('recordRow',res) const editVal={ + id:recordRow?.id, solvingTime:res.endTime, occurrencTime:res.startTime, sketch:res.name, record:res.record, settler:res.settler, - type:res.type + type:res.type, + msg:recordRow?'编辑服务记录':'添加服务记录' } dispatch(service.addRecord(editVal)).then(res => { if (res.success) { @@ -45,9 +48,11 @@ const okHandler=()=>{ }) } return 取消:
+ footer={ + //recordRow?: +
} @@ -56,24 +61,24 @@ const okHandler=()=>{ >
{return item.name}),'type':recordRow?.type,'record':recordRow?.record}} + 'endTime':recordRow?.solvingTime,'settler':recordRow?.maintenanceRecordExecuteUsers.map((item)=>{return item.id}),'type':recordRow?.type,'record':recordRow?.record}} getFormApi={formApi => FormApi.current = formApi} labelPosition='left' labelAlign='right'> - { setStartTime(e) ///console.log('e1',e) }} /> - {setEndTime(e);//console.log('sss',moment(endTime-startTime).format('DD天hh时mm分')) }} /> 中断时间:{endTime&&startTime? {`${tdd}天${tdh}时${tds}分`}:''} - {pepList?.map((item)=>{return ( @@ -83,7 +88,7 @@ const okHandler=()=>{ })} )})} - + es异常 数据库异常 应用异常 @@ -91,7 +96,7 @@ const okHandler=()=>{ 服务器异常 其他 - + diff --git a/web/client/src/sections/service/containers/cyclePlan.jsx b/web/client/src/sections/service/containers/cyclePlan.jsx index 582e8f2..e5f00ae 100644 --- a/web/client/src/sections/service/containers/cyclePlan.jsx +++ b/web/client/src/sections/service/containers/cyclePlan.jsx @@ -34,7 +34,7 @@ const Server = (props) => { msg:'删除周期性计划' } dispatch(service.delMaintenancePlan(query)).then((res)=>{ - if(res.success) getCycPlan() + if(res.success) getCycPlan({type:'period',msg:'获取周期性计划',pageIndex:1,pageSize});setPageIndex(1) }) } //配置分页 @@ -99,14 +99,14 @@ const Server = (props) => { { title: '实际完成时间', render:(record)=>{ - return {moment(record.actualFinishTime).format('YYYY-MM-DD')} + return record.actualFinishTime?{moment(record.actualFinishTime).format('YYYY-MM-DD')}:'' }, }, { title: '操作', render:(record)=>{ return (
- + {delHandler(record)}}>
) } diff --git a/web/client/src/sections/service/containers/serviceRecord.jsx b/web/client/src/sections/service/containers/serviceRecord.jsx index 480ee17..cd46335 100644 --- a/web/client/src/sections/service/containers/serviceRecord.jsx +++ b/web/client/src/sections/service/containers/serviceRecord.jsx @@ -1,7 +1,7 @@ 'use strict'; import React, { useEffect,useState,useMemo } from 'react'; -import { Calendar,DatePicker,RadioGroup, Radio,Button,Table,Modal,Tooltip,Pagination } from '@douyinfe/semi-ui'; +import { Calendar,DatePicker,RadioGroup, Radio,Button,Table,Modal,Tooltip,Pagination, Popconfirm } from '@douyinfe/semi-ui'; import moment from 'moment' import { connect } from 'react-redux'; import RecordModal from '../components/recordModal' @@ -40,7 +40,14 @@ const Server = (props) => { setPepList(res.payload.data) }) }, []) - + const delHandler=(id)=>{ + dispatch(service.delRecord(id)).then((res)=>{ + if(res.success) { + getRecordList({startTime,endTime,pageIndex:1,pageSize}) + setPageIndex(1) + } + }) + } useEffect(() => { const query={ sTime, eTime @@ -110,8 +117,26 @@ const Server = (props) => { { title: '当前状态', render:(record)=>{ - return () + return
+ + { + delHandler(record.id); + }} + > + + +
+ }, }, ]; @@ -165,7 +190,7 @@ const addHandler=()=>{ onChangeDate(e) } density="compact" - style={{ width: 260 }} + style={{ width: 400 }} value={dateValue} onClear={()=>{clearHandler()}} @@ -182,9 +207,10 @@ const addHandler=()=>{ 产生时间 { setStartTime((e[0])+'');setEndTime(e[1]+'') }} - onClear={()=>{setStartTime(null);setEndTime(null)}} /> + onClear={()=>{setStartTime('1970-1-1');setEndTime('2099-12-31')}} />
diff --git a/web/client/src/sections/service/containers/temporaryResponse.jsx b/web/client/src/sections/service/containers/temporaryResponse.jsx index dfb4c66..34d5930 100644 --- a/web/client/src/sections/service/containers/temporaryResponse.jsx +++ b/web/client/src/sections/service/containers/temporaryResponse.jsx @@ -61,7 +61,7 @@ const SetControl = (props) => { } //console.log('service',response) dispatch(service.delMaintenancePlan(query)).then((res)=>{ - if(res.success) getResponse() + if(res.success) getResponse({type:'temp',msg:'获取临时响应',pageIndex:1,pageSize});setPageIndex(1) }) } const columns = [ @@ -103,7 +103,7 @@ const SetControl = (props) => { { title: '实际完成时间', render:(record)=>{ - return {moment(record.actualFinishTime).format('YYYY-MM-DD')} + return record.actualFinishTime?{moment(record.actualFinishTime).format('YYYY-MM-DD')}:'' }, }, @@ -115,7 +115,7 @@ const SetControl = (props) => { title: '操作', render:(record)=>{ return (
- + {delHandler(record)}}>
) }