Browse Source

修改bug

dev
zhaobing 2 years ago
parent
commit
bbe5e7bba0
  1. 63
      api/app/lib/controllers/record/index.js
  2. 4
      api/app/lib/routes/record/index.js
  3. 20
      web/client/src/sections/service/actions/record.js
  4. 3
      web/client/src/sections/service/components/cycAddmodal.jsx
  5. 27
      web/client/src/sections/service/components/recordModal.jsx
  6. 6
      web/client/src/sections/service/containers/cyclePlan.jsx
  7. 40
      web/client/src/sections/service/containers/serviceRecord.jsx
  8. 6
      web/client/src/sections/service/containers/temporaryResponse.jsx

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

@ -7,7 +7,8 @@ async function getRecord(ctx) {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const sequelize = ctx.fs.dc.ORM; const sequelize = ctx.fs.dc.ORM;
const { startTime, endTime, pageSize, pageIndex } = ctx.query const { startTime, endTime, pageSize, pageIndex } = ctx.query
//console.log('queryz', ctx.query) console.log('queryz', ctx.query)
let resCount = await models.MaintenanceRecord.count({ let resCount = await models.MaintenanceRecord.count({
where: { where: {
$and: [ $and: [
@ -76,22 +77,37 @@ async function getRecord(ctx) {
} }
} }
} }
//新增服务记录 //新增和编辑服务记录
async function addRecord(ctx) { 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
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 { 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) //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(); await transaction.commit();
ctx.status = 200 ctx.status = 200
} catch (error) { } catch (error) {
@ -100,14 +116,33 @@ async function addRecord(ctx) {
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 = {
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 = { module.exports = {
getRecord, addRecord getRecord, addRecord, delRecord
}; };

4
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 }; app.fs.api.logAttr['GET/record'] = { content: '获取服务记录列表', visible: true };
router.get('/record', record.getRecord); 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); router.put('/record', record.addRecord);
app.fs.api.logAttr['DEL/record/:id'] = { content: '删除服务记录', visible: true };
router.del('/record/:id', record.delRecord);
}; };

20
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({ return dispatch => basicAction({
type: 'put', type: 'put',
dispatch: dispatch, dispatch: dispatch,
data: query, data: query,
actionType: 'ADD_RECORD', actionType: 'ADD_RECORD',
url: `${ApiTable.addRecord}`, url: `${ApiTable.addRecord}`,
msg: { option: '新增服务记录' } msg: { option: msg }
}); });
} }
@ -42,5 +46,17 @@ export function calculability(query) {//计算系统可用性
params: { noClear: true } 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: '删除服务记录' },
}); });
} }

3
web/client/src/sections/service/components/cycAddmodal.jsx

@ -27,7 +27,8 @@ const okHandler=()=>{
msg:recordRow?'编辑周期性计划':'添加周期性计划' msg:recordRow?'编辑周期性计划':'添加周期性计划'
} }
dispatch(service.editMaintenancePlan(query)).then((res)=>{ dispatch(service.editMaintenancePlan(query)).then((res)=>{
if(res.success) onClose() if(res.success) onClose() ; api.current.reset()
}) })

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

