|
@@ -35,11 +35,11 @@ import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
- * IOT骞冲彴鍚屾�浜嬪姟
|
|
|
+ * IOT平台同步事务
|
|
|
*/
|
|
|
public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFacadeControllerBean {
|
|
|
private static Logger logger = Logger.getLogger(SyncTranForIOTFacadeControllerBean.class);
|
|
|
- //缂撳瓨
|
|
|
+ //缓存
|
|
|
private static ExpiringMapCache<String, String> cache = new ExpiringMapCache();
|
|
|
private Properties propt = new Properties();
|
|
|
private static Map<String, Integer> adminOrgStatusMap = new HashMap<String, Integer>();
|
|
@@ -50,7 +50,7 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
propt.load(new FileInputStream(syncOAConfigPath));
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- String errorMsg = "鑾峰彇閰嶇疆鏂囦欢鎶ラ敊锛岃�妫€鏌ラ厤缃�細" + syncOAConfigPath + " " + e.getMessage();
|
|
|
+ String errorMsg = "获取配置文件报错,请检查配置:" + syncOAConfigPath + " " + e.getMessage();
|
|
|
throw new BOSException(errorMsg);
|
|
|
}
|
|
|
}
|
|
@@ -58,43 +58,43 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
private static Map<String, String> personStatusMap = new HashMap<String, String>();
|
|
|
|
|
|
static {
|
|
|
- adminOrgStatusMap.put("闆嗗洟", 1);//闆嗗洟
|
|
|
- adminOrgStatusMap.put("鍏�徃", 2);//鍏�徃
|
|
|
- adminOrgStatusMap.put("涓€绾х粍缁�", 3);//涓€绾х粍缁� 鍖哄煙
|
|
|
- adminOrgStatusMap.put("浜岀骇缁勭粐", 4);//浜岀骇缁勭粐 鍒嗗叕鍙�
|
|
|
- adminOrgStatusMap.put("涓夌骇缁勭粐", 5);//涓夌骇缁勭粐 瀛愬叕鍙�
|
|
|
- adminOrgStatusMap.put("鍥涚骇缁勭粐", 6);//鍥涚骇缁勭粐 绠$悊
|
|
|
+ adminOrgStatusMap.put("集团", 1);//集团
|
|
|
+ adminOrgStatusMap.put("公司", 2);//公司
|
|
|
+ adminOrgStatusMap.put("一级组织", 3);//一级组织 区域
|
|
|
+ adminOrgStatusMap.put("二级组织", 4);//二级组织 分公司
|
|
|
+ adminOrgStatusMap.put("三级组织", 5);//三级组织 子公司
|
|
|
+ adminOrgStatusMap.put("四级组织", 6);//四级组织 管理
|
|
|
|
|
|
- personStatusMap.put("001", "1");//璇曠敤鍛樺伐
|
|
|
- personStatusMap.put("011", "1");//寰呭矖
|
|
|
- personStatusMap.put("006", "1");//闀挎湡鐥呭亣
|
|
|
- personStatusMap.put("007", "1");//鍋滆柂鐣欒亴
|
|
|
- personStatusMap.put("005", "1");//鍑哄浗
|
|
|
- personStatusMap.put("012", "1");//杩旇仒鍛樺伐
|
|
|
- personStatusMap.put("031", "1");//闀垮�
|
|
|
- personStatusMap.put("S01", "1");//瀹炰範鐢�
|
|
|
- personStatusMap.put("S02", "1");//鍔冲姟娲鹃仯
|
|
|
- personStatusMap.put("S05", "1");//寰呭垎閰�
|
|
|
- personStatusMap.put("S03", "1");//椤鹃棶
|
|
|
- personStatusMap.put("S20", "1");//涓存椂宸�
|
|
|
- personStatusMap.put("002", "3");//杈為€€
|
|
|
- personStatusMap.put("010", "3");//杈炶亴
|
|
|
- personStatusMap.put("009", "3");//閫€浼�
|
|
|
- personStatusMap.put("003", "3");//涓嬪矖
|
|
|
- personStatusMap.put("004", "3");//绂讳紤
|
|
|
- personStatusMap.put("013", "3");//寮€闄�
|
|
|
- personStatusMap.put("020", "3");//瑙h仒
|
|
|
- personStatusMap.put("021", "3");//澶辫釜
|
|
|
- personStatusMap.put("030", "3");//姝讳骸
|
|
|
- personStatusMap.put("S04", "3");//杩旇仒缁堟�
|
|
|
- personStatusMap.put("S08", "3");//绂昏亴
|
|
|
- personStatusMap.put("S09", "3");//娲鹃仯缁堟�
|
|
|
- personStatusMap.put("035", "3");//涓存椂宸ョ粓姝�
|
|
|
- personStatusMap.put("S07", "3");//瀹炰範缁堟�
|
|
|
+ personStatusMap.put("001", "1");//试用员工
|
|
|
+ personStatusMap.put("011", "1");//待岗
|
|
|
+ personStatusMap.put("006", "1");//长期病假
|
|
|
+ personStatusMap.put("007", "1");//停薪留职
|
|
|
+ personStatusMap.put("005", "1");//出国
|
|
|
+ personStatusMap.put("012", "1");//返聘员工
|
|
|
+ personStatusMap.put("031", "1");//长学
|
|
|
+ personStatusMap.put("S01", "1");//实习生
|
|
|
+ personStatusMap.put("S02", "1");//劳务派遣
|
|
|
+ personStatusMap.put("S05", "1");//待分配
|
|
|
+ personStatusMap.put("S03", "1");//顾问
|
|
|
+ personStatusMap.put("S20", "1");//临时工
|
|
|
+ personStatusMap.put("002", "3");//辞退
|
|
|
+ personStatusMap.put("010", "3");//辞职
|
|
|
+ personStatusMap.put("009", "3");//退休
|
|
|
+ personStatusMap.put("003", "3");//下岗
|
|
|
+ personStatusMap.put("004", "3");//离休
|
|
|
+ personStatusMap.put("013", "3");//开除
|
|
|
+ personStatusMap.put("020", "3");//解聘
|
|
|
+ personStatusMap.put("021", "3");//失踪
|
|
|
+ personStatusMap.put("030", "3");//死亡
|
|
|
+ personStatusMap.put("S04", "3");//返聘终止
|
|
|
+ personStatusMap.put("S08", "3");//离职
|
|
|
+ personStatusMap.put("S09", "3");//派遣终止
|
|
|
+ personStatusMap.put("035", "3");//临时工终止
|
|
|
+ personStatusMap.put("S07", "3");//实习终止
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Iot骞冲彴閮ㄩ棬淇℃伅鍚屾�
|
|
|
+ * Iot平台部门信息同步
|
|
|
*
|
|
|
* @param ctx
|
|
|
* @param billds
|
|
@@ -112,7 +112,7 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
logger.error("_syncOrgUnitToOA---billds: " + billds);
|
|
|
IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
|
|
|
//String actionType = action == null ? "" : action.getValue().toLowerCase();
|
|
|
- //褰撳弬鏁癰illIds涓嶄负绌哄€兼椂锛屽�閲忓悓姝ュ弬鏁颁腑鐨勯儴闂ㄦ暟鎹�埌OA
|
|
|
+ //当参数billIds不为空值时,增量同步参数中的部门数据到OA
|
|
|
FilterInfo filterInfo = new FilterInfo();
|
|
|
FilterItemCollection filterItems = filterInfo.getFilterItems();
|
|
|
filterItems.add(new FilterItemInfo("id", "00000000-0000-0000-0000-000000000000CCE7AED4", CompareType.NOTEQUALS));
|
|
@@ -141,29 +141,29 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
|
|
|
AdminOrgUnitCollection adminOrgUnitCollection = iAdminOrgUnit.getAdminOrgUnitCollection(entityViewInfo);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("dataSyncRule", 1);//1锛氱粍缁嘔D瀛樺湪鏃舵洿鏂� 2锛氱粍缁嘔D瀛樺湪鏃惰烦杩囦笉鏇存柊銆傞粯璁ゅ€�1
|
|
|
+ jsonObject.put("dataSyncRule", 1);//1:组织ID存在时更新 2:组织ID存在时跳过不更新。默认值1
|
|
|
List dataList = new ArrayList();
|
|
|
|
|
|
for (int i = 0; i < adminOrgUnitCollection.size(); i++) {
|
|
|
Map adminMap = new HashMap();
|
|
|
AdminOrgUnitInfo adminOrgUnitInfo = adminOrgUnitCollection.get(i);
|
|
|
- OrgUnitLayerTypeInfo unitLayerType = adminOrgUnitInfo.getUnitLayerType();//琛屾斂缁勭粐绫诲瀷
|
|
|
+ OrgUnitLayerTypeInfo unitLayerType = adminOrgUnitInfo.getUnitLayerType();//行政组织类型
|
|
|
String number = unitLayerType.getNumber();
|
|
|
String adminOrgType = String.valueOf(adminOrgStatusMap.getOrDefault(number, 8));
|
|
|
- adminMap.put("id", adminOrgUnitInfo.getId().toString());//鏉ユ簮鏂圭粍缁嘔D
|
|
|
- adminMap.put("code", adminOrgUnitInfo.getNumber());//缁勭粐缂栫爜
|
|
|
- adminMap.put("name", adminOrgUnitInfo.getName());//缁勭粐鍚嶇О
|
|
|
- adminMap.put("type", adminOrgType);//缁勭粐绫诲瀷
|
|
|
- adminMap.put("description", "");//鎻忚堪淇℃伅
|
|
|
- adminMap.put("parentId", adminOrgUnitInfo.getParent().getId().toString());//鏉ユ簮鏂逛笂绾х粍缁嘔D
|
|
|
+ adminMap.put("id", adminOrgUnitInfo.getId().toString());//来源方组织ID
|
|
|
+ adminMap.put("code", adminOrgUnitInfo.getNumber());//组织编码
|
|
|
+ adminMap.put("name", adminOrgUnitInfo.getName());//组织名称
|
|
|
+ adminMap.put("type", adminOrgType);//组织类型
|
|
|
+ adminMap.put("description", "");//描述信息
|
|
|
+ adminMap.put("parentId", adminOrgUnitInfo.getParent().getId().toString());//来源方上级组织ID
|
|
|
Map params = new HashMap();
|
|
|
boolean isSealUp = adminOrgUnitInfo.isIsSealUp();
|
|
|
params.put("status", isSealUp ? "1" : "0");
|
|
|
- adminMap.put("params", params);//缁勭粐鍙傛暟锛堟墿灞曞瓧娈碉級
|
|
|
+ adminMap.put("params", params);//组织参数(扩展字段)
|
|
|
dataList.add(adminMap);
|
|
|
}
|
|
|
- jsonObject.put("data", dataList);//1锛氱粍缁嘔D瀛樺湪鏃舵洿鏂� 2锛氱粍缁嘔D瀛樺湪鏃惰烦杩囦笉鏇存柊銆傞粯璁ゅ€�1
|
|
|
- //鎵ц�鍚屾�缁勭粐鍒癐ot
|
|
|
+ jsonObject.put("data", dataList);//1:组织ID存在时更新 2:组织ID存在时跳过不更新。默认值1
|
|
|
+ //执行同步组织到Iot
|
|
|
return syncOrg(jsonObject.toString(), syncLogInfo, ctx);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -172,7 +172,7 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Iot骞冲彴浜哄憳淇℃伅鍚屾�
|
|
|
+ * Iot平台人员信息同步
|
|
|
*
|
|
|
* @param ctx
|
|
|
* @param billds
|
|
@@ -209,35 +209,36 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
|
|
|
PersonPositionCollection personPositionCollection = iPersonPosition.getPersonPositionCollection(entityViewInfo);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("dataSyncRule", 1);//1锛氱粍缁嘔D瀛樺湪鏃舵洿鏂� 2锛氱粍缁嘔D瀛樺湪鏃惰烦杩囦笉鏇存柊銆傞粯璁ゅ€�1
|
|
|
+ jsonObject.put("dataSyncRule", 1);//1:组织ID存在时更新 2:组织ID存在时跳过不更新。默认值1
|
|
|
List dataList = new ArrayList();
|
|
|
for (int i = 0; i < personPositionCollection.size(); i++) {
|
|
|
Map personMap = new HashMap();
|
|
|
PersonPositionInfo personPositionInfo = personPositionCollection.get(i);
|
|
|
PersonInfo person = personPositionInfo.getPerson();
|
|
|
- //personMap.put("id", person.getId().toString());//鏉ユ簮鏂圭敤鎴稩D
|
|
|
- personMap.put("id", person.getNumber());//鏉ユ簮鏂圭敤鎴稩D
|
|
|
- personMap.put("name", person.getName());//鐢ㄦ埛濮撳悕
|
|
|
- personMap.put("phone", person.getNCell());//鎵嬫満鍙�
|
|
|
- personMap.put("gender", person.getGender() == null ? null : person.getGender().getValue());//鎬у埆
|
|
|
- personMap.put("email", person.getEmail());//閭��
|
|
|
+ //personMap.put("id", person.getId().toString());//来源方用户ID
|
|
|
+ personMap.put("id", person.getNumber());//来源方用户ID
|
|
|
+ personMap.put("name", person.getName());//用户姓名
|
|
|
+ personMap.put("phone", person.getNCell());//手机号
|
|
|
+ personMap.put("gender", person.getGender() == null ? null : person.getGender().getValue());//性别
|
|
|
+ //personMap.put("email", person.getEmail());//邮箱
|
|
|
EmployeeTypeInfo employeeType = person.getEmployeeType();
|
|
|
String number = employeeType.getNumber();
|
|
|
String personStatus = personStatusMap.get(number);
|
|
|
- personMap.put("status", personStatus);//鐘舵€�
|
|
|
+ personMap.put("status", personStatus);//状态
|
|
|
AdminOrgUnitInfo personDep = personPositionInfo.getPersonDep();
|
|
|
List orgIds = new ArrayList();
|
|
|
orgIds.add(personDep.getParent().getId().toString());
|
|
|
- personMap.put("orgIds", orgIds);//鏉ユ簮鏂圭粍缁嘔D鍒楄〃
|
|
|
+ personMap.put("orgIds", orgIds);//来源方组织ID列表
|
|
|
dataList.add(personMap);
|
|
|
- //鍛樺伐缂栫爜
|
|
|
+ //员工编码
|
|
|
Map paramsMap = new HashMap();
|
|
|
paramsMap.put("employeeNo", person.getNumber());
|
|
|
personMap.put("params", paramsMap);
|
|
|
+ personMap.put("areaCode", "+86");
|
|
|
}
|
|
|
- jsonObject.put("data", dataList);//1锛氱粍缁嘔D瀛樺湪鏃舵洿鏂� 2锛氱粍缁嘔D瀛樺湪鏃惰烦杩囦笉鏇存柊銆傞粯璁ゅ€�1
|
|
|
+ jsonObject.put("data", dataList);//1:组织ID存在时更新 2:组织ID存在时跳过不更新。默认值1
|
|
|
syncLogInfo.setRequestParams(jsonObject.toString());
|
|
|
- //鎵ц�鍚屾�浜哄憳鍒癐ot
|
|
|
+ //执行同步人员到Iot
|
|
|
syncLogInfo.setSyncCount(personIds.size());
|
|
|
return syncPerson(ctx, jsonObject.toString(), syncLogInfo);
|
|
|
} catch (Exception e) {
|
|
@@ -250,8 +251,8 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 鑾峰彇token
|
|
|
- * 鏈�湴缂撳瓨token锛屾湁鏁堟椂闀�6.5灏忔椂
|
|
|
+ * 获取token
|
|
|
+ * 本地缓存token,有效时长6.5小时
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
@@ -264,7 +265,7 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 璇锋眰鏂规硶
|
|
|
+ * 请求方法
|
|
|
*
|
|
|
* @param data
|
|
|
*/
|
|
@@ -275,9 +276,9 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
String syncOrgUnitApiUrl = this.propt.getProperty("syncUserApiUrl");
|
|
|
//String syncOrgUnitApiUrl = "http://10.0.3.87/api/open/enterpriseright/org-manage/v1/external/org/batch";
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(syncOrgUnitApiUrl)) {
|
|
|
- throw new BOSException("syncOrgUnitApiUrl涓嶈兘涓虹┖锛�");
|
|
|
+ throw new BOSException("syncOrgUnitApiUrl不能为空!");
|
|
|
}
|
|
|
- logger.error("syncOrg---data-----" + data);
|
|
|
+ logger.error("syncPerson---data-----" + data);
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
MediaType mediaType = MediaType.parse("application/json");
|
|
|
RequestBody body = RequestBody.create(mediaType, data);
|
|
@@ -297,20 +298,103 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
int success = 0;
|
|
|
int fail = 0;
|
|
|
if (response.isSuccessful()) {
|
|
|
-
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
Map<String, List<Map<String, String>>> resultMap = objectMapper.readValue(string, Map.class);
|
|
|
List<Map<String, String>> list = resultMap.get("data");
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
Map<String, String> map = list.get(i);
|
|
|
result.put(map.get("id"), map.get("msg"));
|
|
|
+ if (map.get("code") != null) {
|
|
|
+ if (map.get("code").equals("1")) {
|
|
|
+ success++;
|
|
|
+ } else {
|
|
|
+ fail++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fail++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //todo
|
|
|
+ //return (String) result.get("token");
|
|
|
+ syncLogInfo.setSyncStatus(SyncStatusEnum.SUCCESS);
|
|
|
+ //syncLogInfo.setSyncCount(total);
|
|
|
+ syncLogInfo.setSuccessNum(success);
|
|
|
+ syncLogInfo.setFailNum(fail);
|
|
|
+ syncLogInfo.setSyncResult(result.toString());
|
|
|
+ SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
+ } else{
|
|
|
+ syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
+ syncLogInfo.setSuccessNum(success);
|
|
|
+ syncLogInfo.setFailNum(fail);
|
|
|
+ syncLogInfo.setSyncResult(result.toString());
|
|
|
+ SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
+ }
|
|
|
+ } catch(IOException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
+ syncLogInfo.setFailNum(syncLogInfo.getSyncCount());
|
|
|
+ syncLogInfo.setSyncResult(result.toString());
|
|
|
+ syncLogInfo.setRequestParams(e.getMessage());
|
|
|
+ SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
+ throw new RuntimeException("同步IOT平台人员失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求方法
|
|
|
+ *
|
|
|
+ * @param data
|
|
|
+ */
|
|
|
+ public Map syncOrg (String data, SyncLogInfo syncLogInfo, Context ctx) throws BOSException, EASBizException {
|
|
|
+ Response response = null;
|
|
|
+ Map result = null;
|
|
|
+ try {
|
|
|
+ String syncOrgUnitApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
|
|
|
+ //String syncOrgUnitApiUrl = "http://10.0.3.87/api/open/enterpriseright/org-manage/v1/external/org/batch";
|
|
|
+ if (StringUtils.isBlank(syncOrgUnitApiUrl)) {
|
|
|
+ throw new BOSException("syncOrgUnitApiUrl不能为空!");
|
|
|
+ }
|
|
|
+ logger.error("syncOrg---data-----" + data);
|
|
|
+ OkHttpClient client = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(30, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(30, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(30, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ MediaType mediaType = MediaType.parse("application/json");
|
|
|
+ RequestBody body = RequestBody.create(mediaType, data);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(syncOrgUnitApiUrl)
|
|
|
+ .post(body)
|
|
|
+ //.addHeader("Authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ2UzVMT29mYiIsInNlcnZlciI6dHJ1ZSwidXNlcl9uYW1lIjoic0hSIiwicHJvamVjdE1hcCI6IntcIlNDWVwiOlwiMTMwMDgwNTYwNDAwNDA0NDgwMFwifSIsInNjb3BlIjpbInNlcnZlciJdLCJuYW1lIjoic0hSIiwicHJvamVjdCI6IiIsImV4cCI6MTczMDkxMzQwOSwidGVuYW50IjoidGFpb3QiLCJjbGllbnRfaWQiOiJzeXMifQ.hS1LVZ56rHPvVZmRdipay3XNAmmtFBZKt-wPc7UK2rg ")
|
|
|
+ .addHeader("Authorization", getToken())
|
|
|
+ .addHeader("Accept", "*/*")
|
|
|
+ .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
|
|
|
+ .addHeader("Connection", "keep-alive")
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
+ .build();
|
|
|
+ response = client.newCall(request).execute();
|
|
|
+ String string = response.body().string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ result = objectMapper.readValue(string, Map.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("同步IOT平台组织失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ logger.error("result-----" + result);
|
|
|
+ logger.error("response.isSuccessful()-----" + response.isSuccessful());
|
|
|
+ int success = 0;
|
|
|
+ int fail = 0;
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ List<Map<String, String>> list = (List<Map<String, String>>) result.get("data");
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Map<String, String> map = list.get(i);
|
|
|
if (map.get("code").equals("1")) {
|
|
|
success++;
|
|
|
} else {
|
|
|
fail++;
|
|
|
}
|
|
|
}
|
|
|
- //todo
|
|
|
//return (String) result.get("token");
|
|
|
syncLogInfo.setSyncStatus(SyncStatusEnum.SUCCESS);
|
|
|
//syncLogInfo.setSyncCount(total);
|
|
@@ -325,159 +409,79 @@ public class SyncTranForIOTFacadeControllerBean extends AbstractSyncTranForIOTFa
|
|
|
syncLogInfo.setSyncResult(result.toString());
|
|
|
SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
- syncLogInfo.setFailNum(syncLogInfo.getSyncCount());
|
|
|
- syncLogInfo.setSyncResult(result.toString());
|
|
|
- syncLogInfo.setRequestParams(e.getMessage());
|
|
|
- SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
- throw new RuntimeException("鍚屾�IOT骞冲彴浜哄憳澶辫触: " + e.getMessage());
|
|
|
+ return result;
|
|
|
}
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 璇锋眰鏂规硶
|
|
|
- *
|
|
|
- * @param data
|
|
|
- */
|
|
|
- public Map syncOrg(String data, SyncLogInfo syncLogInfo, Context ctx) throws BOSException, EASBizException {
|
|
|
- Response response = null;
|
|
|
- Map result = null;
|
|
|
- try {
|
|
|
- String syncOrgUnitApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
|
|
|
- //String syncOrgUnitApiUrl = "http://10.0.3.87/api/open/enterpriseright/org-manage/v1/external/org/batch";
|
|
|
- if (StringUtils.isBlank(syncOrgUnitApiUrl)) {
|
|
|
- throw new BOSException("syncOrgUnitApiUrl涓嶈兘涓虹┖锛�");
|
|
|
- }
|
|
|
- logger.error("syncOrg---data-----" + data);
|
|
|
- OkHttpClient client = new OkHttpClient.Builder()
|
|
|
- .connectTimeout(30, TimeUnit.SECONDS)
|
|
|
- .writeTimeout(30, TimeUnit.SECONDS)
|
|
|
- .readTimeout(30, TimeUnit.SECONDS)
|
|
|
- .build();
|
|
|
- MediaType mediaType = MediaType.parse("application/json");
|
|
|
- RequestBody body = RequestBody.create(mediaType, data);
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(syncOrgUnitApiUrl)
|
|
|
- .post(body)
|
|
|
- //.addHeader("Authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ2UzVMT29mYiIsInNlcnZlciI6dHJ1ZSwidXNlcl9uYW1lIjoic0hSIiwicHJvamVjdE1hcCI6IntcIlNDWVwiOlwiMTMwMDgwNTYwNDAwNDA0NDgwMFwifSIsInNjb3BlIjpbInNlcnZlciJdLCJuYW1lIjoic0hSIiwicHJvamVjdCI6IiIsImV4cCI6MTczMDkxMzQwOSwidGVuYW50IjoidGFpb3QiLCJjbGllbnRfaWQiOiJzeXMifQ.hS1LVZ56rHPvVZmRdipay3XNAmmtFBZKt-wPc7UK2rg ")
|
|
|
- .addHeader("Authorization", getToken())
|
|
|
- .addHeader("Accept", "*/*")
|
|
|
- .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
|
|
|
- .addHeader("Connection", "keep-alive")
|
|
|
- .addHeader("Content-Type", "application/json")
|
|
|
- .build();
|
|
|
- response = client.newCall(request).execute();
|
|
|
- String string = response.body().string();
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- result = objectMapper.readValue(string, Map.class);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new RuntimeException("鍚屾�IOT骞冲彴缁勭粐澶辫触: " + e.getMessage());
|
|
|
- }
|
|
|
- logger.error("result-----" + result);
|
|
|
- logger.error("response.isSuccessful()-----" + response.isSuccessful());
|
|
|
- int success = 0;
|
|
|
- int fail = 0;
|
|
|
- if (response.isSuccessful()) {
|
|
|
- List<Map<String, String>> list = (List<Map<String, String>>) result.get("data");
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- Map<String, String> map = list.get(i);
|
|
|
- if (map.get("code").equals("1")) {
|
|
|
- success++;
|
|
|
- } else {
|
|
|
- fail++;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 远程获取Token
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getTokenByRemote () throws BOSException {
|
|
|
+ Response response = null;
|
|
|
+ Map result = null;
|
|
|
+ try {
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
+ String getTokenApiUrl = this.propt.getProperty("getTokenApiUrl");
|
|
|
+ if (StringUtils.isBlank(getTokenApiUrl)) {
|
|
|
+ throw new BOSException("获取token接口地址不能为空!");
|
|
|
}
|
|
|
+ String appid = this.propt.getProperty("appid");
|
|
|
+ if (StringUtils.isBlank(appid)) {
|
|
|
+ throw new BOSException("appid不能为空!");
|
|
|
+ }
|
|
|
+ String secret = this.propt.getProperty("secret");
|
|
|
+ if (StringUtils.isBlank(secret)) {
|
|
|
+ throw new BOSException("secret不能为空!");
|
|
|
+ }
|
|
|
+ params.put("appid", appid);
|
|
|
+ params.put("sign_method", "md5");
|
|
|
+ params.put("timestamp", now + secret);
|
|
|
+ //生成签名
|
|
|
+ String sign = DigestUtils.md5DigestAsHex((appendUrl(null, params)).getBytes());
|
|
|
+ params.put("timestamp", String.valueOf(now));
|
|
|
+ params.put("sign", sign);
|
|
|
+ String requestUrl = appendUrl(getTokenApiUrl, params);
|
|
|
+ logger.error("getTokenByRemote -> requestUrl " + requestUrl);
|
|
|
+ OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
+ .build();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(requestUrl)
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ response = client.newCall(request).execute();
|
|
|
+ String string = response.body().string();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ result = objectMapper.readValue(string, Map.class);
|
|
|
+ logger.error("getTokenByRemote -> result " + result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new BOSException("远程获取IOT平台token失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ String token = (String) result.get("token");
|
|
|
+ //缓存token
|
|
|
+ cache.put("token", token, 27000000);//6.5小时
|
|
|
+ return token;
|
|
|
+ } else {
|
|
|
+ throw new BOSException((String) result.get("msg"));
|
|
|
}
|
|
|
- //return (String) result.get("token");
|
|
|
- syncLogInfo.setSyncStatus(SyncStatusEnum.SUCCESS);
|
|
|
- //syncLogInfo.setSyncCount(total);
|
|
|
- syncLogInfo.setSuccessNum(success);
|
|
|
- syncLogInfo.setFailNum(fail);
|
|
|
- syncLogInfo.setSyncResult(result.toString());
|
|
|
- SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
- } else {
|
|
|
- syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
- syncLogInfo.setSuccessNum(success);
|
|
|
- syncLogInfo.setFailNum(fail);
|
|
|
- syncLogInfo.setSyncResult(result.toString());
|
|
|
- SyncLogFactory.getLocalInstance(ctx).save(syncLogInfo);
|
|
|
}
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 杩滅▼鑾峰彇Token
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String getTokenByRemote() throws BOSException {
|
|
|
- Response response = null;
|
|
|
- Map result = null;
|
|
|
- try {
|
|
|
- long now = System.currentTimeMillis();
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
- String getTokenApiUrl = this.propt.getProperty("getTokenApiUrl");
|
|
|
- if (StringUtils.isBlank(getTokenApiUrl)) {
|
|
|
- throw new BOSException("鑾峰彇token鎺ュ彛鍦板潃涓嶈兘涓虹┖锛�");
|
|
|
+ /**
|
|
|
+ * 拼接地址参数
|
|
|
+ */
|
|
|
+ private String appendUrl (String url, Map < String, String > data){
|
|
|
+ StringBuilder paramStr = new StringBuilder();
|
|
|
+ for (String key : data.keySet()) {
|
|
|
+ paramStr.append(key).append("=").append(data.get(key)).append("&");
|
|
|
}
|
|
|
- String appid = this.propt.getProperty("appid");
|
|
|
- if (StringUtils.isBlank(appid)) {
|
|
|
- throw new BOSException("appid涓嶈兘涓虹┖锛�");
|
|
|
+ paramStr.deleteCharAt(paramStr.lastIndexOf("&"));
|
|
|
+ if (!StringUtils.isEmpty(url)) {
|
|
|
+ return url.contains("?") ? (url + "&" + paramStr) : (url + "?" + paramStr);
|
|
|
}
|
|
|
- String secret = this.propt.getProperty("secret");
|
|
|
- if (StringUtils.isBlank(secret)) {
|
|
|
- throw new BOSException("secret涓嶈兘涓虹┖锛�");
|
|
|
- }
|
|
|
- params.put("appid", appid);
|
|
|
- params.put("sign_method", "md5");
|
|
|
- params.put("timestamp", now + secret);
|
|
|
- //鐢熸垚绛惧悕
|
|
|
- String sign = DigestUtils.md5DigestAsHex((appendUrl(null, params)).getBytes());
|
|
|
- params.put("timestamp", String.valueOf(now));
|
|
|
- params.put("sign", sign);
|
|
|
- String requestUrl = appendUrl(getTokenApiUrl, params);
|
|
|
- logger.error("getTokenByRemote -> requestUrl " + requestUrl);
|
|
|
- OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
- .build();
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .build();
|
|
|
- response = client.newCall(request).execute();
|
|
|
- String string = response.body().string();
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- result = objectMapper.readValue(string, Map.class);
|
|
|
- logger.error("getTokenByRemote -> result " + result);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw new BOSException("杩滅▼鑾峰彇IOT骞冲彴token澶辫触: " + e.getMessage());
|
|
|
- }
|
|
|
- if (response.isSuccessful()) {
|
|
|
- String token = (String) result.get("token");
|
|
|
- //缂撳瓨token
|
|
|
- cache.put("token", token, 27000000);//6.5灏忔椂
|
|
|
- return token;
|
|
|
- } else {
|
|
|
- throw new BOSException((String) result.get("msg"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 鎷兼帴鍦板潃鍙傛暟
|
|
|
- */
|
|
|
- private String appendUrl(String url, Map<String, String> data) {
|
|
|
- StringBuilder paramStr = new StringBuilder();
|
|
|
- for (String key : data.keySet()) {
|
|
|
- paramStr.append(key).append("=").append(data.get(key)).append("&");
|
|
|
- }
|
|
|
- paramStr.deleteCharAt(paramStr.lastIndexOf("&"));
|
|
|
- if (!StringUtils.isEmpty(url)) {
|
|
|
- return url.contains("?") ? (url + "&" + paramStr) : (url + "?" + paramStr);
|
|
|
+ return paramStr.toString();
|
|
|
}
|
|
|
- return paramStr.toString();
|
|
|
}
|
|
|
-}
|