优化同步数据

master
zengwh 4 years ago
parent 914803e2e6
commit 4547504088

@ -1,114 +0,0 @@
/*
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
https://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.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}

Binary file not shown.

@ -1 +0,0 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip

@ -17,6 +17,7 @@
<properties>
<java.version>1.8</java.version>
<skipTests>true</skipTests>
</properties>
<dependencies>

@ -0,0 +1,53 @@
package com.ann.demo.controller;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.CXFBusFactory;
import org.apache.cxf.endpoint.EndpointImplFactory;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.jaxws.support.JaxWsEndpointImplFactory;
import java.util.List;
/**
* @ProjectName:
* @Description:
* @Param
* @Return
* @Author:
* @CreateDate: 2019/9/11 16:15
* @UpdateUser:
* @UpdateDate: 2019/9/11 16:15
* @UpdateRemark:
* @Version: 1.0
*/
public class JAXDynamicClientFactory extends DynamicClientFactory {
protected JAXDynamicClientFactory(Bus bus) {
super(bus);
}
@Override
protected EndpointImplFactory getEndpointImplFactory() {
return JaxWsEndpointImplFactory.getSingleton();
}
@Override
protected boolean allowWrapperOps() {
return true;
}
public static JAXDynamicClientFactory newInstance() {
Bus bus = CXFBusFactory.getThreadDefaultBus();
return new JAXDynamicClientFactory(bus);
}
@Override
public boolean compileJavaSrc(String classPath, List srcList, String dest) {
org.apache.cxf.common.util.Compiler javaCompiler
= new org.apache.cxf.common.util.Compiler();
javaCompiler.setEncoding("UTF-8");
javaCompiler.setClassPath(classPath);
javaCompiler.setOutputDir(dest);
javaCompiler.setTarget("1.8");
return javaCompiler.compileFiles(srcList);
}
}

@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDateTime;
import java.util.List;
@ -67,12 +68,25 @@ public class TestController {
public String cc() {
LocalDateTime beginTime = LocalDateTime.now();
logger.error("开始时间:"+beginTime);
List<ScanningFile> scanningFiles = scanningFileRepository.findScanningFiles();
List<ScanningFile> scanningFiles = scanningFileRepository.findScanningFiles(1);
analysisService.handleScanningFile(scanningFiles);
LocalDateTime endTime = LocalDateTime.now();
logger.error("结束时间:"+endTime);
return "成功";
}
@RequestMapping("/runData")
@ResponseBody
public String runData() {
LocalDateTime beginTime = LocalDateTime.now();
logger.error("开始时间:"+beginTime);
List<ScanningFile> scanningFiles = scanningFileRepository.findScanningFileList();
logger.error("查询出待处理记录数:"+scanningFiles.size()+"个");
analysisService.handleScanningFile(scanningFiles);
LocalDateTime endTime = LocalDateTime.now();
logger.error("结束时间:"+endTime);
return "完成共计:"+scanningFiles.size()+"同步";
}
}

@ -38,7 +38,7 @@ public class ArchiveDetail {
@Column(name = "subassort")
private String subAssort;
@Column(name = "Title")
private String title;
private String flag = "0";
@ -67,4 +67,14 @@ public class ArchiveDetail {
this.pdfPath = pdfPath;
this.number = number;
}
public ArchiveDetail(String masterID, Date upLoadDateTime, String assortID, String source, String applyId, String pdfPath,Integer number,String title) {
this.masterID = masterID;
this.upLoadDateTime = upLoadDateTime;
this.assortID = assortID;
this.source = source;
this.applyId = applyId;
this.pdfPath = pdfPath;
this.number = number;
this.title = title;
}
}

