weaver_trunk_cli/pc4public/stores/hrm/importCommon.js

423 lines
8.5 KiB
JavaScript
Raw Normal View History

2024-12-11 15:32:14 +08:00
import * as asyncFetch from '../../apis/importresource';
2023-03-14 09:11:54 +08:00
import {
observable,
action,
2024-12-11 15:32:14 +08:00
extendObservable,
2023-03-14 09:11:54 +08:00
} from 'mobx';
import {
WeaForm,
2024-12-11 15:32:14 +08:00
WeaTableNew,
2023-03-14 09:11:54 +08:00
} from 'comsMobx';
import {
WeaLocaleProvider,
} from 'ecCom';
2024-12-11 15:32:14 +08:00
import {
message,
} from 'antd';
2023-03-14 09:11:54 +08:00
const getLabel = WeaLocaleProvider.getLabel;
const {
2024-12-11 15:32:14 +08:00
TableStore,
2023-03-14 09:11:54 +08:00
} = WeaTableNew;
2024-12-11 15:32:14 +08:00
export default class HrmImportCommon {
2023-03-14 09:11:54 +08:00
@observable importType = '';
@observable importDialog = {
visible: false,
condition: [],
form: new WeaForm(),
title: '',
loading: true,
templetName: '',
selectedValue: 'workcode',
}
@observable resultDialog = {
title: observable.ref(getLabel(82341, '导入结果')),
2024-12-11 15:32:14 +08:00
errorTip: observable.ref(getLabel(384059, '导入文件存在以下错误,请解决后重新上传!')),
2023-03-14 09:11:54 +08:00
visible: false,
index: 1,
datas: [],
importStatus: '',
pId: '',
interval: '',
tableStore: new TableStore(),
errorInfo: [],
succnum: 0,
failnum: 0,
loading: true,
component: '',
}
@observable recordDialog = {
title: observable.ref(getLabel(24644, '历史导入记录')),
visible: false,
tableStore: new TableStore(),
}
@observable logDialog = {
title: observable.ref(getLabel(24835, '导入日志')),
visible: false,
tableStore: new TableStore(),
isPanelShow: false,
form: new WeaForm(),
condition: [],
loading: true,
}
@action
getImportForm = () => {
this.importDialog.loading = true;
let params = {
2024-12-11 15:32:14 +08:00
importType: this.importType,
2023-03-14 09:11:54 +08:00
};
2024-12-11 15:32:14 +08:00
asyncFetch.getImportForm(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
status,
condition = [],
} = rs;
if (status == '1') {
this.importDialog.condition = condition;
const copy = [...condition];
copy.splice(1);
copy[0].items.splice(2);
this.importDialog.form.initFormFields(copy);
this.importDialog.loading = false;
} else {
message.error(rs.message);
}
2024-12-11 15:32:14 +08:00
}).catch((error) => {
2023-03-14 09:11:54 +08:00
message.error(error);
});
}
@action
getImportProcessInfo = () => {
let params = {
importType: this.importType,
index: this.resultDialog.index,
};
2024-12-11 15:32:14 +08:00
asyncFetch.getImportProcessLog(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
datas,
index,
pId = '',
2024-12-11 15:32:14 +08:00
status,
2023-03-14 09:11:54 +08:00
} = rs;
this.resultDialog.loading = false;
if (status == '1') {
const {
importStatus,
interval,
errorInfo,
2024-12-11 15:32:14 +08:00
component,
2023-03-14 09:11:54 +08:00
} = this.resultDialog;
2024-12-11 15:32:14 +08:00
component.scrollToLast();
2023-03-14 09:11:54 +08:00
if (importStatus == 'over' || importStatus == 'error') {
clearInterval(interval);
if (!this.hasErrorInfo(errorInfo)) this.getResultInfo();
2024-12-11 15:32:14 +08:00
// 导入完成后,刷新节假日设置页面的年视图或清单列表
this.sourceStore && this.sourceStore.refreshTable();
return;
2023-03-14 09:11:54 +08:00
}
if (rs.importStatus == 'over' || rs.importStatus == 'error') {
this.resultDialog.loading = true;
}
this.resultDialog.importStatus = rs.importStatus;
if (pId) this.resultDialog.pId = pId;
if (this.resultDialog.datas.length == 0) {
this.resultDialog.datas = datas;
} else {
2024-12-11 15:32:14 +08:00
this.resultDialog.datas = [...this.resultDialog.datas, ...datas];
2023-03-14 09:11:54 +08:00
}
this.resultDialog.index = index;
}
});
}
@action
getResultInfo = () => {
let params = {
2024-12-11 15:32:14 +08:00
pId: this.resultDialog.pId,
2023-03-14 09:11:54 +08:00
};
this.resultDialog.loading = true;
2024-12-11 15:32:14 +08:00
asyncFetch.getImportResult(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
datas,
2024-12-11 15:32:14 +08:00
status,
} = rs,
{
2023-03-14 09:11:54 +08:00
succnum,
failnum,
2024-12-11 15:32:14 +08:00
sessionkey = '',
2023-03-14 09:11:54 +08:00
} = datas;
if (status == '1') {
this.resultDialog.succnum = succnum;
this.resultDialog.failnum = failnum;
sessionkey && this.resultDialog.tableStore.getDatas(sessionkey, 1);
}
this.resultDialog.loading = false;
});
}
@action
getRecordTable = () => {
let params = {
2024-12-11 15:32:14 +08:00
importType: this.importType,
2023-03-14 09:11:54 +08:00
};
2024-12-11 15:32:14 +08:00
asyncFetch.getImportHistory(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
status,
sessionkey,
} = rs;
if (status == '1') {
this.recordDialog.tableStore.getDatas(sessionkey, 1);
} else {
message.error(rs.message);
}
2024-12-11 15:32:14 +08:00
}).catch((error) => {
2023-03-14 09:11:54 +08:00
message.error(error);
});
}
@action
getLogTable = () => {
let params = {
importType: this.importType,
...this.logDialog.form.getFormParams(),
};
if (this.resultDialog.pId) {
2024-12-11 15:32:14 +08:00
params = { ...params,
pId: this.resultDialog.pId,
};
2023-03-14 09:11:54 +08:00
}
2024-12-11 15:32:14 +08:00
asyncFetch.getImportLogDetail(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
status,
2024-12-11 15:32:14 +08:00
sessionkey,
2023-03-14 09:11:54 +08:00
} = rs;
if (status == '1') {
this.logDialog.tableStore.getDatas(sessionkey, 1);
} else {
message.error(rs.message);
}
2024-12-11 15:32:14 +08:00
}).catch((error) => {
2023-03-14 09:11:54 +08:00
message.error(error);
});
}
@action
submitImportInfo = () => {
2024-12-11 15:32:14 +08:00
let params = {
2023-03-14 09:11:54 +08:00
importType: this.importType,
excelfile: this.importDialog.excelFileId,
2024-12-11 15:32:14 +08:00
operateType: 'add',
2023-03-14 09:11:54 +08:00
};
2024-12-11 15:32:14 +08:00
if (['group', 'groupMember'].includes(this.importType)) {
params = {
...params,
...this.importDialog.form.getFormParams(),
};
}
if (this.otherParams) {
Object.assign(params, this.otherParams);
2023-03-14 09:11:54 +08:00
}
this.setResultInfoDialogVisible(true);
2024-12-11 15:32:14 +08:00
asyncFetch.saveImport(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
status,
2024-12-11 15:32:14 +08:00
errorInfo,
2023-03-14 09:11:54 +08:00
} = rs;
if (status == '1') {
if (this.hasErrorInfo(errorInfo)) {
this.resultDialog.errorInfo = errorInfo;
this.resultDialog.importStatus = 'error';
}
} else {
message.error(rs.message);
}
2024-12-11 15:32:14 +08:00
}).catch((error) => {
2023-03-14 09:11:54 +08:00
message.error(error);
});
this.resultDialog.interval = setInterval(() => this.getImportProcessInfo(), 2000);
}
@action
getLogSearchPanelCondition = () => {
this.logDialog.loading = true;
let params = {
2024-12-11 15:32:14 +08:00
importType: this.importType,
2023-03-14 09:11:54 +08:00
};
2024-12-11 15:32:14 +08:00
asyncFetch.getImportLogSearchCondition(params).then((rs) => {
2023-03-14 09:11:54 +08:00
const {
status,
2024-12-11 15:32:14 +08:00
searchCondition,
2023-03-14 09:11:54 +08:00
} = rs;
if (status == '1') {
this.logDialog.condition = searchCondition;
this.logDialog.form.initFormFields(searchCondition);
} else {
message.error(rs.message);
}
this.logDialog.loading = false;
2024-12-11 15:32:14 +08:00
}).catch((error) => {
2023-03-14 09:11:54 +08:00
message.error(error);
});
}
@action
setExcelFileNo = (id) => {
extendObservable(this.importDialog, {
2024-12-11 15:32:14 +08:00
excelFileId: id,
2023-03-14 09:11:54 +08:00
});
}
@action
submitExcel = () => {
if (!this.importDialog.excelFileId) {
message.warning(getLabel(385362, '请选择导入模板!'));
return;
}
this.submitImportInfo();
}
@action
queryRecord = () => {
this.setRecordDialogVisible(true);
}
@action
queryLog = () => {
this.setLogDialogVisible(true);
}
@action
jumpToImportResult = (id) => {
this.resultDialog.pId = id;
this.resultDialog.importStatus = 'over';
this.setResultInfoDialogVisible(true);
this.getResultInfo();
}
@action
setImportDialogVisible = (bool) => {
this.importDialog.visible = bool;
if (bool) {
this.getImportForm();
} else {
this.importDialogReset();
}
}
@action
setResultInfoDialogVisible = (bool) => {
this.resultDialog.visible = bool;
if (!bool) {
clearInterval(this.resultDialog.interval);
this.resetResultDialogStatus();
}
}
@action
importDialogReset = () => {
this.importDialog.condition = [];
this.importDialog.form = new WeaForm();
this.importDialog.selectedValue = 'workcode';
this.importDialog.excelFileId = '';
}
@action
resetResultDialogStatus = () => {
this.resultDialog.index = 1;
this.resultDialog.datas = [];
this.resultDialog.importStatus = '';
this.resultDialog.pId = '';
this.resultDialog.interval = '';
this.resultDialog.errorInfo = '';
this.resultDialog.loading = true;
}
@action
setRecordDialogVisible = (bool) => {
this.recordDialog.visible = bool;
bool && this.getRecordTable();
}
@action
setLogDialogVisible = (bool) => {
this.logDialog.visible = bool;
bool && this.getLogTable();
if (!bool) {
this.logDialog.isPanelShow = false;
this.logDialog.form = new WeaForm();
this.logDialog.condition = [];
}
}
@action
setLogPanelStatus = (bool) => {
this.logDialog.isPanelShow = bool;
bool && this.logDialog.condition.length == 0 && this.getLogSearchPanelCondition();
}
@action
searchLogInfo = () => {
this.getLogTable();
}
hasErrorInfo = (errorInfo) => {
if (errorInfo.length == 0) return false;
2024-12-11 15:32:14 +08:00
return true;
2023-03-14 09:11:54 +08:00
}
@action
setTempletName = (templetName) => {
this.importDialog.templetName = templetName;
}
@action
setImportDialogTitle = (title) => {
this.importDialog.title = title;
}
@action
setImportType = (type) => {
this.importType = type;
}
@action
setSelectedValue = (value) => {
this.importDialog.selectedValue = value;
}
@action
setScoll = (component) => {
this.resultDialog.component = component;
}
2024-12-11 15:32:14 +08:00
@action
2023-03-14 09:11:54 +08:00
setSourceStore = (store) => {
this.sourceStore = store;
}
2024-12-11 15:32:14 +08:00
setOtherParams=(params) => {
this.otherParams = params;
}
}