con_contract_zr_gps_send.lsc 10.2 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Spencer 3893  
    $Date: 2016-9-19 上午10:24:11  
    $Revision: 1.0  
    $Purpose: 青岛中瑞GPS
-->
<a:service xmlns:ns1="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <a:model-update model="gps.con_contract_gps_data_check"/>
        <s:server-script import="gps/zr_gps.js"><![CDATA[
            importPackage(Packages.java.util);
            importPackage(Packages.rd.zr.gps.addorderwithvpsInfos);
            importPackage(Packages.rd.zr.gps.getalleqpositionsbyappcode);
            importPackage(Packages.rd.zr.gps.getbaseorderInfobyappcode);
            
            var appkey = gps_config.appkey;
            
            function post_get_name(name) {
                var name_arr = {
                    "APPCODE": "Appcode",
                    "PRODUCTID": "ProductId",
                    "PRODUCTTYPE": "productType",
                    "DISTRICTCODE": "DistrictCode",
                    "INSTALLADD": "InstallAdd",
                    "INSTALLTIME": "InstallTime",
                    "SHOPNAME": "ShopName",
                    "LINKMAN": "LinkMan",
                    "LINKPHONE": "LinkPhone",
                    "USERNAME": "UserName",
                    "USERPHONE": "UserPhone",
                    "CARTYPE": "CarType",
                    "PLATENUMBER": "PlateNumber",
                    "VIN": "VIN",
                    "COLOR": "Color",
                    "CARPRICE": "CarPrice",
                    "LOANAMOUNT": "LoanAmount",
                    "CREDITPERIOD": "CreditPeriod",
                    "NUM": "Num",
                    "REMARK": "Remark"
                };
                if (name_arr[name]) {
                    return name_arr[name];
                } else {
                    return name;
                }
            }
            
            function save_gps_resp(savetype, zr_id, zr_appcode, zr_locationtime, address, zr_orderstatus, zr_url) {
                if (savetype == 'ZR_DOWNLOAD_GPS') {
                    if (zr_id != '' && zr_id != null) {
                        null;
                    } else {
                        raise_app_error("新增工单失败:" + zr_id);
                    }
                } else if (savetype == 'ZR_DOWNLOAD_GPS') {
                    var download_url_info = zr_url;
                    if (download_url_info.indexOf('http') == -1) {
                        raise_app_error("下载保单失败:" + download_url_info);
                    }
                    if (download_url_info) {
                        $ctx.parameter.ln_url = String(download_url_info);
                    }
                }
                
                var saveBm = $bm('gps.con_contract_update_zr_gps_response');
                saveBm.update({
                    contract_id: $ctx.parameter.contract_id,
                    zr_id: zr_id,
                    zr_appcode: zr_appcode,
                    address: address,
                    zr_locationtime:zr_locationtime,
                    zr_orderstatus: zr_orderstatus,
                    zr_url: zr_url,
                    savetype: savetype
                });
            }
            
            function new_gps() {
                var infoBm = $bm('gps.con_contract_zr_add_gps_info');
                var infoResult = infoBm.queryAsMap({
                    contract_id: $ctx.parameter.contract_id
                });
                var infoChilds = infoResult.getChildren();
                if (infoChilds.length) {
                    var infoChild = infoChilds[0];
                    var newGpsUrl = gps_config.newGpsUrl;
                    var infoMap = new HashMap();
                    var zr_appcode;
                    for (var name in infoChild) {
                        if (post_get_name(name)) {
                            if (infoChild[name] || infoChild[name] === 0) {
                                infoMap.put(post_get_name(name), infoChild[name]);
                                if (name == 'APPCODE') {
                                    zr_appcode = infoChild[name];
                                }
                            } else {
                                if(name == 'LINKMAN'){
                                    infoMap.put(post_get_name(name), "测试");
                                }else if(name == 'LINKPHONE'){
                                    infoMap.put(post_get_name(name), "13111234567");
                            }else{
                                infoMap.put(post_get_name(name), null);}
                            }
                        }
                    }
                    try {
                        println("newGpsUrl>>>" + newGpsUrl);
                        println("infoMap>>>" + infoMap);
                        var nav = new AddOrderWithVpsInfos(newGpsUrl, infoMap, "UTF-8", appkey);
                        var newresp = nav.run();
                        println("result>>>" + newresp);
                        save_gps_resp('ZR_NEW_GPS', String(newresp), zr_appcode, null, null, null, null);
                    } catch (e) {
                        raise_app_error("新增工单失败:" + e);
                    }
                } else {
                    raise_app_error("未获取到对应的合同工单信息");
                }
            }
            
            
            function find_con_gps() {
                var findGpsUrl = gps_config.findGpsUrl;
                var zr_appcode = $ctx.parameter.zr_appcode;
                var infoMap = new HashMap();
                infoMap.put(post_get_name("APPCODE"), "GH201609220000013");
                //infoMap.put(post_get_name("APPCODE"), $ctx.parameter.zr_appcode);
                try {
                    var fv = new GetBaseOrderInfoByAppCode(findGpsUrl, infoMap, "UTF-8", appkey);
                    var arr = fv.run();
                    var OrderStatus = arr[0];
                    var error_message = null;
                    println("OrderStatus>>>" + OrderStatus); //“新增”“等待派单”“等待加装”“加装完成”
                    if (OrderStatus != '加装完成') {
                        return false;
                        // error_message = "该工单尚未激活";
                        // raise_app_error(message);
                    }
                    return true;
                } catch (e) {
                    var message = null;
                    if (error_message) {
                        message = error_message;
                    } else {
                        message = "查找工单失败:" + e;
                    }
                    raise_app_error(message);
                }
            }
            
            function find_con_posi_gps() {
                var findGpsPosiUrl = gps_config.findGpsPosiUrl;
                var zr_appcode = $ctx.parameter.zr_appcode;
                var infoMap = new HashMap();
                //infoMap.put(post_get_name("APPCODE"), "测试定位001");
                infoMap.put(post_get_name("APPCODE"), "0000585");
                //infoMap.put(post_get_name("APPCODE"), $ctx.parameter.zr_appcode);
                try {
                    var fv = new GetAllEqPositionsByAppCode(findGpsPosiUrl, infoMap, "UTF-8", appkey);
                    var arr = fv.run();
                    var equipment = arr[0];
                    var locationAdd = arr[1];
                    var locationTime = arr[2];
                    var vin = arr[3];
                    var imei = arr[4];
                    var appcode = arr[5];
                    var flag = arr[6];
                    var lat = arr[7];
                    var lng = arr[8];
                    var battery = arr[9];
                    var sbcstatus = arr[10];
                    var typestr = arr[11];
                    var LocateMode = arr[12];
                    var message = arr[13];
             println("locationTime>>>" + locationTime);
                    var error_message = null;
                    save_gps_resp('ZR_FIND_GPS', null, zr_appcode, locationTime, locationAdd, null, null);
                } catch (e) {
                    var message = null;
                    if (error_message) {
                        message = error_message;
                    } else {
                        message = "查找工单失败:" + e;
                    }
                    raise_app_error(message);
                }
            }
            
            function down_con_gps() {
                var infoBm = $bm('gps.con_contract_ln_add_gps_info');
                var infoResult = infoBm.queryAsMap({
                contract_id: $ctx.parameter.contract_id
                });
                var infoChilds = infoResult.getChildren();
                if (infoChilds.length) {
                    var infoChild = infoChilds[0];
                    var downloadGpsUrl = gps_config.downloadGpsUrl;
                    var infoStrArray = [];
            
                    try {
                        var dv = new DownLoadSaleInfo(downloadGpsUrl, saleNo, Account, Password, infoStrArray, "gb2312", ReqfilePath, RespfilePath);
                        var download_url_info = dv.run();
                        save_gps_resp('ZR_DOWNLOAD_GPS', download_url_info);
                    } catch (e) {
                        raise_app_error("初始化新增工单失败:" + e);
                    }
                } else {
                    raise_app_error("未获取到对应的合同工单信息");
                }
            }
            
            var gps_type = $ctx.parameter.gps_type;
            if (gps_type == 'ZR_NEW_GPS') {
                new_gps();
            } else if (gps_type == 'ZR_FIND_GPS') {
                // var flag = find_con_gps();
                // if (flag) {
                    find_con_posi_gps();
                // } else {
                    // raise_app_error("该GPS设备尚未激活!");
                // }
            } else if (gps_type == 'ZR_DOWNLOAD_GPS') {
                //down_con_gps();
            }
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>