You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
5.6 KiB
Java
160 lines
5.6 KiB
Java
package com.docus.bgts.service;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.docus.bgts.entity.*;
|
|
import com.docus.bgts.enums.Codes;
|
|
import com.docus.bgts.facade.IAfCollectTaskService;
|
|
import com.docus.bgts.mapper.dbmysql.ZdAssortMapper;
|
|
import com.docus.bgts.utils.FileUtils;
|
|
import com.docus.bgts.utils.HttpUtils;
|
|
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.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* @author 曾文和
|
|
* @description: 上传文件调下载服务业务
|
|
* @createTime 2022/5/2 10:48
|
|
*/
|
|
@Service
|
|
public class UpdateFileService {
|
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
|
@Autowired
|
|
IAfCollectTaskService afCollectTaskService;
|
|
|
|
@Autowired
|
|
ZdAssortMapper zdAssortMapper;
|
|
/**
|
|
*{
|
|
* "assortid": "string",
|
|
* "collectorid": "string",
|
|
* "ip": "string",
|
|
* "patient": {
|
|
* "jzh": "string"
|
|
* },
|
|
* "scanfiles": [
|
|
* {
|
|
* "downurl": "string",
|
|
* "filesource": 0,
|
|
* "filestoragetype": 0,
|
|
* "filetitle": "string",
|
|
* "filetype": 0,
|
|
* "serialnum": "string",
|
|
* "taskid": 0
|
|
* }
|
|
* ],
|
|
* "scanusercode": "string",
|
|
* "scanusername": "string"
|
|
* }
|
|
*/
|
|
public void updateFile(String jzh, MzSyncDetails mzSyncDetail) {
|
|
ReportDownDto reportDownDto;
|
|
ReportDownScanFileDto reportDownScanFileDto;
|
|
ReportDownPatientDto reportDownPatientDto;
|
|
//临时资料存储
|
|
String serialnum;
|
|
String filetitle;
|
|
String downurl;
|
|
String collectorid = "";
|
|
String assortid = getAssortid(mzSyncDetail.getAssortName());
|
|
reportDownDto = new ReportDownDto();
|
|
reportDownDto.setAssortid(assortid);
|
|
//获取基本数据信息
|
|
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList<>();
|
|
reportDownPatientDto = new ReportDownPatientDto();
|
|
reportDownPatientDto.setJzh(jzh);
|
|
log.info("患者主索引号:" + jzh);
|
|
reportDownDto.setPatient(reportDownPatientDto);
|
|
filetitle = mzSyncDetail.getFileTitle();
|
|
downurl = mzSyncDetail.getFileUrl();
|
|
if(StringUtils.isBlank(downurl)){
|
|
return;
|
|
}
|
|
//特殊处理url
|
|
downurl = subStrUrl(downurl);
|
|
if(StringUtils.isBlank(downurl)){
|
|
return;
|
|
}
|
|
//获取采集流水号
|
|
serialnum = mzSyncDetail.getSerialnum();
|
|
collectorid = mzSyncDetail.getCollectid();
|
|
reportDownScanFileDto = new ReportDownScanFileDto();
|
|
reportDownScanFileDto.setDownurl(downurl);
|
|
reportDownScanFileDto.setFiletitle(filetitle);
|
|
reportDownScanFileDto.setSerialnum(serialnum);
|
|
reportDownScanFileDto.setFilesource(1);
|
|
reportDownScanFileDto.setFilestoragetype(1);
|
|
reportDownDtoArr.add(reportDownScanFileDto);
|
|
reportDownDto.setCollectorid(collectorid);
|
|
reportDownDto.setScanfiles(reportDownDtoArr);
|
|
afCollectTaskService.insert(reportDownDto);
|
|
String post = "";
|
|
log.info("--------执行上传功能----------");
|
|
Map params = JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class);
|
|
Map<String, Object> headMap = new HashMap<>();
|
|
headMap.put("Content-Type", "application/json");
|
|
try {
|
|
post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, params);
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
}
|
|
// String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), map, headMap);
|
|
if (StringUtils.isBlank(post)) {
|
|
log.info("--------上传时出现错误,可能是文件服务没有启动----------");
|
|
throw new RuntimeException("上传时出现错误,可能是文件服务没有启动");
|
|
}
|
|
Map resMap = JSON.parseObject(post, Map.class);
|
|
if (String.valueOf(resMap.get("code")).equals("500")) {
|
|
throw new RuntimeException(String.valueOf(resMap.get("msg")));
|
|
} else {
|
|
log.info("----------执行成功-----------");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取分类id
|
|
*
|
|
* @return
|
|
*/
|
|
private String getAssortid(String assortName) {
|
|
String assortId = String.valueOf(FileUtils.getJsonByName("assortid"));
|
|
if (StringUtils.isBlank(assortId)) {
|
|
List<ZdAssort> zdAssorts = zdAssortMapper.selectAll(assortName);
|
|
if (CollectionUtils.isEmpty(zdAssorts)) {
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
ZdAssort zdAssort = new ZdAssort();
|
|
zdAssort.setAssortName(assortName);
|
|
zdAssort.setAssortId(uuid);
|
|
zdAssort.setEffective(1);
|
|
zdAssortMapper.insertZdAssort(zdAssort);
|
|
assortId = uuid;
|
|
} else {
|
|
assortId = zdAssorts.get(0).getAssortId();
|
|
}
|
|
}
|
|
return assortId;
|
|
}
|
|
|
|
/**
|
|
* 截取url
|
|
* @param str
|
|
* @return
|
|
*/
|
|
private String subStrUrl(String str) {
|
|
List<String> replaceUrls = (List<String>) FileUtils.getJsonByName("replaceUrl");
|
|
if(null != replaceUrls){
|
|
for(String replaceUrl : replaceUrls){
|
|
str = str.replaceAll(replaceUrl,"");
|
|
}
|
|
}
|
|
return str;
|
|
}
|
|
}
|