7 changed files with 227 additions and 16 deletions
			
			
		| @ -0,0 +1,113 @@ | |||||
|  | 'use strict'; | ||||
|  | const moment = require('moment') | ||||
|  | 
 | ||||
|  | async function getResourceClassify(ctx) { | ||||
|  |     try { | ||||
|  |         const { models } = ctx.fs.dc; | ||||
|  |         const { limit, offset } = ctx.query; | ||||
|  |         let rlst = []; | ||||
|  |         const findObj = {} | ||||
|  |         if (Number(limit) > 0 && Number(offset) >= 0) { | ||||
|  |             findObj.limit = Number(limit); | ||||
|  |             findObj.offset = Number(offset); | ||||
|  |         } | ||||
|  |         const trainingInformationLevel = await models.TrainingInformationLevel.findAll(findObj); | ||||
|  |         if (trainingInformationLevel.length) { | ||||
|  |             rlst = [{ | ||||
|  |                 label: "公司培训资料", value: "company", key: "company", operation: true, | ||||
|  |             }, { label: "部门培训资料", value: 'dept', key: 'dept', operation: false }]; | ||||
|  | 
 | ||||
|  |             for (let level of trainingInformationLevel) { | ||||
|  |                 const { id, type, departmentname, traindate, origin } = level; | ||||
|  |                 /**type:1级, departmentname:2级,traindate:3级 */ | ||||
|  |                 const arrIndex = rlst.findIndex(item => item.label == type) | ||||
|  |                 if (arrIndex > -1) {//一级分类名称正确
 | ||||
|  |                     const operation = "import" == origin ? true : false; | ||||
|  |                     if (departmentname) { | ||||
|  |                         if (traindate) { | ||||
|  |                             //区分2级是否记录
 | ||||
|  |                             if (rlst[arrIndex].children) { | ||||
|  |                                 const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); | ||||
|  |                                 if (depIndex > -1) { | ||||
|  |                                     if (rlst[arrIndex].children[depIndex].children) { | ||||
|  |                                         rlst[arrIndex].children[depIndex].children.push({ | ||||
|  |                                             label: moment(traindate).format('YYYY-MM'), | ||||
|  |                                             value: id, | ||||
|  |                                             key: id, | ||||
|  |                                             operation | ||||
|  |                                         }) | ||||
|  |                                     } else { | ||||
|  |                                         rlst[arrIndex].children[depIndex].children = [{ | ||||
|  |                                             label: moment(traindate).format('YYYY-MM'), | ||||
|  |                                             value: id, | ||||
|  |                                             key: id, | ||||
|  |                                             operation | ||||
|  |                                         }] | ||||
|  |                                     } | ||||
|  |                                 } else { | ||||
|  |                                     rlst[arrIndex].children.push({ | ||||
|  |                                         label: departmentname, | ||||
|  |                                         children: [{ | ||||
|  |                                             label: moment(traindate).format('YYYY-MM'), | ||||
|  |                                             value: id, | ||||
|  |                                             key: id, | ||||
|  |                                             operation | ||||
|  |                                         }] | ||||
|  |                                     }); | ||||
|  |                                 } | ||||
|  |                             } else { | ||||
|  |                                 rlst[arrIndex].children = [{ | ||||
|  |                                     label: departmentname, | ||||
|  |                                     children: [{ | ||||
|  |                                         label: moment(traindate).format('YYYY-MM'), | ||||
|  |                                         value: id, | ||||
|  |                                         key: id, | ||||
|  |                                         operation | ||||
|  |                                     }] | ||||
|  |                                 }] | ||||
|  |                             } | ||||
|  |                         } else { | ||||
|  |                             if (rlst[arrIndex].children) { | ||||
|  |                                 const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); | ||||
|  |                                 if (depIndex > -1) { | ||||
|  |                                     if (!rlst[arrIndex].children[depIndex].value) { | ||||
|  |                                         rlst[arrIndex].children[depIndex].value = id; | ||||
|  |                                         rlst[arrIndex].children[depIndex].key = id; | ||||
|  |                                         rlst[arrIndex].children[depIndex].operation = operation; | ||||
|  |                                     } | ||||
|  |                                 } else { | ||||
|  |                                     rlst[arrIndex].children.push({ | ||||
|  |                                         label: departmentname, | ||||
|  |                                         value: id, | ||||
|  |                                         key: id, | ||||
|  |                                         operation | ||||
|  |                                     }) | ||||
|  |                                 } | ||||
|  |                             } else { | ||||
|  |                                 rlst[arrIndex].children = [{ | ||||
|  |                                     label: departmentname, | ||||
|  |                                     value: id, | ||||
|  |                                     key: id, | ||||
|  |                                     operation | ||||
|  |                                 }] | ||||
|  |                             } | ||||
|  |                         } | ||||
|  |                     } | ||||
|  |                 } | ||||
|  |             } | ||||
|  |         } | ||||
|  |         ctx.status = 200; | ||||
|  |         ctx.body = rlst; | ||||
|  |     } catch (error) { | ||||
|  |         ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); | ||||
|  |         ctx.status = 400; | ||||
|  |         ctx.body = { | ||||
|  |             message: '查询培训资源储备库分类目录失败' | ||||
|  |         } | ||||
|  |     } | ||||
|  | 
 | ||||
