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.
udi-spms-java/src/main/java/com/glxp/api/constant/AsyncDiDlHelper.java

154 lines
5.6 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.api.constant;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.entity.basic.ProductInfoEntity;
import com.glxp.api.entity.basic.UdiCompanyEntity;
import com.glxp.api.service.basic.ProductInfoService;
import com.glxp.api.util.HttpClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class AsyncDiDlHelper {
@Value("${UDI_SERVER_URL}")
private String udiUrl;
public List<ProductInfoEntity> dlByTime(String udiUrl, int page, int limit, String updateTime) {
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("page", page);
paramMap.put("limit", limit);
paramMap.put("updateTime", updateTime);
String response = HttpClient.mipsGet(udiUrl + "/udidl/udiwms/syncUdi", paramMap);
try {
BaseResponse<List<ProductInfoEntity>> udiDlDeviceResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<ProductInfoEntity>>>() {
});
List<ProductInfoEntity> udiInfoEntities = udiDlDeviceResponse.getData();
return udiInfoEntities;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public List<UdiCompanyEntity> dlCompanyByTime(String udiUrl, int page, int limit, String updateTime) {
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("page", page);
paramMap.put("limit", limit);
paramMap.put("updateTime", updateTime);
String response = HttpClient.mipsGet(udiUrl + "/udidl/udiwms/syncCompany", paramMap);
try {
BaseResponse<List<UdiCompanyEntity>> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<UdiCompanyEntity>>>() {
});
List<UdiCompanyEntity> udiCompanyEntities = baseResponse.getData();
return udiCompanyEntities;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public List<ProductInfoEntity> dlByDi(String deviceId) {
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("deviceId", deviceId);
String response = HttpClient.mipsGet(udiUrl + "/udidl/device/serchDlByDi", paramMap);
try {
BaseResponse<List<ProductInfoEntity>> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<ProductInfoEntity>>>() {
});
if (baseResponse.getCode() == 200000) {
List<ProductInfoEntity> productInfoEntityList = baseResponse.getData();
return productInfoEntityList;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public BaseResponse<List<ProductInfoEntity>> dlByDiRes(String deviceId) {
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("deviceId", deviceId);
String response = HttpClient.mipsGet(udiUrl + "/udidl/device/serchDlByDi", paramMap);
try {
BaseResponse<List<ProductInfoEntity>> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<ProductInfoEntity>>>() {
});
return baseResponse;
} catch (Exception e) {
e.printStackTrace();
return ResultVOUtils.error(500, "连接UDI国家数据库下载出错");
}
}
public BaseResponse<List<ProductInfoEntity>> dlLastVersionByDi(String deviceId) {
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("deviceId", deviceId);
String response = HttpClient.mipsGet(udiUrl + "/udidl/device/dlLastVersionByDi", paramMap);
try {
BaseResponse<List<ProductInfoEntity>> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<ProductInfoEntity>>>() {
});
return baseResponse;
} catch (Exception e) {
e.printStackTrace();
return ResultVOUtils.error(500, "连接UDI国家数据库下载出错");
}
}
@Resource
ProductInfoService productInfoService;
@Async
public void dlByUuid(String uuid) {
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("uuid", uuid);
String response = HttpClient.mipsGet(udiUrl + "/udidl/device/searchDlByUuid", paramMap);
try {
BaseResponse<List<ProductInfoEntity>> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<ProductInfoEntity>>>() {
});
if (baseResponse != null && baseResponse.getCode() == 20000) {
List<ProductInfoEntity> productInfoEntityList = baseResponse.getData();
if (CollUtil.isNotEmpty(productInfoEntityList)) {
productInfoService.insertProductInfos(productInfoEntityList);
}
} else {
log.error("下载出错");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}