|
|
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();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|