文件新增和依赖导入
This commit is contained in:
parent
ad542999d8
commit
8f381fcf3e
BIN
.idea/.cache/.Apifox_Helper/.toolWindow.db
generated
Normal file
BIN
.idea/.cache/.Apifox_Helper/.toolWindow.db
generated
Normal file
Binary file not shown.
6
.idea/ApifoxUploaderProjectSetting.xml
generated
Normal file
6
.idea/ApifoxUploaderProjectSetting.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ApifoxUploaderProjectSetting">
|
||||||
|
<option name="apiAccessToken" value="APS-HmJUYJuF5hJ5jLJ077A0mIPHzZ9igv97" />
|
||||||
|
</component>
|
||||||
|
</project>
|
12
.idea/dataSources.xml
generated
Normal file
12
.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="服务器MySQL" uuid="294ddda2-3c64-4a2f-aed4-88dc75253b2b">
|
||||||
|
<driver-ref>mysql.8</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mysql://116.204.34.35:13300</jdbc-url>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
File diff suppressed because one or more lines are too long
@ -8,9 +8,9 @@ package org.ssssssss.magicboot.constant;
|
|||||||
* @Author weiloong_zhang
|
* @Author weiloong_zhang
|
||||||
*/
|
*/
|
||||||
public class CertificateConstant {
|
public class CertificateConstant {
|
||||||
public static final String APP_ID = "FSAID_131e877";//appId
|
public static final String APP_ID = "FSAID_131f56a";//appId
|
||||||
public static final String PERMANENT_CODE = "F7D7D42D0459407DE48B27B752650B8C";//永久授权码
|
public static final String PERMANENT_CODE = "1A49B50861909007935CAB5E33E52BAA";//永久授权码
|
||||||
public static final String APP_SECRET = "a639cc4bc28c48cb986a4faf6badcb00";//appSecret
|
public static final String APP_SECRET = "5bda722932a54e80a05d2cc9b1722fed";//appSecret
|
||||||
public static final String CORP_ID = "FSCID_1EDEA7F57E23B1E1173B01D4E06B8DD4";//企业Id
|
public static final String CORP_ID = "FSCID_11F505C980B5FE43D5D7230567802E09";//企业Id
|
||||||
public static final String CURRENT_OPEN_USERID = "FSUID_86490ECFD2B8AD9EE361E6DA9B3AC83D";//当前登录用户id
|
public static final String CURRENT_OPEN_USERID = "FSUID_50D3C26809B163F663DC8557268A8D44";//当前登录用户id
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,679 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.format.datetime.DateFormatter;
|
||||||
|
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 org.ssssssss.magicboot.constant.CertificateConstant;
|
||||||
|
import org.ssssssss.magicboot.constant.URLConstant;
|
||||||
|
import org.ssssssss.magicboot.entity.Filter;
|
||||||
|
import org.ssssssss.magicboot.utils.CaffeineCacheUtil;
|
||||||
|
import org.ssssssss.magicboot.utils.CrmRequestUtil;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门集成
|
||||||
|
*
|
||||||
|
* @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", "2020-01-01 00:00:00");
|
||||||
|
data.put("enable", "1");
|
||||||
|
data.put("number", Arrays.asList("ZHY002.001"));
|
||||||
|
// data.put("level", "3");
|
||||||
|
|
||||||
|
Map deptReq = new HashMap<>();
|
||||||
|
deptReq.put("data", data);
|
||||||
|
deptReq.put("pageNo", 1);
|
||||||
|
deptReq.put("pageSize", 1999);
|
||||||
|
|
||||||
|
String accessToken = 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 = "http://192.168.31.121:8022/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:18088/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");
|
||||||
|
//父部门编码
|
||||||
|
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("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 (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))
|
||||||
|
), "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("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:18088/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", "2020-01-01 00:00:00");
|
||||||
|
data.put("enable", "1");
|
||||||
|
//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 = "http://192.168.31.121:8022/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:18088/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");
|
||||||
|
//父部门编码
|
||||||
|
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("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))
|
||||||
|
), "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("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:18088/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 = "http://192.168.31.121:8022/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:18088/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");
|
||||||
|
|
||||||
|
//开始查询CRM
|
||||||
|
JSONObject crmReq = crmRequestUtil.getCRMList(Arrays.asList(
|
||||||
|
new Filter("EQ", "name", Arrays.asList(deptName)),
|
||||||
|
new Filter("EQ", "field_v711K__c", Arrays.asList(parentDeptName))
|
||||||
|
), "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("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:18088/Log/insert/log_data", logMap, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("日志上传状态为:{}", logRes);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,143 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
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 org.ssssssss.magicboot.utils.CaffeineCacheUtil;
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
@PostMapping("/getKD/APP_token")
|
||||||
|
public String getKDAppToken() {
|
||||||
|
log.info("开始获取金蝶的AppToken");
|
||||||
|
|
||||||
|
//开始封装
|
||||||
|
//接口地址
|
||||||
|
String appTokenUrl = "http://192.168.31.121:8022/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
|
||||||
|
*/
|
||||||
|
@PostMapping("/getKD/access_token")
|
||||||
|
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 = "http://192.168.31.121:8022/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;
|
||||||
|
}
|
||||||
|
}
|
@ -45,6 +45,7 @@ public class CrmRequestUtil {
|
|||||||
//判断是否获取成功
|
//判断是否获取成功
|
||||||
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
|
if (tokenResponse.containsKey("errorMessage") && tokenResponse.getString("errorMessage").equals("success")) {
|
||||||
corpAccessToken = tokenResponse.getString("corpAccessToken");
|
corpAccessToken = tokenResponse.getString("corpAccessToken");
|
||||||
|
CaffeineCacheUtil.put("corpAccessToken", corpAccessToken);
|
||||||
} else {
|
} else {
|
||||||
log.info("获取纷享销客token失败{}", tokenResponse);
|
log.info("获取纷享销客token失败{}", tokenResponse);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user