476 lines
24 KiB
Java
476 lines
24 KiB
Java
|
package com.management.tzcontroller;
|
|||
|
|
|||
|
import com.alibaba.fastjson.JSON;
|
|||
|
import com.alibaba.fastjson.JSONObject;
|
|||
|
import com.management.constant.URLConstant;
|
|||
|
import com.management.entity.Filter;
|
|||
|
import com.management.utils.CrmRequestUtil;
|
|||
|
import lombok.extern.slf4j.Slf4j;
|
|||
|
import org.springframework.http.HttpEntity;
|
|||
|
import org.springframework.http.HttpHeaders;
|
|||
|
import org.springframework.web.bind.annotation.PostMapping;
|
|||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
import org.springframework.web.bind.annotation.RestController;
|
|||
|
import org.springframework.web.client.RestClientException;
|
|||
|
import org.springframework.web.client.RestTemplate;
|
|||
|
|
|||
|
import java.text.SimpleDateFormat;
|
|||
|
import java.util.*;
|
|||
|
|
|||
|
@RestController
|
|||
|
@RequestMapping("/api/device/install")
|
|||
|
@Slf4j
|
|||
|
public class DeviceInstallController {
|
|||
|
|
|||
|
private RestTemplate restTemplate = new RestTemplate();
|
|||
|
|
|||
|
public static void main(String[] args) {
|
|||
|
new DeviceInstallController().syncDeviceInstall();
|
|||
|
//new DeviceInstallController().upDeviceInstall();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 台账设备安装同步创建
|
|||
|
*
|
|||
|
* @return void
|
|||
|
* @Author weiloong_zhang
|
|||
|
*/
|
|||
|
@PostMapping("/sync/device")
|
|||
|
public void syncDeviceInstall() {
|
|||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
|||
|
|
|||
|
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
|
|||
|
|
|||
|
JSONObject getDeviceInstall = crmRequestUtil.getCRMList(Arrays.asList(
|
|||
|
new Filter("GT", "last_modified_time", Arrays.asList("1748923200000")),
|
|||
|
new Filter("EQ", "life_status", Arrays.asList("normal")),
|
|||
|
//new Filter("EQ", "name", Arrays.asList("DEV202505260012"))
|
|||
|
new Filter("IN", "ledger_sync_status__c", Arrays.asList(syncStatus))
|
|||
|
), "DeviceObj");
|
|||
|
|
|||
|
JSONObject deviceInstallRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
deviceInstallRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getDeviceInstall, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
if (!"success".equals(deviceInstallRes.getString("errorDescription")) || deviceInstallRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|||
|
log.info("设备安装为空或者请求失败,将不再向下执行");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
log.info("设备信息存在,将继续向下执行");
|
|||
|
|
|||
|
for (Object deviceInstallObj : deviceInstallRes.getJSONObject("data").getJSONArray("dataList")) {
|
|||
|
JSONObject deviceInstallData = JSON.parseObject(JSON.toJSONString(deviceInstallObj));
|
|||
|
|
|||
|
System.out.println("当前正在处理的设备数据为:" + deviceInstallData);
|
|||
|
|
|||
|
//开始截取关键数据
|
|||
|
//设备id
|
|||
|
String deviceId = deviceInstallData.getString("_id");
|
|||
|
//设备编号
|
|||
|
String deviceName = deviceInstallData.getString("name");
|
|||
|
//创建时间
|
|||
|
String createTime = deviceInstallData.getString("create_time");
|
|||
|
|
|||
|
//开始查询是否已经执行过该单据
|
|||
|
JSONObject isLogRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzdevice&log_type=TZSB&dataId=" + deviceId + "&mark=" + createTime, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
|||
|
log.info("数据已经集成过了,将不再继续向下执行");
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
log.info("数据不存在,继续向下执行");
|
|||
|
|
|||
|
//开始封装数据
|
|||
|
Map deviceInstallMap = new HashMap<>();
|
|||
|
deviceInstallMap.put("crmId", deviceId);//发货设备唯一ID
|
|||
|
deviceInstallMap.put("deviceId", deviceInstallData.getString("device_code"));//主板编号
|
|||
|
deviceInstallMap.put("ICCID", deviceInstallData.getString("smart_card_number_iccid__c__r") != null ? deviceInstallData.getString("smart_card_number_iccid__c__r") : "");//智能卡号ICCID
|
|||
|
deviceInstallMap.put("powerStripVersion", deviceInstallData.getString("power_board_program_versio__c") != null ? deviceInstallData.getString("power_board_program_versio__c") : "");//电源板程序版本号
|
|||
|
deviceInstallMap.put("mainBoardVersion", deviceInstallData.getString("mainboard_program_version__c") != null ? deviceInstallData.getString("mainboard_program_version__c") : "");//主板程序版本号
|
|||
|
deviceInstallMap.put("hardwareVersion", deviceInstallData.getString("mainboard_hardware_version__c") != null ? deviceInstallData.getString("mainboard_hardware_version__c") : "");//硬件版本号
|
|||
|
deviceInstallMap.put("deviceHardwareVersion", deviceInstallData.getString("device_hardware__c") != null ? deviceInstallData.getString("device_hardware__c") : "");//设备硬件
|
|||
|
deviceInstallMap.put("systemVersion", deviceInstallData.getString("system_version_number__c") != null ? deviceInstallData.getString("system_version_number__c") : "");//系统版本号
|
|||
|
deviceInstallMap.put("fourGVersion", deviceInstallData.getString("version_4g__c") != null ? deviceInstallData.getString("version_4g__c") : "");//4G版本号
|
|||
|
deviceInstallMap.put("aiVersion", deviceInstallData.getString("ai_version_number__c") != null ? deviceInstallData.getString("ai_version_number__c") : "");//AI版本号
|
|||
|
//deviceInstallMap.put("deviceStatus", "");//todo 设备状态(选项未提供)
|
|||
|
deviceInstallMap.put("preSignContract", deviceInstallData.getString("pre_signed_contract_id__c__r") != null ? deviceInstallData.getString("pre_signed_contract_id__c__r") : "");//预签合同
|
|||
|
deviceInstallMap.put("contract", deviceInstallData.getString("sales_contract_number__c__r") != null ? deviceInstallData.getString("sales_contract_number__c__r") : "");//销售合同
|
|||
|
deviceInstallMap.put("project", deviceInstallData.getString("project_id__c") != null ? deviceInstallData.getString("project_id__c") : "");//项目号
|
|||
|
deviceInstallMap.put("vol", deviceInstallData.getString("voltage_level__c__r") != null ? deviceInstallData.getString("voltage_level__c__r") : "");//电压等级
|
|||
|
deviceInstallMap.put("line", deviceInstallData.getString("line_name__c") != null ? deviceInstallData.getString("line_name__c") : "");//线路名称
|
|||
|
deviceInstallMap.put("tower", deviceInstallData.getString("pole_number__c") != null ? deviceInstallData.getString("pole_number__c") : "");//杆塔号
|
|||
|
deviceInstallMap.put("towerType", deviceInstallData.getString("pole_type__c__r") != null ? deviceInstallData.getString("pole_type__c__r") : "");////杆塔类型
|
|||
|
deviceInstallMap.put("direction", deviceInstallData.getString("installation_direction__c") != null ? deviceInstallData.getString("installation_direction__c") : "");//安装方向
|
|||
|
|
|||
|
//获取安装日期时间戳
|
|||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|||
|
|
|||
|
String installDateStr = deviceInstallData.getString("install_time") != null ? deviceInstallData.getString("install_time") : "";
|
|||
|
|
|||
|
String installDate = "";
|
|||
|
if (!installDateStr.equals("")) {
|
|||
|
installDate = sdf.format(new Date(Long.parseLong(installDateStr)));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
deviceInstallMap.put("installDate", installDate);//安装日期
|
|||
|
|
|||
|
//到期日期
|
|||
|
String expireDateStr = deviceInstallData.getString("mobile_card_expiration_dat__c") != null ? deviceInstallData.getString("mobile_card_expiration_dat__c") : "";
|
|||
|
|
|||
|
String expireDate = "";
|
|||
|
if (!expireDateStr.equals("")) {
|
|||
|
expireDate = sdf.format(new Date(Long.parseLong(expireDateStr)));
|
|||
|
}
|
|||
|
|
|||
|
deviceInstallMap.put("expireDate", expireDate);//到期日期
|
|||
|
deviceInstallMap.put("signalStrength", deviceInstallData.getString("telecom_signal_strength__c") != null ? deviceInstallData.getString("telecom_signal_strength__c") : "");//电信信号强度
|
|||
|
deviceInstallMap.put("supplier", deviceInstallData.getString("supplier_name__c") != null ? deviceInstallData.getString("supplier_name__c") : "");//供方名称
|
|||
|
deviceInstallMap.put("construction", deviceInstallData.getString("construction_company__c__r") != null ? deviceInstallData.getString("construction_company__c__r") : "");//施工方
|
|||
|
deviceInstallMap.put("operationPlatform", deviceInstallData.getString("run_platform__c__r") != null ? deviceInstallData.getString("run_platform__c__r") : "");//运行平台
|
|||
|
deviceInstallMap.put("thirdDeviceId", deviceInstallData.getString("third_party_platform_id__c") != null ? deviceInstallData.getString("third_party_platform_id__c") : "");//第三方平台编号
|
|||
|
deviceInstallMap.put("thirdMotherboardId", deviceInstallData.getString("third_party_mainboard_id__c") != null ? deviceInstallData.getString("third_party_mainboard_id__c") : "");//第三方主板编号
|
|||
|
deviceInstallMap.put("sensor", deviceInstallData.getString("sensor__c") != null ? deviceInstallData.getString("sensor__c") : "");//传感器
|
|||
|
|
|||
|
//更新时间
|
|||
|
String updateTimeStr = deviceInstallData.getString("update_time__c") != null ? deviceInstallData.getString("update_time__c") : "";
|
|||
|
|
|||
|
String updateTime = "";
|
|||
|
if (!updateTimeStr.equals("")) {
|
|||
|
updateTime = sdf.format(new Date(Long.parseLong(updateTimeStr)));
|
|||
|
}
|
|||
|
|
|||
|
deviceInstallMap.put("updateTime", updateTime);//todo 更新时间(待测)
|
|||
|
deviceInstallMap.put("installationSite", deviceInstallData.getString("address") != null ? deviceInstallData.getString("address") : "");//todo 安装地点
|
|||
|
deviceInstallMap.put("itemGroup", deviceInstallData.getString("work_group__c") != null ? deviceInstallData.getString("work_group__c") : "");//班组
|
|||
|
deviceInstallMap.put("coordinate", deviceInstallData.getString("latitude_longitude__c") != null ? deviceInstallData.getString("latitude_longitude__c") : "");//经纬度
|
|||
|
deviceInstallMap.put("stuctureType", deviceInstallData.getString("structure_type__c__r") != null ? deviceInstallData.getString("structure_type__c__r") : "");//结构件类型
|
|||
|
deviceInstallMap.put("photoAmount", deviceInstallData.getBigDecimal("photo_count__c") != null ? deviceInstallData.getBigDecimal("photo_count__c") : 0);//拍照张数
|
|||
|
deviceInstallMap.put("installationGeography", deviceInstallData.getString("installation_geography__c") != null ? deviceInstallData.getString("installation_geography__c") : "");//安装地理环境
|
|||
|
deviceInstallMap.put("constructionWorkers", deviceInstallData.getString("shigongrenyuan__c") != null ? deviceInstallData.getString("shigongrenyuan__c") : "");//施工人员
|
|||
|
deviceInstallMap.put("siteManager", deviceInstallData.getString("on_site_responsible_person__c__r") != null ? deviceInstallData.getString("on_site_responsible_person__c__r") : "");//现场负责人
|
|||
|
deviceInstallMap.put("siteManagerTel", deviceInstallData.getString("on_site_contact_info__c") != null ? deviceInstallData.getString("on_site_contact_info__c") : "");//现场负责人联系方式
|
|||
|
deviceInstallMap.put("devicePurpose", deviceInstallData.getString("device_purpose__c") != null ? deviceInstallData.getString("device_purpose__c") : "");//设备用途
|
|||
|
deviceInstallMap.put("dangerType", deviceInstallData.getString("hazard_type__c") != null ? deviceInstallData.getString("hazard_type__c") : "");//隐患类型
|
|||
|
deviceInstallMap.put("remarks", deviceInstallData.getString("remark__c") != null ? deviceInstallData.getString("remark__c") : "");//备注
|
|||
|
deviceInstallMap.put("deviceDetailState", deviceInstallData.getString("device_installation_status__c__r") != null ? deviceInstallData.getString("device_installation_status__c__r") : "");//设备安装状态
|
|||
|
|
|||
|
Integer isMaintenance = null;
|
|||
|
|
|||
|
switch (deviceInstallData.getString("is_maintenance_mode__c") != null ? deviceInstallData.getString("is_maintenance_mode__c") : "") {
|
|||
|
case "yes":
|
|||
|
isMaintenance = 1;
|
|||
|
break;
|
|||
|
case "no":
|
|||
|
isMaintenance = 0;
|
|||
|
break;
|
|||
|
default:
|
|||
|
isMaintenance = null;
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
deviceInstallMap.put("isMaintenance", isMaintenance);//是否开启维护模式
|
|||
|
|
|||
|
//更新者
|
|||
|
JSONObject updaterJSON = deviceInstallData.getJSONObject("updater__c__r") != null ? deviceInstallData.getJSONObject("updater__c__r") : new JSONObject();
|
|||
|
|
|||
|
String updaterStr = "";
|
|||
|
if (!updaterJSON.isEmpty()) {
|
|||
|
updaterStr = updaterJSON.getString("name");
|
|||
|
}
|
|||
|
|
|||
|
deviceInstallMap.put("updater", updaterStr);//更新者
|
|||
|
deviceInstallMap.put("deviceAttribute", 1);//todo 主副设备
|
|||
|
|
|||
|
//开始获取token
|
|||
|
String token = new LedgerTokenController().getToken();
|
|||
|
|
|||
|
if (token == null || "".equals(token)) {
|
|||
|
log.info("台账token获取失败,将不再向下执行");
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//开始封装请求头
|
|||
|
HttpHeaders headers = new HttpHeaders();
|
|||
|
headers.set("Content-Type", "application/json");
|
|||
|
headers.set("accessToken", token);
|
|||
|
|
|||
|
HttpEntity reqEntity = new HttpEntity(deviceInstallMap, headers);
|
|||
|
|
|||
|
System.out.println(JSON.parseObject(JSON.toJSONString(reqEntity)));
|
|||
|
|
|||
|
//开始发起请求
|
|||
|
String deviceUrl = "http://192.168.5.55:9011/crm/initInstallationDevice";
|
|||
|
|
|||
|
JSONObject deviceResult = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
deviceResult = restTemplate.postForObject(deviceUrl, reqEntity, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
System.out.println(JSON.parseObject(JSON.toJSONString(deviceResult)));
|
|||
|
|
|||
|
//开始封装回写程序
|
|||
|
Map backReqMap = new HashMap();
|
|||
|
backReqMap.put("_id", deviceId);
|
|||
|
backReqMap.put("dataObjectApiName", "DeviceObj");
|
|||
|
|
|||
|
//开始封装日志
|
|||
|
Map logMap = new HashMap<>();
|
|||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
|||
|
logMap.put("log_type", "TZSB");
|
|||
|
logMap.put("syn_type", "0");
|
|||
|
logMap.put("data_name", deviceName);
|
|||
|
logMap.put("data_id", deviceId);
|
|||
|
logMap.put("mark", createTime);
|
|||
|
logMap.put("send_body", JSON.toJSONString(reqEntity));
|
|||
|
logMap.put("send_res", JSON.toJSONString(deviceResult));
|
|||
|
logMap.put("tableName", "send_log_tzdevice");
|
|||
|
|
|||
|
//判断是否执行成功
|
|||
|
if (deviceResult.getInteger("code") == 0) {
|
|||
|
//同步成功
|
|||
|
logMap.put("log_status", "0");
|
|||
|
logMap.put("res_body", "同步成功");
|
|||
|
backReqMap.put("ledger_sync_status__c", "option_sync_success__c");
|
|||
|
backReqMap.put("ledger_response_status__c", deviceResult.getString("msg"));
|
|||
|
} else {
|
|||
|
//同步失败
|
|||
|
logMap.put("log_status", "1");
|
|||
|
logMap.put("res_body", "同步失败:" + deviceResult.getString("msg"));
|
|||
|
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
|
|||
|
backReqMap.put("ledger_response_status__c", deviceResult.getString("msg"));
|
|||
|
}
|
|||
|
|
|||
|
//开始回写
|
|||
|
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
|
|||
|
|
|||
|
JSONObject backRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, backReq, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
System.out.println("回写结果为:" + backRes);
|
|||
|
|
|||
|
//开始记录日志
|
|||
|
JSONObject logRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
System.out.println("日志插入结果为:" + logRes);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 设备安装信息更新
|
|||
|
*
|
|||
|
* @return void
|
|||
|
* @Author weiloong_zhang
|
|||
|
*/
|
|||
|
@PostMapping("/update/device_install")
|
|||
|
public void upDeviceInstall() {
|
|||
|
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
|
|||
|
|
|||
|
JSONObject getDeviceInstall = crmRequestUtil.getCRMList(Arrays.asList(
|
|||
|
//new Filter("EQ", "name", Arrays.asList("DEV202505260012"))
|
|||
|
new Filter("GT", "last_modified_time", Arrays.asList("1748923200000")),
|
|||
|
new Filter("EQ", "ledger_sync_status__c", Arrays.asList("option_sync_success__c")),
|
|||
|
new Filter("EQ", "life_status", Arrays.asList("normal"))
|
|||
|
), "DeviceObj");
|
|||
|
|
|||
|
JSONObject deviceInstallRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
deviceInstallRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getDeviceInstall, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
if (!"success".equals(deviceInstallRes.getString("errorDescription")) || deviceInstallRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|||
|
log.info("设备安装为空或者请求失败,将不再向下执行");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
log.info("设备信息存在,将继续向下执行");
|
|||
|
|
|||
|
for (Object deviceInstallObj : deviceInstallRes.getJSONObject("data").getJSONArray("dataList")) {
|
|||
|
JSONObject deviceInstallData = JSON.parseObject(JSON.toJSONString(deviceInstallObj));
|
|||
|
|
|||
|
System.out.println("当前正在处理的设备数据为:" + deviceInstallData);
|
|||
|
|
|||
|
//开始截取关键数据
|
|||
|
//设备id
|
|||
|
String deviceId = deviceInstallData.getString("_id");
|
|||
|
//设备编号
|
|||
|
String deviceName = deviceInstallData.getString("name");
|
|||
|
//创建时间
|
|||
|
String modifyTime = deviceInstallData.getString("last_modified_time");
|
|||
|
|
|||
|
//开始查询是否已经执行过该单据
|
|||
|
JSONObject isLogRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzdevice&log_type=TZSBUP&dataId=" + deviceId + "&mark=" + modifyTime, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
if (!isLogRes.getJSONArray("data").isEmpty()) {
|
|||
|
log.info("数据已经集成过了,将不再继续向下执行");
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
log.info("数据不存在,继续向下执行");
|
|||
|
|
|||
|
//开始封装数据
|
|||
|
Map deviceInstallMap = new HashMap<>();
|
|||
|
deviceInstallMap.put("deviceId", deviceInstallData.getString("device_code"));//主板编号
|
|||
|
deviceInstallMap.put("preSignContract", deviceInstallData.getString("pre_signed_contract_id__c__r") != null ? deviceInstallData.getString("pre_signed_contract_id__c__r") : "");//预签合同
|
|||
|
deviceInstallMap.put("contract", deviceInstallData.getString("sales_contract_number__c__r") != null ? deviceInstallData.getString("sales_contract_number__c__r") : "");//销售合同
|
|||
|
deviceInstallMap.put("project", deviceInstallData.getString("project_number__c") != null ? deviceInstallData.getString("project_number__c") : "");//项目号
|
|||
|
|
|||
|
//更新者
|
|||
|
List updaterList = deviceInstallData.getJSONArray("updater__c") != null ? deviceInstallData.getJSONArray("updater__c") : new ArrayList();
|
|||
|
|
|||
|
String updaterStr = "";
|
|||
|
|
|||
|
if (!updaterList.isEmpty()) {
|
|||
|
//更新者不为空
|
|||
|
JSONObject getUpdater = crmRequestUtil.getCRMList(Arrays.asList(
|
|||
|
new Filter("EQ", "user_id", updaterList)
|
|||
|
), "PersonnelObj");
|
|||
|
|
|||
|
JSONObject updaterRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
updaterRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getUpdater, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
if ("success".equals(updaterRes.getString("errorDescription")) && !updaterRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
|
|||
|
JSONObject updaterJSON = updaterRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
|
|||
|
|
|||
|
updaterStr = updaterJSON.getString("name");
|
|||
|
} else {
|
|||
|
updaterStr = "";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
deviceInstallMap.put("updater", updaterStr);//更新者
|
|||
|
|
|||
|
//开始获取token
|
|||
|
String token = new LedgerTokenController().getToken();
|
|||
|
|
|||
|
if (token == null || "".equals(token)) {
|
|||
|
log.info("台账token获取失败,将不再向下执行");
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//开始封装请求头
|
|||
|
HttpHeaders headers = new HttpHeaders();
|
|||
|
headers.set("Content-Type", "application/json");
|
|||
|
headers.set("accessToken", token);
|
|||
|
|
|||
|
HttpEntity reqEntity = new HttpEntity(Arrays.asList(deviceInstallMap), headers);
|
|||
|
|
|||
|
System.out.println(JSON.parseObject(JSON.toJSONString(reqEntity)));
|
|||
|
|
|||
|
//开始发起请求
|
|||
|
String deviceUrl = "http://192.168.5.55:9011/crm/updateDeviceContract";
|
|||
|
|
|||
|
JSONObject deviceResult = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
deviceResult = restTemplate.postForObject(deviceUrl, reqEntity, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
System.out.println(JSON.parseObject(JSON.toJSONString(deviceResult)));
|
|||
|
|
|||
|
//开始封装回写程序
|
|||
|
Map backReqMap = new HashMap();
|
|||
|
backReqMap.put("_id", deviceId);
|
|||
|
backReqMap.put("dataObjectApiName", "DeviceObj");
|
|||
|
|
|||
|
//开始封装日志
|
|||
|
Map logMap = new HashMap<>();
|
|||
|
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
|
|||
|
logMap.put("log_type", "TZSBUP");
|
|||
|
logMap.put("syn_type", "0");
|
|||
|
logMap.put("data_name", deviceName);
|
|||
|
logMap.put("data_id", deviceId);
|
|||
|
logMap.put("mark", modifyTime);
|
|||
|
logMap.put("send_body", JSON.toJSONString(reqEntity));
|
|||
|
logMap.put("send_res", JSON.toJSONString(deviceResult));
|
|||
|
logMap.put("tableName", "send_log_tzdevice");
|
|||
|
|
|||
|
//判断是否执行成功
|
|||
|
if (deviceResult.getInteger("code") == 0) {
|
|||
|
//同步成功
|
|||
|
logMap.put("log_status", "0");
|
|||
|
logMap.put("res_body", "同步成功");
|
|||
|
backReqMap.put("ledger_sync_status__c", "option_sync_success__c");
|
|||
|
backReqMap.put("ledger_response_status__c", deviceResult.getString("msg"));
|
|||
|
} else {
|
|||
|
//同步失败
|
|||
|
logMap.put("log_status", "1");
|
|||
|
logMap.put("res_body", "同步失败:" + deviceResult.getString("msg"));
|
|||
|
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
|
|||
|
backReqMap.put("ledger_response_status__c", deviceResult.getString("msg"));
|
|||
|
}
|
|||
|
|
|||
|
//开始回写
|
|||
|
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
|
|||
|
|
|||
|
JSONObject backRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, backReq, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
System.out.println("回写结果为:" + backRes);
|
|||
|
|
|||
|
//开始记录日志
|
|||
|
JSONObject logRes = new JSONObject();
|
|||
|
|
|||
|
try {
|
|||
|
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
|
|||
|
} catch (RestClientException e) {
|
|||
|
e.printStackTrace();
|
|||
|
}
|
|||
|
|
|||
|
System.out.println("日志插入结果为:" + logRes);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|