Browse Source

增加信产字典对接接口

tags/24080901
WendyYang 7 months ago
parent
commit
6655b714fe
5 changed files with 213 additions and 1 deletions
  1. +39
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/util/EnvironmentUtil.java
  2. +79
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/external/MhApiClient.java
  3. +40
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhDictController.java
  4. +32
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/model/dto/MhDictDTO.java
  5. +23
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/external/model/enumeration/MhDictType.java

+ 39
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/util/EnvironmentUtil.java View File

@@ -0,0 +1,39 @@
package com.hz.pm.api.common.util;

import lombok.AllArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
* <p>
* EnvironmentUtil
* </p>
*
* @author WendyYang
* @since 11:00 2024/3/26
*/
@Component
@AllArgsConstructor
public class EnvironmentUtil {

private final Environment environment;

public boolean isProdEnv() {
String[] profiles = environment.getActiveProfiles();
return Arrays.asList(profiles).contains("prod");
}

public boolean isTestEnv() {
String[] profiles = environment.getActiveProfiles();
return Arrays.asList(profiles).contains("test");
}

public boolean isDevEnv() {
String[] profiles = environment.getActiveProfiles();
return Arrays.asList(profiles).contains("dev");
}


}

+ 79
- 1
hz-pm-api/src/main/java/com/hz/pm/api/external/MhApiClient.java View File

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

}

+ 40
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/controller/MhDictController.java View File

@@ -0,0 +1,40 @@
package com.hz.pm.api.external.controller;

import com.hz.pm.api.external.MhApiClient;
import com.hz.pm.api.external.model.dto.MhDictDTO;
import com.hz.pm.api.external.model.enumeration.MhDictType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* <p>
* MhDictController
* </p>
*
* @author WendyYang
* @since 10:28 2024/3/26
*/
@RestController
@Api(tags = "信产字典对接接口")
@RequiredArgsConstructor
@RequestMapping("/api/v1/mh/dict")
public class MhDictController {

private final MhApiClient mhApiClient;

@GetMapping("/listByType/{dictType}")
@ApiOperation("根据字典类型获取字典信息")
public List<MhDictDTO> dictListByType(@PathVariable MhDictType dictType) {
return mhApiClient.dictListByType(dictType);
}

}



+ 32
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/model/dto/MhDictDTO.java View File

@@ -0,0 +1,32 @@
package com.hz.pm.api.external.model.dto;

import lombok.Data;

import java.util.Date;

/**
* <p>
* MhDictDTO
* </p>
*
* @author WendyYang
* @since 10:27 2024/3/26
*/
@Data
public class MhDictDTO {

private String id;
private int dictSort;
private String dictLabel;
private String dictValue;
private String dictType;
private String dictId;
private String isDefault;
private String status;
private String remark;
private Date createTime;
private Date updateTime;
private String createBy;
private String updateBy;

}

+ 23
- 0
hz-pm-api/src/main/java/com/hz/pm/api/external/model/enumeration/MhDictType.java View File

@@ -0,0 +1,23 @@
package com.hz.pm.api.external.model.enumeration;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* <p>
* MhDictType
* </p>
*
* @author WendyYang
* @since 10:30 2024/3/26
*/
@Getter
@AllArgsConstructor
@SuppressWarnings("all")
public enum MhDictType {

buy_way("采购方式");

private final String val;

}

Loading…
Cancel
Save