Commit ff36fb7b authored by 张俊's avatar 张俊

代码优化

parent 9191b2e8
...@@ -3,13 +3,12 @@ package net.cdkj.gjj.adapter.controller; ...@@ -3,13 +3,12 @@ package net.cdkj.gjj.adapter.controller;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import net.cdkj.gjj.adapter.config.JasyptConfig;
import net.cdkj.gjj.adapter.domain.BusinessProcessing; import net.cdkj.gjj.adapter.domain.BusinessProcessing;
import net.cdkj.gjj.adapter.domain.Json; import net.cdkj.gjj.adapter.domain.Json;
import net.cdkj.gjj.adapter.domain.PropertyqUtil;
import net.cdkj.gjj.adapter.domain.UnitAccountOpeningInformation; import net.cdkj.gjj.adapter.domain.UnitAccountOpeningInformation;
import net.cdkj.gjj.adapter.utils.HttpUtil;
import net.cdkj.gjj.adapter.utils.InternalUtils;
import oracle.jdbc.OracleTypes; import oracle.jdbc.OracleTypes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -17,14 +16,9 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -17,14 +16,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -72,69 +66,9 @@ public class ProvidentFundServicesController { ...@@ -72,69 +66,9 @@ public class ProvidentFundServicesController {
jsonObject.put("app_id", "eb453ca78b354f2c9163a703530f5186"); jsonObject.put("app_id", "eb453ca78b354f2c9163a703530f5186");
jsonObject.put("app_secret", "9a31b84878654a72a999e38ef55aa186"); jsonObject.put("app_secret", "9a31b84878654a72a999e38ef55aa186");
String str = jsonObject.toString(); String str = jsonObject.toString();
StringBuffer sb = new StringBuffer(); String spec = frontEndProcessorServer + "/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices";
HttpURLConnection conn = null; // 发起 post 请求
OutputStream out = null; return HttpUtil.sendPost(spec, str);
try {
// 创建url 资源
URL url = new URL(frontEndProcessorServer + "/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices");//(测试环境地址)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// URL url = new URL("http://192.168.101.34:8080/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices");//(本地测试地址)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// 创建http 连接
conn = (HttpURLConnection) url.openConnection();
// 设置允许输出
conn.setDoOutput(true);
// 设置允许输入
conn.setDoInput(true);
// 设置不使用缓存
conn.setUseCaches(false);
// 设置传递方式
conn.setRequestMethod("POST");
// 设置维持长连接
conn.setRequestProperty("Connection", "Keep-Alive");
// 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json");
// 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组
byte[] data = (str).getBytes("UTF-8");
// 设置文件长度
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
// 开始连接请求
conn.connect();
// 创建写入流,写入请求的字符串
out = new DataOutputStream(conn.getOutputStream());
out.write(data);
// 请求返回的状态
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
// 请求返回的数据
InputStream is = conn.getInputStream();
String readLine = new String();
BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
responseReader.close();
// System.out.println("前置机返回第三方解压之后的公积金服务数据:"+sb.toString());
return sb.toString();
} else {
System.out.println("请求失败!!!");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
}
}
if (conn != null) {
conn.disconnect();
}
}
return null;
} }
/** /**
...@@ -145,29 +79,7 @@ public class ProvidentFundServicesController { ...@@ -145,29 +79,7 @@ public class ProvidentFundServicesController {
@ResponseBody @ResponseBody
@PostMapping("currentime") @PostMapping("currentime")
public static String currenttime(int type) { public static String currenttime(int type) {
String time = null; return InternalUtils.currentTime(type);
if (type == 0) {
// 获取当天零点零分零秒的时间戳
Calendar curentDay = Calendar.getInstance();
curentDay.setTime(new Date());
curentDay.set(Calendar.HOUR_OF_DAY, 0);
curentDay.set(Calendar.MINUTE, 0);
curentDay.set(Calendar.SECOND, 0);
SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
time = df2.format(curentDay.getTime().getTime());
System.out.println(time);
} else if (type == 24) {
// 获取当天24点零分零秒的时间戳,即第二天零点时间
Calendar curentDay = Calendar.getInstance();
curentDay.setTime(new Date());
curentDay.set(Calendar.HOUR_OF_DAY, 24);
curentDay.set(Calendar.MINUTE, 0);
curentDay.set(Calendar.SECOND, 0);
SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
time = df2.format(curentDay.getTime().getTime());
System.out.println(time);
}
return time;
} }
/** /**
...@@ -404,57 +316,16 @@ public class ProvidentFundServicesController { ...@@ -404,57 +316,16 @@ public class ProvidentFundServicesController {
jsonObject.put("departCode", "10"); jsonObject.put("departCode", "10");
jsonObject.put("nodeList", list); jsonObject.put("nodeList", list);
String str = jsonObject.toString(); String str = jsonObject.toString();
StringBuffer sb = new StringBuffer(); String spec = frontEndProcessorServer + "/FrontEndProcessor/FrontEndProcessor/BusinessProcessing";
HttpURLConnection conn = null; // 发起 post 请求
OutputStream out = null; String result = HttpUtil.sendPost(spec, str);
try { if (result != null) {
// 创建url 资源
URL url = new URL(frontEndProcessorServer + "/FrontEndProcessor/FrontEndProcessor/BusinessProcessing");//(测试环境)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// URL url = new URL("http://192.168.101.34:8080/FrontEndProcessor/FrontEndProcessor/BusinessProcessing");//(本地环境)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
// 创建http 连接
conn = (HttpURLConnection) url.openConnection();
// 设置允许输出
conn.setDoOutput(true);
// 设置允许输入
conn.setDoInput(true);
// 设置不使用缓存
conn.setUseCaches(false);
// 设置传递方式
conn.setRequestMethod("POST");
// 设置维持长连接
conn.setRequestProperty("Connection", "Keep-Alive");
// 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json");
// 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组
byte[] data = (str).getBytes("UTF-8");
// 设置文件长度
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
// 开始连接请求
conn.connect();
// 创建写入流,写入请求的字符串
out = new DataOutputStream(conn.getOutputStream());
out.write(data);
// 请求返回的状态
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
// 请求返回的数据
InputStream is = conn.getInputStream();
String readLine = new String();
BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((readLine = responseReader.readLine()) != null) {
sb.append(readLine);
}
responseReader.close();
System.out.println("前置机返回第三方解压之后的进度推送结果" + sb.toString());
String uscc = ""; String uscc = "";
if (!list.isEmpty()) { if (!list.isEmpty()) {
uscc = list.get(0).getUscc(); uscc = list.get(0).getUscc();
} else {
} }
System.out.println(uscc); System.out.println(uscc);
JSONObject jsonObj = JSONObject.parseObject(sb.toString()); JSONObject jsonObj = JSONObject.parseObject(result);
String success = jsonObj.getString("success"); String success = jsonObj.getString("success");
Integer value = 0; Integer value = 0;
if ("true".equals(success)) { if ("true".equals(success)) {
...@@ -468,27 +339,8 @@ public class ProvidentFundServicesController { ...@@ -468,27 +339,8 @@ public class ProvidentFundServicesController {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println(value); System.out.println(value);
return sb.toString();
} else {
System.out.println("请求失败!!!");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
} }
} return result;
if (conn != null) {
conn.disconnect();
}
}
return null;
} }
/** /**
...@@ -572,7 +424,7 @@ public class ProvidentFundServicesController { ...@@ -572,7 +424,7 @@ public class ProvidentFundServicesController {
// 给参数赋值 // 给参数赋值
pstm.setString(1, uscc); pstm.setString(1, uscc);
pstm.setInt(2, value); pstm.setInt(2, value);
// pstm.registerOutParameter(1, OracleTypes.CURSOR); // pstm.registerOutParameter(1, OracleTypes.CURSOR);
// 执行数据库查询操作 // 执行数据库查询操作
pstm.execute(); pstm.execute();
// 输出结果[第二个参数] // 输出结果[第二个参数]
......
...@@ -31,7 +31,7 @@ public class HttpUtil { ...@@ -31,7 +31,7 @@ public class HttpUtil {
/** /**
* 发起 post 请求,并对出参进行解压缩 * 发起 post 请求
*/ */
public static String sendPost(String httpUrl, String content) { public static String sendPost(String httpUrl, String content) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
...@@ -54,8 +54,6 @@ public class HttpUtil { ...@@ -54,8 +54,6 @@ public class HttpUtil {
conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Connection", "Keep-Alive");
// 设置文件类型: // 设置文件类型:
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
// 设置文件字符集: // 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8"); conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组 // 转换为字节数组
...@@ -69,16 +67,15 @@ public class HttpUtil { ...@@ -69,16 +67,15 @@ public class HttpUtil {
out.write(data); out.write(data);
// 请求返回的状态 // 请求返回的状态
if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) { if (HttpURLConnection.HTTP_OK == conn.getResponseCode()) {
// 请求返回的数据,解压缩 // 请求返回的数据
InputStream is = conn.getInputStream(); InputStream is = conn.getInputStream();
GZIPInputStream gzis = new GZIPInputStream(is); String readLine = new String();
InputStreamReader reader = new InputStreamReader(gzis, "UTF-8"); BufferedReader responseReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
BufferedReader br = new BufferedReader(reader); while ((readLine = responseReader.readLine()) != null) {
String temp; sb.append(readLine);
while ((temp = br.readLine()) != null) {
sb.append(temp);
} }
System.out.println("第三方返回的zip解压缩之后的报文:" + sb); responseReader.close();
System.out.println("前置机返回第三方解压之后数据:" + sb);
return sb.toString(); return sb.toString();
} else { } else {
System.out.println("请求失败!!!"); System.out.println("请求失败!!!");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment