Browse Source

(+) 检查项

master
liujiangyong 2 years ago
parent
commit
ca394e92eb
  1. 140
      api/app/lib/controllers/patrolManage/checkItems.js
  2. 31
      api/app/lib/routes/patrolManage/checkItems.js
  3. 76
      web/client/src/sections/patrolManage/actions/checkItems.js
  4. 2
      web/client/src/sections/patrolManage/actions/index.js
  5. 112
      web/client/src/sections/patrolManage/components/checkItemsModal.js
  6. 146
      web/client/src/sections/patrolManage/containers/checkItems.js
  7. 5
      web/client/src/sections/patrolManage/containers/index.js
  8. 3
      web/client/src/sections/patrolManage/nav-item.js
  9. 8
      web/client/src/sections/patrolManage/routes.js
  10. 6
      web/client/src/utils/webapi.js

140
api/app/lib/controllers/patrolManage/checkItems.js

@ -0,0 +1,140 @@
'use strict';
async function getGroup(ctx, next) {
let error = { name: 'FindError', message: '获取检查项分组失败' };
let rslt = [];
try {
const models = ctx.fs.dc.models;
let list = await models.CheckItemsGroup.findAll({});
rslt = list;
error = null;
} catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
}
if (error) {
ctx.status = 400;
ctx.body = error;
} else {
ctx.status = 200;
ctx.body = rslt;
}
}
async function createGroup(ctx, next) {
const models = ctx.fs.dc.models;
try {
const data = ctx.request.body;
await models.CheckItemsGroup.create(data)
ctx.status = 204;
ctx.body = { message: '新建分组成功' }
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '新建分组失败' }
}
}
async function getCheckItems(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { limit, page } = ctx.query;
let options = {
order: [['id', 'asc']],
include: [{
required: true,
model: models.CheckItemsGroup,
attributes: ['id', 'name'],
}]
}
if (limit) {
options.limit = Number(limit);
}
if (page && limit) {
options.offset = Number(page) * Number(limit);
}
const userRes = await models.CheckItems.findAndCountAll(options)
ctx.status = 200;
ctx.body = userRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": "获取检查项失败"
}
}
}
async function createCheckItems(ctx, next) {
let errMsg = "新增检查项失败"
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
await models.CheckItems.create(data);
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": errMsg
}
}
}
async function updateCheckItems(ctx, next) {
let errMsg = "修改检查项失败"
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
const { id } = ctx.params;
await models.CheckItems.update({
name: data.name,
}, {
where: {
id: id
}
});
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": errMsg
}
}
}
async function deleteCheckItems(ctx, next) {
try {
const models = ctx.fs.dc.models;
const { ids } = ctx.params;
const userIds = ids.split(',');
await models.CheckItems.destroy({
where: {
id: { $in: userIds },
}
});
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
"message": "删除检查项失败"
}
}
}
module.exports = {
getGroup,
createGroup,
getCheckItems,
createCheckItems,
updateCheckItems,
deleteCheckItems,
}

31
api/app/lib/routes/patrolManage/checkItems.js

@ -0,0 +1,31 @@
'use strict';
const checkItems = require('../../controllers/patrolManage/checkItems');
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/checkItems/group'] = { content: '获取分组信息', visible: false };
router.get('/checkItems/group', checkItems.getGroup);
app.fs.api.logAttr['POST/checkItems/group'] = { content: '新增分组', visible: false };
router.post('/checkItems/group', checkItems.createGroup);
// app.fs.api.logAttr['PUT/organization/dept/:id/modify'] = { content: '修改部门', visible: true };
// router.put('/organization/dept/:id/modify', checkItems.updateDept);
// app.fs.api.logAttr['DELETE/organization/dept/:id'] = { content: '删除部门', visible: true };
// router.del('/organization/dept/:id', checkItems.delDept);
app.fs.api.logAttr['GET/checkItems'] = { content: '获取检查项', visible: false };
router.get('/checkItems', checkItems.getCheckItems);
app.fs.api.logAttr['POST/checkItems'] = { content: '新增检查项', visible: false };
router.post('/checkItems', checkItems.createCheckItems);
app.fs.api.logAttr['PUT/checkItems/:id'] = { content: '修改检查项', visible: false };
router.put('/checkItems/:id', checkItems.updateCheckItems);
app.fs.api.logAttr['DEL/checkItems/:ids'] = { content: '删除检查项', visible: false };
router.del('/checkItems/:ids', checkItems.deleteCheckItems);
};

76
web/client/src/sections/patrolManage/actions/checkItems.js

