diff --git a/data/magic-api/api/B-传输日志/日志/保存成本同步日志.ms b/data/magic-api/api/B-传输日志/日志/保存成本同步日志.ms new file mode 100644 index 0000000..58bdc45 --- /dev/null +++ b/data/magic-api/api/B-传输日志/日志/保存成本同步日志.ms @@ -0,0 +1,50 @@ +{ + "properties" : { }, + "id" : "copy1749177616553d59101", + "script" : null, + "groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4", + "name" : "保存成本同步日志", + "createTime" : null, + "updateTime" : 1749178315255, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/cost", + "method" : "POST", + "parameters" : [ ], + "options" : [ { + "name" : "wrap_request_parameter", + "value" : "data", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + }, { + "name" : "permission", + "value" : "send:log:save", + "description" : "允许拥有该权限的访问", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + } ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : null, + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : null +} +================================ + data.create_time = new Date() +return db.table('send_log_costrecord').primary('log_id',uuid()).save(data) \ No newline at end of file diff --git a/data/magic-api/api/B-同步日志/修改成本同步.ms b/data/magic-api/api/B-同步日志/修改成本同步.ms new file mode 100644 index 0000000..69dbbc0 --- /dev/null +++ b/data/magic-api/api/B-同步日志/修改成本同步.ms @@ -0,0 +1,126 @@ +{ + "properties" : { }, + "id" : "copy1749178271384d15677", + "script" : null, + "groupId" : "4506c21162d24d4c81bad5bc8707672a", + "name" : "修改成本同步", + "createTime" : null, + "updateTime" : 1749178284980, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/updatecost", + "method" : "POST", + "parameters" : [ ], + "options" : [ { + "name" : "wrap_request_parameter", + "value" : "data", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + }, { + "name" : "permission", + "value" : "send:log:save", + "description" : "允许拥有该权限的访问", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + } ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 500,\n \"message\": \"系统内部出现错误\",\n \"data\": null,\n \"timestamp\": 1701350039104,\n \"executeTime\": 4\n}", + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "code", + "value" : "500", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "message", + "value" : "系统内部出现错误", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "data", + "value" : "null", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "timestamp", + "value" : "1701350039104", + "description" : "", + "required" : false, + "dataType" : "Long", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "executeTime", + "value" : "4", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } +} +================================ + + + + data.update_time = new Date() +return db.table("send_syn_costrecord").primary('send_id') + .update(data) \ No newline at end of file diff --git a/data/magic-api/api/B-同步日志/成本待同步保存.ms b/data/magic-api/api/B-同步日志/成本待同步保存.ms new file mode 100644 index 0000000..9230037 --- /dev/null +++ b/data/magic-api/api/B-同步日志/成本待同步保存.ms @@ -0,0 +1,126 @@ +{ + "properties" : { }, + "id" : "copy1749178229400d98909", + "script" : null, + "groupId" : "4506c21162d24d4c81bad5bc8707672a", + "name" : "成本待同步保存", + "createTime" : null, + "updateTime" : 1749178253225, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/savecost", + "method" : "POST", + "parameters" : [ ], + "options" : [ { + "name" : "wrap_request_parameter", + "value" : "data", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + }, { + "name" : "permission", + "value" : "send:log:save", + "description" : "允许拥有该权限的访问", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + } ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"17a8bc5553e2400badd36ea784255c01\",\n \"timestamp\": 1701350036264,\n \"executeTime\": 4\n}", + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "code", + "value" : "200", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "message", + "value" : "success", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "data", + "value" : "17a8bc5553e2400badd36ea784255c01", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "timestamp", + "value" : "1701350036264", + "description" : "", + "required" : false, + "dataType" : "Long", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "executeTime", + "value" : "4", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } +} +================================ + + + + data.create_time = new Date() +return db.table("send_syn_costrecord").primary('send_id', () => uuid()) + .save(data) \ No newline at end of file diff --git a/data/magic-api/api/B-同步日志/查询成本同步.ms b/data/magic-api/api/B-同步日志/查询成本同步.ms new file mode 100644 index 0000000..ee9aa46 --- /dev/null +++ b/data/magic-api/api/B-同步日志/查询成本同步.ms @@ -0,0 +1,173 @@ +{ + "properties" : { }, + "id" : "copy1749178288259d99831", + "script" : null, + "groupId" : "4506c21162d24d4c81bad5bc8707672a", + "name" : "查询成本同步", + "createTime" : null, + "updateTime" : 1749178301250, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/querycost", + "method" : "GET", + "parameters" : [ { + "name" : "sendType", + "value" : "user", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + }, { + "name" : "sendStatus3", + "value" : "3", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + }, { + "name" : "crmId", + "value" : "665532391d23d0000111cab9", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + }, { + "name" : "sendSyn", + "value" : "0", + "description" : null, + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + } ], + "options" : [ ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [],\n \"timestamp\": 1716889610473,\n \"executeTime\": 8\n}", + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "code", + "value" : "200", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "message", + "value" : "success", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "data", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Array", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "timestamp", + "value" : "1716889610473", + "description" : "", + "required" : false, + "dataType" : "Long", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "executeTime", + "value" : "8", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } +} +================================ +//查询本机mysql +return db.select( +""" + SELECT * FROM `send_syn_costrecord` where + send_type=#{sendType} + + and dsf_id=#{dataId} + + + and dsfzhu_id=#{datapId} + + + and send_syn=#{sendSyn} + + + and send_status=#{sendStatus} + + + and crm_id=#{crmId} + + + and dsf_id=#{dsfId} + + + and send_status!=#{sendStatus3} + + order by create_time desc + +"""); \ No newline at end of file diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CostController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CostController.java index e4877fe..ae1a78c 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CostController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/CostController.java @@ -17,6 +17,7 @@ import org.ssssssss.magicboot.zdyutils.FXTIC; import org.ssssssss.magicboot.zdyutils.GcjJson; import org.ssssssss.magicboot.zdyutils.MagicApi; +import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.LinkedHashMap; @@ -36,12 +37,13 @@ public class CostController { public static void main(String[] args) throws Exception { - // new CostController().getUserData(); - // new CostController().saveSynUser(); + new CostController().getCostData(); + } - @PostMapping("/getUserData") - public void getUserData() throws Exception { + @PostMapping("/getCostData") + public void getCostData() throws Exception { + FXHTTP fxapi = new FXHTTP(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String starttime = sdf.format(System.currentTimeMillis() - (1000 * 60 * 60 * 24)); String endtime = sdf.format(System.currentTimeMillis() ); @@ -54,6 +56,10 @@ public class CostController { log.info("金蝶token为空或不存在"); return; } + + starttime = "2025-05-28 00:00:00"; + endtime = "2025-05-30 00:00:00"; + headers.put("accessToken", accessToken);//放token JSONObject params = new JSONObject(); params.put("starttime", starttime); @@ -65,23 +71,32 @@ public class CostController { if (resjs != null) { if ("0".equals(resjs.getString("errorCode"))) {//查询成功 - JSONArray resJson = resjs.getJSONArray("data"); System.out.println("待更新成本数量" + resJson.size()); for (int i = 0; i < resJson.size(); i++) { + XKTokenAccess xktonken = new XKTokenAccess(); JSONObject str = resJson.getJSONObject(i); - //ERPID - String dataId = GcjJson.getNodeValue(str, "JSON.id") != null ? GcjJson.getNodeValue(str, "JSON.id").toString() : ""; - //ERP人员编码 - String number = GcjJson.getNodeValue(str, "JSON.number") != null ? GcjJson.getNodeValue(str, "JSON.number").toString() : ""; - String name = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + Object cost = GcjJson.getNodeValue(str, "JSON.cost") != null ? GcjJson.getNodeValue(str, "JSON.cost") : "0.0000000000"; + //物料编码 + String number = GcjJson.getNodeValue(str, "JSON.materialnum") != null ? GcjJson.getNodeValue(str, "JSON.materialnum").toString() : ""; + + String crmcost = "0.0000000000"; + + if (cost != null) { + try { + BigDecimal costBigDecimal = new BigDecimal(cost.toString()); + crmcost= costBigDecimal.stripTrailingZeros().toPlainString(); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } String syn_type = "0";//同步类型 0新增 1修改 2删除 - log.info("-------------------开始执行人员" + i + " -------------------" + number); - XxlJobHelper.log("-------------------开始执行人员" + i + " -------------------" + number); + log.info("-------------------开始执行物料成本" + i + " -------------------" + number); + XxlJobHelper.log("-------------------开始执行物料成本" + i + " -------------------" + number); Boolean sendFlag = false; StringBuffer stringBuffer = new StringBuffer(); @@ -89,30 +104,66 @@ public class CostController { try { boolean tbflag = false; //验证数据是否已存在 - JSONObject dataSyn = MagicApi.getSendSYNUser("user", syn_type, dataId); - - if (dataSyn != null && endtime.equals(dataSyn.getString("mark"))) { - log.info("数据已存在-" + name); - XxlJobHelper.log("--数据已存在---" + name); - tbflag = true; - } - - if (tbflag) { + //查询CRM物料 + String crmId = fxapi.getDataBYID("ProductObj", "name", number, "JSON.data.dataList[0]._id"); + if (crmId == null || "".equals(crmId)) { continue; } - log.info("人员待同步数据-" + i + " ------" + name); - JSONObject jsonObjectData = new JSONObject(); - jsonObjectData.put("send_type", "user"); //业务类型 - jsonObjectData.put("send_syn", syn_type); //同步类型 0新增 1修改 2删除 - jsonObjectData.put("dsf_id", dataId);//数据id - jsonObjectData.put("dsfzhu_id", dataId);//数据id - jsonObjectData.put("send_status", 3);//同步状态 true同步成功 false同步失败 3待同步 - jsonObjectData.put("dsf_code", name);//数据名称 - jsonObjectData.put("mark", endtime);//标识 - jsonObjectData.put("dsf_json", str.toJSONString());//标识 + JSONObject obj = new JSONObject(); + LinkedHashMap map = new LinkedHashMap(); + map.put("body.data.object_data._id", crmId); + map.put("body.data.object_data.field_9fU2M__c", crmcost); + map.put("body.data.object_data.dataObjectApiName", "ProductObj"); + + map.put("body.corpId", FXTIC.CORPID); + map.put("body.corpAccessToken", xktonken.getCorpAccessToken().getCorpAccessToken()); + map.put("body.currentOpenUserId", FXTIC.CURRENTOPENUSERID); + for (Object key : map.keySet()) { + GcjJson.setNodeValue(obj, key.toString(), map.get(key)); + } + log.info("--请求json---" + obj); + String res_url = ""; + String res_param = ""; + String res = ""; + try { + + syn_type = "1"; + res = fxapi.updateV2Obj(obj); + res_url = FXTIC.URL_FX_UPDATE; + + res_param = obj.toJSONString(); + log.info("返回值:" + res); + JSONObject datajs = JSON.parseObject(res); + if (datajs != null && "0".equals(datajs.getString("errorCode"))) { + + } else { + sendFlag = true; + stringBuffer.append(datajs.getString("errorMessage") + ""); + } + } catch (Exception e) { + sendFlag = true; + stringBuffer.append("纷享销客接口调用失败,请检查网络配置"); + } + + JSONObject logData = new JSONObject(); + logData.put("log_type", "productcost"); //业务类型 + logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 + logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除 + logData.put("data_id", crmId);//数据id + logData.put("data_name", number);//数据名称 + logData.put("res_body", "同步成功");//返回值 + logData.put("res_url", res_url);// + logData.put("res_param", res_param);// + logData.put("res_res", res);// + if (sendFlag) { + logData.put("res_body", stringBuffer.toString());//返回值 + } + //写入传输日志 + MagicApi.saveCostLog(logData); + + - MagicApi.saveSendSYNUser(jsonObjectData); } catch (Exception e) { continue; } @@ -125,181 +176,7 @@ public class CostController { } - //@PostMapping("/getSynProduct") - public void saveSynUser() throws Exception { - FXHTTP fxapi = new FXHTTP(); - String resJsonStr = MagicApi.getWNRES("http://127.0.0.1:18088/syn/queryuser?sendType=user&sendStatus=3", ""); - JSONObject resJson = JSON.parseObject(resJsonStr); - if (resJson != null) { - log.info("待同步人员数" + resJson.getJSONArray("data").size()); - for (int i = 0; i < resJson.getJSONArray("data").size(); i++) { - XKTokenAccess xktonken = new XKTokenAccess(); - JSONObject getData = resJson.getJSONArray("data").getJSONObject(i); - JSONObject str = getData.getJSONObject("dsfJson"); - String syn_type = "0";//同步类型 0新增 1修改 2删除 - Boolean sendFlag = false; - StringBuffer stringBuffer = new StringBuffer(); - boolean tbflag = false; - // 构建json - JSONObject obj = new JSONObject(); - LinkedHashMap map = new LinkedHashMap(); - Boolean flag = true; - //ID - String dataId = GcjJson.getNodeValue(str, "JSON.id") != null ? GcjJson.getNodeValue(str, "JSON.id").toString() : ""; - //编码 - String number = GcjJson.getNodeValue(str, "JSON.number") != null ? GcjJson.getNodeValue(str, "JSON.number").toString() : ""; - String name = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; - - //最后修改时间 - String endtime = GcjJson.getNodeValue(str, "JSON.modifytime") != null ? GcjJson.getNodeValue(str, "JSON.modifytime").toString() : ""; - //性别 - String gender = GcjJson.getNodeValue(str, "JSON.gender") != null ? GcjJson.getNodeValue(str, "JSON.gender").toString() : ""; - - String email = GcjJson.getNodeValue(str, "JSON.email") != null ? GcjJson.getNodeValue(str, "JSON.email").toString() : ""; - - String phone = GcjJson.getNodeValue(str, "JSON.phone") != null ? GcjJson.getNodeValue(str, "JSON.phone").toString() : ""; - - //状态 - String enable = GcjJson.getNodeValue(str, "JSON.enable") != null ? GcjJson.getNodeValue(str, "JSON.enable").toString() : ""; - - - JSONArray entryentity = str.getJSONArray("entryentity"); - String deptNumber = ""; - String position = ""; - if (entryentity != null) { - JSONObject deptobj = (JSONObject) entryentity.get(0); - deptNumber = deptobj.getString("dpt_number"); - position = deptobj.getString("position"); - } - - - try { - JSONObject dataSyn = MagicApi.getSendSYNDataUser("user", syn_type, dataId, "3"); - if (dataSyn != null && dataId.equals(dataSyn.getString("dsfId")) && endtime.equals(dataSyn.getString("mark"))) { - log.info("数据已存在-" + name); - XxlJobHelper.log("--数据已存在---" + name); - tbflag = true; - } - if (tbflag) { - continue; - } - - //查询人员CRMID - String crmId = fxapi.getDataBYID("PersonnelObj", "field_T1xid__c", number, "JSON.data.dataList[0]._id"); - if (crmId != null && !crmId.equals("")) { - //人员id - map.put("body.data.object_data._id", crmId); - flag = false; - } - String crmdeptID = "999999"; - if (deptNumber != "") { - crmdeptID = fxapi.getDataBYID("DepartmentObj", "field_Vj6sf__c", deptNumber, "JSON.data.dataList[0]._id"); - System.out.println(crmdeptID); - } - - map.put("body.data.object_data.phone", phone); - map.put("body.data.object_data.name", name); - map.put("body.data.object_data.full_name", name); - map.put("body.data.object_data.erp_id__c", dataId);//ID - map.put("body.data.object_data.field_T1xid__c", number);//编码 - map.put("body.data.object_data.user_name", phone); - map.put("body.data.object_data.email", email); - map.put("body.data.object_data.position", position); - - if (enable.equals("2")) { - map.put("body.data.object_data.status", "1"); - map.put("body.data.object_data.is_pause_login", true); - } else { - map.put("body.data.object_data.status", "0"); - map.put("body.data.object_data.is_pause_login", false); - } - if (gender.equals("1")) { - map.put("body.data.object_data.sex", "M"); - - } - if (gender.equals("2")) { - map.put("body.data.object_data.sex", "F"); - - } else { - map.put("body.data.object_data.sex", "P"); - } - map.put("body.data.object_data.main_department[0]", crmdeptID);//主属部门 - - map.put("body.data.object_data.dataObjectApiName", "PersonnelObj"); - - map.put("body.corpId", FXTIC.CORPID); - map.put("body.corpAccessToken", xktonken.getCorpAccessToken().getCorpAccessToken()); - map.put("body.currentOpenUserId", FXTIC.CURRENTOPENUSERID); - for (Object key : map.keySet()) { - GcjJson.setNodeValue(obj, key.toString(), map.get(key)); - } - log.info("--请求json---" + obj); - XxlJobHelper.log("--请求json---" + obj); - - } catch (Exception e) { - sendFlag = true; - stringBuffer.append("参数解析错误,请联系开发人员"); - e.printStackTrace(); - } - getSynDataSave(stringBuffer, sendFlag, flag, fxapi, dataId, name, obj, getData); - - } - } - } - - /** - * 写数据 - */ - public void getSynDataSave(StringBuffer stringBuffer, Boolean sendFlag, Boolean flag, FXHTTP fxapi, String dataId, String nameData, JSONObject obj, JSONObject str) { - String syn_type = "0";//同步类型 0新增 1修改 2删除 - String res_url = ""; - String res_param = ""; - String res = ""; - try { - if (flag) { - res = fxapi.saveV2Obj(obj); - res_url = FXTIC.URL_FX_CREATE; - } else { - syn_type = "1"; - res = fxapi.updateV2Obj(obj); - res_url = FXTIC.URL_FX_UPDATE; - } - res_param = obj.toJSONString(); - log.info("返回值:" + res); - JSONObject resjs = JSON.parseObject(res); - if (resjs != null && "0".equals(resjs.getString("errorCode"))) { - - } else { - sendFlag = true; - stringBuffer.append(resjs.getString("errorMessage") + ""); - } - } catch (Exception e) { - sendFlag = true; - stringBuffer.append("纷享销客接口调用失败,请检查网络配置"); - } - JSONObject sendData = new JSONObject(); - sendData.put("send_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 - sendData.put("crm_code", nameData);//数据名称 - sendData.put("send_id", str.getString("sendId")); //send_id - MagicApi.updateSendSYUPDATENUser(sendData); - - JSONObject logData = new JSONObject(); - logData.put("log_type", "user"); //业务类型 - logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 - logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除 - logData.put("data_id", dataId);//数据id - logData.put("data_name", nameData);//数据名称 - logData.put("res_body", "同步成功");//返回值 - logData.put("res_url", res_url);// - logData.put("res_param", res_param);// - logData.put("res_res", res);// - if (sendFlag) { - logData.put("res_body", stringBuffer.toString());//返回值 - } - //写入传输日志 - MagicApi.saveUserLog(logData); - } } diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/KDTokenController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/KDTokenController.java index b92b2f5..f832087 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/KDTokenController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/KDTokenController.java @@ -157,7 +157,7 @@ public class KDTokenController { appTokenParams.put("appId", "FXXKCRM"); appTokenParams.put("appSecret", "FXXKCRM20251234a!"); appTokenParams.put("tenantid", "zyierp"); - appTokenParams.put("accountId", "2226057923279195136"); + appTokenParams.put("accountId", "2095345516136108032"); //开始发起请求 String appTokenRes = ""; @@ -214,7 +214,7 @@ public class KDTokenController { accessTokenParams.put("usertype", "Mobile"); accessTokenParams.put("apptoken", getKDAppTokenTest()); accessTokenParams.put("tenantid", "zyierp"); - accessTokenParams.put("accountId", "2226057923279195136"); + accessTokenParams.put("accountId", "2095345516136108032"); accessTokenParams.put("language", "zh_CN"); //开始向金蝶发起请求 diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectNewOpportunityController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectNewOpportunityController.java index c14d824..7652735 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectNewOpportunityController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectNewOpportunityController.java @@ -52,8 +52,7 @@ public class ProjectNewOpportunityController { new CrmFXApiParam("EQ", "life_status", "normal") ); - - // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "国网黑龙江省电力有限公司绥化供电公司可视化采购项目(测试)")); + //List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "溧阳大溪水库低空智能巡检建设项目-水利测试")); JSONObject jsonject = fxapi.getSynNewDataObj(false, "商机", apiName, paramList); JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectObjController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectObjController.java index 730c4db..703f116 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectObjController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/ProjectObjController.java @@ -43,7 +43,6 @@ public class ProjectObjController { String time = sdf.format(System.currentTimeMillis() - (1000 * 60 * 60)); String apiName = "ProjectObj"; - List paramList = Arrays.asList( new CrmFXApiParam("GT", "create_time", "1748923200000"), new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), @@ -53,7 +52,7 @@ public class ProjectObjController { ); - // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "设备台账集成测试22")); + //List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "国网江苏省电力有限公司扬州市江都区供电分公司")); JSONObject jsonject = fxapi.getSynNewDataObj(false, "项目启动单", apiName, paramList); JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); @@ -147,6 +146,16 @@ public class ProjectObjController { }else { org = org1; } + + + + String contractno = GcjJson.getNodeValue(str, "JSON.pre_signed_contract_code__c") != null ? GcjJson.getNodeValue(str, "JSON.pre_signed_contract_code__c").toString() : ""; + + String contractno2 = GcjJson.getNodeValue(str, "JSON.sales_contract_code__c") != null ? GcjJson.getNodeValue(str, "JSON.sales_contract_code__c").toString() : ""; + + + + String strJson = ""; try{ JSONObject dataSyn = MagicApi.getSendSYNDataProject("project", syn_type, dataId,"3"); @@ -172,6 +181,16 @@ public class ProjectObjController { datajson.put("group_number","XM-01");//项目分类 datajson.put("name",nameData);//项目名称 datajson.put("f9w5_crmid",dataId);//CRMID + + + if(!"".equals(contractno2)){ + datajson.put("f9w5_conmsalcontract_number",contractno2);//contractno + }else { + datajson.put("f9w5_conmsalcontract_number",contractno);//contractno + } + + + datajson.put("enable","1");//使用状态 datajson.put("status","C");//数据状态 //创建组织 diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/customerController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/customerController.java index 1b4b937..45d7b58 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/customerController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/customerController.java @@ -30,8 +30,8 @@ public class customerController { static Logger log = LoggerFactory.getLogger("customer"); public static void main(String[] args) throws Exception { - //new customerController().getSynDataAdd(); - new customerController().getSynKHUPdate(); + new customerController().getSynDataAdd(); + new customerController().getSynKH(); } @@ -49,12 +49,13 @@ public class customerController { new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new CrmFXApiParam("IS", "erp_id__c", ""), new CrmFXApiParam("ISN", "erp_category__c", ""), - new CrmFXApiParam("EQ", "sync_status__c", "option_test__c"), + new CrmFXApiParam("N", "record_type", "record_account_terminal_self_register__c"), + // new CrmFXApiParam("EQ", "sync_status__c", "option_test__c"), new CrmFXApiParam("EQ", "life_status", "normal") ); - // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "灵宝市窄口水务管理局")); + // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "国网黑龙江省电力有限公司绥化供电公司")); JSONObject jsonject = fxapi.getSynNewDataObj(false, "客户", apiName, paramList); JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); @@ -338,7 +339,7 @@ public class customerController { String apiName = "AccountObj"; List paramList = Arrays.asList( - new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), + new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 8)), new CrmFXApiParam("ISN", "erp_id__c", ""), new CrmFXApiParam("ISN", "erp_category__c", ""), new CrmFXApiParam("EQ", "sync_status__c", "option_sync_success__c"), diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/intentionPredictionController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/intentionPredictionController.java new file mode 100644 index 0000000..0a9326d --- /dev/null +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/intentionPredictionController.java @@ -0,0 +1,681 @@ +package org.ssssssss.magicboot.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.xxl.job.core.context.XxlJobHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.ssssssss.magicboot.constant.ERPURLConstant; +import org.ssssssss.magicboot.fxapi.HttpClientResult; +import org.ssssssss.magicboot.fxapi.HttpClientUtils; +import org.ssssssss.magicboot.fxapi.XKTokenAccess; +import org.ssssssss.magicboot.fxapi.model.CrmFXApiParam; +import org.ssssssss.magicboot.zdyutils.FXHTTP; +import org.ssssssss.magicboot.zdyutils.GcjJson; +import org.ssssssss.magicboot.zdyutils.MagicApi; + +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/intentionPrediction") +public class intentionPredictionController { + static Logger log = LoggerFactory.getLogger("intentionPrediction"); + + public static void main(String[] args) throws Exception { + new intentionPredictionController().getSynDataAdd(); + new intentionPredictionController().SynSave(); + // new intentionPredictionController().getClose(); + } + + public void getClose()throws Exception{ + FXHTTP fxapi = new FXHTTP(); + String apiName = "intention_prediction__c"; + String[] arr ={"option_close_success__c","option_failure_to_close__c"}; + + List paramList = Arrays.asList( + new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), + new CrmFXApiParam("ISN", "erp_id__c", ""), + new CrmFXApiParam("EQ", "sales_prediction_status__c", "option_is_closed__c"), + new CrmFXApiParam("NIN", "closed_status__c", arr), + new CrmFXApiParam("EQ", "life_status", "normal") + ); + JSONObject jsonject = fxapi.getSynNewDataObj(true, "意向预测关闭", apiName, paramList); + JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); + if(array.isEmpty()){ + return; + } + for (int i = 0; i < array.size(); i++) { + JSONObject str = array.getJSONObject(i); + String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; + String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + String erp_organization__c = GcjJson.getNodeValue(str, "JSON.erp_organization__c") != null ? GcjJson.getNodeValue(str, "JSON.erp_organization__c").toString() : ""; + + Boolean sendFlag = false; + JSONObject params = new JSONObject(); + String strJson = ""; + JSONArray dataarr = new JSONArray(); + JSONObject datajson = new JSONObject(); + String cemployeeid = ""; + if (GcjJson.getNodeValue(str, "JSON.owner__r.id") != null) { + cemployeeid = GcjJson.getNodeValue(str, "JSON.owner__r.id").toString(); + cemployeeid = fxapi.getDataBYID("PersonnelObj", "_id", cemployeeid, "JSON.data.dataList[0].field_T1xid__c"); + } + + String cdeptid = ""; + if (GcjJson.getNodeValue(str, "JSON.owner_department_id") != null) { + String dept_id = GcjJson.getNodeValue(str, "JSON.owner_department_id").toString(); + cdeptid = fxapi.getDataBYID("DepartmentObj", "dept_id", dept_id, "JSON.data.dataList[0].field_Vj6sf__c"); + } + + //统一社会信用代码 + datajson.put("billno",nameData); + datajson.put("billstatus","C");//状态 + datajson.put("f9w5_busstatus","B");//状态 关闭默认为B + datajson.put("f9w5_billtypefield_number","f9w5_sm_predict_BT");//状态 + datajson.put("f9w5_crmid",dataId);//CRMID + datajson.put("f9w5_userdept_number",cdeptid); + datajson.put("f9w5_user_number",cemployeeid); + datajson.put("f9w5_org_number",erp_organization__c);//组织 + + dataarr.add(datajson); + params.put("data",dataarr); + log.info("--请求json---" + params.toJSONString()); + System.out.println("--请求json:---" +params.toJSONString()); + strJson = params.toJSONString(); + StringBuffer stringBuffer = new StringBuffer(); + String syn_type = "2";//同步类型 0新增 1修改 2关闭 + String res_url = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/sm/f9w5_sm_predict/smPredictSave"; + String res_param = params.toJSONString(); + String res = ""; + try { + // String accessToken = "2096108315279888384_8elReBSzvx315JiLWiH82YKJGosF3G2kN688q05rHUritX9x3fWS3lmetalPeMe3HceZV7fK1GdSJsk1J46A3S0VkOxIUqf7wnS207"; + String accessToken = new KDTokenController().getKDAccessTokenTest(); + + Map headers = new HashMap(); + headers.put("accessToken", accessToken);//放token + HttpClientResult rtn = HttpClientUtils.doPostJson(res_url, headers, strJson); + String resStr = rtn.getContent(); + JSONObject resjs = JSONObject.parseObject(resStr); + res = resStr; + if (resjs != null && resjs.getBoolean("status")) { + JSONObject successdata = resjs.getJSONObject("data"); + JSONArray result = successdata.getJSONArray("result"); + JSONObject erpdata = (JSONObject) result.get(0); + String erpid = erpdata.getString("id"); + + Map paramMap = new HashMap(); + // paramMap.put("erp_id__c", erpid);//数据ID + paramMap.put("closed_status__c", "option_close_success__c"); + paramMap.put("sync_info__c", "ERP已关闭"); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + }else{ + sendFlag=true; + stringBuffer.append("意向预测关闭接口调用失败:"+resjs.getString("message")); + Map paramMap = new HashMap(); + paramMap.put("closed_status__c", "option_failure_to_close__c"); + paramMap.put("sync_info__c", stringBuffer); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + } + } catch (Exception e) { + sendFlag = true; + stringBuffer.append("意向预测关闭接口调用失败,请检查网络配置"); + Map paramMap = new HashMap(); + paramMap.put("closed_status__c", "option_failure_to_close__c"); + paramMap.put("sync_info__c", stringBuffer); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + } + + JSONObject logData = new JSONObject(); + logData.put("log_type", "IPclose"); //业务类型 + logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 + logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除 + logData.put("data_id", dataId);//数据id + logData.put("data_name", nameData);//数据名称 + logData.put("res_body", "同步成功");//返回值 + logData.put("res_url", res_url);// + logData.put("res_param", res_param);// + logData.put("res_res", res);// + if (sendFlag) { + logData.put("res_body", stringBuffer.toString());//返回值 + } + //写入传输日志 + MagicApi.saveSPLog(logData); + + + } + + } + + public void getSynDataAdd() throws Exception { + FXHTTP fxapi = new FXHTTP(); + XKTokenAccess xktonken = new XKTokenAccess(); + // 查询magic接口 + //获取时间戳 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String time = sdf.format(System.currentTimeMillis() - (1000 * 60 * 60)); + + String apiName = "intention_prediction__c"; + List paramList = Arrays.asList( + new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 12)), + new CrmFXApiParam("IS", "erp_id__c", ""), + new CrmFXApiParam("GT", "create_time", "1748923200000"), + new CrmFXApiParam("EQ", "sync_status__c", "option_pending_sync__c"), + new CrmFXApiParam("EQ", "life_status", "normal") + ); + + + // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "YXYC2506050001")); + + JSONObject jsonject = fxapi.getSynNewDataObj(true, "意向预测", apiName, paramList); + JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); + List paramListB = Arrays.asList( + new CrmFXApiParam("EQ", "sync_status__c", "option_resync__c"), + new CrmFXApiParam("EQ", "life_status", "normal") + ); + JSONObject jsonjectB = fxapi.getSynNewDataObj(true, "意向预测重新同步", apiName, paramListB); + JSONArray arrayA = jsonjectB.getJSONObject("data").getJSONArray("dataList"); + array.addAll(arrayA); + + + + + for (int i = 0; i < array.size(); i++) { + JSONObject str = array.getJSONObject(i); + String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; + String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + String status = GcjJson.getNodeValue(str, "JSON.sync_status__c") != null ? GcjJson.getNodeValue(str, "JSON.sync_status__c").toString() : ""; + String endtime = GcjJson.getNodeValue(str, "JSON.last_modified_time") != null ? GcjJson.getNodeValue(str, "JSON.last_modified_time").toString() : ""; + + String syn_type = "0";//同步类型 0新增 1修改 2删除 + log.info("-------------------开始执行意向预测" + i + " -------------------" + nameData); + XxlJobHelper.log("-------------------开始执行意向预测" + i + " -------------------" + nameData); + + Boolean sendFlag = false; + StringBuffer stringBuffer = new StringBuffer(); + + try { + boolean tbflag = false; + //验证数据是否已存在 + JSONObject dataSyn = MagicApi.getSendSYNDataSP("IP", syn_type, dataId); + + if (dataSyn != null && dataId.equals(dataSyn.getString("crmId"))) { + log.info("数据已存在-" + nameData); + XxlJobHelper.log("--数据已存在---" + nameData); + tbflag = true; + if("option_resync__c".equals(status) && !endtime.equals(dataSyn.getString("mark"))){ + tbflag = false; + } + + } + if (tbflag) { + continue; + } + log.info("意向预测待同步数据-" + i + " ------" + nameData); + JSONObject jsonObjectData = new JSONObject(); + jsonObjectData.put("send_type", "IP"); //业务类型 + jsonObjectData.put("send_syn", "0"); //同步类型 0新增 1修改 2删除 + jsonObjectData.put("crm_id", dataId);//数据id + jsonObjectData.put("crmzhu_id", dataId);//数据id + jsonObjectData.put("send_status", 3);//同步状态 true同步成功 false同步失败 3待同步 + jsonObjectData.put("crm_code", nameData);//数据名称 + jsonObjectData.put("mark", endtime);//标识 + jsonObjectData.put("crm_json", str.toJSONString());//标识 + + MagicApi.saveSendSYNDataSP(jsonObjectData); + } catch (Exception e) { + continue; + } + + } + } + + public void SynSave() throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + FXHTTP fxapi = new FXHTTP(); + String resJsonStr = MagicApi.getWNRES("http://localhost:18088/syn/querysales_prediction?sendType=IP&sendStatus=3&sendSyn=0", ""); + JSONObject resJson = JSON.parseObject(resJsonStr); + if (resJson != null) { + log.info("待同步意向预测数" + resJson.getJSONArray("data").size()); + for (int i = 0; i < resJson.getJSONArray("data").size(); i++) { + + JSONObject getData = resJson.getJSONArray("data").getJSONObject(i); + JSONObject str = getData.getJSONObject("crmJson"); + String syn_type = "0";//同步类型 0新增 1修改 2删除 + Boolean sendFlag = false; + StringBuffer stringBuffer = new StringBuffer(); + boolean tbflag = false; + // 构建json + + String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; + String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + String remark = GcjJson.getNodeValue(str, "JSON.remark__c") != null ? GcjJson.getNodeValue(str, "JSON.remark__c").toString() : ""; + String status = GcjJson.getNodeValue(str, "JSON.sync_status__c") != null ? GcjJson.getNodeValue(str, "JSON.sync_status__c").toString() : ""; + String endtime = GcjJson.getNodeValue(str, "JSON.last_modified_time") != null ? GcjJson.getNodeValue(str, "JSON.last_modified_time").toString() : ""; + + + String erp_organization__c = GcjJson.getNodeValue(str, "JSON.erp_organization__c") != null ? GcjJson.getNodeValue(str, "JSON.erp_organization__c").toString() : ""; + + String cemployeeid = ""; + if (GcjJson.getNodeValue(str, "JSON.owner__r.id") != null) { + cemployeeid = GcjJson.getNodeValue(str, "JSON.owner__r.id").toString(); + cemployeeid = fxapi.getDataBYID("PersonnelObj", "_id", cemployeeid, "JSON.data.dataList[0].field_T1xid__c"); + } + + String cdeptid = ""; + if (GcjJson.getNodeValue(str, "JSON.owner_department_id") != null) { + String dept_id = GcjJson.getNodeValue(str, "JSON.owner_department_id").toString(); + cdeptid = fxapi.getDataBYID("DepartmentObj", "dept_id", dept_id, "JSON.data.dataList[0].field_Vj6sf__c"); + } + String strJson = ""; + try{ + JSONObject dataSyn = MagicApi.getSendSYNDataSP("IP", syn_type, dataId,"3"); + if (dataSyn != null && dataId.equals(dataSyn.getString("crmId"))) { + log.info("数据已存在-" + nameData); + XxlJobHelper.log("--数据已存在---" + nameData); + tbflag = true; + if("option_resync__c".equals(status) && !endtime.equals(dataSyn.getString("mark"))){ + tbflag = false; + } + } + if (tbflag) { + continue; + } + + JSONObject params = new JSONObject(); + + JSONArray dataarr = new JSONArray(); + JSONObject datajson = new JSONObject(); + //统一社会信用代码 + datajson.put("billno",nameData); + //提出时间 + datajson.put("createtime",sdf.format(GcjJson.getNodeValue(str, "JSON.proposal_date__c"))); + datajson.put("f9w5_remark",remark);//备注 + + datajson.put("f9w5_userdept_number",cdeptid); + datajson.put("f9w5_user_number",cemployeeid); + datajson.put("f9w5_billtypefield_number","f9w5_sm_predict_BT");//状态 + datajson.put("f9w5_crmid",dataId);//CRMID + datajson.put("billstatus","C");//状态 + datajson.put("f9w5_busstatus","A");//状态 新增默认为正常 + + datajson.put("f9w5_org_number",erp_organization__c);//组织 + + JSONArray billentry = new JSONArray(); + + + String apiNameZ = "intention_prediction_details__c"; + JSONObject jsonjectZ = fxapi.getSynDataZDYObj("意向预测明细", apiNameZ, "intention_prediction__c", dataId); + JSONArray arrayZ = jsonjectZ.getJSONObject("data").getJSONArray("dataList"); + for (int j = 0; j < arrayZ.size(); j++) { + JSONObject stra = arrayZ.getJSONObject(j); + JSONObject billentryjson = new JSONObject(); + billentryjson.put("f9w5_qty", GcjJson.getNodeValue(stra, "JSON.quantity__c")); + billentryjson.put("f9w5_deliverydate",sdf.format(GcjJson.getNodeValue(stra, "JSON.required_delivery_time__c"))); + billentryjson.put("f9w5_others", GcjJson.getNodeValue(stra, "JSON.other_requirements__c")); + + billentryjson.put("f9w5_business", GcjJson.getNodeValue(stra, "JSON.opportunity_name_text__c")); + billentryjson.put("f9w5_province",GcjJson.getNodeValue(stra, "JSON.province__c")); + + billentryjson.put("f9w5_prosys_number",GcjJson.getNodeValue(stra, "JSON.product_type__c")); + + billentryjson.put("f9w5_crmentryid",GcjJson.getNodeValue(stra, "JSON._id")); + //billentryjson.put("material_number","10010020374"); + billentry.add(billentryjson); + + } + datajson.put("entryentity",billentry);//意向预测明细 + + dataarr.add(datajson); + params.put("data",dataarr); + log.info("--请求json---" + params.toJSONString()); + System.out.println("--请求json:---" +params.toJSONString()); + strJson = params.toJSONString(); + + }catch (Exception e) { + sendFlag = true; + stringBuffer.append("参数解析错误,请联系开发人员"); + e.printStackTrace(); + } + getSynDataSave(stringBuffer,sendFlag,fxapi,dataId,nameData,strJson,getData); + + } + } + } + /** + * 写数据 + */ + public void getSynDataSave(StringBuffer stringBuffer,Boolean sendFlag,FXHTTP fxapi,String dataId,String nameData,String obj,JSONObject str) { + String syn_type = "0";//同步类型 0新增 1修改 2删除 + String res_url = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/sm/f9w5_sm_predict/smPredictSave"; + String res_param = obj; + String res = ""; + try { + // String accessToken = "2096108315279888384_8elReBSzvx315JiLWiH82YKJGosF3G2kN688q05rHUritX9x3fWS3lmetalPeMe3HceZV7fK1GdSJsk1J46A3S0VkOxIUqf7wnS207"; + String accessToken = new KDTokenController().getKDAccessTokenTest(); + + + Map headers = new HashMap(); + headers.put("accessToken", accessToken);//放token + HttpClientResult rtn = HttpClientUtils.doPostJson(res_url, headers, obj); + String resStr = rtn.getContent(); + JSONObject resjs = JSONObject.parseObject(resStr); + res = resStr; + if (resjs != null && resjs.getBoolean("status")) { + JSONObject successdata = resjs.getJSONObject("data"); + JSONArray result = successdata.getJSONArray("result"); + JSONObject erpdata = (JSONObject) result.get(0); + String erpid = erpdata.getString("id"); + + Map paramMap = new HashMap(); + paramMap.put("erp_id__c", erpid);//数据ID + paramMap.put("sync_status__c", "option_sync_success__c"); + paramMap.put("sync_info__c", "同步完成"); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + }else{ + sendFlag=true; + stringBuffer.append("意向预测创建接口调用失败:"+resjs.getString("message")); + Map paramMap = new HashMap(); + paramMap.put("sync_status__c", "option_sync_failure__c"); + paramMap.put("sync_info__c", stringBuffer); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + } + } catch (Exception e) { + sendFlag = true; + stringBuffer.append("意向预测创建接口调用失败,请检查网络配置"); + Map paramMap = new HashMap(); + paramMap.put("sync_status__c", "option_sync_failure__c"); + paramMap.put("sync_info__c", stringBuffer); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + } + + JSONObject sendData = new JSONObject(); + + sendData.put("send_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 + + sendData.put("send_id", str.getString("sendId")); //send_id + MagicApi.updateSendSYUPDATESP(sendData); + + JSONObject logData = new JSONObject(); + logData.put("log_type", "IP"); //业务类型 + logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 + logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除 + logData.put("data_id", dataId);//数据id + logData.put("data_name", nameData);//数据名称 + logData.put("res_body", "同步成功");//返回值 + logData.put("res_url", res_url);// + logData.put("res_param", res_param);// + logData.put("res_res", res);// + if (sendFlag) { + logData.put("res_body", stringBuffer.toString());//返回值 + } + //写入传输日志 + MagicApi.saveSPLog(logData); + } + + + //修改 + public void getSynDataAddUPdate() throws Exception { + FXHTTP fxapi = new FXHTTP(); + XKTokenAccess xktonken = new XKTokenAccess(); + // 查询magic接口 + //获取时间戳 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String time = sdf.format(System.currentTimeMillis() - (1000 * 60 * 60)); + + String apiName = "intention_prediction__c"; + List paramList = Arrays.asList( + new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 8)), + new CrmFXApiParam("ISN", "erp_id__c", ""), + new CrmFXApiParam("EQ", "sales_prediction_status__c", "option_not_closed__c"), + new CrmFXApiParam("GT", "create_time", "1748923200000"), + new CrmFXApiParam("EQ", "sync_status__c", "option_sync_success__c"), + new CrmFXApiParam("EQ", "life_status", "normal") + ); + + + // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "YXYC2506050001")); + + JSONObject jsonject = fxapi.getSynNewDataObj(true, "意向预测修改", apiName, paramList); + JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); + + + for (int i = 0; i < array.size(); i++) { + JSONObject str = array.getJSONObject(i); + String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; + String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + String status = GcjJson.getNodeValue(str, "JSON.sync_status__c") != null ? GcjJson.getNodeValue(str, "JSON.sync_status__c").toString() : ""; + String endtime = GcjJson.getNodeValue(str, "JSON.last_modified_time") != null ? GcjJson.getNodeValue(str, "JSON.last_modified_time").toString() : ""; + + String syn_type = "1";//同步类型 0新增 1修改 2删除 + log.info("-------------------开始执行意向预测修改" + i + " -------------------" + nameData); + XxlJobHelper.log("-------------------开始执行意向预测修改" + i + " -------------------" + nameData); + + Boolean sendFlag = false; + StringBuffer stringBuffer = new StringBuffer(); + + try { + boolean tbflag = false; + //验证数据是否已存在 + JSONObject dataSyn = MagicApi.getSendSYNDataSP("IP", syn_type, dataId); + + if (dataSyn != null && dataId.equals(dataSyn.getString("crmId")) && endtime.equals(dataSyn.getString("mark")) ) { + log.info("数据已存在-" + nameData); + XxlJobHelper.log("--数据已存在---" + nameData); + tbflag = true; + + } + if (tbflag) { + continue; + } + log.info("意向预测待同步数据-" + i + " ------" + nameData); + JSONObject jsonObjectData = new JSONObject(); + jsonObjectData.put("send_type", "IP"); //业务类型 + jsonObjectData.put("send_syn", "1"); //同步类型 0新增 1修改 2删除 + jsonObjectData.put("crm_id", dataId);//数据id + jsonObjectData.put("crmzhu_id", dataId);//数据id + jsonObjectData.put("send_status", 3);//同步状态 true同步成功 false同步失败 3待同步 + jsonObjectData.put("crm_code", nameData);//数据名称 + jsonObjectData.put("mark", endtime);//标识 + jsonObjectData.put("crm_json", str.toJSONString());//标识 + + MagicApi.saveSendSYNDataSP(jsonObjectData); + } catch (Exception e) { + continue; + } + + } + } + public void SynUpdate() throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + FXHTTP fxapi = new FXHTTP(); + String resJsonStr = MagicApi.getWNRES("http://localhost:18088/syn/querysales_prediction?sendType=IP&sendStatus=3&sendSyn=1", ""); + JSONObject resJson = JSON.parseObject(resJsonStr); + if (resJson != null) { + log.info("待同步意向预测数" + resJson.getJSONArray("data").size()); + for (int i = 0; i < resJson.getJSONArray("data").size(); i++) { + + JSONObject getData = resJson.getJSONArray("data").getJSONObject(i); + JSONObject str = getData.getJSONObject("crmJson"); + String syn_type = "1";//同步类型 0新增 1修改 2删除 + Boolean sendFlag = false; + StringBuffer stringBuffer = new StringBuffer(); + boolean tbflag = false; + // 构建json + + String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; + String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + String remark = GcjJson.getNodeValue(str, "JSON.remark__c") != null ? GcjJson.getNodeValue(str, "JSON.remark__c").toString() : ""; + String status = GcjJson.getNodeValue(str, "JSON.sync_status__c") != null ? GcjJson.getNodeValue(str, "JSON.sync_status__c").toString() : ""; + String endtime = GcjJson.getNodeValue(str, "JSON.last_modified_time") != null ? GcjJson.getNodeValue(str, "JSON.last_modified_time").toString() : ""; + + + String erp_organization__c = GcjJson.getNodeValue(str, "JSON.erp_organization__c") != null ? GcjJson.getNodeValue(str, "JSON.erp_organization__c").toString() : ""; + + String cemployeeid = ""; + if (GcjJson.getNodeValue(str, "JSON.owner__r.id") != null) { + cemployeeid = GcjJson.getNodeValue(str, "JSON.owner__r.id").toString(); + cemployeeid = fxapi.getDataBYID("PersonnelObj", "_id", cemployeeid, "JSON.data.dataList[0].field_T1xid__c"); + } + + String cdeptid = ""; + if (GcjJson.getNodeValue(str, "JSON.owner_department_id") != null) { + String dept_id = GcjJson.getNodeValue(str, "JSON.owner_department_id").toString(); + cdeptid = fxapi.getDataBYID("DepartmentObj", "dept_id", dept_id, "JSON.data.dataList[0].field_Vj6sf__c"); + } + String strJson = ""; + try{ + JSONObject dataSyn = MagicApi.getSendSYNDataSP("IP", syn_type, dataId,"3"); + if (dataSyn != null && dataId.equals(dataSyn.getString("crmId")) && endtime.equals(dataSyn.getString("mark")) ) { + log.info("数据已存在-" + nameData); + XxlJobHelper.log("--数据已存在---" + nameData); + tbflag = true; + + } + if (tbflag) { + continue; + } + + JSONObject params = new JSONObject(); + + JSONArray dataarr = new JSONArray(); + JSONObject datajson = new JSONObject(); + //统一社会信用代码 + datajson.put("billno",nameData); + //提出时间 + datajson.put("createtime",sdf.format(GcjJson.getNodeValue(str, "JSON.proposal_date__c"))); + datajson.put("f9w5_remark",remark);//备注 + + datajson.put("f9w5_userdept_number",cdeptid); + datajson.put("f9w5_user_number",cemployeeid); + datajson.put("f9w5_billtypefield_number","f9w5_sm_predict_BT");//状态 + datajson.put("f9w5_crmid",dataId);//CRMID + datajson.put("billstatus","C");//状态 + datajson.put("f9w5_busstatus","A");//状态 新增默认为正常 + + datajson.put("f9w5_org_number",erp_organization__c);//组织 + + JSONArray billentry = new JSONArray(); + + + String apiNameZ = "intention_prediction_details__c"; + JSONObject jsonjectZ = fxapi.getSynDataZDYObj("意向预测明细", apiNameZ, "intention_prediction__c", dataId); + JSONArray arrayZ = jsonjectZ.getJSONObject("data").getJSONArray("dataList"); + for (int j = 0; j < arrayZ.size(); j++) { + JSONObject stra = arrayZ.getJSONObject(j); + JSONObject billentryjson = new JSONObject(); + billentryjson.put("f9w5_qty", GcjJson.getNodeValue(stra, "JSON.quantity__c")); + billentryjson.put("f9w5_deliverydate",sdf.format(GcjJson.getNodeValue(stra, "JSON.required_delivery_time__c"))); + billentryjson.put("f9w5_others", GcjJson.getNodeValue(stra, "JSON.other_requirements__c")); + + billentryjson.put("f9w5_business", GcjJson.getNodeValue(stra, "JSON.opportunity_name_text__c")); + billentryjson.put("f9w5_province",GcjJson.getNodeValue(stra, "JSON.province__c")); + + billentryjson.put("f9w5_prosys_number",GcjJson.getNodeValue(stra, "JSON.product_type__c")); + + billentryjson.put("f9w5_crmentryid",GcjJson.getNodeValue(stra, "JSON._id")); + + billentry.add(billentryjson); + + } + datajson.put("entryentity",billentry);//意向预测明细 + + dataarr.add(datajson); + params.put("data",dataarr); + log.info("--请求json---" + params.toJSONString()); + System.out.println("--请求json:---" +params.toJSONString()); + strJson = params.toJSONString(); + + }catch (Exception e) { + sendFlag = true; + stringBuffer.append("参数解析错误,请联系开发人员"); + e.printStackTrace(); + } + getSynDataSaveUpdate(stringBuffer,sendFlag,fxapi,dataId,nameData,strJson,getData); + + } + } + } + + + public void getSynDataSaveUpdate(StringBuffer stringBuffer,Boolean sendFlag,FXHTTP fxapi,String dataId,String nameData,String obj,JSONObject str) { + String syn_type = "1";//同步类型 0新增 1修改 2删除 + String res_url = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/sm/f9w5_sm_predict/smPredictSave"; + String res_param = obj; + String res = ""; + try { + // String accessToken = "2096108315279888384_8elReBSzvx315JiLWiH82YKJGosF3G2kN688q05rHUritX9x3fWS3lmetalPeMe3HceZV7fK1GdSJsk1J46A3S0VkOxIUqf7wnS207"; + String accessToken = new KDTokenController().getKDAccessTokenTest(); + + + Map headers = new HashMap(); + headers.put("accessToken", accessToken);//放token + HttpClientResult rtn = HttpClientUtils.doPostJson(res_url, headers, obj); + String resStr = rtn.getContent(); + JSONObject resjs = JSONObject.parseObject(resStr); + res = resStr; + if (resjs != null && resjs.getBoolean("status")) { + JSONObject successdata = resjs.getJSONObject("data"); + JSONArray result = successdata.getJSONArray("result"); + JSONObject erpdata = (JSONObject) result.get(0); + String erpid = erpdata.getString("id"); + + }else{ + sendFlag=true; + stringBuffer.append("意向预测修改接口调用失败:"+resjs.getString("message")); + Map paramMap = new HashMap(); + paramMap.put("sync_status__c", "option_sync_failure__c"); + paramMap.put("sync_info__c", stringBuffer); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + } + } catch (Exception e) { + sendFlag = true; + stringBuffer.append("意向预测修改接口调用失败,请检查网络配置"); + Map paramMap = new HashMap(); + paramMap.put("sync_status__c", "option_sync_failure__c"); + paramMap.put("sync_info__c", stringBuffer); + //回写json + fxapi.upSynZDYFieldParam("", "intention_prediction__c", dataId, paramMap); + } + + JSONObject sendData = new JSONObject(); + + sendData.put("send_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 + + sendData.put("send_id", str.getString("sendId")); //send_id + MagicApi.updateSendSYUPDATESP(sendData); + + JSONObject logData = new JSONObject(); + logData.put("log_type", "IP"); //业务类型 + logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 + logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除 + logData.put("data_id", dataId);//数据id + logData.put("data_name", nameData);//数据名称 + logData.put("res_body", "同步成功");//返回值 + logData.put("res_url", res_url);// + logData.put("res_param", res_param);// + logData.put("res_res", res);// + if (sendFlag) { + logData.put("res_body", stringBuffer.toString());//返回值 + } + //写入传输日志 + MagicApi.saveSPLog(logData); + } + + + + +} diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/materialreqbillXTController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/materialreqbillXTController.java index 3708095..92a5404 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/materialreqbillXTController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/materialreqbillXTController.java @@ -29,8 +29,8 @@ public class materialreqbillXTController { static Logger log = LoggerFactory.getLogger("materialreqbillv2"); public static void main(String[] args) throws Exception { - new materialreqbillXTController().getSynDataAdd(); - new materialreqbillXTController().materialreqbillSave(); + new materialreqbillXTController().getOperation(); + // new materialreqbillXTController().materialreqbillSave(); } public void getOperation()throws Exception{ @@ -75,15 +75,15 @@ public class materialreqbillXTController { String apiName = "shipping_application__c"; - List paramList = Arrays.asList( + /* List paramList = Arrays.asList( new CrmFXApiParam("GT", "create_time", "1748923200000"), new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new CrmFXApiParam("IS", "erp_id__c", ""), new CrmFXApiParam("EQ", "sync_status__c", "option_pending_sync__c"), new CrmFXApiParam("EQ", "life_status", "under_review") - ); + );*/ - // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "FHSQ202505280014")); + List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "FHSQ202506060003")); JSONObject jsonject = fxapi.getSynNewDataObj(true, "发货申请", apiName, paramList); JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/salesPredictionController.java b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/salesPredictionController.java index afce89f..f0042d8 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/controller/salesPredictionController.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/controller/salesPredictionController.java @@ -35,6 +35,11 @@ public class salesPredictionController { } + + + + + public void getSynDataAdd() throws Exception { FXHTTP fxapi = new FXHTTP(); XKTokenAccess xktonken = new XKTokenAccess(); @@ -48,20 +53,32 @@ public class salesPredictionController { List paramList = Arrays.asList( new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new CrmFXApiParam("IS", "erp_id__c", ""), + new CrmFXApiParam("GT", "create_time", "1748923200000"), + new CrmFXApiParam("EQ", "sync_status__c", "option_pending_sync__c"), new CrmFXApiParam("EQ", "life_status", "normal") ); - - // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "XSYC-20250312-0001")); + // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "XSYC250605-0003")); JSONObject jsonject = fxapi.getSynNewDataObj(true, "销售预测", apiName, paramList); JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); + List paramListB = Arrays.asList( + new CrmFXApiParam("EQ", "sync_status__c", "option_resync__c"), + new CrmFXApiParam("EQ", "life_status", "normal") + ); + JSONObject jsonjectB = fxapi.getSynNewDataObj(true, "销售预测重新同步", apiName, paramListB); + JSONArray arrayA = jsonjectB.getJSONObject("data").getJSONArray("dataList"); + array.addAll(arrayA); + + for (int i = 0; i < array.size(); i++) { JSONObject str = array.getJSONObject(i); String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; + String status = GcjJson.getNodeValue(str, "JSON.sync_status__c") != null ? GcjJson.getNodeValue(str, "JSON.sync_status__c").toString() : ""; + String endtime = GcjJson.getNodeValue(str, "JSON.last_modified_time") != null ? GcjJson.getNodeValue(str, "JSON.last_modified_time").toString() : ""; String syn_type = "0";//同步类型 0新增 1修改 2删除 log.info("-------------------开始执行销售预测" + i + " -------------------" + nameData); @@ -79,6 +96,10 @@ public class salesPredictionController { log.info("数据已存在-" + nameData); XxlJobHelper.log("--数据已存在---" + nameData); tbflag = true; + if("option_resync__c".equals(status) && !endtime.equals(dataSyn.getString("mark"))){ + tbflag = false; + } + } if (tbflag) { continue; @@ -91,7 +112,7 @@ public class salesPredictionController { jsonObjectData.put("crmzhu_id", dataId);//数据id jsonObjectData.put("send_status", 3);//同步状态 true同步成功 false同步失败 3待同步 jsonObjectData.put("crm_code", nameData);//数据名称 - jsonObjectData.put("mark", nameData);//标识 + jsonObjectData.put("mark", endtime);//标识 jsonObjectData.put("crm_json", str.toJSONString());//标识 MagicApi.saveSendSYNDataSP(jsonObjectData); @@ -122,6 +143,11 @@ public class salesPredictionController { String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; String remark = GcjJson.getNodeValue(str, "JSON.remark__c") != null ? GcjJson.getNodeValue(str, "JSON.remark__c").toString() : ""; + String intention_prediction_code__c = GcjJson.getNodeValue(str, "JSON.intention_prediction_code__c") != null ? GcjJson.getNodeValue(str, "JSON.intention_prediction_code__c").toString() : ""; + String status = GcjJson.getNodeValue(str, "JSON.sync_status__c") != null ? GcjJson.getNodeValue(str, "JSON.sync_status__c").toString() : ""; + String endtime = GcjJson.getNodeValue(str, "JSON.last_modified_time") != null ? GcjJson.getNodeValue(str, "JSON.last_modified_time").toString() : ""; + + String erp_organization__c = GcjJson.getNodeValue(str, "JSON.erp_organization__c") != null ? GcjJson.getNodeValue(str, "JSON.erp_organization__c").toString() : ""; String cemployeeid = ""; @@ -129,10 +155,7 @@ public class salesPredictionController { cemployeeid = GcjJson.getNodeValue(str, "JSON.owner__r.id").toString(); cemployeeid = fxapi.getDataBYID("PersonnelObj", "_id", cemployeeid, "JSON.data.dataList[0].field_T1xid__c"); } - /* if (StringUtils.isBlank(cemployeeid)) { - sendFlag = true; - stringBuffer.append("销售员不存在\n"); - }*/ + String cdeptid = ""; if (GcjJson.getNodeValue(str, "JSON.owner_department_id") != null) { String dept_id = GcjJson.getNodeValue(str, "JSON.owner_department_id").toString(); @@ -146,6 +169,9 @@ public class salesPredictionController { log.info("数据已存在-" + nameData); XxlJobHelper.log("--数据已存在---" + nameData); tbflag = true; + if("option_resync__c".equals(status) && !endtime.equals(dataSyn.getString("mark"))){ + tbflag = false; + } } if (tbflag) { continue; @@ -160,7 +186,7 @@ public class salesPredictionController { //简称 datajson.put("biztime",sdf.format(GcjJson.getNodeValue(str, "JSON.proposal_date__c"))); datajson.put("comment",remark);//备注 - datajson.put("org_number",cdeptid); + datajson.put("org_number",erp_organization__c); datajson.put("dept_number",cdeptid); datajson.put("user_number",cemployeeid); @@ -169,6 +195,12 @@ public class salesPredictionController { datajson.put("f9w5_crmid",dataId);//CRMID // datajson.put("settlementtypeid_number","JSFS04");//结算方式 + datajson.put("f9w5_busstatus","A");//状态 新增默认为正常 + + datajson.put("billstatus","C"); + datajson.put("f9w5_predict",intention_prediction_code__c);//原始预测单据号 + + JSONArray billentry = new JSONArray(); @@ -183,20 +215,31 @@ public class salesPredictionController { billentryjson.put("f9w5_tagname", GcjJson.getNodeValue(stra, "JSON.tag_name__c")); billentryjson.put("f9w5_parameter",GcjJson.getNodeValue(stra, "JSON.parameter__c")); - billentryjson.put("f9w5_country",GcjJson.getNodeValue(stra, "JSON.field_4o10E__c__r")); - billentryjson.put("f9w5_province",GcjJson.getNodeValue(stra, "JSON.field_S0ue4__c__r")); - billentryjson.put("f9w5_city",GcjJson.getNodeValue(stra, "JSON.field_s6uUm__c__r")); - billentryjson.put("f9w5_area",GcjJson.getNodeValue(stra, "JSON.field_kq1O4__c__r")); + billentryjson.put("f9w5_country",GcjJson.getNodeValue(stra, "JSON.country__c")); + billentryjson.put("f9w5_province",GcjJson.getNodeValue(stra, "JSON.province__c")); + billentryjson.put("f9w5_city",GcjJson.getNodeValue(stra, "JSON.city__c")); + billentryjson.put("f9w5_area",GcjJson.getNodeValue(stra, "JSON.district__c")); billentryjson.put("f9w5_siminfo",GcjJson.getNodeValue(stra, "JSON.sim_card_info__c")); - // billentryjson.put("f9w5_isurgent",GcjJson.getNodeValue(stra, "JSON.is_urgent__c")); - billentryjson.put("f9w5_isurgent","1"); + //billentryjson.put("f9w5_isurgent",GcjJson.getNodeValue(stra, "JSON.is_urgent__c")); + + String is_urgent__c = GcjJson.getNodeValue(stra, "JSON.is_urgent__c") != null ? GcjJson.getNodeValue(stra, "JSON.is_urgent__c").toString() : ""; + if("1".equals(is_urgent__c)){ + billentryjson.put("f9w5_isurgent",true); + } else if ("2".equals(is_urgent__c)) { + billentryjson.put("f9w5_isurgent",false); + } + + + billentryjson.put("f9w5_reqdelvytime",sdf.format(GcjJson.getNodeValue(stra, "JSON.required_delivery_time__c"))); billentryjson.put("f9w5_thirdpartyid",GcjJson.getNodeValue(stra, "JSON.third_party_id__c")); billentryjson.put("f9w5_otherrequire",GcjJson.getNodeValue(stra, "JSON.other_requirements__c")); billentryjson.put("entrycomment",GcjJson.getNodeValue(stra, "JSON.remark__c")); billentryjson.put("material_number",GcjJson.getNodeValue(stra, "JSON.product_code_text__c")); - //billentryjson.put("material_number","10010020374"); + billentryjson.put("f9w5_crmentryid",GcjJson.getNodeValue(stra, "JSON._id")); + + billentry.add(billentryjson); } @@ -247,7 +290,7 @@ public class salesPredictionController { Map paramMap = new HashMap(); paramMap.put("erp_id__c", erpid);//数据ID paramMap.put("sync_status__c", "option_sync_success__c"); - paramMap.put("sync_info__c", resjs.getString("message")); + paramMap.put("sync_info__c", "同步完成"); //回写json fxapi.upSynZDYFieldParam("", "sales_prediction__c", dataId, paramMap); }else{ @@ -294,256 +337,6 @@ public class salesPredictionController { } - public void getSynDataUP() throws Exception { - FXHTTP fxapi = new FXHTTP(); - XKTokenAccess xktonken = new XKTokenAccess(); - // 查询magic接口 - //获取时间戳 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String time = sdf.format(System.currentTimeMillis() - (1000 * 60 * 60)); - - String apiName = "sales_prediction__c"; - - List paramList = Arrays.asList( - new CrmFXApiParam("GT", "last_modified_time", System.currentTimeMillis() - (1000 * 60 * 60 * 24)), - new CrmFXApiParam("ISN", "erp_id__c", ""), - new CrmFXApiParam("EQ", "life_status", "normal") - ); - - - // List paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "XSYC-20250312-0001")); - - JSONObject jsonject = fxapi.getSynNewDataObj(true, "销售预测", apiName, paramList); - JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList"); - - - for (int i = 0; i < array.size(); i++) { - JSONObject str = array.getJSONObject(i); - String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; - String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; - - String syn_type = "0";//同步类型 0新增 1修改 2删除 - log.info("-------------------开始执行销售预测" + i + " -------------------" + nameData); - XxlJobHelper.log("-------------------开始执行销售预测" + i + " -------------------" + nameData); - - Boolean sendFlag = false; - StringBuffer stringBuffer = new StringBuffer(); - - try { - boolean tbflag = false; - //验证数据是否已存在 - JSONObject dataSyn = MagicApi.getSendSYNDataSP("SPUP", syn_type, dataId); - - if (dataSyn != null && dataId.equals(dataSyn.getString("crmId"))) { - log.info("数据已存在-" + nameData); - XxlJobHelper.log("--数据已存在---" + nameData); - tbflag = true; - } - if (tbflag) { - continue; - } - log.info("销售预测待同步数据-" + i + " ------" + nameData); - JSONObject jsonObjectData = new JSONObject(); - jsonObjectData.put("send_type", "SPUP"); //业务类型 - jsonObjectData.put("send_syn", "1"); //同步类型 0新增 1修改 2删除 - jsonObjectData.put("crm_id", dataId);//数据id - jsonObjectData.put("crmzhu_id", dataId);//数据id - jsonObjectData.put("send_status", 3);//同步状态 true同步成功 false同步失败 3待同步 - jsonObjectData.put("crm_code", nameData);//数据名称 - jsonObjectData.put("mark", nameData);//标识 - jsonObjectData.put("crm_json", str.toJSONString());//标识 - - MagicApi.saveSendSYNDataSP(jsonObjectData); - } catch (Exception e) { - continue; - } - - } - } - - public void SynUpdate() throws Exception { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - FXHTTP fxapi = new FXHTTP(); - String resJsonStr = MagicApi.getWNRES("http://localhost:18088/syn/querysales_prediction?sendType=SPUP&sendStatus=3&sendSyn=1", ""); - JSONObject resJson = JSON.parseObject(resJsonStr); - if (resJson != null) { - log.info("待同步销售预测数" + resJson.getJSONArray("data").size()); - for (int i = 0; i < resJson.getJSONArray("data").size(); i++) { - - JSONObject getData = resJson.getJSONArray("data").getJSONObject(i); - JSONObject str = getData.getJSONObject("crmJson"); - String syn_type = "1";//同步类型 0新增 1修改 2删除 - Boolean sendFlag = false; - StringBuffer stringBuffer = new StringBuffer(); - boolean tbflag = false; - // 构建json - - String dataId = GcjJson.getNodeValue(str, "JSON._id") != null ? GcjJson.getNodeValue(str, "JSON._id").toString() : ""; - String nameData = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : ""; - String remark = GcjJson.getNodeValue(str, "JSON.remark__c") != null ? GcjJson.getNodeValue(str, "JSON.remark__c").toString() : ""; - - - String cemployeeid = ""; - if (GcjJson.getNodeValue(str, "JSON.owner__r.id") != null) { - cemployeeid = GcjJson.getNodeValue(str, "JSON.owner__r.id").toString(); - cemployeeid = fxapi.getDataBYID("PersonnelObj", "_id", cemployeeid, "JSON.data.dataList[0].field_T1xid__c"); - } - /* if (StringUtils.isBlank(cemployeeid)) { - sendFlag = true; - stringBuffer.append("销售员不存在\n"); - }*/ - String cdeptid = ""; - if (GcjJson.getNodeValue(str, "JSON.owner_department_id") != null) { - String dept_id = GcjJson.getNodeValue(str, "JSON.owner_department_id").toString(); - cdeptid = fxapi.getDataBYID("DepartmentObj", "dept_id", dept_id, "JSON.data.dataList[0].field_Vj6sf__c"); - } - // cdeptid = "zyierp"; - String strJson = ""; - try{ - JSONObject dataSyn = MagicApi.getSendSYNDataSP("SP", syn_type, dataId,"3"); - if (dataSyn != null && dataId.equals(dataSyn.getString("crmId"))) { - log.info("数据已存在-" + nameData); - XxlJobHelper.log("--数据已存在---" + nameData); - tbflag = true; - } - if (tbflag) { - continue; - } - - JSONObject params = new JSONObject(); - - JSONArray dataarr = new JSONArray(); - JSONObject datajson = new JSONObject(); - //统一社会信用代码 - datajson.put("billno",nameData); - //简称 - datajson.put("biztime",sdf.format(GcjJson.getNodeValue(str, "JSON.proposal_date__c"))); - datajson.put("comment",remark);//备注 - datajson.put("org_number",cdeptid); - datajson.put("dept_number",cdeptid); - datajson.put("user_number",cemployeeid); - - datajson.put("billtype_number","f9w5_salespred_BT");//类型 - - datajson.put("f9w5_crmid",dataId);//CRMID - // datajson.put("settlementtypeid_number","JSFS04");//结算方式 - - JSONArray billentry = new JSONArray(); - - - String apiNameZ = "sales_prediction_details__c"; - JSONObject jsonjectZ = fxapi.getSynDataZDYObj("销售预测明细", apiNameZ, "sales_prediction_id__c", dataId); - JSONArray arrayZ = jsonjectZ.getJSONObject("data").getJSONArray("dataList"); - for (int j = 0; j < arrayZ.size(); j++) { - JSONObject stra = arrayZ.getJSONObject(j); - JSONObject billentryjson = new JSONObject(); - billentryjson.put("qty", GcjJson.getNodeValue(stra, "JSON.quantity__c")); - billentryjson.put("f9w5_busopportunity", GcjJson.getNodeValue(stra, "JSON.opportunity_name_text__c")); - billentryjson.put("f9w5_tagname", GcjJson.getNodeValue(stra, "JSON.tag_name__c")); - billentryjson.put("f9w5_parameter",GcjJson.getNodeValue(stra, "JSON.parameter__c")); - - billentryjson.put("f9w5_country",GcjJson.getNodeValue(stra, "JSON.field_4o10E__c__r")); - billentryjson.put("f9w5_province",GcjJson.getNodeValue(stra, "JSON.field_S0ue4__c__r")); - billentryjson.put("f9w5_city",GcjJson.getNodeValue(stra, "JSON.field_s6uUm__c__r")); - billentryjson.put("f9w5_area",GcjJson.getNodeValue(stra, "JSON.field_kq1O4__c__r")); - - billentryjson.put("f9w5_siminfo",GcjJson.getNodeValue(stra, "JSON.sim_card_info__c")); - // billentryjson.put("f9w5_isurgent",GcjJson.getNodeValue(stra, "JSON.is_urgent__c")); - billentryjson.put("f9w5_isurgent","1"); - billentryjson.put("f9w5_reqdelvytime",sdf.format(GcjJson.getNodeValue(stra, "JSON.required_delivery_time__c"))); - billentryjson.put("f9w5_thirdpartyid",GcjJson.getNodeValue(stra, "JSON.third_party_id__c")); - billentryjson.put("f9w5_otherrequire",GcjJson.getNodeValue(stra, "JSON.other_requirements__c")); - billentryjson.put("entrycomment",GcjJson.getNodeValue(stra, "JSON.remark__c")); - billentryjson.put("material_number",GcjJson.getNodeValue(stra, "JSON.product_code_text__c")); - //billentryjson.put("material_number","10010020374"); - billentry.add(billentryjson); - - } - - datajson.put("billentry",billentry);//销售预测明细 - - dataarr.add(datajson); - params.put("data",dataarr); - log.info("--请求json---" + params.toJSONString()); - System.out.println("--请求json:---" +params.toJSONString()); - strJson = params.toJSONString(); - - }catch (Exception e) { - sendFlag = true; - stringBuffer.append("参数解析错误,请联系开发人员"); - e.printStackTrace(); - } - getSynDataSaveUP(stringBuffer,sendFlag,fxapi,dataId,nameData,strJson,getData); - - } - } - } - /** - * 写数据 - */ - public void getSynDataSaveUP(StringBuffer stringBuffer,Boolean sendFlag,FXHTTP fxapi,String dataId,String nameData,String obj,JSONObject str) { - String syn_type = "1";//同步类型 0新增 1修改 2删除 - String res_url = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/sm/f9w5_salespred/salespredSave"; - String res_param = obj; - String res = ""; - try { - String accessToken = "2096108315279888384_8elReBSzvx315JiLWiH82YKJGosF3G2kN688q05rHUritX9x3fWS3lmetalPeMe3HceZV7fK1GdSJsk1J46A3S0VkOxIUqf7wnS207"; - // String accessToken = new KDTokenController().getKDAccessToken(); - - - Map headers = new HashMap(); - headers.put("accessToken", accessToken);//放token - HttpClientResult rtn = HttpClientUtils.doPostJson(res_url, headers, obj); - String resStr = rtn.getContent(); - JSONObject resjs = JSONObject.parseObject(resStr); - res = resStr; - if (resjs != null && resjs.getBoolean("status")) { - JSONObject successdata = resjs.getJSONObject("data"); - JSONArray result = successdata.getJSONArray("result"); - JSONObject erpdata = (JSONObject) result.get(0); - - }else{ - sendFlag=true; - stringBuffer.append("销售预测更新接口调用失败:"+resjs.getString("message")); - Map paramMap = new HashMap(); - paramMap.put("sync_status__c", "option_sync_failure__c"); - paramMap.put("sync_info__c", stringBuffer); - //回写json - // fxapi.upSynZDYFieldParam("", "sales_prediction__c", dataId, paramMap); - } - } catch (Exception e) { - sendFlag = true; - stringBuffer.append("销售预测更新接口调用失败,请检查网络配置"); - Map paramMap = new HashMap(); - paramMap.put("sync_status__c", "option_sync_failure__c"); - paramMap.put("sync_info__c", stringBuffer); - //回写json - // fxapi.upSynZDYFieldParam("", "sales_prediction__c", dataId, paramMap); - } - - JSONObject sendData = new JSONObject(); - - sendData.put("send_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 - - sendData.put("send_id", str.getString("sendId")); //send_id - MagicApi.updateSendSYUPDATESP(sendData); - - JSONObject logData = new JSONObject(); - logData.put("log_type", "SPUP"); //业务类型 - logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步 - logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除 - logData.put("data_id", dataId);//数据id - logData.put("data_name", nameData);//数据名称 - logData.put("res_body", "同步成功");//返回值 - logData.put("res_url", res_url);// - logData.put("res_param", res_param);// - logData.put("res_res", res);// - if (sendFlag) { - logData.put("res_body", stringBuffer.toString());//返回值 - } - //写入传输日志 - MagicApi.saveSPLog(logData); - } diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/FXHTTP.java b/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/FXHTTP.java index 1268779..3553556 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/FXHTTP.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/FXHTTP.java @@ -460,7 +460,7 @@ public class FXHTTP { map.put("body.currentOpenUserId", FXTIC.CURRENTOPENUSERID); map.put("body.data.search_query_info.offset", 0); - map.put("body.data.search_query_info.limit", 999); + map.put("body.data.search_query_info.limit", 1999); map.put("body.data.search_query_info.orders[0].fieldName", "create_time"); map.put("body.data.search_query_info.orders[0].isAsc", "true"); for (int i = 0; i < CrmFXApiParam.size(); i++) { diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/MagicApi.java b/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/MagicApi.java index ea682d5..0b2c17c 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/MagicApi.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/zdyutils/MagicApi.java @@ -38,6 +38,16 @@ public class MagicApi { e.printStackTrace(); } } + public static void saveCostLog(JSONObject data) { + System.out.println(data); + try { + String res = HttpSend.sendMagicPost( + "http://127.0.0.1:18088/send/log/cost" + , data); + } catch (Exception e) { + e.printStackTrace(); + } + } public static void saveCustomerLog(JSONObject data) { System.out.println(data); try { diff --git a/magic-boot/target/classes/org/ssssssss/magicboot/zdyutils/FXTIC.class b/magic-boot/target/classes/org/ssssssss/magicboot/zdyutils/FXTIC.class index 536ac8a..528409d 100644 Binary files a/magic-boot/target/classes/org/ssssssss/magicboot/zdyutils/FXTIC.class and b/magic-boot/target/classes/org/ssssssss/magicboot/zdyutils/FXTIC.class differ