import request from './request';
const { config: { mesUrl } = {} } = global;
// /mdgeneric/md/bmWorkCenter/getLoginWorkCenterAndRoute
// 查询车间
function getOrganization() {
    let url = `${mesUrl}/mdgeneric/md/bmWorkCenter/getLoginWorkCenterAndRoute`;
    return new Promise((resolve, reject) => {
        request({ url }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve([]);
        });
    });
}
// 查询车间
function getFactory() {
    let url = `${mesUrl}/mdgeneric/md/bmWorkCenter/findAllWithPage`;
    let bodys = {
        removePermission: true,
        filter: "type eq 'workshop'",
        page: 1,
        pageSize: 1000,
        sorted: 'createTime desc',
    };
    return new Promise((resolve, reject) => {
        request({ url, bodys }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve([]);
        });
    });
}
// 根据车间查询工艺路线
function getRouterLineByFactory(workCenterCode) {
    let url = `${mesUrl}/mdgeneric/md/bmRoute/findRouteByWorkCenterCode?workCenterCode=${workCenterCode}`;
    return new Promise((resolve, reject) => {
        request({ url }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve([]);
        });
    });
}
// 根据工艺路线查询设备
function getOpByRouterLine(routerLineCode) {
    let url = `${mesUrl}/mdgeneric/md/bmRoute/findOpAndEquipByRoute?routeCode=${routerLineCode}`;
    return new Promise((resolve, reject) => {
        request({ url }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve([]);
        });
    });
}
// 查询水波图，柱状图，环形图
function getTimeRate(workCenterCode) {
    let url = `${mesUrl}/equip/equipment/equipmentOee/queryTimeRate?workCenterCode=${workCenterCode}`;

    return new Promise((resolve, reject) => {
        request({ url }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve({});
        });
    });
}
// 异常消息
function getAbnlException(workCenterCode) {
    let url = `${mesUrl}/abnl/abnl/abnlevent/getAbnlException?workCenterCode=${workCenterCode}`;

    return new Promise((resolve, reject) => {
        request({ url }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve({});
        });
    });
}
// 质量检验合格率
function getSevenQualifiedRate(workCenterCode) {
    let url = `${mesUrl}/equip/equipment/equipmentOee/querySevenQualifiedRate?workCenterCode=${workCenterCode}`;
    return new Promise((resolve, reject) => {
        request({ url }).then((response = {}) => {
            if (response.success) {
                resolve(response.data);
            }
            resolve({});
        });
    });
}
export {
    getTimeRate,
    getAbnlException,
    getSevenQualifiedRate,
    getFactory,
    getRouterLineByFactory,
    getOpByRouterLine,
    getOrganization,
};
