智洋张伟龙编写的代码

This commit is contained in:
itzhang 2025-06-11 13:58:36 +08:00
commit f696d77582
87 changed files with 14190 additions and 0 deletions

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "1500ff0ba1a64b3796ec9114e568869e",
"name" : "B-传输日志",
"type" : "api",
"parentId" : "0",
"path" : "/send",
"createTime" : 1684243742014,
"updateTime" : null,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "传输日志",
"type" : "api",
"parentId" : "1500ff0ba1a64b3796ec9114e568869e",
"path" : "/log",
"createTime" : 1684243742032,
"updateTime" : null,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "copy1724404999212d47014",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存人员同步日志",
"createTime" : null,
"updateTime" : 1743054112942,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/saveuser",
"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_user').primary('log_id',uuid()).save(data)

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "copy1745307476745d27404",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存客户",
"createTime" : null,
"updateTime" : 1745307494790,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savecustomer",
"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_customer').primary('log_id',uuid()).save(data)

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "d0c872104e524be0862e004fe29771c3",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存客户分类",
"createTime" : null,
"updateTime" : 1745307472124,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/save",
"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_customergroup').primary('log_id',uuid()).save(data)

View File

@ -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)

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "copy1747380095360d17588",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存报价询价同步日志",
"createTime" : 1747380116583,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savepriceapprova",
"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_priceapprova').primary('log_id',uuid()).save(data)

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "copy1745905421038d65912",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存销售预测同步日志",
"createTime" : null,
"updateTime" : 1745905450397,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savesales_prediction",
"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_sales_prediction').primary('log_id',uuid()).save(data)

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "copy1745808687043d87940",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存项目同步日志",
"createTime" : null,
"updateTime" : 1745808707906,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/saveproject",
"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_project').primary('log_id',uuid()).save(data)

View File

