Commit 9191b2e8 authored by 张俊's avatar 张俊

单位销户开发

parent 5b767a4c
package net.cdkj.gjj.adapter;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(InternalLogicApplication.class);
}
}
...@@ -29,6 +29,8 @@ public class AlarmTask { ...@@ -29,6 +29,8 @@ public class AlarmTask {
@Resource @Resource
private DeptInfoUpdateController deptInfoUpdateController; private DeptInfoUpdateController deptInfoUpdateController;
@Resource @Resource
private DeptLogoutController deptLogoutController;
@Resource
private ProvidentFundServicesController providentFundServicesController; private ProvidentFundServicesController providentFundServicesController;
/** /**
...@@ -68,5 +70,18 @@ public class AlarmTask { ...@@ -68,5 +70,18 @@ public class AlarmTask {
log.debug("dwxxbgPullTask 开始时间:{}", InternalUtils.getCurrentTime()); log.debug("dwxxbgPullTask 开始时间:{}", InternalUtils.getCurrentTime());
deptInfoUpdateController.dwxxbgPull(); deptInfoUpdateController.dwxxbgPull();
} }
@Scheduled(initialDelay = 80 * 1000, fixedDelayString = "${dwxhPushTaskDelay}")
public void dwxhPushTask() {
log.debug("dwxhPushTask 开始时间:{}", InternalUtils.getCurrentTime());
deptLogoutController.dwxhPush();
}
@Scheduled(initialDelay = 100 * 1000, fixedDelayString = "${dwxhPullTaskDelay}")
public void dwxhPullTask() {
log.debug("dwxhPullTask 开始时间:{}", InternalUtils.getCurrentTime());
deptLogoutController.dwxhPull();
}
} }
...@@ -320,7 +320,10 @@ public class DeptInfoUpdateController { ...@@ -320,7 +320,10 @@ public class DeptInfoUpdateController {
bp.setEntName(rs.getString(9)); bp.setEntName(rs.getString(9));
} }
if (StringUtils.hasText(rs.getString(10))) { if (StringUtils.hasText(rs.getString(10))) {
bp.setBusId(rs.getString(10)); bp.setRn(rs.getString(10));
}
if (StringUtils.hasText(rs.getString(11))) {
bp.setBusId(rs.getString(11));
} }
list.add(bp); list.add(bp);
} }
......
package net.cdkj.gjj.adapter.controller;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import net.cdkj.gjj.adapter.domain.AjaxResult;
import net.cdkj.gjj.adapter.domain.BusinessProcessing;
import net.cdkj.gjj.adapter.domain.Json;
import net.cdkj.gjj.adapter.domain.UnitAccountOpeningInformation;
import net.cdkj.gjj.adapter.utils.InternalUtils;
import oracle.jdbc.OracleTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* 公积金系统服务类
*/
@RestController
@RequestMapping(value = "/InternalLogic")
public class DeptLogoutController {
@Resource
private RestTemplate restTemplate;
@Resource
private DruidDataSource druidDataSource;
@Value("${frontEndProcessorServer}")
private String frontEndProcessorServer;
@Value("${timetype}")
private String timetype;
@Value("${startTime}")
private String startTime;
@Value("${endTime}")
private String endTime;
private static final Logger log = LoggerFactory.getLogger(DeptLogoutController.class);
/**
* 公积金系统服务接口内置机调前置机中间接口
*
* @param
* @param
*/
@ResponseBody
@PostMapping("/getDwxhHttp")
public String getDwxhHttp() {
JSONObject jsonObject = new JSONObject();
if ("1".equals(timetype)) {// 表示正式环境
jsonObject.put("startTime", InternalUtils.currentTime(0));// 正式环境
jsonObject.put("endTime", InternalUtils.currentTime(24));// 正式环境
} else if ("2".equals(timetype)) {// 表示测试环境或本地环境
jsonObject.put("startTime", startTime);// 测试环境或本地环境
jsonObject.put("endTime", endTime);// 测试环境或本地环境
}
jsonObject.put("app_id", "eb453ca78b354f2c9163a703530f5186");
jsonObject.put("app_secret", "9a31b84878654a72a999e38ef55aa186");
String str = jsonObject.toString();
String providentFundServices = frontEndProcessorServer + "/FrontEndProcessor/FrontEndProcessor/ProvidentFundServices";
//(测试环境地址)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
String forObject = restTemplate.postForObject(providentFundServices, str, String.class);
return forObject;
}
/**
* (第一个定时的)
* 调用公积金系统服务接口方法,请求前置机,让前置机请求市监接口,
* 拿到市监返回的开户信息json数据,经过前置机zip解压返回给本内置机处理
*
* @return
*/
@ResponseBody
@PostMapping("/dwxhPull")
public AjaxResult dwxhPull() {
// 1.调用公积金系统服务接口方法,请求前置机,让前置机请求市监接口,拿到市监返回的开户信息json数据,经过前置机zip解压返回给本内置机处理
// String dwxhHttp = getDwxhHttp();
String dwxhHttp = mockDwxhHttp();
log.info("拿到第一个接口返回的第三方数据:{}", dwxhHttp);
Json jsonentity = JSONObject.parseObject(dwxhHttp, Json.class);
List<UnitAccountOpeningInformation> bills = null;
if (!InternalUtils.isNullOrEmpty(jsonentity)) {
bills = jsonentity.getData();
}
if (CollectionUtils.isEmpty(bills)) {
log.info("第三方返回的报文中data数据为空!");
return AjaxResult.success("第三方返回的报文中data数据为空", null);
}
// 2.内置机处理返回的业务数据,调用oracle存储过程
Connection connection = null;
CallableStatement dwxhImp = null;
CallableStatement dwxhSave = null;
try {
connection = druidDataSource.getConnection();
// 得到预编译的Statement对象
dwxhImp = connection.prepareCall("{call JGJ_KSYW_DWXH.DWXH_IMP(?, ?, ?, ?, ?, ?, ?)}");
// 循环插入
for (UnitAccountOpeningInformation uniInfom : bills) {
if (!StringUtils.isEmpty(uniInfom.getOplocdistrict())) {
// 业务标识
String busId = StringUtils.hasText(uniInfom.getBusId()) ? uniInfom.getBusId() : "";
dwxhImp.setString(1, busId);
// 统一社会信用
String uscc = StringUtils.hasText(uniInfom.getUscc()) ? uniInfom.getUscc() : "";
dwxhImp.setString(2, uscc);
// 企业名称
String entName = StringUtils.hasText(uniInfom.getEntName()) ? uniInfom.getEntName() : "";
dwxhImp.setString(3, entName);
// 单位地址
String dom = StringUtils.hasText(uniInfom.getDom()) ? uniInfom.getDom() : "";
dwxhImp.setString(4, dom);
// 所属区域
String oplocdistrict = StringUtils.hasText(uniInfom.getOplocdistrict()) ? uniInfom.getOplocdistrict() : "";
dwxhImp.setString(5, oplocdistrict);
// 输出结果[第二个参数]
dwxhImp.registerOutParameter(6, OracleTypes.VARCHAR);
dwxhImp.registerOutParameter(7, OracleTypes.VARCHAR);
// 执行数据库查询操作
dwxhImp.execute();
// 获取出参
String errcode = dwxhImp.getString(7);
String errmsg = dwxhImp.getString(7);
log.info("DWXH_IMP 执行结果 errcode:{},errmsg :{}", errcode, errmsg);
if (StringUtils.isEmpty(errcode)) {
log.error("DWXH_IMP 执行结果 errcode:{},errmsg :{},对应数据为:{}", errcode, errmsg, JSON.toJSONString(uniInfom));
continue;
} else {
// 避免批量插入高并发,此处设置每次停顿5秒
Thread.currentThread().sleep(2000);
}
}
}
// 调完第一个存储过程DWXX_IMP之后再调DWKH_SAVE存储过程
dwxhSave = connection.prepareCall("{call JGJ_KSYW_DWXH.DWXH_SAVE()}");
dwxhSave.execute();
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
// 释放资源
try {
dwxhImp.close();
dwxhSave.close();
connection.close();
} catch (SQLException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
return AjaxResult.success("请求成功", null);
}
/**
* 模拟数据
*
* @return
*/
private static String mockDwxhHttp() {
List<UnitAccountOpeningInformation> informationList = new ArrayList<>();
UnitAccountOpeningInformation information = new UnitAccountOpeningInformation();
information.setBusId("2");
information.setUscc("91421122MAC7ANQB8C");
information.setEntName("红安县永利土石方工程有限公司");
information.setDom("湖北省黄冈市红安县高桥镇长扬路东端北侧119号");
information.setOplocdistrict("421122");
informationList.add(information);
Json json = new Json();
json.setData(informationList);
String dwxhHttp = JSONObject.toJSONString(json);
return dwxhHttp;
}
/**
* 住建部门返回公积金办理进度数据接口方法
* (第二个定时)
*
* @param
* @param
*/
@ResponseBody
@PostMapping("/dwxhPush")
public String dwxhPush() {
// 调oracle存储过程拿到进度推进的数据集合
List<BusinessProcessing> collDwxhList = collDwxh();
JSONObject jsonObject = new JSONObject();
jsonObject.put("state", "1");
if (!CollectionUtils.isEmpty(collDwxhList)) {
jsonObject.put("timestamp", collDwxhList.stream().min(Comparator.comparing(BusinessProcessing::getTime)).get().getTime());
jsonObject.put("busId", collDwxhList.stream().min(Comparator.comparing(BusinessProcessing::getTime)).get().getBusId());
} else {
jsonObject.put("timestamp", "");
jsonObject.put("busId", "");
}
jsonObject.put("departCode", "10");
jsonObject.put("nodeList", collDwxhList);
String str = jsonObject.toString();
String businessprocessingUrl = frontEndProcessorServer + "/FrontEndProcessor/FrontEndProcessor/BusinessProcessing";
//(测试环境)调用前置机将业务机封装的业务json数据发给前置机,让前置机去请求第三方的公积金系统服务接口
String forObject = restTemplate.postForObject(businessprocessingUrl, str, String.class);
log.info("前置机返回第三方解压之后的进度推送结果:{}", forObject);
JSONObject jsonObj = JSONObject.parseObject(forObject);
Integer value = "true".equals(jsonObj.getString("success")) ? 1 : 0;
String uscc = !CollectionUtils.isEmpty(collDwxhList) ? collDwxhList.get(0).getUscc() : "";
log.info("入参 uscc:{} value:{}", uscc, value);
collDwxhHx(uscc, value);
return forObject;
}
/**
* 住建部门返回公积金办理进度数据接口方法
* 调用oracle存储过程拿到进度数据,然后请求前置机,让前置机请求市监接口,将办理的进度数据推送给市监
*
* @return
*/
@ResponseBody
@PostMapping("/collDwxh")
public List<BusinessProcessing> collDwxh() {
List<BusinessProcessing> list = new ArrayList<>();
Connection connection = null;
CallableStatement dwxhCx = null;
ResultSet rs = null;
try {
// 1.调用oracle存储过程,拿到业务办理进度数据
connection = druidDataSource.getConnection();
// 调用过程,返回企业注册的审核信息
dwxhCx = connection.prepareCall("{call JGJ_KSYW_DWXH.DWXH_CX(?)}");
dwxhCx.registerOutParameter(1, OracleTypes.CURSOR);
dwxhCx.execute();
// 输出结果[第二个参数]
rs = (ResultSet) dwxhCx.getObject(1);// 此处的2要与存储过程中cursor的问题对应
while (rs.next()) {
BusinessProcessing bp = new BusinessProcessing();
if (StringUtils.hasText(rs.getString(1))) {
bp.setBusiLink(rs.getString(1));
}
if (StringUtils.hasText(rs.getString(2))) {
bp.setBusiType(rs.getString(2));
}
if (StringUtils.hasText(rs.getString(3))) {
bp.setOpeartor(rs.getString(3));
}
if (StringUtils.hasText(rs.getString(4))) {
bp.setTel(rs.getString(4));
}
if (StringUtils.hasText(rs.getString(5))) {
bp.setOpinion(rs.getString(5));
}
if (StringUtils.hasText(rs.getString(6))) {
bp.setResult(rs.getString(6));
}
if (StringUtils.hasText(rs.getString(7))) {
bp.setTime(rs.getString(7).substring(0, 19));
}
if (StringUtils.hasText(rs.getString(8))) {
bp.setUscc(rs.getString(8));
}
if (StringUtils.hasText(rs.getString(9))) {
bp.setEntName(rs.getString(9));
}
if (StringUtils.hasText(rs.getString(10))) {
bp.setRn(rs.getString(10));
}
if (StringUtils.hasText(rs.getString(11))) {
bp.setBusId(rs.getString(11));
}
list.add(bp);
}
log.info("调用 DWXH_CX 返回数据:{}", JSONObject.toJSONString(list));
} catch (Exception e) {
log.error("调用 DWXH_CX 异常:{}", e);
} finally {
// 释放资源
try {
rs.close();
dwxhCx.close();
connection.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return list;
}
public void collDwxhHx(String uscc, Integer value) {
Connection connection = null;
CallableStatement pstm = null;
// 1.调用oracle存储过程,拿到业务办理进度数据
try {
// 加载数据库驱动
connection = druidDataSource.getConnection();
// 得到预编译的Statement对象
pstm = connection.prepareCall("{call JGJ_KSYW_DWXH.DWXH_HX(?,?)}");
pstm.setString(1, uscc);
pstm.setInt(2, value);
pstm.execute();
} catch (Exception e) {
log.error("调用 DWXH_HX 过程异常:{}", e);
} finally {
// 释放资源
try {
pstm.close();
connection.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
...@@ -195,21 +195,6 @@ public class ProvidentFundServicesController { ...@@ -195,21 +195,6 @@ public class ProvidentFundServicesController {
CallableStatement pstm = connection.prepareCall("{call JGJ_KSYW_DWKH.DWXX_IMP(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); CallableStatement pstm = connection.prepareCall("{call JGJ_KSYW_DWKH.DWXX_IMP(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
// 调完第一个存储过程DWXX_IMP之后再调DWKH_SAVE存储过程 // 调完第一个存储过程DWXX_IMP之后再调DWKH_SAVE存储过程
CallableStatement pstm2 = connection.prepareCall("{call JGJ_KSYW_DWKH.DWKH_SAVE()}"); CallableStatement pstm2 = connection.prepareCall("{call JGJ_KSYW_DWKH.DWKH_SAVE()}");
// System.out.println(""+bills);
// 给参数赋值
// pstm.getString(1);
// 421102
// 421121
// 421122
// 421123
// 421124
// 421125
// 421126
// 421127
// 421181
// 421182
// 421101
if (!bills.isEmpty()) { if (!bills.isEmpty()) {
for (UnitAccountOpeningInformation uniInfom : bills) { for (UnitAccountOpeningInformation uniInfom : bills) {
if (!"".equals(uniInfom.getOplocdistrict()) && uniInfom.getOplocdistrict() != null) { if (!"".equals(uniInfom.getOplocdistrict()) && uniInfom.getOplocdistrict() != null) {
...@@ -402,7 +387,6 @@ public class ProvidentFundServicesController { ...@@ -402,7 +387,6 @@ public class ProvidentFundServicesController {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
// if(!list.isEmpty()){//查到数据才请求第三方接口推送
System.out.println("调第二个接口了存储过程返回的list" + list); System.out.println("调第二个接口了存储过程返回的list" + list);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("state", "1"); jsonObject.put("state", "1");
......
...@@ -30,6 +30,8 @@ public class BusinessProcessing { ...@@ -30,6 +30,8 @@ public class BusinessProcessing {
private String busId; private String busId;
private String rn;
public String getBusiLink() { public String getBusiLink() {
return busiLink; return busiLink;
} }
...@@ -110,19 +112,11 @@ public class BusinessProcessing { ...@@ -110,19 +112,11 @@ public class BusinessProcessing {
this.busId = busId; this.busId = busId;
} }
@Override public String getRn() {
public String toString() { return rn;
return "BusinessProcessing{" + }
"busiLink='" + busiLink + '\'' +
", busiType='" + busiType + '\'' + public void setRn(String rn) {
", opeartor='" + opeartor + '\'' + this.rn = rn;
", tel='" + tel + '\'' +
", opinion='" + opinion + '\'' +
", result='" + result + '\'' +
", time=" + time +
", uscc='" + uscc + '\'' +
", entName='" + entName + '\'' +
", busId='" + busId + '\'' +
'}';
} }
} }
package net.cdkj.gjj.adapter.utils;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.GZIPInputStream;
public class HttpUtil {
/**
* 获取请求入参数据
*/
public static String getReqData(HttpServletRequest request) {
StringBuffer json = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
json.append(line);
}
} catch (Exception e) {
System.out.println(e);
}
String str = json.toString();
System.out.println("要发送给第三方的公积金系统服务报文:" + str);
return str;
}
/**
* 发起 post 请求,并对出参进行解压缩
*/
public static String sendPost(String httpUrl, String content) {
StringBuffer sb = new StringBuffer();
HttpURLConnection conn = null;
OutputStream out = null;
try {
// 创建url 资源
URL url = new URL(httpUrl);
// 创建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("accept", "*/*");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
// 设置文件字符集:
conn.setRequestProperty("Charset", "UTF-8");
// 转换为字节数组
byte[] data = content.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();
GZIPInputStream gzis = new GZIPInputStream(is);
InputStreamReader reader = new InputStreamReader(gzis, "UTF-8");
BufferedReader br = new BufferedReader(reader);
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
System.out.println("第三方返回的zip解压缩之后的报文:" + sb);
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;
}
}
...@@ -32,6 +32,8 @@ dwkhPullTaskDelay:60000 ...@@ -32,6 +32,8 @@ dwkhPullTaskDelay:60000
dwkhPushTaskDelay:60000 dwkhPushTaskDelay:60000
dwxxbgPushTaskDelay:60000 dwxxbgPushTaskDelay:60000
dwxxbgPullTaskDelay:60000 dwxxbgPullTaskDelay:60000
dwxhPushTaskDelay:60000
dwxhPullTaskDelay:60000
# 日志配置 # 日志配置
logging.config:classpath:logback-spring.xml logging.config:classpath:logback-spring.xml
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
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