|
@@ -4,11 +4,14 @@ import org.bfkj.application.AuthApplicationImpl;
|
|
|
import org.bfkj.application.DataProcess;
|
|
|
import org.bfkj.config.AppConfig;
|
|
|
import org.bfkj.config.ObjectMap;
|
|
|
+import org.bfkj.utils.ImportExcelUtils;
|
|
|
import org.bfkj.utils.MapTools;
|
|
|
import org.bfkj.utils.MyDbHelper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -22,18 +25,20 @@ import java.util.Objects;
|
|
|
public class CommonApi {
|
|
|
|
|
|
@Autowired
|
|
|
- AuthApplicationImpl authApplication;
|
|
|
+ private AuthApplicationImpl authApplication;
|
|
|
+ @Autowired
|
|
|
+ private ImportExcelUtils importExcelUtils;
|
|
|
|
|
|
/**
|
|
|
* 服务数据恢复 : 因为日志的数据内容拆分为4个字段,所有此方法需要调整可
|
|
|
*/
|
|
|
@RequestMapping("abnormalDataRecovery")
|
|
|
- public Map<String,Object> abnormalDataRecovery(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
|
|
|
+ public Map<String, Object> abnormalDataRecovery(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
|
|
|
String verificationToke = authApplication.verificationUserToken(token);
|
|
|
if (!MapTools.isBlank(verificationToke)) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","用户令牌验证失败:" + verificationToke);
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "用户令牌验证失败:" + verificationToke);
|
|
|
return errMap;
|
|
|
}
|
|
|
return authApplication.abnormalDataRecovery(params);
|
|
@@ -82,22 +87,22 @@ public class CommonApi {
|
|
|
/**
|
|
|
* 统一接收处理
|
|
|
*/
|
|
|
- private Map<String,Object> commonInterface(Map<String, String> token, Map<String, Object> params, String defaultEvent) {
|
|
|
+ private Map<String, Object> commonInterface(Map<String, String> token, Map<String, Object> params, String defaultEvent) {
|
|
|
if (token.containsKey("token")) {
|
|
|
String appToken = token.get("token");
|
|
|
String verificationToke = authApplication.verificationToken(appToken);
|
|
|
if (!MapTools.isNumber(verificationToke)) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","应用token验证失败:" + verificationToke);
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "应用token验证失败:" + verificationToke);
|
|
|
return errMap;
|
|
|
}
|
|
|
} else {
|
|
|
String verificationToke = authApplication.verificationUserToken(token);
|
|
|
if (!MapTools.isBlank(verificationToke)) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","用户令牌验证失败:" + verificationToke);
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "用户令牌验证失败:" + verificationToke);
|
|
|
return errMap;
|
|
|
}
|
|
|
}
|
|
@@ -108,48 +113,69 @@ public class CommonApi {
|
|
|
}
|
|
|
if (!MapTools.isBlank(defaultEvent) && !event.equals(defaultEvent)) {//如果有默认事件标识且传入的事件标识与默认事件标识不相同则返回错误
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","当前接口只支持event为" + defaultEvent + ",当前接收参数为:" + params);
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "当前接口只支持event为" + defaultEvent + ",当前接收参数为:" + params);
|
|
|
return errMap;
|
|
|
|
|
|
}
|
|
|
Object serviceId = params.get("serviceId");
|
|
|
if (Objects.isNull(serviceId) || !params.containsKey("event")) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","缺失必要的参数:服务编号serviceId或事件标识event" + params);
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "缺失必要的参数:服务编号serviceId或事件标识event" + params);
|
|
|
return errMap;
|
|
|
}
|
|
|
//通过服务ID 查询对应服务的服务类型是否为1,如果时则继续,否则返回
|
|
|
MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
|
|
|
if (Objects.nonNull(myDbHelper.getErrorMessage())) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","服务:" + serviceId + " 获取数据库对象失败,异常信息 " + myDbHelper.getErrorMessage());
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "服务:" + serviceId + " 获取数据库对象失败,异常信息 " + myDbHelper.getErrorMessage());
|
|
|
return errMap;
|
|
|
}
|
|
|
Map<String, String> hasServiceMap = myDbHelper.queryForObject("select count(1) count from serviceinfo where serviceID=? and serviceType = 1", serviceId);
|
|
|
if (hasServiceMap.get("code").equals("-1")) {
|
|
|
System.out.println("数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
|
|
|
return errMap;
|
|
|
}
|
|
|
String count = hasServiceMap.get("returnData");
|
|
|
- if ("".equals(count)|| "0".equals(count)) {
|
|
|
+ if ("".equals(count) || "0".equals(count)) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","服务:" + serviceId + "是采集服务不支持操作");
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "服务:" + serviceId + "是采集服务不支持操作");
|
|
|
return errMap;
|
|
|
}
|
|
|
DataProcess dataProcessObj = ObjectMap.getordropInput(serviceId.toString(), true);//获取数据输出处理对象
|
|
|
if (null == dataProcessObj || !MapTools.isBlank(dataProcessObj.getErrorMessage())) {
|
|
|
HashMap<String, Object> errMap = new HashMap<>();
|
|
|
- errMap.put("code","-1");
|
|
|
- errMap.put("message","服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
|
|
|
+ errMap.put("code", "-1");
|
|
|
+ errMap.put("message", "服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
|
|
|
return errMap;
|
|
|
}
|
|
|
- return dataProcessObj.processData(params,token.get("user_id"));
|
|
|
+ return dataProcessObj.processData(params, token.get("user_id"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/upload")
|
|
|
+ public Object upload(@RequestParam(value = "file") MultipartFile excelFile,@RequestParam(value = "serviceId") String serviceID, @RequestHeader Map<String, String> tokenMap) throws Exception {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ if (excelFile.isEmpty()) {
|
|
|
+ return MapTools.processFail("文件夹为空,重新上传");
|
|
|
+ } else {
|
|
|
+ String fileName = excelFile.getOriginalFilename();
|
|
|
+ InputStream is = excelFile.getInputStream();
|
|
|
+ Map<String, Object> uploadFile = importExcelUtils.upload(fileName, is);
|
|
|
+ if ("-1".equals(uploadFile.get("code"))) {
|
|
|
+ return uploadFile;
|
|
|
+ }
|
|
|
+ Map<String, Object> sendData = new HashMap<>();
|
|
|
+ sendData.put("serviceId", serviceID);
|
|
|
+ sendData.put("dataContent", uploadFile.get("returnData"));
|
|
|
+ commonInterface(tokenMap, sendData, "1");
|
|
|
+ return MapTools.processSuccess("上传成功");
|
|
|
+ }
|
|
|
}
|
|
|
}
|