From 80b02c2695d692285ca80b617e4e8e1f61f3b22c Mon Sep 17 00:00:00 2001 From: zhouxin Date: Tue, 20 Dec 2022 17:59:07 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E5=9F=B9=E8=AE=AD=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=BA=93=E5=B7=A6=E4=BE=A7=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/resourceRepository/index.js | 44 ++++++++++++++++--- .../lib/routes/resourceRepository/index.js | 7 ++- .../schema/01 create_training_information.sql | 29 ++++++++++++ .../actions/resourceRepository.js | 4 +- .../containers/resourceRepository.jsx | 29 ++++++++++-- 5 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 doc/scripts/PEP V3.2.0/schema/01 create_training_information.sql diff --git a/api/app/lib/controllers/resourceRepository/index.js b/api/app/lib/controllers/resourceRepository/index.js index cd70a08..53edb19 100644 --- a/api/app/lib/controllers/resourceRepository/index.js +++ b/api/app/lib/controllers/resourceRepository/index.js @@ -147,6 +147,11 @@ async function getResourceFileList(ctx, next) { findObj.where = where; } if ("公司培训资料" == type) { + if (findObj.where) { + findObj.where.fileName = { $not: null }; + } else { + findObj.where = { fileName: { $not: null } }; + } rlst = await models.TrainingInformation.findAndCountAll(findObj); } else { rlst = await models.DeptTraining.findAndCountAll(findObj); @@ -163,6 +168,7 @@ async function getResourceFileList(ctx, next) { } } async function postResourceClassify(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); try { const { models } = ctx.fs.dc; const { departmentName, trainDate } = ctx.request.body; @@ -180,17 +186,19 @@ async function postResourceClassify(ctx) { await models.TrainingInformation.create({ departmentName: departmentName, trainDate: trainDate - }) + }, { transaction }) } } - + await transaction.commit(); ctx.status = 204; } catch (err) { + await transaction.rollback(); ctx.status = 400; ctx.body = { message: err.message || '新增培训资源储备库文件夹失败' } } } async function putResourceClassify(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); try { const { models } = ctx.fs.dc; const { oldDepName, oldTrainDate, departmentName, trainDate } = ctx.request.body; @@ -199,24 +207,50 @@ async function putResourceClassify(ctx) { if (trainDate && '' != trainDate && oldTrainDate && '' != oldTrainDate) { where.trainDate = oldTrainDate; - await models.TrainingInformation.update({ trainDate: trainDate }, { where }); + await models.TrainingInformation.update({ trainDate: trainDate }, { where, transaction }); //三级目录 } else { //二级目录 - await models.TrainingInformation.update({ departmentName: departmentName }, { where }); + await models.TrainingInformation.update({ departmentName: departmentName }, { where, transaction }); } } + await transaction.commit(); ctx.status = 204; } catch (err) { + await transaction.rollback(); ctx.status = 400; ctx.body = { message: err.message || '编辑培训资源储备库文件夹失败' }; } } +async function delResourceClassify(ctx) { + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const { departmentName, trainDate } = ctx.query; + const { models } = ctx.fs.dc; + + if (departmentName && '' != departmentName) { + const where = { departmentName }; + if (trainDate && '' != trainDate) { + where.trainDate = trainDate; + } + await models.TrainingInformation.destroy({ where, transaction }); + } + + await transaction.commit(); + ctx.status = 204; + } catch (err) { + await transaction.rollback(); + ctx.status = 400; + ctx.body = { message: err.message || '新增培训资源储备库文件夹失败' } + } +} + module.exports = { getResourceClassify, getResourceFileList, postResourceClassify, - putResourceClassify + putResourceClassify, + delResourceClassify } \ No newline at end of file diff --git a/api/app/lib/routes/resourceRepository/index.js b/api/app/lib/routes/resourceRepository/index.js index 59f5727..61716a7 100644 --- a/api/app/lib/routes/resourceRepository/index.js +++ b/api/app/lib/routes/resourceRepository/index.js @@ -10,10 +10,13 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/train/trainFiles/resourceRepository/fileList'] = { content: '查询培训资源储备库文件列表', visible: false }; router.get('/train/trainFiles/resourceRepository/fileList', resourceRepository.getResourceFileList); - app.fs.api.logAttr['POST/train/trainFiles/resourceRepository/classify'] = { content: '新增培训资源储备库文件夹', visible: false }; + app.fs.api.logAttr['POST/train/trainFiles/resourceRepository/classify'] = { content: '新增培训资源储备库文件夹', visible: true }; router.post('/train/trainFiles/resourceRepository/classify', resourceRepository.postResourceClassify); - app.fs.api.logAttr['PUT/train/trainFiles/resourceRepository/classify'] = { content: '编辑培训资源储备库文件夹', visible: false }; + app.fs.api.logAttr['PUT/train/trainFiles/resourceRepository/classify'] = { content: '编辑培训资源储备库文件夹', visible: true }; router.put('/train/trainFiles/resourceRepository/classify', resourceRepository.putResourceClassify); + app.fs.api.logAttr['DELETE/train/trainFiles/resourceRepository/classify'] = { content: '删除培训资源储备库文件夹', visible: true }; + router.delete('/train/trainFiles/resourceRepository/classify', resourceRepository.delResourceClassify); + }; \ No newline at end of file diff --git a/doc/scripts/PEP V3.2.0/schema/01 create_training_information.sql b/doc/scripts/PEP V3.2.0/schema/01 create_training_information.sql new file mode 100644 index 0000000..19006c7 --- /dev/null +++ b/doc/scripts/PEP V3.2.0/schema/01 create_training_information.sql @@ -0,0 +1,29 @@ +create table training_information +( + id serial not null + constraint training_information_record_pkey + primary key, + departmentname varchar(255) not null, + traindate varchar(255), + filetype varchar(255), + filename varchar(255), + filesize varchar(255), + updatedate timestamp, + attachpath varchar(255) +); + +comment on table training_information is '公司培训资源库'; + +comment on column training_information.departmentname is '部门分类'; + +comment on column training_information.traindate is '时间(三级目录)'; + +comment on column training_information.filetype is '文件类型'; + +comment on column training_information.filename is '文件名'; + +comment on column training_information.filesize is '文件大小'; + +comment on column training_information.updatedate is '更新时间'; + +comment on column training_information.attachpath is '文件路径'; diff --git a/web/client/src/sections/humanAffairs/actions/resourceRepository.js b/web/client/src/sections/humanAffairs/actions/resourceRepository.js index 054831d..1ecdd42 100644 --- a/web/client/src/sections/humanAffairs/actions/resourceRepository.js +++ b/web/client/src/sections/humanAffairs/actions/resourceRepository.js @@ -48,11 +48,11 @@ export function putResourceClassify(data) { }); } -export function delResourceClassify(data) { +export function delResourceClassify(query) { return (dispatch) => basicAction({ type: "del", - query: data, + query: query, dispatch: dispatch, actionType: "DEL_RESOURCE_CLASSIFY", url: `${ApiTable.delResourceClassify}`, diff --git a/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx b/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx index 2f38afc..a12696d 100644 --- a/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx +++ b/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx @@ -1,6 +1,6 @@ import React, { useEffect, useState, useRef } from 'react'; import { connect } from 'react-redux'; -import { Button, Col, Row, Input, Tree, Table, Space, Tooltip, Spin, Notification } from '@douyinfe/semi-ui'; +import { Button, Col, Row, Input, Tree, Table, Space, Tooltip, Spin, Popconfirm } from '@douyinfe/semi-ui'; import { IconSearch, IconEditStroked, IconMinusCircleStroked, IconPlusCircleStroked } from '@douyinfe/semi-icons'; import { getResourceClassify, getResourceFileList, postResourceClassify, putResourceClassify, delResourceClassify } from '../actions/resourceRepository'; import FolderModal from '../components/resourceRepository/folder-model'; @@ -54,7 +54,15 @@ const ResourceRepository = (props) => { {true == data.operation ? handleFolderClick(child ? '编辑' : '编辑子', !child, key[1], key[2] || undefined)} /> - alert("sahnchu")} /> + handleDel(data.key)} + // onCancel={onCancel} + > + + + {child ? { } }); } - + } + + const handleDel = (key) => { + const arr = key.split('/'); + const query = { + departmentName: arr[1] + } + if (arr.length == 3) { + query.trainDate = arr[2]; + } + dispatch(delResourceClassify(query)).then(res => { + if (res.success) { + getClassify(); + setModelVisiable(false); + } + }); } const getFile = (e) => { const arr = e.split("/");