@ -0,0 +1,212 @@
package com.ann.demo.job;
import com.ann.demo.primaryEntity.ScanningFile;
import com.ann.demo.primaryRepository.ScanningFileRepository;
import com.ann.demo.service.AnalysisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @ProjectName:
* @Description:
* @Param
* @Return
* @Author:
* @CreateDate: 2021/12/22 0:07
* @UpdateUser:
* @UpdateDate: 2021/12/22 0:07
* @UpdateRemark:
* @Version: 1.0
*/
@Component
public class DataRunner implements ApplicationRunner {
static final Logger logger = LoggerFactory.getLogger(DataRunner.class);
private static int flag = 0;
private static int count = 0;
@Autowired
private ScanningFileRepository scanningFileRepository;
@Autowired
private AnalysisService analysisService;
@Override
public void run(ApplicationArguments args) throws Exception {
if(flag == 0) {
List<ScanningFile> scanningFiles = scanningFileRepository.findScanningFileList();
count = scanningFiles.size();
logger.error("查询出待处理记录数:"+scanningFiles.size()+"个");
analysisService.handleScanningFile(scanningFiles);
flag = 1;
}
if(count != 0) {
Thread t1 = new Thread1();
Thread t2 = new Thread2();
Thread t3 = new Thread3();
Thread t4 = new Thread4();
Thread t5 = new Thread5();
Thread t6 = new Thread6();
Thread t7 = new Thread7();
Thread t8 = new Thread8();
Thread t9 = new Thread9();
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
t6.start();
t7.start();
t8.start();
t9.start();
}
}
class Thread1 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread2 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread3 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread4 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread5 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread6 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread7 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread8 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread9 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread10 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}

