create_work.js 3.68 KB
Newer Older
Scott Sun's avatar
Scott Sun committed
1 2
var fs = require("fs");
var db = require('topsin.database');
Scott Sun's avatar
Scott Sun committed
3
var error = require('topsin.error');
Scott Sun's avatar
Scott Sun committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var user_name = "Sys";
try {
    db.addConnection({
        databse_type: 'pg',
        database_host: '10.90.2.100:5432',
        database_name: 'TOPSTQ_ATS_V6',
        database_user: 'toplinker',
        database_pwd: 'TopLinker0510'
    }, "ATS_DFM_DB");
    var query_1 = db.query('ATS_DFM_DB');
    // 1.获取客户名称
    var customers_1 = query_1.selectArrayValue({
        table: 'pub_customer',
        field: "code"
    });
Scott Sun's avatar
Scott Sun committed
19 20
    if (query_1.lastError().isValid()){
        throw query_1.lastError().text()};
Scott Sun's avatar
Scott Sun committed
21
    // 获取远程文件夹
Scott Sun's avatar
Scott Sun committed
22
    var samba = fs.listDir("\\\\10.90.2.100\\samba", 1);
Scott Sun's avatar
Scott Sun committed
23

Scott Sun's avatar
Scott Sun committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    var sambaDirs_1 = [];
    var sambaFiles_1 = [];
    samba.forEach(function (v) {
        if (v.isDir) {
            sambaDirs_1.push(v);
        }
        else {
            sambaFiles_1.push(v);
        }
    });
    sambaDirs_1.forEach(function (v) {
        if (customers_1.indexOf(v.name) >= 0) {
            // 获取该客户下所有料号
            var jobs = fs.listDir("\\\\10.90.2.100\\samba\\" + v.name, 0).filter(function (v) { return v.isDir; });
            // 获取dfm种已经存在的料号名
            var dfm_jobs_1 = query_1.selectArrayValue({
                table: 'pdm_job',
                field: "jobname",
                where: { customer_code: v.name },
                order: 'id DESC'
            });
            // 循环判断新料号
            jobs.forEach(function (v2) {
                if (/_/.test(v2.name) && dfm_jobs_1.indexOf(v2.name) < 0) {
                    // 为该新料号创建报价
                    var jobId = query_1.insertRow({
                        table: 'pdm_job',
                        data: {
                            jobname: v2.name,
                            version: '',
                            customer_code: v.name,
                            job_type: "normal",
                            spec_list: "{" + v.name + ",__GENERAL__}",
                            job_status: "active",
                            job_attrs: { "vc_number": v2.name.split("_")[0], "vc_position": v2.name.split("_")[1] },
                            action_data: { "create_time": query_1.getNow(), "create_user_id": 1, "create_user_name": user_name },
                            sys_data: { "sys_data_version": 0 },
                            spec_mode: 0
                        },
                        return_field: 'id'
                    });
                    if (query_1.lastError().isValid())
                        throw query_1.lastError().text();
                    var flowInfo = query_1.selectMap({
                        table: 'pdm_aimdfm_workflow',
                        where: {
                            name: "topcam"
                        }
                    });
                    var flowId = flowInfo["id"];
                    var flowTitle = flowInfo["title"];
                    // 创建料号任务
                    query_1.insertRow({
                        table: 'pdm_aimdfm_task',
                        data: {
                            job_id: jobId,
                            flow_id: flowId,
                            status: 'waiting',
                            user_id: 1,
                            user_name: user_name,
                            priority: 0,
                            task_title: v2.name + ":" + flowTitle
                        }
                    });
                    if (query_1.lastError().isValid())
                        throw query_1.lastError().text();
                }
            });
        }
    });
}
catch (error) {
    console.log("err");
    console.log(error);
}