ShopMerchant缓存

This commit is contained in:
2025-03-12 10:38:50 +08:00
parent 7de83f5dc9
commit 8aa5e98317
5 changed files with 36 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ import com.czg.account.service.ShopMerchantService;
import com.czg.annotation.SaAdminCheckPermission; import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaAdminCheckRole; import com.czg.annotation.SaAdminCheckRole;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -41,6 +42,7 @@ public class ShopMerchantController {
@SaAdminCheckPermission(value = "shopMerchant:edit", name = "商户支付信息修改") @SaAdminCheckPermission(value = "shopMerchant:edit", name = "商户支付信息修改")
@PutMapping @PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopMerchantEditDTO shopMerchantEditDTO) { public CzgResult<Boolean> edit(@RequestBody @Validated ShopMerchantEditDTO shopMerchantEditDTO) {
shopMerchantEditDTO.setShopId(StpKit.USER.getLoginIdAsLong());
return CzgResult.success(shopMerchantService.edit(shopMerchantEditDTO)); return CzgResult.success(shopMerchantService.edit(shopMerchantEditDTO));
} }
} }

View File

@@ -8,6 +8,7 @@ import lombok.Data;
*/ */
@Data @Data
public class ShopMerchantEditDTO { public class ShopMerchantEditDTO {
private Long shopId;
@NotEmpty(message = "支付系统商户id不为空") @NotEmpty(message = "支付系统商户id不为空")
private String storeId; private String storeId;
@NotEmpty(message = "支付系统商户名称不为空") @NotEmpty(message = "支付系统商户名称不为空")

View File

@@ -141,11 +141,11 @@ public class CzgPayUtils {
log.error("超掌柜回调响应失败,{}", respParams); log.error("超掌柜回调响应失败,{}", respParams);
return null; return null;
} }
if (StrUtil.isNotBlank(respParams.getSign())) { // if (StrUtil.isNotBlank(respParams.getSign())) {
if (validateSign(respParams.getSign(), respParams.getBizData())) { // if (validateSign(respParams.getSign(), respParams.getBizData())) {
log.error("超掌柜回调 验签失败"); // log.error("超掌柜回调 验签失败");
} // }
} // }
return JSONObject.parse(respParams.getBizData()); return JSONObject.parse(respParams.getBizData());
} }
@@ -178,11 +178,11 @@ public class CzgPayUtils {
result.setCode("000000".equals(respParams.getCode()) ? 200 : Integer.parseInt(respParams.getCode())); result.setCode("000000".equals(respParams.getCode()) ? 200 : Integer.parseInt(respParams.getCode()));
result.setMsg(respParams.getMsg()); result.setMsg(respParams.getMsg());
if ("000000".equals(respParams.getCode()) && StrUtil.isNotBlank(respParams.getSign())) { if ("000000".equals(respParams.getCode()) && StrUtil.isNotBlank(respParams.getSign())) {
if (validateSign(respParams.getSign(), JSONObject.toJSONString(respParams))) { // if (validateSign(respParams.getSign(), JSONObject.toJSONString(respParams))) {
// result.setCode(CzgRespCode.FAILURE.getCode()); // result.setCode(CzgRespCode.FAILURE.getCode());
// result.setMsg("验签失败"); // result.setMsg("验签失败");
log.info("验签失败"); // log.info("验签失败");
} // }
result.setData(JSONObject.parseObject(respParams.getBizData(), clazz)); result.setData(JSONObject.parseObject(respParams.getBizData(), clazz));
} }
} else { } else {

View File

@@ -9,6 +9,9 @@ import com.czg.service.account.mapper.ShopMerchantMapper;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.io.Serializable; import java.io.Serializable;
@@ -18,6 +21,7 @@ import java.io.Serializable;
* @author Administrator * @author Administrator
* @since 2025-02-11 * @since 2025-02-11
*/ */
@CacheConfig(cacheNames = "shop:merchant")
@DubboService @DubboService
public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, ShopMerchant> implements ShopMerchantService { public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, ShopMerchant> implements ShopMerchantService {
@@ -27,12 +31,12 @@ public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, Sho
return one == null ? new ShopMerchant() : one; return one == null ? new ShopMerchant() : one;
} }
@CacheEvict(key = "#shopMerchantEditDTO.id")
@Override @Override
public Boolean edit(ShopMerchantEditDTO shopMerchantEditDTO) { public Boolean edit(ShopMerchantEditDTO shopMerchantEditDTO) {
ShopMerchant shopMerchant = queryChain().eq(ShopMerchant::getShopId, StpKit.USER.getLoginIdAsLong()).one(); ShopMerchant shopMerchant = queryChain().eq(ShopMerchant::getShopId, shopMerchantEditDTO.getShopId()).one();
if (shopMerchant == null) { if (shopMerchant == null) {
shopMerchant = new ShopMerchant(); shopMerchant = new ShopMerchant();
shopMerchant.setShopId(StpKit.USER.getLoginIdAsLong());
BeanUtil.copyProperties(shopMerchantEditDTO, shopMerchant); BeanUtil.copyProperties(shopMerchantEditDTO, shopMerchant);
return save(shopMerchant); return save(shopMerchant);
} }
@@ -40,10 +44,11 @@ public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, Sho
return updateById(shopMerchant); return updateById(shopMerchant);
} }
@Cacheable(key = "#id")
@Override @Override
public ShopMerchant getById(Serializable id) { public ShopMerchant getById(Serializable id) {
ShopMerchant shopMerchant = getMapper().selectOneById(id); ShopMerchant shopMerchant = getMapper().selectOneById(id);
AssertUtil.isNull(shopMerchant, "暂未开通支付"); AssertUtil.isNull(shopMerchant, "暂未开通支付");
return getMapper().selectOneById(id); return shopMerchant;
} }
} }

