prj-common-globalservice.js 20.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
// 项目通用的全局service服务,供不同的controller使用,自定义指令不使用

// 文件下载服务
angular.module('ScheduleApp').factory('FileDownload_g', function() {
    return {
        downloadFile: function (data, mimeType, fileName) {
            var success = false;
            var blob = new Blob([data], { type: mimeType });
            try {
                if (navigator.msSaveBlob)
                    navigator.msSaveBlob(blob, fileName);
                else {
                    // Try using other saveBlob implementations, if available
                    var saveBlob = navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob;
                    if (saveBlob === undefined) throw "Not supported";
                    saveBlob(blob, fileName);
                }
                success = true;
            } catch (ex) {
                console.log("saveBlob method failed with the following exception:");
                console.log(ex);
            }

            if (!success) {
                // Get the blob url creator
                var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
                if (urlCreator) {
                    // Try to use a download link
                    var link = document.createElement('a');
                    if ('download' in link) {
                        // Try to simulate a click
                        try {
                            // Prepare a blob URL
                            var url = urlCreator.createObjectURL(blob);
                            link.setAttribute('href', url);

                            // Set the download attribute (Supported in Chrome 14+ / Firefox 20+)
                            link.setAttribute("download", fileName);

                            // Simulate clicking the download link
                            var event = document.createEvent('MouseEvents');
                            event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
                            link.dispatchEvent(event);
                            success = true;

                        } catch (ex) {
                            console.log("Download link method with simulated click failed with the following exception:");
                            console.log(ex);
                        }
                    }

                    if (!success) {
                        // Fallback to window.location method
                        try {
                            // Prepare a blob URL
                            // Use application/octet-stream when using window.location to force download
                            var url = urlCreator.createObjectURL(blob);
                            window.location = url;
                            console.log("Download link method with window.location succeeded");
                            success = true;
                        } catch (ex) {
                            console.log("Download link method with window.location failed with the following exception:");
                            console.log(ex);
                        }
                    }
                }
            }

            if (!success) {
                // Fallback to window.open method
                console.log("No methods worked for saving the arraybuffer, using last resort window.open");
                window.open("", '_blank', '');
            }
        }
    };
});

// 车辆信息service
angular.module('ScheduleApp').factory('BusInfoManageService_g', ['$resource', function($resource) {
    return {
        rest: $resource(
            '/cars/:id',
            {order: 'carCode', direction: 'ASC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                }
            }
        ),
        validate: $resource(
            '/cars/validate/:type',
            {},
            {
                insideCode: {
                    method: 'GET'
                }
            }
        ),
        dataTools: $resource(
            '/cars/:type',
            {},
            {
                dataExport: {
                    method: 'GET',
                    responseType: "arraybuffer",
                    params: {
                        type: "dataExport"
                    },
                    transformResponse: function(data, headers){
                        return {data : data};
                    }
                }
            }
        )
    };
}]);
// 人员信息service
angular.module('ScheduleApp').factory('EmployeeInfoManageService_g', ['$resource', function($resource) {
    return {
        rest : $resource(
            '/personnel/:id',
            {order: 'jobCode', direction: 'ASC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                }
            }
        ),
        validate: $resource(
            '/personnel/validate/:type',
            {},
            {
                jobCode: {
                    method: 'GET'
                }
            }
        ),
        dataTools: $resource(
            '/personnel/:type',
            {},
            {
                dataExport: {
                    method: 'GET',
                    responseType: "arraybuffer",
                    params: {
                        type: "dataExport"
                    },
                    transformResponse: function(data, headers){
                        return {data : data};
                    }
                }
            }
        )
    };
}]);
// 车辆设备信息service
angular.module('ScheduleApp').factory('DeviceInfoManageService_g', ['$resource', function($resource) {
    return $resource(
        '/cde/:id',
        {order: 'xl,isCancel,cl,qyrq', direction: 'ASC,ASC,ASC,DESC', id: '@id_route'},
        {
            list: {
                method: 'GET',
                params: {
                    page: 0
                }
            },
            get: {
                method: 'GET'
            },
            save: {
                method: 'POST'
            },
            delete: {
                method: 'DELETE'
            }
        }
    );
}]);

