feat: 市一联众同步添加web,可以补偿同步

广州市市一联众
wyb 10 months ago
parent 966e66abec
commit 03eb85f2f9

@ -2,6 +2,7 @@
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />

@ -13,8 +13,48 @@
<version>2.4.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- RESTful APIs swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
@ -35,6 +75,11 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@ -75,6 +120,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<swagger.version>2.9.2</swagger.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

@ -21,4 +21,19 @@ public class CommonResult<T> {
private T data;
public static <T> CommonResult<T> success(T data){
CommonResult commonResult = new CommonResult();
commonResult.setCode(0);
commonResult.setMsg("操作成功");
commonResult.setData(data);
return commonResult;
}
public static <T> CommonResult<T> failed(T data){
CommonResult commonResult = new CommonResult();
commonResult.setCode(500);
commonResult.setMsg("操作失败");
commonResult.setData(data);
return commonResult;
}
}

@ -0,0 +1,45 @@
package com.jiashi.config;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* api /swagger-ui.html
* @author Zheng Jie
* @date 2018-11-23
*/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
ParameterBuilder ticketPar = new ParameterBuilder();
return new Docket(DocumentationType.SWAGGER_2)
.enable(true)
.apiInfo(apiInfo())
.select()
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("接口文档")
.version("1.0")
.build();
}
}

@ -0,0 +1,152 @@
package com.jiashi.controller;
import com.google.gson.Gson;
import com.jiashi.CommonResult;
import com.jiashi.FileUploader;
import com.jiashi.dao.DataQuery;
import com.jiashi.service.CardInfo;
import com.jiashi.service.FormField;
import com.jiashi.service.Picture;
import com.jiashi.service.UploadInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* @author YongBin Wen
* @date 2024/9/26 15:32
*/
@RestController
@Slf4j
@Api(tags = "广州市一联众同步接口")
@RequestMapping("/gzsy/lianzhong")
public class LianZhongSyncController {
@Autowired
private DataQuery dataQuery;
ExecutorService executor = Executors.newFixedThreadPool(10);
@ApiOperation(value = "根据病案号和出院日期(yyyy-MM-dd)同步联众文件数据 ")
@GetMapping("/sync/byInpNoAndDisDate")
public CommonResult<String> syncByInpNoAndDisDate(@RequestParam("inpatientNo") String inpatientNo, @RequestParam("disDate") String disDate) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List<CardInfo> cardInfos = dataQuery.dateQueryByInpNo(inpatientNo);
CardInfo cardInfo = null;
for (CardInfo info : cardInfos) {
if (disDate.equals(sdf.format(info.getOutdate()))) {
cardInfo = info;
break;
}
}
if (Objects.isNull(cardInfo)) {
return CommonResult.failed("未找到 cardInfo 信息!");
}
sync(cardInfo);
return CommonResult.success("同步完成!");
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
return CommonResult.failed(ex.getMessage());
}
}
public void sync(CardInfo cardInfo) throws IOException {
String uniUrl = "http://192.168.8.74";
List<Picture> pictures = dataQuery.getPictures(cardInfo.getId());
if (pictures == null || pictures.size() == 0) {
//如果是空的则不同步
dataQuery.updateBatchState(cardInfo, 5);
return;
}
String dir = "c:\\pic\\" + cardInfo.getId();
// 创建File对象
File directory = new File(dir);
// 判断目录是否存在
if (!directory.exists()) {
// 目录不存在,创建目录
boolean created = directory.mkdirs();
if (created) {
log.info("目录创建成功:" + dir);
} else {
log.info("目录创建失败:" + dir);
}
}
List<Future> futures = new ArrayList<>();
for (Picture picture : pictures) {
Future future = executor.submit(() -> {
try {
String cmd = "C:\\Debug\\lianzhong.exe 003 192.168.8.74 " + cardInfo.getId() + " " + picture.getPicid() + " " + cardInfo.getPatno() + " " + cardInfo.getOutdateStr() + " " + picture.getPicname() + " " + picture.getFileUrl() + " " + uniUrl + " " + picture.getRotatedegree();
// log.info(cmd);
java.lang.Process process = java.lang.Runtime.getRuntime().exec(cmd);//执行命令生成cube
process.waitFor();
} catch (Exception e) {
log.error(e.getMessage(), e);
e.printStackTrace();
}
});
futures.add(future);
}
for (Future future : futures) {
try {
future.get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
List<File> files = new ArrayList<>();
List<UploadInfo> uploadInfos = new ArrayList<>();
for (Picture picture : pictures) {
files.add(new File(picture.getFileUrl()));
UploadInfo uploadInfo = new UploadInfo(cardInfo.getPatno(), cardInfo.getOutdateStr2(), picture.getPicname(), picture.getPicname(),
picture.getPickind(), cardInfo.getId(), cardInfo.getPatname(),
cardInfo.getIndateStr(), cardInfo.getPatsex(), cardInfo.getPatnum(),
cardInfo.getIcdecode11(), cardInfo.getIcdename11(), cardInfo.getMjwesticde(), cardInfo.getMjwestname(),
cardInfo.getOutdeptname(), cardInfo.getPatciticard(), cardInfo.getOutwardname(), cardInfo.getIndeptname(), cardInfo.getIndeptcode(), cardInfo.getGestno(), cardInfo.getPatbirthdayStr());
uploadInfos.add(uploadInfo);
}
// 额外的表单字段参数
List<FormField> params = new ArrayList<>();
String s = new Gson().toJson(uploadInfos);
params.add(new FormField("uploadFileParams", s));
log.info("请求参数:" + cardInfo.getPatno());
// 上传
CommonResult commonResult = FileUploader.uploadFilesWithParams(files, "http://192.168.161.102:9511/fileUploadJpg", params);
if (commonResult.getCode() == 0) {
dataQuery.updateBatchState(cardInfo, 3);
}
// 删除文件
File file = new File(dir);
FileUploader.deleteFolder(file);
}
}

@ -40,6 +40,20 @@ public class DataQuery {
}
public List<CardInfo> dateQueryByInpNo(String inpNo){
Specification<CardInfo> specification = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.<String>get("patno"), inpNo));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
Sort.Order sortCreateTime = Sort.Order.asc("outdate");
Sort sort = Sort.by(sortCreateTime);
Pageable pageable = PageRequest.of(0, 1000, sort);
Page<CardInfo> all = cardInfoRepository.findAll(specification, pageable);
return all.toList();
}
public void updateBatch(List<CardInfo> cardInfos){
for(CardInfo cardInfo:cardInfos){
cardInfo.setState(1);

Loading…
Cancel
Save