Commit 1db0d3e0 by wang_jiaxing

湖南读取flws内容入库

parent d1df71fd
......@@ -26,47 +26,23 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.1.7.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.com.winmage</groupId>
......@@ -125,12 +101,6 @@
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- ftp -->
<dependency>
......@@ -143,6 +113,10 @@
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--采集生成js文件功能 -->
<dependency>
<groupId>com.founder</groupId>
......
package com.founder.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
/**
* Created by summer on 2016/11/25.
*/
@Configuration
@MapperScan(basePackages = "com.founder.*.mysqldao", sqlSessionTemplateRef = "xzxtMysqlSqlSessionTemplate")
public class DataSourceXzxtMysqlConfig {
@Bean(name = "xzxtMysqlDataSource")
@ConfigurationProperties(prefix = "spring.datasource.mysql")
public DataSource xzxtMysqlDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "xzxtMysqlSqlSessionFactory")
public SqlSessionFactory xzxtMysqlSqlSessionFactory(@Qualifier("xzxtMysqlDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mysqlMapper/*.xml"));
return bean.getObject();
}
@Bean(name = "xzxtMysqlSqlSessionTemplate")
public SqlSessionTemplate xzxtMysqlSqlSessionTemplate(@Qualifier("xzxtMysqlSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
package com.founder.flwshq.controller;
import com.founder.flwshq.service.FlwsHqService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* 法律文书获取Controller层
*
* @author create by lystar
* @date 2022/5/16 09:26
*/
@RestController
@RequestMapping("/flws")
public class FlwsHqController {
@Autowired
private FlwsHqService flwsHqService;
@Scheduled(cron = "0 0 1 * * ?")
public void autoExecuteFlwsRw(){
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, -1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
executeFlwsRw(sdf.format(date), null, null, null, null);
}
@RequestMapping("/executeFlwsRw")
public String executeFlwsRw(String lastDate, String larq, String asjbh, String rybh, String wslb) {
try {
if (StringUtils.isEmpty(lastDate) && StringUtils.isEmpty(larq) && StringUtils.isEmpty(asjbh)) {
return "时间和案件编号不能同时为空";
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date;
if (!StringUtils.isEmpty(lastDate)) {
try {
date = sdf.parse(lastDate);
} catch (Exception e) {
return "时间格式不对";
}
} else {
date = null;
}
Date larqDate;
if (!StringUtils.isEmpty(larq)) {
try {
larqDate = sdf.parse(larq);
} catch (Exception e) {
return "时间格式不对";
}
} else {
larqDate = null;
}
return flwsHqService.executeFlwsRw(date, larqDate, asjbh, rybh, wslb);
} catch (Exception e) {
return e.getMessage();
}
}
}
package com.founder.flwshq.entity;
import lombok.Data;
/**
* 法律文书类(部分字段)
*
* @author create by lystar
* @date 2022/5/16 11:32
*/
@Data
public class TbStAsjFlws {
private String xxzjbh;
private String asjbh;
private String rybh;
private String wslb;
private byte[] wsnr;
private String wswz;
}
package com.founder.flwshq.mysqldao;
import com.founder.flwshq.entity.TbStAsjFlws;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
/**
* 法律文书获取Dao层
*
* @author create by lystar
* @date 2022/5/16 09:27
*/
@Mapper
@Repository
public interface FlwsHqDao {
List<TbStAsjFlws> selectList(@Param("lastDate") Date lastDate, @Param("larq") Date larq, @Param("asjbh") String asjbh, @Param("rybh") String rybh, @Param("wslb") String wslb);
void updateWsnrByXxzjbh(TbStAsjFlws flws);
}
package com.founder.flwshq.service;
import java.util.Date;
/**
* 法律文书获取Service层
*
* @author create by lystar
* @date 2022/5/16 09:27
*/
public interface FlwsHqService {
/**
* executeFlwsRw 执行法律文书任务
* @param lastDate : 上次执行时间
* @param larq : 立案日期
* @param asjbh : 案件编号
* @param rybh : 人员编号
* @param wslb : 文书类别
* @return java.lang.String
* @author lystar
* 2022/5/16 10:06
*/
String executeFlwsRw(Date lastDate, Date larq, String asjbh, String rybh, String wslb);
}
package com.founder.flwshq.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.founder.flwshq.entity.TbStAsjFlws;
import com.founder.flwshq.mysqldao.FlwsHqDao;
import com.founder.flwshq.service.FlwsHqService;
import com.founder.util.HttpUtil;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 法律文书获取Service层实现
*
* @author create by lystar
* @date 2022/5/16 09:27
*/
@Service
public class FlwsHqServiceImpl implements FlwsHqService {
@Autowired
private FlwsHqDao flwsHqDao;
@Override
public String executeFlwsRw(Date lastDate, Date larq, String asjbh, String rybh, String wslb) {
String url = "http://10.142.12.40:9120/XZSERVER/api/v1/getPdf";
wslb = getFlwsdm(wslb);
AtomicInteger cgsl = new AtomicInteger();
AtomicInteger sbsl = new AtomicInteger();
List<TbStAsjFlws> flwsList = flwsHqDao.selectList(lastDate, larq, asjbh, rybh, wslb);
int count = flwsList.size();
flwsList.stream().parallel().forEach(flws -> {
String jsonStr = HttpUtil.doPost(url + "?anjianbianhao=" + flws.getAsjbh() +
"&renyuanbianhao=" + (StringUtils.isEmpty(flws.getRybh()) ? "00000000000000000000000" : flws.getRybh()) +
"&wslb=" + getFlwsdm(flws.getWslb()));
try {
JSONObject jsonObject = JSON.parseObject(jsonStr);
String code = jsonObject.getString("code");
if ("OK".equals(code)) {
String pdfUrl = jsonObject.getString("url");
try (InputStream is = HttpUtil.getInputStreamByUrl(pdfUrl)) {
if (is != null) {
byte[] bytes = IOUtils.toByteArray(is);
if (bytes != null && bytes.length > 0) {
flws.setWsnr(bytes);
flws.setWswz("/sjsb/43/TB_ST_ASJ_FLWS/" + flws.getXxzjbh() + ".pdf");
// System.out.println(flws.getXxzjbh() + " ======== " + flws.getWsnr().length + "字节");
cgsl.incrementAndGet();
flwsHqDao.updateWsnrByXxzjbh(flws);
} else {
System.out.println("文件已损害,无内容");
}
} else {
System.out.println("文件已损害,无内容");
}
} catch (IOException e) {
e.printStackTrace();
sbsl.incrementAndGet();
}
} else {
System.out.println(jsonObject.getString("msg"));
}
} catch (Exception e) {
e.printStackTrace();
sbsl.incrementAndGet();
}
flws.setWsnr(null);
});
int cg = cgsl.get();
int sb = sbsl.get();
int wnr = count - cg - sb;
return "总共待更新法律文书数量:" + count + "个,其中成功更新数量:" + cg + "个,更新失败数量:" + sb + "个,文件不存在或内容为空数量:" + wnr + "个。";
}
private String getFlwsdm(String wslb){
String flwsdm = "";
if (wslb == null) {
return "";
}
switch (wslb) {
case "3109":
flwsdm = "010202";
break;
case "3218":
flwsdm = "050702";
break;
case "3127":
flwsdm = "050302";
break;
case "3124":
flwsdm = "050202";
break;
case "3022":
flwsdm = "030502";
break;
case "3008":
flwsdm = "030302";
break;
case "3015":
flwsdm = "030402";
break;
case "3002":
flwsdm = "020102";
break;
case "010202":
flwsdm = "3109";
break;
case "050702":
flwsdm = "3218";
break;
case "050302":
flwsdm = "3127";
break;
case "050202":
flwsdm = "3124";
break;
case "030502":
flwsdm = "3022";
break;
case "030302":
flwsdm = "3008";
break;
case "030402":
flwsdm = "3015";
break;
case "020102":
flwsdm = "3002";
break;
}
return flwsdm;
}
}
package com.founder.util;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class HttpUtil {
private static final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager();
private static final RequestConfig requestConfig;
static{
// 设置请求和传输超时时间
//setConnectTimeout:设置连接超时时间,单位毫秒。
//setSocketTimeout:请求获取数据的超时时间,单位毫秒。 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。
//setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒
requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
}
/**
* 从网络Url中下载文件
* @param urlStr
* @throws IOException
*/
public static InputStream getInputStreamByUrl(String urlStr) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn =null;
try {
conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");//指定通信方式为get
//设置超时间为3秒
conn.setConnectTimeout(3*1000);
conn.setDoInput(true);//允许读取文件
conn.setDoOutput(true);//允许写文件
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
conn.connect();//建立连接
return conn.getInputStream();
} catch (Exception e){
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
}
//得到输入流
return null;
}
public static String doGet(String url) {
// 不是每次创建新的HttpClient对象,而是从连接池中获取HttpClient对象
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm).build();
HttpGet httpget = new HttpGet(url);
String responseStr = "";
try {
responseStr = getResponseStr(httpClient.execute(httpget));
} catch (Exception e) {
e.printStackTrace();
}
return responseStr;
}
public static String doPost(String url){
// 不是每次创建新的HttpClient对象,而是从连接池中获取HttpClient对象
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm).build();
HttpPost httpPost = new HttpPost(url);
String responseStr = "";
try {
responseStr = getResponseStr(httpClient.execute(httpPost));
} catch (Exception e) {
e.printStackTrace();
}
return responseStr;
}
private static String getResponseStr(CloseableHttpResponse httpResponse) {
String entityStr = "";
CloseableHttpResponse response = null;
try {
response = httpResponse;
HttpEntity entity = response.getEntity();
if (entity != null) {
entityStr = EntityUtils.toString(entity,"UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return entityStr;
}
/**
* 请求的参数类型为json
* @param url
* @param json
* @return {username:"",pass:""}
*/
public static String doPostJson(String url, Map<String, String> headers, String json) {
// post请求返回结果
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm).build();
String jsonResult = null;
HttpPost httpPost = new HttpPost(url);
// 设置请求和传输超时时间
httpPost.setConfig(requestConfig);
if(headers != null) {
for (String key : headers.keySet()) {
httpPost.setHeader(key, headers.get(key));
}
}
try{
//设置参数解决中文乱码
if (null != json){
StringEntity entity = new StringEntity(json,"utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
}
//发送请求
CloseableHttpResponse result = httpClient.execute(httpPost);
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
// 读取服务器返回的json数据(然后解析)
jsonResult = EntityUtils.toString(result.getEntity(), "utf-8");
}else{
throw new Exception();
}
}catch (Exception e){
e.printStackTrace();
}finally{
httpPost.releaseConnection();
}
return jsonResult;
}
}
......@@ -12,6 +12,12 @@ spring:
password: YTHCJ
jdbc-url: jdbc:oracle:thin:@10.142.16.172:1621:STXZ
type: com.alibaba.druid.pool.DruidDataSource
mysql:
driver-class-name: com.mysql.cj.jdbc.Driver
username: xzxt
password: Hn_Xzxt43
jdbc-url: jdbc:mysql://65.26.10.145:4306/xzxt?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
type: com.alibaba.druid.pool.DruidDataSource
#配置jpa 使其展示sql语句
jpa:
......@@ -25,13 +31,17 @@ spring:
ftpserverip: 10.143.242.44
nginxport: 9053
ftpport: 4546+
ftpport: 4546
ftpuser: ftpuser
ftppass: fou3rfnder4SD1
ftpbathPath: C:/ftp/xzxt
ftpfilePath: /hunan
redistimeout: 60000
ipaddress: /IP_ADDRESS
fileDir: /data/file
outDir: /data/out
isCs: true
poorSize: 1000
codemsg:
status:
- code: "10101"
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.founder.flwshq.mysqldao.FlwsHqDao">
<update id="updateWsnrByXxzjbh">
update tb_st_asj_flws
set flws_dzwjnr = #{wsnr},
flws_dzwjwz = #{wswz,jdbcType=VARCHAR},
gxsj = now()
where xxzjbh = #{xxzjbh,jdbcType=VARCHAR}
</update>
<select id="selectList" resultType="com.founder.flwshq.entity.TbStAsjFlws">
select flws.xxzjbh as xxzjbh,
flws.asjbh as asjbh,
flws.asjxgrybh as rybh,
flws.flws_asjflwsdm as wslb
from tb_st_asj_flws flws, tb_st_asj asj
where flws.xxsc_pdbz = '0' and asj.xxsc_pdbz = '0'
and flws.asjbh = asj.asjbh
and flws.flws_asjflwsdm in('010202', '050702', '050302', '050202', '030502', '030302', '030402', '020102')
<!--and (flws.flws_dzwjnr is null or octet_length(flws.flws_dzwjnr) = 0-->
<if test="lastDate != null">
and (flws.djsj >= #{lastDate,jdbcType=DATE}
or flws.gxsj >= #{lastDate,jdbcType=DATE}
or flws.xxrsksj >= #{lastDate,jdbcType=DATE})
</if>
<if test="larq != null">
and asj.larq >= #{larq,jdbcType=DATE}
</if>
<if test="asjbh != null and asjbh != ''">
and flws.asjbh = #{asjbh,jdbcType=VARCHAR}
</if>
<if test="rybh != null and rybh != ''">
and flws.asjxgrybh = #{rybh,jdbcType=VARCHAR}
</if>
<if test="wslb != null and wslb != ''">
and flws.flws_asjflwsdm = #{wslb,jdbcType=VARCHAR}
</if>
</select>
</mapper>
\ No newline at end of file
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