5.3 应用绑定服务类型
5.3.1 系统设计
为应用绑定服务类型即指定应用使用哪些服务类型,数据模型设计如下 :
5.3.2 交易服务-获取平台服务类型(接口①)
绑定服务类型页面,页面中列表出服务类型。
5.3.1.1 接口定义
1、接口描述:查询平台支持的所有服务类型
2、接口定义如下:PayChannelService
package com.huiminpay.transaction.api;
/**
\* 支付渠道服务 管理平台支付渠道,原始支付渠道,以及相关配置
*/
public interface PayChannelService {
/**
\* 获取平台服务类型
\* @return
*/
List<PlatformChannelDTO> queryPlatformChannel() throws BusinessException;
}
5.3.1.2 接口实现
定义PayChannelServiceImpl类及queryPlatformChannel实现方法:
package com.huiminpay.transaction.service;
import com.huiminpay.transaction.api.PayChannelService;
import com.huiminpay.transaction.api.dto.PlatformChannelDTO;
import com.huiminpay.transaction.convert.PlatformChannelConvert;
import com.huiminpay.transaction.entity.PlatformChannel;
import com.huiminpay.transaction.mapper.PlatformChannelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@org.apache.dubbo.config.annotation.Service
public class PayChannelServiceImpl implements PayChannelService {
@Autowired
private PlatformChannelMapper platformChannelMapper;
@Override
public List<PlatformChannelDTO> queryPlatformChannel() {
List<PlatformChannel> platformChannels = platformChannelMapper.selectList(null);
List<PlatformChannelDTO> platformChannelDTOS =
PlatformChannelConvert.INSTANCE.listentity2listdto(platformChannels);
return platformChannelDTOS;
}
}
5.3.3 商户平台应用-获取平台服务类型(接口②)
5.3.3.1 接口定义
在商户平台应用工程添加依赖:
<dependency>
<groupId>com.huiminpay</groupId>
<artifactId>huiminpay-transaction-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
1、接口描述:请求交易服务查询平台支持的所有服务类型
2、接口定义如下:PlatformParamController
package com.huiminpay.merchant.controller;
@Api(value = "商户平台-渠道和支付参数相关", tags = "商户平台-渠道和支付参数", description = "商户平台-渠道和支付参数相关")
@Slf4j
@RestController
public class PlatformParamController {
@Reference
private PayChannelService payChannelService;
@ApiOperation("获取平台服务类型")
@GetMapping(value="/my/platform-channels")
public List<PlatformChannelDTO> queryPlatformChannel(){
return payChannelService.queryPlatformChannel();
}
}
5.3.3.2 接口测试
5.3.4 交易服务-绑定服务类型接口(接口③)
点击开启服务为应用绑定服务类型
5.3.4.1 接口定义
1、接口描述:
1)查询出指定应用就否已绑定选定的服务类型
2)如果该应用没有绑定该 服务类型则进行绑定
2、接口定义如下:
在PayChannelService接口中定义bindPlatformChannelForApp
/**
\* 为app绑定平台服务类型
\* @param appId 应用id
\* @param platformChannelCodes 平台服务类型列表
*/
void bindPlatformChannelForApp(String appId, String platformChannelCodes) throws BusinessException;
5.3.4.2 接口实现
定义PayChannelServiceImpl类及bindPlatformChannelForApp实现方法:
package com.huiminpay.transaction.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huiminpay.transaction.api.PayChannelService;
import com.huiminpay.transaction.entity.AppPlatformChannel;
import com.huiminpay.transaction.mapper.AppPlatformChannelMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
@Service
public class PayChannelServiceImpl implements PayChannelService {
@Autowired
private AppPlatformChannelMapper appPlatformChannelMapper;
@Override
@Transactional
public void bindPlatformChannelForApp(String appId, String platformChannelCodes) throws
BusinessException {
//根据appId和平台服务类型code查询app_platform_channel
AppPlatformChannel appPlatformChannel = appPlatformChannelMapper.selectOne(
new LambdaQueryWrapper<AppPlatformChannel>()
.eq(AppPlatformChannel::getAppId, appId)
.eq(AppPlatformChannel::getPlatformChannel, platformChannelCodes));
//如果没有绑定则绑定
if(appPlatformChannel ==null){
appPlatformChannel = new AppPlatformChannel();
appPlatformChannel.setAppId(appId);
appPlatformChannel.setPlatformChannel(platformChannelCodes);
appPlatformChannelMapper.insert(appPlatformChannel);
}
}
}
5.3.5 商户平台应用-绑定服务类型接口(接口④)
5.3.5.1 接口定义
1、接口描述:请求交易服务为指定应用添加服务类型
2、接口定义如下:
在AppController类中定义bindPlatformForApp方法:
@DubboReference
private PayChannelService payChannelService;
@ApiOperation("绑定服务类型")
@PostMapping(value="/my/apps/{appId}/platform-channels")
@ApiImplicitParams({@ApiImplicitParam(value = "应用id",name = "appId",dataType = "string",paramType = "path"),
@ApiImplicitParam(value = "服务类型code",name = "platformChannelCodes",dataType = "string",paramType = "query")
})
public void bindPlatformForApp(@PathVariable("appId") String appId,
@RequestParam("platformChannelCodes") String platformChannelCodes){
payChannelService.bindPlatformChannelForApp(appId,platformChannelCodes);
}
5.3.5.2 接口测试
5.3.6 交易服务-查询服务类型绑定状态
5.3.6.1 接口定义
1、接口描述
1)查询应用是否已经绑定了某个服务类型
2、接口定义如下
1)PayChannelService
/**
\* 应用是否已经绑定了某个服务类型
\* @param appId
\* @param platformChannel
\* @return 已绑定返回1,否则 返回0
*/
int queryAppBindPlatformChannel(String appId,String platformChannel) throws BusinessException;
5.5.5.2 接口实现
在PayChannelServiceImpl中实现queryAppBindPlatformChannel方法:
@Override
public int queryAppBindPlatformChannel(String appId, String platformChannel) {
int count = appPlatformChannelMapper.selectCount(
new QueryWrapper<AppPlatformChannel>().lambda()
.eq(AppPlatformChannel::getAppId, appId)
.eq(AppPlatformChannel::getPlatformChannel, platformChannel));
//已存在绑定关系返回1
if (count > 0) {
return 1;
} else {
return 0;
}
}
5.3.7 商户平台-查询服务类型绑定状态
5.3.7.1 接口实现
接口描述
查询应用是否已经绑定了某个服务类型
在AppController中定义:
@ApiOperation("查询应用是否绑定了某个服务类型")
@ApiImplicitParams({
@ApiImplicitParam(name = "appId", value = "应用appId", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "platformChannel", value = "服务类型", required = true, dataType = "String", paramType = "query")
})
@GetMapping("/my/merchants/apps/platformchannels")
public int queryAppBindPlatformChannel(@RequestParam String appId, @RequestParam String platformChannel){
return payChannelService.queryAppBindPlatformChannel(appId,platformChannel);
}