从MDM接口获取所属大区和业务区域

This commit is contained in:
feng.li
2023-09-12 14:16:05 +08:00
parent 94612500cf
commit 8cf947a02f
7 changed files with 204 additions and 3 deletions

View File

@@ -243,6 +243,15 @@ public class RedisConstant {
*/ */
public static final String MDM_AREA_OTHERS = "mdm:area:others:{0}"; public static final String MDM_AREA_OTHERS = "mdm:area:others:{0}";
/**
* MDM 所属大区缓存
*/
public static final String MDM_BELONG_REGION = "mdm:belongRegion";
/**
* MDM 业务区域缓存
*/
public static final String MDM_BUSINESS_REGION = "mdm:businessRegion";
/** /**
* 动态标题 * 动态标题

View File

@@ -0,0 +1,26 @@
package com.cool.store.response.mdm;
import lombok.Data;
/**
* @author Fun Li 2023/9/12 11:52
* @version 1.0
* mdm 所属大区 pojo
* 对应
* {
* "id": "1642818197440036864",
* "orgregionid": "Org001",
* "orgregion": "东北战区"
* },
*/
@Data
public class BelongRegion {
private String id;
private String orgregionid;
private String orgregion;
}

View File

@@ -0,0 +1,22 @@
package com.cool.store.response.mdm;
import lombok.Data;
/**
* @author Fun Li 2023/9/12 11:29
* @version 1.0
* mdm 业务区域 pojo
* 对应
* {
* "id": "1643101868734676992",
* "buarea": "东北战区"
* },
*/
@Data
public class BusinessRegion {
private String id;
private String buarea;
}

View File

@@ -37,6 +37,11 @@ public class MDMHttpRequest {
@Value("${hs.mdm.appsec:null}") @Value("${hs.mdm.appsec:null}")
private String mdmAppSec; private String mdmAppSec;
/**
* 获取 mdm token
* @return token
* @throws ApiException 接口异常
*/
public String getMdmAccessToken() throws ApiException { public String getMdmAccessToken() throws ApiException {
RpcGetMdmTokenReq rpcGetMDMTokenReq = new RpcGetMdmTokenReq(); RpcGetMdmTokenReq rpcGetMDMTokenReq = new RpcGetMdmTokenReq();
rpcGetMDMTokenReq.setAppKey(mdmAppKey); rpcGetMDMTokenReq.setAppKey(mdmAppKey);
@@ -60,6 +65,56 @@ public class MDMHttpRequest {
return null; 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{ public String createQualifyVerify(Map<String, String> headers, RpcCreateQualifyVerifyReq rpcRequest) throws ApiException{
String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData"; String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData";
ResponseEntity<MDMResultDTO> responseEntity = null; 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 { public ResponseEntity<MDMResultDTO> uploadFile(Map<String, String> headers, Resource resource) throws ApiException {
String url = mdmBaseUrl + "/api/openapi/ext/upload/file"; String url = mdmBaseUrl + "/api/openapi/ext/upload/file";
MultiValueMap<String,Object> param = new LinkedMultiValueMap<>(); MultiValueMap<String,Object> param = new LinkedMultiValueMap<>();

View File

@@ -1,6 +1,9 @@
package com.cool.store.service; package com.cool.store.service;
import com.cool.store.entity.MDMAreaDO; 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; import java.util.List;
@@ -20,4 +23,17 @@ public interface MDMAreaService {
List<MDMAreaDO> getAllAreaCode(String code); List<MDMAreaDO> getAllAreaCode(String code);
boolean getAreaProvinceType(String code); boolean getAreaProvinceType(String code);
/**
* 获取所有所属大区
* @return 所属大区
*/
List<BelongRegion> getBelongRegion() throws ApiException;
/**
* 获取所有业务区域
* @return 业务区域
*/
List<BusinessRegion> getBusinessRegion() throws ApiException;
} }

View File

@@ -1,19 +1,28 @@
package com.cool.store.service.impl; package com.cool.store.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.RedisConstant; import com.cool.store.constants.RedisConstant;
import com.cool.store.dto.response.MDMResultDTO;
import com.cool.store.entity.MDMAreaDO; 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.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.service.MDMAreaService;
import com.cool.store.utils.RedisUtilPool; import com.cool.store.utils.RedisUtilPool;
import com.cool.store.utils.StringUtil; import com.cool.store.utils.StringUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
public class MDMAreaServiceImpl implements MDMAreaService { public class MDMAreaServiceImpl implements MDMAreaService {
@@ -24,6 +33,9 @@ public class MDMAreaServiceImpl implements MDMAreaService {
@Autowired @Autowired
private MdmAreaMapper mdmAreaMapper; private MdmAreaMapper mdmAreaMapper;
@Autowired
private MDMHttpRequest mdmHttpRequest;
/** /**
* 获取省级数据 * 获取省级数据
*/ */
@@ -96,4 +108,42 @@ public class MDMAreaServiceImpl implements MDMAreaService {
return CollectionUtils.isEmpty(provinceCodeList)?false:true; 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;
}
} }

View File

@@ -2,7 +2,10 @@ package com.cool.store.controller;
import com.cool.store.dto.mdm.AreaSonDTO; import com.cool.store.dto.mdm.AreaSonDTO;
import com.cool.store.entity.MDMAreaDO; import com.cool.store.entity.MDMAreaDO;
import com.cool.store.exception.ApiException;
import com.cool.store.response.ResponseResult; import com.cool.store.response.ResponseResult;
import com.cool.store.response.mdm.BelongRegion;
import com.cool.store.response.mdm.BusinessRegion;
import com.cool.store.service.MDMAreaService; import com.cool.store.service.MDMAreaService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@@ -14,6 +17,8 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import static com.cool.store.response.ResponseResult.success;
@RestController @RestController
@RequestMapping("/mdm/area") @RequestMapping("/mdm/area")
@Api(tags = "MDM省市信息") @Api(tags = "MDM省市信息")
@@ -25,14 +30,25 @@ public class MDMAreaController {
@PostMapping("/province") @PostMapping("/province")
@ApiOperation("获取MDM省级信息") @ApiOperation("获取MDM省级信息")
public ResponseResult<List<MDMAreaDO>> getProvince() { public ResponseResult<List<MDMAreaDO>> getProvince() {
return ResponseResult.success(mdmAreaService.getProvince()); return success(mdmAreaService.getProvince());
} }
@PostMapping("/son") @PostMapping("/son")
@ApiOperation("获取子级区域数据") @ApiOperation("获取子级区域数据")
private ResponseResult<List<MDMAreaDO>> getSonArea(@RequestBody AreaSonDTO areaSon) { public ResponseResult<List<MDMAreaDO>> getSonArea(@RequestBody AreaSonDTO areaSon) {
return ResponseResult.success(mdmAreaService.getSonArea(areaSon.getCode())); return success(mdmAreaService.getSonArea(areaSon.getCode()));
} }
@PostMapping("/belonging/region")
@ApiOperation("获取 mdm 所有归属大区")
public ResponseResult<List<BelongRegion>> getBelongRegion() throws ApiException {
return ResponseResult.success(mdmAreaService.getBelongRegion());
}
@PostMapping("/business/region")
@ApiOperation("获取 mdm 所有业务区域")
public ResponseResult<List<BusinessRegion>> getBusinessRegion() throws ApiException {
return ResponseResult.success(mdmAreaService.getBusinessRegion());
}
} }