|
@@ -0,0 +1,114 @@
|
|
|
+/*
|
|
|
+ * Copyright 2019-2020 Zheng Jie
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+package me.zhengjie.modules.quartz.task;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.zhengjie.modules.system.domain.Dept;
|
|
|
+import me.zhengjie.modules.system.service.DeptService;
|
|
|
+import me.zhengjie.modules.system.service.dto.DeptDto;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * ERP 数据同步
|
|
|
+ * @author Sky
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Component
|
|
|
+public class ErpDataSyncTask {
|
|
|
+
|
|
|
+ private final String erpApiUrl = "http://222.84.157.37:30170";
|
|
|
+ private final String sign = "e34b2f59-0e9d-45ed-a32a-f4abd4381000";
|
|
|
+ private final String header_key = "X_AUTO_USER_INFO_HEAD";
|
|
|
+ private final String header_value = "{\"id\":\"anonymous\",\"tenantId\":\"caih\"}";
|
|
|
+
|
|
|
+ private final DeptService deptService;
|
|
|
+
|
|
|
+ public void run() {
|
|
|
+ log.info("deptsync 执行开始");
|
|
|
+ deptsync();
|
|
|
+ log.info("deptsync 执行结束");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 部门数据同步
|
|
|
+ */
|
|
|
+ private void deptsync() {
|
|
|
+
|
|
|
+ String res = HttpRequest.get(erpApiUrl + "/api-third-party/busi/comm/usky/queryGroup")
|
|
|
+ .header(header_key, header_value)
|
|
|
+ .body("{\n" +
|
|
|
+ " \"formData\":{\n" +
|
|
|
+ " \"pageNum\":1,\n" +
|
|
|
+ " \"pageSize\":100\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"product\":\"17\",\n" +
|
|
|
+ " \"sign\":\"" + sign + "\"\n" +
|
|
|
+ "}").execute().body();
|
|
|
+ JSONObject json = JSONObject.parseObject(res);
|
|
|
+ JSONArray datas = json.getJSONArray("data");
|
|
|
+ JSONObject item;
|
|
|
+ Dept dept;
|
|
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
+ item = datas.getJSONObject(i);
|
|
|
+ dept = new Dept();
|
|
|
+ dept.setId(item.getString("groupId"));
|
|
|
+ dept.setName(item.getString("groupName"));
|
|
|
+
|
|
|
+ if(item.getString("parentId").equals("~")){
|
|
|
+ dept.setPid(null);
|
|
|
+ }else{
|
|
|
+ dept.setPid(item.getString("parentId"));
|
|
|
+ }
|
|
|
+ dept.setDeptSort(item.getInteger("sort"));
|
|
|
+ dept.setEnabled(item.getBoolean("groupStatus"));
|
|
|
+ dept.setTreeNames(item.getString("groupNamePath"));
|
|
|
+ dept.setTreeIds(item.getString("groupIdPath"));
|
|
|
+ dept.setDeptType(item.getInteger("groupType"));
|
|
|
+
|
|
|
+ DeptDto deptDto = deptService.findById(item.getString("groupId"));
|
|
|
+
|
|
|
+ if (deptDto != null) {
|
|
|
+ deptService.update(dept);
|
|
|
+ } else {
|
|
|
+ deptService.create(dept);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人员数据同步
|
|
|
+ */
|
|
|
+ private void usersyncbydepid(String depid) {
|
|
|
+ String res = HttpRequest.get(erpApiUrl + "/api-third-party/busi/comm/usky/queryUser")
|
|
|
+ .header(header_key, header_value)
|
|
|
+ .body("{\n" +
|
|
|
+ " \"formData\":{\n" +
|
|
|
+ " \"pageNum\":1,\n" +
|
|
|
+ " \"pageSize\":100\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"product\":\"17\",\n" +
|
|
|
+ " \"sign\":\"" + sign + "\"\n" +
|
|
|
+ "}").execute().body();
|
|
|
+ JSONObject json = JSONObject.parseObject(res);
|
|
|
+ JSONArray datas = json.getJSONArray("data");
|
|
|
+
|
|
|
+ }
|
|
|
+}
|