update ASMS同步文件
This commit is contained in:
+51
-7
@@ -16,9 +16,12 @@ import com.jero.modules.laws.standard.service.ILawsDomesticStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||
import com.jero.modules.laws.standardization.entity.LawsStandardization;
|
||||
import com.jero.modules.laws.standardization.service.ILawsStandardizationService;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.system.entity.SysDictItem;
|
||||
import com.jero.modules.system.service.ISysDictItemService;
|
||||
import com.spire.ms.System.Collections.ArrayList;
|
||||
import io.minio.errors.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -27,6 +30,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
@@ -67,7 +74,10 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
||||
private ILawsDomesticStandardService lawsDomesticStandardService;
|
||||
@Autowired
|
||||
private ILawsReplacedStandardService lawsReplacedStandardService;
|
||||
@Autowired
|
||||
private IOSSFileService ossFileService;
|
||||
|
||||
private final static String filePath = "asms/";
|
||||
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private static SimpleDateFormat oldDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
@@ -379,7 +389,6 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
||||
List<LawsAsmsDomestic> lawsAsmsDomesticList = lawsAsmsDomesticService.list(queryWrapper);
|
||||
List<SysDictItem> sysDictItemList = sysDictItemService.list();
|
||||
List<LawsStandardization> lawsStandardizationList = lawsStandardizationService.list();
|
||||
List<LawsDomesticStandard> lawsDomesticStandardList = new ArrayList();
|
||||
lawsAsmsDomesticList.forEach(lawsAsmsDomestic -> {
|
||||
String[] parts = lawsAsmsDomestic.getCode().split("[-\\s]"); // 使用空格或破折号作为分隔符
|
||||
if (parts.length < 3) {
|
||||
@@ -455,29 +464,64 @@ public class LawsAsmsOpenApiServiceImpl extends ServiceImpl<LawsAsmsOpenApiMappe
|
||||
// 更新时间
|
||||
lawsDomesticStandard.setUpdateTime(getSimpleDate2(lawsAsmsDomestic.getUpdateTimeString()));
|
||||
lawsDomesticStandardService.save(lawsDomesticStandard);
|
||||
lawsDomesticStandardList.add(lawsDomesticStandard);
|
||||
});
|
||||
// 状态设置为已同步
|
||||
lawsAsmsOpenApi.setStatus("1");
|
||||
log.info("{}同步成功{}条数据", lawsAsmsOpenApi.getApiName(), lawsDomesticStandardList.size());
|
||||
log.info("{}同步成功{}条数据", lawsAsmsOpenApi.getApiName(), lawsAsmsDomesticList.size());
|
||||
} else if ("3".equals(lawsAsmsOpenApi.getApiType()) && "xiaobodata/openApi/domesticLaws/getFile".equals(lawsAsmsOpenApi.getApiUrl())) {
|
||||
// 国内法规相关文档
|
||||
LambdaQueryWrapper<LawsAsmsDomestic> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.orderByAsc(LawsAsmsDomestic::getId);
|
||||
List<LawsAsmsDomestic> lawsAsmsDomesticList = lawsAsmsDomesticService.list(queryWrapper);
|
||||
lawsAsmsDomesticList.forEach(lawsAsmsDomestic -> {
|
||||
String id = lawsAsmsDomestic.getId();
|
||||
String code = lawsAsmsDomestic.getCode();
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("lawCode", lawsAsmsDomestic.getCode());
|
||||
List<Map<String, String>> mapList = asmsPostUtil.sendGetReq(lawsAsmsOpenApi.getApiUrl(), paramMap);
|
||||
Map<String, String> eMap = mapList.get(0);
|
||||
//MinioUtil.upload();
|
||||
paramMap.put("lawCode", code);
|
||||
Map<String, Object> objectMap = asmsPostUtil.sendGetReq2(lawsAsmsOpenApi.getApiUrl(), paramMap);
|
||||
if (Objects.isNull(objectMap)) return;
|
||||
Map<String, String> standardTextPdf = (Map<String, String>) objectMap.get("standardTextPdf");
|
||||
String fileName = standardTextPdf.get("fileName");
|
||||
String fileType = standardTextPdf.get("fileType");
|
||||
String url = standardTextPdf.get("url");
|
||||
if (StringUtils.isNotBlank(url)) {
|
||||
upload(url, fileName, fileType, id, code);
|
||||
}
|
||||
Map<String, String> standardTextWord = (Map<String, String>) objectMap.get("standardTextWord");
|
||||
fileName = standardTextWord.get("fileName");
|
||||
fileType = standardTextWord.get("fileType");
|
||||
url = standardTextWord.get("url");
|
||||
if (StringUtils.isNotBlank(url)) {
|
||||
upload(url, fileName, fileType, id, code);
|
||||
}
|
||||
});
|
||||
// 状态设置为已同步
|
||||
lawsAsmsOpenApi.setStatus("1");
|
||||
log.info("{}同步成功{}条数据", lawsAsmsOpenApi.getApiName(), lawsAsmsDomesticList.size());
|
||||
}
|
||||
});
|
||||
// 同步接口的状态
|
||||
updateBatchById(lawsAsmsOpenApiList);
|
||||
}
|
||||
|
||||
private void upload(String url, String fileName, String fileType, String id, String code) {
|
||||
InputStream inputStream = asmsPostUtil.getFileByteArray(url);
|
||||
try {
|
||||
MinioUtil.upload(inputStream, filePath + url);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new JeroBootException("文件上传错误");
|
||||
}
|
||||
OSSFile ossFile = new OSSFile();
|
||||
ossFile.setFileName(fileName + "." + fileType);
|
||||
ossFile.setUrl(filePath + url);
|
||||
ossFile.setStandardId(id);
|
||||
ossFile.setStandardNo(code);
|
||||
ossFile.setStandardFileType("publish_of_original");
|
||||
ossFileService.save(ossFile);
|
||||
log.info("存储文件:{},url:{}", fileName, url);
|
||||
}
|
||||
|
||||
private Date getSimpleDate(String dateStr) {
|
||||
if (StringUtils.isBlank(dateStr)) return null;
|
||||
try {
|
||||
|
||||
+30
-17
@@ -15,8 +15,10 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
|
||||
@@ -78,6 +80,30 @@ public class AsmsPostUtil {
|
||||
* map:参数map
|
||||
**/
|
||||
public List<Map<String, String>> sendGetReq(String uri, Map<String, String> map) {
|
||||
ResponseEntity<Result> responseEntity = getSendGetReq(uri, map);
|
||||
Map<String, Object> resultMap = (Map<String, Object>) responseEntity.getBody().getResult();
|
||||
if (Objects.isNull(resultMap)) {
|
||||
throw new JeroBootException("返回数据为空");
|
||||
}
|
||||
List<Map<String, String>> mapList = (List<Map<String, String>>) resultMap.get("records");
|
||||
if (CollectionUtils.isEmpty(mapList)) {
|
||||
mapList = new ArrayList<>();
|
||||
Map<String, String> result = (Map<String, String>) responseEntity.getBody().getResult();
|
||||
if (result.containsKey("records")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
mapList.add(result);
|
||||
}
|
||||
log.info("返回{}条数据", mapList.size());
|
||||
return mapList;
|
||||
}
|
||||
|
||||
public Map<String, Object> sendGetReq2(String uri, Map<String, String> map) {
|
||||
ResponseEntity<Result> responseEntity = getSendGetReq(uri, map);
|
||||
return (Map<String, Object>) responseEntity.getBody().getResult();
|
||||
}
|
||||
|
||||
private ResponseEntity<Result> getSendGetReq(String uri, Map<String, String> map) {
|
||||
// 准备请求头
|
||||
String token = getToken();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@@ -111,27 +137,14 @@ public class AsmsPostUtil {
|
||||
if (!responseEntity.getBody().isSuccess()) {
|
||||
throw new JeroBootException("汽车标准数字化平台:请求发送失败");
|
||||
}
|
||||
Map<String, Object> resultMap = (Map<String, Object>) responseEntity.getBody().getResult();
|
||||
if (Objects.isNull(resultMap)) {
|
||||
throw new JeroBootException("返回数据为空");
|
||||
}
|
||||
List<Map<String, String>> mapList = (List<Map<String, String>>) resultMap.get("records");
|
||||
if (CollectionUtils.isEmpty(mapList)) {
|
||||
mapList = new ArrayList<>();
|
||||
Map<String, String> result = (Map<String, String>) responseEntity.getBody().getResult();
|
||||
if (result.containsKey("records")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
mapList.add(result);
|
||||
}
|
||||
log.info("返回{}条数据", mapList.size());
|
||||
return mapList;
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
public byte[] getFileByteArray(String fileUrl) {
|
||||
public InputStream getFileByteArray(String fileUrl) {
|
||||
// 执行GET请求
|
||||
ResponseEntity<byte[]> response = restTemplate.getForEntity(host + fileUrl, byte[].class);
|
||||
return response.getBody();
|
||||
byte[] bytes = response.getBody();
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user