|  | } | ||||
|  | 
 | ||||
|  | module.exports = { | ||||
|  |     getResourceClassify | ||||
|  | } | ||||
| @ -0,0 +1,9 @@ | |||||
|  | 'use strict'; | ||||
|  | /**培训资料库 */ | ||||
|  | const resourceRepository = require('../../controllers/resourceRepository'); | ||||
|  | 
 | ||||
|  | module.exports = function (app, router, opts) { | ||||
|  | 
 | ||||
|  |     app.fs.api.logAttr['GET/train/trainFiles/resourceRepository/classify'] = { content: '查询培训资源储备库分类目录', visible: false }; | ||||
|  |     router.get('/train/trainFiles/resourceRepository/classify', resourceRepository.getResourceClassify); | ||||
|  | }; | ||||
| @ -0,0 +1,54 @@ | |||||
|  | 'use strict'; | ||||
|  | 
 | ||||
|  | import { ApiTable, basicAction } from '$utils' | ||||
|  | 
 | ||||
|  | export function getResourceClassify() {//查询籍贯列表
 | ||||
|  |     return (dispatch) => basicAction({ | ||||
|  |         type: "get", | ||||
|  |         dispatch: dispatch, | ||||
|  |         actionType: "GET_RESOURCE_CLASSIFY", | ||||
|  |         // query: query,
 | ||||
|  |         url: `${ApiTable.getResourceClassify}`, | ||||
|  |         msg: { option: "查询培训资料库目录" }, | ||||
|  |         reducer: { name: "resourceClassify" }, | ||||
|  |     }); | ||||
|  | } | ||||
|  | 
 | ||||
|  | export function postResourceClassify(data) { | ||||
|  |     return (dispatch) => | ||||
|  |         basicAction({ | ||||
|  |             type: "post", | ||||
|  |             dispatch: dispatch, | ||||
|  |             data, | ||||
|  |             actionType: "POST_RESOURCE_CLASSIFY", | ||||
|  |             url: `${ApiTable.postResourceClassify}`, | ||||
|  |             msg: { option: "新增" }, | ||||
|  |             reducer: { name: "" }, | ||||
|  |         }); | ||||
|  | } | ||||
|  | 
 | ||||
|  | export function putResourceClassify(data) { | ||||
|  |     return (dispatch) => | ||||
|  |         basicAction({ | ||||
|  |             type: "put", | ||||
|  |             dispatch: dispatch, | ||||
|  |             data, | ||||
|  |             actionType: "PUT_RESOURCE_CLASSIFY", | ||||
|  |             url: `${ApiTable.putResourceClassify}`, | ||||
|  |             msg: { option: "修改" }, | ||||
|  |             reducer: {}, | ||||
|  |         }); | ||||
|  | } | ||||
|  | 
 | ||||
|  | export function delResourceClassify(data) { | ||||
|  |     return (dispatch) => | ||||
|  |         basicAction({ | ||||
|  |             type: "del", | ||||
|  |             query: data, | ||||
|  |             dispatch: dispatch, | ||||
|  |             actionType: "DEL_RESOURCE_CLASSIFY", | ||||
|  |             url: `${ApiTable.delResourceClassify}`, | ||||
|  |             msg: { option: "删除" }, //删除
 | ||||
|  |             reducer: {}, | ||||
|  |         }); | ||||
|  | } | ||||
					Loading…
					
					
				
		Reference in new issue