feat:钱包规则缓存

This commit is contained in:
dzc committed 2025-03-26 15:16:45 +08:00
1 parent 70db17490c
commit 63c6d1ed2b
9 files changed
+142 -11

No files matched your search

@@ -132,6 +132,8 @@ public interface CacheConstants {
String WALLET_SETTING_DETAIL = "wallet:detail:setting";
String WALLET_RULE_PRICE_CONFIG_DETAIL = "wallet:detail:rule_price_config";
/* ************************************* end 钱包相关 end ************************************* */
/* ************************************* start 第三方对接相关 start ************************************* */
@@ -19,13 +19,11 @@ import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
import com.bsd.pjcloud.hard.api.dto.HardManagerDto;
import com.bsd.pjcloud.hard.api.dto.hard.CurrentUserHardTypeInfoDto;
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
@@ -61,7 +59,6 @@ import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -73,7 +70,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
* 订单表
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.wallet.api.dto.rule;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleMchConfigEntity;
import lombok.Data;
@Data
public class WalletRuleMchConfigDto extends WalletRuleMchConfigEntity {
}
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.wallet.api.dto.rule;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRulePriceConfigEntity;
import lombok.Data;
@Data
public class WalletRulePriceConfigDto extends WalletRulePriceConfigEntity {
}
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.wallet.api.vo.rule;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleMchConfigEntity;
import lombok.Data;
@Data
public class WalletRuleMchConfigVo extends WalletRuleMchConfigEntity {
}
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.wallet.api.vo.rule;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRulePriceConfigEntity;
import lombok.Data;
@Data
public class WalletRulePriceConfigVo extends WalletRulePriceConfigEntity {
}
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.wallet.api.dto.rule.WalletRulePriceConfigDto;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRulePriceConfigEntity;
import com.bsd.pjcloud.wallet.service.WalletRulePriceConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -39,7 +40,7 @@ public class WalletRulePriceConfigController {
}
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/id")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('wallet_walletRulePriceConfig_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(walletRulePriceConfigService.getById(id));
@@ -49,16 +50,16 @@ public class WalletRulePriceConfigController {
@SysLog("新增钱包规则")
@PostMapping
@PreAuthorize("@pms.hasPermission('wallet_walletRulePriceConfig_add')")
public R save(@RequestBody WalletRulePriceConfigEntity walletRulePriceConfig) {
return R.ok(walletRulePriceConfigService.save(walletRulePriceConfig));
public R save(@RequestBody WalletRulePriceConfigDto dto) {
return R.ok(walletRulePriceConfigService.create(dto));
}
@Operation(summary = "修改钱包规则", description = "修改钱包规则")
@SysLog("修改钱包规则")
@PutMapping
@PreAuthorize("@pms.hasPermission('wallet_walletRulePriceConfig_edit')")
public R updateById(@RequestBody WalletRulePriceConfigEntity walletRulePriceConfig) {
return R.ok(walletRulePriceConfigService.updateById(walletRulePriceConfig));
public R updateById(@RequestBody WalletRulePriceConfigDto dto) {
return R.ok(walletRulePriceConfigService.edit(dto));
}
@Operation(summary = "通过id删除钱包规则", description = "通过id删除钱包规则")
@@ -66,7 +67,8 @@ public class WalletRulePriceConfigController {
@DeleteMapping
@PreAuthorize("@pms.hasPermission('wallet_walletRulePriceConfig_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(walletRulePriceConfigService.removeBatchByIds(CollUtil.toList(ids)));
walletRulePriceConfigService.delByIds(CollUtil.toList(ids));
return R.ok();
}
@ResponseExcel
@@ -1,8 +1,24 @@
package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.wallet.api.dto.rule.WalletRulePriceConfigDto;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRulePriceConfigEntity;
public interface WalletRulePriceConfigService extends IService<WalletRulePriceConfigEntity> {
import java.util.ArrayList;
public interface WalletRulePriceConfigService extends IService<WalletRulePriceConfigEntity> {
/**
* 新增
*/
Long create(WalletRulePriceConfigDto dto);
/**
* 修改
*/
Long edit(WalletRulePriceConfigDto dto);
/**
* 删除
*/
void delByIds(ArrayList<Long> list);
}
@@ -1,16 +1,99 @@
package com.bsd.pjcloud.wallet.service.impl.rule;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.common.core.constant.CacheConstants;
import com.bsd.pjcloud.wallet.api.dto.rule.WalletRulePriceConfigDto;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRulePriceConfigEntity;
import com.bsd.pjcloud.wallet.mapper.rule.WalletRulePriceConfigMapper;
import com.bsd.pjcloud.wallet.service.WalletRulePriceConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.io.Serializable;
import java.util.ArrayList;
/**
* 钱包规则
*
* @author dzc
* @date 2025-03-26 11:09:52
*/
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class WalletRulePriceConfigServiceImpl extends ServiceImpl<WalletRulePriceConfigMapper, WalletRulePriceConfigEntity> implements WalletRulePriceConfigService {
private final StringRedisTemplate redisTemplate;
@Override
@Cacheable(value = CacheConstants.WALLET_RULE_PRICE_CONFIG_DETAIL, key = "#id", condition = "#id != null", unless = "#result == null")
public WalletRulePriceConfigEntity getById(Serializable id) {
return super.getById(id);
}
/**
* 新增
*/
@Override
@CacheEvict(value = CacheConstants.WALLET_RULE_PRICE_CONFIG_DETAIL, key = "#dto.getId()", condition = "#dto.getId() != null")
public Long create(WalletRulePriceConfigDto dto) {
if (existRulePriceType(dto.getRulePriceType(), null)) {
throw new RuntimeException("规则类型不能重复");
}
baseMapper.insert(dto);
return dto.getId();
}
/**
* 修改
*/
@Override
@CacheEvict(value = CacheConstants.WALLET_RULE_PRICE_CONFIG_DETAIL, key = "#dto.getId()", condition = "#dto.getId() != null")
public Long edit(WalletRulePriceConfigDto dto) {
if (existRulePriceType(dto.getRulePriceType(), dto.getId())) {
throw new RuntimeException("规则类型不能重复");
}
WalletRulePriceConfigEntity detial = getSelf().getById(dto.getId());
if (ObjectUtil.isEmpty(detial)) throw new RuntimeException("商户不存在");
baseMapper.updateById(dto);
return dto.getId();
}
/**
* 删除
*/
@Override
public void delByIds(ArrayList<Long> list) {
if (ObjectUtil.isEmpty(list)) return;
// 删除缓存
list.forEach(v -> {
redisTemplate.opsForValue().getAndDelete(CacheConstants.WALLET_RULE_PRICE_CONFIG_DETAIL + v);
// walletThirdZyService.syncAllMch(v, Boolean.TRUE);
});
baseMapper.deleteByIds(list);
}
private boolean existRulePriceType(String rulePriceConfigType, Long id) {
Long count = baseMapper.selectCount(new LambdaQueryWrapper<WalletRulePriceConfigEntity>()
.eq(ObjectUtil.isNotEmpty(rulePriceConfigType), WalletRulePriceConfigEntity::getRulePriceType, rulePriceConfigType)
.ne(ObjectUtil.isNotEmpty(id), WalletRulePriceConfigEntity::getId, id)
);
if (ObjectUtil.isNotEmpty(id)) {
return count >= 1;
}
return count > 0;
}
private WalletRulePriceConfigServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
}