|
@@ -1,22 +1,19 @@
|
|
|
package com.sooka.system.service.impl;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
-import com.business.domain.ImputationData;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.business.mapper.ImputationDataMapper;
|
|
|
import com.sooka.apply.domain.IntDetailed;
|
|
|
import com.sooka.apply.mapper.IntRecordMapper;
|
|
|
+import com.sooka.common.core.domain.AjaxResult;
|
|
|
import com.sooka.common.core.text.Convert;
|
|
|
import com.sooka.common.utils.DateUtils;
|
|
|
import com.sooka.common.utils.uuid.UUID;
|
|
|
import com.sooka.framework.util.ShiroUtils;
|
|
|
+import com.util.HttpUtil2;
|
|
|
import com.util.NumberUtils;
|
|
|
import com.util.SecretKeyUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.sooka.system.mapper.TUInterfaceinfoMapper;
|
|
|
import com.sooka.system.domain.TUInterfaceinfo;
|
|
@@ -302,6 +299,147 @@ public class TUInterfaceinfoServiceImpl implements ITUInterfaceinfoService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 测试接口可用性状态
|
|
|
+ * @return 结果
|
|
|
+ * */
|
|
|
+ private boolean testInterface(TUInterfaceinfo interfaceinfo){
|
|
|
+ String http_province = "http://172.24.5.241:6689";
|
|
|
+ String http_local_api = "http://172.17.5.4:7777";
|
|
|
+ Map<String, String> interfaceTest = tUInterfaceinfoMapper.selectInterfaceTest(interfaceinfo.getId());
|
|
|
+ // share_type_1=市共享,share_type_2=市归集,share_type_3=省上报,share_type_4=省共享
|
|
|
+ if(interfaceTest == null){// 未配置接口参数的接口不做统计 默认算正常状态
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ String deptId = interfaceTest.get("dept_id");
|
|
|
+ String deptName = interfaceTest.get("dept_name");
|
|
|
+ String shareType = interfaceTest.get("share_type");
|
|
|
+ String interfaceType = interfaceTest.get("interface_type");
|
|
|
+ String intCode = interfaceTest.get("int_code");
|
|
|
+ String secretKey = interfaceTest.get("secret_key");
|
|
|
+ String interfaceAddress = interfaceTest.get("interface_address");
|
|
|
+ String testParam = interfaceTest.get("test_param");
|
|
|
+ String interfaceId = interfaceTest.get("interface_id");
|
|
|
+ String interfaceName = interfaceTest.get("interface_name");
|
|
|
+ if(interfaceType.equals("get")){
|
|
|
+ return true;
|
|
|
+ }else if(interfaceType.equals("post")){
|
|
|
+ if(shareType.equals("share_type_1") || shareType.equals("share_type_2") || shareType.equals("share_type_3") || shareType.equals("share_type_4")){// 市共享 市归集 省上报 省共享
|
|
|
+ boolean status = false;
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("intCode", intCode);
|
|
|
+ map.put("secretKey", secretKey);
|
|
|
+ map.put("Content-Type", "application/json");
|
|
|
+// String params = "{\"certNumMan\":\""+tUPeoplemarryinfodouble.getCertnumberman()+"\",\"nameMan\":\""+tUPeoplemarryinfodouble.getNameman()+"\",\"certNumWoman\":\""+tUPeoplemarryinfodouble.getCertnumberwoman()+"\",\"nameWoman\":\""+tUPeoplemarryinfodouble.getNamewoman()+"\"}";
|
|
|
+ String params = testParam;
|
|
|
+// map.put("Authorization-Type", "Basic");
|
|
|
+// map.put("Authorization", "Basic NjBlODQxNzQyZTIyMDE2NjUzYmQ3NmE4N2QxY2FjMzA6ODhlOWM0NzcxMWZkMTM5YjhiMGMyODlkZjBiMWI5YmQ=");
|
|
|
+// map.put("Service-ID", "qNpU77");
|
|
|
+ try {
|
|
|
+ String result = HttpUtil2.doPost(http_local_api + interfaceAddress, params, map);
|
|
|
+// System.out.println("share_type_1=市共享,share_type_2=市归集 测试接口可用性状态" + interfaceName + "testInterface result=" + result);
|
|
|
+ if(result != null && (JSONObject.parseObject(result).getString("code").equals("0") || JSONObject.parseObject(result).getString("code").equals("1000"))){// 省共享返回的是1000
|
|
|
+ status = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ String shareTypeLabel = "";
|
|
|
+ if(shareType.equals("share_type_1")){
|
|
|
+ shareTypeLabel = "share_type_1=市共享";
|
|
|
+ }else if(shareType.equals("share_type_2")){
|
|
|
+ shareTypeLabel = "share_type_2=市归集";
|
|
|
+ }else if(shareType.equals("share_type_3")){
|
|
|
+ shareTypeLabel = "share_type_3=省上报";
|
|
|
+ }else if(shareType.equals("share_type_4")){
|
|
|
+ shareTypeLabel = "share_type_4=省共享";
|
|
|
+ }
|
|
|
+ System.out.println(shareTypeLabel + " 测试接口可用性状态:" + interfaceName + "testInterface status=" + (status ? "0" : "1"));
|
|
|
+ Map interfaceStatus = new HashMap();
|
|
|
+ interfaceStatus.put("id", UUID.randomUUID().toString());
|
|
|
+ interfaceStatus.put("intCode", intCode);
|
|
|
+ interfaceStatus.put("status", status ? "0" : "1");
|
|
|
+ interfaceStatus.put("shareType", shareType);
|
|
|
+ interfaceStatus.put("interfaceId", interfaceId);
|
|
|
+ interfaceStatus.put("interfaceName", interfaceName);
|
|
|
+ interfaceStatus.put("interfaceAddress", interfaceAddress);
|
|
|
+ interfaceStatus.put("deptId", deptId);
|
|
|
+ interfaceStatus.put("deptName", deptName);
|
|
|
+ tUInterfaceinfoMapper.insertInterfaceStatus(interfaceStatus);
|
|
|
+ }
|
|
|
+ return status;
|
|
|
+ }else { // 省上报 省共享
|
|
|
+ boolean status = false;
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("intCode", intCode);
|
|
|
+ map.put("secretKey", secretKey);
|
|
|
+ map.put("Content-Type", "application/json");
|
|
|
+// String params = "{\"certNumMan\":\""+tUPeoplemarryinfodouble.getCertnumberman()+"\",\"nameMan\":\""+tUPeoplemarryinfodouble.getNameman()+"\",\"certNumWoman\":\""+tUPeoplemarryinfodouble.getCertnumberwoman()+"\",\"nameWoman\":\""+tUPeoplemarryinfodouble.getNamewoman()+"\"}";
|
|
|
+ map.put("Authorization-Type", "Basic");
|
|
|
+ map.put("Authorization", "Basic NjBlODQxNzQyZTIyMDE2NjUzYmQ3NmE4N2QxY2FjMzA6ODhlOWM0NzcxMWZkMTM5YjhiMGMyODlkZjBiMWI5YmQ=");
|
|
|
+ map.put("Service-ID", "qNpU77");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询接口状态 接口可用性监测
|
|
|
+ * @return 结果
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public AjaxResult getInterfaceStatus(){
|
|
|
+ Map map = new HashMap();
|
|
|
+ List<TUInterfaceinfo> interfaceCountTotalList = tUInterfaceinfoMapper.interfaceCountTotal();
|
|
|
+ Integer interfaceCountTotal = interfaceCountTotalList.size();
|
|
|
+ Integer interfaceCountActive = tUInterfaceinfoMapper.interfaceCountActive();
|
|
|
+ Integer interfaceCountAvailable = tUInterfaceinfoMapper.interfaceCountAvailable();
|
|
|
+ if(interfaceCountAvailable == 0){// 今日无数据 需要测试接口 若今日已有数据 测过接口不重复测试 使用已有数据
|
|
|
+ for (int i = 0; i < interfaceCountTotal; i++) {
|
|
|
+ boolean available = testInterface(interfaceCountTotalList.get(i));
|
|
|
+ if(available){
|
|
|
+ interfaceCountAvailable++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer interfaceCountUnavailable = tUInterfaceinfoMapper.interfaceCountUnavailable();
|
|
|
+ map.put("interfaceCountTotal", interfaceCountTotal);
|
|
|
+ map.put("interfaceCountActive", interfaceCountActive);
|
|
|
+ map.put("interfaceCountInactive", interfaceCountTotal - interfaceCountActive);
|
|
|
+ map.put("interfaceCountAvailable", interfaceCountTotal - interfaceCountUnavailable);
|
|
|
+ map.put("interfaceCountUnavailable", interfaceCountUnavailable);
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询接口状态 接口可用性监测 防止系统接口调用过于频繁 每日仅验证一次可用性 只有刷新的时候再重新验证可用性
|
|
|
+ * @return 结果
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public AjaxResult getInterfaceStatusAgain(){
|
|
|
+ Map map = new HashMap();
|
|
|
+ List<TUInterfaceinfo> interfaceCountTotalList = tUInterfaceinfoMapper.interfaceCountTotal();
|
|
|
+ Integer interfaceCountTotal = interfaceCountTotalList.size();
|
|
|
+ Integer interfaceCountActive = tUInterfaceinfoMapper.interfaceCountActive();
|
|
|
+ Integer interfaceCountAvailable = 0;
|
|
|
+ tUInterfaceinfoMapper.deleteInterfaceStatusToday();// 删除今日接口状态监测数据
|
|
|
+ for (TUInterfaceinfo interfaceInfo : interfaceCountTotalList) {
|
|
|
+ if(testInterface(interfaceInfo)){
|
|
|
+ interfaceCountAvailable++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer interfaceCountUnavailable = tUInterfaceinfoMapper.interfaceCountUnavailable();
|
|
|
+ map.put("interfaceCountTotal", interfaceCountTotal);
|
|
|
+ map.put("interfaceCountActive", interfaceCountActive);
|
|
|
+ map.put("interfaceCountInactive", interfaceCountTotal - interfaceCountActive);
|
|
|
+ map.put("interfaceCountAvailable", interfaceCountTotal - interfaceCountUnavailable);
|
|
|
+ map.put("interfaceCountUnavailable", interfaceCountUnavailable);
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据部门ID查询分类数量
|
|
|
* @return 结果
|
|
|
* */
|