Commit 52f9f3eb by guojuxing

微盟授权接口对接

parent c9afcdff
......@@ -32,6 +32,23 @@ public enum MallModeEnum {
return false;
}
/**
* 与微盟code进行匹配 0 微盟微商城 1 微盟智慧零售
* @Title: mapToWm

* @Description:

* @author guojuxing
* @param code

* @return int


*/
public static int mapToWm(Integer code) {
if (code.intValue() == 1) {
return 0;
} else if (code.intValue() == 2) {
return 1;
}
return 0;
}
public int getCode() {
return code;
}
......
......@@ -199,6 +199,11 @@
<artifactId>gic-data-api</artifactId>
<version>${gic-data-api}</version>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-weimob-api</artifactId>
<version>${test}</version>
</dependency>
</dependencies>
<build>
......
package com.gic.enterprise.web.controller.wm;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -7,16 +9,24 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.alibaba.fastjson.JSON;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GlobalVar;
import com.gic.commons.web.ResponseThreadLocal;
import com.gic.enterprise.web.utils.DomainUtils;
import com.gic.enterprise.web.vo.MemberCardVO;
import com.gic.enterprise.web.vo.wm.MemberGradeVO;
import com.gic.enterprise.web.vo.wm.WmStoreDetailVO;
import com.gic.enterprise.web.vo.wm.WmStoreVO;
import com.gic.member.config.api.service.MemberCardApiService;
import com.gic.weimob.api.service.WeimobMerchantService;
import com.gic.weimob.api.service.WeimobStoreSiteService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.gic.api.base.commons.ServiceResponse;
......@@ -39,11 +49,24 @@ public class WmMallStoreController {
private WmStoreApiService wmStoreApiService;
@Autowired
private MemberCardApiService memberCardApiService;
@Autowired
private WeimobStoreSiteService weimobStoreSiteService;
@Autowired
private WeimobMerchantService weimobMerchantService;
@RequestMapping("/save-wm-store")
public RestResponse save(WmStoreDTO dto) {
dto.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
return OperationResultUtils.operationResult(wmStoreApiService.saveWmStore(dto),
ServiceResponse<Integer> result = wmStoreApiService.saveWmStore(dto);
if (result.isSuccess()) {
//创建微盟gic关联
ServiceResponse<Void> saveStoreInfo = weimobMerchantService
.saveStoreInfo(result.getResult(), dto.getEnterpriseId(),
dto.getWmMainAccount(), Long.valueOf(dto.getWmPid()), Long.valueOf(dto.getWmStoreId()),
MallModeEnum.mapToWm(dto.getMallMode()));
LOGGER.info("微盟商城店铺-微盟结果:{}", JSON.toJSONString(saveStoreInfo));
}
return OperationResultUtils.operationResult(result,
OperationResultUtils.LOG_NEW + "微盟商城店铺", dto.getWmPidName());
}
......@@ -96,7 +119,7 @@ public class WmMallStoreController {
}
/**
* 授权
* 获取授权链接
* @Title: authWmStore

* @Description:

* @author guojuxing
......@@ -105,9 +128,85 @@ public class WmMallStoreController {

*/
@RequestMapping("/get-auth-url")
public RestResponse getAuthUrl(Integer wmMallStoreId) {
ServiceResponse<String> result = wmStoreApiService.authWmStore(wmMallStoreId);
//todo
return RestResponse.success("http://baidu.com");
//
ServiceResponse<String> response = weimobMerchantService.getAuthUrl();
if (response.isSuccess()) {
String authUrl = response.getResult();
String mainHost = DomainUtils.getCurrentDomain() + "/wm-mall-store/auth-callback?wmMallStoreId=" + wmMallStoreId;
return RestResponse.success(authUrl + "&redirect_uri=" + mainHost);
} else {
return RestResponse.failure(response.getCode(), response.getMessage());
}
}
/**
* 同步会员等级到微盟
* @Title: syncMemberGradeToWm

* @Description:

* @author guojuxing
* @param memberCardId
* @param wmMallStoreId

* @return com.gic.commons.webapi.reponse.RestResponse


*/
@RequestMapping("/sync-member-grade-to-wm")
public RestResponse syncMemberGradeToWm(String memberCardId, Integer wmMallStoreId) {
ServiceResponse<Void> syncMemberCardResponse = weimobMerchantService
.saveWmMallStoreIdAndMcuAreaId(wmMallStoreId, Long.valueOf(memberCardId));
ServiceResponse<Void> syncMemberGradeResponse = weimobMerchantService
.saveOrUpdateCardGradeSetting(wmMallStoreId, Long.valueOf(memberCardId));
LOGGER.info("同步会员等级-会员卡结果:{}", JSON.toJSONString(syncMemberCardResponse));
LOGGER.info("同步会员等级-会员卡等级结果:{}", JSON.toJSONString(syncMemberGradeResponse));
return RestResponse.success();
}
/**
* 获取会员卡已同步接口
* @Title: listMemberGrade

* @Description:

* @author guojuxing
* @param wmMallStoreId

* @return com.gic.commons.webapi.reponse.RestResponse


*/
@RequestMapping("/list-member-grade")
public RestResponse listMemberGrade(Integer wmMallStoreId) {
return ResultControllerUtils.commonResult(weimobMerchantService.getGradeList(wmMallStoreId), MemberGradeVO.class);
}
/**
* 获取微盟卡券列表
* @Title: listWmCoupom

* @Description:

* @author guojuxing
* @param wmMainAccount

* @return com.gic.commons.webapi.reponse.RestResponse


*/
@RequestMapping("/list-wm-coupon")
public RestResponse listWmCoupom(String wmMainAccount) {
//todo getWeimobCouponTemplate
return RestResponse.success();
}
/**
* 授权回调
* @param code
*/
@RequestMapping("auth-callback")
@ResponseBody
public void authCallBack(String code, Integer wmMallStoreId) throws IOException {
Integer enterpriseId = UserDetailUtils.getUserDetail().getEnterpriseId();
try {
ServiceResponse<Void> authWmResponse = weimobMerchantService.weimobStoreAuth(enterpriseId, code);
LOGGER.info("微盟中间件返回结果:{}", JSON.toJSONString(authWmResponse));
if (authWmResponse.isSuccess()) {
//更新gic侧店铺授权状态
ServiceResponse<String> wmMallStoreResponse = wmStoreApiService.authWmStore(wmMallStoreId);
if (!wmMallStoreResponse.isSuccess()) {
LOGGER.warn("企业侧微盟店铺授权结果:{}", JSON.toJSONString(wmMallStoreResponse));
}
}
} catch (Exception e) {
LOGGER.warn("微盟授权返回结果:{}", e.getMessage(), e);
}
}
@RequestMapping("/list-mall-mode")
......
package com.gic.enterprise.web.utils;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
public class DomainUtils {
/**
* 获取当前环境的域名
* @Title: getCurrentDomain

* @Description:

* @author guojuxing 

* @return java.lang.String


*/
public static String getCurrentDomain() {
Config config = ConfigService.getConfig("COMMON.4.0-gic-properties");
String url = config.getProperty("service_host", "").replace("/gic", "");
return url;
}
}
package com.gic.enterprise.web.vo.wm;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable;
public class MemberGradeVO implements Serializable{
private static final long serialVersionUID = -4371810311919948562L;
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long gradeId;
private String gradeName;
private String gradeCode;
public Long getGradeId() {
return gradeId;
}
public MemberGradeVO setGradeId(Long gradeId) {
this.gradeId = gradeId;
return this;
}
public String getGradeName() {
return gradeName;
}
public MemberGradeVO setGradeName(String gradeName) {
this.gradeName = gradeName;
return this;
}
public String getGradeCode() {
return gradeCode;
}
public MemberGradeVO setGradeCode(String gradeCode) {
this.gradeCode = gradeCode;
return this;
}
}
......@@ -124,4 +124,7 @@
<dubbo:reference interface="com.gic.auth.service.ResourceApiService" id="resourceApiService" timeout="6000"/>
<dubbo:reference interface="com.gic.data.api.service.MemberDataApiService" id="memberDataApiService" timeout="6000"/>
<dubbo:reference interface="com.gic.member.config.api.service.MemberCardApiService" id="memberCardApiService" timeout="6000"/>
<dubbo:reference interface="com.gic.weimob.api.service.WeimobStoreSiteService" id="weimobStoreSiteService" timeout="6000"/>
<dubbo:reference interface="com.gic.weimob.api.service.WeimobMerchantService" id="weimobMerchantService" timeout="6000"/>
</beans>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment