Commit 45b24b13 by wang_jiaxing

新疆法律文书从ftp拿去文件

parent dcef7317
......@@ -237,7 +237,7 @@
<!-- 公司的maven plugin仓库 -->
<pluginRepository>
<id>founder</id>
<url>http://39.99.224.27:8081/nexus/content/groups/public/</url>
<url>http://47.92.223.200:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
......
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.file.dao.jzzjk", sqlSessionTemplateRef = "jzzjkSqlSessionTemplate")
public class DataSourceJzzjkConfig {
@Bean(name = "jzzjkDataSource")
@ConfigurationProperties(prefix = "spring.datasource.jzzjk")
public DataSource db2DataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "jzzjkSqlSessionFactory")
public SqlSessionFactory db2SqlSessionFactory(@Qualifier("jzzjkDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/xjFlwsMpaaer/*.xml"));
return bean.getObject();
}
@Bean(name = "jzzjkSqlSessionTemplate")
public SqlSessionTemplate db2SqlSessionTemplate(@Qualifier("jzzjkSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
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.file.dao.xjxz", sqlSessionTemplateRef = "xjxzSqlSessionTemplate")
public class DataSourceXjxzConfig {
@Bean(name = "xjxzDataSource")
@ConfigurationProperties(prefix = "spring.datasource.xjxz")
public DataSource db1DataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "xjxzSqlSessionFactory")
public SqlSessionFactory db1SqlSessionFactory(@Qualifier("xjxzDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/xjFlwsMpaaer/*.xml"));
return bean.getObject();
}
@Bean(name = "xjxzSqlSessionTemplate")
public SqlSessionTemplate db1SqlSessionTemplate(@Qualifier("xjxzSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
package com.founder.file.controller;
import com.founder.file.service.XjFlwsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Calendar;
import java.util.Date;
@RestController
@Slf4j
public class XjFlwsController {
@Autowired
private XjFlwsService xjFlwsService;
@RequestMapping("/getJzzjkFlwsnrToXjxz")
public String getJzzjkFlwsnrToXjxz(@DateTimeFormat(pattern = "yyyyMMdd") Date date, @RequestParam(required = false) String xxzjbh){
try {
if (date == null){
Calendar calendar=Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DATE, -1);
date = calendar.getTime();
}
return xjFlwsService.getJzzjkFlwsnrToXjxz(date, xxzjbh);
} catch (Exception e) {
e.printStackTrace();
log.error("错误信息", e);
return e.getMessage();
}
}
@Scheduled(cron = "0 0 0 * * ?")
public void autoGetJzzjkFlwsnrToXjxz(){
getJzzjkFlwsnrToXjxz(null, null);
}
}
package com.founder.file.dao.jzzjk;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Mapper
@Component
public interface JzzjkFlwsMapper {
List<Map<String, String>> getFlwsWzByDate(@Param("date") Date date, @Param("xxzjbh") String xxzjbh, @Param("page") Integer page, @Param("rows") Integer rows);
Integer getFlwsCountWzByDate(@Param("date") Date date, @Param("xxzjbh") String xxzjbh);
}
package com.founder.file.dao.xjxz;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Mapper
@Component
public interface XjxzFlwsMapper {
void update(@Param("xxzjbh") String xxzjbh, @Param("bytes") byte[] bytes);
List<String> getNoFileFlwsXxzjbh(@Param("flwsList") List<Map<String, String>> flwsList);
}
package com.founder.file.service;
import java.io.IOException;
import java.util.Date;
public interface XjFlwsService {
String getJzzjkFlwsnrToXjxz(Date date, String xxzjbh) throws IOException;
}
package com.founder.file.service.impl;
import com.founder.file.dao.jzzjk.JzzjkFlwsMapper;
import com.founder.file.dao.xjxz.XjxzFlwsMapper;
import com.founder.file.service.XjFlwsService;
import com.founder.util.HttpUtil;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.FutureTask;
@Service
public class XjFlwsServiceImpl implements XjFlwsService {
@Autowired
private JzzjkFlwsMapper jzzjkFlwsMapper;
@Autowired
private XjxzFlwsMapper xjxzFlwsMapper;
@Override
public String getJzzjkFlwsnrToXjxz(Date date, String xxzjbh) throws IOException {
Integer count = jzzjkFlwsMapper.getFlwsCountWzByDate(date, xxzjbh);
int page = (count / 1000) + 1;
ArrayList<FutureTask<Map<String, Integer>>> list = new ArrayList<>();
for (int i = 0; i < page; i++) {
int limit = 1000;
int begin = i * limit;
int end = (i+1) * limit;
int finalI = i;
FutureTask<Map<String, Integer>> xsAjTask = new FutureTask<>(() -> {
HashMap<String, Integer> map = new HashMap<>();
List<Map<String, String>> flwsList = jzzjkFlwsMapper.getFlwsWzByDate(date, xxzjbh, begin, end);
List<String> xxzjbhList = xjxzFlwsMapper.getNoFileFlwsXxzjbh(flwsList);
HashSet<String> set = new HashSet<>(xxzjbhList);
map.put("flws", set.size());
ArrayList<Exception> exceptions = new ArrayList<>();
System.out.println("+++++++++++++" + flwsList.size());
int j = 1;
for (Map<String, String> flws : flwsList) {
if (!set.contains(flws.get("XXZJBH"))){
continue;
}
try {
String flwsUrl = flws.get("FWDZ") + flws.get("TXLJ");
InputStream is = HttpUtil.getInputStreamByUrl(flwsUrl);
byte[] bytes = IOUtils.toByteArray(is);
xjxzFlwsMapper.update(flws.get("XXZJBH"), bytes);
} catch (Exception e) {
exceptions.add(e);
}
System.out.println("线程" + finalI + "++++++++++++++" + (j++));
}
map.put("exceptions", flwsList.size());
System.out.println("=============" + exceptions.size());
return map;
});
new Thread(xsAjTask).start();
list.add(xsAjTask);
}
int flsws = 0;
int exc = 0;
for (FutureTask<Map<String, Integer>> task : list) {
try {
Map<String, Integer> map = task.get();
flsws += map.get("flws");
exc += map.get("exceptions");
} catch (Exception e) {
e.printStackTrace();
exc += 1;
}
}
return "共更新了" + flsws + "个法律文书,其中出错" + exc + "个法律文书";
}
}
package com.founder.task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.founder.model.Rycj;
import com.founder.model.Jccj;
import com.founder.service.RycjService;
import com.founder.service.LogService;
import com.founder.dictmanager.model.GabXfdm;
import com.founder.dictmanager.service.DictService;
import com.founder.dictmanager.service.RedisService;
@Component
public class ScheduleTask {
@Autowired
private RycjService rycjService;
@Autowired
private LogService logService;
@Autowired
private DictService sysDictService;
@Autowired
private RedisService redisService;
private SimpleDateFormat format=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
private Logger logger= LoggerFactory.getLogger(ScheduleTask.class);
/*
* 定时任务从采集平台获取的信息发送给公安部
* */
/*
* 定时执行-查询一个表中的数据,存到字典表或者字典js文件
* */
private void xxbsSerevice(){
logger.info("This is a say method!"+format.format(new Date()));
//1.从表中获取未上报的信息
List<Rycj> list= rycjService.selectRycj();
if(list!=null&&list.size()>0){
for(Rycj r:list) {
r.getRycj_dzwjwz();//url
Rycj rycj =new Rycj();
rycj.setTaskid(r.getTaskid());
rycj.setUser_id(r.getUser_id());
/*//直接从服务器获取zip包并转成base64
Jccj jccj =new Jccj();
URL url = new URL(r.getRycj_dzwjwz());
URL url = new URL("http://47.92.129.99/neimeng/FZXZ/201909/JCXX-R1100000500002014070008.zip");
InputStream inStream = url.openStream();
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据
int rc = 0;
while ((rc = inStream.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
byte[] in_b = swapStream.toByteArray(); //in_b为转换之后的结果
final String encodedText = encoder.encodeToString(in_b);
jccj.setXxsb_zip(encodedText);
jccj.setTaskid("JCXX-R1100000500002014070008");
jccj.setUser_id("142728188997588823");
jccj.setUser_dept("1400000000");
jccj.setVersion("1.00");*/
//2..将从采集平台获取的信息,在发送给公安部
// JSONObject jsonResult= requestByPost("http://api.xz.xz.ga/jccj/xxbs",jccj);
//更新写日志
//公安部接口开通后Status_code等在jsonResult中解析
rycj.setStatus_code("10102");
rycj.setZxjgdm("00000");
rycj.setStatus_message("大西瓜");
rycjService.updateStatusByPrimaryKey(rycj);
logService.insertLog(rycj);
}
}
}
private void dictSerevice(){
//查询信息服务告知信息处理标志为"0"的数量
int undealCodes=sysDictService.getUndealXfdms();
logger.info("undealCodes:"+undealCodes);
if(undealCodes>0){
int q=undealCodes/100;
int m=undealCodes%100;
logger.info("undealCodes:"+undealCodes+",q:"+q+",m:"+m);
for(int i=0;i<q;i++){
logger.warn("这是第"+i+"批次任务");
List<GabXfdm> lists=sysDictService.getGabXfdmRows(100);
int r= -1;
try {
r = sysDictService.updateManagerDicts(lists);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("更新行数:"+r);
}
if(m>0){
logger.warn("这是剩余的"+m+"次任务");
List<GabXfdm> lists=sysDictService.getGabXfdmRows(m);
int r= -1;
try {
r = sysDictService.updateManagerDicts(lists);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("更新行数:"+r);
}
//刷新redis
redisService.flushAll();
//更新js文件
sysDictService.updateSysDictJsFiles();
}
}
}
// package com.founder.task;
//
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.scheduling.annotation.Scheduled;
// import org.springframework.stereotype.Component;
//
// import java.text.SimpleDateFormat;
// import java.util.Date;
// import java.util.List;
// import com.founder.model.Rycj;
// import com.founder.model.Jccj;
// import com.founder.service.RycjService;
// import com.founder.service.LogService;
// import com.founder.dictmanager.model.GabXfdm;
// import com.founder.dictmanager.service.DictService;
// import com.founder.dictmanager.service.RedisService;
// @Component
// public class ScheduleTask {
// @Autowired
// private RycjService rycjService;
// @Autowired
// private LogService logService;
// @Autowired
// private DictService sysDictService;
// @Autowired
// private RedisService redisService;
//
// private SimpleDateFormat format=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//
// private Logger logger= LoggerFactory.getLogger(ScheduleTask.class);
//
// /*
// * 定时任务从采集平台获取的信息发送给公安部
// * */
//
// /*
// * 定时执行-查询一个表中的数据,存到字典表或者字典js文件
// * */
//
//
// private void xxbsSerevice(){
// logger.info("This is a say method!"+format.format(new Date()));
// //1.从表中获取未上报的信息
// List<Rycj> list= rycjService.selectRycj();
// if(list!=null&&list.size()>0){
// for(Rycj r:list) {
// r.getRycj_dzwjwz();//url
// Rycj rycj =new Rycj();
// rycj.setTaskid(r.getTaskid());
// rycj.setUser_id(r.getUser_id());
// /*//直接从服务器获取zip包并转成base64
// Jccj jccj =new Jccj();
// URL url = new URL(r.getRycj_dzwjwz());
// URL url = new URL("http://47.92.129.99/neimeng/FZXZ/201909/JCXX-R1100000500002014070008.zip");
// InputStream inStream = url.openStream();
// ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
// byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据
// int rc = 0;
// while ((rc = inStream.read(buff, 0, 100)) > 0) {
// swapStream.write(buff, 0, rc);
// }
// byte[] in_b = swapStream.toByteArray(); //in_b为转换之后的结果
// final String encodedText = encoder.encodeToString(in_b);
// jccj.setXxsb_zip(encodedText);
// jccj.setTaskid("JCXX-R1100000500002014070008");
// jccj.setUser_id("142728188997588823");
// jccj.setUser_dept("1400000000");
// jccj.setVersion("1.00");*/
//
// //2..将从采集平台获取的信息,在发送给公安部
// // JSONObject jsonResult= requestByPost("http://api.xz.xz.ga/jccj/xxbs",jccj);
// //更新写日志
// //公安部接口开通后Status_code等在jsonResult中解析
// rycj.setStatus_code("10102");
// rycj.setZxjgdm("00000");
// rycj.setStatus_message("大西瓜");
// rycjService.updateStatusByPrimaryKey(rycj);
// logService.insertLog(rycj);
// }
// }
// }
//
// private void dictSerevice(){
// //查询信息服务告知信息处理标志为"0"的数量
// int undealCodes=sysDictService.getUndealXfdms();
// logger.info("undealCodes:"+undealCodes);
// if(undealCodes>0){
// int q=undealCodes/100;
// int m=undealCodes%100;
// logger.info("undealCodes:"+undealCodes+",q:"+q+",m:"+m);
// for(int i=0;i<q;i++){
// logger.warn("这是第"+i+"批次任务");
// List<GabXfdm> lists=sysDictService.getGabXfdmRows(100);
// int r= -1;
// try {
// r = sysDictService.updateManagerDicts(lists);
// } catch (Exception e) {
// e.printStackTrace();
// }
// System.out.println("更新行数:"+r);
// }
// if(m>0){
// logger.warn("这是剩余的"+m+"次任务");
// List<GabXfdm> lists=sysDictService.getGabXfdmRows(m);
// int r= -1;
// try {
// r = sysDictService.updateManagerDicts(lists);
// } catch (Exception e) {
// e.printStackTrace();
// }
// System.out.println("更新行数:"+r);
// }
// //刷新redis
// redisService.flushAll();
// //更新js文件
// sysDictService.updateSysDictJsFiles();
// }
// }
// }
package com.founder.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpUtil {
/**
* 从网络Url中下载文件
* @param urlStr
* @throws IOException
*/
public static InputStream getInputStreamByUrl(String urlStr) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection 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();
}
}
......@@ -12,6 +12,18 @@ spring:
password: manager
jdbc-url: jdbc:oracle:thin:@47.92.129.99:1600:orcl
type: com.alibaba.druid.pool.DruidDataSource
xjxz:
jdbc-url: jdbc:oracle:thin:@10.20.2.208:6521:XJXZXT
username: XZXT
password: XzxtPwd#65
driver-class-name: oracle.jdbc.driver.OracleDriver
type: com.alibaba.druid.pool.DruidDataSource
jzzjk:
jdbc-url: jdbc:oracle:thin:@10.20.2.208:6521:XJXZXT
username: JZZJK
password: JZZJK
driver-class-name: oracle.jdbc.driver.OracleDriver
type: com.alibaba.druid.pool.DruidDataSource
#配置jpa 使其展示sql语句
jpa:
......
<?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.file.dao.jzzjk.JzzjkFlwsMapper">
<select id="getFlwsWzByDate" resultType="java.util.Map">
select *
from (select rownum r, t.*
from (
select dz.FWDZ as fwdz,
dz.TXLJ as txlj,
fl.XXZJBH as xxzjbh
from AJ_DZJZXX dz, AJ_FLWS fl, XZXT.TB_ST_ASJ_FLWS flws
where dz.flwsbh = fl.flwsbh
and dz.ajbh = fl.ajbh
and dz.txsx = fl.txsx
and dz.txlj = fl.txlj
and fl.xxzjbh = flws.xxzjbh
and flws.flws_dzwjnr is null
and to_date(DJRQ, 'yyyyMMdd') <![CDATA[>=]]> #{date}
<if test="xxzjbh != null and xxzjbh != ''">
and dz.TZTXBH = #{xxzjbh}
</if>) t
where rownum <![CDATA[ <= ]]> #{page})
where r <![CDATA[ > ]]> #{rows}
</select>
<select id="getFlwsCountWzByDate" resultType="java.lang.Integer">
select count(1)
from AJ_DZJZXX dz, AJ_FLWS fl, XZXT.TB_ST_ASJ_FLWS flws
where dz.flwsbh = fl.flwsbh
and dz.ajbh = fl.ajbh
and dz.txsx = fl.txsx
and dz.txlj = fl.txlj
and fl.xxzjbh = flws.xxzjbh
and flws.flws_dzwjnr is null
and to_date(DJRQ, 'yyyyMMdd') <![CDATA[>=]]> #{date}
<if test="xxzjbh != null and xxzjbh != ''">
and dz.TZTXBH = #{xxzjbh}
</if>
</select>
</mapper>
\ No newline at end of file
<?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.file.dao.xjxz.XjxzFlwsMapper">
<update id="update">
update TB_ST_ASJ_FLWS set FLWS_DZWJNR = #{bytes}, GXSJ = sysdate where xxzjbh = #{xxzjbh}
</update>
<select id="getNoFileFlwsXxzjbh" resultType="java.lang.String">
select xxzjbh from TB_ST_ASJ_FLWS where FLWS_DZWJNR is null and xxzjbh in
<foreach collection="flwsList" item="flws" open="(" separator="," close=")">
#{flws.XXZJBH}
</foreach>
</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