Browse Source

(*)培训资源库左侧删除

master
周沫沫历险记 2 years ago
parent
commit
80b02c2695
  1. 44
      api/app/lib/controllers/resourceRepository/index.js
  2. 7
      api/app/lib/routes/resourceRepository/index.js
  3. 29
      doc/scripts/PEP V3.2.0/schema/01 create_training_information.sql
  4. 4
      web/client/src/sections/humanAffairs/actions/resourceRepository.js
  5. 27
      web/client/src/sections/humanAffairs/containers/resourceRepository.jsx

44
api/app/lib/controllers/resourceRepository/index.js

@ -147,6 +147,11 @@ async function getResourceFileList(ctx, next) {
findObj.where = where; findObj.where = where;
} }
if ("公司培训资料" == type) { if ("公司培训资料" == type) {
if (findObj.where) {
findObj.where.fileName = { $not: null };
} else {
findObj.where = { fileName: { $not: null } };
}
rlst = await models.TrainingInformation.findAndCountAll(findObj); rlst = await models.TrainingInformation.findAndCountAll(findObj);
} else { } else {
rlst = await models.DeptTraining.findAndCountAll(findObj); rlst = await models.DeptTraining.findAndCountAll(findObj);
@ -163,6 +168,7 @@ async function getResourceFileList(ctx, next) {
} }
} }
async function postResourceClassify(ctx) { async function postResourceClassify(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { departmentName, trainDate } = ctx.request.body; const { departmentName, trainDate } = ctx.request.body;
@ -180,17 +186,19 @@ async function postResourceClassify(ctx) {
await models.TrainingInformation.create({ await models.TrainingInformation.create({
departmentName: departmentName, departmentName: departmentName,
trainDate: trainDate trainDate: trainDate
}) }, { transaction })
} }
} }
await transaction.commit();
ctx.status = 204; ctx.status = 204;
} catch (err) { } catch (err) {
await transaction.rollback();
ctx.status = 400; ctx.status = 400;
ctx.body = { message: err.message || '新增培训资源储备库文件夹失败' } ctx.body = { message: err.message || '新增培训资源储备库文件夹失败' }
} }
} }
async function putResourceClassify(ctx) { async function putResourceClassify(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { oldDepName, oldTrainDate, departmentName, trainDate } = ctx.request.body; const { oldDepName, oldTrainDate, departmentName, trainDate } = ctx.request.body;
@ -199,24 +207,50 @@ async function putResourceClassify(ctx) {
if (trainDate && '' != trainDate && oldTrainDate && '' != oldTrainDate) { if (trainDate && '' != trainDate && oldTrainDate && '' != oldTrainDate) {
where.trainDate = oldTrainDate; where.trainDate = oldTrainDate;
await models.TrainingInformation.update({ trainDate: trainDate }, { where }); await models.TrainingInformation.update({ trainDate: trainDate }, { where, transaction });
//三级目录 //三级目录
} else { } else {
//二级目录 //二级目录
await models.TrainingInformation.update({ departmentName: departmentName }, { where }); await models.TrainingInformation.update({ departmentName: departmentName }, { where, transaction });
} }
} }
await transaction.commit();
ctx.status = 204; ctx.status = 204;
} catch (err) { } catch (err) {
await transaction.rollback();
ctx.status = 400; ctx.status = 400;
ctx.body = { message: err.message || '编辑培训资源储备库文件夹失败' }; 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 = { module.exports = {
getResourceClassify, getResourceClassify,
getResourceFileList, getResourceFileList,
postResourceClassify, postResourceClassify,
putResourceClassify putResourceClassify,
delResourceClassify
} }

7
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 }; app.fs.api.logAttr['GET/train/trainFiles/resourceRepository/fileList'] = { content: '查询培训资源储备库文件列表', visible: false };
router.get('/train/trainFiles/resourceRepository/fileList', resourceRepository.getResourceFileList); 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); 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); 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);
}; };

29
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 '文件路径';

4
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) => return (dispatch) =>
basicAction({ basicAction({
type: "del", type: "del",
query: data, query: query,
dispatch: dispatch, dispatch: dispatch,
actionType: "DEL_RESOURCE_CLASSIFY", actionType: "DEL_RESOURCE_CLASSIFY",
url: `${ApiTable.delResourceClassify}`, url: `${ApiTable.delResourceClassify}`,

27
web/client/src/sections/humanAffairs/containers/resourceRepository.jsx

@ -1,6 +1,6 @@
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'react-redux'; 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 { IconSearch, IconEditStroked, IconMinusCircleStroked, IconPlusCircleStroked } from '@douyinfe/semi-icons';
import { getResourceClassify, getResourceFileList, postResourceClassify, putResourceClassify, delResourceClassify } from '../actions/resourceRepository'; import { getResourceClassify, getResourceFileList, postResourceClassify, putResourceClassify, delResourceClassify } from '../actions/resourceRepository';
import FolderModal from '../components/resourceRepository/folder-model'; import FolderModal from '../components/resourceRepository/folder-model';
@ -54,7 +54,15 @@ const ResourceRepository = (props) => {
{true == data.operation ? {true == data.operation ?
<span className='tree-icon'> <span className='tree-icon'>
<IconEditStroked size='default' onClick={() => handleFolderClick(child ? '编辑' : '编辑子', !child, key[1], key[2] || undefined)} /> <IconEditStroked size='default' onClick={() => handleFolderClick(child ? '编辑' : '编辑子', !child, key[1], key[2] || undefined)} />
<IconMinusCircleStroked size='default' onClick={() => alert("sahnchu")} /> <Popconfirm
title="确定是否要删除?"
content="该文件夹下的所有子文件/附件将永久删除,请慎重!"
onConfirm={() => handleDel(data.key)}
// onCancel={onCancel}
>
<IconMinusCircleStroked size='default' />
</Popconfirm>
{child ? {child ?
<IconPlusCircleStroked <IconPlusCircleStroked
size='default' size='default'
@ -88,7 +96,22 @@ const ResourceRepository = (props) => {
} }
}); });
} }
}
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 getFile = (e) => {
const arr = e.split("/"); const arr = e.split("/");

Loading…
Cancel
Save