修改采集保存路径

master
linjj 1 year ago
parent be9b598674
commit 4433370d56

@ -93,6 +93,21 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>

@ -0,0 +1,48 @@
package com.shibofu.spring.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 org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* @author potter.fu
* @date 2018-12-07 15:30
*/
@Configuration
@MapperScan(basePackages = "com.shibofu.spring.db3.dao", sqlSessionTemplateRef = "db3SqlSessionTemplate")
public class DataSource3Config {
@Bean(name = "db3DataSource")
@ConfigurationProperties(prefix = "spring.datasource.hikari.db3")
public DataSource testDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "db3SqlSessionFactory")
public SqlSessionFactory testSqlSessionFactory(@Qualifier("db3DataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db3/*.xml"));
return bean.getObject();
}
@Bean(name = "db3TransactionManager")
public DataSourceTransactionManager testTransactionManager(@Qualifier("db3DataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "db3SqlSessionTemplate")
public SqlSessionTemplate testSqlSessionTemplate(@Qualifier("db3SqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}

@ -2,6 +2,7 @@ package com.shibofu.spring.controller;
import com.shibofu.spring.db1.service.PacsPollingService;
import com.shibofu.spring.db2.service.MoneyService;
import com.shibofu.spring.db3.service.CostListService;
import com.shibofu.spring.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -19,6 +20,8 @@ import java.util.Map;
public class MoneyController {
@Autowired
private PacsPollingService pacsPollingService;
@Autowired
private CostListService costListService;
@GetMapping("/makeUpByPacsAndTime")
public String makeUpByNeed() {
@ -30,4 +33,10 @@ public class MoneyController {
public Msg makeUpPacsByMasterId(String masterId) {
return pacsPollingService.makeUpPacsByMasterId(masterId);
}
@GetMapping("/costList")
public String getCostList(){
costListService.collectionCostList();
return "采集完成";
}
}

@ -29,4 +29,6 @@ public interface ArchiveMasterDao {
int updatePacsCompenSate(String masterId);
String selectPacsPush();
String getIdbyJzh(String jzh);
}

@ -0,0 +1,21 @@
package com.shibofu.spring.db3.dao;
import com.shibofu.spring.vo.CostListVo;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @InterfaceName CostListServiceMapper
* @Description
* @Author linjj
* @Date 2024/5/22 10:30
* @Version 1.0
*/
@Mapper
public interface CostListDao {
List<CostListVo>getCostList(int offset);
int getConut();
}

@ -0,0 +1,13 @@
package com.shibofu.spring.db3.service;
/**
* @InterfaceName CostListService
* @Description
* @Author linjj
* @Date 2024/5/22 10:18
* @Version 1.0
*/
public interface CostListService {
void collectionCostList();
}

@ -0,0 +1,141 @@
package com.shibofu.spring.db3.serviceImpl;
import com.shibofu.spring.db1.dao.ArchiveDetailDao;
import com.shibofu.spring.db1.dao.ArchiveMasterDao;
import com.shibofu.spring.db3.dao.CostListDao;
import com.shibofu.spring.db3.service.CostListService;
import com.shibofu.spring.dto.ArchiveDetailDto;
import com.shibofu.spring.vo.ArchiveDetailVo;
import com.shibofu.spring.vo.CostListVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @ClassName CostListServiceImpl
* @Description
* @Author linjj
* @Date 2024/5/22 10:19
* @Version 1.0
*/
@Service
@Slf4j
public class CostListServiceImpl implements CostListService {
@Autowired
private CostListDao costListDao;
@Autowired
private ArchiveMasterDao archiveMasterDao;
@Autowired
private ArchiveDetailDao archiveDetailDao;
@Value("${savePath}")
private String savePath;
/**
* @description:
* @author linjj
* @date: 2024/5/22 10:21
*/
@Override
public void collectionCostList() {
//插入文件表数据集合
List<ArchiveDetailDto> ArchiveDetailList = new ArrayList<>();
//查询一共有多条记录
int conut = costListDao.getConut();
//每次查询50条记录
int pollingNum = (int) Math.floor((double) conut / (double) 50);
for (int i = 0; i <= pollingNum; i++) {
//每次查询50条记录
int offset = i * 50;
//查询需要采集清单病历
List<CostListVo> costList = costListDao.getCostList(offset);
if (!CollectionUtils.isEmpty(costList)) {
log.info("费用清单本次采集" + costList.size() + "份!!!");
for (CostListVo list : costList) {
if (StringUtils.isEmpty(list.getFpdf())) {
log.info(list.getFjzh() + "路径为空!!");
continue;
}
try {
download(list, ArchiveDetailList);
} catch (IOException e) {
log.info(e.getMessage());
}
}
archiveDetailDao.addArchiveDetail(ArchiveDetailList);
log.info("完成采集" + ArchiveDetailList.size() + "份!!!");
ArchiveDetailList.clear();
}
}
log.info("本次采集没有费用清单记录");
}
private void download(CostListVo costListVo, List<ArchiveDetailDto> ArchiveDetailList) throws IOException {
ArchiveDetailDto archiveDetailDto = new ArchiveDetailDto();
//使用yyyyMMddHHmmssSSS格式作为文件名
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String newDate = format.format(date);
//根据jzh查询患者主键id
String masterId = archiveMasterDao.getIdbyJzh(costListVo.getFjzh());
//判断文件是否存在存在删除后新增不存在新增
List<ArchiveDetailVo> subAssort = archiveDetailDao.getSubAssort(masterId);
if (subAssort.size() > 0) {
deleteFliepath(subAssort);
}
//组织保存目录
String filePathdir = savePath + File.separatorChar + costListVo.getFpatid() + File.separatorChar + costListVo.getFtimes();
File file = new File(filePathdir);
//判断文件夹是否存在不存在创建文件夹
if (!file.exists()) {
file.mkdirs();
}
//文件保存路径
String filePath = filePathdir + File.separatorChar + newDate + ".pdf";
//下载文件
try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)) {
// 将二进制数据写入文件
fileOutputStream.write(costListVo.getFpdf());
fileOutputStream.flush();
} catch (IOException e) {
log.info(masterId + "异常处理" + e.getMessage());
}
//保存文件表
archiveDetailDto.setMasterId(masterId);
archiveDetailDto.setUploadDateTime(new Date());
archiveDetailDto.setAssortId("DE599D770E8347CCB5122BC357D96F47");
archiveDetailDto.setSource("pacs");
archiveDetailDto.setFlag("0");
archiveDetailDto.setTitle("费用结算清单");
archiveDetailDto.setPdfPath(filePath);
archiveDetailDto.setSubAssort(masterId);
ArchiveDetailList.add(archiveDetailDto);
}
private void deleteFliepath(List<ArchiveDetailVo> listPath) {
for (ArchiveDetailVo list : listPath) {
archiveDetailDao.delSubAssort(list.getId());
File file = new File(list.getPdfPath());
try {
file.delete(); // 删除照片
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -3,6 +3,7 @@ package com.shibofu.spring.quartz;
import com.shibofu.spring.db1.service.PacsPollingService;
import com.shibofu.spring.db3.service.CostListService;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
@ -17,11 +18,15 @@ public class PacsQuartz extends QuartzJobBean {
@Resource
private PacsPollingService pacsPollingService;
@Resource
private CostListService costListService;
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) {
//每天轮询查询昨天数据进来采集
pacsPollingService.PacsEveryDayPolling();
//费用清单采集
costListService.collectionCostList();
//每天轮询查询一周内数据进来采集
pacsPollingService.PacsEveryWeekPolling();
}

@ -38,13 +38,11 @@ public class test {
@Test
public void testDemo() {
String filePathdir = savePath + File.separatorChar + "1231" + File.separatorChar + "111";
File file = new File(filePathdir);
//判断文件夹是否存在不存在创建文件夹
log.info("创建文件的路径:" + file.getAbsolutePath());
if (!file.exists()) {
log.info("尝试创建文件:" + file.getAbsolutePath());
file.mkdirs();
File temporaryFile = new File("D:\\jiashi\\scanning\\35131\\1412");
try {
temporaryFile.delete(); // 删除临时照片
} catch (Exception e) {
e.printStackTrace();
}
}

@ -0,0 +1,29 @@
package com.shibofu.spring.vo;
import lombok.Data;
/**
* @ClassName CostListVo
* @Description
* @Author linjj
* @Date 2024/5/22 10:32
* @Version 1.0
*/
@Data
public class CostListVo {
//住院号
private String fpatid;
//住院次数
private String ftimes;
//二进制文件
private byte[] fpdf;
//记帐号
private String fjzh;
//出院时间
private String ffirstdate;
//最后更新时间
private String fnewdate;
//文件地址
private String filepath;
}

@ -1,29 +1,36 @@
server.port=3391
#spring.datasource.hikari.db1.jdbc-url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=yd_record
#spring.datasource.hikari.db1.username=sa
#spring.datasource.hikari.db1.password=admin123
#spring.datasource.hikari.db1.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.datasource.hikari.db2.jdbc-url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=yd_record
#spring.datasource.hikari.db2.username=sa
#spring.datasource.hikari.db2.password=admin123
#spring.datasource.hikari.db2.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#sqlserver
spring.datasource.hikari.db1.jdbc-url=jdbc:sqlserver://10.36.116.108:1433;DatabaseName=emr_record
spring.datasource.hikari.db1.jdbc-url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=yd_record
spring.datasource.hikari.db1.username=sa
spring.datasource.hikari.db1.password=xjgs+docus911
spring.datasource.hikari.db1.password=admin123
spring.datasource.hikari.db1.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#sqlserver
spring.datasource.hikari.db2.jdbc-url=jdbc:sqlserver://10.36.116.100:1433;DatabaseName=pacsdb
spring.datasource.hikari.db2.username=AP
spring.datasource.hikari.db2.password=AP
##sqlserver
spring.datasource.hikari.db2.jdbc-url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=yd_record
spring.datasource.hikari.db2.username=sa
spring.datasource.hikari.db2.password=admin123
spring.datasource.hikari.db2.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#pg
spring.datasource.hikari.db3.jdbc-url=jdbc:postgresql://localhost:5432/School
spring.datasource.hikari.db3.username=sassssddss
spring.datasource.hikari.db3.password=AP
spring.datasource.hikari.db3.driver-class-name=org.hsqldb.jdbcDriver
spring.datasource.hikari.db3.jdbc-url=jdbc:postgresql://localhost:5432/yd
spring.datasource.hikari.db3.username=postgres
spring.datasource.hikari.db3.password=admin123
spring.datasource.hikari.db3.driver-class-name=org.postgresql.Driver
#sqlserver
#spring.datasource.hikari.db1.jdbc-url=jdbc:sqlserver://10.36.116.108:1433;DatabaseName=emr_record
#spring.datasource.hikari.db1.username=sa
#spring.datasource.hikari.db1.password=xjgs+docus911
#spring.datasource.hikari.db1.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
##sqlserver
#spring.datasource.hikari.db2.jdbc-url=jdbc:sqlserver://10.36.116.100:1433;DatabaseName=pacsdb
#spring.datasource.hikari.db2.username=AP
#spring.datasource.hikari.db2.password=AP
#spring.datasource.hikari.db2.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
##pg
#spring.datasource.hikari.db3.jdbc-url=jdbc:postgresql://192.168.55.230:5432/postgres
#spring.datasource.hikari.db3.username=postgres
#spring.datasource.hikari.db3.password=pl4grWwt
#spring.datasource.hikari.db3.driver-class-name=org.postgresql.Driver

@ -62,6 +62,9 @@
<select id="selectPacsPush" resultType="java.lang.String">
select top 1 masterId from pacs_compensate where compensateState=0
</select>
<select id="getIdbyJzh" resultType="java.lang.String">
select id from archive_master where patient_id=#{jzh}
</select>
</mapper>

@ -0,0 +1,19 @@
<?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.shibofu.spring.db3.dao.CostListDao">
<select id="getConut" resultType="java.lang.Integer">
select count(*)
from public.bajsdpdf
where fnewdate between CURRENT_DATE - INTERVAL '6 days' AND CURRENT_DATE
</select>
<select id="getCostList" resultType="com.shibofu.spring.vo.CostListVo">
SELECT fpatid, ftimes, fpdf, fjzh, ffirstdate, fnewdate, filepath
FROM public.bajsdpdf
where fnewdate between CURRENT_DATE - INTERVAL '6 days' AND CURRENT_DATE
order by fnewdate DESC
LIMIT 50 OFFSET #{offset}
</select>
</mapper>
Loading…
Cancel
Save