@ -0,0 +1,76 @@
'use strict';
import { basicAction } from '@peace/utils'
import { ApiTable } from '$utils'
export function getCheckItemsGroup() {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_CHECK_ITEMS_GRROUP',
url: ApiTable.checkItemsGroup,
msg: { error: '获取检查项分组失败' },
});
}
export function createCheckItemsGroup(data) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'CREATE_CHECK_ITEMS_GRROUP',
url: ApiTable.checkItemsGroup,
msg: { option: '创建检查项分组' },
});
}
export function getCheckItems() {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
actionType: 'GET_CHECK_ITEMS',
url: ApiTable.checkItems,
msg: { error: '获取检查项失败' }
});
}
export function createCheckItems(data) {
return dispatch => basicAction({
type: 'post',
data,
dispatch: dispatch,
actionType: 'CREATE_CHECK_ITEMS',
url: ApiTable.checkItems,
msg: { option: '新建检查项' },
});
}
export function updateCheckItems(id, data) {
return dispatch => basicAction({
type: 'put',
data,
dispatch: dispatch,
actionType: 'UPDATE_CHECK_ITEMS',
url: ApiTable.updateCheckItems.replace('{id}', id),
msg: { option: '修改检查项' },
});
}
export function delCheckItems(ids) {
return dispatch => basicAction({
type: 'del',
dispatch: dispatch,
actionType: 'DEL_CHECK_ITEMS',
url: ApiTable.delUser.replace('{ids}', ids),
msg: { option: '删除检查项' },
});
}
export default {
getCheckItemsGroup,
createCheckItemsGroup,
getCheckItems,
createCheckItems,
updateCheckItems,
delCheckItems,
}

2
web/client/src/sections/patrolManage/actions/index.js

@ -2,8 +2,10 @@
import * as plan from './plan'
import * as record from './record'
import * as checkItems from './checkItems'
export default {
...plan,
...record,
...checkItems,
}

112
web/client/src/sections/patrolManage/components/checkItemsModal.js

@ -0,0 +1,112 @@
import { Button, Form, Input, Modal, Select } from 'antd';
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import { getUserList, getProjectList, positionList } from '../actions/plan';
import { getCheckItemsGroup } from '../actions/checkItems';
import moment from 'moment';
const CheckItemsModal = ({ visible, onCreate, onCancel, dispatch, type, curRecord }) => {
const [pointOpt, setPointOpt] = useState();
const [points, setPoints] = useState();
const [isNewGroup, setIsNewGroup] = useState(false);
const [form] = Form.useForm();
useEffect(() => {
dispatch(getCheckItemsGroup());
if (type === 'create') {
dispatch(getUserList())
} else {
dispatch(positionList({ projectId: curRecord?.project?.id })).then(res => {
if (res.success) {
setPoints(res.payload.data?.rows)
setPointOpt(res.payload.data?.rows[0]?.points?.map(p => ({ label: p.name, value: p.id })))
}
})
}
}, [])
return (
<Modal
visible={visible}
title="新增巡检计划"
okText="确定"
cancelText="取消"
onCancel={() => {
form.resetFields();
onCancel();
}}
onOk={() => {
if (type === 'view') {
form.resetFields();
onCancel();
return;
}
form
.validateFields()
.then((values) => {
form.resetFields();
const params = {
...values,
startTime: values.time[0],
endTime: values.time[1],
points: points[0]?.points?.filter(p => values?.points?.includes(p.id))
}
onCreate(params);
})
.catch((info) => {
console.log('Validate Failed:', info);
});
}}
>
<Form
form={form}
layout="vertical"
name="form_in_modal"
initialValues={{
...curRecord,
points: curRecord?.points?.map(p => p.id),
userDept: curRecord?.user?.department?.name,
}}
disabled={type === 'view'}
>
<Form.Item
name="name"
label="检查项名称"
rules={[
{ required: true, message: '请输入检查项名称' },
]}
>
<Input />
</Form.Item>
<Form.Item
name="groupName"
label="分组名称"
rules={[
{ required: true, message: '请选择分组' },
]}
>
{
isNewGroup ?
<Select options={pointOpt} disabled={!pointOpt || type === 'view'} /> :
<Input />
}
</Form.Item>
</Form>
<Button type='link' onClick={() => {
setIsNewGroup(!isNewGroup);
}}>创建分组</Button>
</Modal >
);
};
function mapStateToProps(state) {
const { auth, userList, structureList } = state
return {
user: auth.user,
userList: userList.data || [],
structureList: structureList.data || [],
userLoading: userList.isRequesting,
struLoading: structureList.isRequesting
}
}
export default connect(mapStateToProps)(CheckItemsModal);

146
web/client/src/sections/patrolManage/containers/checkItems.js

