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 dlByTime(String udiUrl, int page, int limit, String updateTime) { Map 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> udiDlDeviceResponse = JSONObject.parseObject(response, new TypeReference>>() { }); List udiInfoEntities = udiDlDeviceResponse.getData(); return udiInfoEntities; } catch (Exception e) { e.printStackTrace(); return null; } } public List dlCompanyByTime(String udiUrl, int page, int limit, String updateTime) { Map 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> baseResponse = JSONObject.parseObject(response, new TypeReference>>() { }); List udiCompanyEntities = baseResponse.getData(); return udiCompanyEntities; } catch (Exception e) { e.printStackTrace(); return null; } } public List dlByDi(String deviceId) { Map paramMap = new HashMap<>(16); paramMap.put("deviceId", deviceId); String response = HttpClient.mipsGet(udiUrl + "/udidl/device/serchDlByDi", paramMap); try { BaseResponse> baseResponse = JSONObject.parseObject(response, new TypeReference>>() { }); if (baseResponse.getCode() == 200000) { List productInfoEntityList = baseResponse.getData(); return productInfoEntityList; } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } } public BaseResponse> dlByDiRes(String deviceId) { Map paramMap = new HashMap<>(16); paramMap.put("deviceId", deviceId); String response = HttpClient.mipsGet(udiUrl + "/udidl/device/serchDlByDi", paramMap); try { BaseResponse> baseResponse = JSONObject.parseObject(response, new TypeReference>>() { }); return baseResponse; } catch (Exception e) { e.printStackTrace(); return ResultVOUtils.error(500, "连接UDI国家数据库下载出错!"); } } public BaseResponse> dlLastVersionByDi(String deviceId) { Map paramMap = new HashMap<>(16); paramMap.put("deviceId", deviceId); String response = HttpClient.mipsGet(udiUrl + "/udidl/device/dlLastVersionByDi", paramMap); try { BaseResponse> baseResponse = JSONObject.parseObject(response, new TypeReference>>() { }); return baseResponse; } catch (Exception e) { e.printStackTrace(); return ResultVOUtils.error(500, "连接UDI国家数据库下载出错!"); } } @Resource ProductInfoService productInfoService; @Async public void dlByUuid(String uuid) { Map paramMap = new HashMap<>(16); paramMap.put("uuid", uuid); String response = HttpClient.mipsGet(udiUrl + "/udidl/device/searchDlByUuid", paramMap); try { BaseResponse> baseResponse = JSONObject.parseObject(response, new TypeReference>>() { }); if (baseResponse != null && baseResponse.getCode() == 20000) { List productInfoEntityList = baseResponse.getData(); if (CollUtil.isNotEmpty(productInfoEntityList)) { productInfoService.insertProductInfos(productInfoEntityList); } } else { log.error("下载出错"); } } catch (Exception e) { e.printStackTrace(); } } }