Merge branch 'master' into dev/feat/partner1.4_20231009

# Conflicts:
#	coolstore-partner-dao/src/main/java/com/cool/store/dao/HyPartnerIntentInfoDAO.java
#	coolstore-partner-dao/src/main/java/com/cool/store/mapper/HyPartnerIntentInfoMapper.java
#	coolstore-partner-dao/src/main/resources/mapper/HyPartnerIntentInfoMapper.xml
#	coolstore-partner-model/src/main/java/com/cool/store/entity/HyPartnerIntentInfoDO.java
#	coolstore-partner-service/src/main/java/com/cool/store/service/impl/FlowServiceImpl.java
#	coolstore-partner-service/src/main/java/com/cool/store/service/impl/HyPartnerIntentInfoServiceImpl.java
This commit is contained in:
俞扬
2023-09-19 10:34:52 +08:00
15 changed files with 410 additions and 65 deletions

View File

@@ -243,6 +243,15 @@ public class RedisConstant {
*/
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

@@ -78,4 +78,12 @@ public class HyPartnerIntentInfoDAO {
return hyPartnerIntentInfoMapper.updateByPartnerLineId(record);
}
public int updateAcquaintanceFlag(Long id ,Integer acquaintanceFlag,String acquaintanceName, Integer acquaintanceRelationshipType,String otherRelationshipType){
if (id==null){
return 0;
}
return hyPartnerIntentInfoMapper.updateAcquaintanceFlag(id,acquaintanceFlag,acquaintanceName,acquaintanceRelationshipType,otherRelationshipType);
}
}

View File

@@ -67,4 +67,14 @@ public interface HyPartnerIntentInfoMapper {
int updateByPartnerLineId(@Param("record") HyPartnerIntentInfoDO record);
/**
* 更新数据
* @param id
* @param acquaintanceFlag
* @param acquaintanceName
* @param acquaintanceRelationshipType
* @param otherRelationshipType
*/
int updateAcquaintanceFlag(Long id ,Integer acquaintanceFlag,String acquaintanceName, Integer acquaintanceRelationshipType,String otherRelationshipType);
}

View File

@@ -27,12 +27,15 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="detailed_address" jdbcType="VARCHAR" property="detailedAddress" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="acquaintance_flag" jdbcType="TINYINT" property="acquaintanceFlag" />
<result column="acquaintance_name" jdbcType="VARCHAR" property="acquaintanceName" />
<result column="acquaintance_relationship_type" jdbcType="TINYINT" property="acquaintanceRelationshipType" />
<result column="other_relationship_type" jdbcType="VARCHAR" property="otherRelationshipType" />
</resultMap>
<sql id="Base_Column_List">
id, partner_id, partner_line_id, live_area, want_shop_area, accept_adjust_type, is_have_want_shop,
want_shop_info, max_budget, money_source, money_prove, education, work_year, is_have_work_exp,
work_exp, is_consumer, other_band, brand_strength, need_improve, strength, weakness,
create_time, update_time,detailed_address,email
work_exp, is_consumer, other_band, brand_strength, need_improve, strength, weakness,detailed_address,email ,acquaintance_flag,acquaintance_name,acquaintance_relationship_type,other_relationship_type
</sql>
<select id="selectByPrimaryKeySelective" resultMap="BaseResultMap">
select
@@ -117,6 +120,18 @@
<if test="record.email != null">
email,
</if>
<if test="record.acquaintanceFlag != null">
acquaintance_flag,
</if>
<if test="record.acquaintanceName != null">
acquaintance_name,
</if>
<if test="record.acquaintanceRelationshipType != null">
acquaintance_relationship_type,
</if>
<if test="record.otherRelationshipType != null">
other_relationship_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="record.partnerId != null">
@@ -191,6 +206,18 @@
<if test="record.email != null">
#{record.email},
</if>
<if test="record.acquaintanceFlag != null">
#{record.acquaintanceFlag},
</if>
<if test="record.acquaintanceName != null">
#{record.acquaintanceName},
</if>
<if test="record.acquaintanceRelationshipType != null">
#{record.acquaintanceRelationshipType},
</if>
<if test="record.otherRelationshipType != null">
#{record.otherRelationshipType},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective">
@@ -358,6 +385,16 @@
where partner_line_id = #{oldLineId}
</update>
<update id="updateAcquaintanceFlag">
update hy_partner_intent_info
set
acquaintance_flag = #{acquaintanceFlag} ,
other_relationship_type = #{otherRelationshipType},
acquaintance_name = #{acquaintanceName},
acquaintance_relationship_type = #{acquaintanceRelationshipType}
where id = #{id}
</update>
<update id="updateByPartnerLineId">
update hy_partner_intent_info
<set>

View File