// 车辆配置service
angular.module('ScheduleApp').factory('BusConfigService_g', ['$resource', function($resource) {
    return {
        rest : $resource(
            '/cci/:id',
            {order: 'xl.id,cl.insideCode,isCancel', direction: 'ASC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                }
            }
        )
    };
}]);

// 人员配置service
angular.module('ScheduleApp').factory('EmployeeConfigService_g', ['$resource', function($resource) {
    return {
        rest : $resource(
            '/eci/:id',
            {order: 'xl.id,isCancel,dbbmFormula', direction: 'ASC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                },
                delete: {
                    method: 'DELETE'
                }
            }
        ),
        validate: $resource( // TODO:
            '/personnel/validate/:type',
            {},
            {
                jobCode: {
                    method: 'GET'
                }
            }
        )
    };
}]);

// 路牌管理service
angular.module('ScheduleApp').factory('GuideboardManageService_g', ['$resource', function($resource) {
    return {
        rest: $resource(
            '/gic/:id',
            {order: 'createDate', direction: 'DESC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                }
            }
        )
    };
}]);

// 排班管理service
angular.module('ScheduleApp').factory('ScheduleRuleManageService_g', ['$resource', function($resource) {
    return {
        rest: $resource(
            '/sr1fc/:id',
            {order: 'createDate', direction: 'DESC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                },
                delete: {
                    method: 'DELETE'
                }
            }
        )
    };
}]);

// 套跑管理service
angular.module('ScheduleApp').factory('rerunManageService_g', ['$resource', function($resource) {
    return {
        rest: $resource(
            'rms/:id',
            {order: 'rerunXl.id,isCancel', direction: 'ASC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                },
                delete: {
                    method: 'DELETE'
                }
            }
        )
    };
}]);

// 时刻表管理service
angular.module('ScheduleApp').factory('TimeTableManageService_g', ['$resource', function($resource) {
    return {
        rest: $resource(
            '/tic/:id',
            {order: 'xl,isCancel,isEnableDisTemplate,qyrq', direction: 'DESC,ASC,DESC,DESC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                }
            }
        )
    };
}]);
// 时刻表明细管理service
angular.module('ScheduleApp').factory('TimeTableDetailManageService_g', ['$resource', function($resource) {
    return {
        rest: $resource(
            '/tidc/:id',
            {order: 'createDate', direction: 'DESC', id: '@id_route'},
            {
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                }
            }
        ),
        edit: $resource(
            '/tidc/edit/:xlid/:ttid',
            {},
            {
                list: {
                    method: 'GET'
                }
            }
        ),
        bcdetails: $resource(
            '/tidc/bcdetail',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        )
    };
}]);



// 排班计划管理service
angular.module('ScheduleApp').factory('SchedulePlanManageService_g', ['$resource', function($resource) {
    return {
        rest : $resource(
            '/spc/:id',
            {order: 'createDate', direction: 'DESC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                },
                delete: {
                    method: 'DELETE'
                }
            }
        ),
        tommorw: $resource(
            '/spc/tommorw',
            {},
            {
                list: {
                    method: 'GET'
                }
            }
        )
    };
}]);