@ -17,6 +17,7 @@ const RecordModal =(props)=>{
// console.log('endTimex',endTime) // console.log('endTimex',endTime)
useEffect(()=>{ useEffect(()=>{
setEndTime(recordRow?.solvingTime) setEndTime(recordRow?.solvingTime)
console.log('recordRow',recordRow)
},[recordRow]) },[recordRow])
const cancelHandler=()=>{ const cancelHandler=()=>{
onClose() onClose()
@ -26,14 +27,16 @@ const cancelHandler=()=>{
} }
const okHandler=()=>{ const okHandler=()=>{
FormApi.current.validate().then((res)=>{ FormApi.current.validate().then((res)=>{
// console.log('res',res) console.log('recordRow',res)
const editVal={ const editVal={
id:recordRow?.id,
solvingTime:res.endTime, solvingTime:res.endTime,
occurrencTime:res.startTime, occurrencTime:res.startTime,
sketch:res.name, sketch:res.name,
record:res.record, record:res.record,
settler:res.settler, settler:res.settler,
type:res.type type:res.type,
msg:recordRow?'编辑服务记录':'添加服务记录'
} }
dispatch(service.addRecord(editVal)).then(res => { dispatch(service.addRecord(editVal)).then(res => {
if (res.success) { if (res.success) {
@ -45,9 +48,11 @@ const okHandler=()=>{
}) })
} }
return <Modal return <Modal
title={recordRow?'查看':'服务记录添加'} title={recordRow?'编辑服务记录':'服务记录添加'}
visible={visible} visible={visible}
footer={recordRow?<Button onClick={cancelHandler}>取消</Button>:<div> footer={
//recordRow?<Button onClick={cancelHandler}></Button>:
<div>
<Button onClick={cancelHandler}>取消</Button> <Button onClick={cancelHandler}>取消</Button>
<Button theme='solid' type='primary' onClick={okHandler}>确定</Button> <Button theme='solid' type='primary' onClick={okHandler}>确定</Button>
</div>} </div>}
@ -56,24 +61,24 @@ const okHandler=()=>{
> >
<Form wrapperCol={{ span: 20 }} <Form wrapperCol={{ span: 20 }}
initValues={{'name':recordRow?.sketch,'startTime':recordRow?.occurrenceTime, initValues={{'name':recordRow?.sketch,'startTime':recordRow?.occurrenceTime,
'endTime':recordRow?.solvingTime,'settler':recordRow?.maintenanceRecordExecuteUsers.map((item)=>{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} getFormApi={formApi => FormApi.current = formApi}
labelPosition='left' labelPosition='left'
labelAlign='right'> labelAlign='right'>
<Form.Input field='name' label='故障简述:' trigger='blur' <Form.Input field='name' label='故障简述:' trigger='blur'
disabled={recordRow?true:false}
placeholder='选择或搜索项目' rules={[{ required: true, message:'请输入故障简述' }]} maxLength={30}/> placeholder='选择或搜索项目' rules={[{ required: true, message:'请输入故障简述' }]} maxLength={30}/>
<Form.DatePicker disabled={recordRow?true:false} field='startTime' label='发生时间:' rules={[{ required: true, message:'请输入发生时间' }]} <Form.DatePicker field='startTime' label='发生时间:' rules={[{ required: true, message:'请输入发生时间' }]}
type="dateTime" onChange={(e)=>{ type="dateTime" onChange={(e)=>{
setStartTime(e) setStartTime(e)
///console.log('e1',e) ///console.log('e1',e)
}} }}
/> />
<Form.DatePicker disabled={recordRow?true:false} 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)=>{setEndTime(e);//console.log('sss',moment(endTime-startTime).format('DDhhmm'))
}} /> }} />
中断时间:{endTime&&startTime? <span style={{marginLeft:30}}>{`${tdd}${tdh}${tds}`}</span>:''} 中断时间:{endTime&&startTime? <span style={{marginLeft:30}}>{`${tdd}${tdh}${tds}`}</span>:''}
<Form.Select disabled={recordRow?true:false} 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>
{pepList?.map((item)=>{return ( <Form.Select.OptGroup label={item.name}> {pepList?.map((item)=>{return ( <Form.Select.OptGroup label={item.name}>
@ -83,7 +88,7 @@ const okHandler=()=>{
})} })}
</Form.Select.OptGroup> )})} </Form.Select.OptGroup> )})}
</Form.Select> </Form.Select>
<Form.Select disabled={recordRow?true:false} field="type" label={{ text: '故障类型'}} style={{ width: 200 }}> <Form.Select field="type" label={{ text: '故障类型'}} style={{ width: 200 }}>
<Form.Select.Option value="es异常">es异常</Form.Select.Option> <Form.Select.Option value="es异常">es异常</Form.Select.Option>
<Form.Select.Option value="数据库异常">数据库异常</Form.Select.Option> <Form.Select.Option value="数据库异常">数据库异常</Form.Select.Option>
<Form.Select.Option value="应用异常">应用异常</Form.Select.Option> <Form.Select.Option value="应用异常">应用异常</Form.Select.Option>
@ -91,7 +96,7 @@ const okHandler=()=>{
<Form.Select.Option value="服务器异常">服务器异常</Form.Select.Option> <Form.Select.Option value="服务器异常">服务器异常</Form.Select.Option>
<Form.Select.Option value="其他">其他</Form.Select.Option> <Form.Select.Option value="其他">其他</Form.Select.Option>
</Form.Select> </Form.Select>
<Form.TextArea disabled={recordRow?true:false} field="record" label={{text:'故障记录'}} rules={[{ required: true, message:'请输入故障记录' }]}> <Form.TextArea field="record" label={{text:'故障记录'}} rules={[{ required: true, message:'请输入故障记录' }]}>
</Form.TextArea> </Form.TextArea>
</Form> </Form>

6
web/client/src/sections/service/containers/cyclePlan.jsx

@ -34,7 +34,7 @@ const Server = (props) => {
msg:'删除周期性计划' msg:'删除周期性计划'
} }
dispatch(service.delMaintenancePlan(query)).then((res)=>{ 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: '实际完成时间', title: '实际完成时间',
render:(record)=>{ render:(record)=>{
return <span>{moment(record.actualFinishTime).format('YYYY-MM-DD')}</span> return record.actualFinishTime?<span>{moment(record.actualFinishTime).format('YYYY-MM-DD')}</span>:''
}, },
}, },
{ {
title: '操作', title: '操作',
render:(record)=>{ render:(record)=>{
return (<div> return (<div>
<Button onClick={()=>{setAddVis(true);setRecordRow(record)}}>编辑</Button> <Button onClick={()=>{setAddVis(true);setRecordRow(record)}} style={{marginRight:10}}>编辑</Button>
<Popconfirm title="确定是否删除?" onConfirm={()=>{delHandler(record)}}><Button type='danger'> 删除</Button></Popconfirm> <Popconfirm title="确定是否删除?" onConfirm={()=>{delHandler(record)}}><Button type='danger'> 删除</Button></Popconfirm>
</div>) </div>)
} }

40
web/client/src/sections/service/containers/serviceRecord.jsx

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import React, { useEffect,useState,useMemo } from 'react'; 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 moment from 'moment'
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import RecordModal from '../components/recordModal' import RecordModal from '../components/recordModal'
@ -40,7 +40,14 @@ const Server = (props) => {
setPepList(res.payload.data) 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(() => { useEffect(() => {
const query={ const query={
sTime, eTime sTime, eTime
@ -110,8 +117,26 @@ const Server = (props) => {
{ {
title: '当前状态', title: '当前状态',
render:(record)=>{ render:(record)=>{
return (<Button onClick={()=>{ setModalVis(true);setRecordRow(record) return <div>
}}>查看</Button>) <Button
style={{marginRight:10}}
onClick={() => {
setModalVis(true);setRecordRow(record)
}}
>
编辑
</Button>
<Popconfirm
title='确定是否删除?'
onConfirm={() => {
delHandler(record.id);
}}
>
<Button type='danger' > 删除</Button>
</Popconfirm>
</div>
}, },
}, },
]; ];
@ -165,7 +190,7 @@ const addHandler=()=>{
<DatePicker type="dateTimeRange" <DatePicker type="dateTimeRange"
onChange={e => onChangeDate(e) } onChange={e => onChangeDate(e) }
density="compact" density="compact"
style={{ width: 260 }} style={{ width: 400 }}
value={dateValue} value={dateValue}
onClear={()=>{clearHandler()}} onClear={()=>{clearHandler()}}
@ -182,9 +207,10 @@ const addHandler=()=>{
<span >产生时间</span> <span >产生时间</span>
<DatePicker type="dateRange" insetInput style={{ width: 280,marginLeft:10 }} onChange={(e)=>{ <DatePicker type="dateRange" insetInput style={{ width: 280,marginLeft:10 }} onChange={(e)=>{
setStartTime((e[0])+'');setEndTime(e[1]+'') }} setStartTime((e[0])+'');setEndTime(e[1]+'') }}
onClear={()=>{setStartTime(null);setEndTime(null)}} /> onClear={()=>{setStartTime('1970-1-1');setEndTime('2099-12-31')}} />
<Button style={{ marginLeft:20 }} onClick={()=>{ <Button style={{ marginLeft:20 }} onClick={()=>{
getRecordList({ startTime,endTime,pageIndex,pageSize}); setPageIndex(1);setPageSize(10)
getRecordList({ startTime,endTime,pageIndex:1,pageSize:10});
//console.log('setStartTime',startTime,'setEndTime',endTime) //console.log('setStartTime',startTime,'setEndTime',endTime)
}}>查询</Button> }}>查询</Button>
</div> </div>

6
web/client/src/sections/service/containers/temporaryResponse.jsx

@ -61,7 +61,7 @@ const SetControl = (props) => {
} }
//console.log('service',response) //console.log('service',response)
dispatch(service.delMaintenancePlan(query)).then((res)=>{ dispatch(service.delMaintenancePlan(query)).then((res)=>{
if(res.success) getResponse() if(res.success) getResponse({type:'temp',msg:'获取临时响应',pageIndex:1,pageSize});setPageIndex(1)
}) })
} }
const columns = [ const columns = [
@ -103,7 +103,7 @@ const SetControl = (props) => {
{ {
title: '实际完成时间', title: '实际完成时间',
render:(record)=>{ render:(record)=>{
return <span>{moment(record.actualFinishTime).format('YYYY-MM-DD')}</span> return record.actualFinishTime?<span>{moment(record.actualFinishTime).format('YYYY-MM-DD')}</span>:''
}, },
}, },
@ -115,7 +115,7 @@ const SetControl = (props) => {
title: '操作', title: '操作',
render:(record)=>{ render:(record)=>{
return (<div> return (<div>
<Button onClick={()=>{setAddVis(true);setRecordRow(record)}}>编辑</Button> <Button style={{marginRight:10}} onClick={()=>{setAddVis(true);setRecordRow(record)}}>编辑</Button>
<Popconfirm title="确定是否删改?" onConfirm={()=>{delHandler(record)}}><Button type='danger'> 删除</Button></Popconfirm> <Popconfirm title="确定是否删改?" onConfirm={()=>{delHandler(record)}}><Button type='danger'> 删除</Button></Popconfirm>
</div>) </div>)
} }

Loading…
Cancel
Save