@@ -104,4 +104,12 @@ public class HyPartnerIntentInfoDO implements Serializable {
@ApiModelProperty("邮箱地址")
private String email;
private Integer acquaintanceFlag;
private String acquaintanceName;
private Integer acquaintanceRelationshipType;
private String otherRelationshipType;
}

View File

@@ -87,4 +87,12 @@ public class PartnerIntentInfoRequest {
@ApiModelProperty("提交标识 提交-true 暂存-false")
private Boolean submitFlag;
private Integer acquaintanceFlag;
private String acquaintanceName;
private Integer acquaintanceRelationshipType;
private String otherRelationshipType;
}

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

@@ -99,5 +99,12 @@ public class PartnerIntentInfoVO {
@ApiModelProperty("创建时间")
private Date createTime;
private Integer acquaintanceFlag;
private String acquaintanceName;
private Integer acquaintanceRelationshipType;
private String otherRelationshipType;
}

View File

@@ -0,0 +1,157 @@
package com.cool.store.http;
import com.alibaba.fastjson.JSONObject;
import com.cool.store.dto.mdm.AccessTokenDTO;
import com.cool.store.dto.response.MDMResultDTO;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.request.RpcCreateQualifyVerifyReq;
import com.cool.store.request.RpcGetMdmTokenReq;
import com.cool.store.utils.RestTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.Map;
import java.util.Objects;
/**
* @author Fun Li 2023/9/12 10:07
* @version 1.0
*/
@Slf4j
@Service
public class MDMHttpRequest {
@Value("${hs.mdm.baseUrl:null}")
private String mdmBaseUrl;
@Value("${hs.mdm.appkey:null}")
private String mdmAppKey;
@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);
rpcGetMDMTokenReq.setAppSecret(mdmAppSec);
String url = mdmBaseUrl + "/api/oauth2/accessToken";
ResponseEntity<MDMResultDTO> responseEntity = null;
try {
responseEntity = RestTemplateUtil.post(url,rpcGetMDMTokenReq, MDMResultDTO.class);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if (Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()) {
AccessTokenDTO accessTokenDTO = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), AccessTokenDTO.class);
if(accessTokenDTO==null || StringUtils.isBlank(accessTokenDTO.getAccessToken())){
throw new ServiceException("获取Mdm token失败!");
}
return accessTokenDTO.getAccessToken();
}
} catch (Exception e) {
log.info("获取MDM Token 出错 url:\t{}, e:\t{}", url, e);
throw new ApiException(e.getMessage());
}
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;
try {
responseEntity = RestTemplateUtil.post(url, headers, rpcRequest, MDMResultDTO.class);
log.info("url:{}, header:{}, request:{} response:{}", url, JSONObject.toJSONString(headers), JSONObject.toJSONString(rpcRequest), JSONObject.toJSONString(responseEntity));
if (Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()) {
return JSONObject.toJSONString(responseEntity.getBody().getData());
}
} catch (Exception e) {
log.info("调用MDM接口出错 url{}, e{}", url, e);
throw new ApiException(e.getMessage());
}
return null;
}
/**
*
* @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<>();
try {
param.add("file", resource);
ResponseEntity<MDMResultDTO> responseEntity = RestTemplateUtil.post(url, headers, param, MDMResultDTO.class);
log.info("url:{}, header:{}, response statusCode:{}", url, JSONObject.toJSONString(headers), JSONObject.toJSONString(responseEntity.getStatusCode()));
return responseEntity;
} catch (Exception e) {
log.info("调用MDM接口出错 url{}, e{}", url, e);
throw new ApiException(e.getMessage());
}
}
}

View File

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

View File

@@ -19,6 +19,7 @@ import com.cool.store.entity.*;
import com.cool.store.enums.*;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.http.MDMHttpRequest;
import com.cool.store.mapper.*;
import com.cool.store.oss.OSSServer;
import com.cool.store.request.*;
@@ -103,6 +104,9 @@ public class FlowServiceImpl implements FlowService {
@Autowired
private HyPartnerFraSourceMapper hyPartnerFraSourceMapper;
@Autowired
private MDMHttpRequest mdmHttpRequest;
@Override
@Transactional(rollbackFor = Exception.class)
public void createQualifyVerify(CreateQualifyVerifyReq request) throws ApiException, IOException {
@@ -176,12 +180,16 @@ public class FlowServiceImpl implements FlowService {
}
//通过 rpc 请求审核系统获取返回数据
//上传证明文件数据
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", mdmHttpRequest.getMdmAccessToken());
if (StringUtils.isNotEmpty(request.getSignerRealControlRelationCert())) {
List<String> certFileList = Arrays.asList(request.getSignerRealControlRelationCert().split(","));
List<SkrRelshipProve> relshipProves = OSSFileToMDMFile(certFileList);
List<SkrRelshipProve> relshipProves = OSSFileToMDMFile(headers, certFileList);
rpcRequest.getData().setSkrRelshipProve(relshipProves);
}
Map<String, String> qualifyVerifyRespData = JSON.parseObject(createQualifyVerify(rpcRequest), new TypeReference<HashMap<String,String>>() {});
//调用接口发起审批
String qualifyVerify = mdmHttpRequest.createQualifyVerify(headers, rpcRequest);
Map<String, String> qualifyVerifyRespData = JSON.parseObject(qualifyVerify, new TypeReference<HashMap<String,String>>() {});
//2.更新审核信息
HyPartnerCertificationInfoDO partnerCertificationInfoDO = new HyPartnerCertificationInfoDO();
@@ -301,14 +309,10 @@ public class FlowServiceImpl implements FlowService {
return hyPartnerFraSourceMapper.selectAllFraSourceList();
}
public List<SkrRelshipProve> OSSFileToMDMFile(List<String> fileUrlList) throws ApiException, IOException {
String url = mdmBaseUrl + "/api/openapi/ext/upload/file";
ResponseEntity<MDMResultDTO> responseEntity = null;
RpcGetMdmTokenReq rpcGetMDMTokenReq = new RpcGetMdmTokenReq();
rpcGetMDMTokenReq.setAppKey(mdmAppKey);
rpcGetMDMTokenReq.setAppSecret(mdmAppSec);
private List<SkrRelshipProve> OSSFileToMDMFile(Map<String, String> headers, List<String> fileUrlList) throws ApiException, IOException {
ByteArrayOutputStream outputStream = null;
List<SkrRelshipProve> relshipProves = new ArrayList<>();
ResponseEntity<MDMResultDTO> responseEntity = null;
//逐个处理文件
for (String fileUrl : fileUrlList) {
@@ -317,76 +321,30 @@ public class FlowServiceImpl implements FlowService {
outputStream = ossServer.downloadFileServer(fileName);
//2. 将下载到的文件上传到 MDM 系统中
try {
//获取 token 设置到 header
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getMdmAccessToken(rpcGetMDMTokenReq));
//将文件流编辑为 formdata 格式的数据
MultiValueMap<String,Object> param = new LinkedMultiValueMap<>();
ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray()) {
@Override
public String getFilename() throws IllegalStateException {
return fileName;
}
};
param.add("file", resource);
//上传文件
responseEntity = RestTemplateUtil.post(url, headers, param, MDMResultDTO.class);
log.info("url:{}, header:{}, response statusCode:{}", url, JSONObject.toJSONString(headers), JSONObject.toJSONString(responseEntity.getStatusCode()));
responseEntity = mdmHttpRequest.uploadFile(headers, resource);
Map<String, String> data = (Map<String, String>) responseEntity.getBody().getData();
SkrRelshipProve skrRelshipProve= BeanUtil.fillBeanWithMap(data, new SkrRelshipProve(), false);
relshipProves.add(skrRelshipProve);
} catch (Exception e) {
log.info("调用MDM接口出错 url{}, fileUrl{}, e{}", url, fileUrl, e);
log.info("上传文件到MDM出错, e{}", e);
throw new ApiException(e.getMessage());
} finally {
outputStream.close();
if (outputStream != null) {
outputStream.close();
}
}
}
return relshipProves;
}
public String createQualifyVerify(RpcCreateQualifyVerifyReq rpcRequest) throws ApiException{
String url = mdmBaseUrl + "/api/openapi/runtime/form/startFraQualExamWithData";
ResponseEntity<MDMResultDTO> responseEntity = null;
try {
RpcGetMdmTokenReq rpcGetMDMTokenReq = new RpcGetMdmTokenReq();
rpcGetMDMTokenReq.setAppKey(mdmAppKey);
rpcGetMDMTokenReq.setAppSecret(mdmAppSec);
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", getMdmAccessToken(rpcGetMDMTokenReq));
responseEntity = RestTemplateUtil.post(url, headers, rpcRequest, MDMResultDTO.class);
log.info("url:{}, header:{}, request:{} response:{}", url, JSONObject.toJSONString(headers), JSONObject.toJSONString(rpcRequest), JSONObject.toJSONString(responseEntity));
if (Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()) {
return JSONObject.toJSONString(responseEntity.getBody().getData());
}
} catch (Exception e) {
log.info("调用MDM接口出错 url{}, e{}", url, e);
throw new ApiException(e.getMessage());
}
return null;
}
public String getMdmAccessToken(RpcGetMdmTokenReq rpcGetMDMTokenReq) throws ApiException {
String url = mdmBaseUrl + "/api/oauth2/accessToken";
ResponseEntity<MDMResultDTO> responseEntity = null;
try {
responseEntity = RestTemplateUtil.post(url,rpcGetMDMTokenReq, MDMResultDTO.class);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if (Objects.nonNull(responseEntity.getBody()) && responseEntity.getBody().isSuccess()) {
AccessTokenDTO accessTokenDTO = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getBody().getData()), AccessTokenDTO.class);
if(accessTokenDTO==null || StringUtils.isBlank(accessTokenDTO.getAccessToken())){
throw new ServiceException("获取Mdm token失败!");
}
return accessTokenDTO.getAccessToken();
}
} catch (Exception e) {
log.info("获取MDM Token 出错 url:\t{}, e:\t{}", url, e);
throw new ApiException(e.getMessage());
}
return null;
}
/**
* 生成授权码

View File

@@ -220,6 +220,11 @@ public class HyPartnerIntentInfoServiceImpl implements HyPartnerIntentInfoServic
BeanUtil.copyProperties(intentInfoDO, beforeIntentInfoUpdate);
fillIntentInfo(intentInfoDO, request);
hyPartnerIntentInfoDAO.updateByPrimaryKeySelective(intentInfoDO);
//PC端 AcquaintanceFlag 不传值 移动端修改必填
if (request.getAcquaintanceFlag()!=null){
hyPartnerIntentInfoDAO.updateAcquaintanceFlag(intentInfoDO.getId(),request.getAcquaintanceFlag(), request.getAcquaintanceName(),
request.getAcquaintanceRelationshipType(),request.getOtherRelationshipType());
}
BeanUtil.copyProperties(intentInfoDO, afterIntentInfoUpdate);
}
redisUtilPool.delKey(cacheKey);
@@ -445,6 +450,10 @@ public class HyPartnerIntentInfoServiceImpl implements HyPartnerIntentInfoServic
intentInfoDO.setWantShopArea(request.getWantShopArea());
intentInfoDO.setDetailedAddress(request.getDetailedAddress());
intentInfoDO.setEmail(request.getEmail());
intentInfoDO.setAcquaintanceFlag(request.getAcquaintanceFlag());
intentInfoDO.setAcquaintanceName(request.getAcquaintanceName());
intentInfoDO.setAcquaintanceRelationshipType(request.getAcquaintanceRelationshipType());
intentInfoDO.setOtherRelationshipType(request.getOtherRelationshipType());
intentInfoDO.setAcceptAdjustType(request.getAcceptAdjustType());
intentInfoDO.setIsHaveWantShop(request.getIsHaveWantShop());
intentInfoDO.setWantShopInfo("");
@@ -502,6 +511,10 @@ public class HyPartnerIntentInfoServiceImpl implements HyPartnerIntentInfoServic
if(StringUtils.isNotEmpty(hyPartnerIntentInfoDO.getWantShopInfo())){
partnerIntentInfoVO.setWantShopInfo(JSONObject.parseArray(hyPartnerIntentInfoDO.getWantShopInfo(), WantShopInfoVO.class));
}
partnerIntentInfoVO.setAcquaintanceFlag(hyPartnerIntentInfoDO.getAcquaintanceFlag());
partnerIntentInfoVO.setAcquaintanceName(hyPartnerIntentInfoDO.getAcquaintanceName());
partnerIntentInfoVO.setAcquaintanceRelationshipType(hyPartnerIntentInfoDO.getAcquaintanceRelationshipType());
partnerIntentInfoVO.setOtherRelationshipType(hyPartnerIntentInfoDO.getOtherRelationshipType());
return partnerIntentInfoVO;
}

View File

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

View File

@@ -2,7 +2,10 @@ package com.cool.store.controller;
import com.cool.store.dto.mdm.AreaSonDTO;
import com.cool.store.entity.MDMAreaDO;
import com.cool.store.exception.ApiException;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -14,9 +17,11 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static com.cool.store.response.ResponseResult.success;
@RestController
@RequestMapping("/mdm/area")
@Api(tags = "MDM省市信息")
@Api(tags = "MDM区域信息")
public class MDMAreaController {
@Autowired
@@ -25,14 +30,25 @@ public class MDMAreaController {
@PostMapping("/province")
@ApiOperation("获取MDM省级信息")
public ResponseResult<List<MDMAreaDO>> getProvince() {
return ResponseResult.success(mdmAreaService.getProvince());
return success(mdmAreaService.getProvince());
}
@PostMapping("/son")
@ApiOperation("获取子级区域数据")
private ResponseResult<List<MDMAreaDO>> getSonArea(@RequestBody AreaSonDTO areaSon) {
return ResponseResult.success(mdmAreaService.getSonArea(areaSon.getCode()));
public ResponseResult<List<MDMAreaDO>> getSonArea(@RequestBody AreaSonDTO areaSon) {
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());
}
}