// 排班计划明细管理service
angular.module('ScheduleApp').factory('SchedulePlanInfoManageService_g', ['$resource', function($resource) {
    return {
        rest : $resource(
            '/spic/:id',
            {order: 'scheduleDate,lp,fcno', direction: 'ASC', id: '@id_route'},
            {
                list: {
                    method: 'GET',
                    params: {
                        page: 0
                    }
                },
                get: {
                    method: 'GET'
                },
                save: {
                    method: 'POST'
                }
            }
        ),
        groupinfo : $resource(
            '/spic/groupinfos/:xlid/:sdate',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        updateGroupInfo : $resource(
            '/spic/groupinfos/update',
            {},
            {
                update: {
                    method: 'POST'
                }
            }
        )
    };
}]);

// 线路运营统计service
angular.module('ScheduleApp').factory('BusLineInfoStatService_g', ['$resource', function($resource) {
    return $resource(
        '/bic/:id',
        {order: 'createDate', direction: 'DESC', id: '@id_route'}, // TODO:以后需要根据属性对象的属性查询
        {
            list: {
                method: 'GET',
                params: {
                    page: 0
                }
            }
        }
    );
}]);




/**
 * saSelect2指令,根据属性值,动态载入数据,然后支持拼音搜索,点击右边的按钮清除选择并重新载入数据。
 * 1、compile阶段使用的属性如下:
 *      required:用于和表单验证连接,指定成required="true"才有效。
 * 2、link阶段使用的属性如下
 *      model:关联的模型对象
 *      name:表单验证时需要的名字
 *      type:关联的那种数据值(xl/cl/ry)-> 对应线路信息/车辆信息/人员信息,后面有的继续加
 *      modelcolname1:关联的模型字段名字1(一般应该是编码字段)
 *      modelcolname2:关联的模型字段名字2(一般应该是名字字段)
 *      datacolname1;内部数据对应的字段名字1(与模型字段1对应)
 *      datacolname2:内部数据对应的字段名字2(与模型字段2对应)
 *      showcolname:下拉框显示的内部数据字段名(注意:不是模型数据字段名),TODO:以后考虑放动态表达式,并在compile阶段使用
 *      placeholder:select placeholder字符串描述
 *
 * $$pyFilter,内部的filter指令,结合简拼音进行拼音过滤。
 * $$SearchInfoService_g,内部使用的数据服务
 */
// saSelect2指令使用的内部信service
angular.module('ScheduleApp').factory('$$SearchInfoService_g', ['$resource', function($resource) {
    return {
        xl: $resource(
            '/line/:type',
            {order: 'name', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        zd: $resource(
            '/stationroute/stations',
            {order: 'stationCode', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        tcc: $resource(
            '/carpark/:type',
            {order: 'parkCode', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        ry: $resource(
            '/personnel/:type',
            {order: 'personnelName', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cl: $resource(
            '/cars/:type',
            {order: "insideCode", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        ttInfo: $resource(
            '/tic/:type',
            {order: "name", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        lpInfo: $resource(
            '/gic/ttlpnames',
            {order: "lpName", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        lpInfo2: $resource(
            '/gic/:type',
            {order: "lpName", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cci: $resource(
            '/cci/cars',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }

        ),
        cci2: $resource(
            '/cci/:type',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cci3: $resource(
            '/cci/cars2',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }

        ),
        eci: $resource(
            '/eci/jsy',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        eci2: $resource(
            '/eci/spy',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        eci3: $resource(
            '/eci/:type',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),


        validate: { // remoteValidation指令用到的resource
            cl1: { // 车辆自编号不能重复验证
                template: {'insideCode_eq': '-1'}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/cars/validate/equale',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            cde1: { // 车辆设备启用日期验证
                template: {'qyrq': 0, 'xl': 1, 'cl': 1}, // 日期毫秒
                remote: $resource( // $resource封装对象
                    '/cde//validate/qyrq',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            ttc1: { // 时刻表名字验证
                template: {'xl.id_eq': -1, 'name_eq': 'ddd'},
                remote: $resource( // $resource封装对象
                    '/tic/validate/equale',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            }
        }

        //validate: $resource(
        //    '/cars/validate/:type',
        //    {},
        //    {
        //        insideCode: {
        //            method: 'GET'
        //        }
        //    }
        //)



    }
}]);