From ca394e92eb4c87201050b1f53b5c6782cca99faf Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Tue, 21 Feb 2023 15:33:02 +0800 Subject: [PATCH] =?UTF-8?q?(+)=20=E6=A3=80=E6=9F=A5=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/patrolManage/checkItems.js | 140 +++++++++++++++++ api/app/lib/routes/patrolManage/checkItems.js | 31 ++++ .../patrolManage/actions/checkItems.js | 76 +++++++++ .../sections/patrolManage/actions/index.js | 2 + .../components/checkItemsModal.js | 112 ++++++++++++++ .../patrolManage/containers/checkItems.js | 146 ++++++++++++++++++ .../sections/patrolManage/containers/index.js | 5 +- .../src/sections/patrolManage/nav-item.js | 3 + .../src/sections/patrolManage/routes.js | 8 +- web/client/src/utils/webapi.js | 6 + 10 files changed, 526 insertions(+), 3 deletions(-) create mode 100644 api/app/lib/controllers/patrolManage/checkItems.js create mode 100644 api/app/lib/routes/patrolManage/checkItems.js create mode 100644 web/client/src/sections/patrolManage/actions/checkItems.js create mode 100644 web/client/src/sections/patrolManage/components/checkItemsModal.js create mode 100644 web/client/src/sections/patrolManage/containers/checkItems.js diff --git a/api/app/lib/controllers/patrolManage/checkItems.js b/api/app/lib/controllers/patrolManage/checkItems.js new file mode 100644 index 0000000..a6dca43 --- /dev/null +++ b/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, +} \ No newline at end of file diff --git a/api/app/lib/routes/patrolManage/checkItems.js b/api/app/lib/routes/patrolManage/checkItems.js new file mode 100644 index 0000000..f6874ae --- /dev/null +++ b/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); + +}; \ No newline at end of file diff --git a/web/client/src/sections/patrolManage/actions/checkItems.js b/web/client/src/sections/patrolManage/actions/checkItems.js new file mode 100644 index 0000000..b98fe62 --- /dev/null +++ b/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, +} \ No newline at end of file diff --git a/web/client/src/sections/patrolManage/actions/index.js b/web/client/src/sections/patrolManage/actions/index.js index c465b0f..1e56c03 100644 --- a/web/client/src/sections/patrolManage/actions/index.js +++ b/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, } \ No newline at end of file diff --git a/web/client/src/sections/patrolManage/components/checkItemsModal.js b/web/client/src/sections/patrolManage/components/checkItemsModal.js new file mode 100644 index 0000000..aaeb857 --- /dev/null +++ b/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 ( + { + 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); + }); + }} + > +
p.id), + userDept: curRecord?.user?.department?.name, + }} + disabled={type === 'view'} + > + + + + + { + isNewGroup ? + + } + +
+ +
+ ); +}; + +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); \ No newline at end of file diff --git a/web/client/src/sections/patrolManage/containers/checkItems.js b/web/client/src/sections/patrolManage/containers/checkItems.js new file mode 100644 index 0000000..63858ad --- /dev/null +++ b/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
{record?.check_items_group?.name}
+ } + }, { + title: '操作', + dataIndex: 'action', + key: 'action', + search: false, + width: 200, + render: (_, record) => { + return <> + + { + dispatch(delPatrolPlan(record.id)).then(res => { + if (res.success) { + tableRef.current.reload(); + } + }) + }}> + + + + }, + }]; + + return ( + <> + { + const res = await dispatch(getCheckItems(params)); + setDataSource(res?.payload.data?.rows); + return { ...res }; + }} + onReset={() => { }} + search={{ + defaultCollapsed: false, + optionRender: (searchConfig, formProps, dom) => [ + ...dom.reverse(), + , + , + ], + }} + rowSelection={{ + selectedRowKeys: select?.map(v => v.id) || [], + onChange: (selectedRowKeys, selectedRows) => { + setSelect(selectedRows) + } + }} + /> + { + visible ? + { + setVisible(false); + }} + /> : null + } + + ) +} + +function mapStateToProps(state) { + const { auth } = state + return { + user: auth.user + } +} +export default connect(mapStateToProps)(CheckItems); diff --git a/web/client/src/sections/patrolManage/containers/index.js b/web/client/src/sections/patrolManage/containers/index.js index 480a30c..acdb15d 100644 --- a/web/client/src/sections/patrolManage/containers/index.js +++ b/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 }; \ No newline at end of file +export { PatrolPlan, PatrolReocrd, CheckItems, PlanTemplate }; \ No newline at end of file diff --git a/web/client/src/sections/patrolManage/nav-item.js b/web/client/src/sections/patrolManage/nav-item.js index 86bda99..62639a8 100644 --- a/web/client/src/sections/patrolManage/nav-item.js +++ b/web/client/src/sections/patrolManage/nav-item.js @@ -17,6 +17,9 @@ export function getNavItem (user, dispatch) { 巡检记录 + + 检查项设定 + 巡检模板 diff --git a/web/client/src/sections/patrolManage/routes.js b/web/client/src/sections/patrolManage/routes.js index e2f75b8..ba0f6e4 100644 --- a/web/client/src/sections/patrolManage/routes.js +++ b/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', diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index ce46c8a..f0c4216 100644 --- a/web/client/src/utils/webapi.js +++ b/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',