|
|
@@ -5,9 +5,12 @@ import cn.hutool.core.lang.TypeReference; |
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.hz.pm.api.common.util.EnvironmentUtil; |
|
|
|
import com.hz.pm.api.external.model.dto.*; |
|
|
|
import com.hz.pm.api.external.model.enumeration.MhDictType; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.omg.CORBA.TIMEOUT; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
@@ -26,8 +29,11 @@ import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMATTER; |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class MhApiClient { |
|
|
|
|
|
|
|
private final EnvironmentUtil environmentUtil; |
|
|
|
|
|
|
|
@Value("${mh.api-host:}") |
|
|
|
private String mhApiHost; |
|
|
|
|
|
|
@@ -45,6 +51,8 @@ public class MhApiClient { |
|
|
|
|
|
|
|
private static final String ZWDD_MSG_URL = "/message/send"; |
|
|
|
|
|
|
|
private static final String DICT_URL = "/dict_data/listByType"; |
|
|
|
|
|
|
|
|
|
|
|
public MhRetDTO<List<MhUnitDTO>> queryUnits() { |
|
|
|
String requestUrl = mhApiHost + UNIT_URL; |
|
|
@@ -101,5 +109,75 @@ public class MhApiClient { |
|
|
|
return Boolean.FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
static final String DICT_RET_JSON = "{\n" + |
|
|
|
" \"code\": 200,\n" + |
|
|
|
" \"msg\": \"success\",\n" + |
|
|
|
" \"data\": [\n" + |
|
|
|
" {\n" + |
|
|
|
" \"id\": \"035931f1fdb698cdf0d4cb7a04154a34\",\n" + |
|
|
|
" \"dictSort\": 0,\n" + |
|
|
|
" \"dictLabel\": \"竞争性切磋\",\n" + |
|
|
|
" \"dictValue\": \"JZXQC\",\n" + |
|
|
|
" \"dictType\": \"buy_way\",\n" + |
|
|
|
" \"dictId\": \"6f578f6f717a5d5bb0bf63a9b0870239\",\n" + |
|
|
|
" \"isDefault\": \"N\",\n" + |
|
|
|
" \"status\": \"0\",\n" + |
|
|
|
" \"remark\": null,\n" + |
|
|
|
" \"createTime\": \"2024-01-3021:21:40\",\n" + |
|
|
|
" \"updateTime\": null,\n" + |
|
|
|
" \"createBy\": \"7b40b2e2d396930d4f8567fd3d47a39e\",\n" + |
|
|
|
" \"updateBy\": \"\"\n" + |
|
|
|
" },\n" + |
|
|
|
" {\n" + |
|
|
|
" \"id\": \"1b66784a1af14660186d5e3e40dec96b\",\n" + |
|
|
|
" \"dictSort\": 0,\n" + |
|
|
|
" \"dictLabel\": \"询价\",\n" + |
|
|
|
" \"dictValue\": \"XJ\",\n" + |
|
|
|
" \"dictType\": \"buy_way\",\n" + |
|
|
|
" \"dictId\": \"6f578f6f717a5d5bb0bf63a9b0870239\",\n" + |
|
|
|
" \"isDefault\": \"N\",\n" + |
|
|
|
" \"status\": \"0\",\n" + |
|
|
|
" \"remark\": null,\n" + |
|
|
|
" \"createTime\": \"2024-01-3021:22:04\",\n" + |
|
|
|
" \"updateTime\": null,\n" + |
|
|
|
" \"createBy\": \"7b40b2e2d396930d4f8567fd3d47a39e\",\n" + |
|
|
|
" \"updateBy\": \"\"\n" + |
|
|
|
" },\n" + |
|
|
|
" {\n" + |
|
|
|
" \"id\": \"fc5d7c2cb97b15db54e3f6265df9e5f1\",\n" + |
|
|
|
" \"dictSort\": 0,\n" + |
|
|
|
" \"dictLabel\": \"邀请招标\",\n" + |
|
|
|
" \"dictValue\": \"YQZB\",\n" + |
|
|
|
" \"dictType\": \"buy_way\",\n" + |
|
|
|
" \"dictId\": \"6f578f6f717a5d5bb0bf63a9b0870239\",\n" + |
|
|
|
" \"isDefault\": \"N\",\n" + |
|
|
|
" \"status\": \"0\",\n" + |
|
|
|
" \"remark\": null,\n" + |
|
|
|
" \"createTime\": \"2024-01-3021:18:39\",\n" + |
|
|
|
" \"updateTime\": null,\n" + |
|
|
|
" \"createBy\": \"7b40b2e2d396930d4f8567fd3d47a39e\",\n" + |
|
|
|
" \"updateBy\": \"\"\n" + |
|
|
|
" }\n" + |
|
|
|
" ]\n" + |
|
|
|
"}"; |
|
|
|
|
|
|
|
public List<MhDictDTO> dictListByType(MhDictType dictType) { |
|
|
|
String retBody; |
|
|
|
if (!environmentUtil.isDevEnv()) { |
|
|
|
String url = mhApiHost + DICT_URL; |
|
|
|
retBody = HttpUtil.get(url + "?dictType=" + dictType); |
|
|
|
} else { |
|
|
|
retBody = DICT_RET_JSON; |
|
|
|
} |
|
|
|
MhRetDTO<List<MhDictDTO>> retObj = JSONUtil.toBean(retBody, |
|
|
|
new TypeReference<MhRetDTO<List<MhDictDTO>>>() { |
|
|
|
}, false); |
|
|
|
if (retObj.isOk()) { |
|
|
|
return retObj.getData(); |
|
|
|
} else { |
|
|
|
log.error("获取字典信息失败:{} {}", dictType, retBody); |
|
|
|
throw BizException.wrap("获取字典【%s】失败", dictType.getVal()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |