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.

125 lines
5.2 KiB
Java

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.docus.bgts.service;
import com.alibaba.fastjson.JSON;
import com.docus.bgts.entity.MzSyncDetails;
import com.docus.bgts.entity.ReportDownDto;
import com.docus.bgts.entity.ReportDownPatientDto;
import com.docus.bgts.entity.ReportDownScanFileDto;
import com.docus.bgts.entity.ZdAssort;
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 java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
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;
@Service
public class UpdateFileService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
IAfCollectTaskService afCollectTaskService;
@Autowired
ZdAssortMapper zdAssortMapper;
public void updateFile(String jzh, MzSyncDetails mzSyncDetail) {
String collectorid = "";
String assortid = this.getAssortid(mzSyncDetail.getAssortName());
ReportDownDto reportDownDto = new ReportDownDto();
reportDownDto.setAssortid(assortid);
List<ReportDownScanFileDto> reportDownDtoArr = new ArrayList();
ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto();
reportDownPatientDto.setJzh(jzh);
this.log.info("患者主索引号:" + jzh);
reportDownDto.setPatient(reportDownPatientDto);
String filetitle = mzSyncDetail.getFileTitle();
String downurl = mzSyncDetail.getFileUrl();
if (!StringUtils.isBlank(downurl)) {
downurl = this.subStrUrl(downurl);
if (!StringUtils.isBlank(downurl)) {
String serialnum = mzSyncDetail.getSerialnum();
collectorid = mzSyncDetail.getCollectid();
ReportDownScanFileDto 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);
this.afCollectTaskService.insert(reportDownDto);
String post = "";
this.log.info("--------执行上传功能----------");
Map params = (Map)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();
}
if (StringUtils.isBlank(post)) {
this.log.info("--------上传时出现错误,可能是文件服务没有启动----------");
throw new RuntimeException("上传时出现错误,可能是文件服务没有启动");
} else {
Map resMap = (Map)JSON.parseObject(post, Map.class);
if (String.valueOf(resMap.get("code")).equals("500")) {
throw new RuntimeException(String.valueOf(resMap.get("msg")));
} else {
this.log.info("----------执行成功-----------");
}
}
}
}
}
private String getAssortid(String assortName) {
String assortId = String.valueOf(FileUtils.getJsonByName("assortid"));
if (StringUtils.isBlank(assortId)) {
List<ZdAssort> zdAssorts = this.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);
this.zdAssortMapper.insertZdAssort(zdAssort);
assortId = uuid;
} else {
assortId = ((ZdAssort)zdAssorts.get(0)).getAssortId();
}
}
return assortId;
}
private String subStrUrl(String str) {
List<String> replaceUrls = (List)FileUtils.getJsonByName("replaceUrl");
if (null != replaceUrls) {
for(String replaceUrl : replaceUrls) {
str = str.replaceAll(replaceUrl, "");
}
}
return str;
}
}