从MDM接口获取所属大区和业务区域
This commit is contained in:
@@ -37,6 +37,11 @@ public class MDMHttpRequest {
|
||||
@Value("${hs.mdm.appsec:null}")
|
||||
private String mdmAppSec;
|
||||
|
||||
/**
|
||||
* 获取 mdm token
|
||||
* @return token
|
||||
* @throws ApiException 接口异常
|
||||
*/
|
||||
public String getMdmAccessToken() throws ApiException {
|
||||
RpcGetMdmTokenReq rpcGetMDMTokenReq = new RpcGetMdmTokenReq();
|
||||
rpcGetMDMTokenReq.setAppKey(mdmAppKey);
|
||||
@@ -60,6 +65,56 @@ public class MDMHttpRequest {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 mdm 所有所属大区
|
||||
* @param headers
|
||||
* @return
|
||||
*/
|
||||
public ResponseEntity<MDMResultDTO> getBelongRegion(Map<String, String> headers) throws ApiException {
|
||||
String url = mdmBaseUrl + "/api/openapi/regionget/getallregion";
|
||||
ResponseEntity<MDMResultDTO> responseEntity = null;
|
||||
try {
|
||||
//需要传一个空 body
|
||||
RpcCreateQualifyVerifyReq rpcRequest = new RpcCreateQualifyVerifyReq();
|
||||
RpcCreateQualifyVerifyReq.Data dataBody = new RpcCreateQualifyVerifyReq().new Data();
|
||||
rpcRequest.setData(dataBody);
|
||||
responseEntity = RestTemplateUtil.post(url, headers, rpcRequest, MDMResultDTO.class);
|
||||
return responseEntity;
|
||||
} catch (Exception e) {
|
||||
log.info("调用MDM接口出错 url{}, e{}", url, e);
|
||||
throw new ApiException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 mdm 所有业务区域
|
||||
* @param headers headers
|
||||
* @return ResponseEntity<MDMResultDTO> JSON
|
||||
* @throws ApiException 接口异常
|
||||
*/
|
||||
public ResponseEntity<MDMResultDTO> getBusinessRegion(Map<String, String> headers) throws ApiException {
|
||||
String url = mdmBaseUrl + "/api/openapi/regionget/getallbuarea";
|
||||
ResponseEntity<MDMResultDTO> responseEntity = null;
|
||||
try {
|
||||
//需要传一个空 body
|
||||
RpcCreateQualifyVerifyReq rpcRequest = new RpcCreateQualifyVerifyReq();
|
||||
RpcCreateQualifyVerifyReq.Data dataBody = new RpcCreateQualifyVerifyReq().new Data();
|
||||
rpcRequest.setData(dataBody);
|
||||
responseEntity = RestTemplateUtil.post(url, headers, rpcRequest, MDMResultDTO.class);
|
||||
return responseEntity;
|
||||
} catch (Exception e) {
|
||||
log.info("调用MDM接口出错 url{}, e{}", url, e);
|
||||
throw new ApiException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起 mdm 审批
|
||||
* @param headers headers
|
||||
* @param rpcRequest 请求参数
|
||||
* @return ResponseEntity<MDMResultDTO> JSON
|
||||
* @throws ApiException 接口异常
|
||||
*/
|
||||
public String createQualifyVerify(Map<String, String> headers, RpcCreateQualifyVerifyReq rpcRequest) throws ApiException{
|
||||
String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData";
|
||||
ResponseEntity<MDMResultDTO> responseEntity = null;
|
||||
@@ -77,6 +132,13 @@ public class MDMHttpRequest {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param headers headers
|
||||
* @param resource 资源文件
|
||||
* @return ResponseEntity<MDMResultDTO>
|
||||
* @throws ApiException 接口异常
|
||||
*/
|
||||
public ResponseEntity<MDMResultDTO> uploadFile(Map<String, String> headers, Resource resource) throws ApiException {
|
||||
String url = mdmBaseUrl + "/api/openapi/ext/upload/file";
|
||||
MultiValueMap<String,Object> param = new LinkedMultiValueMap<>();
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.response.mdm.BelongRegion;
|
||||
import com.cool.store.response.mdm.BusinessRegion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,4 +23,17 @@ public interface MDMAreaService {
|
||||
List<MDMAreaDO> getAllAreaCode(String code);
|
||||
|
||||
boolean getAreaProvinceType(String code);
|
||||
|
||||
/**
|
||||
* 获取所有所属大区
|
||||
* @return 所属大区
|
||||
*/
|
||||
List<BelongRegion> getBelongRegion() throws ApiException;
|
||||
|
||||
/**
|
||||
* 获取所有业务区域
|
||||
* @return 业务区域
|
||||
*/
|
||||
List<BusinessRegion> getBusinessRegion() throws ApiException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.RedisConstant;
|
||||
import com.cool.store.dto.response.MDMResultDTO;
|
||||
import com.cool.store.entity.MDMAreaDO;
|
||||
import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.http.MDMHttpRequest;
|
||||
import com.cool.store.mapper.MdmAreaMapper;
|
||||
import com.cool.store.response.mdm.BelongRegion;
|
||||
import com.cool.store.response.mdm.BusinessRegion;
|
||||
import com.cool.store.service.MDMAreaService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.utils.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
@@ -24,6 +33,9 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
@Autowired
|
||||
private MdmAreaMapper mdmAreaMapper;
|
||||
|
||||
@Autowired
|
||||
private MDMHttpRequest mdmHttpRequest;
|
||||
|
||||
/**
|
||||
* 获取省级数据
|
||||
*/
|
||||
@@ -96,4 +108,42 @@ public class MDMAreaServiceImpl implements MDMAreaService {
|
||||
return CollectionUtils.isEmpty(provinceCodeList)?false:true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有所属大区
|
||||
* @return 所属大区
|
||||
*/
|
||||
@Override
|
||||
public List<BelongRegion> getBelongRegion() throws ApiException {
|
||||
String belongRegionsString = redisUtilPool.getString(RedisConstant.MDM_BELONG_REGION);
|
||||
if (StringUtil.isNotEmpty(belongRegionsString)) {
|
||||
return (List<BelongRegion>) JSONObject.parseObject(belongRegionsString, List.class);
|
||||
}
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", mdmHttpRequest.getMdmAccessToken());
|
||||
ResponseEntity<MDMResultDTO> belongRegionResp = mdmHttpRequest.getBelongRegion(headers);
|
||||
List<BelongRegion> belongRegions = (List<BelongRegion>) belongRegionResp.getBody().getData();
|
||||
//缓存,半个小时过期
|
||||
redisUtilPool.setString(RedisConstant.MDM_BELONG_REGION, JSON.toJSONString(belongRegions), 30 * 60);
|
||||
return belongRegions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有业务区域
|
||||
* @return 业务区域
|
||||
*/
|
||||
@Override
|
||||
public List<BusinessRegion> getBusinessRegion() throws ApiException {
|
||||
String belongRegionsString = redisUtilPool.getString(RedisConstant.MDM_BUSINESS_REGION);
|
||||
if (StringUtil.isNotEmpty(belongRegionsString)) {
|
||||
return (List<BusinessRegion>) JSONObject.parseObject(belongRegionsString, List.class);
|
||||
}
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", mdmHttpRequest.getMdmAccessToken());
|
||||
ResponseEntity<MDMResultDTO> belongRegionResp = mdmHttpRequest.getBusinessRegion(headers);
|
||||
List<BusinessRegion> businessRegions = (List<BusinessRegion>) belongRegionResp.getBody().getData();
|
||||
//缓存,半个小时过期
|
||||
redisUtilPool.setString(RedisConstant.MDM_BUSINESS_REGION, JSON.toJSONString(businessRegions), 30 * 60);
|
||||
return businessRegions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user