package com.supwisdom.dlpay.api.service;
import com.supwisdom.dlpay.api.domain.TSourceType;
-import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
public interface SourceTypeService {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
- TSourceType getByPaytype(String paytype);
+ TSourceType getBySourceType(String paytype);
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
- Map<String, String> getPaytypeConfigByPaytype(String pattype);
+ Map<String, String> getSourceTypeConfigBySourceType(String pattype);
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
boolean checkRechargeSourcetype(String sourcetype) throws Exception;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
- boolean checkShopPaytype(String shopaccno, String sourceType, boolean anonymousflag) throws Exception;
+ boolean checkShopSourceType(String shopaccno, String sourceType, boolean anonymousflag) throws Exception;
/**
* 获取支付能力充值参数全局配置
@Override
- @Cacheable(cacheNames = "source_type_cache", keyGenerator = "tenantCacheKey")
- public TSourceType getByPaytype(String paytype) {
+ @Cacheable(cacheNames = "dictionary_cache", keyGenerator = "tenantCacheKey")
+ public TSourceType getBySourceType(String paytype) {
return paytypeDao.getOne(paytype);
}
@Override
- @Cacheable(cacheNames = "source_type_config_cache", keyGenerator = "tenantCacheKey")
- public Map<String, String> getPaytypeConfigByPaytype(String pattype) {
+ @Cacheable(cacheNames = "dictionary_cache", keyGenerator = "tenantCacheKey")
+ public Map<String, String> getSourceTypeConfigBySourceType(String pattype) {
List<TSourceTypeConfig> list = paytypeConfigDao.getBySourceType(pattype);
Map<String, String> map = new HashMap<>(list.size());
for (TSourceTypeConfig paytypeConfig : list) {
}
@Override
- public boolean checkShopPaytype(String shopaccno, String sourceType, boolean anonymousflag) throws Exception {
+ public boolean checkShopSourceType(String shopaccno, String sourceType, boolean anonymousflag) throws Exception {
//step1: 判断系统支付能力是否启用
TSourceType tSourceType = paytypeDao.getBySourceType(sourceType);
if (null == tSourceType) {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder name = new StringBuilder();
+ name.append(target.getClass().getSimpleName())
+ .append(delimiter);
String tenant = TenantContext.getTenantSchema();
if (StringUtils.isEmpty(tenant)) {
tenant = "default";
}
- name.append(tenant);
+ name.append(tenant).append(delimiter);
for (Object item : params) {
name.append(delimiter).append(item.toString());
}
--- /dev/null
+package com.supwisdom.dlpay.framework.tenant;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
+
+@Component("tenantHolder")
+public class TenantHolder {
+ private static final char delimiter = '-';
+
+ public String getId() {
+ String id = TenantContext.getTenantSchema();
+ if (id == null || StringUtils.isEmpty(id)) {
+ return "default";
+ }
+ return id;
+ }
+
+ public String genKey(String prefix, String... args) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(prefix).append(delimiter)
+ .append(getId());
+ for (String item : args) {
+ builder.append(delimiter).append(item);
+ }
+ return builder.toString();
+ }
+}
import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.domain.TSyspara;
import com.supwisdom.dlpay.framework.tenant.TenantContext;
+import com.supwisdom.dlpay.framework.tenant.TenantHolder;
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.StringUtil;
import com.supwisdom.dlpay.system.service.ParamService;
}
@Override
- @Cacheable(cacheNames = "source_type_cache", key = "#p0")
- public TSourceType getSourceType(String paytype) {
- if (!StringUtil.isEmpty(paytype)) {
- return sourceTypeDao.getBySourceType(paytype.trim());
+ @Cacheable(cacheNames = "dictionary_cache", key = "#{@tenantHolder.genKey('sourcetype', sourceType)}")
+ public TSourceType getSourceType(String sourceType) {
+ if (!StringUtil.isEmpty(sourceType)) {
+ return sourceTypeDao.getBySourceType(sourceType.trim());
}
return null;
}
@Override
- @Cacheable(cacheNames = "source_type_cache")
+ @Cacheable(cacheNames = "dictionary_cache", key = "@tenantHolder.genKey('sourcetype')")
public List<TSourceType> getAllSourceType() {
return sourceTypeDao.findAll();
}
@Override
- @CacheEvict(cacheNames = "source_type_cache", key = "#paytype.sourceType")
- public boolean saveOrUpdateSourceType(TSourceType paytype) {
- if (null != paytype) {
- paytype.setTenantid(TenantContext.getTenantSchema());
- sourceTypeDao.save(paytype);
+ @CacheEvict(cacheNames = "dictionary_cache", key = "@tenantHolder.genKey('sourcetype', sourceType.sourceType)")
+ public boolean saveOrUpdateSourceType(TSourceType sourceType) {
+ if (null != sourceType) {
+ sourceType.setTenantid(TenantContext.getTenantSchema());
+ sourceTypeDao.save(sourceType);
return true;
}
return false;
}
@Override
- @CacheEvict(cacheNames = "source_type_cache", key = "#paytype.sourceType")
- public boolean deleteSourceType(TSourceType paytype) {
- if (null != paytype) {
- sourceTypeDao.delete(paytype);
+ @CacheEvict(cacheNames = "dictionary_cache", key = "@tenantHolder.genKey('sourcetype', sourceType.sourceType)")
+ public boolean deleteSourceType(TSourceType sourceType) {
+ if (null != sourceType) {
+ sourceTypeDao.delete(sourceType);
return true;
}
return false;
}
@Override
- @Cacheable(cacheNames = "source_type_config_cache", key = "#p0")
- public List<TSourceTypeConfig> getSourceTypeConfigList(String paytype) {
- if (!StringUtil.isEmpty(paytype)) {
- List<TSourceTypeConfig> list = paytypeConfigDao.getBySourceTypeOrderByConfigid(paytype.trim());
+ @Cacheable(cacheNames = "source_type_config_cache", key = "@tenantHolder.genKey('sourcetype_config', sourceType)")
+ public List<TSourceTypeConfig> getSourceTypeConfigList(String sourceType) {
+ if (!StringUtil.isEmpty(sourceType)) {
+ List<TSourceTypeConfig> list = paytypeConfigDao.getBySourceTypeOrderByConfigid(sourceType.trim());
if (!StringUtil.isEmpty(list))
return list;
}
}
@Override
- @CacheEvict(cacheNames = "source_type_config_cache", key = "#p0")
- public boolean saveSourceTypeConfig(String paytype, Map<String, String> param) throws WebCheckException {
- TSourceType tPaytype = getSourceType(paytype);
- if (null == tPaytype) throw new WebCheckException("支付能力[" + paytype + "]不存在");
+ @CacheEvict(cacheNames = "source_type_config_cache", key = "@tenantHolder.genKey('sourcetype_config', sourceType)")
+ public boolean saveSourceTypeConfig(String sourceType, Map<String, String> param) throws WebCheckException {
+ TSourceType tPaytype = getSourceType(sourceType);
+ if (null == tPaytype) throw new WebCheckException("支付能力[" + sourceType + "]不存在");
for (String key : param.keySet()) {
String value = param.get(key);
TSourceTypeConfig config = paytypeConfigDao.getBySourceTypeAndConfigid(tPaytype.getSourceType(), key);
@PostMapping("/ykt/payinit")
fun yktPayInit(@RequestBody param: YktCardPayinitParam): ResponseEntity<Any> {
// val person = param.uid?.let { userService.findByThirdUniqueIdenty(it) } //没注册,可能匿名?
-// if (consumePayService.checkShopPaytype(param.shopaccno, TradeDict.PAYTYPE_YKT_CARD, person == null)) {
+// if (consumePayService.checkShopSourceType(param.shopaccno, TradeDict.PAYTYPE_YKT_CARD, person == null)) {
// val dtl = PersonTransBuilder.newBuilder(accountUtilServcie)
// .chooseTradetype(Tradetype.CONSUME) //消费
// .also {
// }
// }
// }.done(personBalancePayService, false)
-// val code = CallService.callWechatPay(paytypeService.getPaytypeConfigByPaytype(PaytypeUtil.WECHAT),
+// val code = CallService.callWechatPay(paytypeService.getSourceTypeConfigBySourceType(PaytypeUtil.WECHAT),
// dtl, DateUtil.getNow(), wechattype, realip, qrcode, openid)
// if (code.retcode == "0") {
// ResponseEntity.ok(ResponseBodyBuilder.create()
map = StringUtil.paraFilter(map)
//TODO 校验签名
var signStr = StringUtil.createLinkString(map)
- val config = paytypeService.getPaytypeConfigByPaytype(PaytypeUtil.WECHAT)
+ val config = paytypeService.getSourceTypeConfigBySourceType(PaytypeUtil.WECHAT)
if (config["appkey"].isNullOrEmpty()) {
logger.error("签名错误")
return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[签名错误]]></return_msg></xml>"
lateinit var transactionMainDao: TransactionMainDao
override fun checkShopPaytype(shopaccno: String, sourceType: String, anonymousflag: Boolean?): Boolean {
- return sourceTypeService.checkShopPaytype(shopaccno, sourceType, true == anonymousflag)
+ return sourceTypeService.checkShopSourceType(shopaccno, sourceType, true == anonymousflag)
}
override fun getPaytypeConfig(paytype: String, shopaccno: String,
package com.supwisdom.dlpay.api.service.impl
import com.supwisdom.dlpay.api.TransactionBuilder
-import com.supwisdom.dlpay.api.dao.AccountDao
import com.supwisdom.dlpay.api.dao.TransactionMainDao
import com.supwisdom.dlpay.api.domain.*
import com.supwisdom.dlpay.api.repositories.AccountService
import com.supwisdom.dlpay.api.service.TransactionService
import com.supwisdom.dlpay.exception.TransactionCheckException
import com.supwisdom.dlpay.exception.TransactionProcessException
-import com.supwisdom.dlpay.framework.dao.ShopaccDao
-import com.supwisdom.dlpay.framework.dao.SubjectDao
import com.supwisdom.dlpay.framework.service.SystemUtilService
import com.supwisdom.dlpay.framework.tenant.TenantContext
import com.supwisdom.dlpay.framework.util.Subject
private fun builderRecords(builder: TransactionBuilder, status: String): TTransactionMain {
try {
preCheck(builder)
- val sourceType = sourceTypeService.getByPaytype(builder.sourceType)
+ val sourceType = sourceTypeService.getBySourceType(builder.sourceType)
?: throw TransactionCheckException(TradeErrorCode.BUSINESS_PAYTYPE_NOSUPPORT,
"交易源未定义,sourctype <${builder.sourceType}>")
// 记录三方的交易流水(个人,商户,科目)
}
val jwt = JwtTokenUtil(jwtConfig).verifyToken(auth.substring(jwtConfig.tokenHeader.length))
val appid = jwt["uid"] as String
- return apiClientDao.findByAppid(appid)?.let {
+ val result = apiClientDao.findByAppid(appid)?.let {
if (it.status == TradeDict.STATUS_NORMAL) {
// 新证书
val token = JwtTokenUtil(jwtConfig).generateToken(
.success(ApiLoginResponse(token.jwtToken,
appid, DateUtil.getUTCTime(token.expiration.valueInMillis))))
} else {
- ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()
+ ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(mapOf("msg" to "appid error"))
}
- } ?: ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()
+ } ?: ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(mapOf("msg" to "appid error"))
+ return result as ResponseEntity<Any>
}
}