@ -0,0 +1,50 @@
{
"properties" : { },
"id" : "copy1747118188498d320",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "保存领料同步日志",
"createTime" : null,
"updateTime" : 1747118204682,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savematerialreqbill",
"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_materialreqbill').primary('log_id',uuid()).save(data)

View File

@ -0,0 +1,47 @@
{
"properties" : { },
"id" : "ed67a93b6ded41029fdb69f3f3420fb9",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "列表",
"createTime" : null,
"updateTime" : 1699275219305,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/list",
"method" : "POST",
"parameters" : [ ],
"options" : [ {
"name" : "permission",
"value" : "send:log:view",
"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
}
================================
return db.page("""
select log_id,log_type,log_status,syn_type,data_id,create_time,data_name,mark,res_body,send_flag,send_memo from send_log_info where 1=1
?{logType, and log_type = #{logType} }
?{logStatus, and log_status = #{logStatus} }
?{synType, and syn_type = #{synType} }
?{dataId, and data_id = #{dataId} }
?{dataName, and data_name = #{dataName} }
?{createTime && createTime.split(',')[0], and create_time >= #{createTime.split(',')[0]}}
?{createTime && createTime.split(',')[1], and create_time <= #{createTime.split(',')[1]}}
?{sendFlag, and send_flag = #{sendFlag} } order by create_time desc
""")

View File

@ -0,0 +1,37 @@
{
"properties" : { },
"id" : "f2d89c16aa424d74b9d6e944ea138998",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "删除",
"createTime" : 1696953066814,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/delete",
"method" : "DELETE",
"parameters" : [ ],
"options" : [ {
"name" : "permission",
"value" : "send:log:delete",
"description" : "允许拥有该权限的访问",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ],
"requestBody" : null,
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
return db.table('send_log_info').where().eq('log_id', log_id).delete()

View File

@ -0,0 +1,39 @@
{
"properties" : { },
"id" : "33b0df7daae64483b6c7067755ca7b68",
"script" : null,
"groupId" : "6ee06a9b9fe04b85b70a9364ef324ab4",
"name" : "详情",
"createTime" : 1696953066831,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/get",
"method" : "GET",
"parameters" : [ ],
"options" : [ {
"name" : "permission",
"value" : "send:log:view",
"description" : "允许拥有该权限的访问",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ],
"requestBody" : null,
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
return db.selectOne("""
select log_id,log_type,log_status,syn_type,data_id,create_time,data_name,res_body,send_flag,send_memo from send_log_info where log_id = #{log_id}
""")

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "B-同步日志",
"type" : "api",
"parentId" : "0",
"path" : "/syn",
"createTime" : 1701349598045,
"updateTime" : 1701349674007,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1701349941295d22163",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "人员待同步保存",
"createTime" : null,
"updateTime" : 1743047168232,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/saveuser",
"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_user").primary('send_id', () => uuid())
.save(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1701349998399d81042",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "修改人员同步",
"createTime" : null,
"updateTime" : 1743047188007,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/updateuser",
"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_user").primary('send_id')
.update(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1745307450958d20455",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "修改客户同步",
"createTime" : null,
"updateTime" : 1745307461569,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/updatecustomer",
"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_customer").primary('send_id')
.update(data)

View File

@ -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)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1747380151826d80978",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "修改报价同步",
"createTime" : 1747380163630,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/updatepriceapprova",
"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_priceapprova").primary('send_id')
.update(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1745905491097d61575",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "修改销售预测同步",
"createTime" : null,
"updateTime" : 1745912331249,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/updatesales_prediction",
"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_sales_prediction").primary('send_id')
.update(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1745808609390d29375",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "修改项目同步",
"createTime" : null,
"updateTime" : 1745808680843,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/updateProjcet",
"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_project").primary('send_id')
.update(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1747118253162d84764",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "修改领料同步",
"createTime" : null,
"updateTime" : 1747129492177,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/updatematerialreqbill",
"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_materialreqbill").primary('send_id')
.update(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1745307427497d38560",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "客户待同步保存",
"createTime" : null,
"updateTime" : 1745307448992,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savecustomer",
"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_customer").primary('send_id', () => uuid())
.save(data)

View File

@ -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)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1747380139022d12449",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "报价待同步保存",
"createTime" : 1747380149469,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savepriceapprova",
"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_priceapprova").primary('send_id', () => uuid())
.save(data)

View File

@ -0,0 +1,173 @@
{
"properties" : { },
"id" : "copy1743047080239d23438",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询人员同步",
"createTime" : null,
"updateTime" : 1743047414999,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/queryuser",
"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_user` where
send_type=#{sendType}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,135 @@
{
"properties" : { },
"id" : "95d66a27a4794b8c8126ad131743da56",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询客户分类同步",
"createTime" : null,
"updateTime" : 1744339012019,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/querygroup",
"method" : "GET",
"parameters" : [ {
"name" : "sendType",
"value" : "group",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "dataId",
"value" : "北京市",
"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\": 1744339010854,\n \"executeTime\": 91\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" : "1744339010854",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "91",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
}
================================
//查询本机mysql
return db.select(
"""
SELECT * FROM `send_log_customergroup` where
log_type=#{sendType}
<if test="dataId != null">
and data_id=#{dataId}
</if>
<if test="sendSyn != null">
and syn_type=#{sendSyn}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,173 @@
{
"properties" : { },
"id" : "copy1732497876949d77458",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询客户同步日志",
"createTime" : null,
"updateTime" : 1745307421060,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/queryCustomer",
"method" : "GET",
"parameters" : [ {
"name" : "sendType",
"value" : "TuiHuo",
"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_customer` where
send_type=#{sendType}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -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}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,173 @@
{
"properties" : { },
"id" : "copy1747380121763d51481",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询报价同步日志",
"createTime" : null,
"updateTime" : 1747380132413,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/querypriceapprova",
"method" : "GET",
"parameters" : [ {
"name" : "sendType",
"value" : "TuiHuo",
"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_priceapprova` where
send_type=#{sendType}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,173 @@
{
"properties" : { },
"id" : "copy1745905454396d11136",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询销售预测同步日志",
"createTime" : null,
"updateTime" : 1745905470230,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/querysales_prediction",
"method" : "GET",
"parameters" : [ {
"name" : "sendType",
"value" : "TuiHuo",
"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_sales_prediction` where
send_type=#{sendType}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,173 @@
{
"properties" : { },
"id" : "copy1745808556895d15952",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询项目同步日志",
"createTime" : null,
"updateTime" : 1745808575698,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/queryProject",
"method" : "GET",
"parameters" : [ {
"name" : "sendType",
"value" : "TuiHuo",
"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_project` where
send_type=#{sendType}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,173 @@
{
"properties" : { },
"id" : "copy1747118211168d30333",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "查询领料同步日志",
"createTime" : null,
"updateTime" : 1747118228927,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/querymaterialreqbill",
"method" : "GET",
"parameters" : [ {
"name" : "sendType",
"value" : "TuiHuo",
"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_materialreqbill` where
send_type=#{sendType}
<if test="dataId != null">
and dsf_id=#{dataId}
</if>
<if test="datapId != null">
and dsfzhu_id=#{datapId}
</if>
<if test="sendSyn != null">
and send_syn=#{sendSyn}
</if>
<if test="sendStatus != null">
and send_status=#{sendStatus}
</if>
<if test="crmId != null">
and crm_id=#{crmId}
</if>
<if test="dsfId != null">
and dsf_id=#{dsfId}
</if>
<if test="sendStatus3 != null">
and send_status!=#{sendStatus3}
</if>
order by create_time desc
""");

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1745905472523d55220",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "销售预测待同步保存",
"createTime" : null,
"updateTime" : 1745905488288,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savesales_prediction",
"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_sales_prediction").primary('send_id', () => uuid())
.save(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1745808582300d24910",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "项目待同步保存",
"createTime" : 1745808599992,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/saveProject",
"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_project").primary('send_id', () => uuid())
.save(data)

View File

@ -0,0 +1,126 @@
{
"properties" : { },
"id" : "copy1747118238121d79879",
"script" : null,
"groupId" : "4506c21162d24d4c81bad5bc8707672a",
"name" : "领料待同步保存",
"createTime" : null,
"updateTime" : 1747118249721,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/savematerialreqbill",
"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_materialreqbill").primary('send_id', () => uuid())
.save(data)

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "55b38df92caf40b99b60fcc88e5ce361",
"name" : "日志",
"type" : "api",
"parentId" : "0",
"path" : "Log",
"createTime" : 1742981192694,
"updateTime" : null,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,46 @@
{
"properties" : { },
"id" : "0ed26502b95049db8e00316c785c24c3",
"script" : null,
"groupId" : "55b38df92caf40b99b60fcc88e5ce361",
"name" : "新增日志",
"createTime" : null,
"updateTime" : 1749432031009,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/insert/log_data",
"method" : "POST",
"parameters" : [ ],
"options" : [ ],
"requestBody" : "",
"headers" : [ ],
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"responseBodyDefinition" : null
}
================================
return db.Log.insert("""
insert into ${body.tableName} (
log_id,
log_type,
log_status,
syn_type,
data_id,
data_name,
mark,
res_body,
mark_id,
send_url,
send_body,
send_res,
send_flag,
send_memo)
values
(#{body.log_id},#{body.log_type},#{body.log_status},#{body.syn_type},#{body.data_id},#{body.data_name},#{body.mark},#{body.res_body},#{body.mark_id},
#{body.send_url},#{body.send_body},#{body.send_res},#{body.send_flag},#{body.send_memo})
""")

View File

@ -0,0 +1,330 @@
{
"properties" : { },
"id" : "89c69bcd049d47228b3298cf0e318756",
"script" : null,
"groupId" : "55b38df92caf40b99b60fcc88e5ce361",
"name" : "查询日志",
"createTime" : null,
"updateTime" : 1749615961240,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/query/log_data",
"method" : "GET",
"parameters" : [ {
"name" : "table",
"value" : "send_log_htxx",
"description" : null,
"required" : true,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "dataId",
"value" : "68402bae3bf7c10001a2df32",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "mark",
"value" : "1749084392443",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "log_type",
"value" : "XSHT",
"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 \"logId\": \"08380a4057b3489b8e7952503c73e33e\",\n \"logType\": \"XSHT\",\n \"logStatus\": \"0\",\n \"synType\": \"0\",\n \"dataId\": \"68402bae3bf7c10001a2df32\",\n \"dataName\": \"ZHY2506040011\",\n \"mark\": \"1749084392443\",\n \"resBody\": \"同步成功\",\n \"markId\": null,\n \"sendUrl\": null,\n \"sendBody\": \"{\\\"body\\\":{\\\"data\\\":[{\\\"billname\\\":\\\"2025041509582039142220250604测试\\\",\\\"customer_number\\\":\\\"K01430013\\\",\\\"installationmethod\\\":\\\"opt1\\\",\\\"city\\\":\\\"湖南省\\\",\\\"payingcustomer_number\\\":\\\"K01430013\\\",\\\"county\\\":\\\"2251\\\",\\\"type_number\\\":\\\"XSHT-QD01\\\",\\\"reccustomer_number\\\":\\\"K01430013\\\",\\\"zhybilltype\\\":\\\"opt1\\\",\\\"totalallamount\\\":0,\\\"projectsource\\\":\\\"opt3\\\",\\\"party1st\\\":\\\"湖南星航电力科技有限公司\\\",\\\"operator\\\":\\\"ZHY11191\\\",\\\"industrytype_number\\\":\\\"opt1\\\",\\\"bizmode\\\":\\\"C\\\",\\\"crmid\\\":\\\"68402bae3bf7c10001a2df32\\\",\\\"billtype_number\\\":\\\"conm_salcontract_BT_QD\\\",\\\"province\\\":\\\"湖南省\\\",\\\"currency_number\\\":\\\"CNY\\\",\\\"salesmethod\\\":\\\"opt2\\\",\\\"biztimeend\\\":1744646400000,\\\"station\\\":\\\"opt2\\\",\\\"warranty\\\":24,\\\"biztime\\\":1744646400000,\\\"customerpropert\\\":\\\"opt2\\\",\\\"party2nd\\\":\\\"智洋创新科技股份有限公司\\\",\\\"deviceqty\\\":0,\\\"delivery\\\":false,\\\"biztimebegin\\\":1744646400000,\\\"isbidding\\\":false,\\\"dept\\\":\\\"004\\\",\\\"createorg_number\\\":\\\"ZHY\\\",\\\"contparties_number\\\":\\\"ZHY\\\",\\\"productline_number\\\":\\\"opt1\\\",\\\"project_number\\\":\\\"SJ20250604-0480\\\",\\\"billentry\\\":[{\\\"unit1_number\\\":\\\"pcs\\\",\\\"f9w5_unit1_number\\\":\\\"pcs\\\",\\\"baseunit\\\":\\\"套\\\",\\\"taxrateid_number\\\":\\\"V13\\\",\\\"linetype_number\\\":\\\"020\\\",\\\"specification\\\":\\\"无\\\",\\\"baseqty\\\":2,\\\"goodsname\\\":\\\"线路在线监测装置, 视频在线监测装置\\\",\\\"crmentryid\\\":\\\"68402bae3bf7c10001a2df33\\\",\\\"unit_number\\\":\\\"pcs\\\",\\\"material_number\\\":\\\"TEST0001\\\",\\\"qty\\\":2,\\\"curamountandtax\\\":53000.00,\\\"priceandtax\\\":26500.00}],\\\"org_number\\\":\\\"ZHY\\\",\\\"settlecurrency_number\\\":\\\"CNY\\\",\\\"settlecustomer_number\\\":\\\"K01430013\\\",\\\"billno\\\":\\\"ZHY2506040011\\\"}]},\\\"headers\\\":{\\\"Content-Type\\\":[\\\"application/json\\\"],\\\"accessToken\\\":[\\\"2095345516136108032_1IUXws7URzEN2w5yui9HYbtRNXcmFDGZ42aUIqhyVV8dMfy7GV2EiEwAJq4JzGWhDKPzAVPgQwC5phRjGh6sid53qc88G6e9NmQS00\\\"],\\\"Idempotency-Key\\\":[\\\"96a5582c51984b479fad836c84f38d10\\\"]}}\",\n \"sendRes\": \"{\\\"data\\\":{\\\"failCount\\\":\\\"0\\\",\\\"result\\\":[{\\\"billIndex\\\":0,\\\"billStatus\\\":true,\\\"errors\\\":[],\\\"id\\\":\\\"2230400248864334848\\\",\\\"keys\\\":{\\\"f9w5_crmid\\\":\\\"68402bae3bf7c10001a2df32\\\"},\\\"number\\\":\\\"ZHY2506040011\\\",\\\"type\\\":\\\"Add\\\"}],\\\"successCount\\\":\\\"1\\\"},\\\"errorCode\\\":\\\"0\\\",\\\"status\\\":true}\",\n \"sendFlag\": null,\n \"sendMemo\": null\n }],\n \"timestamp\": 1749615949677,\n \"executeTime\": 67\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" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ {
"name" : "logId",
"value" : "08380a4057b3489b8e7952503c73e33e",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "logType",
"value" : "XSHT",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "logStatus",
"value" : "0",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "synType",
"value" : "0",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "dataId",
"value" : "68402bae3bf7c10001a2df32",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "dataName",
"value" : "ZHY2506040011",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "mark",
"value" : "1749084392443",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "resBody",
"value" : "同步成功",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "markId",
"value" : "null",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "sendUrl",
"value" : "null",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "sendBody",
"value" : "{\\\"body\\\":{\\\"data\\\":[{\\\"billname\\\":\\\"2025041509582039142220250604测试\\\",\\\"customer_number\\\":\\\"K01430013\\\",\\\"installationmethod\\\":\\\"opt1\\\",\\\"city\\\":\\\"湖南省\\\",\\\"payingcustomer_number\\\":\\\"K01430013\\\",\\\"county\\\":\\\"2251\\\",\\\"type_number\\\":\\\"XSHT-QD01\\\",\\\"reccustomer_number\\\":\\\"K01430013\\\",\\\"zhybilltype\\\":\\\"opt1\\\",\\\"totalallamount\\\":0,\\\"projectsource\\\":\\\"opt3\\\",\\\"party1st\\\":\\\"湖南星航电力科技有限公司\\\",\\\"operator\\\":\\\"ZHY11191\\\",\\\"industrytype_number\\\":\\\"opt1\\\",\\\"bizmode\\\":\\\"C\\\",\\\"crmid\\\":\\\"68402bae3bf7c10001a2df32\\\",\\\"billtype_number\\\":\\\"conm_salcontract_BT_QD\\\",\\\"province\\\":\\\"湖南省\\\",\\\"currency_number\\\":\\\"CNY\\\",\\\"salesmethod\\\":\\\"opt2\\\",\\\"biztimeend\\\":1744646400000,\\\"station\\\":\\\"opt2\\\",\\\"warranty\\\":24,\\\"biztime\\\":1744646400000,\\\"customerpropert\\\":\\\"opt2\\\",\\\"party2nd\\\":\\\"智洋创新科技股份有限公司\\\",\\\"deviceqty\\\":0,\\\"delivery\\\":false,\\\"biztimebegin\\\":1744646400000,\\\"isbidding\\\":false,\\\"dept\\\":\\\"004\\\",\\\"createorg_number\\\":\\\"ZHY\\\",\\\"contparties_number\\\":\\\"ZHY\\\",\\\"productline_number\\\":\\\"opt1\\\",\\\"project_number\\\":\\\"SJ20250604-0480\\\",\\\"billentry\\\":[{\\\"unit1_number\\\":\\\"pcs\\\",\\\"f9w5_unit1_number\\\":\\\"pcs\\\",\\\"baseunit\\\":\\\"套\\\",\\\"taxrateid_number\\\":\\\"V13\\\",\\\"linetype_number\\\":\\\"020\\\",\\\"specification\\\":\\\"无\\\",\\\"baseqty\\\":2,\\\"goodsname\\\":\\\"线路在线监测装置, 视频在线监测装置\\\",\\\"crmentryid\\\":\\\"68402bae3bf7c10001a2df33\\\",\\\"unit_number\\\":\\\"pcs\\\",\\\"material_number\\\":\\\"TEST0001\\\",\\\"qty\\\":2,\\\"curamountandtax\\\":53000.00,\\\"priceandtax\\\":26500.00}],\\\"org_number\\\":\\\"ZHY\\\",\\\"settlecurrency_number\\\":\\\"CNY\\\",\\\"settlecustomer_number\\\":\\\"K01430013\\\",\\\"billno\\\":\\\"ZHY2506040011\\\"}]},\\\"headers\\\":{\\\"Content-Type\\\":[\\\"application/json\\\"],\\\"accessToken\\\":[\\\"2095345516136108032_1IUXws7URzEN2w5yui9HYbtRNXcmFDGZ42aUIqhyVV8dMfy7GV2EiEwAJq4JzGWhDKPzAVPgQwC5phRjGh6sid53qc88G6e9NmQS00\\\"],\\\"Idempotency-Key\\\":[\\\"96a5582c51984b479fad836c84f38d10\\\"]}}",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "sendRes",
"value" : "{\\\"data\\\":{\\\"failCount\\\":\\\"0\\\",\\\"result\\\":[{\\\"billIndex\\\":0,\\\"billStatus\\\":true,\\\"errors\\\":[],\\\"id\\\":\\\"2230400248864334848\\\",\\\"keys\\\":{\\\"f9w5_crmid\\\":\\\"68402bae3bf7c10001a2df32\\\"},\\\"number\\\":\\\"ZHY2506040011\\\",\\\"type\\\":\\\"Add\\\"}],\\\"successCount\\\":\\\"1\\\"},\\\"errorCode\\\":\\\"0\\\",\\\"status\\\":true}",
"description" : "",
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "sendFlag",
"value" : "null",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "sendMemo",
"value" : "null",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
} ]
}, {
"name" : "timestamp",
"value" : "1749615949677",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "67",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
}
================================
return db.Log.select("""
select log_id,log_type,log_status,syn_type,data_id,data_name,mark,res_body,mark_id,send_url,send_body,send_res,send_flag,send_memo from ${table}
where log_type = #{log_type} and data_id = #{dataId} and mark = #{mark}
""")

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "710c9f13f48248a382e695af54270dd6",
"name" : "传输日志",
"type" : "component",
"parentId" : "0",
"path" : "/send",
"createTime" : 1684243742087,
"updateTime" : null,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "24eb9e08fa46447db43eba7618df7cc7",
"name" : "传输日志",
"type" : "component",
"parentId" : "710c9f13f48248a382e695af54270dd6",
"path" : "/log",
"createTime" : 1684243742092,
"updateTime" : null,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,238 @@
{
"properties" : { },
"id" : "49575ce482694a50ab641e9835c64865",
"script" : null,
"groupId" : "24eb9e08fa46447db43eba7618df7cc7",
"name" : "列表",
"createTime" : 1684253377806,
"updateTime" : 1684253426051,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/list",
"description" : null
}
================================
<template>
<mb-list ref="magicList" v-bind="listOptions" />
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
<template #content>
<mb-form ref="magicForm" @reload="magicList.reload" v-bind="formOptions" />
</template>
</mb-dialog>
</template>
<script setup>
import { ref, reactive, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance()
const formDialog = ref()
const magicList = ref()
const magicForm = ref()
const magicFormTitle = ref()
const listOptions = reactive({
tools: [{
type: 'add',
permission: 'send:log:save',
click: () => {
magicFormTitle.value = '添加'
formDialog.value.show(() => magicForm.value.initFormData())
}
}],
table: {
url: '/send/log/list',
where: {
logType: {
label: '业务类型',
component: 'select',
props: {
type: '业务类型'
}
},
logStatus: {
label: '同步状态',
component: 'select',
props: {
type: '同步状态'
}
},
synType: {
label: '同步类型',
component: 'select',
props: {
type: '同步类型'
}
},
dataId: {
label: '数据id',
component: 'input'
},
dataName: {
label: '数据名称',
component: 'input'
},
createTime: {
component: 'date',
label: '创建时间',
props: {
type: 'daterange'
}
},
sendFlag: {
label: '重新发送',
component: 'select',
props: {
type: '重新发送'
}
}
},
cols: [
{
field: 'logId',
label: '主键'
},
{
field: 'logType',
label: '业务类型',
dictType: '业务类型'
},
{
field: 'logStatus',
label: '同步状态',
dictType: '同步状态'
},
{
field: 'synType',
label: '同步类型',
dictType: '同步类型'
},
{
field: 'dataId',
label: '数据id'
},
{
field: 'createTime',
label: '创建时间'
},
{
field: 'dataName',
label: '数据名称'
},
{
field: 'resBody',
label: '返回值'
},
{
field: 'sendFlag',
label: '重新发送',
dictType: '重新发送'
},
{
field: 'sendMemo',
label: '备注'
},{
label: '操作',
type: 'btns',
width: 140,
fixed: 'right',
btns: [
{
permission: 'send:log:delete',
label: '重新发起同步',
type: 'primary',
link: true,
icon: 'ElIconDelete',
click: (row) => {
proxy.$alert(`确定重新发起“${row.dataName}”数据同步么?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: (action) => {
if (action === 'confirm') {
proxy.$post('/send/log/save',{ log_id: row.logId,send_flag: "1"}).then(() => {
magicList.value.reload()
})
}
}
})
}
}
]
}
]
}
})
const formOptions = reactive({
detail: {
request: {
url: '/send/log/get'
}
},
form: {
request: {
url: "/send/log/save"
},
rows: [{
gutter: 24,
cols: [{
span: 12,
name: 'logType',
label: '业务类型',
component: 'select',
props: {
type: '业务类型'
}
},{
span: 12,
name: 'logStatus',
label: '同步状态',
component: 'select',
props: {
type: '同步状态'
}
},{
span: 12,
name: 'synType',
label: '同步类型',
component: 'select',
props: {
type: '同步类型'
}
},{
span: 12,
name: 'dataId',
label: '数据id',
component: 'input'
},{
span: 12,
name: 'createTime',
label: '创建时间',
component: 'input'
},{
span: 12,
name: 'dataName',
label: '数据名称',
component: 'input'
},{
span: 12,
name: 'resBody',
label: '返回值',
component: 'input'
},{
span: 12,
name: 'sendFlag',
label: '重新发送',
component: 'select',
props: {
type: '重新发送'
}
},{
span: 12,
name: 'sendMemo',
label: '备注',
component: 'input'
}]
}]
}
})
</script>

View File

@ -0,0 +1,10 @@
{
"properties" : { },
"id" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"name" : "数据管理",
"type" : "component",
"parentId" : "0",
"path" : "/data",
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,10 @@
{
"properties" : { },
"id" : "eb5dbed949de4f50ba4bf59f483252a5",
"name" : "测试生成",
"type" : "component",
"parentId" : "55ff62aa20144b7bb5c6dfb5d76c8139",
"path" : "/test",
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,166 @@
{
"properties" : { },
"id" : "5770db2417964e91a87544a3d3ceb807",
"script" : null,
"groupId" : "eb5dbed949de4f50ba4bf59f483252a5",
"name" : "列表",
"createTime" : 1702995342933,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/list",
"description" : null
}
================================
<template>
<mb-list ref="magicList" v-bind="listOptions" />
<mb-dialog ref="formDialog" :title="magicFormTitle" @confirm-click="magicForm.save($event)" width="50%">
<template #content>
<mb-form ref="magicForm" @reload="magicList.reload" v-bind="formOptions" />
</template>
</mb-dialog>
</template>
<script setup>
import { ref, reactive, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance()
const formDialog = ref()
const magicList = ref()
const magicForm = ref()
const magicFormTitle = ref()
const listOptions = reactive({
tools: [{
type: 'add',
permission: 'data:test:save',
click: () => {
magicFormTitle.value = '添加'
formDialog.value.show(() => magicForm.value.initFormData())
}
}],
table: {
url: '/data/test/list',
where: {
name: {
label: '名字',
component: 'input'
},
sex: {
label: '性别',
component: 'select',
props: {
type: 'sex'
}
},
headPortrait: {
label: '头像',
component: 'upload-image'
},
remarks: {
label: '备注',
component: 'input',
props: {
type: 'textarea'
}
}
},
cols: [
{
field: 'name',
label: '名字'
},
{
field: 'sex',
label: '性别',
dictType: 'sex'
},
{
field: 'headPortrait',
label: '头像',
type: 'image'
},
{
field: 'remarks',
label: '备注'
},{
label: '操作',
type: 'btns',
width: 140,
fixed: 'right',
btns: [
{
permission: 'data:test:save',
label: '修改',
type: 'primary',
link: true,
icon: 'ElIconEdit',
click: (row) => {
magicFormTitle.value = '修改'
formDialog.value.show(() => magicForm.value.getDetail(row.id))
}
}, {
permission: 'data:test:delete',
label: '删除',
type: 'primary',
link: true,
icon: 'ElIconDelete',
click: (row) => {
proxy.$common.handleDelete({
url: '/data/test/delete',
id: row.id,
done: () => magicList.value.reload()
})
}
}
]
}
]
}
})
const formOptions = reactive({
detail: {
request: {
url: '/data/test/get'
}
},
form: {
request: {
url: "/data/test/save"
},
rows: [{
gutter: 24,
cols: [{
span: 12,
name: 'name',
label: '名字',
component: 'input',
rules: [{ required: true, message: '请输入名字', trigger: 'change' }]
},{
span: 12,
name: 'sex',
label: '性别',
component: 'select',
props: {
type: 'sex'
}
},{
span: 12,
name: 'headPortrait',
label: '头像',
component: 'upload-image',
rules: [{ required: true, message: '请选择头像', trigger: 'change' }]
},{
span: 12,
name: 'remarks',
label: '备注',
component: 'input',
props: {
type: 'textarea'
}
}]
}]
}
})
</script>

View File

@ -0,0 +1,19 @@
{
"properties" : { },
"id" : "3e3ba03a77b943eb85e4c528916e3586",
"script" : null,
"groupId" : "datasource:0",
"name" : "日志",
"createTime" : 1742981169023,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"url" : "jdbc:mysql://116.204.34.35:13300/zycx",
"username" : "root",
"password" : "root",
"key" : "Log",
"maxRows" : -1,
"driverClassName" : "com.mysql.cj.jdbc.Driver",
"type" : "com.alibaba.druid.pool.DruidDataSource"
}

View File

@ -0,0 +1,10 @@
{
"properties" : { },
"id" : "41922e26ef57421f8819fe6c59f14d63",
"name" : "权限",
"type" : "function",
"parentId" : "0",
"path" : "/permission",
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,54 @@
{
"properties" : { },
"id" : "a5f80b11b7fb4f3c97252331c80bcf85",
"script" : null,
"groupId" : "41922e26ef57421f8819fe6c59f14d63",
"name" : "组织机构",
"createTime" : 1646490239535,
"updateTime" : 1642327198030,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
"path" : "/office",
"description" : null,
"returnType" : null,
"mappingPath" : "/permission/office",
"parameters" : [ ]
}
================================
import 'cn.dev33.satoken.stp.StpUtil';
var currentUserId = StpUtil.getLoginId()
//查出当前用户有多少角色
var roles = db.select("""
select permission from sys_role where is_del = 0 and id in (select role_id from sys_user_role where user_id = #{currentUserId})
""")
var userIds = []
for(role in roles){
if(role.permission == '0'){
return []
}else if(role.permission == '1'){
userIds.addAll(db.select("""
select id from sys_user where is_del = 0 and office_id in (
select office_id from sys_role_office where role_id in (
select role_id from sys_user_role where user_id = #{currentUserId}
)
)
""").map(it => it.id))
}else{
var officeId = db.selectValue("select office_id from sys_user where id = #{currentUserId}")
var offices = []
offices.push(officeId)
var getOfficeId = (list,pid) => {
var ids = select t.id from list t where t.pid = pid;
for(it in ids){
offices.push(it.id)
getOfficeId(list,it.id)
}
}
getOfficeId(db.select('select id, pid from sys_office where is_del = 0 order by sort'),officeId)
userIds.addAll(db.select("select id from sys_user where office_id in (#{offices})").map(it => it.id))
}
}
return userIds

View File

@ -0,0 +1,14 @@
{
"properties" : { },
"id" : "7e31035eb8d4471b9fc2923ea1d966c3",
"name" : "配置中心",
"type" : "function",
"parentId" : "0",
"path" : "configure",
"createTime" : 1653109451626,
"updateTime" : null,
"createBy" : null,
"updateBy" : null,
"paths" : [ ],
"options" : [ ]
}

View File

@ -0,0 +1,48 @@
{
"properties" : { },
"id" : "copy1653111178446d65648",
"script" : null,
"groupId" : "7e31035eb8d4471b9fc2923ea1d966c3",
"name" : "根据keyAndcondition获取数据值",
"createTime" : null,
"updateTime" : 1653118303409,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/getBykeyCondition",
"description" : null,
"returnType" : null,
"mappingPath" : null,
"parameters" : [ {
"name" : "configureKey",
"value" : null,
"description" : null,
"required" : false,
"dataType" : "String",
"type" : "java.lang.String",
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "configureCondition",
"value" : null,
"description" : null,
"required" : false,
"dataType" : "String",
"type" : "java.lang.String",
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ]
}
================================
var configure = db.cache(`configure:${configureKey}${configureCondition}`).selectOne("""
select configure_value from sys_configure where configure_key = #{configureKey}
?{configureCondition, and configure_condition = #{configureCondition}}
""")
return configure == null ? "" : configure.get("configureValue")

View File

@ -0,0 +1,48 @@
{
"properties" : { },
"id" : "copy1653112036134d44643",
"script" : null,
"groupId" : "7e31035eb8d4471b9fc2923ea1d966c3",
"name" : "根据keyLikeCondition获取数据值",
"createTime" : null,
"updateTime" : 1653118334978,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/getLikeCondition",
"description" : null,
"returnType" : null,
"mappingPath" : null,
"parameters" : [ {
"name" : "configureKey",
"value" : null,
"description" : null,
"required" : false,
"dataType" : "String",
"type" : "java.lang.String",
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "configureCondition",
"value" : null,
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ]
}
================================
var configure = db.cache(`configure:${configureKey}${configureCondition}`).selectOne("""
select configure_value from sys_configure where configure_key = #{configureKey}
?{configureCondition, and configure_condition like concat('%',#{configureCondition},'%')}
""")
return configure == null ? "" : configure.get("configureValue")

View File

@ -0,0 +1,34 @@
{
"properties" : { },
"id" : "3a21cd5fcd9b4e96b870a2268088266d",
"script" : null,
"groupId" : "7e31035eb8d4471b9fc2923ea1d966c3",
"name" : "根据key获取数据值",
"createTime" : null,
"updateTime" : 1653119091752,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/getBykey",
"description" : null,
"returnType" : null,
"mappingPath" : null,
"parameters" : [ {
"name" : "configureKey",
"value" : null,
"description" : null,
"required" : false,
"dataType" : "String",
"type" : "java.lang.String",
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ]
}
================================
var configure = db.cache(`configure:${configureKey}`).selectOne("""
select configure_value from sys_configure where configure_key = #{configureKey}
""")
return configure == null ? "" : configure.get("configureValue")

114
pom.xml Normal file
View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>zhyManagement</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zhyManagement</name>
<description>zhyManagement</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.6.13</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.22</version>
</dependency>
<!--咖啡因缓存-->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.4</version> <!-- 或与您的 Jackson 版本一致 -->
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.management.ZhyManagementApplication</mainClass>
<!-- <skip>true</skip>-->
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>zhyManagement</finalName>
</build>
</project>

View File

@ -0,0 +1,16 @@
package com.management;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@Slf4j
public class ZhyManagementApplication {
public static void main(String[] args) {
SpringApplication.run(ZhyManagementApplication.class, args);
log.info("程序启动成功");
}
}

View File

@ -0,0 +1,19 @@
package com.management.config;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Configuration
public class MagicBootConfiguration {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
LocalDateTimeSerializer localDateTimeSerializer = new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeSerializer);
}
}

View File

@ -0,0 +1,22 @@
package com.management.constant;
/**
* 创宇CRM的证书常量
*
* @param
* @return null
* @Author weiloong_zhang
*/
public class CertificateConstant {
public static final String APP_ID = "FSAID_131f56a";//appId
public static final String PERMANENT_CODE = "1A49B50861909007935CAB5E33E52BAA";//永久授权码
public static final String APP_SECRET = "5bda722932a54e80a05d2cc9b1722fed";//appSecret
public static final String CORP_ID = "FSCID_11F505C980B5FE43D5D7230567802E09";//企业Id
public static final String CURRENT_OPEN_USERID = "FSUID_A9AD0C360309427B3F431487883B73B9";//当前登录用户id
// public static final String APP_ID = "FSAID_131fa51";//appId
// public static final String PERMANENT_CODE = "EF03533F6929B59934A7E1155221420B";//永久授权码
// public static final String APP_SECRET = "1ce9804037ff4baf9d308bd32a4ec6ef";//appSecret
// public static final String CORP_ID = "FSCID_EC935623350FB07DBF52F84F49874A81";//企业Id
// public static final String CURRENT_OPEN_USERID = "FSUID_7B52D1CF1B01E5A2A143E250A5B60595";//当前登录用户id
}

View File

@ -0,0 +1,6 @@
package com.management.constant;
public class ERPURLConstant {
public static final String ERP_URL = "http://192.168.31.233:8022";//erp地址
public static final String ACCOUNT_ID = "2095345516136108032";//erp地址
}

View File

@ -0,0 +1,22 @@
package com.management.constant;
/**
* 接口地址URL常量
*
* @param
* @return null
* @Author weiloong_zhang
*/
public class URLConstant {
public static final String GET_CORPACCESSTOKEN_URL = "https://open.fxiaoke.com/cgi/corpAccessToken/get/V2";//获取token的接口地址
public static final String GET_CRM_LIST_URL = "https://open.fxiaoke.com/cgi/crm/v2/data/query";//获取客户列表的接口地址
public static final String GET_CUSTOMIZE_LIST_URL = "https://open.fxiaoke.com/cgi/crm/custom/v2/data/query";//获取自定义对象列表的接口地址
public static final String UPDATE_CRM_MAIN = "https://open.fxiaoke.com/cgi/crm/v2/data/update";
public static final String CREATE_CRM_MAIN = "https://open.fxiaoke.com/cgi/crm/v2/data/create";
public static final String CREATE_CRM_CUSTOMER_MAIN = "https://open.fxiaoke.com/cgi/crm/custom/v2/data/create";
public static final String UNLOCK_CRM_URL = "https://open.fxiaoke.com/cgi/crm/v2/object/unlock";
public static final String LOCK_CRM_URL = "https://open.fxiaoke.com/cgi/crm/v2/object/lock";
public static final String UPDATE_CRM_CUSTOMIZE = "https://open.fxiaoke.com/cgi/crm/custom/v2/data/update";
public static final String UPLOAD_FILE_URL = "https://open.fxiaoke.com/media/upload";
public static final String UPLOAD_ANNEX_URL = "https://open.fxiaoke.com/cgi/crm/custom/v2/data/update";
}

View File

@ -0,0 +1,439 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
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.http.MediaType;
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.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/api/bank")
@Slf4j
public class BankInfoController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new BankInfoController().updateBankInfo();
}
/**
* 银行信息同步接口
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/bankInfo")
public void syncBankInfo() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步银行信息");
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(1);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
String nowStr = now.format(formatter);
//开始查询部门(暂时使用固定值)
Map data = new HashMap<>();
data.put("startTime", twoDaysAgoStr);
data.put("endTime", nowStr);
//data.put("number", Arrays.asList("ZHY002.005.003.004"));
// data.put("level", "3");
Map deptReq = new HashMap<>();
deptReq.put("data", data);
deptReq.put("pageNo", 1);
deptReq.put("pageSize", 1999);
//开始获取金蝶token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
//开始发起请求
String bankInfoUrl = ERPURLConstant.ERP_URL +"/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
String bankInfoResStr = "";
//开始发起请求
try {
bankInfoResStr = restTemplate.postForObject(bankInfoUrl, bankReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
JSONObject bankInfoRes = JSONObject.parseObject(bankInfoResStr);
System.out.println("获取到金蝶银行信息");
if (!"0".equals(bankInfoRes.getString("errorCode")) || bankInfoRes.getJSONObject("data").isEmpty() || bankInfoRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("金蝶查询银行信息失败或者没有符合条件的数据");
return;
}
log.info("数据存在,将继续向下执行");
for (Object bankInfoObj : bankInfoRes.getJSONObject("data").getJSONArray("rows")) {
JSONObject bankInfoData = JSON.parseObject(JSON.toJSONString(bankInfoObj));
//开始截取关键数据
//银行名称
String bankName = bankInfoData.getString("name");
//行号
String bankNumber = bankInfoData.getString("number");
//todo 创建时间
String createTime = "2025-05-14 00:00:00";
//开始查询是否已经集成过了
JSONObject isLog = new JSONObject();
try {
isLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_bank&log_type=BANK&dataId=" + bankNumber + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLog.getJSONArray("data").isEmpty()) {
log.info("当前银行已经集成过了,将不再向下执行");
continue;
}
//开始封装数据
Map bankInfoMap = new HashMap<>();
bankInfoMap.put("name", bankNumber);//行号
bankInfoMap.put("bank_name__c", bankName);//银行名称
bankInfoMap.put("province__c", bankInfoData.getString("province_name") != null ? bankInfoData.getString("province_name") : "");//省份
bankInfoMap.put("city_banking__c", bankInfoData.getString("city_name") != null ? bankInfoData.getString("city_name") : "");//
bankInfoMap.put("country_region__c", bankInfoData.getString("country_fullname") != null ? bankInfoData.getString("country_fullname") : "");//国家地区
bankInfoMap.put("branch_number__c", bankInfoData.getString("union_number") != null ? bankInfoData.getString("union_number") : "");//联行号
bankInfoMap.put("dataObjectApiName", "bank_info__c");
//发起请求前查询是否已存在该数据
JSONObject isCrmExist = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList(bankNumber)),
new Filter("EQ", "bank_name__c", Arrays.asList(bankName))
), "bank_info__c");
JSONObject isCrmExistRes = new JSONObject();
try {
isCrmExistRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, isCrmExist, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(isCrmExistRes.getString("errorDescription")) && !isCrmExistRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("数据已存在,将执行更新");
JSONObject isCrmExistData = isCrmExistRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
bankInfoMap.put("_id", isCrmExistData.getString("_id"));
//更新请求
JSONObject updateReq = crmRequestUtil.updateCRM(bankInfoMap);
JSONObject updateRes = new JSONObject();
try {
updateRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, updateReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("更新结果为:" + JSON.parseObject(JSON.toJSONString(updateRes)));
//记录日志
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "BANKUP");
logMap.put("syn_type", "0");
logMap.put("data_name", bankName);
logMap.put("data_id", bankNumber);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(updateReq));
logMap.put("send_res", JSON.toJSONString(updateRes));
logMap.put("tableName", "send_log_bank");
//判断
if ("success".equals(updateRes.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + updateRes.getString("errorMessage"));
}
JSONObject logRes = new JSONObject();
try {
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
continue;
}
log.info("数据不存在,将执行创建");
JSONObject createReq = crmRequestUtil.createCRM(bankInfoMap);
JSONObject createRes = new JSONObject();
try {
createRes = restTemplate.postForObject(URLConstant.CREATE_CRM_CUSTOMER_MAIN, createReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("创建结果为:" + JSON.parseObject(JSON.toJSONString(createRes)));
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "BANK");
logMap.put("syn_type", "0");
logMap.put("data_name", bankName);
logMap.put("data_id", bankNumber);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(createReq));
logMap.put("send_res", JSON.toJSONString(createRes));
logMap.put("tableName", "send_log_bank");
//判断
if ("success".equals(createRes.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + createRes.getString("errorMessage"));
}
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/bankInfo")
public void updateBankInfo() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步银行信息");
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(2);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
String nowStr = now.format(formatter);
//开始查询部门(暂时使用固定值)
Map data = new HashMap<>();
data.put("startTime", twoDaysAgoStr);
data.put("endTime", nowStr);
//data.put("number", Arrays.asList("ZHY002.005.003.004"));
// data.put("level", "3");
Map deptReq = new HashMap<>();
deptReq.put("data", data);
deptReq.put("pageNo", 1);
deptReq.put("pageSize", 1999);
//开始获取金蝶token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity bankReqEntity = new HttpEntity(deptReq, headers);
//开始发起请求
String bankInfoUrl = ERPURLConstant.ERP_URL+"/ierp/kapi/v2/f9w5/basedata/bd_bebank/bebankQuery";
String bankInfoResStr = "";
//开始发起请求
try {
bankInfoResStr = restTemplate.postForObject(bankInfoUrl, bankReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
JSONObject bankInfoRes = JSONObject.parseObject(bankInfoResStr);
System.out.println("金蝶银行信息结果为:" + bankInfoRes);
if (!"0".equals(bankInfoRes.getString("errorCode")) || bankInfoRes.getJSONObject("data").isEmpty() || bankInfoRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("金蝶查询银行信息失败或者没有符合条件的数据");
return;
}
log.info("数据存在,将继续向下执行");
for (Object bankInfoObj : bankInfoRes.getJSONObject("data").getJSONArray("rows")) {
JSONObject bankInfoData = JSON.parseObject(JSON.toJSONString(bankInfoObj));
System.out.println("当前正在处理的银行信息数据为:" + bankInfoData);
//开始截取关键数据
//银行名称
String bankName = bankInfoData.getString("name");
//行号
String bankNumber = bankInfoData.getString("number");
//todo 最新更新时间
String modifyTime = "2025-05-14 00:00:00";
//开始查询是否已经集成过了
JSONObject isLog = new JSONObject();
try {
isLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_bank&log_type=BANKUP&dataId=" + bankNumber + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLog.getJSONArray("data").isEmpty()) {
log.info("当前银行已经集成过了,将不再向下执行");
continue;
}
//开始封装数据
Map bankInfoMap = new HashMap<>();
bankInfoMap.put("name", bankNumber);//行号
bankInfoMap.put("bank_name__c", bankName);//银行名称
bankInfoMap.put("province__c", bankInfoData.getString("province_name") != null ? bankInfoData.getString("province_name") : "");//省份
bankInfoMap.put("city_banking__c", bankInfoData.getString("city_name") != null ? bankInfoData.getString("city_name") : "");//
bankInfoMap.put("country_region__c", bankInfoData.getString("country_fullname") != null ? bankInfoData.getString("country_fullname") : "");//国家地区
bankInfoMap.put("branch_number__c", bankInfoData.getString("union_number") != null ? bankInfoData.getString("union_number") : "");//联行号
bankInfoMap.put("dataObjectApiName", "bank_info__c");
//发起请求前查询是否已存在该数据
JSONObject isCrmExist = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList(bankNumber)),
new Filter("EQ", "bank_name__c", Arrays.asList(bankName))
), "bank_info__c");
JSONObject isCrmExistRes = new JSONObject();
try {
isCrmExistRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, isCrmExist, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(isCrmExistRes.getString("errorDescription")) || isCrmExistRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("数据不存在或者查询失败,将不再继续向下执行");
continue;
}
JSONObject isCrmExistData = isCrmExistRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
bankInfoMap.put("_id", isCrmExistData.getString("_id"));
//更新请求
JSONObject updateReq = crmRequestUtil.updateCRM(bankInfoMap);
JSONObject updateRes = new JSONObject();
try {
updateRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, updateReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("更新结果为:" + JSON.parseObject(JSON.toJSONString(updateRes)));
//记录日志
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "BANKUP");
logMap.put("syn_type", "0");
logMap.put("data_name", bankName);
logMap.put("data_id", bankNumber);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(updateReq));
logMap.put("send_res", JSON.toJSONString(updateRes));
logMap.put("tableName", "send_log_bank");
//判断
if ("success".equals(updateRes.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + updateRes.getString("errorMessage"));
}
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);
}
}
}

View File

@ -0,0 +1,53 @@
package com.management.controller;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.CertificateConstant;
import com.management.constant.URLConstant;
import com.management.utils.CaffeineCacheUtil;
import lombok.extern.slf4j.Slf4j;
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.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/crm")
@Slf4j
public class CRMTokenController {
private RestTemplate restTemplate = new RestTemplate();
@PostMapping("/getToken")
public void getCRMToken() {
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = new JSONObject();
try {
tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//判断是否成功
if ("success".equals(tokenResponse.getString("errorMessage"))) {
String corpAccessToken = tokenResponse.getString("corpAccessToken");
//移除
CaffeineCacheUtil.remove("corpAccessToken");
//存入新的
CaffeineCacheUtil.put("corpAccessToken", corpAccessToken);
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
}

View File

@ -0,0 +1,698 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.CertificateConstant;
import com.management.constant.URLConstant;
import com.management.entity.Filter;
import com.management.utils.CrmRequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
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.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* 部门集成
*
* @param
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping("/zy/api/dept")
@Slf4j
public class DeptController {
@Autowired
private KDTokenController kdTokenController;
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
// new DeptController().syncDept();
new DeptController().syncDeptUp();
}
/**
* 部门同步,新增接口
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_create")
public void syncDept() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(2);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
//开始查询部门(暂时使用固定值)
Map data = new HashMap<>();
data.put("createtime", "2025-06-01 00:00:00");
data.put("enable", "1");
// data.put("number", Arrays.asList("ZHY002.005.003.004"));
// data.put("level", "3");
Map deptReq = new HashMap<>();
deptReq.put("data", data);
deptReq.put("pageNo", 1);
deptReq.put("pageSize", 1999);
String accessToken = new KDTokenController().getKDAccessToken();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity deptReqEntity = new HttpEntity(deptReq, headers);
//开始发起请求
//请求地址
String deptUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/base/bos_adminorg/adminOrgQuery";
String deptRes = "";
try {
deptRes = restTemplate.postForObject(deptUrl, deptReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//将请求到的数据转换为JSONObject
JSONObject deptResObj = JSON.parseObject(deptRes);
//开始执行判断
if (deptResObj.getBooleanValue("status") != true || deptResObj.getJSONObject("data").isEmpty() || deptResObj.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("金蝶部门数据请求失败或者为空");
return;
}
//数据不为空开始遍历数据
JSONArray deptRows = deptResObj.getJSONObject("data").getJSONArray("rows");
for (Object deptObj : deptRows) {
JSONObject deptData = JSON.parseObject(JSON.toJSONString(deptObj));
log.info("当前正在操作的数据为:{}", deptData);
//获取部门数据
//部门id
String deptId = deptData.getString("id");
//获取最后更新时间
String createTime = deptData.getString("createtime");
//查询日志
JSONObject getLog = new JSONObject();
try {
getLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_bmxx&log_type=DEPT&dataId=" + deptId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(getLog.getString("message")) && !getLog.getJSONArray("data").isEmpty()) {
log.info("当前部门已经新建过了,将不再向下执行");
continue;
}
log.info("没有集成过,将继续向下执行");
//部门名称
String deptName = deptData.getString("name");
if (deptName.contains("")) {
deptName = deptName.replace("", "_");
}
//父部门编码
JSONObject structureObj = deptData.getJSONArray("structure").getJSONObject(0);
String parentDeptCode = structureObj.getString("viewparent_id");
String parentDeptName = structureObj.getString("viewparent_name");
//部门编码
String deptCode = deptData.getString("number");
//开始封装数据
Map deptSyncReq = new HashMap<>();
deptSyncReq.put("name", deptName);
deptSyncReq.put("erp_id__c", deptId);
deptSyncReq.put("field_Vj6sf__c", deptCode);
deptSyncReq.put("field_v711K__c", parentDeptName);
deptSyncReq.put("field_31u4r__c", parentDeptCode);
deptSyncReq.put("owner", Arrays.asList("FSUID_50D3C26809B163F663DC8557268A8D44"));
deptSyncReq.put("dataObjectApiName", "DepartmentObj");
//查找父编码
//根据金蝶部门父编码查询crm部门父编码
JSONObject parentDeptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "erp_id__c", Arrays.asList(parentDeptCode))
), "DepartmentObj");
JSONObject parentDeptRes = new JSONObject();
try {
parentDeptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, parentDeptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(parentDeptRes);
if (!"success".equals(parentDeptRes.getString("errorDescription"))) {
log.info("查询失败");
continue;
}
if (parentDeptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("父编码为空,将不再向下执行");
continue;
}
//获取父部门和父编码
JSONObject parentDeptData = parentDeptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
String parentDeptId = parentDeptData.getString("_id");
deptSyncReq.put("parent_id", Arrays.asList(parentDeptId));
//判断部门是否在crm中存在
//请求封装
JSONObject deptIsExistReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList(deptName)),
new Filter("EQ", "field_v711K__c", Arrays.asList(parentDeptName)),
new Filter("EQ", "field_31u4r__c", Arrays.asList(parentDeptCode))
), "DepartmentObj");
//开始发起请求
JSONObject deptIsExistRes = new JSONObject();
try {
deptIsExistRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptIsExistReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptIsExistRes.getString("errorDescription")) && !deptIsExistRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
//部门已经存在将直接进行数据更新
log.info("部门已经存在,将直接进行数据更新");
String dept_id = deptIsExistRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id");
deptSyncReq.put("_id", dept_id);
//开始执行更新
JSONObject deptUpReq = crmRequestUtil.updateCRM(deptSyncReq);
JSONObject deptUpRes = new JSONObject();
try {
deptUpRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, deptUpReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
log.info("部门更新状态为:{}", deptUpRes);
continue;
}
//crm中不存在该部门继续进行新增
//开始执行新建
JSONObject deptCreateReq = crmRequestUtil.createCRM(deptSyncReq);
JSONObject deptCreateRes = new JSONObject();
try {
deptCreateRes = restTemplate.postForObject(URLConstant.CREATE_CRM_MAIN, deptCreateReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
log.info("部门创建状态为:{}", deptCreateRes);
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "DEPT");
logMap.put("syn_type", "0");
logMap.put("data_name", deptName);
logMap.put("data_id", deptId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(deptCreateReq));
logMap.put("send_res", JSON.toJSONString(deptCreateRes));
logMap.put("tableName", "send_log_bmxx");
//判断
if ("success".equals(deptCreateRes.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + deptCreateRes.getString("errorMessage"));
}
JSONObject logRes = new JSONObject();
try {
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
log.info("日志上传状态为:{}", logRes);
}
}
/**
* 部门更新接口
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_up")
public void syncDeptUp() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(2);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
//开始查询部门(暂时使用固定值)
Map data = new HashMap<>();
data.put("modifytime", "2025-06-01 00:00:00");
data.put("enable", "1");
// data.put("number", Arrays.asList("ZHY002.005.001.006"));
// data.put("level", "3");
Map deptReq = new HashMap<>();
deptReq.put("data", data);
deptReq.put("pageNo", 1);
deptReq.put("pageSize", 1000);
String accessToken = new KDTokenController().getKDAccessToken();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity deptReqEntity = new HttpEntity(deptReq, headers);
//开始发起请求
//请求地址
String deptUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/base/bos_adminorg/adminOrgQuery";
String deptRes = "";
try {
deptRes = restTemplate.postForObject(deptUrl, deptReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//将请求到的数据转换为JSONObject
JSONObject deptResObj = JSON.parseObject(deptRes);
System.out.println("请求结果为:" + deptRes);
//开始执行判断
if (deptResObj.getBooleanValue("status") != true || deptResObj.getJSONObject("data").isEmpty() || deptResObj.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("金蝶部门数据请求失败或者为空");
return;
}
//数据不为空开始遍历数据
JSONArray deptRows = deptResObj.getJSONObject("data").getJSONArray("rows");
for (Object deptObj : deptRows) {
JSONObject deptData = JSON.parseObject(JSON.toJSONString(deptObj));
log.info("当前正在操作的数据为:{}", deptData);
//获取部门数据
//部门id
String deptId = deptData.getString("id");
//获取最后更新时间
String modifyTime = deptData.getString("modifytime");
//查询日志
JSONObject getLog = new JSONObject();
try {
getLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_bmxx&log_type=DEPTUP&dataId=" + deptId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(getLog.getString("message")) && !getLog.getJSONArray("data").isEmpty()) {
log.info("当前部门已经更新过了,将不再向下执行");
continue;
}
log.info("没有集成过,将继续向下执行");
//部门名称
String deptName = deptData.getString("name");
if (deptName.contains("")) {
deptName = deptName.replace("", "_");
}
//父部门编码
JSONObject structureObj = deptData.getJSONArray("structure").getJSONObject(0);
String parentDeptCode = structureObj.getString("viewparent_id");
String parentDeptName = structureObj.getString("viewparent_name");
//部门编码
String deptCode = deptData.getString("number");
//开始封装数据
Map deptSyncReq = new HashMap<>();
deptSyncReq.put("name", deptName);
deptSyncReq.put("erp_id__c", deptId);
deptSyncReq.put("field_Vj6sf__c", deptCode);
deptSyncReq.put("field_v711K__c", parentDeptName);
deptSyncReq.put("field_31u4r__c", parentDeptCode);
deptSyncReq.put("owner", Arrays.asList("FSUID_50D3C26809B163F663DC8557268A8D44"));
deptSyncReq.put("dataObjectApiName", "DepartmentObj");
//查找父编码
//根据金蝶部门父编码查询crm部门父编码
JSONObject parentDeptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "erp_id__c", Arrays.asList(parentDeptCode))
), "DepartmentObj");
JSONObject parentDeptRes = new JSONObject();
try {
parentDeptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, parentDeptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(parentDeptRes.getString("errorDescription")) || parentDeptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("父编码为空,将不再向下执行");
continue;
}
//获取父部门和父编码
JSONObject parentDeptData = parentDeptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
String parentDeptId = parentDeptData.getString("_id");
deptSyncReq.put("parent_id", Arrays.asList(parentDeptId));
//判断部门是否在crm中存在
//请求封装
JSONObject deptIsExistReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList(deptName)),
new Filter("EQ", "field_v711K__c", Arrays.asList(parentDeptName)),
new Filter("EQ", "field_31u4r__c", Arrays.asList(parentDeptCode))
), "DepartmentObj");
//开始发起请求
JSONObject deptIsExistRes = new JSONObject();
try {
deptIsExistRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptIsExistReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptIsExistRes.getString("errorDescription")) && deptIsExistRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
//数据不存在将不再向下执行
log.info("部门不存在,将不再向下执行");
continue;
}
//数据存在将继续向下执行更新
//部门已经存在将直接进行数据更新
log.info("部门已经存在,将直接进行数据更新");
String dept_id = deptIsExistRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id");
deptSyncReq.put("_id", dept_id);
//开始执行更新
JSONObject deptUpReq = crmRequestUtil.updateCRM(deptSyncReq);
JSONObject deptUpRes = new JSONObject();
try {
deptUpRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_MAIN, deptUpReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "DEPTUP");
logMap.put("syn_type", "1");
logMap.put("data_name", deptName);
logMap.put("data_id", deptId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(deptUpReq));
logMap.put("send_res", JSON.toJSONString(deptUpRes));
logMap.put("tableName", "send_log_bmxx");
//判断
if ("success".equals(deptUpRes.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败");
}
JSONObject logRes = new JSONObject();
try {
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
log.info("日志上传状态为:{}", logRes);
}
}
/**
* 部门删除同步
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_delete")
public void syncDeptDel() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(2);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
//开始查询部门(暂时使用固定值)
Map data = new HashMap<>();
data.put("modifytime", "2020-01-01 00:00:00");
data.put("enable", "2");
//data.put("number", Arrays.asList("ZHY003.002"));
// data.put("level", "3");
Map deptReq = new HashMap<>();
deptReq.put("data", data);
deptReq.put("pageNo", 1);
deptReq.put("pageSize", 1000);
String accessToken = kdTokenController.getKDAccessToken();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity deptReqEntity = new HttpEntity(deptReq, headers);
//开始发起请求
//请求地址
String deptUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/base/bos_adminorg/adminOrgQuery";
String deptRes = "";
try {
deptRes = restTemplate.postForObject(deptUrl, deptReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//将请求到的数据转换为JSONObject
JSONObject deptResObj = JSON.parseObject(deptRes);
System.out.println("请求结果为:" + deptRes);
//开始执行判断
if (deptResObj.getBooleanValue("status") != true || deptResObj.getJSONObject("data").isEmpty() || deptResObj.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("金蝶部门数据请求失败或者为空");
return;
}
//数据不为空开始遍历数据
JSONArray deptRows = deptResObj.getJSONObject("data").getJSONArray("rows");
for (Object deptObj : deptRows) {
JSONObject deptData = JSON.parseObject(JSON.toJSONString(deptObj));
log.info("当前正在操作的数据为:{}", deptData);
//获取部门数据
//部门id
String deptId = deptData.getString("id");
//获取最后更新时间
String modifyTime = deptData.getString("modifytime");
//查询日志
JSONObject getLog = new JSONObject();
try {
getLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_bmxx&log_type=DEPTDEL&dataId=" + deptId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(getLog.getString("message")) && !getLog.getJSONArray("data").isEmpty()) {
log.info("当前部门已经执行过了,将不再向下执行");
continue;
}
log.info("没有集成过,将继续向下执行");
//部门名称
String deptName = deptData.getString("name");
//父部门编码
JSONObject structureObj = deptData.getJSONArray("structure").getJSONObject(0);
//父级全称
String parentDeptName = structureObj.getString("viewparent_name");
String parentDeptCode = structureObj.getString("viewparent_id");
//开始查询CRM
JSONObject crmReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList(deptName)),
new Filter("EQ", "field_v711K__c", Arrays.asList(parentDeptName)),
new Filter("EQ", "field_31u4r__c", Arrays.asList(parentDeptCode))
), "DepartmentObj");
JSONObject crmRes = new JSONObject();
try {
crmRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, crmReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(crmRes.getString("errorDescription"))) {
log.info("请求失败");
continue;
}
if (crmRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("未查询到数据");
continue;
}
//数据存在执行作废
JSONObject crmData = crmRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
String crmId = crmData.getString("_id");
//开始封装作废数据
Map delData = new HashMap<>();
delData.put("object_data_id", crmId);
delData.put("dataObjectApiName", "DepartmentObj");
Map delReq = new HashMap<>();
delReq.put("corpAccessToken", crmRequestUtil.getCRMToken());
delReq.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
delReq.put("corpId", CertificateConstant.CORP_ID);
delReq.put("data", delData);
//开始请求作废接口
JSONObject delRes = new JSONObject();
try {
delRes = restTemplate.postForObject("https://open.fxiaoke.com/cgi/crm/custom/v2/data/invalid", delReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "DEPTDEL");
logMap.put("syn_type", "2");
logMap.put("data_name", deptName);
logMap.put("data_id", deptId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(delReq));
logMap.put("send_res", JSON.toJSONString(delRes));
logMap.put("tableName", "send_log_bmxx");
//判断
if ("success".equals(delRes.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + delRes.getString("errorMessage"));
}
JSONObject logRes = new JSONObject();
try {
logRes = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
log.info("日志上传状态为:{}", logRes);
}
}
}

View File

@ -0,0 +1,652 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
import com.management.constant.URLConstant;
import com.management.entity.Filter;
import com.management.utils.CrmRequestUtil;
import com.management.utils.KingDeeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
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.util.*;
/**
* 设计文件
*
* @param
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping("/api/design")
@Slf4j
public class DesignController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new DesignController().syncDesign();
}
/**
* 设计文件同步
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/designDoc")
public void syncDesign() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步设计文件");
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
//new Filter("EQ", "name", Arrays.asList("SJWJ250528-0022")),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
new Filter("EQ", "life_status", Arrays.asList("normal"))
), "design_file__c");
JSONObject designDocRes = new JSONObject();
try {
designDocRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDoc, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(designDocRes.getString("errorDescription")) || designDocRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或者不存在符合条件的数据");
return;
}
log.info("查询成功,继续向下执行");
for (Object designDocObj : designDocRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject designDocData = JSON.parseObject(JSON.toJSONString(designDocObj));
System.out.println("当前正在处理的设计文件数据为:" + designDocData);
//当前设计文件的唯一id
String designDocId = designDocData.getString("_id");
//当前单据的编号
String designDocName = designDocData.getString("name");
//当前单据的创建时间
//String createTime = designDocData.getString("create_time");
String createTime = designDocData.getString("last_modified_time");
//开始查询该单据是否已经集成过
JSONObject isLog = new JSONObject();
try {
isLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_sjwj&log_type=DF&dataId=" + designDocId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//判断是否已经执行过
if (!isLog.getJSONArray("data").isEmpty()) {
log.info("当前单据已经集成过了,将不再向下执行");
continue;
}
log.info("当前单据没有集成过,将开始向下执行");
//开始封装传输至ERP中的请求
Map erpDesignMap = new HashMap<>();
erpDesignMap.put("billno", designDocName);//设计文件编号
//判断组织编码
String orgCode = "";
if (designDocData.getString("erp_organization_sales_con__c__v") != null && !"".equals(designDocData.getString("erp_organization_sales_con__c__v"))) {
orgCode = designDocData.getString("erp_organization_sales_con__c__v");
} else if (designDocData.getString("erp_organization_pre_contr__c__v") != null && !"".equals(designDocData.getString("erp_organization_pre_contr__c__v"))) {
orgCode = designDocData.getString("erp_organization_pre_contr__c__v");
} else {
log.info("当前单据没有组织编码,将不再向下执行");
continue;
}
erpDesignMap.put("org_number", orgCode);//组织编码
erpDesignMap.put("billtype_number", "pm_requirapplybill_BT_sjwjxf");//单据类型
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
//开始获取单据日期
long bizTime = designDocData.getLong("document_date__c");
Date date = new Date(bizTime);
erpDesignMap.put("biztime", date);//单据日期
//部门编码
String deptCode = "";
List deptIdList = designDocData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
//erpDesignMap.put("dept_number", "004");//部门编码
erpDesignMap.put("dept_number", deptCode);//部门编码
//获取负责人编码
String ownerCode = "";
List ownerIdList = designDocData.getJSONArray("owner");
System.out.println(ownerIdList);
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("查询负责人结果为:" + ownerRes);
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
//erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
erpDesignMap.put("bizuser_number", ownerCode);//人员编码
erpDesignMap.put("bizorg_number", orgCode);//采购组织
erpDesignMap.put("project_number", "SJ20250424-0033");//todo 项目号商机
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
erpDesignMap.put("crmid", designDocId);//crm唯一id
erpDesignMap.put("comment", designDocData.getString("remark__c") != null ? designDocData.getString("remark__c") : "");//备注
//开始获取设计文件明细
JSONObject getDesignDocDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "design_file__c", Arrays.asList(designDocId))
), "design_file_details__c");
JSONObject designDocDetailRes = new JSONObject();
try {
designDocDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDocDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(designDocDetailRes.getString("errorDescription")) || designDocDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或不存在当前设计文件明细");
continue;
}
List designDocList = new ArrayList<>();
for (Object designDocDetailObj : designDocDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject designDocDetailData = JSON.parseObject(JSON.toJSONString(designDocDetailObj));
System.out.println("当前正在处理的设计文件明细数据为:" + designDocDetailData);
//开始封装设计文件明细
Map designDocDetailMap = new HashMap<>();
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_name__c"));//设计文件明细
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
designDocDetailMap.put("entrycomment", designDocDetailData.getString("remark__c") != null ? designDocDetailData.getString("remark__c") : "");//备注
designDocDetailMap.put("supplier_number", designDocDetailData.getString("supplier_code__c") != null ? designDocDetailData.getString("supplier_code__c") : "");//建议供应商
designDocList.add(designDocDetailMap);
}
erpDesignMap.put("billentry", designDocList);
Map erpContractData = new HashMap<>();
erpContractData.put("data", Arrays.asList(erpDesignMap));//请求体
System.out.println("erp请求为" + JSON.parseObject(JSON.toJSONString(erpContractData)));
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity designDocReqEntity = new HttpEntity(erpContractData, headers);
System.out.println("请求为:" + JSON.parseObject(JSON.toJSONString(designDocReqEntity)));
//开始向金蝶发起请求
String designPlanUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/pssc/requirapplybillSave";
JSONObject erpDesignDocRes = new JSONObject();
try {
erpDesignDocRes = restTemplate.postForObject(designPlanUrl, designDocReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("设计文件结果为:" + JSON.parseObject(JSON.toJSONString(erpDesignDocRes)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", designDocId);
backReqMap.put("dataObjectApiName", "design_file__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "DF");
logMap.put("syn_type", "0");
logMap.put("data_name", designDocName);
logMap.put("data_id", designDocId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(designDocReqEntity));
logMap.put("send_res", JSON.toJSONString(erpDesignDocRes));
logMap.put("tableName", "send_log_sjwj");
//判断是否执行成功
if ("0".equals(erpDesignDocRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
//审核
KingDeeUtils kingDeeUtils = new KingDeeUtils();
kingDeeUtils.audit(erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getString("id"), "pm_requirapplybill");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + erpDesignDocRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", erpDesignDocRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, backReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("回写结果为:" + backRes);
//开始记录日志
JSONObject logResMap = new JSONObject();
try {
logResMap = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("日志插入结果为:" + logResMap);
//判断一下设计文件的状态没有成功就不传了
if (!"0".equals(erpDesignDocRes.getString("errorCode"))) {
continue;
}
//开始封装明细回写程序
for (Object resultObj : erpDesignDocRes.getJSONObject("datas").getJSONArray("result").getJSONObject(0).getJSONArray("entry")) {
JSONObject resultData = JSON.parseObject(JSON.toJSONString(resultObj));
String erpLineId = resultData.getString("entryid");
String crmLineId = resultData.getString("crmentryid");
//开始封装
Map backMap = new HashMap();
backMap.put("_id", crmLineId);
backMap.put("erp_line_id__c", erpLineId);
backMap.put("dataObjectApiName", "design_file_details__c");
JSONObject detailReq = crmRequestUtil.updateCRM(backMap);
JSONObject detailRes = new JSONObject();
try {
detailRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, detailReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("明细回写结果为:" + detailRes);
}
}
}
/**
* 设计文件更新接口
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/syncUp/designDoc")
public void upDesignDoc() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步设计文件");
JSONObject getDesignDoc = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList("SJWJ250509-0003"))
), "design_file__c");
JSONObject designDocRes = new JSONObject();
try {
designDocRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDoc, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(designDocRes.getString("errorDescription")) || designDocRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或者不存在符合条件的数据");
return;
}
log.info("查询成功,继续向下执行");
for (Object designDocObj : designDocRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject designDocData = JSON.parseObject(JSON.toJSONString(designDocObj));
System.out.println("当前正在处理的设计文件数据为:" + designDocData);
//当前设计文件的唯一id
String designDocId = designDocData.getString("_id");
//当前单据的编号
String designDocName = designDocData.getString("name");
//当前单据的创建时间
String createTime = designDocData.getString("create_time");
//开始查询该单据是否已经集成过
JSONObject isLog = new JSONObject();
try {
isLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_sjwj&log_type=DFUP&dataId=" + designDocId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//判断是否已经执行过
if (!isLog.getJSONArray("data").isEmpty()) {
log.info("当前单据已经集成过了,将不再向下执行");
continue;
}
log.info("当前单据没有集成过,将开始向下执行");
//开始封装传输至ERP中的请求
String erpId = designDocData.getString("erp_id__c") != null ? designDocData.getString("erp_id__c") : "";
if ("".equals(erpId)) {
log.info("当前单据erp_id__c为空不再向下执行");
continue;
}
Map erpDesignMap = new HashMap<>();
erpDesignMap.put("id", erpId);//erpId
erpDesignMap.put("billno", designDocName);//设计文件编号
//判断组织编码
String orgCode = "";
if (designDocData.getString("erp_organization_sales_con__c__v") != null && !"".equals(designDocData.getString("erp_organization_sales_con__c__v"))) {
orgCode = designDocData.getString("erp_organization_sales_con__c__v");
} else if (designDocData.getString("erp_organization_pre_contr__c__v") != null && !"".equals(designDocData.getString("erp_organization_pre_contr__c__v"))) {
orgCode = designDocData.getString("erp_organization_pre_contr__c__v");
} else {
log.info("当前单据没有组织编码,将不再向下执行");
continue;
}
erpDesignMap.put("org_number", orgCode);//组织编码
erpDesignMap.put("billtype_number", "pm_requirapplybill_STD_BT_S");//单据类型
erpDesignMap.put("biztype_name", "物料类采购");//业务类型
//开始获取单据日期
long bizTime = designDocData.getLong("document_date__c");
Date date = new Date(bizTime);
erpDesignMap.put("biztime", date);//单据日期
//部门编码
String deptCode = "";
List deptIdList = designDocData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
//erpDesignMap.put("dept_number", "ZHY");//部门编码
erpDesignMap.put("dept_number", deptCode);//部门编码
//获取负责人编码
String ownerCode = "";
List ownerIdList = designDocData.getJSONArray("owner");
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
//erpDesignMap.put("bizuser_number", "ID-000011");//人员编码
erpDesignMap.put("bizuser_number", ownerCode);//人员编码
erpDesignMap.put("bizorg_number", orgCode);//采购组织
erpDesignMap.put("project_number", designDocData.getString("project_id__c"));//todo 项目号商机
erpDesignMap.put("contractno", designDocData.getString("sales_contract_number__c__r"));//合同号
erpDesignMap.put("crmid", designDocId);//crm唯一id
erpDesignMap.put("comment", designDocData.getString("remark__c") != null ? designDocData.getString("remark__c") : "");//备注
//开始获取设计文件明细
JSONObject getDesignDocDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "design_file__c", Arrays.asList(designDocId))
), "design_file_details__c");
JSONObject designDocDetailRes = new JSONObject();
try {
designDocDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDesignDocDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(designDocDetailRes.getString("errorDescription")) || designDocDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或不存在当前设计文件明细");
continue;
}
List designDocList = new ArrayList<>();
for (Object designDocDetailObj : designDocDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject designDocDetailData = JSON.parseObject(JSON.toJSONString(designDocDetailObj));
System.out.println("当前正在处理的设计文件明细数据为:" + designDocDetailData);
//开始封装设计文件明细
Map designDocDetailMap = new HashMap<>();
designDocDetailMap.put("materialmasterid_number", designDocDetailData.getString("material_name__c"));//设计文件明细
designDocDetailMap.put("qty", designDocDetailData.getBigDecimal("quantity__c") != null ? designDocDetailData.getBigDecimal("quantity__c") : 0);//数量
designDocDetailMap.put("materialtype", designDocDetailData.getString("customer_material_type__c"));//客指供应类型
designDocDetailMap.put("crmentryid", designDocDetailData.getString("_id"));//crm明细行id
designDocDetailMap.put("entrycomment", designDocDetailData.getString("remark__c") != null ? designDocDetailData.getString("remark__c") : "");//备注
designDocDetailMap.put("supplier_number", "G08000001");//todo 建议供应商
designDocList.add(designDocDetailMap);
}
erpDesignMap.put("billentry", designDocList);
Map erpContractData = new HashMap<>();
erpContractData.put("data", Arrays.asList(erpDesignMap));//请求体
System.out.println("erp请求为" + JSON.parseObject(JSON.toJSONString(erpContractData)));
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity designDocReqEntity = new HttpEntity(erpContractData, headers);
System.out.println("请求为:" + JSON.parseObject(JSON.toJSONString(designDocReqEntity)));
//开始向金蝶发起请求
String designPlanUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/pssc/pm_requirapplybill/requirapplybillSave";
JSONObject erpDesignDocRes = new JSONObject();
try {
erpDesignDocRes = restTemplate.postForObject(designPlanUrl, designDocReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("设计文件结果为:" + JSON.parseObject(JSON.toJSONString(erpDesignDocRes)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", designDocId);
backReqMap.put("dataObjectApiName", "design_file__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "DFUP");
logMap.put("syn_type", "0");
logMap.put("data_name", designDocName);
logMap.put("data_id", designDocId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(designDocReqEntity));
logMap.put("send_res", JSON.toJSONString(erpDesignDocRes));
logMap.put("tableName", "send_log_sjwj");
//判断是否执行成功
if ("0".equals(erpDesignDocRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", erpDesignDocRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + erpDesignDocRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", erpDesignDocRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, backReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("回写结果为:" + backRes);
//开始记录日志
JSONObject logResMap = new JSONObject();
try {
logResMap = restTemplate.postForObject("http://localhost:18085/Log/insert/log_data", logMap, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("日志插入结果为:" + logResMap);
}
}
}

View File

@ -0,0 +1,340 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
import com.management.constant.URLConstant;
import com.management.entity.Filter;
import com.management.utils.CrmRequestUtil;
import com.management.utils.KingDeeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
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.util.*;
@RestController
@RequestMapping("/api/frame")
@Slf4j
public class FrameContractController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new FrameContractController().syncFrameContract();
}
/**
* 同步框架合同
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping
public void syncFrameContract() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject frameContract = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("EQ", "life_status", Arrays.asList("normal")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
//new Filter("EQ", "name", Arrays.asList("KJ2505200005")),
new Filter("GT", "create_time", Arrays.asList("1748923200000"))
), "framework_contract__c");
JSONObject frameContractRes = new JSONObject();
try {
frameContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, frameContract, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(frameContractRes.getString("errorDescription")) || frameContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或者不存在符合条件的数据");
return;
}
log.info("查询成功,继续向下执行");
for (Object frameContractObj : frameContractRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject frameContractData = JSON.parseObject(JSON.toJSONString(frameContractObj));
System.out.println("当前正在处理的框架合同数据为:" + frameContractData);
//开始截取关键数据
String frameContractId = frameContractData.getString("_id");
//合同名称
String frameContractName = frameContractData.getString("name");
//创建时间
//String createTime = frameContractData.getString("create_time");
String createTime = frameContractData.getString("last_modified_time");
//开始查询是否已经集成过该合同
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=KJHT&dataId=" + frameContractId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
//开始封装数据
Map frameContractReqMap = new HashMap<>();
frameContractReqMap.put("billno", frameContractName);//合同编号
frameContractReqMap.put("crmid", frameContractId);//合同编号
//开始查询商机编号
String businessId = frameContractData.getString("business_opportunity__c") != null ? frameContractData.getString("business_opportunity__c") : "";
if (businessId == null || businessId.equals("")) {
log.info("当前数据没有商机编号,将不再向下执行");
continue;
}
JSONObject businessReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(businessId))
), "NewOpportunityObj");
JSONObject businessRes = new JSONObject();
businessRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, businessReq, JSONObject.class);
String projectCode = "";
if ("success".equals(businessRes.getString("errorDescription")) && !businessRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject businessData = businessRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
projectCode = businessData.getString("opportunity_id__c");
}
//frameContractReqMap.put("project_number", "SJ20250424-0033");//todo 项目号商机编号
frameContractReqMap.put("project_number", projectCode);//todo 项目号商机编号
frameContractReqMap.put("billtype_number", "conm_salcontract_BT_QD");//erp单据类型
frameContractReqMap.put("zhybilltype", frameContractData.getString("contract_type__c") != null ? frameContractData.getString("contract_type__c") : "");//合同类型
frameContractReqMap.put("billname", frameContractData.getString("project_name__c") != null ? frameContractData.getString("project_name__c") : "");//合同名称
frameContractReqMap.put("type_number", "XSHT-QD03");//合同类型
frameContractReqMap.put("contparties_number", frameContractData.getString("our_company_name__c") != null ? frameContractData.getString("our_company_name__c") : "");//合同主体
frameContractReqMap.put("createorg_number", frameContractData.getString("our_company_name__c") != null ? frameContractData.getString("our_company_name__c") : "");//销售组织编码
frameContractReqMap.put("org_number", frameContractData.getString("our_company_name__c") != null ? frameContractData.getString("our_company_name__c") : "");//销售组织编码
frameContractReqMap.put("currency_number", "CNY");//本位币.货币代码
frameContractReqMap.put("settlecurrency_number", "CNY");//结算币别.货币代码
long signDate = frameContractData.getLong("signing_date__c");
frameContractReqMap.put("biztime", signDate);//签订日期,单据日期
frameContractReqMap.put("biztimebegin", signDate);//起始日期
frameContractReqMap.put("biztimeend", signDate);//截止日期
frameContractReqMap.put("party1st", frameContractData.getString("contract_unit_name__c__r") != null ? frameContractData.getString("contract_unit_name__c__r") : "");//甲方
frameContractReqMap.put("party2nd", frameContractData.getString("our_company_name__c__r") != null ? frameContractData.getString("our_company_name__c__r") : "");//乙方
frameContractReqMap.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
//部门编码
String deptCode = "";
List deptIdList = frameContractData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
frameContractReqMap.put("dept", deptCode);//归属部门
//获取负责人编码
String ownerCode = "";
List ownerIdList = frameContractData.getJSONArray("owner");
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
//frameContractReqMap.put("operator", "ZHY12025");//todo 负责人
frameContractReqMap.put("operator", ownerCode);
//合同单位
String customerId = frameContractData.getString("contract_unit_name__c");
//根据客户唯一id查询客户名称
JSONObject customerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, customerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("客户名称查询失败或者不存在,直接跳过更新");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
frameContractReqMap.put("customer_number", customerData.getString("account_no"));//合同单位名称
frameContractReqMap.put("reccustomer_number", customerData.getString("account_no"));//收获客户单位名称
//frameContractReqMap.put("customer_number", "Cus-000007");//todo 合同单位名称
frameContractReqMap.put("settlecustomer_number", frameContractData.getString("billing_customer_code__c") != null ? frameContractData.getString("billing_customer_code__c") : "");//结算客户
frameContractReqMap.put("payingcustomer_number", frameContractData.getString("payment_customer_code__c") != null ? frameContractData.getString("payment_customer_code__c") : "");//付款客户
//获取产品线
frameContractReqMap.put("productline_number", frameContractData.getString("product_line__c"));//产品线
//获取具体安装方式
frameContractReqMap.put("installationmethod", frameContractData.getString("installation_method__c"));//安装方式
//行业类型
frameContractReqMap.put("industrytype_number", frameContractData.getString("industry_type__c"));//行业类型
frameContractReqMap.put("province", frameContractData.getString("field_t3fgo__c__r"));//
frameContractReqMap.put("city", frameContractData.getString("field_ngwth__c__r"));//
frameContractReqMap.put("county", frameContractData.getString("field_K5p2C__c__r"));//
frameContractReqMap.put("station", frameContractData.getString("single_choice__c") != null ? frameContractData.getString("single_choice__c") : "");//局级
frameContractReqMap.put("delivery", frameContractData.getString("ship_on_payment_received__c") != null ? frameContractData.getString("ship_on_payment_received__c") : "");//款到发货
frameContractReqMap.put("projectsource", frameContractData.getString("project_source__c") != null ? frameContractData.getString("project_source__c") : "");//项目来源
frameContractReqMap.put("salesmethod", frameContractData.getString("sales_method__c") != null ? frameContractData.getString("sales_method__c") : "");//销售方式
Map erpFrameContractReqMap = new HashMap<>();
erpFrameContractReqMap.put("data", Arrays.asList(frameContractReqMap));//请求体
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity contractReqEntity = new HttpEntity(erpFrameContractReqMap, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
//开始向金蝶发起请求
String contractUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/conm/conm_salcontract/savecontract";
JSONObject contractRes = new JSONObject();
try {
contractRes = restTemplate.postForObject(contractUrl, contractReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", frameContractId);
backReqMap.put("dataObjectApiName", "framework_contract__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "KJHT");
logMap.put("syn_type", "0");
logMap.put("data_name", frameContractName);
logMap.put("data_id", frameContractId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(contractReqEntity));
logMap.put("send_res", JSON.toJSONString(contractRes));
logMap.put("tableName", "send_log_htxx");
//判断是否执行成功
if ("0".equals(contractRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
//审核
KingDeeUtils kingDeeUtils = new KingDeeUtils();
kingDeeUtils.audit(contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + contractRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", contractRes.getString("message"));
}
//开始回写
//解锁
if ("1".equals(frameContractData.getString("lock_status"))) {
log.info("解锁");
crmRequestUtil.unlockCRM(frameContractId, "framework_contract__c");
}
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,709 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
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.http.MediaType;
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.math.BigDecimal;
import java.util.*;
@RestController
@RequestMapping("/api/invoice")
@Slf4j
public class InvoiceController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new InvoiceController().syncInvoice();
//new InvoiceController().syncRedInvoice();
}
/**
* 发票同步
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_invoice")
public void syncInvoice() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getInvoice = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("EQ", "life_status", Arrays.asList("normal")),
//new Filter("EQ", "name", Arrays.asList("20250527-000010"))
new Filter("GT", "create_time", Arrays.asList("1748923200000"))
), "InvoiceApplicationObj");
log.info("开始同步创建发票");
JSONObject invoiceRes = new JSONObject();
try {
invoiceRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInvoice, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(invoiceRes.getString("errorDescription")) || invoiceRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("发票查询失败或者不存在");
return;
}
log.info("单据存在,继续向下执行");
for (Object invoiceObj : invoiceRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject invoiceData = JSON.parseObject(JSON.toJSONString(invoiceObj));
System.out.println("当前正在处理的发票为:" + invoiceData);
//开始截取关键数据
//发票CRMID
String invoiceId = invoiceData.getString("_id");
//发票名称
String invoiceName = invoiceData.getString("name");
//开票创建时间
//String createTime = invoiceData.getString("create_time");
String createTime = invoiceData.getString("last_modified_time");
//开始判断数据库中是否存在数据
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_invoice&log_type=KP&dataId=" + invoiceId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
//开始封装请求
Map invoiceMap = new HashMap();
String invoiceType = invoiceData.getString("record_type") != null ? invoiceData.getString("record_type") : "";
invoiceMap.put("billsourcetype", "blue");
invoiceMap.put("crmbillno", invoiceName);//单据编号
invoiceMap.put("crmid", invoiceData.getString("sales1_contract__c"));//销售合同CRMID
//是否国网
String isGWStr = invoiceData.getString("is_state_grid__c") != null ? invoiceData.getString("is_state_grid__c") : "";
Boolean isGW = null;
switch (isGWStr) {
case "ubaL12a0M":
isGW = true;
break;
case "tiVjNIMLU":
isGW = false;
break;
default:
isGW = null;
break;
}
invoiceMap.put("isgw", isGW);//是否国网
//是否设计建筑服务
String isJZStr = invoiceData.getString("is_involved_construction_s__c") != null ? invoiceData.getString("is_involved_construction_s__c") : "";
Boolean isJZ = null;
switch (isJZStr) {
case "option_is_yes__c":
isJZ = true;
break;
case "option_is_no__c":
isJZ = false;
break;
default:
isJZ = null;
break;
}
invoiceMap.put("isjzfw", isJZ);//是否设计建筑服务
//是否跨地市
String isCityStr = invoiceData.getString("is_cross_city__c") != null ? invoiceData.getString("is_cross_city__c") : "";
Boolean isCity = null;
switch (isCityStr) {
case "option_is_yes__c":
isCity = true;
break;
case "option_is_no__c":
isCity = false;
break;
default:
isCity = null;
break;
}
invoiceMap.put("iskds", isCity);//是否跨地市
invoiceMap.put("jzaddr", invoiceData.getString("field_b11hY__c") != null ? invoiceData.getString("field_b11hY__c") : "");//建筑服务发生地
invoiceMap.put("jzpjname", invoiceData.getString("field_6cxEV__c") != null ? invoiceData.getString("field_6cxEV__c") : "");//建筑服务项目名称
invoiceMap.put("crminvoiceid", invoiceId);//crm开票申请ID
//开票类型
String invoiceKinds = invoiceData.getString("invoice_type") != null ? invoiceData.getString("invoice_type") : "";
invoiceMap.put("invoicetype", invoiceKinds);
invoiceMap.put("comment", invoiceData.getString("remark") != null ? invoiceData.getString("remark") : "");//发票备注
invoiceMap.put("buyeremail", invoiceData.getString("invoice_delivery_email__c") != null ? invoiceData.getString("invoice_delivery_email__c") : "2019326567@qq.com");//发票推送邮箱
//开票单位编码
String customerId = invoiceData.getString("invoice_unit__c") != null ? invoiceData.getString("invoice_unit__c") : "TEST0001";
//根据客户唯一id查询客户编码
JSONObject getCustomer = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getCustomer, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("未找到开票单位或者查询失败");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
String customerNumber = customerData.getString("account_no");
invoiceMap.put("asstact_number", customerNumber);//往来户(客户)
invoiceMap.put("buyertaxno", invoiceData.getString("tax_id") != null ? invoiceData.getString("tax_id") : "");//纳税人识别号
//开票地址
String invoice_add = invoiceData.getString("invoice_add") != null ? invoiceData.getString("invoice_add") : "";
invoiceMap.put("buyeraddr", invoice_add);//购方地址
//电话
String invoice_phone = invoiceData.getString("invoice_tel") != null ? invoiceData.getString("invoice_tel") : "";
invoiceMap.put("buyerphone", invoice_phone);//购方电话
//开户行
String account_bank = invoiceData.getString("account_bank") != null ? invoiceData.getString("account_bank") : "";
invoiceMap.put("buyerbank", account_bank);
//开户账号
String account_bank_no = invoiceData.getString("account_bank_no") != null ? invoiceData.getString("account_bank_no") : "";
invoiceMap.put("buyerbanknumber", account_bank_no);
//是否展示地址电话
Boolean isShowTel = invoiceData.getBoolean("show_address_phone__c");
invoiceMap.put("showbuyeraddresstel", isShowTel);
//是否展示明细
Boolean isShowDetail = invoiceData.getBoolean("invoice_details_complete__c");
invoiceMap.put("showdetails", isShowDetail);
//是否展示开户行及账号
Boolean isShowBank = invoiceData.getBoolean("show_bank_account__c");
invoiceMap.put("showbuyerbank", isShowBank);
//是否含软
String isHasSoft = invoiceData.getString("is_contain_soft__c");
Boolean isHasSoftBool = false;
switch (isHasSoft) {
case "v2j71Ak5p":
isHasSoftBool = true;
break;
case "YOZj917km":
isHasSoftBool = false;
break;
}
invoiceMap.put("issoftworks", isHasSoftBool);
//软著版本编码
invoiceMap.put("softworks_number", invoiceData.getString("positive_number__c") != null ? invoiceData.getString("positive_number__c") : "");
//开始查询明细
JSONObject getInvoiceDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "invoice_id", Arrays.asList(invoiceId))
), "InvoiceApplicationLinesObj");
JSONObject invoiceDetailRes = new JSONObject();
try {
invoiceDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInvoiceDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(invoiceDetailRes.getString("errorDescription")) || invoiceDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("发票明细查询失败或者不存在");
continue;
}
log.info("发票明细查询成功,将继续向下执行");
List entry = new ArrayList<>();
for (Object invoiceDetailObj : invoiceDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject invoiceDetailData = JSON.parseObject(JSON.toJSONString(invoiceDetailObj));
System.out.println("当前正在处理的明细为:" + invoiceDetailData);
Map entryMap = new HashMap();
if (invoiceType.equals("default__c")) {
//blue传销售合同明细id
entryMap.put("crmentryid", invoiceDetailData.getString("sales_contract_details__c"));
} else if (invoiceType.equals("record_3pGf2__c")) {
//red传开票申请单明细id
entryMap.put("crmentryid", invoiceDetailData.getString("_id"));
}
entryMap.put("crminvoiceentryid", invoiceDetailData.getString("_id"));//开票申请明细id
entryMap.put("goodsname", invoiceDetailData.getString("invoice_product_name__c") != null ? invoiceDetailData.getString("invoice_product_name__c") : "");//商品名称
//entryMap.put("softworks_number", invoiceDetailData.getString("invoice_product_num__c") != null ? invoiceDetailData.getString("invoice_product_num__c") : "");//软著编码
entryMap.put("taxratecodeid_number", invoiceDetailData.getString("product_category__c") != null ? invoiceDetailData.getString("product_category__c") : "");//税收分类
entryMap.put("quantity", invoiceDetailData.getBigDecimal("field_9C0j7__c") != null ? invoiceDetailData.getBigDecimal("field_9C0j7__c") : 0);//数量
entryMap.put("taxunitprice", invoiceDetailData.getBigDecimal("tax_inclusive_unit_price__c") != null ? invoiceDetailData.getBigDecimal("tax_inclusive_unit_price__c") : 0);//含税单价
entryMap.put("recamount", invoiceDetailData.getBigDecimal("invoiced_amount") != null ? invoiceDetailData.getBigDecimal("invoiced_amount") : 0);//应收金额-开票小计
entryMap.put("taxrateid_number", invoiceDetailData.getString("tax_rate_code__c") != null ? invoiceDetailData.getString("tax_rate_code__c") : "");//税率编码
entryMap.put("measureunit_number", invoiceDetailData.getString("unit__c") != null ? invoiceDetailData.getString("unit__c") : "");//计量单位
entryMap.put("specification", invoiceDetailData.getString("specification_model__c") != null ? invoiceDetailData.getString("specification_model__c") : "");//规格型号
entry.add(entryMap);
}
invoiceMap.put("entry", entry);
//开始获取token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity invoiceReqEntity = new HttpEntity(invoiceMap, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(invoiceReqEntity)));
String invoiceUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/ar/arbusbill/createInvoice";
JSONObject erpInvoiceRes = new JSONObject();
try {
erpInvoiceRes = restTemplate.postForObject(invoiceUrl, invoiceReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(erpInvoiceRes);
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", invoiceId);
backReqMap.put("dataObjectApiName", "InvoiceApplicationObj");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "KP");
logMap.put("syn_type", "0");
logMap.put("data_name", invoiceName);
logMap.put("data_id", invoiceId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(invoiceReqEntity));
logMap.put("send_res", JSON.toJSONString(erpInvoiceRes));
logMap.put("tableName", "send_log_invoice");
//判断是否执行成功
if ("0".equals(erpInvoiceRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", erpInvoiceRes.getJSONObject("data").getString("pkId"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + erpInvoiceRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", erpInvoiceRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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
public void syncRedInvoice() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getRedInvoice = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
//new Filter("IS", "field_UB1hE__c", Arrays.asList("")),
//new Filter("EQ", "name", Arrays.asList("HCFP2505-0003")),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
new Filter("EQ", "life_status", Arrays.asList("normal"))
), "custom_object_example1__c");
JSONObject redInvoiceRes = new JSONObject();
try {
redInvoiceRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getRedInvoice, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(redInvoiceRes.getString("errorDescription")) || redInvoiceRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("未找到红冲发票或者查询失败");
return;
}
for (Object redInvoiceObj : redInvoiceRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject redInvoiceData = JSON.parseObject(JSON.toJSONString(redInvoiceObj));
System.out.println("当前正在处理数据为:" + redInvoiceData);
//开始截取关键数据
//唯一性编码
String redInvoiceId = redInvoiceData.getString("_id");
//红冲单号
String redInvoiceName = redInvoiceData.getString("name");
//红冲单创建时间
String createTime = redInvoiceData.getString("create_time");
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_invoice&log_type=REDKP&dataId=" + redInvoiceId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("查询日志结果为:" + isLogRes);
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
Map invoiceMap = new HashMap();
invoiceMap.put("billsourcetype", "red");//单据类型
invoiceMap.put("crmbillno", redInvoiceName);//单据编号
invoiceMap.put("crmid", redInvoiceData.getString("blue_invoice_application__c"));//红冲开票CRMID
invoiceMap.put("crminvoiceid", redInvoiceId);//CRM红冲开票申请ID
invoiceMap.put("invoicetype", redInvoiceData.getString("invoice_type__c") != null ? redInvoiceData.getString("invoice_type__c") : "");//开票类型
invoiceMap.put("comment", redInvoiceData.getString("invoice_note__c") != null ? redInvoiceData.getString("invoice_note__c") : "");//备注
invoiceMap.put("buyeremail", redInvoiceData.getString("invoice_delivery_email__c") != null ? redInvoiceData.getString("invoice_delivery_email__c") : "2019326567@qq.com");//发票推送邮箱
//开票单位编码
String customerId = redInvoiceData.getString("customer_name__c") != null ? redInvoiceData.getString("customer_name__c") : "TEST0001";
//根据客户唯一id查询客户编码
JSONObject getCustomer = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getCustomer, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("未找到开票单位或者查询失败");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
String customerNumber = customerData.getString("account_no");
invoiceMap.put("asstact_number", customerNumber);//往来户(客户)
invoiceMap.put("buyertaxno", redInvoiceData.getString("tax_identification_number__c") != null ? redInvoiceData.getString("tax_identification_number__c") : "");//纳税识别号
invoiceMap.put("buyeraddr", redInvoiceData.getString("invoice_address__c") != null ? redInvoiceData.getString("invoice_address__c") : "");//地址
invoiceMap.put("buyerphone", redInvoiceData.getString("field_SM1Wc__c") != null ? redInvoiceData.getString("field_SM1Wc__c") : "");//电话
invoiceMap.put("showbuyeraddresstel", redInvoiceData.getBooleanValue("show_address_phone__c"));//是否展示地址电话
invoiceMap.put("buyerbank", redInvoiceData.getString("bank_branch__c") != null ? redInvoiceData.getString("bank_branch__c") : "");//开户行
invoiceMap.put("buyerbanknumber", redInvoiceData.getString("account_number__c") != null ? redInvoiceData.getString("account_number__c") : "");//开户行账号
invoiceMap.put("showbuyerbank", redInvoiceData.getBooleanValue("show_bank_account__c"));//是否展示开户行
invoiceMap.put("showdetails", redInvoiceData.getBooleanValue("is_display_invoice_details__c"));//是否展示发票明细名称数量单价单位规格
String isSoftWorks = redInvoiceData.getString("is_contain_soft__c");
Boolean isSoftWorksFlag = false;
switch (isSoftWorks) {
case "v2j71Ak5p":
isSoftWorksFlag = true;
break;
case "YOZj917km":
isSoftWorksFlag = false;
break;
}
invoiceMap.put("issoftworks", isSoftWorksFlag);//是否含软
//是否国网
String isGWStr = redInvoiceData.getString("is_state_grid__c") != null ? redInvoiceData.getString("is_state_grid__c") : "";
Boolean isGW = null;
switch (isGWStr) {
case "ubaL12a0M":
isGW = true;
break;
case "tiVjNIMLU":
isGW = false;
break;
default:
isGW = null;
break;
}
invoiceMap.put("isgw", isGW);//是否国网
//是否设计建筑服务
String isJZStr = redInvoiceData.getString("is_involved_construction__c") != null ? redInvoiceData.getString("is_involved_construction__c") : "";
Boolean isJZ = null;
switch (isJZStr) {
case "option_is_yes__c":
isJZ = true;
break;
case "option_is_no__c":
isJZ = false;
break;
default:
isJZ = null;
break;
}
invoiceMap.put("isjzfw", isJZ);//是否设计建筑服务
//是否跨地市
String isCityStr = redInvoiceData.getString("is_cross_city__c") != null ? redInvoiceData.getString("is_cross_city__c") : "";
Boolean isCity = null;
switch (isCityStr) {
case "option_is_yes__c":
isCity = true;
break;
case "option_is_no__c":
isCity = false;
break;
default:
isCity = null;
break;
}
invoiceMap.put("iskds", isCity);//是否跨地市
invoiceMap.put("jzaddr", redInvoiceData.getString("service_occurrence_locatio__c") != null ? redInvoiceData.getString("service_occurrence_locatio__c") : "");//建筑服务发生地
invoiceMap.put("jzpjname", redInvoiceData.getString("project_name__c") != null ? redInvoiceData.getString("project_name__c") : "");//建筑服务项目名称
invoiceMap.put("softworks_number", redInvoiceData.getString("registration_number__c") != null ? redInvoiceData.getString("registration_number__c") : "");//软著版本编码
invoiceMap.put("blueinvoiceno", redInvoiceData.getString("original_invoice_number__c") != null ? redInvoiceData.getString("original_invoice_number__c") : "");//待冲蓝字发票号码
invoiceMap.put("redreason", redInvoiceData.getString("redemption_reason__c") != null ? redInvoiceData.getString("redemption_reason__c") : "");//冲红原因
//开始查询明细数据
JSONObject getInvoiceDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "red_invoice_application__c", Arrays.asList(redInvoiceId))
), "red_invoice_details__c");
JSONObject invoiceDetailRes = new JSONObject();
try {
invoiceDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getInvoiceDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(invoiceDetailRes.getString("errorDescription")) || invoiceDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("请求失败或数据不存在");
continue;
}
log.info("查询明细数据成功,继续向下执行和封装");
List<Map> invoiceDetailList = new ArrayList<>();
for (Object invoiceDetailObj : invoiceDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject invoiceDetailData = JSON.parseObject(JSON.toJSONString(invoiceDetailObj));
Map invoiceDetailMap = new HashMap();
invoiceDetailMap.put("crmentryid", invoiceDetailData.getString("invoice_application_detail__c"));
invoiceDetailMap.put("crminvoiceentryid", invoiceDetailData.getString("_id"));
invoiceDetailMap.put("goodsname", invoiceDetailData.getString("name__c") != null ? invoiceDetailData.getString("name__c") : "");//商品名称
invoiceDetailMap.put("taxratecodeid_number", invoiceDetailData.getString("product_category__c") != null ? invoiceDetailData.getString("product_category__c") : "");//税收分类编码-商品分类编码
BigDecimal quality = invoiceDetailData.getBigDecimal("red_canceled_quantity__c");
if (quality.compareTo(BigDecimal.ZERO) > 0) {
quality = quality.negate();
}
invoiceDetailMap.put("quality", quality);//数量
invoiceDetailMap.put("taxunitprice", invoiceDetailData.getBigDecimal("tax_inclusive_unit_price__c"));//含税单价
BigDecimal receivablePrice = invoiceDetailData.getBigDecimal("unit_price_taxINCLUDED_tot__c");
if (receivablePrice.compareTo(BigDecimal.ZERO) > 0) {
receivablePrice = receivablePrice.negate();
}
invoiceDetailMap.put("recamount", receivablePrice);//应收金额
invoiceDetailMap.put("taxrateid_number", invoiceDetailData.getString("tax_rate_code__c"));//税率编码
invoiceDetailMap.put("measureunit_number", invoiceDetailData.getString("unit__c") != null ? invoiceDetailData.getString("unit__c") : "");//计量单位
invoiceDetailMap.put("specification", invoiceDetailData.getString("specification_model__c"));//规格型号
invoiceDetailList.add(invoiceDetailMap);
}
invoiceMap.put("entry", invoiceDetailList);
//开始获取token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity invoiceReqEntity = new HttpEntity(invoiceMap, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(invoiceReqEntity)));
String invoiceUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/ar/arbusbill/createInvoice";
JSONObject erpInvoiceRes = new JSONObject();
try {
erpInvoiceRes = restTemplate.postForObject(invoiceUrl, invoiceReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(erpInvoiceRes);
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", redInvoiceId);
backReqMap.put("dataObjectApiName", "custom_object_example1__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "REDKP");
logMap.put("syn_type", "0");
logMap.put("data_name", redInvoiceName);
logMap.put("data_id", redInvoiceId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(invoiceReqEntity));
logMap.put("send_res", JSON.toJSONString(erpInvoiceRes));
logMap.put("tableName", "send_log_invoice");
//判断是否执行成功
if ("0".equals(erpInvoiceRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("field_UB1hE__c", erpInvoiceRes.getJSONObject("data").getString("pkId"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + erpInvoiceRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", erpInvoiceRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

View File

@ -0,0 +1,243 @@
package com.management.controller;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
import com.management.utils.CaffeineCacheUtil;
import lombok.extern.slf4j.Slf4j;
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.util.LinkedHashMap;
/**
* 金蝶APP授权码获取
*
* @param
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping
@Slf4j
public class KDTokenController {
private RestTemplate restTemplate = new RestTemplate();
/**
* 测试入口
*
* @param args
* @return void
* @Author weiloong_zhang
*/
public static void main(String[] args) {
new KDTokenController().getKDAppToken();
//new KDTokenController().getKDAccessToken();
}
/**
* 金蝶APP授权码获取
*
* @return void
* @Author weiloong_zhang
*/
public String getKDAppToken() {
log.info("开始获取金蝶的AppToken");
//开始封装
//接口地址
String appTokenUrl = "https://lxr2.zhydsp.cn:40448/ierp/api/getAppToken.do";
//请求参数
LinkedHashMap appTokenParams = new LinkedHashMap<>();
appTokenParams.put("appId", "erpapi");
appTokenParams.put("appSecret", "ZHYkdERPapi@2025");
appTokenParams.put("tenantid", "zyierp");
appTokenParams.put("accountId", "2095350818281620480");
//开始发起请求
String appTokenRes = "";
try {
appTokenRes = restTemplate.postForObject(appTokenUrl, appTokenParams, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//转换为JSONObject
JSONObject appTokenJSON = JSONObject.parseObject(appTokenRes);
if (!"success".equals(appTokenJSON.getString("state")) || appTokenJSON.getJSONObject("data") == null) {
log.error("获取金蝶的AppToken失败,{}", appTokenRes);
return "";
}
//获取apptoken成功
String appToken = appTokenJSON.getJSONObject("data").getString("app_token");
log.info("获取金蝶的AppToken成功,{}", appToken);
return appToken;
}
/**
* 金蝶access_token获取
*
* @return java.lang.String
* @Author weiloong_zhang
*/
public String getKDAccessToken() {
log.info("开始获取金蝶accessToken");
//用来接收token的字符串
String accessToken = "";
//判断咖啡因中是否存在accessToken
if (CaffeineCacheUtil.get("kd_access_token") != null && !"".equals(CaffeineCacheUtil.get("kd_access_token"))) {
log.info("获取到缓存中的accessToken,{}", accessToken);
accessToken = CaffeineCacheUtil.get("kd_access_token").toString();
return accessToken;
}
//不存在将执行获取accessToken的逻辑
//开始封装参数
//URL
String accessTokenUrl = "https://lxr2.zhydsp.cn:40448/ierp/api/login.do";
//请求参数
LinkedHashMap accessTokenParams = new LinkedHashMap<>();
accessTokenParams.put("user", "19819780536");
accessTokenParams.put("usertype", "Mobile");
accessTokenParams.put("apptoken", getKDAppToken());
accessTokenParams.put("tenantid", "zyierp");
accessTokenParams.put("accountId", "2095350818281620480");
accessTokenParams.put("language", "zh_CN");
//开始向金蝶发起请求
String accessTokenRes = "";
try {
accessTokenRes = restTemplate.postForObject(accessTokenUrl, accessTokenParams, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
JSONObject accessTokenJSON = JSONObject.parseObject(accessTokenRes);
if (!"success".equals(accessTokenJSON.getString("state")) || accessTokenJSON.getJSONObject("data") == null) {
log.error("获取金蝶的accessToken失败,{}", accessTokenRes);
return "";
}
log.info("获取金蝶的accessToken成功,{}", accessTokenJSON.getJSONObject("data").getString("access_token"));
accessToken = accessTokenJSON.getJSONObject("data").getString("access_token");
//存放到咖啡因之中
CaffeineCacheUtil.put("kd_access_token", accessToken);
return accessToken;
}
/**
* 金蝶测试系统App授权码获取
* @return java.lang.String
* @Author weiloong_zhang
*/
public String getKDAppTokenTest() {
log.info("开始获取金蝶的AppToken");
//开始封装
//接口地址
String appTokenUrl = ERPURLConstant.ERP_URL + "/ierp/api/getAppToken.do";
//请求参数
LinkedHashMap appTokenParams = new LinkedHashMap<>();
appTokenParams.put("appId", "FXXKCRM");
appTokenParams.put("appSecret", "FXXKCRM20251234a!");
appTokenParams.put("tenantid", "zyierp");
appTokenParams.put("accountId", ERPURLConstant.ACCOUNT_ID);
//开始发起请求
String appTokenRes = "";
try {
appTokenRes = restTemplate.postForObject(appTokenUrl, appTokenParams, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//转换为JSONObject
JSONObject appTokenJSON = JSONObject.parseObject(appTokenRes);
if (!"success".equals(appTokenJSON.getString("state")) || appTokenJSON.getJSONObject("data") == null) {
log.error("获取金蝶的AppToken失败,{}", appTokenRes);
return "";
}
//获取apptoken成功
String appToken = appTokenJSON.getJSONObject("data").getString("app_token");
log.info("获取金蝶的AppToken成功,{}", appToken);
return appToken;
}
/**
* 金蝶a测试access_token获取
*
* @return java.lang.String
* @Author weiloong_zhang
*/
public String getKDAccessTokenTest() {
log.info("开始获取金蝶accessToken");
//用来接收token的字符串
String accessToken = "";
//判断咖啡因中是否存在accessToken
if (CaffeineCacheUtil.get("kd_access_token") != null && !"".equals(CaffeineCacheUtil.get("kd_access_token"))) {
log.info("获取到缓存中的accessToken,{}", accessToken);
accessToken = CaffeineCacheUtil.get("kd_access_token").toString();
return accessToken;
}
//不存在将执行获取accessToken的逻辑
//开始封装参数
//URL
String accessTokenUrl = ERPURLConstant.ERP_URL + "/ierp/api/login.do";
//请求参数
LinkedHashMap accessTokenParams = new LinkedHashMap<>();
accessTokenParams.put("user", "19819780536");
accessTokenParams.put("usertype", "Mobile");
accessTokenParams.put("apptoken", getKDAppTokenTest());
accessTokenParams.put("tenantid", "zyierp");
accessTokenParams.put("accountId", ERPURLConstant.ACCOUNT_ID);
accessTokenParams.put("language", "zh_CN");
//开始向金蝶发起请求
String accessTokenRes = "";
try {
accessTokenRes = restTemplate.postForObject(accessTokenUrl, accessTokenParams, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
JSONObject accessTokenJSON = JSONObject.parseObject(accessTokenRes);
if (!"success".equals(accessTokenJSON.getString("state")) || accessTokenJSON.getJSONObject("data") == null) {
log.error("获取金蝶的accessToken失败,{}", accessTokenRes);
return "";
}
log.info("获取金蝶的accessToken成功,{}", accessTokenJSON.getJSONObject("data").getString("access_token"));
accessToken = accessTokenJSON.getJSONObject("data").getString("access_token");
//存放到咖啡因之中
CaffeineCacheUtil.put("kd_access_token", accessToken);
return accessToken;
}
}

View File

@ -0,0 +1,624 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
import com.management.constant.URLConstant;
import com.management.entity.Filter;
import com.management.utils.CrmRequestUtil;
import com.management.utils.KingDeeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
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.util.*;
/**
* 预签合同
*
* @param
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping("/api/pre/contract")
@Slf4j
public class PreContractController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new PreContractController().syncContract();
//new PreContractController().bgPreContract();
}
/**
* 智洋同步预签合同
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_pre_contract")
public void syncContract() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
//new Filter("EQ", "name", Arrays.asList("YQ2505220005")),
new Filter("EQ", "life_status", Arrays.asList("normal"))
), "pre_signed_contract__c");
JSONObject preContractRes = new JSONObject();
try {
preContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, preContractReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("查询结果为:" + preContractRes);
//判断查询是否成功
if (!"success".equals(preContractRes.getString("errorDescription")) || preContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或者没有符合条件的单据");
return;
}
//数据存在
for (Object preContractObj : preContractRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject preContractData = JSON.parseObject(JSON.toJSONString(preContractObj));
System.out.println("当前正在处理的数据为:" + preContractData);
String preContractId = preContractData.getString("_id");
//String createTime = preContractData.getString("create_time");
String createTime = preContractData.getString("last_modified_time");
//根据唯一id和创建时间查询是否已经执行当前数据
JSONObject preContractIsExist = new JSONObject();
try {
preContractIsExist = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=YQHT&dataId=" + preContractId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(preContractIsExist);
if (!preContractIsExist.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("没有集成过,将继续向下执行");
long documentDate = preContractData.getLong("document_date__c");
Date date = new Date(documentDate);
//开始封装传输至ERP的请求
Map erpContractReq = new HashMap<>();
erpContractReq.put("billno", preContractData.getString("name"));//预签合同编号
erpContractReq.put("crmid", preContractData.getString("_id"));//CRM唯一性编码
//erpContractReq.put("project_number", preContractData.getString("opportunity_id__c"));//项目号
erpContractReq.put("project_number", "SJ20250424-0033");//项目号
erpContractReq.put("billtype_number", "conm_salcontract_BT_YQ");//单据类型
erpContractReq.put("billname", preContractData.getString("project_name__c") != null ? preContractData.getString("project_name__c") : "预签合同");//合同名称
erpContractReq.put("type_number", "XSHT-YQ01");//合同类型
erpContractReq.put("contparties_number", preContractData.getString("our_company_name__c") != null ? preContractData.getString("our_company_name__c") : "");//合同主体
erpContractReq.put("createorg_number", preContractData.getString("our_company_name__c") != null ? preContractData.getString("our_company_name__c") : "");//销售组织编码
erpContractReq.put("org_number", preContractData.getString("our_company_name__c") != null ? preContractData.getString("our_company_name__c") : "");//销售组织编码
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
erpContractReq.put("biztime", date);//签订日期,单据日期
erpContractReq.put("biztimebegin", date);//起始日期
erpContractReq.put("biztimeend", date);//截止日期
erpContractReq.put("party1st", preContractData.getString("contract_unit_name__c__r"));//甲方
erpContractReq.put("party2nd", preContractData.getString("our_company_name__c"));//乙方
erpContractReq.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
erpContractReq.put("isentrysumamt", false);//isentrysumamt
//部门编码
String deptCode = "";
List deptIdList = preContractData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
//erpContractReq.put("dept", "ZHY");//归属部门
erpContractReq.put("dept", deptCode);//归属部门
//erpContractReq.put("dept_number", "004");//归属部门
erpContractReq.put("dept_number", deptCode);//归属部门
//获取负责人编码
String ownerCode = "";
List ownerIdList = preContractData.getJSONArray("owner");
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
//erpContractReq.put("operator", "ID-000016");//todo 负责人
erpContractReq.put("operator", ownerCode);//负责人
//合同单位
String customerId = preContractData.getString("contract_unit_name__c");
//根据客户唯一id查询客户名称
JSONObject customerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, customerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("客户名称查询失败或者不存在,直接跳过更新");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
erpContractReq.put("reccustomer_number", customerData.getString("account_no"));//收获客户单位名称
//erpContractReq.put("customer_number", "Cus-000007");//todo 合同单位名称
erpContractReq.put("settlecustomer_number", preContractData.getString("billing_customer_code__c") != null ? preContractData.getString("billing_customer_code__c") : "");//结算客户
erpContractReq.put("payingcustomer_number", preContractData.getString("payment_customer_code__c") != null ? preContractData.getString("payment_customer_code__c") : "");//付款客户
//获取产品线
erpContractReq.put("productline_number", preContractData.getString("product_line__c"));//产品线
//获取具体安装方式
erpContractReq.put("installationmethod", preContractData.getString("installation_method__c"));//安装方式
//行业类型
erpContractReq.put("industrytype_number", preContractData.getString("industry_type__c"));//行业类型
erpContractReq.put("province", preContractData.getString("field_t3fgo__c__r"));//
erpContractReq.put("city", preContractData.getString("field_ngwth__c__r"));//
erpContractReq.put("county", preContractData.getString("field_K5p2C__c__r"));//
erpContractReq.put("deviceqty", preContractData.getBigDecimal("device_quantity__c") != null ? preContractData.getBigDecimal("device_quantity__c") : 0);//设备数量
erpContractReq.put("totalallamount", preContractData.getBigDecimal("pre_signed_amount__c") != null ? preContractData.getBigDecimal("pre_signed_amount__c") : 0);//预签金额
erpContractReq.put("warranty", preContractData.getBigDecimal("warranty_period_months__c") != null ? preContractData.getBigDecimal("warranty_period_months__c") : 0);//质保期
Map erpContractData = new HashMap<>();
erpContractData.put("data", Arrays.asList(erpContractReq));//请求体
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity contractReqEntity = new HttpEntity(erpContractData, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
//开始向金蝶发起请求
String contractUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/conm/conm_salcontract/savecontract";
JSONObject contractRes = new JSONObject();
try {
contractRes = restTemplate.postForObject(contractUrl, contractReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", preContractId);
backReqMap.put("dataObjectApiName", "pre_signed_contract__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "YQHT");
logMap.put("syn_type", "0");
logMap.put("data_name", preContractData.getString("name"));
logMap.put("data_id", preContractId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(contractReqEntity));
logMap.put("send_res", JSON.toJSONString(contractRes));
logMap.put("tableName", "send_log_htxx");
//判断是否执行成功
if ("0".equals(contractRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
//开始审核
KingDeeUtils kingDeeUtils = new KingDeeUtils();
kingDeeUtils.audit(contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + contractRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", contractRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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("/bg_pre_contract")
public void bgPreContract() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
JSONObject preContractBGReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "name", Arrays.asList("YQHTBG20250518-0002"))
), "pre_signed_contract_amendm__c");
JSONObject preContractBGRes = new JSONObject();
try {
preContractBGRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, preContractBGReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("预签合同变更查询结果为:" + preContractBGRes);
if (!"success".equals(preContractBGRes.getString("errorDescription")) || preContractBGRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("不存在要变更的预签合同");
return;
}
for (Object preContractBGObj : preContractBGRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject preContractBGData = JSON.parseObject(JSON.toJSONString(preContractBGObj));
System.out.println("当前正在处理的单据为:" + preContractBGData);
//开始截取关键数据
//唯一ID
String preContractId = preContractBGData.getString("_id");
//单据名称
String preContractName = preContractBGData.getString("name");
//创建时间
String createTime = preContractBGData.getString("create_time");
//开始查询是否已经集成过该单据
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=YQHTBG&dataId=" + preContractId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
//开始封装数据
Map preContractBGMap = new HashMap<>();
//开始封装传输至ERP的请求
//preContractBGMap.put("billno", preContractBGData.getString("source_pre_signed_contract__c__r"));//原预签合同编号
preContractBGMap.put("crmid", preContractBGData.getString("source_pre_signed_contract__c"));//CRM唯一性编码
//开始查询项目号
String projectCode = "";
if (preContractBGData.getString("business_opportunity__c") != null) {
projectCode = preContractBGData.getString("business_opportunity__c");
}
JSONObject projectReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(projectCode))
), "NewOpportunityObj");
JSONObject projectRes = new JSONObject();
try {
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, projectReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("项目号查询结果为:" + projectRes);
if (!"success".equals(projectRes.getString("errorDescription")) || projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("商机不存在,将不再向下执行");
continue;
}
projectCode = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("opportunity_id__c");
//preContractBGMap.put("project_number", projectCode);//项目号
preContractBGMap.put("project_number", "SJ20250424-0033");//项目号
preContractBGMap.put("billtype_number", "conm_salcontract_BT_YQ");//单据类型
preContractBGMap.put("billname", preContractBGData.getString("contract_name__c") != null ? preContractBGData.getString("contract_name__c") : "测试");//todo 合同名称
preContractBGMap.put("type_number", "XSHT-YQ01");//合同类型
preContractBGMap.put("contparties_number", "BU-0002");//合同主体
preContractBGMap.put("createorg_number", "zyierp");//销售组织编码
preContractBGMap.put("org_number", "zyierp");//销售组织编码
preContractBGMap.put("currency_number", "CNY");//本位币.货币代码
preContractBGMap.put("settlecurrency_number", "CNY");//结算币别.货币代码
//日期格式化为Date
long documentDate = preContractBGData.getLong("document_date__c");
preContractBGMap.put("biztime", new Date(documentDate));//签订日期,单据日期
preContractBGMap.put("biztimebegin", new Date(documentDate));//起始日期
preContractBGMap.put("biztimeend", new Date(documentDate));//截止日期
preContractBGMap.put("party1st", preContractBGData.getString("contract_unit_name__c__r"));//甲方
preContractBGMap.put("party2nd", preContractBGData.getString("our_company_name__c"));//乙方
preContractBGMap.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
//部门编码
String deptCode = "";
List deptIdList = preContractBGData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
preContractBGMap.put("dept", deptCode);//归属部门
preContractBGMap.put("dept_number", "004");//归属部门
//获取负责人编码
String ownerCode = "";
List ownerIdList = preContractBGData.getJSONArray("owner");
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
preContractBGMap.put("operator", "ID-000016");//todo 负责人
preContractBGMap.put("user_operatornumber", "ID-000016");//todo 负责人
//合同单位
String customerId = preContractBGData.getString("contract_unit_name__c");
//根据客户唯一id查询客户名称
JSONObject customerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, customerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("客户名称查询失败或者不存在,直接跳过更新");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
//preContractBGMap.put("customer_number", customerData.getString("account_no"));//合同单位名称
preContractBGMap.put("customer_number", "Cus-000007");//todo 合同单位名称
//获取产品线
preContractBGMap.put("productline_number", preContractBGData.getString("product_line__c"));//产品线
//获取具体安装方式
preContractBGMap.put("installationmethod", preContractBGData.getString("installation_method__c"));//安装方式
//行业类型
preContractBGMap.put("industrytype_number", preContractBGData.getString("industry_type__c"));//行业类型
preContractBGMap.put("deviceqty", preContractBGData.getBigDecimal("device_quantity__c") != null ? preContractBGData.getBigDecimal("device_quantity__c") : 0);//设备数量
preContractBGMap.put("totalallamount", preContractBGData.getBigDecimal("pre_signed_amount__c") != null ? preContractBGData.getBigDecimal("pre_signed_amount__c") : 0);//预签金额
preContractBGMap.put("warranty", preContractBGData.getBigDecimal("warranty_period_months__c") != null ? preContractBGData.getBigDecimal("warranty_period_months__c") : 0);//质保期
Map erpContractBGDataReq = new HashMap<>();
erpContractBGDataReq.put("data", Arrays.asList(preContractBGMap));//请求体
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity contractReqEntity = new HttpEntity(erpContractBGDataReq, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
//开始向金蝶发起请求
String contractUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/conm/salcontract/change";
String erpPreContractBGRes = "";
try {
erpPreContractBGRes = restTemplate.postForObject(contractUrl, contractReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
JSONObject erpPreContractBGResJson = JSON.parseObject(erpPreContractBGRes);
System.out.println("金蝶预签结果为:" + erpPreContractBGResJson);
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", preContractId);
backReqMap.put("dataObjectApiName", "pre_signed_contract_amendm__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "YQHTBG");
logMap.put("syn_type", "0");
logMap.put("data_name", preContractName);
logMap.put("data_id", preContractId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(contractReqEntity));
logMap.put("send_res", JSON.toJSONString(erpPreContractBGResJson));
logMap.put("tableName", "send_log_htxx");
//判断是否执行成功
if ("0".equals(erpPreContractBGResJson.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", erpPreContractBGResJson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
//审核
KingDeeUtils kingDeeUtils = new KingDeeUtils();
kingDeeUtils.audit(erpPreContractBGResJson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + erpPreContractBGResJson.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", erpPreContractBGResJson.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

View File

@ -0,0 +1,297 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
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.http.MediaType;
import org.springframework.util.MultiValueMap;
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.util.*;
@RestController
@RequestMapping("/api/quality/feedback")
@Slf4j
public class QualityBackController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new QualityBackController().qualityFeedBack();
}
/**
* 问题质量反馈单更新
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/quality_back")
public void qualityFeedBack() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步新建质量反馈单");
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getQualityBack = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("EQ", "life_status", Arrays.asList("normal")),
//new Filter("EQ", "name", Arrays.asList("ZLXXFK202505270002")),
new Filter("GT", "create_time", Arrays.asList("1748923200000"))
), "quality_feedback_form__c");
JSONObject qualityBack = new JSONObject();
try {
qualityBack = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getQualityBack, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(qualityBack.getString("errorDescription")) || qualityBack.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("质量反馈单请求失败,或者不存在符合条件的数据");
return;
}
log.info("质量反馈单请求成功,继续向下执行");
for (Object qualityBackObj : qualityBack.getJSONObject("data").getJSONArray("dataList")) {
JSONObject qualityBackData = JSON.parseObject(JSON.toJSONString(qualityBackObj));
System.out.println("当前正在处理的数据为:" + qualityBackData);
//开始截取关键数据
//唯一性id
String qualityId = qualityBackData.getString("_id");
//反馈单单号
String qualityName = qualityBackData.getString("name");
//反馈单创建时间
//String createTime = qualityBackData.getString("create_time");
String createTime = qualityBackData.getString("last_modified_time");
//开始查询当前单据是否已经集成过
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_quality&log_type=Quality&dataId=" + qualityId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
//开始封装数据
Map qualityReqMap = new HashMap<>();
qualityReqMap.put("billno", qualityName);//单据编号
qualityReqMap.put("crmid", qualityId);//CRM唯一id
//获取负责人编码
String ownerCode = "";
List ownerIdList = qualityBackData.getJSONArray("owner");
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
//qualityReqMap.put("provider_number", "ZHY10542");//todo 反馈人负责人编号
qualityReqMap.put("provider_number", ownerCode);//todo 反馈人负责人编号
//部门编码
String deptCode = "";
List deptIdList = qualityBackData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
//qualityReqMap.put("dept_number", "ZHY");//归属部门
qualityReqMap.put("dept_number", deptCode);//归属部门
//qualityReqMap.put("org_number", "ZHY");//todo 组织编码
qualityReqMap.put("org_number", qualityBackData.getString("erp_organization__c") != null ? qualityBackData.getString("erp_organization__c") : "");//todo 组织编码
qualityReqMap.put("contractno", qualityBackData.getString("contract_number__c__r") != null ? qualityBackData.getString("contract_number__c__r") : "");//销售合同号
qualityReqMap.put("productionbatch", qualityBackData.getString("production_batch__c") != null ? qualityBackData.getString("production_batch__c") : "");//生产批次
long askedTime = qualityBackData.getLong("required_processing_time__c") != null ? qualityBackData.getLong("required_processing_time__c") : 0;
qualityReqMap.put("handletime", new Date(askedTime));//要求处理时间
long installTime = qualityBackData.getLong("installation_time__c") != null ? qualityBackData.getLong("installation_time__c") : 0;
qualityReqMap.put("installtime", new Date(installTime));//项目安装时间
long happenTime = qualityBackData.getLong("event_occurrence_time__c") != null ? qualityBackData.getLong("event_occurrence_time__c") : 0;
qualityReqMap.put("occurrencetime", new Date(happenTime));//事件发生时间
//产品型号
qualityReqMap.put("productmodel", qualityBackData.getString("product_model__c") != null ? qualityBackData.getString("product_model__c") : "");//产品型号
qualityReqMap.put("problemdesc", qualityBackData.getString("on_site_issue_description__c") != null ? qualityBackData.getString("on_site_issue_description__c") : "");//现场问题描述
Map erpQualityData = new HashMap<>();
erpQualityData.put("data", Arrays.asList(qualityReqMap));//请求体
//开始获取token
String token = new KDTokenController().getKDAccessTokenTest();
if (token == null || token.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", token);
headers.set("Idempotency-Key", uuid);
HttpEntity qualityBackReqEntity = new HttpEntity(erpQualityData, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(qualityBackReqEntity)));
String qualityBackUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/qcqi/f9w5_problemfeedback/save";
String qualityBackRes = "";
try {
qualityBackRes = restTemplate.postForObject(qualityBackUrl, qualityBackReqEntity, String.class);
} catch (RestClientException e) {
e.printStackTrace();
}
JSONObject qualityBackResJson = JSON.parseObject(qualityBackRes);
System.out.println("质量反馈结果为:" + qualityBackResJson);
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", qualityId);
backReqMap.put("dataObjectApiName", "quality_feedback_form__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "Quality");
logMap.put("syn_type", "0");
logMap.put("data_name", qualityName);
logMap.put("data_id", qualityId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(erpQualityData));
logMap.put("send_res", JSON.toJSONString(qualityBackResJson));
logMap.put("tableName", "send_log_quality");
//判断是否执行成功
if ("0".equals(qualityBackResJson.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", qualityBackResJson.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + qualityBackResJson.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", qualityBackResJson.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
//判断是否存在附件
if (qualityBackData.getJSONArray("attachment__c") == null || qualityBackData.getJSONArray("attachment__c").isEmpty()) {
log.info("该质量反馈单不存在附件,将不再向下执行。");
continue;
}
//附件存在将开始执行附件上传
List attachmentList = qualityBackData.getJSONArray("attachment__c");
MultiValueMap<String, Object> body = crmRequestUtil.proxyUploadFileToTarget(attachmentList, qualityId);
//开始封装请求实体
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
httpHeaders.set("accessToken", token);
HttpEntity entity = new HttpEntity(body, httpHeaders);
//开始发起传输
JSONObject fileRes = new JSONObject();
try {
fileRes = restTemplate.postForObject(ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/qcqi/feedback/uploadFile", entity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("附件上传结果为:" + fileRes);
}
}
}

View File

@ -0,0 +1,652 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
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.http.MediaType;
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.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
@RestController
@RequestMapping("/api/reimbursement")
@Slf4j
public class ReimbursementController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new ReimbursementController().syncReimbursement();
//new ReimbursementController().syncPublicExpenses();
}
/**
* 报销查询同步 todo 需要完善
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/reimburse")
public void syncReimbursement() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步银行信息");
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(1);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
String nowStr = now.format(formatter);
//开始查询f费用报销单
Map data = new HashMap<>();
data.put("startTime", twoDaysAgoStr);
data.put("endTime", nowStr);
Map expensesMap = new HashMap<>();
expensesMap.put("data", data);
expensesMap.put("pageNo", 1);
expensesMap.put("pageSize", 1999);
//开始获取金蝶token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity expensesEntity = new HttpEntity(expensesMap, headers);
String expensesUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/em/er_dailyreimbursebill/dailyreimbursebillQuery";
JSONObject expensesRes = new JSONObject();
try {
expensesRes = restTemplate.postForObject(expensesUrl, expensesEntity, JSONObject.class);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(expensesRes);
//开始判断是否存在符合条件的数据
if (!"0".equals(expensesRes.getString("errorCode")) || expensesRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("查询失败或者没有符合条件的单据");
return;
}
log.info("数据存在,将继续向下执行");
for (Object expensesObj : expensesRes.getJSONObject("data").getJSONArray("rows")) {
JSONObject expensesData = JSON.parseObject(JSON.toJSONString(expensesObj));
System.out.println("当前正在处理的报销单数据为:" + expensesData);
//开始截取关键数据
//ERPID
String expensesId = expensesData.getString("erpid");
//String expensesId = "6467554454212545";
String expensesCode = expensesData.getString("billno");//编码
String modifyTime = expensesData.getString("modifytime");//最后修改时间
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_fybx&log_type=FY&dataId=" + expensesId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前报销单存在日志,将不再向下执行");
continue;
}
log.info("不存在日志,继续向下执行");
//开始封装请求
Map expensesMapReq = new HashMap<>();
expensesMapReq.put("erp_document_number__c", expensesCode);//单据编号
expensesMapReq.put("erp_id__c", expensesId);//单据ERPID
expensesMapReq.put("record_type", "record_kYs9j__c");//业务类型
expensesMapReq.put("dataObjectApiName", "ExpenseClaimFormObj");//对象名称
//开始获取时间数据并转换为字符串
String bizDate = expensesData.getString("bizdate");
// 定义时间格式
DateTimeFormatter formatterB = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 解析字符串为 LocalDateTime
LocalDateTime localDateTime = LocalDateTime.parse(bizDate, formatterB);
// 转换为时间戳毫秒
long timestamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
expensesMapReq.put("application_date", timestamp);//申请日期
//获取负责人信息
String ownerCode = "ID-000016";//todo 负责人编码
JSONObject getOwner = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "field_T1xid__c", Arrays.asList(ownerCode))
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getOwner, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(ownerRes.getString("errorDescription")) || ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("负责人不存在或者请求失败");
continue;
}
System.out.println("负责人数据为:" + ownerRes);
//开始截取负责人user_id
String ownerUserId = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("user_id");
expensesMapReq.put("owner", Arrays.asList(ownerUserId));
expensesMapReq.put("applicant", Arrays.asList(ownerUserId));
//todo 费用承担公司
String costCompany = expensesData.getString("costcompany_number");
//事由
String description = expensesData.getString("description") != null ? expensesData.getString("description") : "";
expensesMapReq.put("reason_for_event__c", description);//事由
//开始判断CRM里面是否已经存在该单据
Boolean isExist = false;
JSONObject getExpenses = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "erp_id__c", Arrays.asList(expensesId)),
new Filter("EQ", "erp_document_number__c", Arrays.asList(expensesCode))
), "ExpenseClaimFormObj");
JSONObject expensesCRMRes = new JSONObject();
try {
expensesCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getExpenses, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(expensesCRMRes.getString("errorDescription")) && !expensesCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("该报销单已经存在");
isExist = true;
expensesMapReq.put("_id", expensesCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
}
//开始封装明细数据
List expensesDetails = new ArrayList<>();
for (Object expensesDetailObj : expensesData.getJSONArray("expenseentryentity")) {
JSONObject expensesDetailData = JSON.parseObject(JSON.toJSONString(expensesDetailObj));
System.out.println("当前正在处理的报销单明细数据为:" + expensesDetailData);
//开始封装明细数据
Map expensesDetailMap = new HashMap<>();
expensesDetailMap.put("record_type", "default__c");
String costProject = expensesDetailData.getString("std_project_number");
//项目号
if (costProject.contains("SJ")) {
//商机编号
JSONObject getBusiness = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "opportunity_id__c", Arrays.asList(costProject))
), "NewOpportunityObj");
JSONObject businessRes = new JSONObject();
try {
businessRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getBusiness, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(businessRes.getString("errorDescription")) && !businessRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject businessData = businessRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
expensesDetailMap.put("", businessData.getString("_id"));
}
} else if (costProject.contains("XM")) {
//项目编号
JSONObject getProject = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "project_no__c", Arrays.asList(costProject))
), "ProjectObj");
JSONObject projectRes = new JSONObject();
try {
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProject, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(projectRes.getString("errorDescription")) && !projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject projectData = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
expensesDetailMap.put("project_id", projectData.getString("_id"));
}
}
//todo 成本中心
String costCenter = expensesDetailData.getString("expensesDetailData") != null ? expensesDetailData.getString("expensesDetailData") : "";
expensesDetailMap.put("amount", expensesDetailData.getBigDecimal("expenseamount"));//金额价税合计
expensesDetailMap.put("erp_row_id__c", expensesDetailData.getString("entryId"));//ERP行ID
//开始根据ERP行ID判断是否已经集成过该单据
JSONObject getExpensesDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(expensesDetailData.getString("entryId")))
), "ExpenseClaimFormDetailObj");
JSONObject expensesDetailCRMRes = new JSONObject();
try {
expensesDetailCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getExpensesDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(expensesDetailCRMRes.getString("errorDescription")) && !expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("该报销单明细已经存在");
expensesDetailMap.put("_id", expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
}
expensesDetails.add(expensesDetailMap);
}
Map detailsMap = new HashMap<>();
detailsMap.put("ExpenseClaimFormDetailObj", expensesDetails);
JSONObject expensesReq = crmRequestUtil.crmWithDetail(expensesMapReq, detailsMap);
System.out.println("费用报销请求结果为:" + expensesReq);
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "FY");
logMap.put("data_name", expensesCode);
logMap.put("data_id", expensesId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(expensesReq));
logMap.put("tableName", "send_log_fybx");
JSONObject expensesCRMReq = new JSONObject();
if (isExist) {
//已存在该单据将进行更新
logMap.put("syn_type", "1");
try {
expensesCRMReq = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, expensesReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("费用报销更新请求结果为:" + expensesCRMReq);
} else {
logMap.put("syn_type", "0");
try {
expensesCRMReq = restTemplate.postForObject(URLConstant.CREATE_CRM_CUSTOMER_MAIN, expensesReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("费用报销创建请求结果为:" + expensesCRMReq);
}
if ("success".equals(expensesCRMReq.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + expensesCRMReq.getString("errorMessage"));
}
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);
}
}
/**
* 对公报销 todo 待完善
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping
public void syncPublicExpenses() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始同步对公报销信息");
//获取当前时间
LocalDateTime now = LocalDateTime.now();
log.info("当前时间:{}", now);
//获取两天前的时间
LocalDateTime twoDaysAgo = now.minusDays(5);
//将时间转换样式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String twoDaysAgoStr = twoDaysAgo.format(formatter);
String nowStr = now.format(formatter);
//开始查询f费用报销单
Map data = new HashMap<>();
data.put("startTime", twoDaysAgoStr);
data.put("endTime", nowStr);
Map expensesMap = new HashMap<>();
expensesMap.put("data", data);
expensesMap.put("pageNo", 1);
expensesMap.put("pageSize", 1999);
//开始获取金蝶token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity expensesEntity = new HttpEntity(expensesMap, headers);
String expensesUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/em/er_publicreimbursebill/publicreimbursebillQuery";
JSONObject expensesRes = new JSONObject();
try {
expensesRes = restTemplate.postForObject(expensesUrl, expensesEntity, JSONObject.class);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(expensesRes);
//判断是否成功或者数据是否存在
if (!"0".equals(expensesRes.getString("errorCode")) || expensesRes.getJSONObject("data").getJSONArray("rows").isEmpty()) {
log.info("查询失败或者没有符合条件的单据");
return;
}
for (Object expensesObj : expensesRes.getJSONObject("data").getJSONArray("rows")) {
JSONObject expensesData = JSON.parseObject(JSON.toJSONString(expensesObj));
System.out.println("当前正在处理数据为:" + expensesData);
//开始截取关键数据
//ERPID
String erpId = expensesData.getString("erpid");
//单据名称
String erpNo = expensesData.getString("billno");
//最后修改时间
String modifyTime = expensesData.getString("modifytime");
//开始判断是否已经集成过该单据
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_fybx&log_type=FYDG&dataId=" + erpId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
//开始封装请求参数
Map expensesMainReq = new HashMap();
expensesMainReq.put("erp_document_number__c", erpNo);//ERP单据编码
expensesMainReq.put("erp_id__c", erpId);//ERP单据ID
expensesMainReq.put("record_type", "record_Lu2Cc__c");
expensesMainReq.put("dataObjectApiName", "ExpenseClaimFormObj");//对象名称
expensesMainReq.put("reason_for_event__c", expensesData.getString("description") != null ? expensesData.getString("description") : "");//事由
//开始获取时间数据并转换为字符串
String bizDate = expensesData.getString("bizdate");
// 定义时间格式
DateTimeFormatter formatterB = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 解析字符串为 LocalDateTime
LocalDateTime localDateTime = LocalDateTime.parse(bizDate, formatterB);
// 转换为时间戳毫秒
long timestamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
expensesMainReq.put("application_date", timestamp);//申请日期
//获取负责人信息
String ownerCode = "ID-000016";//todo 负责人编码
JSONObject getOwner = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "field_T1xid__c", Arrays.asList(ownerCode))
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getOwner, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(ownerRes.getString("errorDescription")) || ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("负责人不存在或者请求失败");
continue;
}
System.out.println("负责人数据为:" + ownerRes);
//开始截取负责人user_id
String ownerUserId = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("user_id");
expensesMainReq.put("owner", Arrays.asList(ownerUserId));
expensesMainReq.put("applicant", Arrays.asList(ownerUserId));
//开始判断CRM里面是否已经存在该单据
Boolean isExist = false;
JSONObject getExpenses = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "erp_id__c", Arrays.asList(erpId)),
new Filter("EQ", "erp_document_number__c", Arrays.asList(erpNo))
), "ExpenseClaimFormObj");
JSONObject expensesCRMRes = new JSONObject();
try {
expensesCRMRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, getExpenses, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(expensesCRMRes.getString("errorDescription")) && !expensesCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("该报销单已经存在");
isExist = true;
expensesMainReq.put("_id", expensesCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
}
List expensesDetailReq = new ArrayList();
//开始封装明细数据
for (Object expenseDetailObj : expensesData.getJSONArray("expenseentryentity")) {
JSONObject expenseDetailData = JSON.parseObject(JSON.toJSONString(expenseDetailObj));
System.out.println("当前正在处理明细数据为:" + expenseDetailData);
//开始封装明细数据
Map expensesDetail = new HashMap();
expensesDetail.put("record_type", "record_Eex1M__c");//对公报销
String projectCode = expenseDetailData.getString("std_project_number") != null ? expenseDetailData.getString("std_project_number") : "";
//开始判断项目来源
if (projectCode.contains("SJ")) {
//商机编号
JSONObject getBusiness = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "opportunity_id__c", Arrays.asList(projectCode))
), "NewOpportunityObj");
JSONObject businessRes = new JSONObject();
try {
businessRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getBusiness, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(businessRes.getString("errorDescription")) && !businessRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject businessData = businessRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
expensesDetail.put("", businessData.getString("_id"));
}
} else if (projectCode.contains("XM")) {
//项目编号
JSONObject getProject = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "project_no__c", Arrays.asList(projectCode))
), "ProjectObj");
JSONObject projectRes = new JSONObject();
try {
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProject, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(projectRes.getString("errorDescription")) && !projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject projectData = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
expensesDetail.put("project_id", projectData.getString("_id"));
}
}
expensesDetail.put("amount", expenseDetailData.getBigDecimal("expenseamount"));//金额价税合计
expensesDetail.put("erp_row_id__c", expenseDetailData.getString("entryId"));//ERP行ID
//开始根据ERP行ID判断是否已经集成过该单据
JSONObject getExpensesDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(expenseDetailData.getString("entryId")))
), "ExpenseClaimFormDetailObj");
JSONObject expensesDetailCRMRes = new JSONObject();
try {
expensesDetailCRMRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getExpensesDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(expensesDetailCRMRes.getString("errorDescription")) && !expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("该报销单明细已经存在");
expensesDetail.put("_id", expensesDetailCRMRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("_id"));
}
expensesDetailReq.add(expensesDetail);
}
Map detailsMap = new HashMap<>();
detailsMap.put("ExpenseClaimFormDetailObj", expensesDetailReq);
JSONObject expensesReq = crmRequestUtil.crmWithDetail(expensesMainReq, detailsMap);
System.out.println("费用报销请求结果为:" + expensesReq);
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "FYDG");
logMap.put("data_name", erpNo);
logMap.put("data_id", erpId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(expensesReq));
logMap.put("tableName", "send_log_fybx");
JSONObject expensesCRMReq = new JSONObject();
if (isExist) {
//已存在该单据将进行更新
logMap.put("syn_type", "1");
try {
expensesCRMReq = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, expensesReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("费用报销更新请求结果为:" + expensesCRMReq);
} else {
logMap.put("syn_type", "0");
try {
expensesCRMReq = restTemplate.postForObject(URLConstant.CREATE_CRM_CUSTOMER_MAIN, expensesReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("费用报销创建请求结果为:" + expensesCRMReq);
}
if ("success".equals(expensesCRMReq.getString("errorDescription"))) {
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
} else {
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败" + expensesCRMReq.getString("errorMessage"));
}
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);
}
}
}

View File

@ -0,0 +1,242 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
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.http.MediaType;
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.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/api/tendering")
@Slf4j
public class TenderingController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new TenderingController().syncTendering();
}
/**
* 投标费用
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/tendering")
public void syncTendering() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getTendering = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("EQ", "life_status", Arrays.asList("normal")),
//new Filter("EQ", "name", Arrays.asList("BSGM250509")),
new Filter("GT", "create_time", Arrays.asList("1748923200000"))
), "bid_application__c");
JSONObject tenderingRes = new JSONObject();
//开始查询
try {
tenderingRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getTendering, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(tenderingRes.getString("errorDescription")) || tenderingRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("投标费用请求失败或者没有符合条件的数据");
return;
}
log.info("投标费用请求成功,继续向下执行");
for (Object tenderingObj : tenderingRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject tenderingData = JSON.parseObject(JSON.toJSONString(tenderingObj));
System.out.println("当前正在处理数据为:" + tenderingData);
//开始截取关键数据
//唯一性ID
String tenderingId = tenderingData.getString("_id");
//投标单号
String tenderingName = tenderingData.getString("name");
//投标单创建时间
//String createTime = tenderingData.getString("create_time");
String createTime = tenderingData.getString("last_modified_time");
//开始判断是否集成过该单据了
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tendering&log_type=TBFY&dataId=" + tenderingId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前投标单存在日志,将不再向下执行");
continue;
}
log.info("不存在日志,继续向下执行");
//开始封装请求
Map tenderingMapReq = new HashMap<>();
tenderingMapReq.put("number", tenderingData.getString("field_31pd4__c"));//标书购买申请流水号
tenderingMapReq.put("f9w5_crmid", tenderingId);//标书购买申请ID
tenderingMapReq.put("name", tenderingData.getString("opportunity_name__c__r") != null ? tenderingData.getString("opportunity_name__c__r") : "");//商机名称
//申请类型
String applyType = tenderingData.getString("application_type__c") != null ? tenderingData.getString("application_type__c") : "";
String applyTypeStr = "";
switch (applyType) {
case "cNKcx460m":
applyTypeStr = "A";
break;
case "option1":
applyTypeStr = "B";
break;
default:
applyTypeStr = "";
}
tenderingMapReq.put("f9w5_applytype", applyTypeStr);//申请类型
tenderingMapReq.put("f9w5_lot", tenderingData.getString("batch_name__c") != null ? tenderingData.getString("batch_name__c") : "");//批次名称
tenderingMapReq.put("createorg_number", tenderingData.getString("erp_organization__c__v") != null ? tenderingData.getString("erp_organization__c__v") : "");//组织
//供应商ID
String vendorId = tenderingData.getString("bidding_agency__c") != null ? tenderingData.getString("bidding_agency__c") : "";
String vendorErpCode = "";
if (vendorId != null && !vendorId.equals("")) {
JSONObject getVendor = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(vendorId))
), "SupplierObj");
JSONObject vendorRes = new JSONObject();
try {
vendorRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getVendor, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(vendorRes.getString("errorDescription")) && !vendorRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
vendorErpCode = vendorRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("erp_number__c");
}
}
tenderingMapReq.put("f9w5_institution_number", vendorErpCode);//招投标代理机构
Map data = new HashMap<>();
data.put("data", tenderingMapReq);
//开始获取ERP的Token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity tenderingReqEntity = new HttpEntity(data, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(tenderingReqEntity)));
String tenderingUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/em/f9w5_tenderbuyapply/save";
JSONObject tenderingERPRes = new JSONObject();
try {
tenderingERPRes = restTemplate.postForObject(tenderingUrl, tenderingReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(tenderingERPRes);
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", tenderingId);
backReqMap.put("dataObjectApiName", "bid_application__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "TBFY");
logMap.put("syn_type", "0");
logMap.put("data_name", tenderingName);
logMap.put("data_id", tenderingId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(tenderingReqEntity));
logMap.put("send_res", JSON.toJSONString(tenderingERPRes));
logMap.put("tableName", "send_log_tendering");
//判断是否执行成功
if ("0".equals(tenderingERPRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", tenderingERPRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_status__c", "同步成功");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + tenderingERPRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_status__c", tenderingERPRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

View File

@ -0,0 +1,656 @@
package com.management.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
import com.management.constant.URLConstant;
import com.management.entity.Filter;
import com.management.utils.CrmRequestUtil;
import com.management.utils.KingDeeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
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.util.*;
/**
* 销售合同同步
*
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping("/api/sign/conract")
@Slf4j
public class XSHTController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new XSHTController().syncXSHT();
//new XSHTController().isComplete();
}
/**
* 销售合同同步
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_xsht")
public void syncXSHT() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject preContractReq = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("IS", "erp_id__c", Arrays.asList("")),
new Filter("IN", "sync_status__c", Arrays.asList(syncStatus)),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
//new Filter("EQ", "name", Arrays.asList("ZHY2505280021")),
new Filter("EQ", "life_status", Arrays.asList("normal"))
), "SaleContractObj");
JSONObject ContractRes = new JSONObject();
try {
ContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, preContractReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//判断查询是否成功
if (!"success".equals(ContractRes.getString("errorDescription")) || ContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("查询失败或者没有符合条件的单据");
return;
}
for (Object ContractObj : ContractRes.getJSONObject("data").getJSONArray("dataList")) {
//销售合同数据
JSONObject contractData = JSON.parseObject(JSON.toJSONString(ContractObj));
System.out.println("当前正在处理的数据为:" + contractData);
//合同唯一id
String contractId = contractData.getString("_id");
//合同名称
String contractName = contractData.getString("name");
//创建时间
//String createTime = contractData.getString("create_time");
String createTime = contractData.getString("last_modified_time");
//查看数据库表中是否已执行过当前数据
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=XSHT&dataId=" + contractId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(isLogRes);
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("没有集成过,将继续向下执行");
//签订日期
long documentDate = contractData.getLong("contract_time");
Date date = new Date(documentDate);
//开始查询项目号商机
JSONObject projectReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(contractData.getString("opportunity_name__c")))
), "NewOpportunityObj");
JSONObject projectRes = new JSONObject();
try {
projectRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, projectReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(projectRes.getString("errorDescription")) || projectRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("项目号不存在,将不再向下执行");
continue;
}
String projectCode = projectRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0).getString("opportunity_id__c");
//合同种类
String contractType = contractData.getString("contract_zl__c") != null ? contractData.getString("contract_zl__c") : "";
if (contractType.equals("")) {
log.info("合同种类不存在,将不再向下执行");
continue;
}
String contractMainType = "";
String contractTypeStr = "";
if (contractType.equals("option_sales_contract_details__c")) {
contractMainType = "XSHT-QD01";
contractTypeStr = "020";
} else if (contractType.equals("option_sales_contract_total_amoun__c")) {
contractMainType = "XSHT-QD02";
contractTypeStr = "020-1";
}
//开始封装传输至ERP的请求
Map erpContractReq = new HashMap<>();
erpContractReq.put("billno", contractData.getString("name"));//合同编号
erpContractReq.put("crmid", contractData.getString("_id"));//CRM唯一性编码
erpContractReq.put("project_number", projectCode);//项目号
erpContractReq.put("zhybilltype", contractData.getString("contract_type__c"));//合同类型
//erpContractReq.put("project_number", "SJ20250424-0033");//项目号
erpContractReq.put("billtype_number", "conm_salcontract_BT_QD");//单据类型
erpContractReq.put("billname", contractData.getString("project_name__c") != null ? contractData.getString("project_name__c") : "销售合同");//合同名称
erpContractReq.put("type_number", contractMainType);//合同类型
erpContractReq.put("contparties_number", contractData.getString("our_company_name__c") != null ? contractData.getString("our_company_name__c") : "");//合同主体
erpContractReq.put("createorg_number", contractData.getString("our_company_name__c") != null ? contractData.getString("our_company_name__c") : "");//销售组织编码
erpContractReq.put("org_number", contractData.getString("our_company_name__c") != null ? contractData.getString("our_company_name__c") : "");//销售组织编码
erpContractReq.put("currency_number", "CNY");//本位币.货币代码
erpContractReq.put("settlecurrency_number", "CNY");//结算币别.货币代码
erpContractReq.put("biztime", date);//签订日期,单据日期
erpContractReq.put("biztimebegin", date);//起始日期
erpContractReq.put("biztimeend", date);//截止日期
erpContractReq.put("party1st", contractData.getString("account_id__r"));//甲方
erpContractReq.put("party2nd", contractData.getString("our_company_name__c__r"));//乙方
erpContractReq.put("bizmode", "C");//业务模式 A:统谈统签, B:统谈分签,C:分谈分签
erpContractReq.put("totalallamount", 0);//价税合计
erpContractReq.put("deviceqty", 0);//价税合计
//部门编码
String deptCode = "";
List deptIdList = contractData.getJSONArray("data_own_department");
//开始查询部门编码
JSONObject deptReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", deptIdList)
), "DepartmentObj");
JSONObject deptRes = new JSONObject();
try {
deptRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, deptReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(deptRes.getString("errorDescription")) && !deptRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject deptData = deptRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
deptCode = deptData.getString("field_Vj6sf__c") != null ? deptData.getString("field_Vj6sf__c") : "";
}
//erpContractReq.put("dept", "zyierp");//归属部门
erpContractReq.put("dept", deptCode);//归属部门
//获取负责人编码
String ownerCode = "";
List ownerIdList = contractData.getJSONArray("owner");
JSONObject ownerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "user_id", ownerIdList)
), "PersonnelObj");
JSONObject ownerRes = new JSONObject();
try {
ownerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, ownerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if ("success".equals(ownerRes.getString("errorDescription")) && !ownerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
JSONObject ownerData = ownerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
ownerCode = ownerData.getString("field_T1xid__c") != null ? ownerData.getString("field_T1xid__c") : "";
}
//erpContractReq.put("operator", "ZHY10542");//todo 负责人
erpContractReq.put("operator", ownerCode);//todo 负责人
//合同单位
String customerId = contractData.getString("account_id");
//根据客户唯一id查询客户名称
JSONObject customerReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "_id", Arrays.asList(customerId))
), "AccountObj");
JSONObject customerRes = new JSONObject();
try {
customerRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, customerReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(customerRes.getString("errorDescription")) || customerRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("客户名称查询失败或者不存在,直接跳过更新");
continue;
}
JSONObject customerData = customerRes.getJSONObject("data").getJSONArray("dataList").getJSONObject(0);
erpContractReq.put("customer_number", customerData.getString("account_no"));//合同单位名称
erpContractReq.put("reccustomer_number", contractData.getString("receiver_customer__c"));//收获客户单位名称
//erpContractReq.put("customer_number", "Cus-000001");//合同单位名称
erpContractReq.put("settlecustomer_number", contractData.getString("billing_customer_code__c") != null ? contractData.getString("billing_customer_code__c") : "");//结算客户
erpContractReq.put("payingcustomer_number", contractData.getString("payment_customer_code__c") != null ? contractData.getString("payment_customer_code__c") : "");//付款客户
//获取产品线
erpContractReq.put("productline_number", contractData.getString("product_line__c"));//产品线
//获取具体安装方式
erpContractReq.put("installationmethod", contractData.getString("installation_method__c"));//安装方式
//行业类型
erpContractReq.put("industrytype_number", contractData.getString("industry_type__c"));//行业类型
erpContractReq.put("province", contractData.getString("field_9IuQE__c__r"));//
erpContractReq.put("city", contractData.getString("field_9IuQE__c__r"));//
erpContractReq.put("county", contractData.getString("field_e9XrV__c"));//
erpContractReq.put("warranty", contractData.getBigDecimal("warranty_period_months__c") != null ? contractData.getBigDecimal("warranty_period_months__c") : 0);//质保期
//是否招投标
Boolean isBidding = null;
switch (contractData.getString("is_bidding__c")) {
case "yes":
isBidding = true;
break;
case "no":
isBidding = false;
break;
default:
isBidding = null;
break;
}
erpContractReq.put("isbidding", isBidding);
erpContractReq.put("customerpropert", contractData.getString("customer_attribute__c"));//客户属性
erpContractReq.put("station", contractData.getString("bureau_level__c"));//局级
//款到发货
Boolean delivery = null;
switch (contractData.getString("ship_on_payment_received__c")) {
case "yes":
delivery = true;
break;
case "no":
delivery = false;
break;
default:
delivery = null;
break;
}
erpContractReq.put("delivery", delivery);
//项目来源
erpContractReq.put("projectsource", contractData.getString("project_source__c"));
//销售方式
erpContractReq.put("salesmethod", contractData.getString("sales_method__c"));
//根据合同号查询合同明细
JSONObject contractDetailReq = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "sale_contract_id", Arrays.asList(contractId))
), "SaleContractLineObj");
JSONObject contractDetailRes = new JSONObject();
try {
contractDetailRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, contractDetailReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(contractDetailRes.getString("errorDescription")) || contractDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("合同明细查询失败或者不存在,直接跳过");
continue;
}
//合同明细存在继续向下执行
List contractDetailList = new ArrayList<>();
for (Object contractDetailObj : contractDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject contractDetailData = JSON.parseObject(JSON.toJSONString(contractDetailObj));
System.out.println("当前正在处理的明细为:" + contractDetailData);
//开始封装销售合同明细
Map contractDetailMap = new HashMap();
contractDetailMap.put("linetype_number", contractTypeStr);//行类型
contractDetailMap.put("goodsname", contractDetailData.getString("product_name__c"));//产品名称
//contractDetailMap.put("material_number", contractDetailData.getString("product_id__r"));//物料编号
contractDetailMap.put("material_number", "TEST0001");//todo 物料编号
contractDetailMap.put("specification", contractDetailData.getString("specification__c") != null ? contractDetailData.getString("specification__c") : "");//规格
contractDetailMap.put("baseunit", contractDetailData.getString("unit__c__r") != null ? contractDetailData.getString("unit__c__r") : "");//单位
//contractDetailMap.put("baseunit", "TEST0001");//todo 单位
contractDetailMap.put("unit_number", "pcs");//单位编码
contractDetailMap.put("unit1_number", "pcs");//单位编码
contractDetailMap.put("f9w5_unit1_number", "pcs");//单位编码
contractDetailMap.put("baseqty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
contractDetailMap.put("qty", contractDetailData.getBigDecimal("quantity") != null ? contractDetailData.getBigDecimal("quantity") : 0);//数量
contractDetailMap.put("priceandtax", contractDetailData.getBigDecimal("sales_price") != null ? contractDetailData.getBigDecimal("sales_price") : 0);//含税单价
//contractDetailMap.put("taxrateid_number", contractDetailData.getBigDecimal("tax_rate__c") != null ? contractDetailData.getBigDecimal("tax_rate__c") : 0);//税率
contractDetailMap.put("taxrateid_number", "V13");//税率
contractDetailMap.put("curamountandtax", contractDetailData.getBigDecimal("subtotal") != null ? contractDetailData.getBigDecimal("subtotal") : 0);//价税合计
//contractDetailMap.put("curtaxamount", contractDetailData.getBigDecimal("tax_amount__c") != null ? contractDetailData.getBigDecimal("tax_amount__c") : 0);//金额
contractDetailMap.put("crmentryid", contractDetailData.getString("_id"));//明细id
contractDetailList.add(contractDetailMap);
}
//开始封装明细
erpContractReq.put("billentry", contractDetailList);
System.out.println("erp请求为" + JSON.parseObject(JSON.toJSONString(erpContractReq)));
Map erpContractData = new HashMap<>();
erpContractData.put("data", Arrays.asList(erpContractReq));//请求体
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
String uuid = UUID.randomUUID().toString().replace("-", "");
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
headers.set("Idempotency-Key", uuid);
HttpEntity contractReqEntity = new HttpEntity(erpContractData, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(contractReqEntity)));
//开始向金蝶发起请求
String contractUrl = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/conm/conm_salcontract/savecontract";
JSONObject contractRes = new JSONObject();
try {
contractRes = restTemplate.postForObject(contractUrl, contractReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(contractRes)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", contractId);
backReqMap.put("dataObjectApiName", "SaleContractObj");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "XSHT");
logMap.put("syn_type", "0");
logMap.put("data_name", contractName);
logMap.put("data_id", contractId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(contractReqEntity));
logMap.put("send_res", JSON.toJSONString(contractRes));
logMap.put("tableName", "send_log_htxx");
//判断是否执行成功
if ("0".equals(contractRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("erp_id__c", contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"));
backReqMap.put("sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
//审核
KingDeeUtils kingDeeUtils = new KingDeeUtils();
kingDeeUtils.audit(contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id"), "conm_salcontract");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + contractRes.getString("message"));
backReqMap.put("sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", contractRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
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);
log.info("开始同步销售合同附件");
//判断销售合同是否执行成功
String contractERPID = "";
if ("0".equals(contractRes.getString("errorCode"))) {
log.info("销售合同执行成功");
contractERPID = contractRes.getJSONObject("data").getJSONArray("result").getJSONObject(0).getString("id");
} else {
log.info("销售合同执行失败,将不再向下执行");
continue;
}
List contractFileList = contractData.getJSONArray("contract_attachment__c") != null ? contractData.getJSONArray("contract_attachment__c") : new ArrayList();
if (contractFileList == null || contractFileList.isEmpty()) {
log.info("该销售合同不存在附件,将不再向下执行。");
continue;
}
log.info("附件存在,继续向下执行");
MultiValueMap<String, Object> body = crmRequestUtil.contractFile(contractFileList, Long.parseLong(contractERPID));
//开始封装请求实体
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
httpHeaders.set("accessToken", accessToken);
HttpEntity entity = new HttpEntity(body, httpHeaders);
//开始发起传输
JSONObject fileRes = new JSONObject();
try {
fileRes = restTemplate.postForObject(ERPURLConstant.ERP_URL + "/ierp/kapi/v2/frame/attachment/uploadFile", entity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("附件上传结果为:" + fileRes);
}
}
/**
* 是否竣工
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/isComplete")
public void isComplete() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
JSONObject contractReq = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("EQ", "name", Arrays.asList("ZHY2505180013")),
new Filter("GT", "create_time", Arrays.asList("1748923200000")),
new Filter("EQ", "is_completed__c", Arrays.asList("yes"))
), "SaleContractObj");
JSONObject contractRes = new JSONObject();
try {
contractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, contractReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(contractRes.getString("errorDescription")) || contractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("没有找到销售合同");
return;
}
log.info("数据存在,继续向下执行");
for (Object contractObj : contractRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject contractData = JSON.parseObject(JSON.toJSONString(contractObj));
System.out.println("当前正在处理的销售合同数据为:" + contractData);
//开始查询该销售合同是否已经执行过
JSONObject isLogRes = new JSONObject();
String contractId = contractData.getString("_id");
String contractName = contractData.getString("name");
String createTime = contractData.getString("create_time");
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_htxx&log_type=是否竣工&dataId=" + contractId + "&mark=" + createTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("当前数据已经执行过了,将不再向下执行");
continue;
}
log.info("日志不存在,将继续向下执行");
//开始封装请求
Map isCompleteReqMap = new HashMap<>();
isCompleteReqMap.put("billno", contractName);
Map isCompleteReq = new HashMap<>();
isCompleteReq.put("model", isCompleteReqMap);
//开始获取token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity isCompleteEntity = new HttpEntity(isCompleteReq, headers);
System.out.println(JSON.parseObject(JSON.toJSONString(isCompleteEntity)));
JSONObject isCompleteRes = new JSONObject();
try {
isCompleteRes = restTemplate.postForObject(ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/f9w5_conm_ext/salcontract/beComplete", isCompleteEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(isCompleteRes)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", contractId);
backReqMap.put("dataObjectApiName", "SaleContractObj");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "是否竣工");
logMap.put("syn_type", "0");
logMap.put("data_name", contractName);
logMap.put("data_id", contractId);
logMap.put("mark", createTime);
logMap.put("send_body", JSON.toJSONString(isCompleteEntity));
logMap.put("send_res", JSON.toJSONString(isCompleteRes));
logMap.put("tableName", "send_log_htxx");
//判断是否执行成功
if ("0".equals(isCompleteRes.getString("errorCode"))) {
//同步成功
logMap.put("log_status", "0");
logMap.put("res_body", "同步成功");
backReqMap.put("completion_sync_status__c", "option_sync_success__c");
backReqMap.put("response_info__c", "同步成功");
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + isCompleteRes.getString("message"));
backReqMap.put("completion_sync_status__c", "option_sync_failure__c");
backReqMap.put("response_info__c", isCompleteRes.getString("message"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
System.out.println("回写请求为:" + JSON.parseObject(JSON.toJSONString(backReq)));
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);
}
}
}

View File

@ -0,0 +1,56 @@
package com.management.entity;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class Filter {
@JsonProperty("operator")
private String operator;
@JsonProperty("field_name")
private String fieldName;
@JsonProperty("field_values")
private List<String> fieldValues;
// 构造方法
public Filter(String operator, String fieldName, List<String> fieldValues) {
this.operator = operator;
this.fieldName = fieldName;
this.fieldValues = fieldValues;
}
// Getter Setter 方法
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public List<String> getFieldValues() {
return fieldValues;
}
public void setFieldValues(List<String> fieldValues) {
this.fieldValues = fieldValues;
}
// 方便打印的 toString 方法
@Override
public String toString() {
return "Filter{" +
"operator='" + operator + '\'' +
", field_name='" + fieldName + '\'' +
", field_values=" + fieldValues +
'}';
}
}

View File

@ -0,0 +1,74 @@
package com.management.task;
import com.management.controller.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
/**
* 计划任务
*
* @return null
* @Author weiloong_zhang
*/
@Configuration
@EnableScheduling
public class CrmTask {
@Autowired
CRMTokenController crmTokenController;
@Autowired
PreContractController preContractController;
@Autowired
FrameContractController frameContractController;
@Autowired
XSHTController xshtController;
@Autowired
DesignController designController;
@Autowired
GoodsPlanController goodsPlanController;
@Autowired
InvoiceController invoiceController;
@Autowired
QualityBackController qualityBackController;
@Autowired
TenderingController tenderingController;
@Autowired
BankInfoController bankInfoController;
/**
* 定时任务获取纷享销客token
*
* @return void
* @Author weiloong_zhang
*/
@Scheduled(cron = "0 0/60 * * * ?")
private void crmTokenTask() {
crmTokenController.getCRMToken();
}
/**
* 定时任务同步ERP数据
*
* @return void
* @Author weiloong_zhang
*/
// @Scheduled(cron = "0 0/1 * * * ?")
// private void configureTasks() throws Exception {
// System.out.println("开始同步ERP数据");
// preContractController.syncContract();
// frameContractController.syncFrameContract();
// xshtController.syncXSHT();
// xshtController.isComplete();
// designController.syncDesign();
// goodsPlanController.syncGoodsPlan();
// invoiceController.syncInvoice();
// invoiceController.syncRedInvoice();
// qualityBackController.qualityFeedBack();
// tenderingController.syncTendering();
// bankInfoController.syncBankInfo();
// System.out.println("ERP数据执行完毕");
// }
}

View File

@ -0,0 +1,50 @@
package com.management.task;
import com.management.tzcontroller.*;
import com.management.tzcontroller.DeliveryReqController;
import com.management.tzcontroller.DeviceInstallController;
import com.management.tzcontroller.ProjectInitiateController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
/**
* @Description: 台账定时任务
* @return null
* @Author weiloong_zhang
*/
@Configuration
@EnableScheduling
public class CrmTaskTZ {
@Autowired
DeliveryReqController deliveryReqController;
@Autowired
DeviceInstallController deviceInstallController;
@Autowired
ProjectInitiateController projectInitiateController;
@Autowired
TZXSHTController xshtController;
@Autowired
YQHTController yqhtController;
/**
* 定时任务同步太脏数据
*
* @return void
* @Author weiloong_zhang
*/
// @Scheduled(cron = "0 0/2 * * * ?")
// private void configureTasks() throws Exception {
// System.out.println("开始同步台账数据");
// projectInitiateController.syncProjectInitiate();
// deliveryReqController.syncDeliveryReq();
// deliveryReqController.syncRefund();
// deviceInstallController.syncDeviceInstall();
// deviceInstallController.upDeviceInstall();
// xshtController.syncSaleOrder();
// yqhtController.syncYQHT();
// System.out.println("台账执行完毕");
// }
}

View File

@ -0,0 +1,446 @@
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.math.BigDecimal;
import java.util.*;
/**
* 发货申请单
*
* @param
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping("/api/delivery")
@Slf4j
public class DeliveryReqController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
//new DeliveryReqController().syncDeliveryReq();
new DeliveryReqController().syncRefund();
}
/**
* 同步发货申请单
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync_delivery")
public void syncDeliveryReq() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
log.info("开始执行发货申请单台账新增");
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getDelivery = 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("FHSQ202505270013")),
new Filter("IN", "ledger_sync_status__c", Arrays.asList(syncStatus))
), "shipping_application__c");
JSONObject deliveryRes = new JSONObject();
try {
deliveryRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getDelivery, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(deliveryRes.getString("errorDescription")) || deliveryRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("发货申请单为空或者请求失败,将不再向下执行");
return;
}
for (Object deliveryObj : deliveryRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject deliveryData = JSON.parseObject(JSON.toJSONString(deliveryObj));
System.out.println("当前正在处理的数据为:" + deliveryData);
//开始截取关键数据
String deliveryId = deliveryData.getString("_id");
String deliveryName = deliveryData.getString("name");
String modifiedTime = deliveryData.getString("last_modified_time");
//开始查询是否已经集成过该单据了
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzfhsq&log_type=TZFHSQ&dataId=" + deliveryId + "&mark=" + modifiedTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("数据已经存在,将不再继续向下执行");
continue;
}
log.info("数据不存在,将开始向下执行");
//开始封装主表数据
Map deliveryReqMap = new HashMap<>();
deliveryReqMap.put("id", deliveryId);//主表唯一id
deliveryReqMap.put("dispatchNo", deliveryName);//发货单号
deliveryReqMap.put("salesContract", deliveryData.getString("sales_contract_number__c__r") != null ? deliveryData.getString("sales_contract_number__c__r") : "");//销售合同号
deliveryReqMap.put("salesId", deliveryData.getString("sales_contract_number__c") != null ? deliveryData.getString("sales_contract_number__c") : "");//预签合同号
deliveryReqMap.put("preSignContract", deliveryData.getString("pre_signed_contract_id__c__r") != null ? deliveryData.getString("pre_signed_contract_id__c__r") : "");//预签合同号
deliveryReqMap.put("preSignId", deliveryData.getString("pre_signed_contract_id__c") != null ? deliveryData.getString("pre_signed_contract_id__c") : "");
deliveryReqMap.put("project", deliveryData.getString("project_id__c") != null ? deliveryData.getString("project_id__c") : "");//项目号
deliveryReqMap.put("businessType", 0);//业务类型
deliveryReqMap.put("organization", "ZHY");//组织
//开始查询明细数据
JSONObject deliveryDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "shipping_application__c", Arrays.asList(deliveryId))
), "shipping_product__c");
JSONObject deliveryDetailRes = new JSONObject();
try {
deliveryDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, deliveryDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(deliveryDetailRes.getString("errorDescription")) || deliveryDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("发货申请单明细为空或者请求失败,将不再向下执行");
continue;
}
log.info("存在发货明细数据,将继续向下执行");
List deliveryDetailList = new ArrayList();
for (Object deliveryDetailObj : deliveryDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject deliveryDetailData = JSON.parseObject(JSON.toJSONString(deliveryDetailObj));
System.out.println("当前正在处理的明细数据为:" + deliveryDetailData);
String materialCode = deliveryDetailData.getString("material_code__c__r") != null ? deliveryDetailData.getString("material_code__c__r") : "";
if (!materialCode.startsWith("30")) {
continue;
}
//开始封装数据
Map deliveryDetailMap = new HashMap<>();
deliveryDetailMap.put("id", deliveryDetailData.getString("_id"));//明细id
deliveryDetailMap.put("lot", deliveryDetailData.getString("batch_number__c") != null ? deliveryDetailData.getString("batch_number__c") : "");//批号
deliveryDetailMap.put("trackNo", deliveryDetailData.getString("shipping_tracking_number__c") != null ? deliveryDetailData.getString("shipping_tracking_number__c") : "");//跟踪号
deliveryDetailMap.put("unit", deliveryDetailData.getString("unit__c__r") != null ? deliveryDetailData.getString("unit__c__r") : "");//单位
deliveryDetailMap.put("materialCode", deliveryDetailData.getString("material_code__c__r") != null ? deliveryDetailData.getString("material_code__c__r") : "");//物料编码
deliveryDetailMap.put("quantity", deliveryDetailData.getBigDecimal("current_application_quanti__c") != null ? deliveryDetailData.getBigDecimal("current_application_quanti__c") : new BigDecimal(0));//数量
deliveryDetailList.add(deliveryDetailMap);
}
if (deliveryDetailList.isEmpty()) {
log.info("发货申请单明细为空,将不再向下执行");
continue;
}
deliveryReqMap.put("detailList", deliveryDetailList);//发货申请明细
//开始获取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(deliveryReqMap), headers);
//开始发起请求
String deliveryUrl = "http://192.168.5.55:9011/crm/initShipApply";
JSONObject deliveryResult = new JSONObject();
try {
deliveryResult = restTemplate.postForObject(deliveryUrl, reqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(deliveryResult)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", deliveryId);
backReqMap.put("dataObjectApiName", "shipping_application__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "TZFHSQ");
logMap.put("syn_type", "0");
logMap.put("data_name", deliveryName);
logMap.put("data_id", deliveryId);
logMap.put("mark", modifiedTime);
logMap.put("send_body", JSON.toJSONString(reqEntity));
logMap.put("send_res", JSON.toJSONString(deliveryResult));
logMap.put("tableName", "send_log_tzfhsq");
//判断是否执行成功
if (deliveryResult.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", deliveryResult.getString("msg"));
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + deliveryResult.getString("msg"));
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
backReqMap.put("ledger_response_status__c", deliveryResult.getString("msg"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
/**
* 退货申请
*
* @Author weiloong_zhang
*/
@PostMapping
public void syncRefund() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getRefund = 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("FHSQ202505270013")),
new Filter("IN", "ledger_sync_status__c", Arrays.asList(syncStatus))
), "return_application__c");
JSONObject refundRes = new JSONObject();
try {
refundRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getRefund, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(refundRes.getString("errorDescription")) || refundRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("退货申请不存在或者请求失败");
return;
}
for (Object refundObj : refundRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject refundData = JSON.parseObject(JSON.toJSONString(refundObj));
System.out.println("当前正在处理的数据为:" + refundData);
//开始截取关键数据
String refundId = refundData.getString("_id");//唯一id
String refundName = refundData.getString("name");//单据编号
String modifyTime = refundData.getString("last_modified_time");//创建时间
//判断该单据是否已经集成过
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzfhsq&log_type=TZTHSQ&dataId=" + refundId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("数据存在,将不再向下执行");
continue;
}
log.info("数据不存在,将继续向下执行");
//封装退货申请
Map refundReqMap = new HashMap<>();
refundReqMap.put("id", refundId);//主表唯一id
refundReqMap.put("dispatchNo", refundName);//发货单号
refundReqMap.put("salesContract", refundData.getString("sales_contract_number__c__r") != null ? refundData.getString("sales_contract_number__c__r") : "");//销售合同号
refundReqMap.put("salesId", refundData.getString("sales_contract_number__c") != null ? refundData.getString("sales_contract_number__c") : "");//销售合同ID
refundReqMap.put("preSignContract", refundData.getString("pre_signed_contract__c__r") != null ? refundData.getString("pre_signed_contract__c__r") : "");//预签合同号
refundReqMap.put("preSignId", refundData.getString("pre_signed_contract__c") != null ? refundData.getString("pre_signed_contract__c") : "");//预签合同ID
refundReqMap.put("project", refundData.getString("refer_project_id__c") != null ? refundData.getString("refer_project_id__c") : "");//项目号
refundReqMap.put("businessType", 1);//业务类型
refundReqMap.put("organization", "ZHY");//组织
//开始查询明细数据
JSONObject refundDetail = crmRequestUtil.getCRMList(Arrays.asList(
new Filter("EQ", "field_Ok1G3__c", Arrays.asList(refundId))
), "return_application_details__c");
JSONObject refundDetailRes = new JSONObject();
try {
refundDetailRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, refundDetail, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(refundDetailRes.getString("errorDescription")) || refundDetailRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("退货申请单明细为空或者请求失败,将不再向下执行");
continue;
}
log.info("存在退货明细数据,将继续向下执行");
List refundDetailList = new ArrayList();
for (Object refundDetailObj : refundDetailRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject refundDetailData = JSON.parseObject(JSON.toJSONString(refundDetailObj));
System.out.println("当前正在处理的明细数据为:" + refundDetailData);
//开始封装数据
Map refundDetailMap = new HashMap<>();
refundDetailMap.put("id", refundDetailData.getString("_id"));//明细id
refundDetailMap.put("lot", refundDetailData.getString("batch_number__c") != null ? refundDetailData.getString("batch_number__c") : "");//批号
refundDetailMap.put("trackNo", refundDetailData.getString("tracking_number__c") != null ? refundDetailData.getString("tracking_number__c") : "");//跟踪号
refundDetailMap.put("unit", refundDetailData.getString("unit__c__r") != null ? refundDetailData.getString("unit__c__r") : "");//单位
refundDetailMap.put("materialCode", refundDetailData.getString("material_id__c__r") != null ? refundDetailData.getString("material_id__c__r") : "");//物料编码
refundDetailMap.put("quantity", refundDetailData.getBigDecimal("quantity__c") != null ? refundDetailData.getBigDecimal("quantity__c") : new BigDecimal(0));//数量
refundDetailList.add(refundDetailMap);
}
refundReqMap.put("detailList", refundDetailList);
//开始获取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(refundReqMap), headers);
//开始发起请求
String refundUrl = "http://192.168.5.55:9011/crm/initShipApply";
JSONObject refundResult = new JSONObject();
try {
refundResult = restTemplate.postForObject(refundUrl, reqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(refundResult)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", refundId);
backReqMap.put("dataObjectApiName", "return_application__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "TZTHSQ");
logMap.put("syn_type", "0");
logMap.put("data_name", refundName);
logMap.put("data_id", refundId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(reqEntity));
logMap.put("send_res", JSON.toJSONString(refundResult));
logMap.put("tableName", "send_log_tzfhsq");
//判断是否执行成功
if (refundResult.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", refundResult.getString("msg"));
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + refundResult.getString("msg"));
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
backReqMap.put("ledger_response_status__c", refundResult.getString("msg"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

View File

@ -0,0 +1,475 @@
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);
}
}
}

View File

@ -0,0 +1,62 @@
package com.management.tzcontroller;
import com.alibaba.fastjson.JSONObject;
import com.management.utils.CaffeineCacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class LedgerTokenController {
private RestTemplate restTemplate = new RestTemplate();
/**
* 台账token获取
* @return java.lang.String
* @Author weiloong_zhang
*/
public String getToken() {
String token = "";
if (CaffeineCacheUtil.get("ledgerToken") != null && !"".equals(CaffeineCacheUtil.get("ledgerToken"))) {
log.info("台账token存在");
token = CaffeineCacheUtil.get("ledgerToken").toString();
return token;
}
log.info("台账token不存在即将重新获取");
//开始封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("user", "equip");
tokenParams.put("pwt", "E2Q0U2I5P0M5E1N2T");
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
HttpEntity tokenReqEntity = new HttpEntity(tokenParams, headers);
//开始获取台账token
JSONObject tokenRes = new JSONObject();
try {
tokenRes = restTemplate.postForObject("http://192.168.5.55:9011/equip/getToken", tokenReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (tokenRes.getInteger("code") == 0 && !tokenRes.getJSONObject("data").isEmpty()) {
token = tokenRes.getJSONObject("data").getString("token");
CaffeineCacheUtil.put("ledgerToken", token);
}
return token;
}
}

View File

@ -0,0 +1,193 @@
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.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* 项目启动单同步接口
*
* @return null
* @Author weiloong_zhang
*/
@RestController
@RequestMapping("/api/project/initiate")
@Slf4j
public class ProjectInitiateController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new ProjectInitiateController().syncProjectInitiate();
}
/**
* 项目启动单同步
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/project_initiate")
public void syncProjectInitiate() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getProjectInitiate = crmRequestUtil.getCRMList(Arrays.asList(
//new Filter("EQ", "project_no__c", Arrays.asList("XM202504250001"))
new Filter("GT", "last_modified_time", Arrays.asList("1748923200000")),
new Filter("EQ", "life_status", Arrays.asList("normal")),
new Filter("IN", "ledger_sync_status__c", Arrays.asList(syncStatus))
), "ProjectObj");
JSONObject projectInitiateRes = new JSONObject();
try {
projectInitiateRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getProjectInitiate, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(projectInitiateRes.getString("errorDescription")) || projectInitiateRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("项目启动单获取失败或者数据不存在,将不再向下执行");
return;
}
log.info("项目启动单获取成功,继续向下执行");
for (Object projectInitiateObj : projectInitiateRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject projectInitiateData = JSON.parseObject(JSON.toJSONString(projectInitiateObj));
System.out.println("当前正在处理的数据为:" + projectInitiateData);
//开始截取关键数据
//CRM唯一ID
String projectInitiateId = projectInitiateData.getString("_id");
//单据编号
String projectInitiateCode = projectInitiateData.getString("project_no__c");
//最后修改时间
String modifyTime = projectInitiateData.getString("last_modified_time");
//开始判断项目启动单是否已经执行过了
JSONObject isLogRes = new JSONObject();
try {
isLogRes = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzproject&log_type=项目启动单&dataId=" + projectInitiateId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLogRes.getJSONArray("data").isEmpty()) {
log.info("数据已经执行过了,将不再向下执行");
continue;
}
log.info("数据没有执行过,将开始向下执行");
//开始封装数据
Map projectInitiateMap = new HashMap<>();
projectInitiateMap.put("project", projectInitiateCode);
projectInitiateMap.put("projectName", projectInitiateData.getString("name"));
//开始获取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(projectInitiateMap), headers);
//开始发起请求
String projectUrl = "http://192.168.5.55:9011/crm/initProject";
JSONObject projectResult = new JSONObject();
try {
projectResult = restTemplate.postForObject(projectUrl, reqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(projectResult)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", projectInitiateId);
backReqMap.put("dataObjectApiName", "ProjectObj");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "项目启动单");
logMap.put("syn_type", "0");
logMap.put("data_name", projectInitiateCode);
logMap.put("data_id", projectInitiateId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(reqEntity));
logMap.put("send_res", JSON.toJSONString(projectResult));
logMap.put("tableName", "send_log_tzproject");
//判断是否执行成功
if (projectResult.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_info__c", projectResult.getString("msg"));
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + projectResult.getString("msg"));
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
backReqMap.put("ledger_response_info__c", projectResult.getString("msg"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

View File

@ -0,0 +1,216 @@
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.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/api/tz/salesOrder")
@Slf4j
public class TZXSHTController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new TZXSHTController().syncSaleOrder();
}
/**
* 智洋同步销售合同台账
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/order")
public void syncSaleOrder() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject salesOrderReq = 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("ZHY2505260018")),
new Filter("IN", "ledger_sync_status__c", Arrays.asList(syncStatus))
), "SaleContractObj");
JSONObject salesOrderRes = new JSONObject();
try {
salesOrderRes = restTemplate.postForObject(URLConstant.GET_CRM_LIST_URL, salesOrderReq, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!"success".equals(salesOrderRes.getString("errorDescription")) || salesOrderRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("销售合同为空或者请求失败,将不再向下执行");
return;
}
for (Object salesOrderObj : salesOrderRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject salesOrderData = JSON.parseObject(JSON.toJSONString(salesOrderObj));
System.out.println("当前正在处理的数据为:" + salesOrderData);
//开始截取关键数据
String salesOrderId = salesOrderData.getString("_id");//唯一id
String salesOrderName = salesOrderData.getString("name");
String modifyTime = salesOrderData.getString("last_modified_time");
//开始查询数据库是否已经存在该数据
JSONObject salesOrderIsExist = new JSONObject();
try {
salesOrderIsExist = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzht&log_type=TZXSHT&dataId=" + salesOrderId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!salesOrderIsExist.getJSONArray("data").isEmpty()) {
log.info("数据已经存在,将不再继续向下执行");
continue;
}
log.info("数据不存在,将开始向下执行");
Map salesOrderReqMap = new HashMap<>();
salesOrderReqMap.put("crmId", salesOrderId);
salesOrderReqMap.put("contract", salesOrderName);//合同号
salesOrderReqMap.put("contractName", salesOrderData.getString("project_name__c") != null ? salesOrderData.getString("project_name__c") : "");//合同名称
salesOrderReqMap.put("signingUnit", salesOrderData.getString("account_id__r") != null ? salesOrderData.getString("account_id__r") : "");//签订单位
//开始获取地区
//
String province = salesOrderData.getString("field_9IuQE__c__r") != null ? salesOrderData.getString("field_9IuQE__c__r") : "";
//
String city = salesOrderData.getString("field_cuMW9__c__r") != null ? salesOrderData.getString("field_cuMW9__c__r") : "";
//
String district = salesOrderData.getString("field_e9XrV__c__r") != null ? salesOrderData.getString("field_e9XrV__c__r") : "";
//详细地址
String address = salesOrderData.getString("field_tfkq9__c") != null ? salesOrderData.getString("field_tfkq9__c") : "";
//地址
String region = province + city + district + address;
salesOrderReqMap.put("region", region);//地区
//是否竣工
String isComplete = salesOrderData.getString("is_completed__c") != null ? salesOrderData.getString("is_completed__c") : "";
Integer isCompletion = 0;
switch (isComplete) {
case "yes":
isCompletion = 1;
break;
case "no":
isCompletion = 0;
break;
default:
isCompletion = 0;
}
salesOrderReqMap.put("isCompletion", isCompletion);//是否竣工
//开始获取oken
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(salesOrderReqMap), headers);
System.out.println(JSON.parseObject(JSON.toJSONString(reqEntity)));
String url = "http://192.168.5.55:9011/crm/initContract";
JSONObject salesOrderResult = new JSONObject();
try {
salesOrderResult = restTemplate.postForObject(url, reqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(salesOrderResult)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", salesOrderId);
backReqMap.put("dataObjectApiName", "SaleContractObj");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "TZXSHT");
logMap.put("syn_type", "0");
logMap.put("data_name", salesOrderName);
logMap.put("data_id", salesOrderId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(reqEntity));
logMap.put("send_res", JSON.toJSONString(salesOrderResult));
logMap.put("tableName", "send_log_tzht");
//判断是否执行成功
if (salesOrderResult.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", salesOrderResult.getString("msg"));
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + salesOrderResult.getString("msg"));
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
backReqMap.put("ledger_response_status__c", salesOrderResult.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);
}
}
}

View File

@ -0,0 +1,206 @@
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.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@RestController
@RequestMapping("/api/tz/yqht")
@Slf4j
public class YQHTController {
private RestTemplate restTemplate = new RestTemplate();
public static void main(String[] args) {
new YQHTController().syncYQHT();
}
/**
* 台账预签合同
*
* @return void
* @Author weiloong_zhang
*/
@PostMapping("/sync/yqht")
public void syncYQHT() {
CrmRequestUtil crmRequestUtil = new CrmRequestUtil();
String[] syncStatus = {"option_pending_sync__c", "option_resync__c"};
JSONObject getPreContract = 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("YQ2505260006")),
new Filter("IN", "ledger_sync_status__c", Arrays.asList(syncStatus))
), "pre_signed_contract__c");
JSONObject preContractRes = new JSONObject();
try {
preContractRes = restTemplate.postForObject(URLConstant.GET_CUSTOMIZE_LIST_URL, getPreContract, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
//判断预签合同是否存在
if (!"success".equals(preContractRes.getString("errorDescription")) || preContractRes.getJSONObject("data").getJSONArray("dataList").isEmpty()) {
log.info("预签合同不存在或者请求失败");
return;
}
log.info("预签合同数据存在,将继续向下执行");
for (Object preContractObj : preContractRes.getJSONObject("data").getJSONArray("dataList")) {
JSONObject preContractData = JSON.parseObject(JSON.toJSONString(preContractObj));
System.out.println("当前正在处理的数据为:" + preContractData);
//开始截取关键数据
String preContractId = preContractData.getString("_id");
String preContractName = preContractData.getString("name");
String modifyTime = preContractData.getString("last_modified_time");
//查询日志是否已经集成过了
JSONObject isLog = new JSONObject();
try {
isLog = restTemplate.getForObject("http://localhost:18085/Log/query/log_data?table=send_log_tzht&log_type=TZYQHT&dataId=" + preContractId + "&mark=" + modifyTime, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
if (!isLog.getJSONArray("data").isEmpty()) {
log.info("当前单据已经集成过了,将不再向下执行");
continue;
}
log.info("当前单据没有集成过,将开始向下执行");
//开始封装请求数据
Map preContractReqMap = new HashMap<>();
preContractReqMap.put("crmId", preContractId);
preContractReqMap.put("contract", preContractName);//合同号
preContractReqMap.put("contractName", preContractData.getString("project_name__c") != null ? preContractData.getString("project_name__c") : "");//合同名称
preContractReqMap.put("signingUnit", preContractData.getString("contract_unit_name__c__r") != null ? preContractData.getString("contract_unit_name__c__r") : "");//签订单位客户名
//开始获取地区
//
String province = preContractData.getString("field_t3fgo__c__r") != null ? preContractData.getString("field_t3fgo__c__r") : "";
//
String city = preContractData.getString("field_ngwth__c__r") != null ? preContractData.getString("field_ngwth__c__r") : "";
//
String district = preContractData.getString("field_K5p2C__c__r") != null ? preContractData.getString("field_K5p2C__c__r") : "";
//详细地址
String address = preContractData.getString("field_740WI__c") != null ? preContractData.getString("field_740WI__c") : "";
//地址
String region = province + city + district + address;
preContractReqMap.put("region", region);//地址
preContractReqMap.put("isCompletion", 0);//todo 是否已完成(暂时默认0)
//开始获取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 preContractReqEntity = new HttpEntity(Arrays.asList(preContractReqMap), headers);
System.out.println(JSON.parseObject(JSON.toJSONString(preContractReqEntity)));
//开始发起请求
String preContractUrl = "http://192.168.5.55:9011/crm/initContract";
JSONObject preContractResult = new JSONObject();
try {
preContractResult = restTemplate.postForObject(preContractUrl, preContractReqEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println(JSON.parseObject(JSON.toJSONString(preContractResult)));
//开始封装回写程序
Map backReqMap = new HashMap();
backReqMap.put("_id", preContractId);
backReqMap.put("dataObjectApiName", "pre_signed_contract__c");
//开始封装日志
Map logMap = new HashMap<>();
logMap.put("log_id", UUID.randomUUID().toString().replace("-", ""));
logMap.put("log_type", "TZYQHT");
logMap.put("syn_type", "0");
logMap.put("data_name", preContractName);
logMap.put("data_id", preContractId);
logMap.put("mark", modifyTime);
logMap.put("send_body", JSON.toJSONString(preContractReqEntity));
logMap.put("send_res", JSON.toJSONString(preContractResult));
logMap.put("tableName", "send_log_tzht");
//判断是否执行成功
if (preContractResult.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", preContractResult.getString("msg"));
} else {
//同步失败
logMap.put("log_status", "1");
logMap.put("res_body", "同步失败:" + preContractResult.getString("msg"));
backReqMap.put("ledger_sync_status__c", "option_sync_failure__c");
backReqMap.put("ledger_response_status__c", preContractResult.getString("msg"));
}
//开始回写
JSONObject backReq = crmRequestUtil.updateCRM(backReqMap);
JSONObject backRes = new JSONObject();
try {
backRes = restTemplate.postForObject(URLConstant.UPDATE_CRM_CUSTOMIZE, 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);
}
}
}

View File

@ -0,0 +1,59 @@
package com.management.utils;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.concurrent.TimeUnit;
public class CaffeineCacheUtil {
private static final Cache<Object, Object> cache = Caffeine.newBuilder()
.maximumSize(100) // 最大缓存容量
.expireAfterWrite(90, TimeUnit.MINUTES) // 120分钟后过期
.build();
/**
* 存储数据到缓存
*
* @param key 缓存的键
* @param value 缓存的值
*/
public static void put(Object key, Object value) {
cache.put(key, value);
}
/**
* 从缓存中获取数据
*
* @param key 缓存的键
* @return 缓存的值如果不存在则返回null
*/
public static Object get(Object key) {
return cache.getIfPresent(key);
}
/**
* 从缓存中删除数据
*
* @param key 缓存的键
*/
public static void remove(Object key) {
cache.invalidate(key);
}
public static void main(String[] args) {
// 存储数据到缓存
put("key1", "value1");
// 从缓存中获取数据
Object value = get("key1");
System.out.println("Cached value for key1: " + value);
// 从缓存中删除数据
remove("key1");
// 尝试获取被删除的数据
value = get("key1");
System.out.println("Cached value for key1 after removal: " + value);
}
}

View File

@ -0,0 +1,536 @@
package com.management.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.CertificateConstant;
import com.management.constant.URLConstant;
import com.management.entity.Filter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.*;
/**
* 本工具类用于封装向纷享销客发送的请求参数后续会完善其他的参数方法
*
* @param
* @return null
* @Author weiloong_zhang
*/
@Slf4j
public class CrmRequestUtil {
private RestTemplate restTemplate = new RestTemplate();
//封装根据条件查询数据列表的请求
public JSONObject getCRMList(List<Filter> filters, String dataObjectApiName) {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
CaffeineCacheUtil.put("corpAccessToken", corpAccessToken);
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
Map orderMap = new HashMap<>();
orderMap.put("fieldName", "create_time");
orderMap.put("isAsc", "false");
Map searchQueryInfoMap = new HashMap<>();
searchQueryInfoMap.put("offset", "0");
searchQueryInfoMap.put("limit", "100");
searchQueryInfoMap.put("orders", Arrays.asList(orderMap));
searchQueryInfoMap.put("filters", filters);
Map data = new HashMap<>();
data.put("search_query_info", searchQueryInfoMap);
data.put("dataObjectApiName", dataObjectApiName);
Map request = new HashMap<>();
request.put("corpAccessToken", corpAccessToken);
request.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
request.put("corpId", CertificateConstant.CORP_ID);
request.put("data", data);
JSONObject requestJSON = new JSONObject(request);
return requestJSON;
}
//封装更新单据的请求参数
public JSONObject updateCRM(Map data) {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
//封装object_data
Map objectData = new HashMap<>();
objectData.put("object_data", data);
// Map rootData = new HashMap<>();
// rootData.put("data", objectData);
Map request = new HashMap<>();
request.put("corpAccessToken", corpAccessToken);
request.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
request.put("corpId", CertificateConstant.CORP_ID);
request.put("triggerWorkFlow", "false");
request.put("triggerApprovalFlow", "false");
request.put("data", objectData);
JSONObject requestJSON = new JSONObject(request);
return requestJSON;
}
//封装新建单据的请求参数
public JSONObject createCRM(Map map) {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
//封装object_data
Map objectData = new HashMap<>();
objectData.put("object_data", map);
//Map rootData = new HashMap<>();
//rootData.put("data", objectData);
Map request = new HashMap<>();
request.put("corpAccessToken", corpAccessToken);
request.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
request.put("corpId", CertificateConstant.CORP_ID);
request.put("data", objectData);
JSONObject requestJSON = new JSONObject(request);
return requestJSON;
}
/**
* 生成crm请求数据
*
* @param crmId
* @param dataObjectApiName:
* @return com.alibaba.fastjson.JSONObject
* @Author weiloong_zhang
*/
public JSONObject unlockCRM(String crmId, String dataObjectApiName) {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
Map data = new HashMap<>();
data.put("dataIds", Arrays.asList(crmId));
data.put("dataObjectApiName", dataObjectApiName);
Map request = new HashMap<>();
request.put("corpAccessToken", corpAccessToken);
request.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
request.put("corpId", CertificateConstant.CORP_ID);
request.put("data", data);
JSONObject requestJSON = new JSONObject(request);
return requestJSON;
}
public JSONObject crmWithDetail(Map map, Map details) {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
//封装object_data
Map objectData = new HashMap<>();
objectData.put("object_data", map);
objectData.put("details", details);
Map request = new HashMap<>();
request.put("corpAccessToken", corpAccessToken);
request.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
request.put("corpId", CertificateConstant.CORP_ID);
request.put("data", objectData);
JSONObject requestJSON = new JSONObject(request);
return requestJSON;
}
public JSONObject uploadFile(String dataId, String dataObjectApiName, String apiName, Map file) {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
Map fileMap = new HashMap<>();
fileMap.put("_id", dataId);
fileMap.put(apiName, Arrays.asList(file));
fileMap.put("dataObjectApiName", dataObjectApiName);
//封装object_data
Map objectData = new HashMap<>();
objectData.put("object_data", fileMap);
Map request = new HashMap<>();
request.put("corpAccessToken", corpAccessToken);
request.put("currentOpenUserId", CertificateConstant.CURRENT_OPEN_USERID);
request.put("corpId", CertificateConstant.CORP_ID);
request.put("data", objectData);
JSONObject requestJSON = new JSONObject(request);
return requestJSON;
}
public String getCRMToken() {
String corpAccessToken = "";
//判断咖啡因中是否有数据
if (CaffeineCacheUtil.get("corpAccessToken") != null) {
log.info("咖啡因中有缓存的token数据");
corpAccessToken = CaffeineCacheUtil.get("corpAccessToken").toString();
} else {
log.info("咖啡因中不存在token缓存");
//封装请求
Map tokenParams = new HashMap<>();
tokenParams.put("appId", CertificateConstant.APP_ID);
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
JSONObject tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
//判断是否获取成功
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
corpAccessToken = tokenResponse.getString("corpAccessToken");
} else {
log.info("获取纷享销客token失败{}", tokenResponse);
}
}
return corpAccessToken;
}
/**
* 纷享销客文件转码base64
*
* @param fileList
* @return java.lang.String[]
* @Author weiloong_zhang
*/
public MultiValueMap<String, Object> proxyUploadFileToTarget(List<?> fileList, String crmId) {
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("crmId", crmId);
body.add("fieldName", "f9w5_feedbackinfoattach");
if (fileList == null || fileList.isEmpty()) {
log.info("文件列表为空");
return body; // 返回空map而不是null
}
for (Object fileObj : fileList) {
JSONObject fileData = JSON.parseObject(JSON.toJSONString(fileObj));
Map<String, Object> fileReq = new HashMap<>();
fileReq.put("corpAccessToken", getCRMToken());
fileReq.put("corpId", CertificateConstant.CORP_ID);
fileReq.put("mediaTypeDesc", "DOCUMENT");
fileReq.put("mediaId", fileData.getString("path"));
fileReq.put("igonreMediaIdConvert", false);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Map<String, Object>> fileReqEntity = new HttpEntity<>(fileReq, headers);
try {
ResponseEntity<byte[]> fileResp = restTemplate.exchange(
"https://open.fxiaoke.com/media/download",
HttpMethod.POST,
fileReqEntity,
byte[].class);
if (fileResp.getStatusCode() == HttpStatus.OK && fileResp.getBody() != null) {
byte[] fileBytes = fileResp.getBody();
String fileName = fileData.getString("filename");
String contentType = fileData.getString("ext");
ByteArrayResource byteArrayResource = new ByteArrayResource(fileBytes) {
@Override
public String getFilename() {
return fileName != null ? fileName : UUID.randomUUID() + ".dat";
}
};
HttpHeaders fileHeaders = new HttpHeaders();
fileHeaders.setContentDispositionFormData("files", byteArrayResource.getFilename());
try {
fileHeaders.setContentType(MediaType.parseMediaType(
contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM_VALUE));
} catch (Exception e) {
fileHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
}
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(byteArrayResource, fileHeaders);
body.add("files", fileEntity);
} else {
log.error("文件下载失败mediaId: {}", fileData.getString("path"));
}
} catch (Exception e) {
log.error("下载文件出错", e);
}
}
return body;
}
//上传询价单附件
public MultiValueMap<String, Object> attachmentuploadFile(List<?> fileList, Long erpId) {
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
JSONObject args = new JSONObject();
args.put("entityNumber","f9w5_pmp_priceapproval");
args.put("billPkId",erpId);
args.put("controlKey","f9w5_technicalstd");
body.add("attachmentUploadFileArgs", args);
if (fileList == null || fileList.isEmpty()) {
log.info("文件列表为空");
return body; // 返回空map而不是null
}
for (Object fileObj : fileList) {
JSONObject fileData = JSON.parseObject(JSON.toJSONString(fileObj));
Map<String, Object> fileReq = new HashMap<>();
fileReq.put("corpAccessToken", getCRMToken());
fileReq.put("corpId", CertificateConstant.CORP_ID);
fileReq.put("mediaTypeDesc", "DOCUMENT");
fileReq.put("mediaId", fileData.getString("path"));
fileReq.put("igonreMediaIdConvert", false);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Map<String, Object>> fileReqEntity = new HttpEntity<>(fileReq, headers);
try {
ResponseEntity<byte[]> fileResp = restTemplate.exchange(
"https://open.fxiaoke.com/media/download",
HttpMethod.POST,
fileReqEntity,
byte[].class);
if (fileResp.getStatusCode() == HttpStatus.OK && fileResp.getBody() != null) {
byte[] fileBytes = fileResp.getBody();
String fileName = fileData.getString("filename");
String contentType = fileData.getString("ext");
ByteArrayResource byteArrayResource = new ByteArrayResource(fileBytes) {
@Override
public String getFilename() {
return fileName != null ? fileName : UUID.randomUUID() + ".dat";
}
};
HttpHeaders fileHeaders = new HttpHeaders();
fileHeaders.setContentDispositionFormData("file", byteArrayResource.getFilename());
try {
fileHeaders.setContentType(MediaType.parseMediaType(
contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM_VALUE));
} catch (Exception e) {
fileHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
}
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(byteArrayResource, fileHeaders);
body.add("file", fileEntity);
} else {
log.error("文件下载失败mediaId: {}", fileData.getString("path"));
}
} catch (Exception e) {
log.error("下载文件出错", e);
}
}
return body;
}
public MultiValueMap<String, Object> contractFile(List<?> fileList, Long erpId) {
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
JSONObject args = new JSONObject();
args.put("entityNumber","conm_salcontract");
args.put("billPkId",erpId);
args.put("controlKey","attachmentpanel");
body.add("attachmentUploadFileArgs", args);
if (fileList == null || fileList.isEmpty()) {
log.info("文件列表为空");
return body; // 返回空map而不是null
}
for (Object fileObj : fileList) {
JSONObject fileData = JSON.parseObject(JSON.toJSONString(fileObj));
Map<String, Object> fileReq = new HashMap<>();
fileReq.put("corpAccessToken", getCRMToken());
fileReq.put("corpId", CertificateConstant.CORP_ID);
fileReq.put("mediaTypeDesc", "DOCUMENT");
fileReq.put("mediaId", fileData.getString("path"));
fileReq.put("igonreMediaIdConvert", false);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Map<String, Object>> fileReqEntity = new HttpEntity<>(fileReq, headers);
try {
ResponseEntity<byte[]> fileResp = restTemplate.exchange(
"https://open.fxiaoke.com/media/download",
HttpMethod.POST,
fileReqEntity,
byte[].class);
if (fileResp.getStatusCode() == HttpStatus.OK && fileResp.getBody() != null) {
byte[] fileBytes = fileResp.getBody();
String fileName = fileData.getString("filename");
String contentType = fileData.getString("ext");
ByteArrayResource byteArrayResource = new ByteArrayResource(fileBytes) {
@Override
public String getFilename() {
return fileName != null ? fileName : UUID.randomUUID() + ".dat";
}
};
HttpHeaders fileHeaders = new HttpHeaders();
fileHeaders.setContentDispositionFormData("file", byteArrayResource.getFilename());
try {
fileHeaders.setContentType(MediaType.parseMediaType(
contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM_VALUE));
} catch (Exception e) {
fileHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
}
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(byteArrayResource, fileHeaders);
body.add("file", fileEntity);
} else {
log.error("文件下载失败mediaId: {}", fileData.getString("path"));
}
} catch (Exception e) {
log.error("下载文件出错", e);
}
}
return body;
}
}

View File

@ -0,0 +1,63 @@
package com.management.utils;
import com.alibaba.fastjson.JSONObject;
import com.management.constant.ERPURLConstant;
import com.management.controller.KDTokenController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class KingDeeUtils {
private RestTemplate restTemplate = new RestTemplate();
/**
* 根据ERPID和单据类型进行审核
*
* @param ErpId
* @param BillType:
* @return void
* @Author weiloong_zhang
*/
public void audit(String ErpId, String BillType) {
String url = ERPURLConstant.ERP_URL + "/ierp/kapi/v2/f9w5/devportal/operation/submit";
//开始封装参数
Map auditParams = new HashMap();
auditParams.put("erpId", ErpId);
auditParams.put("formId", BillType);
//开始获取accessToken
//开始获取金蝶token
String accessToken = new KDTokenController().getKDAccessTokenTest();
if (accessToken == null || accessToken.equals("")) {
log.info("金蝶token为空或不存在");
return;
}
//开始封装请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("accessToken", accessToken);
HttpEntity auditEntity = new HttpEntity(auditParams, headers);
JSONObject auditResult = new JSONObject();
try {
auditResult = restTemplate.postForObject(url, auditEntity, JSONObject.class);
} catch (RestClientException e) {
e.printStackTrace();
}
System.out.println("审核单据的状态为:" + auditResult);
}
}

View File

@ -0,0 +1,21 @@
package com.management.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class PortConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
}

View File

@ -0,0 +1,24 @@
package com.management.utils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
public class WebUtils {
public static HttpServletRequest getHttpServletRequest(){
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
public static String getContextUrl() {
HttpServletRequest request = getHttpServletRequest();
StringBuffer url = request.getRequestURL();
return url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
}
public static String getUeditorPrefix(){
return getContextUrl();
}
}

View File

@ -0,0 +1,118 @@
server:
port: 18085
compression:
enabled: true
min-response-size: 128
spring:
profiles:
active: dev
servlet:
multipart:
max-file-size: 200MB
max-request-size: 200MB
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://116.204.34.35:13300/zycx?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
druid:
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
initial-size: 5
min-idle: 5
max-active: 1000
# 配置获取连接等待超时的时间
max-wait: 360000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
# 打开PSCache并且指定每个连接上PSCache的大小
pool-prepared-statements: true
# 配置监控统计拦截的filters去掉后监控界面sql无法统计'wall'用于防火墙
max-pool-prepared-statement-per-connection-size: 20
filters: stat,wall
use-global-data-source-stat: true
# 通过connectProperties属性来打开mergeSql功能慢SQL记录
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 配置监控服务器
stat-view-servlet:
login-username: admin
login-password: 123456
reset-enable: false
url-pattern: /druid/*
# 添加IP白名单
#allow:
# 添加IP黑名单当白名单和黑名单重复时黑名单优先级更高
#deny:
web-stat-filter:
# 添加过滤规则
url-pattern: /*
# 忽略过滤格式
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
# 上传路径
upload:
dir: D:/mb/
magic-api:
web: /magic/web
show-sql: true #配置打印SQL
sql-column-case: camel
resource:
location: data/magic-api
backup: #备份相关配置
enable: true #是否启用
max-history: -1 #备份保留天数,-1为永久保留
table-name: magic_backup_record_v2 #使用数据库存储备份时的表名
page:
page: current
size: size
cache:
enable: true #开启缓存,默认是不开启的
ttl: 3600000 #有效期1小时默认-1 即永不过期
response-code:
success: 200 #执行成功的code值
invalid: 400 #参数验证未通过的code值
exception: 500 #执行出现异常的code值
crud: # CRUD相关配置
logic-delete-column: is_del #逻辑删除列
logic-delete-value: 1 #逻辑删除值
# security:
# username: admin
# password: 123456
# Sa-Token配置
sa-token:
# token名称 (同时也是cookie名称)
token-name: token
# token有效期单位s 默认30天, -1代表永不过期
timeout: 2592000
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout: -1
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
is-concurrent: true
# 在多人登录同一账号时是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share: false
# token风格
token-style: uuid
# 是否输出操作日志
is-log: false
oss:
enable: false
endpoint: ""
accessKeyId: ""
accessKeySecret: ""
roleArn: ""
roleSessionName: ""
bucket: ""
bucketDomain: ""

View File

@ -0,0 +1,6 @@
<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
</body>
</html>