|
|
@@ -1,533 +0,0 @@
|
|
|
-package com.malk.paineng.service.impl;
|
|
|
-
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.malk.paineng.service.YD_PN;
|
|
|
-import com.malk.server.aliwork.YDConf;
|
|
|
-import com.malk.server.aliwork.YDParam;
|
|
|
-import com.malk.server.dingtalk.DDR_New;
|
|
|
-import com.malk.service.aliwork.YDClient;
|
|
|
-import com.malk.service.dingtalk.DDClient;
|
|
|
-import com.malk.service.dingtalk.DDClient_Workflow;
|
|
|
-import com.malk.utils.UtilDateTime;
|
|
|
-import com.malk.utils.UtilMap;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections4.map.HashedMap;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.net.*;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneId;
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class YD_PNImpl implements YD_PN {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DDClient ddClient;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private YDClient ydClient;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DDClient_Workflow ddClient_workflow;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ZT_PNImpl ZT_PNImpl;
|
|
|
- @Autowired
|
|
|
- private ZhongTai_AllImpl ZhongTai_AllImpl;
|
|
|
-
|
|
|
- @Override
|
|
|
- public String syncYD_PN(String processInstanceId, String type, String SSGS) throws IOException {
|
|
|
- if ("出差".equals(type) && processInstanceId != "") {
|
|
|
- System.out.println("正在同步派能出差:" + processInstanceId + " !!!");
|
|
|
- Map<String, String> compsId_main = UtilMap.map("出差事由, 所属公司", "textareaField_lygo9owv, textField_m2sdke9h");
|
|
|
- Map<String, String> compsId_itinerary = UtilMap.map("交通工具, 单程往返, 出发城市, 目的城市, 开始时间, 结束时间, 时长", "textField_m2sdke90, textField_m2sdke91, textField_m2sdke92, textField_m2sdke93, textField_m2sdke94, textField_m2sdke95, numberField_m2sdke96");
|
|
|
- compsId_main.put("出差明细", "tableField_lygo9owu"); // 子表组件
|
|
|
- syncYD_PN_impl(processInstanceId, compsId_main, compsId_itinerary, "itinerary", SSGS);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 派能出差数据通过钉钉连接器同步到宜搭
|
|
|
- *
|
|
|
- * @param processInstanceId
|
|
|
- * @param compsId_main
|
|
|
- * @param compsId_itinerary
|
|
|
- * @param compId_sub_oa
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public void syncYD_PN_impl(String processInstanceId, Map<String, String> compsId_main, Map<String, String> compsId_itinerary, String compId_sub_oa, String SSGS) throws IOException {
|
|
|
- /// dingtalk——派能
|
|
|
- String APP_EKY = "dingmpxci8bolc3jpima";
|
|
|
- String APP_SECRET = "Y_k3jpKNHbGvb9S9As2Y61ZaUFNglm7SCqquIkcowLBRoc4ZpH7DG0ZTn8LyHMwI";
|
|
|
- String token = ddClient.getAccessToken(APP_EKY, APP_SECRET);//ddtokken
|
|
|
- Map processData = ddClient_workflow.getProcessInstanceId(token, processInstanceId);//通过instanceID ID获取钉钉数据
|
|
|
- List<Map> formComponentValues = (List<Map>) processData.get("formComponentValues");
|
|
|
- String ifagree = processData.get("result").toString();
|
|
|
- String ifstatus = processData.get("status").toString();
|
|
|
-
|
|
|
- if (ifagree.equals("agree") && ifstatus.equals("COMPLETED")) {//status为COMPLETED且result为agree时,表示审批单完结并审批通过。
|
|
|
- String userId = String.valueOf(processData.get("originatorUserId"));
|
|
|
- long cDate = UtilDateTime.parse(UtilMap.getString(processData, "createTime"), "yyyy-MM-dd'T'HH:mm").getTime();//chuangajin
|
|
|
- LocalDateTime dateTime = LocalDateTime.ofInstant(new Date(cDate).toInstant(), ZoneId.systemDefault());
|
|
|
- int nianyue = dateTime.getYear();//所属年份
|
|
|
- double HCGLS = 0;//火车公里数
|
|
|
- double QCGLS = 0;//汽车公里数
|
|
|
- double CZCGLS = 0;//出租车公里数
|
|
|
- double FJGLS = 0;//飞机单程公里数
|
|
|
-
|
|
|
-
|
|
|
- Map formData = UtilMap.map("employeeField_ltxqs53k, departmentSelectField_lu20ayky, dateField_ltxqs53j, textField_lygnetw9, dateField_m3pl2xmv, textField_m4118cyp", Arrays.asList(userId), Arrays.asList(processData.get("originatorDeptId")), cDate, UtilMap.getString(processData, "businessId"), cDate, nianyue);
|
|
|
- String ssgs = "";
|
|
|
- if (SSGS.equals("")) {
|
|
|
- Map formComp_SSGS = formComponentValues.stream().filter(item -> "所属公司".equals(item.get("name"))).findAny().get();
|
|
|
- ssgs = (String) formComp_SSGS.get("value");
|
|
|
- } else {
|
|
|
- ssgs = SSGS;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for (String name : compsId_main.keySet()) {
|
|
|
- String compId = compsId_main.get(name);
|
|
|
- // 判定是否子表 [宜搭]
|
|
|
- if (compId.startsWith("tableField_")) {
|
|
|
- List<Map> details = new ArrayList<>();
|
|
|
- // 兼容明细组件, 存在多条情况 [加班跨天才有有明细]
|
|
|
- Optional optional = formComponentValues.stream().filter(item -> compId_sub_oa.equals(item.get("bizAlias"))).findAny();
|
|
|
- if (!optional.isPresent()) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String schedule = UtilMap.getString((Map) optional.get(), "value");
|
|
|
- List<Map> itineraryList = ((List<Map>) JSON.parse(schedule));
|
|
|
- // 循环明细数据
|
|
|
- String dizhiA = "";
|
|
|
- String dizhiB = "";
|
|
|
- String dcwf = "";//单程往返
|
|
|
- String jtgj = "";//交通工具
|
|
|
- for (Map itinerary : itineraryList) {
|
|
|
- List<Map> rowValue = (List<Map>) itinerary.get("rowValue");
|
|
|
- Map rowData = new HashedMap();
|
|
|
- // 循环子表组件
|
|
|
- for (String subName : compsId_itinerary.keySet()) {
|
|
|
- log.info("子表字段, {}", subName);
|
|
|
- // 加班单跨天 [子表label为空]
|
|
|
-
|
|
|
- rowData.put(compsId_itinerary.get(subName), rowValue.stream().filter(item -> subName.equals(item.get("bizAlias")) || subName.equals(item.get("label"))).findAny().get().get("value"));
|
|
|
- if (subName.equals("出发城市")) {
|
|
|
- dizhiA = (String) rowValue.stream().filter(item -> "出发城市".equals(item.get("bizAlias")) || "出发城市".equals(item.get("label"))).findAny().get().get("value");
|
|
|
- }
|
|
|
- if (subName.equals("目的城市")) {
|
|
|
- dizhiB = (String) rowValue.stream().filter(item -> "目的城市".equals(item.get("bizAlias")) || "目的城市".equals(item.get("label"))).findAny().get().get("value");
|
|
|
- }
|
|
|
- if (subName.equals("交通工具")) {
|
|
|
- jtgj = (String) rowValue.stream().filter(item -> "交通工具".equals(item.get("bizAlias")) || "交通工具".equals(item.get("label"))).findAny().get().get("value");
|
|
|
- }
|
|
|
- if (subName.equals("单程往返")) {
|
|
|
- dcwf = (String) rowValue.stream().filter(item -> "单程往返".equals(item.get("bizAlias")) || "单程往返".equals(item.get("label"))).findAny().get().get("value");
|
|
|
- }
|
|
|
- if (jtgj.contains("其他") && subName.equals("交通工具")) {
|
|
|
- rowData.put(compsId_itinerary.get(subName), "其他");
|
|
|
- String[] parts = jtgj.split("[()]");
|
|
|
- String result = jtgj;
|
|
|
- // 提取括号内的内容(跳过第一个空字符串)
|
|
|
- if (parts.length > 1) {
|
|
|
- result = parts[1];
|
|
|
- System.out.println(result); // 输出: 公车 火车
|
|
|
- }
|
|
|
- rowData.put("textField_m2wrpa40", result);
|
|
|
-
|
|
|
- } else {
|
|
|
- rowData.put(compsId_itinerary.get(subName), rowValue.stream().filter(item -> subName.equals(item.get("bizAlias")) || subName.equals(item.get("label"))).findAny().get().get("value"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- double ipdiz = 0;
|
|
|
- ipdiz = getdizhibyYD(dizhiA, dizhiB);//通过表单源获取计算
|
|
|
-
|
|
|
- if (ipdiz == 0) {
|
|
|
- ipdiz = getdizhi(dizhiA, dizhiB);//通过API计算
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- double leiji = 0;
|
|
|
- double fjleiji = 0;
|
|
|
- rowData.put("numberField_m2sdke98", ipdiz);
|
|
|
- if (dcwf.equals("往返")) {
|
|
|
- rowData.put("numberField_m2wrpa42", ipdiz * 2);
|
|
|
- leiji = ipdiz * 2;
|
|
|
- fjleiji = ipdiz*2;
|
|
|
- } else {
|
|
|
- rowData.put("numberField_m2wrpa42", ipdiz);
|
|
|
- leiji = ipdiz;
|
|
|
- fjleiji = ipdiz;
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (jtgj.contains("汽车")) {
|
|
|
- QCGLS += leiji;
|
|
|
- }
|
|
|
- if (jtgj.contains("火车")) {
|
|
|
- HCGLS += leiji;
|
|
|
- }
|
|
|
- if (jtgj.contains("出租车")) {
|
|
|
- CZCGLS += leiji;
|
|
|
- }
|
|
|
- if (jtgj.contains("飞机")) {
|
|
|
- FJGLS += fjleiji;
|
|
|
- }
|
|
|
- details.add(rowData);
|
|
|
- }
|
|
|
- formData.put(compId, details);
|
|
|
- continue;
|
|
|
- }
|
|
|
- log.info("主表字段, {}", name);
|
|
|
- // 请假套件: 开始时间 / 结束时间 / 时长 / 单位 / 请假类型
|
|
|
- if ("DDHolidayField".equals(name)) {
|
|
|
- Optional optional = formComponentValues.stream().filter(item -> "DDHolidayField".equals(item.get("componentType"))).findAny();
|
|
|
- if (optional.isPresent()) {
|
|
|
- String[] ids = compId.split(" / ");
|
|
|
- List vas = (List) JSON.parse(UtilMap.getString((Map) optional.get(), "value"));
|
|
|
- for (int i = 0; i < ids.length; i++) {
|
|
|
- formData.put(ids[i], vas.get(i));
|
|
|
- }
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //是否为国际差旅 为否才计算 1106先不动
|
|
|
- // 成员组件, 数据处理
|
|
|
- if (name.equals("所属公司") && !SSGS.equals("")){
|
|
|
- formData.put(compId, SSGS);
|
|
|
- }else {
|
|
|
- Map formComp = formComponentValues.stream().filter(item -> name.equals(item.get("name"))).findAny().get();
|
|
|
- Object value = formComp.get("value");
|
|
|
- if ("InnerContactField".equals(formComp.get("componentType")) && formComp.containsKey("value")) {
|
|
|
- List<Map> empInfos = (List<Map>) JSON.parse(String.valueOf(formComp.get("extValue")));
|
|
|
- List<String> emplsId = new ArrayList<>();
|
|
|
- for (Map empInfo : empInfos) {
|
|
|
- emplsId.add(String.valueOf(empInfo.get("emplId")));
|
|
|
- }
|
|
|
- value = emplsId; // 成员多选
|
|
|
- }
|
|
|
- formData.put(compId, value);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 用于审批回传
|
|
|
- List<Map> tasks = UtilMap.getList(processData, "tasks");
|
|
|
- formData.put("textField_lygvvyd9", tasks.get(0).get("taskId"));
|
|
|
- formData.put("textField_lygvvyda", tasks.get(0).get("userId"));
|
|
|
- formData.put("textField_lyh4y3th", processInstanceId);
|
|
|
- formData.put("numberField_m3pl2xm6", HCGLS);
|
|
|
- formData.put("numberField_m3pl2xm8", QCGLS);
|
|
|
- formData.put("numberField_m3pl2xme", CZCGLS);
|
|
|
- if (FJGLS > 3700) {
|
|
|
- formData.put("numberField_m3pl2xmc", FJGLS);
|
|
|
- } else {
|
|
|
- formData.put("numberField_m3pl2xma", FJGLS);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-// formData.put("selectField_lyo1uao4", "否"); // 出差是否报销, 否
|
|
|
-// formData.put("selectField_lyo1zprd", "是"); // 同步存量数据, 否
|
|
|
-
|
|
|
- log.info("审批数据, {}", JSON.toJSONString(formData));
|
|
|
- if (ssgs.equals("上海派能")) {
|
|
|
- ydClient.operateData(YDParam.builder()
|
|
|
- .appType("APP_U4GYY20ZKB7REZKT8586")
|
|
|
- .systemToken("9Z766DC19KWMUGCK7OQ8Z8UQ30YB2VVY74PYLCI3")
|
|
|
- .formUuid("FORM-E41AE15E41CA46D6A245AA1C5E7DFB15D622")
|
|
|
- .formDataJson(JSON.toJSONString(formData))
|
|
|
- .userId(userId)
|
|
|
- .build(), YDConf.FORM_OPERATION.create);
|
|
|
- }
|
|
|
- if (ssgs.equals("扬州派能")) {
|
|
|
- ydClient.operateData(YDParam.builder()
|
|
|
- .appType("APP_LECHEG4IXU554WD3BOUB")
|
|
|
- .systemToken("5H9662C1TMHPRLFDANK0ZCOVUF4I3WOLUMB2MG")
|
|
|
- .formUuid("FORM-65EFD9616EF54386AEDE6F064BC53DE22XGG")
|
|
|
- .formDataJson(JSON.toJSONString(formData))
|
|
|
- .userId(userId)
|
|
|
- .build(), YDConf.FORM_OPERATION.create);
|
|
|
- }
|
|
|
- if (ssgs.equals("安徽派能能源科技有限公司") || ssgs.equals("安徽派能能源技术有限公司") || ssgs.equals("安徽派能")) {
|
|
|
- ydClient.operateData(YDParam.builder()
|
|
|
- .appType("APP_IEZRE28YCR3DE8EFOMG3")
|
|
|
- .systemToken("F2766O915RHP3GY2E4K3M9PF82S92HGY8RC2M122")
|
|
|
- .formUuid("FORM-8ADBE73416E84A65ACBF2AAD81089A50HFM9")
|
|
|
- .formDataJson(JSON.toJSONString(formData))
|
|
|
- .userId(userId)
|
|
|
- .build(), YDConf.FORM_OPERATION.create);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取工时数据 到宜搭碳排放后台,根据公司区别
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void syncYD_GSSJ() {
|
|
|
- try {
|
|
|
- log.info("执行!工时数据");
|
|
|
- System.out.println("执行!工时数据");
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
- params.put("appId", "1");
|
|
|
- params.put("tablename", "ads_hr_work_hours_sub_o");
|
|
|
- params.put("schemalname", "ads");
|
|
|
- params.put("connectortype", "ads_hr_total_api_i");
|
|
|
- params.put("appToken", "Qu9JsOqZ9UJEgMklqr+wlLHAkaSjLCno9YIy34QpT8pG473Z2giJJwA1PZPIUSXO");
|
|
|
- ZhongTai_AllImpl.sendGetRequest_ALL(params);
|
|
|
- log.info("同步结束!工时数据:");
|
|
|
- System.out.println("同步结束!工时数据:");
|
|
|
- } catch (Exception e) {
|
|
|
- log.info(e.toString());
|
|
|
- System.out.println(e.toString());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void syncYD_GSSJTOMonth() {
|
|
|
- try {
|
|
|
- log.info("执行!月度工时数据");
|
|
|
- System.out.println("执行!月度工时数据");
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
- params.put("appId", "1");
|
|
|
- params.put("tablename", "ads_hr_work_hours_sum_o");
|
|
|
- params.put("schemalname", "ads");
|
|
|
- params.put("connectortype", "ads_hr_total_api_i");
|
|
|
- params.put("appToken", "Qu9JsOqZ9UJEgMklqr+wlLHAkaSjLCno9YIy34QpT8pG473Z2giJJwA1PZPIUSXO");
|
|
|
- ZhongTai_AllImpl.sendGetRequest_ALL(params);
|
|
|
- log.info("同步结束!月度工时数据:");
|
|
|
- System.out.println("同步结束!月度工时数据:");
|
|
|
- } catch (Exception e) {
|
|
|
- log.info(e.toString());
|
|
|
- System.out.println(e.toString());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 执行抓取未处理的数据处理写入碳排放
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void CCSJtoYD() throws IOException {
|
|
|
- cn.hutool.json.JSONObject searchCondition = new cn.hutool.json.JSONObject();
|
|
|
- searchCondition.put("textField_m3wod35s", "出差");
|
|
|
- searchCondition.put("textField_m3wod35t", "未同步");
|
|
|
- List<Map> list = (List<Map>) ydClient.queryData(
|
|
|
- YDParam.builder()
|
|
|
- .appType("APP_Z4YYJI3LG8WXWY51L4B2")
|
|
|
- .systemToken("KMC66FA18ZEQU27NCQKE3982F2JH3NF4NHM3MW2")
|
|
|
- .formUuid("FORM-8E9F37B1CCD34F708D560ED0CF59CC27TW5C")
|
|
|
- .searchCondition(JSON.toJSONString(searchCondition))
|
|
|
- .build(),
|
|
|
- YDConf.FORM_QUERY.retrieve_list).getData();
|
|
|
- if (list.size() > 0) {
|
|
|
- for (Map formData : list) {
|
|
|
- String formInstanceId = formData.get("formInstanceId").toString();
|
|
|
- String processInstanceId = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_m3wod35r"));
|
|
|
- String SSGS = String.valueOf(UtilMap.getMap(formData, "formData").get("textField_m4kqfmd9"));
|
|
|
- if (!processInstanceId.equals("")) {
|
|
|
- syncYD_PN(processInstanceId, "出差", SSGS);
|
|
|
- ydClient.operateData(YDParam.builder()
|
|
|
- .appType("APP_Z4YYJI3LG8WXWY51L4B2")
|
|
|
- .systemToken("KMC66FA18ZEQU27NCQKE3982F2JH3NF4NHM3MW2")
|
|
|
- .formInstanceId(String.valueOf(formInstanceId))
|
|
|
- .updateFormDataJson(JSON.toJSONString(UtilMap.map("textField_m3wod35t", "已同步")))
|
|
|
- .build(), YDConf.FORM_OPERATION.update);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /***
|
|
|
- * 通过两个地址,获取两点之间距离
|
|
|
- * @param STR_DZ
|
|
|
- * @param END_DZ
|
|
|
- * @return
|
|
|
- */
|
|
|
-
|
|
|
- private static final String GEOCODING_API_URL = "https://restapi.amap.com/v3/geocode/geo";
|
|
|
-
|
|
|
- private static final String YOUR_AMAP_KEY = "f26ada1decb558baa08accd1a43913c5"; // 高德地图API Key yp的账号
|
|
|
-
|
|
|
- private static final String API_KEY = "f26ada1decb558baa08accd1a43913c5";
|
|
|
- private static final String GEOCODING_API = "http://api.amap.com/v3/geocode/geo?key=%s&address=%s";
|
|
|
-
|
|
|
-
|
|
|
- public double getdizhi(String STR_DZ, String END_DZ) throws IOException {
|
|
|
- double tt = 0;
|
|
|
- try {
|
|
|
- // 第一个位置获取
|
|
|
- double lng_A = 0;
|
|
|
- double lat_A = 0;
|
|
|
-// String API_KEY = "f26ada1decb558baa08accd1a43913c5";
|
|
|
-// String GEOCODING_API = "https://restapi.amap.com/v3/geocode/geo?key=%s&address=%s";
|
|
|
-//
|
|
|
-// String apiUrl = String.format(GEOCODING_API, API_KEY, END_DZ);
|
|
|
-//
|
|
|
-// URL url = new URL(apiUrl);
|
|
|
-// BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8));
|
|
|
-//
|
|
|
-// String inputLine;
|
|
|
-// StringBuilder content = new StringBuilder();
|
|
|
-// while ((inputLine = in.readLine()) != null) {
|
|
|
-// content.append(inputLine);
|
|
|
-// }
|
|
|
-// in.close();
|
|
|
-//
|
|
|
-// // 解析JSON或者XML来获取经纬度
|
|
|
-// // 示例中省略了解析过程,直接打印结果
|
|
|
-// System.out.println(content.toString());
|
|
|
-
|
|
|
- if (true) {
|
|
|
- String encodedCityName = URLEncoder.encode(STR_DZ, String.valueOf(StandardCharsets.UTF_8));
|
|
|
- String requestUrl = GEOCODING_API_URL + "?key=" + YOUR_AMAP_KEY + "&address=" + encodedCityName + "&city=" + encodedCityName;
|
|
|
- URL url = new URL(requestUrl);
|
|
|
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
- connection.setRequestMethod("GET");
|
|
|
- connection.connect();
|
|
|
-
|
|
|
- BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
- String inputLine;
|
|
|
- StringBuffer content = new StringBuffer();
|
|
|
- while ((inputLine = in.readLine()) != null) {
|
|
|
- content.append(inputLine);
|
|
|
- }
|
|
|
- in.close();
|
|
|
- connection.disconnect();
|
|
|
- JSONObject jsonObject = new JSONObject(content.toString());
|
|
|
- if ("1".equals(jsonObject.get("status"))) {
|
|
|
- JSONObject geocodes = jsonObject.getJSONArray("geocodes").getJSONObject(0);
|
|
|
- // String sss=geocodes.get("location").toString();
|
|
|
- lng_A = Double.parseDouble(geocodes.get("location").toString().split(",")[0]);
|
|
|
- lat_A = Double.parseDouble(geocodes.get("location").toString().split(",")[1]);
|
|
|
- System.out.println("A经度:" + lng_A + ", A纬度:" + lat_A);
|
|
|
-
|
|
|
- } else {
|
|
|
- System.out.println("未能成功获取经纬度");
|
|
|
- }
|
|
|
- }
|
|
|
- double lng_B = 0;
|
|
|
- double lat_B = 0;
|
|
|
- if (true) {
|
|
|
- String encodedCityName = URLEncoder.encode(END_DZ, String.valueOf(StandardCharsets.UTF_8));
|
|
|
- String requestUrl = GEOCODING_API_URL + "?key=" + YOUR_AMAP_KEY + "&address=" + encodedCityName + "&city=" + encodedCityName;
|
|
|
- URL url = new URL(requestUrl);
|
|
|
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
- connection.setRequestMethod("GET");
|
|
|
- connection.connect();
|
|
|
- BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
- String inputLine;
|
|
|
- StringBuffer content = new StringBuffer();
|
|
|
- while ((inputLine = in.readLine()) != null) {
|
|
|
- content.append(inputLine);
|
|
|
- }
|
|
|
- in.close();
|
|
|
- connection.disconnect();
|
|
|
- JSONObject jsonObject = new JSONObject(content.toString());
|
|
|
- if ("1".equals(jsonObject.get("status"))) {
|
|
|
- JSONObject geocodes = jsonObject.getJSONArray("geocodes").getJSONObject(0);
|
|
|
- // String sss=geocodes.get("location").toString();
|
|
|
- lng_B = Double.parseDouble(geocodes.get("location").toString().split(",")[0]);
|
|
|
- lat_B = Double.parseDouble(geocodes.get("location").toString().split(",")[1]);
|
|
|
- System.out.println("A经度:" + lng_B + ", A纬度:" + lat_B);
|
|
|
-
|
|
|
- } else {
|
|
|
- System.out.println("未能成功获取经纬度");
|
|
|
- }
|
|
|
- }
|
|
|
-// double EARTH_RADIUS = 6371; // 地球半径,单位为公里
|
|
|
-//
|
|
|
-// double latDistance = toRadians(lat_B - lat_A);
|
|
|
-// double lonDistance = toRadians(lng_B - lng_A);
|
|
|
-// double a = sin(latDistance / 2) * sin(latDistance / 2) +
|
|
|
-// cos(toRadians(lat_A)) * cos(toRadians(lat_B)) *
|
|
|
-// sin(lonDistance / 2) * sin(lonDistance / 2);
|
|
|
-// double c = 2 * atan2(sqrt(a), sqrt(1 - a));
|
|
|
-// tt= EARTH_RADIUS * c;
|
|
|
-
|
|
|
- if (lng_A > 0 && lng_B > 0 && lat_A > 0 && lat_B > 0) {
|
|
|
- double pk = 180 / 3.14169; // 地球周长与直径的比例
|
|
|
- // a1、a2、b1、b2:将纬度和经度转换为弧度后的值
|
|
|
- double a1 = lat_A / pk;
|
|
|
- double a2 = lng_A / pk;
|
|
|
- double b1 = lat_B / pk;
|
|
|
- double b2 = lng_B / pk;
|
|
|
- // t1、t2、t3:三个余弦值,用于后续计算
|
|
|
- double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
|
|
|
- double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
|
|
|
- double t3 = Math.sin(a1) * Math.sin(b1);
|
|
|
- // 两个坐标之间的距离(弧度)
|
|
|
- tt = Math.acos(t1 + t2 + t3) / 1000 * 6371000;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return tt;
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public double getdizhibyYD(String STR_DZ, String END_DZ) {
|
|
|
- double tt = 0;
|
|
|
- try {
|
|
|
- if (!STR_DZ.equals("") && !END_DZ.equals("")) {
|
|
|
- List<Map> dataList = (List<Map>) ydClient.queryData(YDParam.builder()
|
|
|
- .appType("APP_Z4YYJI3LG8WXWY51L4B2")
|
|
|
- .systemToken("KMC66FA18ZEQU27NCQKE3982F2JH3NF4NHM3MW2")
|
|
|
- .formUuid("FORM-6340D2874C3347CA85840D2E55731FB81CZI")
|
|
|
- .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_m3mhndep, textField_m3mhndeq", STR_DZ, END_DZ)))//D041P16
|
|
|
- .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
|
|
|
- if (dataList != null && dataList.size() > 0) {
|
|
|
- for (Map formData : dataList) {
|
|
|
- tt = Double.parseDouble(String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_m3mhnder")));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (tt == 0) {
|
|
|
- dataList = (List<Map>) ydClient.queryData(YDParam.builder()
|
|
|
- .appType("APP_Z4YYJI3LG8WXWY51L4B2")
|
|
|
- .systemToken("KMC66FA18ZEQU27NCQKE3982F2JH3NF4NHM3MW2")
|
|
|
- .formUuid("FORM-6340D2874C3347CA85840D2E55731FB81CZI")
|
|
|
- .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_m3mhndep, textField_m3mhndeq", END_DZ, STR_DZ)))//D041P16
|
|
|
- .build(), YDConf.FORM_QUERY.retrieve_search_form).getData();
|
|
|
- if (dataList != null && dataList.size() > 0) {
|
|
|
- for (Map formData : dataList) {
|
|
|
- tt = Double.parseDouble(String.valueOf(UtilMap.getMap(formData, "formData").get("numberField_m3mhnder")));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- return tt;
|
|
|
-
|
|
|
- }
|
|
|
-}
|