@ -34,7 +34,8 @@ import java.util.concurrent.ScheduledFuture;
public class ScheduledJob implements Job {
static final Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
private static int flag = 0;
private static int count = 0;
@Autowired
private ScanningFileRepository scanningFileRepository;
@ -50,11 +51,285 @@ public class ScheduledJob implements Job {
@Value("${over}")
private int over;
@Override
public void execute(JobExecutionContext context) {
QuartzUtils.pauseScheduleJob(scheduler, "group1", "job1");
try {
if(flag == 0) {
List<ScanningFile> scanningFiles = scanningFileRepository.findScanningFileList();
count = scanningFiles.size();
logger.error("查询出待处理记录数:"+scanningFiles.size()+"个");
analysisService.handleScanningFile(scanningFiles);
flag = 1;
}
if(count != 0) {
Thread t1 = new Thread1();
Thread t2 = new Thread2();
Thread t3 = new Thread3();
Thread t4 = new Thread4();
Thread t5 = new Thread5();
Thread t6 = new Thread6();
Thread t7 = new Thread7();
Thread t8 = new Thread8();
Thread t9 = new Thread9();
Thread t10 = new Thread10();
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
/* t6.start();
t7.start();
t8.start();
t9.start();
t10.start();*/
/* Thread t11 = new Thread10();
t11.start();
Thread t12 = new Thread10();
t12.start();
Thread t13 = new Thread10();
t13.start();
Thread t14 = new Thread10();
t14.start();
Thread t15 = new Thread10();
t15.start();*/
}
} catch (Exception e) {
// 如果报错-- 捕捉异常 继续执行
logger.error("执行定时任务出错:{}" ,e.getMessage());
}
QuartzUtils.resumeScheduleJob(scheduler, "group1", "job1");
}
class Thread1 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread2 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread3 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread4 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread5 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread6 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread7 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread8 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread9 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread10 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread11 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread12 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread13 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread14 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Thread15 extends Thread {
@Override
public void run() {
while (true) {
try {
count--;
analysisService.startThread(count);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/*
@Override
public void execute(JobExecutionContext context) {
QuartzUtils.pauseScheduleJob(scheduler, "group1", "job1");
List<ScanningFile> scanningFiles =new ArrayList<ScanningFile>();
LocalDateTime beginTime = LocalDateTime.now();
try {
if(start==0){
scanningFiles = scanningFileRepository.findScanningFiles(over);
@ -67,10 +342,8 @@ public class ScheduledJob implements Job {
logger.error("执行定时任务出错:{}" ,e.getMessage());
}
QuartzUtils.resumeScheduleJob(scheduler, "group1", "job1");
LocalDateTime endTime = LocalDateTime.now();
logger.error("总耗时:"+ Duration.between(beginTime,endTime).toMillis()/1000);
logger.error("结束时间:{}" ,LocalDateTime.now());
}
*/
}

@ -61,11 +61,11 @@ public class SchedulerAllJob {
*/
JobDetail jobDetail = JobBuilder.newJob(ScheduledJob.class).withIdentity("job1", "group1").build();
// 凌晨1点-凌晨7点 每隔1分钟执行一次
// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 */1 * * * ?");
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0,1,2,3,4,5,6,7,19,20,21,22,23 * * ? ");
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/30 * * * * ?");
// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0,1,2,3,4,5,6,7,19,20,21,22,23 * * ? ");
// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/1 * 16,17,18,19 * * ? ");
CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("job1", "group1").withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(jobDetail, cronTrigger);
/* CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("job1", "group1").withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(jobDetail, cronTrigger);*/
}
}

@ -19,7 +19,6 @@ public class QuartzConfig implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
scheduleJobs.scheduleJobs();
System.out.println(">>>>>>>>>>>>>>>定时任务开始执行<<<<<<<<<<<<<");
//scheduleJobs.scheduleJobs();
}
}

@ -4,6 +4,7 @@ import lombok.Data;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Data
@ -13,7 +14,7 @@ public class ScanningFile {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "id")
private String id;
private Long id;
//住院号
@Column(name = "FBIHID")
@ -99,5 +100,9 @@ public class ScanningFile {
@Column(name = "FLDM")
private String assortId;
//真实文件名
@Column(name = "FLMC")
private String realFileName;
@Transient
private List<byte[]> byteList;
}

@ -1,13 +1,12 @@
package com.ann.demo.primaryRepository;
import com.ann.demo.primaryEntity.ScanningFile;
import org.apache.xml.res.XMLErrorResources_tr;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.awt.print.Pageable;
import java.util.List;
@Repository
@ -22,4 +21,13 @@ public interface ScanningFileRepository extends JpaRepository<ScanningFile,Integ
public List<ScanningFile> findScanningFiles(int over);
@Query(nativeQuery= true,value = "select top(?1) * from scanning_file where STATUS = 0 and id not in (select top(?2) id from scanning_file where STATUS = 0 order by id desc) order by id desc")
public List<ScanningFile> findScanningFilesMore(int length,int start);
@Query(nativeQuery= true,value = "select * from scanning_file inner join (select MAX(id) id,FBIHID,FBINCU from scanning_file where STATUS = 0 group by FBIHID,FBINCU) scanning_file1 on scanning_file.id = scanning_file1.id")
public List<ScanningFile> findScanningFileList();
@Query(nativeQuery= true,value = "select * from scanning_file where FBIHID = (?1) and FBINCU = (?2) AND STATUS = 0")
public List<ScanningFile> findScanningFileDetailList(String inpNo,String visitId);
@Transactional
@Modifying(clearAutomatically = true)
@Query(nativeQuery = true,value="update scanning_file set FREMARK = (?1),STATUS = (?2) where id in (?3)")
public void updateBatch(String remark,String status,List<Long> ids);
}

@ -8,22 +8,25 @@ import com.ann.demo.entity.interfaceEntity.CommonTable1;
import com.ann.demo.entity.normalEntity.OutPara;
import com.ann.demo.primaryRepository.ScanningFileRepository;
import com.ann.demo.primaryEntity.ScanningFile;
import com.ann.demo.repository.ArchiveDetailRepository;
import com.ann.demo.repository.CommonTable1Repository;
import com.ann.demo.repository.CommonTableRepository;
import com.ann.demo.utils.*;
import com.itextpdf.text.DocumentException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.io.IOException;
import java.io.PrintStream;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
/**
@ -37,7 +40,7 @@ public class AnalysisService {
final Logger logger = LoggerFactory.getLogger(AnalysisService.class);
public static volatile LinkedBlockingQueue<ScanningFile> queue = new LinkedBlockingQueue<>();// 消息队列
@Autowired
private ScanningFileRepository scanningFileRepository;
@ -53,6 +56,17 @@ public class AnalysisService {
@Autowired
private ArchiveMasterService archiveMasterService;
@Autowired
private ArchiveDetailRepository archiveDetailRepository;
public void handleScanningFile(List<ScanningFile> scanningFileList) {
if(!CollectionUtils.isEmpty(scanningFileList)) {
//处理ScanningFile\
for (int i = 0;i < scanningFileList.size();i++) {
queue.add(scanningFileList.get(i));
}
}
}
/*
public void handleScanningFile(List<ScanningFile> scanningFileList) {
LocalDateTime beginTime = LocalDateTime.now();
logger.error("开始时间:"+beginTime);
@ -83,7 +97,236 @@ public class AnalysisService {
logger.error("结束时间:"+endTime);
}
*/
public void startThread(int i){
try {
ScanningFile scanningFile = queue.take();
handlePdfFile(scanningFile,i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private String savaHomePageData(ScanningFile scanningFile){
String masterId = null;
// 判断病案首页数据是否存在
try {
masterId = scanningFile.getApplyId() != null ? scanningFile.getApplyId() : UUID.randomUUID().toString();;
CommonTable commonTable = commonTableRepository.findByInpNoAndVisitId(scanningFile.getInpNo(), scanningFile.getVisitId());
if(null != commonTable) {
logger.error("commomtable.patientId=" + commonTable.getPatientId());
}
if(commonTable == null){
commonTable = new CommonTable(masterId,scanningFile.getPatientId(),scanningFile.getAge(),scanningFile.getSex(),scanningFile.getVisitId(),scanningFile.getName(),
scanningFile.getAdmissDate(),scanningFile.getDisDate(),scanningFile.getDisDept(),scanningFile.getAttending(),scanningFile.getInpNo(),"扫描系统");
// //保存公共表
commonTableRepository.save(commonTable);
//保存公共表1
commonTable1Repository.save( new CommonTable1(commonTable.getMasterId(),scanningFile.getBirthday(),scanningFile.getIdCard(),scanningFile.getAdmissDept(),scanningFile.getAdmissDoctor()));
}else{
masterId = commonTable.getMasterId();
}
} catch (Exception e) {
logger.error("保存首页数据出错了,FBIHID="+scanningFile.getInpNo() + "&FBINCU="+scanningFile.getVisitId());
e.printStackTrace();
throw new RuntimeException("保存首页数据出错了,FBIHID="+scanningFile.getInpNo() + "&FBINCU="+scanningFile.getVisitId());
}
logger.error("masterId="+masterId);
return masterId;
}
private void handlePdfFile(ScanningFile scanningFile,int i){
//保存首页数据
long start = System.currentTimeMillis();
long start1 = System.currentTimeMillis();
String masterId = savaHomePageData(scanningFile);
long end = System.currentTimeMillis();
logger.error("保存首页数据:FBIHID=" + scanningFile.getInpNo() + "&FBINCU="+scanningFile.getVisitId()+"所用时间:"+(end-start)/1000.00+"s");
//根据住院号和住院次数查询文件集合
//保存图片并更新scanningFile表数据
savePdfDetail(scanningFile,masterId);
long end1 = System.currentTimeMillis();
logger.error("完成同步:FBIHID=" + scanningFile.getInpNo() + "&FBINCU="+scanningFile.getVisitId()+"所用时间:"+(end1-start1)/1000.00+"s");
logger.error("剩余待处理记录数:" + i);
}
public static void main(String[] args) throws Exception{
for(int i = 0;i<100000;i++) {
long start = System.currentTimeMillis();
Object[] objects = WebServiceUtils.connect("123");
long end = System.currentTimeMillis();
System.out.println("("+(100000-i)+")调用webService接口所用时间:" + (end - start) / 1000.00 + "s");
}
}
private void savePdfDetail(ScanningFile scanningFile,String masterId) {
if(StringUtils.isNotBlank(masterId)) {
//根据住院号、住院次数查询文件明细
List<ScanningFile> scanningFiles = scanningFileRepository.findScanningFileDetailList(scanningFile.getInpNo(), scanningFile.getVisitId());
//处理ScanningFile
String remark = "";
//定义分组的文件明细map
Map<String, ScanningFile> fileMap = new HashMap<>();
//定义文件明细id集合
List<Long> ids = new ArrayList<>();
for (ScanningFile obj : scanningFiles) {
ids.add(obj.getId());
if (StringUtils.isBlank(remark)) {
//获取文件名称
String realFileName = obj.getRealFileName();
List<byte[]> byteList = new ArrayList<>();
try {
long start = System.currentTimeMillis();
Object[] objects = WebServiceUtils.connect(obj.getPath() + "\\" + obj.getFileName());
logger.error("objects:" + objects[0] + "&obj:" + obj.getId());
long end = System.currentTimeMillis();
logger.error("调用webService接口返回图片流:FBIHID=" + scanningFile.getInpNo() + "&FBINCU=" + scanningFile.getVisitId() + "所用时间:" + (end - start) / 1000.00 + "s");
if (fileMap.containsKey(realFileName)) {
//获取缓存scanningFile对象
obj = fileMap.get(realFileName);
//获取缓存字节流
byteList = obj.getByteList();
}
byteList.add((byte[]) objects[0]);
obj.setByteList(byteList);
fileMap.put(realFileName, obj);
} catch (Exception e) {
remark = e.getMessage();
e.printStackTrace();
logger.error("调用webService出错了:FBIHID=" + scanningFile.getInpNo() + "&FBINCU=" + scanningFile.getVisitId());
throw new RuntimeException("调用webService出错了:FBIHID=" + scanningFile.getInpNo() + "&FBINCU=" + scanningFile.getVisitId());
}
}
}
logger.error("fileMap:" + fileMap.toString());
//定义批量添加detail集合
List<ArchiveDetail> insertBatchList = new ArrayList<>();
if (!CollectionUtils.isEmpty(fileMap)) {
try {
long start = System.currentTimeMillis();
try {
for (Map.Entry<String, ScanningFile> map : fileMap.entrySet()) {
//获取真实文件名
String fileName = map.getKey();
//获取缓存对象
ScanningFile obj = map.getValue();
String number = getNumber(obj.getNumber());
String applyId = masterId + "~" + (number != null ? number : "");
File pdfFile = FileUtils.createFile("pdfs", obj.getInpNo(), obj.getVisitId(), applyId);
FileUtils.generatePdfFile(obj.getByteList(), pdfFile.getAbsolutePath());
//合成pdf
String pdfPath = pdfFile.getAbsolutePath();
//获取assortId
String assortId = getAssortId(obj.getAssortId());
ArchiveDetail archiveDetail = new ArchiveDetail(masterId, new Date(), assortId, "扫描系统", applyId, pdfPath, Integer.valueOf(number), fileName);
insertBatchList.add(archiveDetail);
}
long end = System.currentTimeMillis();
logger.error("图片合成pdf:FBIHID=" + scanningFile.getInpNo() + "&FBINCU=" + scanningFile.getVisitId() + "所用时间:" + (end - start) / 1000.00 + "s");
if (!CollectionUtils.isEmpty(insertBatchList)) {
//批量添加进detail表
archiveDetailRepository.saveAll(insertBatchList);
}
} catch (Exception e) {
e.printStackTrace();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(baos));
String exception = baos.toString();
logger.error("合成pdf出错了" + exception);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("合成pdf或插入detail表出错了:FBIHID=" + scanningFile.getInpNo() + "&FBINCU=" + scanningFile.getVisitId());
throw new RuntimeException("合成pdf或插入detail表出错了:FBIHID=" + scanningFile.getInpNo() + "&FBINCU=" + scanningFile.getVisitId());
}
}
if (!CollectionUtils.isEmpty(ids)) {
//批量更新scanningFile表
String status = "1";
if (StringUtils.isNotBlank(remark)) {
status = "2";
} else {
remark = LocalDateTime.now().toString();
}
//更新scanningFile表
scanningFileRepository.updateBatch(remark, status, ids);
}
}
}
/**
* applyId
* @param number
* @return
*/
private String getNumber(String number){
// Integer number = 1;
//37006704-10-47-1.CDP 截成 10-47-1.CDP
number = number.substring(number.indexOf("-")+1,number.length());
//10-47-1.CDP 截成 47-1.CDP
number = number.substring(number.indexOf("-")+1,number.length());
//47-1.CDP 截成47
number = number.substring(0,number.indexOf("-"));
return number;
}
/**
* assortId
* @param thirdAssortId
* @return
*/
private String getAssortId(String thirdAssortId) {
String assortId = "1";
switch (thirdAssortId){
case "1": // 病案首页
assortId = "3";
break;
case "2": //出院(或死亡)记录(小结)
assortId = "113";
break;
case "3": //入院记录
assortId = "9";
break;
case "4": //病程记录
assortId = "11";
break;
case "5": //死亡病例讨论
assortId = "14";
break;
case "6": //特殊病情及治疗记录
assortId = "20";
break;
case "7": //会诊记录单
assortId = "15";
break;
case "8": //病重(病危)护理记录
assortId = "121";
break;
case "9": //知情同意书
assortId = "20";
break;
case "10": //辅助检查报告单
assortId = "110";
break;
case "11": //医嘱单
assortId = "25";
break;
case "12": //体温单
assortId = "5";
break;
case "13": //护理记录
assortId = "2";
break;
case "14": //死亡患者门诊病历
assortId = "18";
break;
case "15": //其他资料
assortId = "18";
break;
}
return assortId;
}
/*
public String handlePdfFile(ScanningFile scanningFile) throws Exception{
//处理ScanningFile
// 判断病案首页数据是否存在
@ -118,6 +361,7 @@ public class AnalysisService {
// String s = WebServiceUtil.urlConnectionUtil("http://10.6.0.224/cdms/cdmsservice.asmx?wsdl", scanningFile.getPath() + "\\" + scanningFile.getFileName());
*/
/*if(!"".equals(s)){
int w=9;
}
@ -126,7 +370,8 @@ public class AnalysisService {
Object[] objects = new Object[strArr.length];
for(int i=0;i<strArr.length;i++) {
objects[i] = strArr[i];
}*/
}*//*
if (objects == null) {
return "下载图片出错了。。。";
}
@ -231,6 +476,7 @@ public class AnalysisService {
logger.error("保存耗时:"+Duration.between(now9,end9).toMillis());//删掉
return null;
}
*/
public String handlePdfFile1(MessageDto messageDto) throws Exception{
String pdfPath = "";

@ -1,6 +1,10 @@
package com.ann.demo.utils;
import org.apache.cxf.common.logging.LogUtils;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.PdfWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@ -8,6 +12,7 @@ import org.springframework.stereotype.Component;
import java.io.*;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
/**
@ -16,6 +21,14 @@ import java.util.Objects;
*/
@Component
public class FileUtils {
/**
* A4
*/
final private static float A4_WEIGHT = 595;
/**
* A4
*/
final private static float A4_HEIGHT = 842;
static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
@ -42,8 +55,97 @@ public class FileUtils {
public static String getImagePath() {
return imagePath;
}
public static void generatePdfFile(List<byte[]> fileBytes, String pdfFileName) throws IOException, DocumentException {
try {
float percent=100;
float w,h;
Document doc = new Document(PageSize.A4,0,0,0,0);
PdfWriter.getInstance(doc, new FileOutputStream(pdfFileName));
doc.open();
doc.newPage();
for(byte[] fileByte : fileBytes) {
Image img = Image.getInstance(fileByte);
logger.error("img:"+img.toString());
w = img.getWidth();
h = img.getHeight();
if ((w > A4_WEIGHT) && (h < A4_HEIGHT)) {
percent = (A4_WEIGHT * 100) / w;
} else if ((w < A4_WEIGHT) && (h > A4_HEIGHT)) {
percent = (A4_HEIGHT * 100) / h;
} else if ((w > A4_WEIGHT) && (h > A4_HEIGHT)) {
percent = (A4_WEIGHT * 100) / w;
h = (h * percent) / 100;
if (h > A4_HEIGHT) {
percent = (A4_HEIGHT * 100) / h;
}
}
img.setAlignment(Image.ALIGN_CENTER);
if(percent != 100){
img.scaleAbsolute(A4_WEIGHT, A4_HEIGHT);
}else{
img.scalePercent(percent);
}
doc.add(img);
}
doc.close();
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(baos));
String exception = baos.toString();
logger.error(pdfFileName+"合成pdf出错了"+exception);
}
}
/**
*
*
* @param height
* @param weight
* @return
*/
private static int getPercent(float height, float weight) {
float percent = 0.0F;
if (height > weight) {
percent = PageSize.A4.getHeight() / height * 100;
} else {
percent = PageSize.A4.getWidth() / weight * 100;
}
return Math.round(percent);
}
public static void getFile(List<byte[]> list,File file) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
for(byte[] obj : list){
bos.write(obj);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.flush();
bos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
public static File createFile(String fileType, String inpNo, String visitId, String path) throws IOException {
File localFile = null;
try {

@ -1,15 +1,7 @@
package com.ann.demo.utils;
import com.alibaba.fastjson.JSONArray;
import com.ann.demo.controller.InterfaceForm;
import com.ann.demo.entity.constant.InterfaceName;
import com.ann.demo.controller.JAXDynamicClientFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import javax.imageio.stream.FileImageOutputStream;
import java.io.*;
import java.util.Objects;
import java.util.Optional;
/**
* @Author: LeiJiaXin
@ -17,9 +9,23 @@ import java.util.Optional;
*/
public class WebServiceUtils {
Object[] objects = null;
private static Client client = null;
public static Object[] connect(String path) throws Exception {
String wsdlUrl = "http://10.6.0.224/cdms/cdmsservice.asmx?wsdl";
String wsdlMethod = "GetImageStream";
/*String wsdlUrl = "http://localhost:8099/services/api?wsdl";
String wsdlMethod = "emrService";*/
if(client == null) {
JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance();
client = dcf.createClient(wsdlUrl);
}
try {
// invoke("方法名",参数1,参数2,参数3....);
return client.invoke(wsdlMethod, path);
} catch (Exception e) {
return null;
}
/*
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://10.6.0.224/cdms/cdmsservice.asmx?wsdl");
Object[] objects = new Object[0];
@ -29,6 +35,17 @@ public class WebServiceUtils {
} catch (Exception e) {
return null;
}
*/
}
public static void main(String[] args) {
String path = "D:/test";
try {
Object[] objects = connect(path);
String s = objects[0].toString();
System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -1,3 +1,15 @@
#spring:
# datasource:
# primary:
# jdbc-url: jdbc:sqlserver://localhost:1433;DatabaseName=sanningfile
# username: sa
# password: docus702
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# secondary:
# jdbc-url: jdbc:sqlserver://localhost:1433;DatabaseName=zj_record_new
# username: sa
# password: docus702
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
spring:
datasource:
primary:

Loading…
Cancel
Save