|
@ -23,6 +23,7 @@ import com.ruoyi.business.service.IAdapterService; |
|
|
import com.ruoyi.business.service.IDatabaseService; |
|
|
import com.ruoyi.business.service.IDatabaseService; |
|
|
import com.ruoyi.business.service.IServiceBusinessService; |
|
|
import com.ruoyi.business.service.IServiceBusinessService; |
|
|
import com.ruoyi.business.service.IServiceGrantService; |
|
|
import com.ruoyi.business.service.IServiceGrantService; |
|
|
|
|
|
import com.ruoyi.business.utils.FileZipUtils; |
|
|
import com.ruoyi.common.auth.entity.OauthClientDetails; |
|
|
import com.ruoyi.common.auth.entity.OauthClientDetails; |
|
|
import com.ruoyi.common.auth.service.OauthClientDetailsService; |
|
|
import com.ruoyi.common.auth.service.OauthClientDetailsService; |
|
|
import com.ruoyi.common.core.domain.R; |
|
|
import com.ruoyi.common.core.domain.R; |
|
@ -53,6 +54,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import javax.servlet.ServletInputStream; |
|
|
import javax.servlet.ServletInputStream; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.sql.DataSource; |
|
|
import javax.sql.DataSource; |
|
|
import java.io.BufferedReader; |
|
|
import java.io.BufferedReader; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
@ -93,7 +95,7 @@ public class OutBusinessController { |
|
|
private OauthClientDetailsService oauthClientDetailsService; |
|
|
private OauthClientDetailsService oauthClientDetailsService; |
|
|
|
|
|
|
|
|
@PostMapping |
|
|
@PostMapping |
|
|
public String outInsert(HttpServletRequest request) throws Exception { |
|
|
|
|
|
|
|
|
public String outInsert(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
// if(files != null && files.length > 0 && !Objects.equals(files[0].getOriginalFilename(), "")) { |
|
|
// if(files != null && files.length > 0 && !Objects.equals(files[0].getOriginalFilename(), "")) { |
|
|
// return outInsert2(request,files, jsonData); |
|
|
// return outInsert2(request,files, jsonData); |
|
|
// } else { |
|
|
// } else { |
|
@ -130,11 +132,11 @@ public class OutBusinessController { |
|
|
log.info("==================================token验证成功================================"); |
|
|
log.info("==================================token验证成功================================"); |
|
|
tokenFlag = true; |
|
|
tokenFlag = true; |
|
|
} else { |
|
|
} else { |
|
|
log.info("==================================token验证失败2================================"); |
|
|
|
|
|
|
|
|
log.info("==================================token验证失败1================================"); |
|
|
tokenFlag = false; |
|
|
tokenFlag = false; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
log.info("==================================token验证失败3================================"); |
|
|
|
|
|
|
|
|
log.info("==================================token验证失败2================================"); |
|
|
transportRequest.getHeader().setReqType("1"); |
|
|
transportRequest.getHeader().setReqType("1"); |
|
|
transportRequest.getHeader().setCode("9999"); |
|
|
transportRequest.getHeader().setCode("9999"); |
|
|
transportRequest.getHeader().setMessage("token不存在"); |
|
|
transportRequest.getHeader().setMessage("token不存在"); |
|
@ -149,6 +151,25 @@ public class OutBusinessController { |
|
|
String transportResponse = gson.toJson(transportRequest); |
|
|
String transportResponse = gson.toJson(transportRequest); |
|
|
return transportResponse; |
|
|
return transportResponse; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String ipcType = transportRequest.getHeader().getIpcType(); |
|
|
|
|
|
AjaxResult ajaxResult = AjaxResult.success(); |
|
|
|
|
|
if(ipcType == null || "".equals(ipcType)) { |
|
|
|
|
|
ajaxResult = AjaxResult.error("ipcType不能为空"); |
|
|
|
|
|
transportRequest.getHeader().setReqType("1"); |
|
|
|
|
|
transportRequest.getHeader().setCode("9999"); |
|
|
|
|
|
transportRequest.getHeader().setMessage(ajaxResult.get("msg").toString()); |
|
|
|
|
|
String transportResponse = gson.toJson(transportRequest); |
|
|
|
|
|
return transportResponse; |
|
|
|
|
|
} |
|
|
|
|
|
if ("GL1001".equals(ipcType)) { |
|
|
|
|
|
ajaxResult = AjaxResult.success("心跳检测成功"); |
|
|
|
|
|
transportRequest.getHeader().setReqType("1"); |
|
|
|
|
|
transportRequest.getHeader().setCode("9999"); |
|
|
|
|
|
transportRequest.getHeader().setMessage(ajaxResult.get("msg").toString()); |
|
|
|
|
|
String transportResponse = gson.toJson(transportRequest); |
|
|
|
|
|
return transportResponse; |
|
|
|
|
|
} |
|
|
String decryptBodyStr = ""; |
|
|
String decryptBodyStr = ""; |
|
|
if (!org.springframework.util.StringUtils.isEmpty(body)) { |
|
|
if (!org.springframework.util.StringUtils.isEmpty(body)) { |
|
|
try { |
|
|
try { |
|
@ -158,7 +179,11 @@ public class OutBusinessController { |
|
|
throw new RuntimeException(e); |
|
|
throw new RuntimeException(e); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
AjaxResult ajaxResult = outInsert1(transportRequest,decryptBodyStr); |
|
|
|
|
|
|
|
|
if ("GL1004".equals(ipcType)) { |
|
|
|
|
|
outFiles(decryptBodyStr,response); |
|
|
|
|
|
return "附件获取成功"; |
|
|
|
|
|
} |
|
|
|
|
|
ajaxResult = outInsert1(transportRequest,decryptBodyStr,response); |
|
|
if (ajaxResult.isSuccess() || Integer.valueOf(200).equals(ajaxResult.get("code"))) { |
|
|
if (ajaxResult.isSuccess() || Integer.valueOf(200).equals(ajaxResult.get("code"))) { |
|
|
transportRequest.getHeader().setReqType("1"); |
|
|
transportRequest.getHeader().setReqType("1"); |
|
|
transportRequest.getHeader().setCode("0000"); |
|
|
transportRequest.getHeader().setCode("0000"); |
|
@ -173,15 +198,9 @@ public class OutBusinessController { |
|
|
return transportResponse; |
|
|
return transportResponse; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private AjaxResult outInsert1(TransportRequest transportRequest, String jsonData) throws Exception{ |
|
|
|
|
|
|
|
|
private AjaxResult outInsert1(TransportRequest transportRequest, String jsonData, HttpServletResponse response) throws Exception{ |
|
|
|
|
|
|
|
|
String ipcType = transportRequest.getHeader().getIpcType(); |
|
|
String ipcType = transportRequest.getHeader().getIpcType(); |
|
|
if(ipcType == null || "".equals(ipcType)) { |
|
|
|
|
|
return AjaxResult.error("ipcType不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if ("GL1001".equals(ipcType)) { |
|
|
|
|
|
return AjaxResult.success("心跳检测成功"); |
|
|
|
|
|
} |
|
|
|
|
|
ServiceBusiness serviceBusiness = serviceBusinessService.selectServiceBusinessByOutName(ipcType+"_OUT"); |
|
|
ServiceBusiness serviceBusiness = serviceBusinessService.selectServiceBusinessByOutName(ipcType+"_OUT"); |
|
|
// validGrant(String.valueOf(serviceBusiness.getId())); |
|
|
// validGrant(String.valueOf(serviceBusiness.getId())); |
|
|
if(!BusinessServiceEnum.insert.getCode().equals(serviceBusiness.getType())) { |
|
|
if(!BusinessServiceEnum.insert.getCode().equals(serviceBusiness.getType())) { |
|
@ -210,8 +229,32 @@ public class OutBusinessController { |
|
|
final String finalReqBody = reqBody; |
|
|
final String finalReqBody = reqBody; |
|
|
TransportRequestInfo transportRequestInfo = JSONObject.parseObject(jsonData, TransportRequestInfo.class); |
|
|
TransportRequestInfo transportRequestInfo = JSONObject.parseObject(jsonData, TransportRequestInfo.class); |
|
|
Map<String,Object> transportMap = (Map<String, Object>) transportRequestInfo.getReqInfo(); |
|
|
Map<String,Object> transportMap = (Map<String, Object>) transportRequestInfo.getReqInfo(); |
|
|
JSONArray jsonArray = (JSONArray.parseArray(String.valueOf(transportMap.get(finalReqBody)))); |
|
|
|
|
|
log.info(jsonArray.toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//JSONArray jsonArray = (JSONArray.parseArray(String.valueOf(transportMap.get(finalReqBody)))); |
|
|
|
|
|
//log.info(jsonArray.toString()); |
|
|
|
|
|
// 增加JSON类型判断逻辑 |
|
|
|
|
|
Object data = transportMap.get(finalReqBody); |
|
|
|
|
|
String jsonStr = String.valueOf(data); |
|
|
|
|
|
JSONArray jsonArray; |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(jsonStr)) { |
|
|
|
|
|
if (jsonStr.trim().startsWith("[")) { |
|
|
|
|
|
jsonArray = JSONArray.parseArray(jsonStr); |
|
|
|
|
|
} else if (jsonStr.trim().startsWith("{")) { |
|
|
|
|
|
// 如果字段要求数组但收到对象,可以按需处理: |
|
|
|
|
|
// 1. 返回错误:return AjaxResult.error(finalReqBody + "字段应为数组格式"); |
|
|
|
|
|
// 2. 包装成数组 |
|
|
|
|
|
jsonArray = new JSONArray(); |
|
|
|
|
|
jsonArray.add(JSONObject.parseObject(jsonStr)); |
|
|
|
|
|
} else { |
|
|
|
|
|
return AjaxResult.error(finalReqBody + "字段格式异常,应为JSON数组或对象"); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
return AjaxResult.error(finalReqBody + "字段不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("插入的jsonArray.toString数组:"+jsonArray.toString()); |
|
|
|
|
|
|
|
|
int batchSize = 50; |
|
|
int batchSize = 50; |
|
|
if (jsonArray.size() > batchSize) { |
|
|
if (jsonArray.size() > batchSize) { |
|
|
return AjaxResult.error("超过50条数据"); |
|
|
return AjaxResult.error("超过50条数据"); |
|
@ -355,6 +398,51 @@ public class OutBusinessController { |
|
|
return AjaxResult.success("插入成功"); |
|
|
return AjaxResult.success("插入成功"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void outFiles(String jsonData, HttpServletResponse response) throws Exception{ |
|
|
|
|
|
String finalReqBody = "recordInfo"; |
|
|
|
|
|
// 新增final副本用于lambda |
|
|
|
|
|
TransportRequestInfo transportRequestInfo = JSONObject.parseObject(jsonData, TransportRequestInfo.class); |
|
|
|
|
|
Map<String,Object> transportMap = (Map<String, Object>) transportRequestInfo.getReqInfo(); |
|
|
|
|
|
|
|
|
|
|
|
Object data = transportMap.get(finalReqBody); |
|
|
|
|
|
String jsonStr = String.valueOf(data); |
|
|
|
|
|
JSONArray jsonArray = new JSONArray(); |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(jsonStr)) { |
|
|
|
|
|
if (jsonStr.trim().startsWith("[")) { |
|
|
|
|
|
jsonArray = JSONArray.parseArray(jsonStr); |
|
|
|
|
|
} else if (jsonStr.trim().startsWith("{")) { |
|
|
|
|
|
// 如果字段要求数组但收到对象,可以按需处理: |
|
|
|
|
|
// 1. 返回错误:return AjaxResult.error(finalReqBody + "字段应为数组格式"); |
|
|
|
|
|
// 2. 包装成数组 |
|
|
|
|
|
jsonArray = new JSONArray(); |
|
|
|
|
|
jsonArray.add(JSONObject.parseObject(jsonStr)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("jsonArray.toString数组:"+jsonArray.toString()); |
|
|
|
|
|
|
|
|
|
|
|
Map<String,String> fileInfo = new HashMap<>(); |
|
|
|
|
|
// 循环处理JSONArray中的每个JSONObject |
|
|
|
|
|
for (int i = 0; i < jsonArray.size(); i++) { |
|
|
|
|
|
final int idx = i; // 创建final副本解决lambda表达式变量捕获问题 |
|
|
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(idx); |
|
|
|
|
|
for (String key : jsonObject.keySet()) { |
|
|
|
|
|
Object value = jsonObject.get(key); |
|
|
|
|
|
if (key.contains("Id")) { |
|
|
|
|
|
fileInfo.put("Id", String.valueOf(value)); |
|
|
|
|
|
} |
|
|
|
|
|
if (key.contains("Name")) { |
|
|
|
|
|
fileInfo.put("Name", String.valueOf(value)); |
|
|
|
|
|
} |
|
|
|
|
|
if (key.contains("Type")) { |
|
|
|
|
|
fileInfo.put("Type", String.valueOf(value)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
FileZipUtils.getEncryptZip(response,fileInfo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 接口权限 |
|
|
* 接口权限 |
|
|
* @param businessId 业务id |
|
|
* @param businessId 业务id |
|
@ -719,12 +807,15 @@ public class OutBusinessController { |
|
|
// 设置参数 |
|
|
// 设置参数 |
|
|
for (String key : json.keySet()) { |
|
|
for (String key : json.keySet()) { |
|
|
if (resFieldSet.contains(FebsUtil.camelToUnderscore(key))) { |
|
|
if (resFieldSet.contains(FebsUtil.camelToUnderscore(key))) { |
|
|
// 检查是否是 JsonArray类型比如qxhydsxx 字段,确保它是一个有效的 JSON 字符串 |
|
|
|
|
|
if (json.get(key) instanceof JSONArray) { |
|
|
|
|
|
// 将 JSON 对象转换为字符串 |
|
|
|
|
|
ps.setString(index++, json.getJSONArray(key).toString()); |
|
|
|
|
|
|
|
|
Object value = json.get(key); |
|
|
|
|
|
if (value instanceof JSONArray) { |
|
|
|
|
|
ps.setString(index++, ((JSONArray) value).toJSONString()); |
|
|
|
|
|
} else if (value instanceof JSONObject) { |
|
|
|
|
|
ps.setString(index++, ((JSONObject) value).toJSONString()); |
|
|
|
|
|
} else if (value != null) { |
|
|
|
|
|
ps.setString(index++, value.toString()); |
|
|
} else { |
|
|
} else { |
|
|
ps.setObject(index++, json.get(key)); |
|
|
|
|
|
|
|
|
ps.setNull(index++, Types.VARCHAR); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|