View File

@@ -13,6 +13,7 @@ import com.czg.config.RedisCst;
import com.czg.entity.req.*; import com.czg.entity.req.*;
import com.czg.entity.resp.*; import com.czg.entity.resp.*;
import com.czg.enums.ShopUserFlowBizEnum; import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
import com.czg.exception.PaySuccessException; import com.czg.exception.PaySuccessException;
import com.czg.order.dto.BigDecimalDTO; import com.czg.order.dto.BigDecimalDTO;
import com.czg.order.dto.CheckOrderPay; import com.czg.order.dto.CheckOrderPay;
@@ -638,14 +639,14 @@ public class PayServiceImpl implements PayService {
@Override @Override
@Transactional @Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) { public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
return czgPayService.queryPayOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo); return czgPayService.queryPayOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
} }
@Override @Override
@Transactional @Transactional
public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) { public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
return czgPayService.queryRefundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId); return czgPayService.queryRefundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
} }
@@ -665,7 +666,7 @@ public class PayServiceImpl implements PayService {
private CzgResult<Map<String, Object>> h5Pay(@NonNull Long shopId, CzgH5PayReq bizData) { private CzgResult<Map<String, Object>> h5Pay(@NonNull Long shopId, CzgH5PayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(), bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode())); sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
CzgResult<CzgH5PayResp> h5PayRespCzgResult = czgPayService.h5Pay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData); CzgResult<CzgH5PayResp> h5PayRespCzgResult = czgPayService.h5Pay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
@@ -673,7 +674,7 @@ public class PayServiceImpl implements PayService {
} }
private CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData) { private CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid()); bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序"); AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(), bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
@@ -684,7 +685,7 @@ public class PayServiceImpl implements PayService {
} }
private CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData) { private CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid()); bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序"); AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(), bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
@@ -694,7 +695,7 @@ public class PayServiceImpl implements PayService {
} }
private CzgResult<Map<String, Object>> scanPay(@NonNull Long shopId, CzgScanPayReq bizData) { private CzgResult<Map<String, Object>> scanPay(@NonNull Long shopId, CzgScanPayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(), bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode())); sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
CzgResult<CzgScanPayResp> scanPayRespCzgResult = czgPayService.scanPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData); CzgResult<CzgScanPayResp> scanPayRespCzgResult = czgPayService.scanPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
@@ -703,7 +704,7 @@ public class PayServiceImpl implements PayService {
private CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) { private CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) {
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试"); AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(), bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode())); sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
String firstTwoDigitsStr = bizData.getAuthCode().substring(0, 2); String firstTwoDigitsStr = bizData.getAuthCode().substring(0, 2);
@@ -727,11 +728,19 @@ public class PayServiceImpl implements PayService {
} }
private CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData) { private CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId); ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setNotifyUrl(sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_REFUND_NOTIFY_URL.getCode())); bizData.setNotifyUrl(sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_REFUND_NOTIFY_URL.getCode()));
return czgPayService.refundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData); return czgPayService.refundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
} }
private ShopMerchant getMerchant(Long shopId) {
try {
return shopMerchantService.getById(shopId);
} catch (Exception e) {
throw new CzgException(e.getMessage());
}
}
private CzgResult<Map<String, Object>> execPayResult(CzgResult<? extends CzgBaseResp> res) { private CzgResult<Map<String, Object>> execPayResult(CzgResult<? extends CzgBaseResp> res) {
CzgResult<Map<String, Object>> result = CzgResult.success(); CzgResult<Map<String, Object>> result = CzgResult.success();
if (res.getCode() != 200 || res.getData() == null) { if (res.getCode() != 200 || res.getData() == null) {