更新
This commit is contained in:
parent
9c8b1aa500
commit
71a2889878
@ -0,0 +1,323 @@
|
||||
package org.ssssssss.magicboot.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.ssssssss.magicboot.fxapi.HttpClientResult;
|
||||
import org.ssssssss.magicboot.fxapi.HttpClientUtils;
|
||||
import org.ssssssss.magicboot.fxapi.XKTokenAccess;
|
||||
import org.ssssssss.magicboot.zdyutils.FXHTTP;
|
||||
import org.ssssssss.magicboot.zdyutils.FXTIC;
|
||||
import org.ssssssss.magicboot.zdyutils.GcjJson;
|
||||
import org.ssssssss.magicboot.zdyutils.MagicApi;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 人员同步
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/Cost")
|
||||
|
||||
public class CostController {
|
||||
private final Logger log = LoggerFactory.getLogger(CostController.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new CostController().getUserData();
|
||||
new CostController().saveSynUser();
|
||||
}
|
||||
|
||||
@PostMapping("/getUserData")
|
||||
public void getUserData() throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String time = sdf.format(System.currentTimeMillis() - (1000 * 60 * 62 * 24));
|
||||
// time = "2024-05-01";
|
||||
String sendUrl = "https://lxr2.zhydsp.cn:40448/ierp/kapi/v2/f9w5/base/bos_user/userQuery";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//String accessToken = "2096108315279888384_8elReBSzvx315JiLWiH82YKJGosF3G2kN688q05rHUritX9x3fWS3lmetalPeMe3HceZV7fK1GdSJsk1J46A3S0VkOxIUqf7wnS207";
|
||||
String accessToken = new KDTokenController().getKDAccessToken();
|
||||
|
||||
if (accessToken == null || accessToken.equals("")) {
|
||||
log.info("金蝶token为空或不存在");
|
||||
return;
|
||||
}
|
||||
headers.put("accessToken", accessToken);//放token
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
|
||||
JSONObject datajson = new JSONObject();
|
||||
datajson.put("createtime", "2012-02-26 11:04:43");
|
||||
JSONArray arr = new JSONArray();
|
||||
String[] strings = {
|
||||
"苗依达"
|
||||
};
|
||||
|
||||
// 将字符串添加到 JSONArray 中
|
||||
for (String str : strings) {
|
||||
arr.add(str);
|
||||
}
|
||||
|
||||
|
||||
datajson.put("name", arr);
|
||||
|
||||
|
||||
params.put("data", datajson);
|
||||
params.put("pageNo", 1);
|
||||
params.put("pageSize", 1000);
|
||||
|
||||
|
||||
HttpClientResult rtn = HttpClientUtils.doPostJson(sendUrl, headers, params.toJSONString());
|
||||
String resStr = rtn.getContent();
|
||||
JSONObject resjs = JSONObject.parseObject(resStr);
|
||||
if (resjs != null) {
|
||||
if ("0".equals(resjs.getString("errorCode"))) {//查询成功
|
||||
JSONObject data = resjs.getJSONObject("data");
|
||||
System.out.println("查询人员总数量" + data.getInteger("totalCount"));
|
||||
JSONArray resJson = data.getJSONArray("rows");
|
||||
|
||||
System.out.println("待同步人员数量" + resJson.size());
|
||||
|
||||
for (int i = 0; i < resJson.size(); i++) {
|
||||
JSONObject str = resJson.getJSONObject(i);
|
||||
//ERPID
|
||||
String dataId = GcjJson.getNodeValue(str, "JSON.id") != null ? GcjJson.getNodeValue(str, "JSON.id").toString() : "";
|
||||
//ERP人员编码
|
||||
String number = GcjJson.getNodeValue(str, "JSON.number") != null ? GcjJson.getNodeValue(str, "JSON.number").toString() : "";
|
||||
|
||||
String name = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : "";
|
||||
|
||||
String endtime = GcjJson.getNodeValue(str, "JSON.modifytime") != null ? GcjJson.getNodeValue(str, "JSON.modifytime").toString() : "";
|
||||
|
||||
String syn_type = "0";//同步类型 0新增 1修改 2删除
|
||||
log.info("-------------------开始执行人员" + i + " -------------------" + number);
|
||||
XxlJobHelper.log("-------------------开始执行人员" + i + " -------------------" + number);
|
||||
|
||||
Boolean sendFlag = false;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
|
||||
try {
|
||||
boolean tbflag = false;
|
||||
//验证数据是否已存在
|
||||
JSONObject dataSyn = MagicApi.getSendSYNUser("user", syn_type, dataId);
|
||||
|
||||
if (dataSyn != null && endtime.equals(dataSyn.getString("mark"))) {
|
||||
log.info("数据已存在-" + name);
|
||||
XxlJobHelper.log("--数据已存在---" + name);
|
||||
tbflag = true;
|
||||
}
|
||||
|
||||
if (tbflag) {
|
||||
continue;
|
||||
}
|
||||
log.info("人员待同步数据-" + i + " ------" + name);
|
||||
|
||||
JSONObject jsonObjectData = new JSONObject();
|
||||
jsonObjectData.put("send_type", "user"); //业务类型
|
||||
jsonObjectData.put("send_syn", syn_type); //同步类型 0新增 1修改 2删除
|
||||
jsonObjectData.put("dsf_id", dataId);//数据id
|
||||
jsonObjectData.put("dsfzhu_id", dataId);//数据id
|
||||
jsonObjectData.put("send_status", 3);//同步状态 true同步成功 false同步失败 3待同步
|
||||
jsonObjectData.put("dsf_code", name);//数据名称
|
||||
jsonObjectData.put("mark", endtime);//标识
|
||||
jsonObjectData.put("dsf_json", str.toJSONString());//标识
|
||||
|
||||
MagicApi.saveSendSYNUser(jsonObjectData);
|
||||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@PostMapping("/getSynProduct")
|
||||
public void saveSynUser() throws Exception {
|
||||
FXHTTP fxapi = new FXHTTP();
|
||||
String resJsonStr = MagicApi.getWNRES("http://127.0.0.1:18088/syn/queryuser?sendType=user&sendStatus=3", "");
|
||||
JSONObject resJson = JSON.parseObject(resJsonStr);
|
||||
if (resJson != null) {
|
||||
log.info("待同步人员数" + resJson.getJSONArray("data").size());
|
||||
for (int i = 0; i < resJson.getJSONArray("data").size(); i++) {
|
||||
XKTokenAccess xktonken = new XKTokenAccess();
|
||||
JSONObject getData = resJson.getJSONArray("data").getJSONObject(i);
|
||||
JSONObject str = getData.getJSONObject("dsfJson");
|
||||
String syn_type = "0";//同步类型 0新增 1修改 2删除
|
||||
Boolean sendFlag = false;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
boolean tbflag = false;
|
||||
// 构建json
|
||||
JSONObject obj = new JSONObject();
|
||||
LinkedHashMap map = new LinkedHashMap<String, Object>();
|
||||
Boolean flag = true;
|
||||
//ID
|
||||
String dataId = GcjJson.getNodeValue(str, "JSON.id") != null ? GcjJson.getNodeValue(str, "JSON.id").toString() : "";
|
||||
//编码
|
||||
String number = GcjJson.getNodeValue(str, "JSON.number") != null ? GcjJson.getNodeValue(str, "JSON.number").toString() : "";
|
||||
|
||||
String name = GcjJson.getNodeValue(str, "JSON.name") != null ? GcjJson.getNodeValue(str, "JSON.name").toString() : "";
|
||||
|
||||
//最后修改时间
|
||||
String endtime = GcjJson.getNodeValue(str, "JSON.modifytime") != null ? GcjJson.getNodeValue(str, "JSON.modifytime").toString() : "";
|
||||
//性别
|
||||
String gender = GcjJson.getNodeValue(str, "JSON.gender") != null ? GcjJson.getNodeValue(str, "JSON.gender").toString() : "";
|
||||
|
||||
String email = GcjJson.getNodeValue(str, "JSON.email") != null ? GcjJson.getNodeValue(str, "JSON.email").toString() : "";
|
||||
|
||||
String phone = GcjJson.getNodeValue(str, "JSON.phone") != null ? GcjJson.getNodeValue(str, "JSON.phone").toString() : "";
|
||||
|
||||
//状态
|
||||
String enable = GcjJson.getNodeValue(str, "JSON.enable") != null ? GcjJson.getNodeValue(str, "JSON.enable").toString() : "";
|
||||
|
||||
|
||||
JSONArray entryentity = str.getJSONArray("entryentity");
|
||||
String deptNumber = "";
|
||||
String position = "";
|
||||
if (entryentity != null) {
|
||||
JSONObject deptobj = (JSONObject) entryentity.get(0);
|
||||
deptNumber = deptobj.getString("dpt_number");
|
||||
position = deptobj.getString("position");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
JSONObject dataSyn = MagicApi.getSendSYNDataUser("user", syn_type, dataId, "3");
|
||||
if (dataSyn != null && dataId.equals(dataSyn.getString("dsfId")) && endtime.equals(dataSyn.getString("mark"))) {
|
||||
log.info("数据已存在-" + name);
|
||||
XxlJobHelper.log("--数据已存在---" + name);
|
||||
tbflag = true;
|
||||
}
|
||||
if (tbflag) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//查询人员CRMID
|
||||
String crmId = fxapi.getDataBYID("PersonnelObj", "field_T1xid__c", number, "JSON.data.dataList[0]._id");
|
||||
if (crmId != null && !crmId.equals("")) {
|
||||
//人员id
|
||||
map.put("body.data.object_data._id", crmId);
|
||||
flag = false;
|
||||
}
|
||||
String crmdeptID = "999999";
|
||||
if (deptNumber != "") {
|
||||
crmdeptID = fxapi.getDataBYID("DepartmentObj", "field_Vj6sf__c", deptNumber, "JSON.data.dataList[0]._id");
|
||||
System.out.println(crmdeptID);
|
||||
}
|
||||
|
||||
map.put("body.data.object_data.phone", phone);
|
||||
map.put("body.data.object_data.name", name);
|
||||
map.put("body.data.object_data.full_name", name);
|
||||
map.put("body.data.object_data.erp_id__c", dataId);//ID
|
||||
map.put("body.data.object_data.field_T1xid__c", number);//编码
|
||||
map.put("body.data.object_data.user_name", phone);
|
||||
map.put("body.data.object_data.email", email);
|
||||
map.put("body.data.object_data.position", position);
|
||||
|
||||
if (enable.equals("2")) {
|
||||
map.put("body.data.object_data.status", "1");
|
||||
map.put("body.data.object_data.is_pause_login", true);
|
||||
} else {
|
||||
map.put("body.data.object_data.status", "0");
|
||||
map.put("body.data.object_data.is_pause_login", false);
|
||||
}
|
||||
if (gender.equals("1")) {
|
||||
map.put("body.data.object_data.sex", "M");
|
||||
|
||||
}
|
||||
if (gender.equals("2")) {
|
||||
map.put("body.data.object_data.sex", "F");
|
||||
|
||||
} else {
|
||||
map.put("body.data.object_data.sex", "P");
|
||||
}
|
||||
map.put("body.data.object_data.main_department[0]", crmdeptID);//主属部门
|
||||
|
||||
map.put("body.data.object_data.dataObjectApiName", "PersonnelObj");
|
||||
|
||||
map.put("body.corpId", FXTIC.CORPID);
|
||||
map.put("body.corpAccessToken", xktonken.getCorpAccessToken().getCorpAccessToken());
|
||||
map.put("body.currentOpenUserId", FXTIC.CURRENTOPENUSERID);
|
||||
for (Object key : map.keySet()) {
|
||||
GcjJson.setNodeValue(obj, key.toString(), map.get(key));
|
||||
}
|
||||
log.info("--请求json---" + obj);
|
||||
XxlJobHelper.log("--请求json---" + obj);
|
||||
|
||||
} catch (Exception e) {
|
||||
sendFlag = true;
|
||||
stringBuffer.append("参数解析错误,请联系开发人员");
|
||||
e.printStackTrace();
|
||||
}
|
||||
getSynDataSave(stringBuffer, sendFlag, flag, fxapi, dataId, name, obj, getData);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写数据
|
||||
*/
|
||||
public void getSynDataSave(StringBuffer stringBuffer, Boolean sendFlag, Boolean flag, FXHTTP fxapi, String dataId, String nameData, JSONObject obj, JSONObject str) {
|
||||
String syn_type = "0";//同步类型 0新增 1修改 2删除
|
||||
String res_url = "";
|
||||
String res_param = "";
|
||||
String res = "";
|
||||
try {
|
||||
if (flag) {
|
||||
res = fxapi.saveV2Obj(obj);
|
||||
res_url = FXTIC.URL_FX_CREATE;
|
||||
} else {
|
||||
syn_type = "1";
|
||||
res = fxapi.updateV2Obj(obj);
|
||||
res_url = FXTIC.URL_FX_UPDATE;
|
||||
}
|
||||
res_param = obj.toJSONString();
|
||||
log.info("返回值:" + res);
|
||||
JSONObject resjs = JSON.parseObject(res);
|
||||
if (resjs != null && "0".equals(resjs.getString("errorCode"))) {
|
||||
|
||||
} else {
|
||||
sendFlag = true;
|
||||
stringBuffer.append(resjs.getString("errorMessage") + "");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sendFlag = true;
|
||||
stringBuffer.append("纷享销客接口调用失败,请检查网络配置");
|
||||
}
|
||||
JSONObject sendData = new JSONObject();
|
||||
sendData.put("send_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步
|
||||
sendData.put("crm_code", nameData);//数据名称
|
||||
sendData.put("send_id", str.getString("sendId")); //send_id
|
||||
MagicApi.updateSendSYUPDATENUser(sendData);
|
||||
|
||||
JSONObject logData = new JSONObject();
|
||||
logData.put("log_type", "user"); //业务类型
|
||||
logData.put("log_status", !sendFlag);//同步状态 true同步成功 false同步失败 3待同步
|
||||
logData.put("syn_type", syn_type);//同步类型 0新增 1修改 2删除
|
||||
logData.put("data_id", dataId);//数据id
|
||||
logData.put("data_name", nameData);//数据名称
|
||||
logData.put("res_body", "同步成功");//返回值
|
||||
logData.put("res_url", res_url);//
|
||||
logData.put("res_param", res_param);//
|
||||
logData.put("res_res", res);//
|
||||
if (sendFlag) {
|
||||
logData.put("res_body", stringBuffer.toString());//返回值
|
||||
}
|
||||
//写入传输日志
|
||||
MagicApi.saveUserLog(logData);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ public class materialreqbillXTController {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new materialreqbillXTController().getSynDataAdd();
|
||||
new materialreqbillXTController().materialreqbillSave();
|
||||
//new materialreqbillXTController().doOperation("682f14a051a7140001ecc663","audit");
|
||||
// new materialreqbillXTController().doOperation("68356982c826f00001e61b75","audit");
|
||||
}
|
||||
|
||||
public void getSynDataAdd() throws Exception {
|
||||
@ -154,7 +154,7 @@ public class materialreqbillXTController {
|
||||
|
||||
JSONArray dataarr = new JSONArray();
|
||||
JSONObject datajson = new JSONObject();
|
||||
|
||||
datajson.put("billno",nameData);
|
||||
//datajson.put("org_number","zyierp");
|
||||
datajson.put("org","ZHY");
|
||||
datajson.put("bizorg","ZHY");
|
||||
@ -166,7 +166,7 @@ public class materialreqbillXTController {
|
||||
datajson.put("erpId",sjerpid);//设计文件erpID //design_file_ERPID__c
|
||||
|
||||
//编号
|
||||
// datajson.put("billno",nameData);
|
||||
|
||||
//datajson.put("comment",remark);
|
||||
|
||||
|
||||
@ -200,7 +200,7 @@ public class materialreqbillXTController {
|
||||
|
||||
groupstandardjson.put("crmentryid",GcjJson.getNodeValue(stra, "JSON._id"));
|
||||
|
||||
groupstandardjson.put("tracknumber_number",GcjJson.getNodeValue(stra, "JSON.shipping_tracking_number__c"));
|
||||
groupstandardjson.put("tracknumber",GcjJson.getNodeValue(stra, "JSON.shipping_tracking_number__c"));
|
||||
|
||||
|
||||
groupstandardarr.add(groupstandardjson);
|
||||
@ -245,6 +245,7 @@ public class materialreqbillXTController {
|
||||
JSONObject resjs = JSONObject.parseObject(resStr);
|
||||
res = resStr;
|
||||
if (resjs != null && resjs.getBoolean("status")) {
|
||||
System.out.println(resjs);
|
||||
JSONObject successdata = resjs.getJSONObject("data");
|
||||
JSONArray result = successdata.getJSONArray("result");
|
||||
JSONObject erpdata = (JSONObject) result.get(0);
|
||||
@ -253,7 +254,7 @@ public class materialreqbillXTController {
|
||||
Map<String, Object> paramMap = new HashMap<String, Object>();
|
||||
paramMap.put("erp_id__c", erpid);//数据ID
|
||||
paramMap.put("sync_status__c", "option_sync_success__c");
|
||||
paramMap.put("sync_info__c", resjs.getString("message"));
|
||||
paramMap.put("sync_info__c", "同步成功");
|
||||
//回写json
|
||||
fxapi.upSynZDYFieldParam("", "shipping_application__c", dataId, paramMap);
|
||||
//调用提交
|
||||
@ -324,7 +325,6 @@ public class materialreqbillXTController {
|
||||
String crmid = successdata.getString("crmid");
|
||||
String erpid = successdata.getString("pkId");
|
||||
String billno = successdata.getString("billno");
|
||||
|
||||
}else{
|
||||
//响应的消息
|
||||
String message = resjs.getString("message");
|
||||
|
@ -58,7 +58,7 @@ public class priceapprovaController {
|
||||
);*/
|
||||
|
||||
|
||||
List<CrmFXApiParam> paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "BJD-2025-05-230001"));
|
||||
List<CrmFXApiParam> paramList = Arrays.asList(new CrmFXApiParam("EQ", "name", "BJD-2025-05-270002"));
|
||||
|
||||
JSONObject jsonject = fxapi.getSynNewDataObj(true, "项目报价询价", apiName, paramList);
|
||||
JSONArray array = jsonject.getJSONObject("data").getJSONArray("dataList");
|
||||
@ -221,8 +221,8 @@ public class priceapprovaController {
|
||||
groupstandardjson.put("user_operatornumber","ID-000016");
|
||||
groupstandardjson.put("dept_number","004");
|
||||
//供应商编码
|
||||
// groupstandardjson.put("supplierid_number",GcjJson.getNodeValue(stra, "JSON.supplier_code__c"));
|
||||
groupstandardjson.put("supplierid_number","Sup-000001");
|
||||
groupstandardjson.put("supplierid_number",GcjJson.getNodeValue(stra, "JSON.supplier_code__c"));
|
||||
// groupstandardjson.put("supplierid_number","Sup-000001");
|
||||
|
||||
groupstandardjson.put("f9w5_mtdescription",GcjJson.getNodeValue(stra, "JSON.material_description__c"));
|
||||
groupstandardjson.put("f9w5_modelnum",GcjJson.getNodeValue(stra, "JSON.specification_model__c"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user