@ -0,0 +1,146 @@
import React, { useState, useRef } from 'react';
import { connect } from 'react-redux';
import { Button, Popconfirm } from 'antd';
import ProTable from '@ant-design/pro-table';
import CheckItemsModal from '../components/checkItemsModal';
import { createPatrolPlan, delPatrolPlan, updatePatrolPlan } from '../actions/plan';
import { getCheckItems } from '../actions/checkItems';
import moment from 'moment';
function CheckItems(props) {
const { dispatch, user } = props;
const tableRef = useRef();
const [dataSource, setDataSource] = useState([{}]);
const [visible, setVisible] = useState(false);
const [type, setType] = useState();
const [curRecord, setCurRecord] = useState();
const [select, setSelect] = useState([]);
const onCreate = (values) => {
if (type === 'create') {
dispatch(createPatrolPlan(values)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
} else {
dispatch(updatePatrolPlan({ ...values, id: curRecord.id })).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}
setVisible(false);
};
const columns = [{
title: '检查项',
dataIndex: 'name',
key: 'name',
ellipsis: true,
width: 150,
}, {
title: '分组名称',
dataIndex: 'groupName',
key: 'groupName',
ellipsis: true,
search: false,
width: 150,
render: (_, record) => {
return <div>{record?.check_items_group?.name}</div>
}
}, {
title: '操作',
dataIndex: 'action',
key: 'action',
search: false,
width: 200,
render: (_, record) => {
return <>
<Button type="link" onClick={() => {
setType('edit')
setCurRecord(record)
setVisible(true)
}}>修改</Button>
<Popconfirm
title="确认删除?"
onConfirm={() => {
dispatch(delPatrolPlan(record.id)).then(res => {
if (res.success) {
tableRef.current.reload();
}
})
}}>
<Button type="link" danger>删除</Button>
</Popconfirm>
</>
},
}];
return (
<>
<ProTable
columns={columns}
actionRef={tableRef}
options={false}
dataSource={dataSource || []}
rowKey='id'
pagination={{ pageSize: 10 }}
request={async (params = {}) => {
const res = await dispatch(getCheckItems(params));
setDataSource(res?.payload.data?.rows);
return { ...res };
}}
onReset={() => { }}
search={{
defaultCollapsed: false,
optionRender: (searchConfig, formProps, dom) => [
...dom.reverse(),
<Button
key="add"
type='primary'
onClick={() => {
setType('create')
setVisible(true)
}}
>新增</Button>,
<Button
key="del"
type='primary'
onClick={() => {
const values = searchConfig?.form?.getFieldsValue();
console.log(values);
}}
>批量删除</Button>,
],
}}
rowSelection={{
selectedRowKeys: select?.map(v => v.id) || [],
onChange: (selectedRowKeys, selectedRows) => {
setSelect(selectedRows)
}
}}
/>
{
visible ?
<CheckItemsModal
visible={visible}
onCreate={onCreate}
type={type}
curRecord={curRecord}
onCancel={() => {
setVisible(false);
}}
/> : null
}
</>
)
}
function mapStateToProps(state) {
const { auth } = state
return {
user: auth.user
}
}
export default connect(mapStateToProps)(CheckItems);

5
web/client/src/sections/patrolManage/containers/index.js

@ -2,6 +2,7 @@
import PatrolPlan from './patrolPlan';
import PatrolReocrd from './patrolRecord';
import PlanTemplate from './patrolTemplate'
import CheckItems from './checkItems';
import PlanTemplate from './patrolTemplate';
export { PatrolPlan, PatrolReocrd, PlanTemplate };
export { PatrolPlan, PatrolReocrd, CheckItems, PlanTemplate };

3
web/client/src/sections/patrolManage/nav-item.js

@ -17,6 +17,9 @@ export function getNavItem (user, dispatch) {
<Menu.Item key="patrolRecord">
<Link to="/patrolManage/patrolRecord">巡检记录</Link>
</Menu.Item>
<Menu.Item key="checkItems">
<Link to="/patrolManage/checkItems">检查项设定</Link>
</Menu.Item>
<Menu.Item key="patrolTemplate">
<Link to="/patrolManage/patrolTemplate">巡检模板</Link>
</Menu.Item>

8
web/client/src/sections/patrolManage/routes.js

@ -1,5 +1,5 @@
'use strict';
import { PatrolPlan, PatrolReocrd, PlanTemplate } from './containers';
import { PatrolPlan, PatrolReocrd, CheckItems, PlanTemplate } from './containers';
export default [{
type: 'inner',
@ -17,6 +17,12 @@ export default [{
key: 'patrolRecord',
component: PatrolReocrd,
breadcrumb: '巡检记录',
},
{
path: '/checkItems',
key: 'checkItems',
component: CheckItems,
breadcrumb: '检查项设定',
}, {
path: '/patrolTemplate',
key: 'patrolTemplate',

6
web/client/src/utils/webapi.js

@ -26,6 +26,12 @@ export const ApiTable = {
// 巡检记录
patrolRecord: 'patrolRecord/:patrolPlanId/:startTime/:endTime/:alarm/:pointId',
// 检查项设定
checkItems: '/checkItems', // 获取/新增
updateCheckItems: '/checkItems/{id}',
delCheckItems: '/checkItems/{ids}',
checkItemsGroup: '/checkItems/group', // 获取/新增
// 用户权限
getResource: 'resource',
getUserResource: 'user/resource',

Loading…
Cancel
Save